mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-11 21:38:56 -05:00
keep BlendShape normal
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user