| [2072] | 1 | /* |
|---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
|---|
| 3 | * > www.orxonox.net < |
|---|
| 4 | * |
|---|
| 5 | * |
|---|
| 6 | * License notice: |
|---|
| 7 | * |
|---|
| 8 | * This program is free software; you can redistribute it and/or |
|---|
| 9 | * modify it under the terms of the GNU General Public License |
|---|
| 10 | * as published by the Free Software Foundation; either version 2 |
|---|
| 11 | * of the License, or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, |
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | * GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * You should have received a copy of the GNU General Public License |
|---|
| 19 | * along with this program; if not, write to the Free Software |
|---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 21 | * |
|---|
| 22 | * Author: |
|---|
| 23 | * Fabian 'x3n' Landau |
|---|
| 24 | * Co-authors: |
|---|
| 25 | * ... |
|---|
| 26 | * |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| [3196] | 29 | #include "Model.h" |
|---|
| [2072] | 30 | |
|---|
| [2662] | 31 | #include <OgreEntity.h> |
|---|
| [3196] | 32 | |
|---|
| 33 | #include "core/CoreIncludes.h" |
|---|
| [2896] | 34 | #include "core/GameMode.h" |
|---|
| [2072] | 35 | #include "core/XMLPort.h" |
|---|
| [5735] | 36 | #include "Scene.h" |
|---|
| [2072] | 37 | |
|---|
| 38 | namespace orxonox |
|---|
| 39 | { |
|---|
| 40 | CreateFactory(Model); |
|---|
| 41 | |
|---|
| [2662] | 42 | Model::Model(BaseObject* creator) : StaticEntity(creator) |
|---|
| [2072] | 43 | { |
|---|
| 44 | RegisterObject(Model); |
|---|
| 45 | |
|---|
| [2662] | 46 | this->bCastShadows_ = true; |
|---|
| 47 | |
|---|
| [2072] | 48 | this->registerVariables(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | Model::~Model() |
|---|
| 52 | { |
|---|
| 53 | if (this->isInitialized() && this->mesh_.getEntity()) |
|---|
| [2662] | 54 | this->detachOgreObject(this->mesh_.getEntity()); |
|---|
| [2072] | 55 | } |
|---|
| 56 | |
|---|
| 57 | void Model::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
|---|
| 58 | { |
|---|
| 59 | SUPER(Model, XMLPort, xmlelement, mode); |
|---|
| [6691] | 60 | |
|---|
| 61 | //LoD |
|---|
| 62 | XMLPortParam(Model, "lodLevel", setLodLevel, getLodLevel, xmlelement, mode).defaultValues(5); |
|---|
| 63 | |
|---|
| [2072] | 64 | XMLPortParam(Model, "mesh", setMeshSource, getMeshSource, xmlelement, mode); |
|---|
| 65 | XMLPortParam(Model, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | void Model::registerVariables() |
|---|
| 69 | { |
|---|
| [3280] | 70 | registerVariable(this->meshSrc_, VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedMesh)); |
|---|
| 71 | registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedShadows)); |
|---|
| [2072] | 72 | } |
|---|
| 73 | |
|---|
| 74 | void Model::changedMesh() |
|---|
| 75 | { |
|---|
| [2896] | 76 | if (GameMode::showsGraphics()) |
|---|
| [2662] | 77 | { |
|---|
| 78 | if (this->mesh_.getEntity()) |
|---|
| 79 | this->detachOgreObject(this->mesh_.getEntity()); |
|---|
| [6691] | 80 | |
|---|
| [2662] | 81 | this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_); |
|---|
| [2072] | 82 | |
|---|
| [2662] | 83 | if (this->mesh_.getEntity()) |
|---|
| 84 | { |
|---|
| 85 | this->attachOgreObject(this->mesh_.getEntity()); |
|---|
| 86 | this->mesh_.getEntity()->setCastShadows(this->bCastShadows_); |
|---|
| 87 | this->mesh_.setVisible(this->isVisible()); |
|---|
| [6691] | 88 | |
|---|
| 89 | //LOD |
|---|
| 90 | if(this->mesh_.getEntity()->getMesh()->getNumLodLevels()==1 |
|---|
| 91 | &&this->meshSrc_!="laserbeam.mesh" |
|---|
| 92 | &&this->lodLevel_!=0) |
|---|
| 93 | { |
|---|
| [6794] | 94 | Vector3 scale3d = this->getScale3D(); |
|---|
| 95 | float scaleFactor = scale3d.x; |
|---|
| 96 | if(scale3d.y>scaleFactor) |
|---|
| 97 | scaleFactor = scale3d.y; |
|---|
| 98 | if(scale3d.z>scaleFactor) |
|---|
| 99 | scaleFactor = scale3d.z; |
|---|
| 100 | |
|---|
| [6691] | 101 | COUT(0) << this->meshSrc_<< " lodLevel_: " << this->lodLevel_ <<" scale: "<< scaleFactor << std::endl; |
|---|
| 102 | //Für Asteroiden perfekt |
|---|
| 103 | |
|---|
| 104 | #if OGRE_VERSION >= 0x010700 |
|---|
| 105 | Ogre::Mesh::LodValueList distList; |
|---|
| 106 | #else |
|---|
| 107 | Ogre::Mesh::LodDistanceList distList; |
|---|
| 108 | #endif |
|---|
| 109 | |
|---|
| [6794] | 110 | float factor = scaleFactor; |
|---|
| 111 | COUT(0)<<"scaleFactor:"<<scaleFactor<<std::endl; |
|---|
| [6691] | 112 | |
|---|
| [6786] | 113 | distList.push_back(70.0f*factor); |
|---|
| 114 | distList.push_back(140.0f*factor); |
|---|
| 115 | distList.push_back(170.0f*factor); |
|---|
| 116 | distList.push_back(200.0f*factor); |
|---|
| 117 | distList.push_back(230.0f*factor); |
|---|
| 118 | distList.push_back(250.0f*factor); |
|---|
| 119 | distList.push_back(270.0f*factor); |
|---|
| 120 | distList.push_back(290.0f*factor); |
|---|
| 121 | distList.push_back(310.0f*factor); |
|---|
| 122 | distList.push_back(330.0f*factor); |
|---|
| [6691] | 123 | |
|---|
| [6794] | 124 | float reductionValue = 0.2f; |
|---|
| [6786] | 125 | |
|---|
| [6691] | 126 | |
|---|
| 127 | //Generiert LOD-Levels |
|---|
| 128 | this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue); |
|---|
| 129 | } |
|---|
| [2662] | 130 | } |
|---|
| [2072] | 131 | } |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | void Model::changedShadows() |
|---|
| 135 | { |
|---|
| 136 | this->mesh_.setCastShadows(this->bCastShadows_); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | void Model::changedVisibility() |
|---|
| 140 | { |
|---|
| 141 | SUPER(Model, changedVisibility); |
|---|
| 142 | |
|---|
| 143 | this->mesh_.setVisible(this->isVisible()); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|