From 0394b2a5fe664b4daf45c81666519f36f89bfe29 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 17 Nov 2023 21:39:40 +0900 Subject: [PATCH] UpdateMeshIntegrationGroups --- .../Editor/MeshUtility/MeshIntegrationTab.cs | 16 +++++------ .../Runtime/MeshUtility/GltfMeshUtility.cs | 27 +++++++++++++++++++ .../MeshUtility/Vrm10MeshIntegrationTab.cs | 8 ------ .../Runtime/MeshUtility/Vrm10MeshUtility.cs | 18 +------------ 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/Assets/UniGLTF/Editor/MeshUtility/MeshIntegrationTab.cs b/Assets/UniGLTF/Editor/MeshUtility/MeshIntegrationTab.cs index cf90961e5..6c9c6ec93 100644 --- a/Assets/UniGLTF/Editor/MeshUtility/MeshIntegrationTab.cs +++ b/Assets/UniGLTF/Editor/MeshUtility/MeshIntegrationTab.cs @@ -8,7 +8,7 @@ namespace UniGLTF.MeshUtility public class MeshIntegrationTab { bool _modified = false; - protected GltfMeshUtility _meshUti; + protected GltfMeshUtility _meshUtil; Splitter _splitter; ReorderableList _groupList; @@ -23,29 +23,29 @@ namespace UniGLTF.MeshUtility { return; } - if (value < 0 || value >= _meshUti.MeshIntegrationGroups.Count) + if (value < 0 || value >= _meshUtil.MeshIntegrationGroups.Count) { return; } _selected = value; _renderers.Clear(); - _renderers.AddRange(_meshUti.MeshIntegrationGroups[_selected].Renderers); + _renderers.AddRange(_meshUtil.MeshIntegrationGroups[_selected].Renderers); } } public MeshIntegrationTab(EditorWindow editor, GltfMeshUtility meshUtility) { - _meshUti = meshUtility; + _meshUtil = meshUtility; _splitter = new VerticalSplitter(editor, 200, 50); - _groupList = new ReorderableList(_meshUti.MeshIntegrationGroups, typeof(MeshIntegrationGroup)); + _groupList = new ReorderableList(_meshUtil.MeshIntegrationGroups, typeof(MeshIntegrationGroup)); _groupList.drawHeaderCallback = (Rect rect) => { GUI.Label(rect, "Integration group"); }; _groupList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { - var group = _meshUti.MeshIntegrationGroups[index]; + var group = _meshUtil.MeshIntegrationGroups[index]; EditorGUI.TextField(rect, group.Name); }; _groupList.onSelectCallback = rl => @@ -65,10 +65,10 @@ namespace UniGLTF.MeshUtility }; } - public virtual void UpdateMeshIntegrationList(GameObject root) + public void UpdateMeshIntegrationList(GameObject root) { _selected = -1; - _meshUti.MeshIntegrationGroups.Clear(); + _meshUtil.UpdateMeshIntegrationGroups(root); Selected = 0; } diff --git a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs index 4a4af9177..41e1132f5 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs @@ -59,6 +59,33 @@ namespace UniGLTF.MeshUtility /// public bool SplitByBlendShape = false; + protected UniGLTF.MeshUtility.MeshIntegrationGroup _GetOrCreateGroup(string name) + { + foreach (var g in MeshIntegrationGroups) + { + if (g.Name == name) + { + return g; + } + } + MeshIntegrationGroups.Add(new UniGLTF.MeshUtility.MeshIntegrationGroup + { + Name = name, + }); + return MeshIntegrationGroups.Last(); + } + + public virtual void UpdateMeshIntegrationGroups(GameObject root) + { + MeshIntegrationGroups.Clear(); + if (root == null) + { + return; + } + var group = _GetOrCreateGroup("all mesh"); + group.Renderers.AddRange(root.GetComponentsInChildren()); + } + public void IntegrateAll(GameObject root) { if (root == null) diff --git a/Assets/VRM10/Editor/MeshUtility/Vrm10MeshIntegrationTab.cs b/Assets/VRM10/Editor/MeshUtility/Vrm10MeshIntegrationTab.cs index 9a2d13fd8..4bee935da 100644 --- a/Assets/VRM10/Editor/MeshUtility/Vrm10MeshIntegrationTab.cs +++ b/Assets/VRM10/Editor/MeshUtility/Vrm10MeshIntegrationTab.cs @@ -11,13 +11,5 @@ namespace UniVRM10 { _vrmMeshUtil = meshUtility; } - - public override void UpdateMeshIntegrationList(GameObject root) - { - _selected = -1; - _meshUti.MeshIntegrationGroups.Clear(); - _vrmMeshUtil.IntegrateFirstPerson(root); - Selected = 0; - } } } \ No newline at end of file diff --git a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs index 48b79d617..60e665dd5 100644 --- a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs +++ b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs @@ -117,7 +117,7 @@ namespace UniVRM10 } } - public void IntegrateFirstPerson(GameObject root) + public override void UpdateMeshIntegrationGroups(GameObject root) { if (root == null) { @@ -144,21 +144,5 @@ namespace UniVRM10 g.Renderers.Add(a.GetRenderer(root.transform)); } } - - UniGLTF.MeshUtility.MeshIntegrationGroup _GetOrCreateGroup(string name) - { - foreach (var g in MeshIntegrationGroups) - { - if (g.Name == name) - { - return g; - } - } - MeshIntegrationGroups.Add(new UniGLTF.MeshUtility.MeshIntegrationGroup - { - Name = name, - }); - return MeshIntegrationGroups.Last(); - } } } \ No newline at end of file