| 91 | } |
| 92 | |
| 93 | void ::Vob::setVisual(VobInformation& vob, const std::string& _visual) |
| 94 | { |
| 95 | std::string visual = _visual; |
| 96 | std::transform(visual.begin(), visual.end(), visual.begin(), ::toupper); |
| 97 | |
| 98 | // Don't set twice |
| 99 | if (vob.visual && vob.visual->getName() == visual) |
| 100 | return; |
| 101 | |
| 102 | Logic::VisualController** ppVisual = &vob.world->getComponentAllocator().getElement<Components::VisualComponent>(vob.entity).m_pVisualController; |
| 103 | |
| 104 | // Clear old visual |
| 105 | delete *ppVisual; |
| 106 | |
| 107 | *ppVisual = nullptr; |
| 108 | vob.visual = nullptr; |
| 109 | |
| 110 | // Check type of visual |
| 111 | if (visual.find(".3DS") != std::string::npos || visual.find(".MMB") != std::string::npos || visual.find(".MMS") != std::string::npos || visual.find(".MDMS") != std::string::npos) |
| 112 | { |
| 113 | Logic::VisualController* ld = new Logic::StaticMeshVisual(*vob.world, vob.entity); |
| 114 | if (ld->load(visual)) |
| 115 | (*ppVisual) = ld; |
| 116 | else |
| 117 | delete ld; |
| 118 | } |
| 119 | else if (visual.find(".MDM") != std::string::npos || visual.find(".MDL") != std::string::npos || visual.find(".MDS") != std::string::npos || visual.find(".ASC") != std::string::npos) |
| 120 | { |
| 121 | Logic::VisualController* ld = new Logic::ModelVisual(*vob.world, vob.entity); |
| 122 | if (ld->load(visual)) |
| 123 | { |
| 124 | (*ppVisual) = ld; |
| 125 | } |
| 126 | else |
| 127 | delete ld; |
| 128 | } |
| 129 | else if (visual.find(".PFX") != std::string::npos) |
| 130 | { |
| 131 | Logic::VisualController* ld = new Logic::PfxVisual(*vob.world, vob.entity); |
| 132 | if (ld->load(visual)) |
| 133 | { |
| 134 | (*ppVisual) = ld; |
| 135 | } |
| 136 | else |
| 137 | delete ld; |
| 138 | } |
| 139 | |
| 140 | // Notify the logic controller |
| 141 | if (vob.visual != (*ppVisual)) |
| 142 | { |
| 143 | if (vob.logic) |
| 144 | vob.logic->onVisualChanged(); |
| 145 | } |
| 146 | |
| 147 | vob.visual = (*ppVisual); |
| 148 | } |
| 149 | |
| 150 | void ::Vob::setName(VobInformation& vob, const std::string& name) |