diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs index 6c61ffa57..7137b8549 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs @@ -64,28 +64,28 @@ namespace UniGLTF foreach (var info in Meshes) { // invalid materials.len - if (info.Renderer.sharedMaterials.Length < info.Mesh.subMeshCount) + if (info.Materials.Length < info.Mesh.subMeshCount) { // submesh より material の方が少ない yield return Validation.Error(Messages.MATERIALS_LESS_THAN_SUBMESH_COUNT.Msg()); } else { - if (info.Renderer.sharedMaterials.Length > info.Mesh.subMeshCount) + if (info.Materials.Length > info.Mesh.subMeshCount) { // submesh より material の方が多い yield return Validation.Warning(Messages.MATERIALS_GREATER_THAN_SUBMESH_COUNT.Msg()); } - if (info.Renderer.sharedMaterials.Take(info.Mesh.subMeshCount).Any(x => x == null)) + if (info.Materials.Take(info.Mesh.subMeshCount).Any(x => x == null)) { // material に null が含まれる(unity で magenta になっているはず) - yield return Validation.Error($"{info.Renderer}: {Messages.MATERIALS_CONTAINS_NULL.Msg()}"); + yield return Validation.Error($"{info.Renderers}: {Messages.MATERIALS_CONTAINS_NULL.Msg()}"); } } } - foreach (var m in Meshes.SelectMany(x => x.Renderer.sharedMaterials).Distinct()) + foreach (var m in Meshes.SelectMany(x => x.Materials).Distinct()) { if (m == null) { diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidatorEditor.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidatorEditor.cs index 70edf409c..e69f21ba2 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidatorEditor.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidatorEditor.cs @@ -40,12 +40,15 @@ namespace UniGLTF var (left, right) = LeftRight(r.x, r.y, col0, r.width - col0, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(left, $"{i,3}"); - GUI.enabled = false; - EditorGUI.ObjectField(right, info.Renderer, info.Renderer.GetType(), true); - - right.y += EditorGUIUtility.singleLineHeight; - EditorGUI.ObjectField(right, info.Mesh, info.Renderer.GetType(), true); - GUI.enabled = true; + using (new EditorGUI.DisabledScope(false)) + { + foreach (var renderer in info.Renderers) + { + EditorGUI.ObjectField(right, renderer, info.Renderers.GetType(), true); + } + right.y += EditorGUIUtility.singleLineHeight; + EditorGUI.ObjectField(right, info.Mesh, info.Renderers.GetType(), true); + } right.y += EditorGUIUtility.singleLineHeight; EditorGUI.LabelField(right, info.Summary); diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshExportInfo.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshExportInfo.cs index a069ae375..785cb5b0a 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshExportInfo.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshExportInfo.cs @@ -7,10 +7,18 @@ using UnityEngine; namespace UniGLTF { [Serializable] - public struct MeshExportInfo + public class MeshExportInfo { - public Renderer Renderer; + #region この2つの組が gltf mesh の Unique なキーとなる public Mesh Mesh; + public Material[] Materials; + #endregion + + /// + /// ひとつの Mesh を複数の Renderer が共有することがありうる + /// + public List Renderers; + public bool IsRendererActive; public bool Skinned; @@ -50,6 +58,12 @@ namespace UniGLTF public string Summary; + MeshExportInfo(Renderer renderer) + { + Materials = renderer.sharedMaterials; + Renderers = new List { renderer }; + } + /// /// ヒエラルキーからエクスポートする Mesh の情報を収集する /// @@ -76,27 +90,27 @@ namespace UniGLTF static bool TryGetMeshInfo(GameObject root, Renderer renderer, MeshExportSettings settings, IBlendShapeExportFilter blendShapeFilter, out MeshExportInfo info) { - info = default; if (root == null) { - info.Summary = ""; + info = default; return false; } if (renderer == null) { - info.Summary = "no Renderer"; + info = default; return false; } - info.Renderer = renderer; if (renderer is SkinnedMeshRenderer smr) { + info = new MeshExportInfo(renderer); info.Skinned = true; info.Mesh = smr.sharedMesh; info.IsRendererActive = smr.EnableForExport(); } else if (renderer is MeshRenderer mr) { + info = new MeshExportInfo(renderer); var filter = mr.GetComponent(); if (filter != null) { @@ -106,11 +120,15 @@ namespace UniGLTF } else { - info.Summary = "no Mesh"; - return false; + throw new NotImplementedException(); } - info.VertexColor = VertexColorUtility.DetectVertexColor(info.Mesh, info.Renderer.sharedMaterials); + if (info.Mesh == null) + { + info.Summary = "no mesh"; + } + + info.VertexColor = VertexColorUtility.DetectVertexColor(info.Mesh, info.Materials); var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(renderer.transform, root.transform); CalcMeshSize(ref info, relativePath, settings, blendShapeFilter); diff --git a/Assets/VRM/Editor/Format/VRMExporterWizard.cs b/Assets/VRM/Editor/Format/VRMExporterWizard.cs index 1c0f426fe..2861af0c6 100644 --- a/Assets/VRM/Editor/Format/VRMExporterWizard.cs +++ b/Assets/VRM/Editor/Format/VRMExporterWizard.cs @@ -259,7 +259,7 @@ namespace VRM switch (meshInfo.VertexColor) { case UniGLTF.VertexColorState.ExistsAndMixed: - Validation.Warning($"{meshInfo.Renderer}: Both vcolor.multiply and not multiply unlit materials exist").DrawGUI(); + Validation.Warning($"{meshInfo.Renderers}: Both vcolor.multiply and not multiply unlit materials exist").DrawGUI(); break; } }