diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/SkinningInfo.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/SkinningInfo.cs index 33fae084a..d51054a0c 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/SkinningInfo.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/SkinningInfo.cs @@ -4,15 +4,53 @@ namespace UniGLTF { public JointsAccessor.Getter Joints; public WeightsAccessor.Getter Weights; + public bool AssignBoneWeight { get; private set; } public static SkinningInfo Create(GltfData data, glTFMesh mesh, glTFPrimitives primitives) { + // var hasMorphTarget = HasMorphTarget(mesh); + var hasMorphTarget = false; + var positions = data.GLTF.accessors[primitives.attributes.POSITION]; - return new SkinningInfo + var skinning = new SkinningInfo { Joints = primitives.GetJoints(data, positions.count), Weights = primitives.GetWeights(data, positions.count), }; + + if (skinning.Joints != null) + { + // use SkinnedMeshRenderer + return skinning; + } + else if (!hasMorphTarget) + { + // use MeshRenderer + return skinning; + } + else + { + // use SkinnedMeshRenderer without boneWeight. + // https://github.com/vrm-c/UniVRM/issues/1675 + return new SkinningInfo + { + AssignBoneWeight = true, + Joints = _ => (0, 0, 0, 0), + Weights = _ => (1, 0, 0, 0), // assign weight 1 + }; + } + } + + static bool HasMorphTarget(glTFMesh mesh) + { + foreach (var prim in mesh.primitives) + { + if (prim.targets != null && prim.targets.Count > 0) + { + return true; + } + } + return false; } private static (float x, float y, float z, float w) NormalizeBoneWeight(