------------------------------------------------------------------------------------------------ Add a node to the scenegraph and setup its final transformation
| 407 | // ------------------------------------------------------------------------------------------------ |
| 408 | // Add a node to the scenegraph and setup its final transformation |
| 409 | void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut, D3DS::Node *pcIn, aiMatrix4x4 & /*absTrafo*/) { |
| 410 | std::vector<unsigned int> iArray; |
| 411 | iArray.reserve(3); |
| 412 | |
| 413 | aiMatrix4x4 abs; |
| 414 | |
| 415 | // Find all meshes with the same name as the node |
| 416 | for (unsigned int a = 0; a < pcSOut->mNumMeshes; ++a) { |
| 417 | const auto *pcMesh = (const D3DS::Mesh *)pcSOut->mMeshes[a]->mColors[0]; |
| 418 | ai_assert(nullptr != pcMesh); |
| 419 | |
| 420 | if (pcIn->mName == pcMesh->mName) |
| 421 | iArray.push_back(a); |
| 422 | } |
| 423 | if (!iArray.empty()) { |
| 424 | // The matrix should be identical for all meshes with the |
| 425 | // same name. It HAS to be identical for all meshes ..... |
| 426 | auto *imesh = ((D3DS::Mesh *)pcSOut->mMeshes[iArray[0]]->mColors[0]); |
| 427 | |
| 428 | // Compute the inverse of the transformation matrix to move the |
| 429 | // vertices back to their relative and local space |
| 430 | aiMatrix4x4 mInv = imesh->mMat, mInvTransposed = imesh->mMat; |
| 431 | mInv.Inverse(); |
| 432 | mInvTransposed.Transpose(); |
| 433 | aiVector3D pivot = pcIn->vPivot; |
| 434 | |
| 435 | pcOut->mNumMeshes = static_cast<unsigned int>(iArray.size()); |
| 436 | pcOut->mMeshes = new unsigned int[iArray.size()]; |
| 437 | for (unsigned int i = 0; i < iArray.size(); ++i) { |
| 438 | const unsigned int iIndex = iArray[i]; |
| 439 | aiMesh *const mesh = pcSOut->mMeshes[iIndex]; |
| 440 | |
| 441 | if (mesh->mColors[1] == nullptr) { |
| 442 | // Transform the vertices back into their local space |
| 443 | // fixme: consider computing normals after this, so we don't need to transform them |
| 444 | const aiVector3D *const pvEnd = mesh->mVertices + mesh->mNumVertices; |
| 445 | aiVector3D *pvCurrent = mesh->mVertices, *t2 = mesh->mNormals; |
| 446 | |
| 447 | for (; pvCurrent != pvEnd; ++pvCurrent, ++t2) { |
| 448 | *pvCurrent = mInv * (*pvCurrent); |
| 449 | *t2 = mInvTransposed * (*t2); |
| 450 | } |
| 451 | |
| 452 | // Handle negative transformation matrix determinant -> invert vertex x |
| 453 | if (imesh->mMat.Determinant() < 0.0f) { |
| 454 | // we *must* have normals |
| 455 | for (pvCurrent = mesh->mVertices, t2 = mesh->mNormals; pvCurrent != pvEnd; ++pvCurrent, ++t2) { |
| 456 | pvCurrent->x *= -1.f; |
| 457 | t2->x *= -1.f; |
| 458 | } |
| 459 | ASSIMP_LOG_INFO("3DS: Flipping mesh X-Axis"); |
| 460 | } |
| 461 | |
| 462 | // Handle pivot point |
| 463 | if (pivot.x || pivot.y || pivot.z) { |
| 464 | for (pvCurrent = mesh->mVertices; pvCurrent != pvEnd; ++pvCurrent) { |
| 465 | *pvCurrent -= pivot; |
| 466 | } |
nothing calls this directly
no test coverage detected