mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-15 15:11:43 -05:00
WIP add bone weight
This commit is contained in:
parent
0bcc0a1ed6
commit
03c2c83880
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user