mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 06:19:47 -05:00
name
This commit is contained in:
parent
b69b3a14d2
commit
735e17dd7a
|
|
@ -6,8 +6,9 @@ namespace UniGLTF.MeshUtility
|
|||
{
|
||||
public class MeshIntegrator
|
||||
{
|
||||
public const string INTEGRATED_MESH_NAME = "MeshesIntegrated";
|
||||
public const string INTEGRATED_MESH_BLENDSHAPE_NAME = "MeshesBlendShapeIntegrated";
|
||||
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)";
|
||||
|
||||
struct SubMesh
|
||||
{
|
||||
|
|
@ -252,34 +253,47 @@ namespace UniGLTF.MeshUtility
|
|||
}
|
||||
mesh.bindposes = BindPoses.ToArray();
|
||||
|
||||
// blendshape
|
||||
switch (onlyBlendShapeRenderers)
|
||||
{
|
||||
case MeshEnumerateOption.OnlyWithBlendShape:
|
||||
{
|
||||
AddBlendShapesToMesh(mesh);
|
||||
mesh.name = INTEGRATED_MESH_BLENDSHAPE_NAME;
|
||||
mesh.name = INTEGRATED_MESH_WITH_BLENDSHAPE_NAME;
|
||||
break;
|
||||
}
|
||||
case MeshEnumerateOption.OnlyWithoutBlendShape:
|
||||
|
||||
case MeshEnumerateOption.All:
|
||||
{
|
||||
mesh.name = INTEGRATED_MESH_NAME;
|
||||
AddBlendShapesToMesh(mesh);
|
||||
mesh.name = INTEGRATED_MESH_ALL_NAME;
|
||||
break;
|
||||
}
|
||||
|
||||
case MeshEnumerateOption.OnlyWithoutBlendShape:
|
||||
{
|
||||
mesh.name = INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// meshName
|
||||
var meshNode = new GameObject();
|
||||
switch (onlyBlendShapeRenderers)
|
||||
{
|
||||
case MeshEnumerateOption.OnlyWithBlendShape:
|
||||
{
|
||||
meshNode.name = "MeshIntegrator(BlendShape)";
|
||||
meshNode.name = INTEGRATED_MESH_WITH_BLENDSHAPE_NAME;
|
||||
break;
|
||||
}
|
||||
case MeshEnumerateOption.OnlyWithoutBlendShape:
|
||||
{
|
||||
meshNode.name = INTEGRATED_MESH_WITHOUT_BLENDSHAPE_NAME;
|
||||
break;
|
||||
}
|
||||
case MeshEnumerateOption.All:
|
||||
{
|
||||
meshNode.name = "MeshIntegrator";
|
||||
meshNode.name = INTEGRATED_MESH_ALL_NAME;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,6 @@ namespace UniGLTF.MeshUtility
|
|||
{
|
||||
const string ASSET_SUFFIX = ".mesh.asset";
|
||||
|
||||
public static string INTEGRATED_MESH_NAME => MeshIntegrator.INTEGRATED_MESH_NAME;
|
||||
public static string INTEGRATED_MESH_BLENDSHAPE_NAME => MeshIntegrator.INTEGRATED_MESH_BLENDSHAPE_NAME;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// go を root としたヒエラルキーから Renderer を集めて、統合された Mesh 作成する
|
||||
/// </summary>
|
||||
|
|
@ -174,14 +170,11 @@ namespace UniGLTF.MeshUtility
|
|||
}
|
||||
foreach (var normalMesh in copy.GetComponentsInChildren<MeshFilter>())
|
||||
{
|
||||
if (normalMesh.sharedMesh.name != MeshIntegratorUtility.INTEGRATED_MESH_NAME)
|
||||
if (normalMesh.gameObject.GetComponent<MeshRenderer>())
|
||||
{
|
||||
if (normalMesh.gameObject.GetComponent<MeshRenderer>())
|
||||
{
|
||||
GameObject.DestroyImmediate(normalMesh.gameObject.GetComponent<MeshRenderer>());
|
||||
}
|
||||
GameObject.DestroyImmediate(normalMesh);
|
||||
GameObject.DestroyImmediate(normalMesh.gameObject.GetComponent<MeshRenderer>());
|
||||
}
|
||||
GameObject.DestroyImmediate(normalMesh);
|
||||
}
|
||||
|
||||
// Add integrated
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UniGLTF;
|
||||
using UniGLTF.MeshUtility;
|
||||
using UnityEditor;
|
||||
|
|
@ -32,14 +33,18 @@ namespace VRM
|
|||
}
|
||||
var dstPath = result.IntegratedRenderer.transform.RelativePathFrom(root.transform);
|
||||
|
||||
// copy
|
||||
// copy modify and write
|
||||
var clipAssetPathList = new List<string>();
|
||||
var sb = new StringBuilder();
|
||||
var clips = new List<BlendShapeClip>();
|
||||
foreach (var src in proxy.BlendShapeAvatar.Clips)
|
||||
{
|
||||
if (src == null) continue;
|
||||
|
||||
// copy
|
||||
var clip = BlendShapeClip.Instantiate(src);
|
||||
clips.Add(clip);
|
||||
|
||||
// modify
|
||||
for (var i = 0; i < clip.Values.Length; ++i)
|
||||
{
|
||||
var val = clip.Values[i];
|
||||
|
|
@ -48,6 +53,10 @@ namespace VRM
|
|||
var srcRenderer = rendererDict[val.RelativePath];
|
||||
var name = srcRenderer.sharedMesh.GetBlendShapeName(val.Index);
|
||||
var newIndex = result.IntegratedRenderer.sharedMesh.GetBlendShapeIndex(name);
|
||||
if (newIndex == -1)
|
||||
{
|
||||
throw new KeyNotFoundException($"blendshape:{name} not found");
|
||||
}
|
||||
|
||||
val.RelativePath = dstPath;
|
||||
val.Index = newIndex;
|
||||
|
|
@ -56,10 +65,19 @@ namespace VRM
|
|||
clip.Values[i] = val;
|
||||
}
|
||||
|
||||
// write
|
||||
var assetPath = $"{assetFolder}/{clip.name}.asset";
|
||||
Debug.Log($"write: {assetPath}");
|
||||
sb.AppendLine($"write: {assetPath}");
|
||||
AssetDatabase.CreateAsset(clip, assetPath);
|
||||
|
||||
clipAssetPathList.Add(assetPath);
|
||||
clips.Add(clip);
|
||||
}
|
||||
Debug.Log(sb.ToString());
|
||||
|
||||
// reload
|
||||
// AssetDatabase.Refresh();
|
||||
// var clips = clipAssetPathList.Select(x => AssetDatabase.LoadAssetAtPath<BlendShapeClip>(x)).ToList();
|
||||
|
||||
{
|
||||
// create blendshape avatar & replace
|
||||
|
|
@ -67,6 +85,12 @@ namespace VRM
|
|||
blendShapeAvatar.Clips.AddRange(clips);
|
||||
var assetPath = $"{assetFolder}/blendshape.asset";
|
||||
AssetDatabase.CreateAsset(blendShapeAvatar, assetPath);
|
||||
|
||||
// reload
|
||||
// AssetDatabase.Refresh();
|
||||
// blendShapeAvatar = AssetDatabase.LoadAssetAtPath<BlendShapeAvatar>(assetPath);
|
||||
|
||||
// assign
|
||||
proxy.BlendShapeAvatar = blendShapeAvatar;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user