mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-13 22:09:53 -05:00
BoneWeight の無い SkinndedMeshRenderer への bake transform
This commit is contained in:
parent
6e13c87c00
commit
cf4dfb0fdb
|
|
@ -76,9 +76,12 @@ namespace UniGLTF.MeshUtility
|
|||
return dst;
|
||||
}
|
||||
|
||||
public static void ApplyRotationAndScale(this Mesh src, Matrix4x4 m)
|
||||
public static void ApplyRotationAndScale(this Mesh src, Matrix4x4 m, bool removeTranslation = true)
|
||||
{
|
||||
m.SetColumn(3, new Vector4(0, 0, 0, 1)); // remove translation
|
||||
if (removeTranslation)
|
||||
{
|
||||
m.SetColumn(3, new Vector4(0, 0, 0, 1)); // remove translation
|
||||
}
|
||||
src.ApplyMatrix(m);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -147,9 +147,13 @@ namespace UniGLTF.MeshUtility
|
|||
if (!hasBoneWeight)
|
||||
{
|
||||
// Before bake, bind no weight bones
|
||||
//Debug.LogFormat("no weight: {0}", srcMesh.name);
|
||||
|
||||
srcMesh = srcMesh.Copy(true);
|
||||
var rootBone = src.rootBone ?? src.transform;
|
||||
srcMesh.ApplyRotationAndScale(rootBone.localToWorldMatrix, false);
|
||||
|
||||
Debug.LogFormat($"apply: {src.transform} {rootBone}");
|
||||
|
||||
var bw = new BoneWeight
|
||||
{
|
||||
boneIndex0 = 0,
|
||||
|
|
@ -162,8 +166,8 @@ namespace UniGLTF.MeshUtility
|
|||
weight3 = 0.0f,
|
||||
};
|
||||
srcMesh.boneWeights = Enumerable.Range(0, srcMesh.vertexCount).Select(x => bw).ToArray();
|
||||
src.rootBone = src.transform;
|
||||
src.bones = new[] { src.transform };
|
||||
src.rootBone = rootBone;
|
||||
src.bones = new[] { rootBone };
|
||||
src.sharedMesh = srcMesh;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user