@@ -142,7 +142,7 @@ bool LLGLTFLoader::parseMeshes()
142
142
143
143
// Populate the joints from skins first.
144
144
// There's not many skins - and you can pretty easily iterate through the nodes from that.
145
- for (auto skin : mGLTFAsset .mSkins )
145
+ for (auto & skin : mGLTFAsset .mSkins )
146
146
{
147
147
populateJointFromSkin (skin);
148
148
}
@@ -164,7 +164,7 @@ bool LLGLTFLoader::parseMeshes()
164
164
coord_system_rotation.initRotation (90 .0f * DEG_TO_RAD, 0 .0f , 0 .0f );
165
165
166
166
// Gather bounds from all meshes
167
- for (auto node : mGLTFAsset .mNodes )
167
+ for (auto & node : mGLTFAsset .mNodes )
168
168
{
169
169
auto meshidx = node.mMesh ;
170
170
if (meshidx >= 0 && meshidx < mGLTFAsset .mMeshes .size ())
@@ -238,7 +238,7 @@ bool LLGLTFLoader::parseMeshes()
238
238
}
239
239
240
240
// Second pass: Process each node with the global scale and offset
241
- for (auto node : mGLTFAsset .mNodes )
241
+ for (auto & node : mGLTFAsset .mNodes )
242
242
{
243
243
LLMatrix4 transformation;
244
244
material_map mats;
@@ -281,7 +281,7 @@ bool LLGLTFLoader::parseMeshes()
281
281
transformation = mesh_scale;
282
282
if (transformation.determinant () < 0 )
283
283
{ // negative scales are not supported
284
- LL_INFOS () << " Negative scale detected, unsupported post-normalization transform. domInstance_geometry: "
284
+ LL_INFOS (" GLTF " ) << " Negative scale detected, unsupported post-normalization transform. domInstance_geometry: "
285
285
<< pModel->mLabel << LL_ENDL;
286
286
LLSD args;
287
287
args[" Message" ] = " NegativeScaleNormTrans" ;
@@ -292,6 +292,60 @@ bool LLGLTFLoader::parseMeshes()
292
292
mScene [transformation].push_back (LLModelInstance (pModel, pModel->mLabel , transformation, mats));
293
293
stretch_extents (pModel, transformation);
294
294
mTransform = saved_transform;
295
+
296
+ S32 skin_index = node.mSkin ;
297
+ if (skin_index >= 0 && mGLTFAsset .mSkins .size () > skin_index)
298
+ {
299
+ LL::GLTF::Skin& gltf_skin = mGLTFAsset .mSkins [skin_index];
300
+ LLMeshSkinInfo& skin_info = pModel->mSkinInfo ;
301
+
302
+ size_t jointCnt = gltf_skin.mJoints .size ();
303
+ if (gltf_skin.mInverseBindMatrices >= 0 && jointCnt != gltf_skin.mInverseBindMatricesData .size ())
304
+ {
305
+ LL_INFOS (" GLTF" ) << " Bind matrices count mismatch joints count" << LL_ENDL;
306
+ LLSD args;
307
+ args[" Message" ] = " InvBindCountMismatch" ;
308
+ mWarningsArray .append (args);
309
+ }
310
+
311
+ for (size_t i = 0 ; i < jointCnt; ++i)
312
+ {
313
+ // Process joint name and idnex
314
+ S32 joint = gltf_skin.mJoints [i];
315
+ LL::GLTF::Node& jointNode = mGLTFAsset .mNodes [joint];
316
+ jointNode.makeMatrixValid ();
317
+
318
+ std::string legal_name (jointNode.mName );
319
+ if (mJointMap .find (legal_name) != mJointMap .end ())
320
+ {
321
+ legal_name = mJointMap [legal_name];
322
+ }
323
+ skin_info.mJointNames .push_back (legal_name);
324
+ skin_info.mJointNums .push_back (-1 );
325
+
326
+ if (i < gltf_skin.mInverseBindMatricesData .size ())
327
+ {
328
+ // Process bind matrix
329
+ LL::GLTF::mat4 gltf_mat = gltf_skin.mInverseBindMatricesData [i];
330
+ LLMatrix4 gltf_transform (glm::value_ptr (gltf_mat));
331
+ skin_info.mInvBindMatrix .push_back (LLMatrix4a (gltf_transform));
332
+
333
+ LL_DEBUGS (" GLTF" ) << " mInvBindMatrix name: " << legal_name << " val: " << gltf_transform << LL_ENDL;
334
+
335
+ // Translate based of mJointList
336
+ gltf_transform.setTranslation (mJointList [legal_name].getTranslation ());
337
+ skin_info.mAlternateBindMatrix .push_back (LLMatrix4a (gltf_transform));
338
+ }
339
+ }
340
+
341
+ // "Bind Shape Matrix" is supposed to transform the geometry of the skinned mesh
342
+ // into the coordinate space of the joints.
343
+ // In GLTF, this matrix is omitted, and it is assumed that this transform is either
344
+ // premultiplied with the mesh data, or postmultiplied to the inverse bind matrices.
345
+ LLMatrix4 bind_shape;
346
+ bind_shape.setIdentity ();
347
+ skin_info.mBindShapeMatrix .loadu (bind_shape);
348
+ }
295
349
}
296
350
else
297
351
{
@@ -560,10 +614,29 @@ void LLGLTFLoader::populateJointFromSkin(const LL::GLTF::Skin& skin)
560
614
for (auto joint : skin.mJoints )
561
615
{
562
616
auto jointNode = mGLTFAsset .mNodes [joint];
617
+
618
+ std::string legal_name (jointNode.mName );
619
+ if (mJointMap .find (legal_name) != mJointMap .end ())
620
+ {
621
+ legal_name = mJointMap [legal_name];
622
+ }
623
+ else
624
+ {
625
+ LL_INFOS (" GLTF" ) << " Rigged to unrecognized joint name : "
626
+ << legal_name << LL_ENDL;
627
+ LLSD args;
628
+ args[" Message" ] = " UnrecognizedJoint" ;
629
+ args[" [NAME]" ] = legal_name;
630
+ mWarningsArray .append (args);
631
+ }
632
+
563
633
jointNode.makeMatrixValid ();
564
634
565
- mJointList [jointNode.mName ] = LLMatrix4 (glm::value_ptr (jointNode.mMatrix ));
566
- mJointsFromNode .push_front (jointNode.mName );
635
+ LLMatrix4 gltf_transform = LLMatrix4 (glm::value_ptr (jointNode.mMatrix ));
636
+ mJointList [legal_name] = gltf_transform;
637
+ mJointsFromNode .push_front (legal_name);
638
+
639
+ LL_DEBUGS (" GLTF" ) << " mJointList name: " << legal_name << " val: " << gltf_transform << LL_ENDL;
567
640
}
568
641
}
569
642
0 commit comments