Skip to content

Commit

Permalink
reuse joints and weights on import for submeshes
Browse files Browse the repository at this point in the history
  • Loading branch information
pfcDorn committed Oct 24, 2023
1 parent 660161e commit 02f8558
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Runtime/Scripts/SceneExporter/ExporterSkinning.cs
Expand Up @@ -81,6 +81,9 @@ private void ExportSkinFromNode(Transform transform)
Vector4[] bones = boneWeightToBoneVec4(mesh.boneWeights);
Vector4[] weights = boneWeightToWeightVec4(mesh.boneWeights);

AccessorId sharedBones = null;
AccessorId sharedWeights = null;

if(val != null)
{
GLTF.Schema.GLTFMesh gltfMesh = _root.Meshes[val.Id];
Expand All @@ -90,16 +93,28 @@ private void ExportSkinFromNode(Transform transform)
{
if (!prim.Attributes.ContainsKey("JOINTS_0"))
{
var jointsAccessor = ExportAccessorUint(bones);
jointsAccessor.Value.BufferView.Value.Target = BufferViewTarget.ArrayBuffer;
prim.Attributes.Add("JOINTS_0", jointsAccessor);
if (sharedBones != null)
prim.Attributes.Add("JOINTS_0", sharedBones);
else
{
var jointsAccessor = ExportAccessorUint(bones);
jointsAccessor.Value.BufferView.Value.Target = BufferViewTarget.ArrayBuffer;
prim.Attributes.Add("JOINTS_0", jointsAccessor);
sharedBones = jointsAccessor;
}
}

if (!prim.Attributes.ContainsKey("WEIGHTS_0"))
{
var weightsAccessor = ExportAccessor(weights);
weightsAccessor.Value.BufferView.Value.Target = BufferViewTarget.ArrayBuffer;
prim.Attributes.Add("WEIGHTS_0", weightsAccessor);
if (sharedWeights != null)
prim.Attributes.Add("WEIGHTS_0", sharedWeights);
else
{
var weightsAccessor = ExportAccessor(weights);
weightsAccessor.Value.BufferView.Value.Target = BufferViewTarget.ArrayBuffer;
prim.Attributes.Add("WEIGHTS_0", weightsAccessor);
sharedWeights = weightsAccessor;
}
}
}
}
Expand Down

0 comments on commit 02f8558

Please sign in to comment.