------------------------------------------------------------------------------------------------ Recursively build the scene-graph
| 326 | // ------------------------------------------------------------------------------------------------ |
| 327 | // Recursively build the scene-graph |
| 328 | void LWSImporter::BuildGraph(aiNode *nd, LWS::NodeDesc &src, std::vector<AttachmentInfo> &attach, |
| 329 | BatchLoader &batch, |
| 330 | aiCamera **&camOut, |
| 331 | aiLight **&lightOut, |
| 332 | std::vector<aiNodeAnim *> &animOut) { |
| 333 | // Setup a very cryptic name for the node, we want the user to be happy |
| 334 | SetupNodeName(nd, src); |
| 335 | aiNode *ndAnim = nd; |
| 336 | |
| 337 | // If the node is an object |
| 338 | if (src.type == LWS::NodeDesc::OBJECT) { |
| 339 | |
| 340 | // If the object is from an external file, get it |
| 341 | aiScene *obj = nullptr; |
| 342 | if (src.path.length()) { |
| 343 | obj = batch.GetImport(src.id); |
| 344 | if (!obj) { |
| 345 | ASSIMP_LOG_ERROR("LWS: Failed to read external file ", src.path); |
| 346 | } else { |
| 347 | if (obj->mRootNode->mNumChildren == 1) { |
| 348 | |
| 349 | //If the pivot is not set for this layer, get it from the external object |
| 350 | if (!src.isPivotSet) { |
| 351 | src.pivotPos.x = +obj->mRootNode->mTransformation.a4; |
| 352 | src.pivotPos.y = +obj->mRootNode->mTransformation.b4; |
| 353 | src.pivotPos.z = -obj->mRootNode->mTransformation.c4; //The sign is the RH to LH back conversion |
| 354 | } |
| 355 | |
| 356 | //Remove first node from obj (the old pivot), reset transform of second node (the mesh node) |
| 357 | aiNode *newRootNode = obj->mRootNode->mChildren[0]; |
| 358 | obj->mRootNode->mChildren[0] = nullptr; |
| 359 | delete obj->mRootNode; |
| 360 | |
| 361 | obj->mRootNode = newRootNode; |
| 362 | obj->mRootNode->mTransformation.a4 = 0.0; |
| 363 | obj->mRootNode->mTransformation.b4 = 0.0; |
| 364 | obj->mRootNode->mTransformation.c4 = 0.0; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | //Setup the pivot node (also the animation node), the one we received |
| 370 | nd->mName = std::string("Pivot:") + nd->mName.data; |
| 371 | ndAnim = nd; |
| 372 | |
| 373 | //Add the attachment node to it |
| 374 | nd->mNumChildren = 1; |
| 375 | nd->mChildren = new aiNode *[1]; |
| 376 | nd->mChildren[0] = new aiNode(); |
| 377 | nd->mChildren[0]->mParent = nd; |
| 378 | nd->mChildren[0]->mTransformation.a4 = -src.pivotPos.x; |
| 379 | nd->mChildren[0]->mTransformation.b4 = -src.pivotPos.y; |
| 380 | nd->mChildren[0]->mTransformation.c4 = -src.pivotPos.z; |
| 381 | SetupNodeName(nd->mChildren[0], src); |
| 382 | |
| 383 | //Update the attachment node |
| 384 | nd = nd->mChildren[0]; |
| 385 |
nothing calls this directly
no test coverage detected