mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-08 20:08:53 -05:00
Fixed blendShapeCopy before normalize for mesh without boneWeight
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user