Fixed blendShapeCopy before normalize for mesh without boneWeight

This commit is contained in:
ousttrue
2018-08-03 14:55:55 +09:00
parent 5a4488a5e6
commit 6fe746b08d
4 changed files with 98 additions and 4 deletions

View File

@@ -153,7 +153,7 @@ namespace VRM
// Before bake, bind no weight bones
//Debug.LogFormat("no weight: {0}", srcMesh.name);
srcMesh = srcMesh.Copy();
srcMesh = srcMesh.Copy(true);
var bw = new BoneWeight
{
boneIndex0 = 0,
@@ -175,7 +175,7 @@ namespace VRM
}
// BakeMesh
var mesh = srcMesh.Copy();
var mesh = srcMesh.Copy(false);
mesh.name = srcMesh.name + ".baked";
srcRenderer.BakeMesh(mesh);
mesh.boneWeights = srcMesh.boneWeights; // restore weights. clear when BakeMesh
@@ -328,7 +328,7 @@ namespace VRM
// Meshに乗っているボーンの姿勢を適用する
var dstFilter = dst.gameObject.AddComponent<MeshFilter>();
var dstMesh = srcFilter.sharedMesh.Copy();
var dstMesh = srcFilter.sharedMesh.Copy(false);
dstMesh.ApplyRotationAndScale(src.localToWorldMatrix);
dstFilter.sharedMesh = dstMesh;

View File

@@ -6,7 +6,7 @@ namespace VRM
{
public static class MeshExtensions
{
public static Mesh Copy(this Mesh src)
public static Mesh Copy(this Mesh src, bool copyBlendShape)
{
var dst = new Mesh();
dst.name = src.name + "(copy)";
@@ -33,6 +33,24 @@ namespace VRM
dst.RecalculateBounds();
if (copyBlendShape)
{
var vertices = src.vertices;
var normals = src.normals;
var tangents = src.tangents.Select(x => (Vector3)x).ToArray();
for (int i = 0; i < src.blendShapeCount; ++i)
{
src.GetBlendShapeFrameVertices(i, 0, vertices, normals, tangents);
dst.AddBlendShapeFrame(
src.GetBlendShapeName(i),
src.GetBlendShapeFrameWeight(i, 0),
vertices,
normals,
tangents
);
}
}
return dst;
}