| 469 | |
| 470 | |
| 471 | void MaterialLoader::dereference( |
| 472 | const std::shared_ptr<std::map<QString, std::shared_ptr<Material>>>& materialMap, |
| 473 | const std::shared_ptr<Material>& material) |
| 474 | { |
| 475 | // Avoid recursion |
| 476 | if (material->getDereferenced()) { |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | auto parentUUID = material->getParentUUID(); |
| 481 | if (parentUUID.size() > 0) { |
| 482 | std::shared_ptr<Material> parent; |
| 483 | try { |
| 484 | parent = materialMap->at(parentUUID); |
| 485 | } |
| 486 | catch (std::out_of_range&) { |
| 487 | Base::Console().log( |
| 488 | "Unable to apply inheritance for material '%s', parent '%s' not found.\n", |
| 489 | material->getName().toStdString().c_str(), |
| 490 | parentUUID.toStdString().c_str()); |
| 491 | return; |
| 492 | } |
| 493 | |
| 494 | // Ensure the parent has been dereferenced |
| 495 | dereference(materialMap, parent); |
| 496 | |
| 497 | // Add physical models |
| 498 | auto modelVector = parent->getPhysicalModels(); |
| 499 | for (auto& model : *modelVector) { |
| 500 | if (!material->hasPhysicalModel(model)) { |
| 501 | material->addPhysical(model); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | // Add appearance models |
| 506 | modelVector = parent->getAppearanceModels(); |
| 507 | for (auto& model : *modelVector) { |
| 508 | if (!material->hasAppearanceModel(model)) { |
| 509 | material->addAppearance(model); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | // Add values |
| 514 | auto properties = parent->getPhysicalProperties(); |
| 515 | for (auto& itp : properties) { |
| 516 | auto name = itp.first; |
| 517 | auto property = itp.second; |
| 518 | |
| 519 | if (material->getPhysicalProperty(name)->isNull()) { |
| 520 | material->getPhysicalProperty(name)->setValue(property->getValue()); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | properties = parent->getAppearanceProperties(); |
| 525 | for (auto& itp : properties) { |
| 526 | auto name = itp.first; |
| 527 | auto property = itp.second; |
| 528 |
nothing calls this directly
no test coverage detected