| 425 | } |
| 426 | |
| 427 | S32 ColladaAppMesh::addMaterial(const char* symbol) |
| 428 | { |
| 429 | if (!symbol) |
| 430 | return TSDrawPrimitive::NoMaterial; |
| 431 | |
| 432 | // Lookup the symbol in the materials already bound to this geometry/controller |
| 433 | // instance |
| 434 | Map<StringTableEntry,U32>::Iterator itr = boundMaterials.find(symbol); |
| 435 | if (itr != boundMaterials.end()) |
| 436 | return itr->value; |
| 437 | |
| 438 | // Find the Collada material that this symbol maps to |
| 439 | U32 matIndex = TSDrawPrimitive::NoMaterial; |
| 440 | const domBind_material* binds = instanceGeom ? instanceGeom->getBind_material() : |
| 441 | instanceCtrl->getBind_material(); |
| 442 | if (binds) { |
| 443 | const domInstance_material_Array& matArray = binds->getTechnique_common()->getInstance_material_array(); |
| 444 | for (S32 iBind = 0; iBind < matArray.getCount(); iBind++) { |
| 445 | if (dStrEqual(matArray[iBind]->getSymbol(), symbol)) { |
| 446 | |
| 447 | // Find the index of the bound material in the shape global list |
| 448 | const domMaterial* mat = daeSafeCast<domMaterial>(matArray[iBind]->getTarget().getElement()); |
| 449 | for (matIndex = 0; matIndex < appMaterials.size(); matIndex++) { |
| 450 | if (static_cast<ColladaAppMaterial*>(appMaterials[matIndex])->mat == mat) |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | // Check if this material needs to be added to the shape global list |
| 455 | if (matIndex == appMaterials.size()) { |
| 456 | if (mat) |
| 457 | appMaterials.push_back(new ColladaAppMaterial(mat)); |
| 458 | else |
| 459 | appMaterials.push_back(new ColladaAppMaterial(symbol)); |
| 460 | } |
| 461 | |
| 462 | break; |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | else |
| 467 | { |
| 468 | // No Collada material is present for this symbol, so just create an empty one |
| 469 | appMaterials.push_back(new ColladaAppMaterial(symbol)); |
| 470 | } |
| 471 | |
| 472 | // Add this symbol to the bound list for the mesh |
| 473 | boundMaterials.insert(StringTable->insert(symbol), matIndex); |
| 474 | return matIndex; |
| 475 | } |
| 476 | |
| 477 | void ColladaAppMesh::getPrimitives(const domGeometry* geometry) |
| 478 | { |
nothing calls this directly
no test coverage detected