diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs index 7b987fb10..e5ed04f6e 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs @@ -64,14 +64,10 @@ namespace UniGLTF // MorphTarget を Position だけにする(normal とか捨てる) public bool ExportOnlyBlendShapePosition; - // VertexColor が存在していても捨てる - public bool RemoveVertexColor; - public static MeshExportSettings Default => new MeshExportSettings { UseSparseAccessorForMorphTarget = false, ExportOnlyBlendShapePosition = false, - RemoveVertexColor = false, }; } @@ -80,8 +76,7 @@ namespace UniGLTF static glTFMesh ExportPrimitives(glTF gltf, int bufferIndex, string rendererName, Mesh mesh, Material[] materials, - List unityMaterials, - bool removeVertexColor) + List unityMaterials) { var positions = mesh.vertices.Select(y => y.ReverseZ()).ToArray(); var positionAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, positions, glBufferTarget.ARRAY_BUFFER); @@ -95,8 +90,16 @@ namespace UniGLTF var uvAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.uv.Select(y => y.ReverseUV()).ToArray(), glBufferTarget.ARRAY_BUFFER); var colorAccessorIndex = -1; - if (!removeVertexColor) - colorAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.colors, glBufferTarget.ARRAY_BUFFER); + if (mesh.colors != null && mesh.colors.Length == mesh.vertexCount) + { + // この Mesh が 頂点カラーを保持していて + if (materials.Any(x => x.shader.name == UniGLTF.UniUnlit.Utils.ShaderName + && UniGLTF.UniUnlit.Utils.GetVColBlendMode(x) == UniUnlit.UniUnlitVertexColorBlendOp.Multiply)) + { + // UniUnlit で Multiply 設定になっている + colorAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.colors, glBufferTarget.ARRAY_BUFFER); + } + } var boneweights = mesh.boneWeights; var weightAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, boneweights.Select(y => new Vector4(y.weight0, y.weight1, y.weight2, y.weight3)).ToArray(), glBufferTarget.ARRAY_BUFFER); @@ -306,7 +309,7 @@ namespace UniGLTF var gltfMesh = ExportPrimitives(gltf, bufferIndex, x.Renderer.name, - mesh, materials, unityMaterials, settings.RemoveVertexColor); + mesh, materials, unityMaterials); var blendShapeIndexMap = new Dictionary(); int exportBlendShapes = 0; diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs b/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs index 2d48de97c..a3726090a 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs @@ -16,12 +16,12 @@ namespace VRM /// /// 出力先 /// エクスポート設定 - public static void Export(string path, GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings) + public static void Export(string path, GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings, IReadOnlyList info) { List destroy = new List(); try { - Export(path, exportRoot, meta, settings, destroy); + Export(path, exportRoot, meta, settings, info, destroy); } finally { @@ -136,7 +136,9 @@ namespace VRM /// /// /// 作業が終わったらDestoryするべき一時オブジェクト - static void Export(string path, GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings, List destroy) + static void Export(string path, GameObject exportRoot, VRMMetaObject meta, + VRMExportSettings settings, IReadOnlyList info, + List destroy) { var target = exportRoot; diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs index 48f4f2c9e..35205b54a 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using UnityEngine; namespace VRM @@ -42,17 +43,10 @@ namespace VRM [Tooltip("Remove blendShapeClip that preset is Unknown")] public bool ReduceBlendshapeClip = false; - /// - /// 頂点カラーを削除する - /// - [Tooltip("Remove vertex color")] - public bool RemoveVertexColor = false; - public UniGLTF.MeshExportSettings MeshExportSettings => new UniGLTF.MeshExportSettings { UseSparseAccessorForMorphTarget = UseSparseAccessor, ExportOnlyBlendShapePosition = OnlyBlendshapePosition, - RemoveVertexColor = RemoveVertexColor, }; } } diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettingsEditor.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettingsEditor.cs index 11db19e15..2f9a1c3e8 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettingsEditor.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettingsEditor.cs @@ -78,19 +78,12 @@ namespace VRM [Tooltip("Remove blendShapeClip that preset is Unknown")] public bool ReduceBlendshapeClip = false; - /// - /// 頂点カラーを削除する - /// - [Tooltip("Remove vertex color")] - public bool RemoveVertexColor = false; - CheckBoxProp m_forceTPose; CheckBoxProp m_poseFreeze; CheckBoxProp m_useSparseAccessor; CheckBoxProp m_onlyBlendShapePosition; CheckBoxProp m_reduceBlendShape; CheckBoxProp m_reduceBlendShapeClip; - CheckBoxProp m_removeVertexColor; static string Msg(Options key) { @@ -140,7 +133,6 @@ namespace VRM m_onlyBlendShapePosition = new CheckBoxProp(serializedObject.FindProperty(nameof(OnlyBlendshapePosition)), Options.BLENDSHAPE_EXCLUDE_NORMAL_AND_TANGENT); m_reduceBlendShape = new CheckBoxProp(serializedObject.FindProperty(nameof(ReduceBlendshape)), Options.BLENDSHAPE_ONLY_CLIP_USE); m_reduceBlendShapeClip = new CheckBoxProp(serializedObject.FindProperty(nameof(ReduceBlendshapeClip)), Options.BLENDSHAPE_EXCLUDE_UNKNOWN); - m_removeVertexColor = new CheckBoxProp(serializedObject.FindProperty(nameof(RemoveVertexColor)), Options.REMOVE_VERTEX_COLOR); } public override void OnInspectorGUI() @@ -153,7 +145,6 @@ namespace VRM m_onlyBlendShapePosition.Draw(); m_reduceBlendShape.Draw(); m_reduceBlendShapeClip.Draw(); - m_removeVertexColor.Draw(); serializedObject.ApplyModifiedProperties(); } } diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs index 8ef084ccd..4af90e282 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs @@ -361,7 +361,7 @@ namespace VRM m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/"); // export - VRMEditorExporter.Export(path, ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings); + VRMEditorExporter.Export(path, ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings, m_meshes.Meshes); } void OnWizardUpdate()