diff --git a/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs b/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs
index 7caaf44ae..343ecafa5 100644
--- a/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs
+++ b/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs
@@ -205,7 +205,9 @@ namespace UniGLTF.MeshUtility
var (results, created) = MeshUtility.Process(context.Instance, groupCopy);
- WriteAssets(context.Instance, context.AssetFolder, results);
+ WriteAssets(context.Instance, context.AssetFolder, results, _exportTarget);
+
+ MeshUtility.clear(results);
}
catch (Exception ex)
{
@@ -221,6 +223,7 @@ namespace UniGLTF.MeshUtility
using (var context = new UndoContext("MeshUtility", _exportTarget))
{
var (results, created) = MeshUtility.Process(_exportTarget, MeshUtility.MeshIntegrationGroups);
+ MeshUtility.clear(results);
foreach (var go in created)
{
@@ -238,7 +241,7 @@ namespace UniGLTF.MeshUtility
///
/// Write Mesh & Prefab
///
- protected virtual void WriteAssets(GameObject copy, string assetFolder, List results)
+ protected virtual string WriteAssets(GameObject copy, string assetFolder, List results, GameObject prefab)
{
// write mesh asset
foreach (var result in results)
@@ -265,6 +268,8 @@ namespace UniGLTF.MeshUtility
{
throw new System.Exception($"PrefabUtility.SaveAsPrefabAsset: {prefabPath}");
}
+
+ return prefabPath;
}
protected bool ToggleIsModified(string label, ref bool value)
diff --git a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs
index ce3b5a23b..6366450b3 100644
--- a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs
+++ b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs
@@ -163,7 +163,12 @@ namespace UniGLTF.MeshUtility
}
}
- // // 用が済んだ 統合前 の renderer を削除する
+ return (results, newList);
+ }
+
+ public void clear(List results)
+ {
+ // 用が済んだ 統合前 の renderer を削除する
foreach (var result in results)
{
foreach (var r in result.SourceMeshRenderers)
@@ -187,14 +192,12 @@ namespace UniGLTF.MeshUtility
}
else
{
- GameObject.DestroyImmediate(r);
+ GameObject.DestroyImmediate(r, true);
}
}
}
MeshIntegrationGroups.Clear();
-
- return (results, newList);
}
protected virtual bool TryIntegrate(GameObject empty,
diff --git a/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs b/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs
index 5478f008e..5a7f24a5b 100644
--- a/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs
+++ b/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs
@@ -328,18 +328,7 @@ namespace UniHumanoid
var avatarDescription = UniHumanoid.AvatarDescription.Create();
avatarDescription.SetHumanBones(map);
- // ??? clear old avatar ???
- var t = src.transform;
- if (Application.isPlaying)
- {
- GameObject.Destroy(src);
- }
- else
- {
- GameObject.DestroyImmediate(src, true);
- }
-
- var avatar = avatarDescription.CreateAvatar(t);
+ var avatar = avatarDescription.CreateAvatar(src.transform);
avatar.name = "created";
return avatar;
}
diff --git a/Assets/VRM/Editor/SkinnedMeshUtility/VRMMeshIntegratorUtility.cs b/Assets/VRM/Editor/SkinnedMeshUtility/VRMMeshIntegratorUtility.cs
index 33faa8359..4fe5542b6 100644
--- a/Assets/VRM/Editor/SkinnedMeshUtility/VRMMeshIntegratorUtility.cs
+++ b/Assets/VRM/Editor/SkinnedMeshUtility/VRMMeshIntegratorUtility.cs
@@ -21,7 +21,7 @@ namespace VRM
{
return clips;
}
- var result = results.FirstOrDefault(x => x.Integrated.Mesh.blendShapeCount > 0);
+ var result = results.FirstOrDefault(x => x.Integrated?.Mesh.blendShapeCount > 0);
if (result == null)
{
return clips;
diff --git a/Assets/VRM/Editor/SkinnedMeshUtility/VrmMeshIntegratorWizard.cs b/Assets/VRM/Editor/SkinnedMeshUtility/VrmMeshIntegratorWizard.cs
index 776cefccd..7da4743f9 100644
--- a/Assets/VRM/Editor/SkinnedMeshUtility/VrmMeshIntegratorWizard.cs
+++ b/Assets/VRM/Editor/SkinnedMeshUtility/VrmMeshIntegratorWizard.cs
@@ -50,30 +50,32 @@ namespace VRM
return firstPerson || mod;
}
- protected override void WriteAssets(GameObject copy, string assetFolder, List results)
+ protected override string WriteAssets(GameObject target, string assetFolder, List results, GameObject prefab)
{
- base.WriteAssets(copy, assetFolder, results);
-
// 統合した結果を反映した BlendShapeClip を作成して置き換える
- // var clips = VRMMeshIntegratorUtility.FollowBlendshapeRendererChange(results, copy, assetFolder);
+ var clips = VRMMeshIntegratorUtility.FollowBlendshapeRendererChange(results, target, assetFolder);
// reset firstperson
- // var firstperson = copy.GetComponent();
- // if (firstperson != null)
- // {
- // firstperson.Reset();
- // }
+ if (target.GetComponent() is VRMFirstPerson firstperson)
+ {
+ firstperson.Reset();
+ }
- // var prefabReference = AssetDatabase.LoadAssetAtPath(prefabPath);
- // foreach (var clip in clips)
- // {
- // var so = new SerializedObject(clip);
- // so.Update();
- // // clip.Prefab = copy;
- // var prop = so.FindProperty("m_prefab");
- // prop.objectReferenceValue = prefabReference;
- // so.ApplyModifiedProperties();
- // }
+ // write mesh & prefab
+ var prefabPath = base.WriteAssets(target, assetFolder, results, prefab);
+
+ var prefabReference = AssetDatabase.LoadAssetAtPath(prefabPath);
+ foreach (var clip in clips)
+ {
+ var so = new SerializedObject(clip);
+ so.Update();
+ // clip.Prefab = copy;
+ var prop = so.FindProperty("m_prefab");
+ prop.objectReferenceValue = prefabReference;
+ so.ApplyModifiedProperties();
+ }
+
+ return prefabPath;
}
protected override void DialogMessage()
diff --git a/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs b/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs
index aa3e0b272..21d9bdd4f 100644
--- a/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs
+++ b/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs
@@ -12,30 +12,33 @@ namespace VRM
bool _generateFirstPerson = false;
public override IEnumerable CopyInstantiate(GameObject go, GameObject instance)
{
- var copy = new List();
_generateFirstPerson = false;
+
+ var copy = base.CopyInstantiate(go, instance);
if (GenerateMeshForFirstPersonAuto)
{
- foreach (var g in MeshIntegrationGroups)
+ foreach (var g in copy)
{
if (g.Name == "auto")
{
_generateFirstPerson = true;
// 元のメッシュを三人称に変更
- copy.Add(new UniGLTF.MeshUtility.MeshIntegrationGroup
+ yield return new UniGLTF.MeshUtility.MeshIntegrationGroup
{
Name = FirstPersonFlag.ThirdPersonOnly.ToString(),
Renderers = g.Renderers.ToList(),
- });
+ };
}
- copy.Add(g);
+ yield return g;
}
}
else
{
- copy.AddRange(MeshIntegrationGroups);
+ foreach (var g in copy)
+ {
+ yield return g;
+ }
}
- return copy;
}
protected override bool
@@ -107,7 +110,19 @@ namespace VRM
{
var animator = target.GetComponent();
var newAvatar = AvatarDescription.RecreateAvatar(animator);
- animator.avatar = newAvatar;
+
+ // ??? clear old avatar ???
+ var t = animator.gameObject;
+ if (Application.isPlaying)
+ {
+ GameObject.Destroy(animator);
+ }
+ else
+ {
+ GameObject.DestroyImmediate(animator);
+ }
+
+ t.AddComponent().avatar = newAvatar;
}
return (list, newList);
@@ -119,12 +134,12 @@ namespace VRM
{
return;
}
- var vrm1 = root.GetComponent();
- if (vrm1 == null)
+ var vrm0 = root.GetComponent();
+ if (vrm0 == null)
{
return;
}
- foreach (var a in vrm1.Renderers)
+ foreach (var a in vrm0.Renderers)
{
var g = _GetOrCreateGroup(a.FirstPersonFlag.ToString());
g.Renderers.Add(a.Renderer);