mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-12 13:34:39 -05:00
blendShapeIndexMap for skip blendShape
This commit is contained in:
parent
6cf415ec5d
commit
656e8256ed
|
|
@ -232,7 +232,7 @@ namespace UniGLTF
|
|||
};
|
||||
}
|
||||
|
||||
public static void ExportMeshes(glTF gltf, int bufferIndex,
|
||||
public static IEnumerable<(Mesh, glTFMesh, Dictionary<int, int>)> ExportMeshes(glTF gltf, int bufferIndex,
|
||||
List<MeshWithRenderer> unityMeshes, List<Material> unityMaterials,
|
||||
bool useSparseAccessorForMorphTarget,
|
||||
bool exportOnlyBlendShapePosition,
|
||||
|
|
@ -248,6 +248,8 @@ namespace UniGLTF
|
|||
x.Renderer.name,
|
||||
mesh, materials, unityMaterials, removeVertexColor);
|
||||
|
||||
var blendShapeIndexMap = new Dictionary<int, int>();
|
||||
int exportBlendShapes = 0;
|
||||
for (int j = 0; j < mesh.blendShapeCount; ++j)
|
||||
{
|
||||
var morphTarget = ExportMorphTarget(gltf, bufferIndex,
|
||||
|
|
@ -255,6 +257,10 @@ namespace UniGLTF
|
|||
useSparseAccessorForMorphTarget,
|
||||
exportOnlyBlendShapePosition);
|
||||
|
||||
// maybe skip
|
||||
|
||||
blendShapeIndexMap.Add(j, exportBlendShapes++);
|
||||
|
||||
//
|
||||
// all primitive has same blendShape
|
||||
//
|
||||
|
|
@ -265,7 +271,7 @@ namespace UniGLTF
|
|||
}
|
||||
}
|
||||
|
||||
gltf.meshes.Add(gltfMesh);
|
||||
yield return (mesh, gltfMesh, blendShapeIndexMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace UniGLTF
|
|||
var go = Selection.activeObject as GameObject;
|
||||
|
||||
if (go.transform.position == Vector3.zero &&
|
||||
go.transform.rotation == Quaternion.identity &&
|
||||
go.transform.rotation == Quaternion.identity &&
|
||||
go.transform.localScale == Vector3.one)
|
||||
{
|
||||
var path = EditorUtility.SaveFilePanel(
|
||||
|
|
@ -91,6 +91,18 @@ namespace UniGLTF
|
|||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mesh毎に、元のBlendShapeIndex => ExportされたBlendShapeIndex の対応を記録する
|
||||
///
|
||||
/// BlendShape が空の場合にスキップするので
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Dictionary<Mesh, Dictionary<int, int>> MeshBlendShapeIndexMap
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Transform> Nodes
|
||||
{
|
||||
get;
|
||||
|
|
@ -261,8 +273,15 @@ namespace UniGLTF
|
|||
return true;
|
||||
})
|
||||
.ToList();
|
||||
MeshExporter.ExportMeshes(gltf, bufferIndex, unityMeshes, Materials, useSparseAccessorForMorphTarget,
|
||||
ExportOnlyBlendShapePosition, removeVertexColor);
|
||||
|
||||
MeshBlendShapeIndexMap = new Dictionary<Mesh, Dictionary<int, int>>();
|
||||
foreach (var (mesh, gltfMesh, blendShapeIndexMap) in MeshExporter.ExportMeshes(
|
||||
gltf, bufferIndex, unityMeshes, Materials, useSparseAccessorForMorphTarget,
|
||||
ExportOnlyBlendShapePosition, removeVertexColor))
|
||||
{
|
||||
gltf.meshes.Add(gltfMesh);
|
||||
MeshBlendShapeIndexMap.Add(mesh, blendShapeIndexMap);
|
||||
}
|
||||
Meshes = unityMeshes.Select(x => x.Mesh).ToList();
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -100,10 +100,9 @@ namespace VRM
|
|||
var avatar = master.BlendShapeAvatar;
|
||||
if (avatar != null)
|
||||
{
|
||||
var meshes = exporter.Meshes;
|
||||
foreach (var x in avatar.Clips)
|
||||
{
|
||||
gltf.extensions.VRM.blendShapeMaster.Add(x, exporter.Copy.transform, meshes);
|
||||
gltf.extensions.VRM.blendShapeMaster.Add(x, exporter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@ namespace VRM
|
|||
public static class glTF_VRMExtensions
|
||||
{
|
||||
[Obsolete("Use Create(root, meshes, binding)")]
|
||||
public static glTF_VRM_BlendShapeBind Cerate(Transform root, List<Mesh> meshes, BlendShapeBinding binding)
|
||||
public static glTF_VRM_BlendShapeBind Cerate(Transform root, BlendShapeBinding binding,
|
||||
gltfExporter exporter)
|
||||
{
|
||||
return Create(root, meshes, binding);
|
||||
return Create(root, binding, exporter);
|
||||
}
|
||||
|
||||
public static glTF_VRM_BlendShapeBind Create(Transform root, List<Mesh> meshes, BlendShapeBinding binding)
|
||||
public static glTF_VRM_BlendShapeBind Create(Transform root, BlendShapeBinding binding,
|
||||
gltfExporter exporter)
|
||||
{
|
||||
var transform = UniGLTF.UnityExtensions.GetFromPath(root.transform, binding.RelativePath);
|
||||
var renderer = transform.GetComponent<SkinnedMeshRenderer>();
|
||||
|
|
@ -24,35 +26,55 @@ namespace VRM
|
|||
return null;
|
||||
}
|
||||
|
||||
if(!renderer.gameObject.activeInHierarchy)
|
||||
if (!renderer.gameObject.activeInHierarchy)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var mesh = renderer.sharedMesh;
|
||||
var meshIndex = meshes.IndexOf(mesh);
|
||||
var meshIndex = exporter.Meshes.IndexOf(mesh);
|
||||
if (meshIndex == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!exporter.MeshBlendShapeIndexMap.TryGetValue(mesh, out Dictionary<int, int> blendShapeIndexMap))
|
||||
{
|
||||
// この Mesh は エクスポートされていない
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!blendShapeIndexMap.TryGetValue(binding.Index, out int blendShapeIndex))
|
||||
{
|
||||
// この blendShape は エクスポートされていない(空だった?)
|
||||
return null;
|
||||
}
|
||||
|
||||
return new glTF_VRM_BlendShapeBind
|
||||
{
|
||||
mesh = meshIndex,
|
||||
index = binding.Index,
|
||||
index = blendShapeIndex,
|
||||
weight = binding.Weight,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="master"></param>
|
||||
/// <param name="clip"></param>
|
||||
/// <param name="transform"></param>
|
||||
/// <param name="meshes"></param>
|
||||
/// <param name="blendShapeIndexMap">エクスポート中にBlendShapeIndexが変わったかもしれない</param>
|
||||
public static void Add(this glTF_VRM_BlendShapeMaster master,
|
||||
BlendShapeClip clip, Transform transform, List<Mesh> meshes)
|
||||
BlendShapeClip clip, gltfExporter exporter)
|
||||
{
|
||||
var list = new List<glTF_VRM_BlendShapeBind>();
|
||||
if (clip.Values != null)
|
||||
{
|
||||
foreach (var value in clip.Values)
|
||||
{
|
||||
var bind = Create(transform, meshes, value);
|
||||
var bind = Create(exporter.Copy.transform, value, exporter);
|
||||
if (bind == null)
|
||||
{
|
||||
// Debug.LogFormat("{0}: skip blendshapebind", clip.name);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user