mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-14 23:24:09 -05:00
fix VrmMeshIntegratorWizard.WriteAssets
This commit is contained in:
parent
b5a7c1b13b
commit
fb7cb163b1
|
|
@ -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
|
|||
/// <summary>
|
||||
/// Write Mesh & Prefab
|
||||
/// </summary>
|
||||
protected virtual void WriteAssets(GameObject copy, string assetFolder, List<MeshIntegrationResult> results)
|
||||
protected virtual string WriteAssets(GameObject copy, string assetFolder, List<MeshIntegrationResult> 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)
|
||||
|
|
|
|||
|
|
@ -163,7 +163,12 @@ namespace UniGLTF.MeshUtility
|
|||
}
|
||||
}
|
||||
|
||||
// // 用が済んだ 統合前 の renderer を削除する
|
||||
return (results, newList);
|
||||
}
|
||||
|
||||
public void clear(List<MeshIntegrationResult> 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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -50,30 +50,32 @@ namespace VRM
|
|||
return firstPerson || mod;
|
||||
}
|
||||
|
||||
protected override void WriteAssets(GameObject copy, string assetFolder, List<MeshIntegrationResult> results)
|
||||
protected override string WriteAssets(GameObject target, string assetFolder, List<MeshIntegrationResult> 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<VRMFirstPerson>();
|
||||
// if (firstperson != null)
|
||||
// {
|
||||
// firstperson.Reset();
|
||||
// }
|
||||
if (target.GetComponent<VRMFirstPerson>() is VRMFirstPerson firstperson)
|
||||
{
|
||||
firstperson.Reset();
|
||||
}
|
||||
|
||||
// var prefabReference = AssetDatabase.LoadAssetAtPath<GameObject>(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<GameObject>(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()
|
||||
|
|
|
|||
|
|
@ -12,30 +12,33 @@ namespace VRM
|
|||
bool _generateFirstPerson = false;
|
||||
public override IEnumerable<UniGLTF.MeshUtility.MeshIntegrationGroup> CopyInstantiate(GameObject go, GameObject instance)
|
||||
{
|
||||
var copy = new List<UniGLTF.MeshUtility.MeshIntegrationGroup>();
|
||||
_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<Animator>();
|
||||
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<Animator>().avatar = newAvatar;
|
||||
}
|
||||
|
||||
return (list, newList);
|
||||
|
|
@ -119,12 +134,12 @@ namespace VRM
|
|||
{
|
||||
return;
|
||||
}
|
||||
var vrm1 = root.GetComponent<VRMFirstPerson>();
|
||||
if (vrm1 == null)
|
||||
var vrm0 = root.GetComponent<VRMFirstPerson>();
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user