MCPcopy Create free account
hub / github.com/assimp/assimp / ImportTriangles

Method ImportTriangles

code/AssetLib/3MF/XmlSerializer.cpp:455–544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455void XmlSerializer::ImportTriangles(XmlNode &node, aiMesh *mesh) {
456 std::vector<aiFace> faces;
457 for (XmlNode &currentNode : node.children()) {
458 const std::string currentName = currentNode.name();
459 if (currentName == XmlTag::triangle) {
460 int pid = IdNotSet;
461 bool hasPid = getNodeAttribute(currentNode, D3MF::XmlTag::pid, pid);
462
463 int pindex[3];
464 aiFace face = ReadTriangle(currentNode, pindex[0], pindex[1], pindex[2]);
465 if (hasPid && (pindex[0] != IdNotSet || pindex[1] != IdNotSet || pindex[2] != IdNotSet)) {
466 auto it = mResourcesDictionnary.find(pid);
467 if (it != mResourcesDictionnary.end()) {
468 if (it->second->getType() == ResourceType::RT_BaseMaterials) {
469 BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
470
471 auto update_material = [&](int idx) {
472 if (pindex[idx] != IdNotSet) {
473 mesh->mMaterialIndex = baseMaterials->mMaterialIndex[pindex[idx]];
474 }
475 };
476
477 update_material(0);
478 update_material(1);
479 update_material(2);
480
481 } else if (it->second->getType() == ResourceType::RT_Texture2DGroup) {
482 // Load texture coordinates into mesh, when any
483 Texture2DGroup *group = static_cast<Texture2DGroup *>(it->second); // fix bug
484 if (mesh->mTextureCoords[0] == nullptr) {
485 mesh->mNumUVComponents[0] = 2;
486 for (unsigned int i = 1; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
487 mesh->mNumUVComponents[i] = 0;
488 }
489
490 const std::string name = ai_to_string(group->mTexId);
491 for (size_t i = 0; i < mMaterials.size(); ++i) {
492 if (name == mMaterials[i]->GetName().C_Str()) {
493 mesh->mMaterialIndex = static_cast<unsigned int>(i);
494 }
495 }
496 mesh->mTextureCoords[0] = new aiVector3D[mesh->mNumVertices];
497 for (unsigned int vertex_index = 0; vertex_index < mesh->mNumVertices; vertex_index++) {
498 mesh->mTextureCoords[0][vertex_index].z = IdNotSet;//mark not set
499 }
500 }
501
502 auto update_texture = [&](int idx) {
503 if (pindex[idx] != IdNotSet) {
504 size_t vertex_index = face.mIndices[idx];
505 mesh->mTextureCoords[0][vertex_index] =
506 aiVector3D(group->mTex2dCoords[pindex[idx]].x, group->mTex2dCoords[pindex[idx]].y, 0.0f);
507 }
508 };
509
510 update_texture(0);
511 update_texture(1);
512 update_texture(2);

Callers

nothing calls this directly

Calls 12

getNodeAttributeFunction · 0.85
ReadTriangleFunction · 0.85
aiVector3DClass · 0.85
childrenMethod · 0.80
C_StrMethod · 0.80
nameMethod · 0.45
endMethod · 0.45
getTypeMethod · 0.45
sizeMethod · 0.45
GetNameMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected