keep BlendShape normal

This commit is contained in:
ousttrue
2024-06-24 20:26:13 +09:00
parent a0ea3ad2e5
commit b69a58997e
2 changed files with 15 additions and 11 deletions

View File

@@ -168,12 +168,13 @@ namespace UniGLTF.MeshUtility
src.ClearBlendShapes();
foreach (var blendshape in blendshapes)
{
// blendshape の normal, tangent はちゃんと動作しなかった。
// position とロジックが違うのかもしれない。詳細不明。
// 法線に不要な変化が発生し、MToon の outline が乱れたりする。
// 変化しないようにする。
src.AddBlendShapeFrame(blendshape.Name, blendshape.FrameWeight,
blendshape.Vertices, null, null);
blendshape.Vertices,
// 法線は import / export 対象
blendshape.Normals,
// tangent は import / export の扱いが無い
null
);
}
}
}

View File

@@ -143,10 +143,13 @@ namespace UniGLTF.MeshUtility
}
// BakeMesh
var mesh = src.sharedMesh.Copy(false, ".baked");
// TODO: scale に関する第2引数があるが true にすると mesh がつぶれた。どうやって使うのか
var mesh = new Mesh
{
name = src.sharedMesh.name + ".baked"
};
// memo: BakeMesh(mesh, useScale) という第2引数がある
src.BakeMesh(mesh);
CopyBlendShapes(src, mesh);
BakeBlendShapes(src, mesh);
// apply SkinnedMesh.transform rotation
var m = Matrix4x4.TRS(Vector3.zero, src.transform.rotation, Vector3.one);
@@ -183,7 +186,7 @@ namespace UniGLTF.MeshUtility
src.sharedMesh = srcMesh;
}
private static void CopyBlendShapes(SkinnedMeshRenderer src, Mesh mesh)
private static void BakeBlendShapes(SkinnedMeshRenderer src, Mesh mesh)
{
var srcMesh = src.sharedMesh;
@@ -247,7 +250,7 @@ namespace UniGLTF.MeshUtility
Vector3[] normals = blendShapeMesh.normals;
for (int j = 0; j < normals.Length; ++j)
{
normals[j] = normals[j] - meshNormals[j];
normals[j] = normals[j].normalized - meshNormals[j].normalized;
}
Vector3[] tangents = blendShapeMesh.tangents.Select(x => (Vector3)x).ToArray();
@@ -255,7 +258,7 @@ namespace UniGLTF.MeshUtility
{
for (int j = 0; j < tangents.Length; ++j)
{
tangents[j] = tangents[j] - meshTangents[j];
tangents[j] = tangents[j].normalized - meshTangents[j].normalized;
}
}