mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 06:19:47 -05:00
Merge pull request #2 from ousttrue/indexmap_for_removed_blendshape
BlendShapeのindexずれ対策
This commit is contained in:
commit
677f98c2ab
|
|
@ -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,
|
||||
|
|
@ -259,6 +261,10 @@ namespace UniGLTF
|
|||
continue;
|
||||
}
|
||||
|
||||
// maybe skip
|
||||
|
||||
blendShapeIndexMap.Add(j, exportBlendShapes++);
|
||||
|
||||
//
|
||||
// all primitive has same blendShape
|
||||
//
|
||||
|
|
@ -269,7 +275,7 @@ namespace UniGLTF
|
|||
}
|
||||
}
|
||||
|
||||
gltf.meshes.Add(gltfMesh);
|
||||
yield return (mesh, gltfMesh, blendShapeIndexMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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