fix no weight bone

This commit is contained in:
ousttrue 2023-12-11 13:34:25 +09:00
parent cf4dfb0fdb
commit 2be66df5aa
3 changed files with 17 additions and 6 deletions

View File

@ -73,6 +73,12 @@ namespace UniGLTF.MeshUtility
var r = _renderers[index];
EditorGUI.ObjectField(rect, r, typeof(Renderer), true);
};
// +ボタンが押された時のコールバック
_rendererList.onAddCallback = list => Debug.Log("+ clicked.");
// -ボタンが押された時のコールバック
_rendererList.onRemoveCallback = list => Debug.Log("- clicked : " + list.index + ".");
}
public void UpdateMeshIntegrationList(GameObject root)

View File

@ -85,6 +85,13 @@ namespace UniGLTF.MeshUtility
src.ApplyMatrix(m);
}
public static void ApplyTranslation(this Mesh src, Vector3 p)
{
var m = Matrix4x4.identity;
m.SetColumn(3, new Vector4(p.x, p.y, p.z, 1));
src.ApplyMatrix(m);
}
public static void ApplyMatrix(this Mesh src, Matrix4x4 m)
{
src.vertices = src.vertices.Select(x => m.MultiplyPoint(x)).ToArray();

View File

@ -149,10 +149,7 @@ namespace UniGLTF.MeshUtility
// Before bake, bind no weight bones
srcMesh = srcMesh.Copy(true);
var rootBone = src.rootBone ?? src.transform;
srcMesh.ApplyRotationAndScale(rootBone.localToWorldMatrix, false);
Debug.LogFormat($"apply: {src.transform} {rootBone}");
srcMesh.ApplyRotationAndScale(src.transform.localToWorldMatrix, false);
var bw = new BoneWeight
{
@ -166,8 +163,9 @@ namespace UniGLTF.MeshUtility
weight3 = 0.0f,
};
srcMesh.boneWeights = Enumerable.Range(0, srcMesh.vertexCount).Select(x => bw).ToArray();
src.rootBone = rootBone;
src.bones = new[] { rootBone };
src.bones = new[] { src.rootBone ?? src.transform };
srcMesh.bindposes = src.bones.Select(x => x.worldToLocalMatrix).ToArray();
src.sharedMesh = srcMesh;
}