diff --git a/Assets/UniGLTF/Runtime/MeshUtility/MeshIntegrator.cs b/Assets/UniGLTF/Runtime/MeshUtility/MeshIntegrator.cs index a2c37dd2e..28b2e7f6b 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/MeshIntegrator.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/MeshIntegrator.cs @@ -1,14 +1,18 @@ +using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; using UnityEngine; namespace UniGLTF.MeshUtility { public class MeshIntegrator { - public const string INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME = "Integrated(WithoutBlendShape)"; - public const string INTEGRATED_MESH_WITH_BLENDSHAPE_NAME = "Integrated(WithBlendShape)"; - public const string INTEGRATED_MESH_ALL_NAME = "Integrated(All)"; + private MeshIntegrator() + { + + } struct SubMesh { @@ -81,7 +85,7 @@ namespace UniGLTF.MeshUtility return bw; } - public void Push(MeshRenderer renderer) + void Push(MeshRenderer renderer) { var meshFilter = renderer.GetComponent(); if (meshFilter == null) @@ -232,7 +236,24 @@ namespace UniGLTF.MeshUtility } } - public MeshIntegrationResult Integrate(MeshEnumerateOption onlyBlendShapeRenderers) + public static MeshIntegrationResult Integrate(MeshIntegrationGroup group, bool useBlendShape) + { + var integrator = new MeshUtility.MeshIntegrator(); + foreach (var x in group.Renderers) + { + if (x is SkinnedMeshRenderer smr) + { + integrator.Push(smr); + } + else if (x is MeshRenderer mr) + { + integrator.Push(mr); + } + } + return integrator.Integrate(group.Name, useBlendShape); + } + + public MeshIntegrationResult Integrate(string name, bool useBlendShape) { var mesh = new Mesh(); @@ -253,51 +274,15 @@ namespace UniGLTF.MeshUtility mesh.SetIndices(SubMeshes[i].Indices.ToArray(), MeshTopology.Triangles, i); } mesh.bindposes = BindPoses.ToArray(); - - // blendshape - switch (onlyBlendShapeRenderers) + if (useBlendShape) { - case MeshEnumerateOption.OnlyWithBlendShape: - { - AddBlendShapesToMesh(mesh); - mesh.name = INTEGRATED_MESH_WITH_BLENDSHAPE_NAME; - break; - } - - case MeshEnumerateOption.All: - { - AddBlendShapesToMesh(mesh); - mesh.name = INTEGRATED_MESH_ALL_NAME; - break; - } - - case MeshEnumerateOption.OnlyWithoutBlendShape: - { - mesh.name = INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME; - break; - } + AddBlendShapesToMesh(mesh); } + mesh.name = name; // meshName var meshNode = new GameObject(); - switch (onlyBlendShapeRenderers) - { - case MeshEnumerateOption.OnlyWithBlendShape: - { - meshNode.name = INTEGRATED_MESH_WITH_BLENDSHAPE_NAME; - break; - } - case MeshEnumerateOption.OnlyWithoutBlendShape: - { - meshNode.name = INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME; - break; - } - case MeshEnumerateOption.All: - { - meshNode.name = INTEGRATED_MESH_ALL_NAME; - break; - } - } + meshNode.name = name; var integrated = meshNode.AddComponent(); integrated.sharedMesh = mesh; diff --git a/Assets/UniGLTF/Runtime/MeshUtility/MeshIntegratorUtility.cs b/Assets/UniGLTF/Runtime/MeshUtility/MeshIntegratorUtility.cs index 7050bcb99..68970c2c3 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/MeshIntegratorUtility.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/MeshIntegratorUtility.cs @@ -1,11 +1,14 @@ using System.Collections.Generic; -using System.IO; using UnityEngine; namespace UniGLTF.MeshUtility { public static class MeshIntegratorUtility { + public const string INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME = "Integrated(WithoutBlendShape)"; + public const string INTEGRATED_MESH_WITH_BLENDSHAPE_NAME = "Integrated(WithBlendShape)"; + public const string INTEGRATED_MESH_ALL_NAME = "Integrated(All)"; + /// /// go を root としたヒエラルキーから Renderer を集めて、統合された Mesh 作成する /// @@ -22,32 +25,39 @@ namespace UniGLTF.MeshUtility { var exclude = new MeshExclude(excludes); - var integrator = new MeshUtility.MeshIntegrator(); + var group = new MeshIntegrationGroup(); + bool useBlendShape = false; switch (onlyBlendShapeRenderers) { case MeshEnumerateOption.OnlyWithBlendShape: { + group.Name = INTEGRATED_MESH_WITH_BLENDSHAPE_NAME; + useBlendShape = true; + foreach (var x in EnumerateSkinnedMeshRenderer(go.transform, onlyBlendShapeRenderers)) { if (exclude.IsExcluded(x)) { continue; } - integrator.Push(x); + group.Renderers.Add(x); } break; } case MeshEnumerateOption.OnlyWithoutBlendShape: { + group.Name = INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME; + useBlendShape = false; + foreach (var x in EnumerateSkinnedMeshRenderer(go.transform, onlyBlendShapeRenderers)) { if (exclude.IsExcluded(x)) { continue; } - integrator.Push(x); + group.Renderers.Add(x); } foreach (var x in EnumerateMeshRenderer(go.transform)) @@ -56,7 +66,7 @@ namespace UniGLTF.MeshUtility { continue; } - integrator.Push(x); + group.Renderers.Add(x); } break; @@ -64,13 +74,16 @@ namespace UniGLTF.MeshUtility case MeshEnumerateOption.All: { + group.Name = INTEGRATED_MESH_ALL_NAME; + useBlendShape = true; + foreach (var x in EnumerateSkinnedMeshRenderer(go.transform, onlyBlendShapeRenderers)) { if (exclude.IsExcluded(x)) { continue; } - integrator.Push(x); + group.Renderers.Add(x); } foreach (var x in EnumerateMeshRenderer(go.transform)) @@ -79,14 +92,14 @@ namespace UniGLTF.MeshUtility { continue; } - integrator.Push(x); + group.Renderers.Add(x); } break; } } - return integrator.Integrate(onlyBlendShapeRenderers); + return MeshIntegrator.Integrate(group, useBlendShape); } public static IEnumerable EnumerateSkinnedMeshRenderer(Transform root, MeshEnumerateOption hasBlendShape) diff --git a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs index 841fd348f..4e6279b00 100644 --- a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs +++ b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs @@ -145,13 +145,22 @@ namespace UniVRM10 // TODO: integration foreach (var group in MeshIntegrationGroups) { - foreach (var renderer in group.Renderers) - { + var newMesh = MeshIntegrator.Integrate(group, true); + // TODO: firstperson + // TODO: split + if (SplitByBlendShape) + { + // var withBlendShape, withoutBlendShape + // TODO: remove old renderer + // TODO: add new renderer to root + } + else + { + // TODO: remove old renderer + // TODO: add new renderer to root } } - - // TODO: split } } }