MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / setNodeVisual

Method setNodeVisual

src/logic/visuals/ModelVisual.cpp:439–503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

437}
438
439Handle::EntityHandle ModelVisual::setNodeVisual(const std::string& visual, const std::string& nodeName)
440{
441 // Register first
442 m_AttachmentVisualsByNode[nodeName] = visual;
443
444 size_t nodeIndex = findNodeIndex(nodeName);
445 if (nodeIndex > getMeshLib().getNodes().size())
446 return Handle::EntityHandle::makeInvalidHandle(); // Invalid node?
447
448 // TODO: Allow to overwrite attachments!
449 //if(!m_VisualAttachments[nodeIndex].empty())
450 // return Handle::EntityHandle::makeInvalidHandle();
451
452 if (visual.empty())
453 {
454 if (m_VisualAttachments[nodeIndex].empty())
455 return Handle::EntityHandle::makeInvalidHandle(); // Nothing to do here
456
457 // Clear whatever there was here
458 for (Handle::EntityHandle e : m_VisualAttachments[nodeIndex])
459 {
460 m_World.removeEntity(e);
461
462 // Remove from attachment list
463 m_PartEntities.dynamicAttachments.erase(
464 std::remove(m_PartEntities.dynamicAttachments.begin(),
465 m_PartEntities.dynamicAttachments.end(),
466 e),
467 m_PartEntities.dynamicAttachments.end());
468 }
469
470 m_VisualAttachments[nodeIndex].clear();
471
472 rebuildMainEntityList();
473
474 return Handle::EntityHandle::makeInvalidHandle();
475 }
476 else
477 {
478 // See these attachments as vob, for simplicities sake
479 Handle::EntityHandle avh = Vob::constructVob(m_World);
480
481 Vob::VobInformation vob = Vob::asVob(m_World, avh);
482
483 // Carry over draw distance-mod // TODO: Should be in some other structure, this is too arbitrary
484 vob.position->m_DrawDistanceFactor = m_World.getEntity<Components::PositionComponent>(m_Entity).m_DrawDistanceFactor;
485
486 Vob::setVisual(vob, visual);
487
488 if (vob.visual)
489 vob.visual->setTransient(true); // Don't export these objects
490
491 // Clear old visual, if there was one
492 setNodeVisual("", nodeName);
493
494 // Only add the main vob, all submeshes etc. will be updated using onTransformChanged()
495 m_VisualAttachments[nodeIndex].push_back(avh);
496 m_PartEntities.dynamicAttachments.push_back(avh);

Callers 1

Calls 9

removeEntityMethod · 0.80
eraseMethod · 0.80
setTransientMethod · 0.80
push_backMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected