Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lod/src/orxonox/graphics/Model.cc @ 6838

Last change on this file since 6838 was 6838, checked in by kolibri7, 15 years ago

implemented the XMLPort for additional lod information.

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
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
29#include "Model.h"
30
31// What's this? With the directory in front the filename, my compiler can't find the file...
32//#include <OGRE/OgreEntity.h>
33#include <OgreEntity.h>
34
35#include "core/CoreIncludes.h"
36#include "core/GameMode.h"
37#include "core/XMLPort.h"
38#include "Scene.h"
39#include "graphics/MeshLodInformation.h"
40#include "Level.h"
41
42namespace orxonox
43{
44    CreateFactory(Model);
45
46    Model::Model(BaseObject* creator) : StaticEntity(creator)
47    {
48        RegisterObject(Model);
49
50        this->bCastShadows_ = true;
51
52        this->registerVariables();
53    }
54
55    Model::~Model()
56    {
57        if (this->isInitialized() && this->mesh_.getEntity())
58            this->detachOgreObject(this->mesh_.getEntity());
59    }
60
61    void Model::XMLPort(Element& xmlelement, XMLPort::Mode mode)
62    {
63        SUPER(Model, XMLPort, xmlelement, mode);
64       
65        //LoD
66        XMLPortParam(Model, "lodLevel", setLodLevel, getLodLevel, xmlelement, mode).defaultValues(5);
67       
68        XMLPortParam(Model, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
69        XMLPortParam(Model, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
70    }
71
72    void Model::registerVariables()
73    {
74        registerVariable(this->meshSrc_,    VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedMesh));
75        registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedShadows));
76    }
77
78    void Model::changedMesh()
79    {
80        if (GameMode::showsGraphics())
81        {
82            if (this->mesh_.getEntity())
83                this->detachOgreObject(this->mesh_.getEntity());
84           
85            this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
86
87            if (this->mesh_.getEntity())
88            {
89                this->attachOgreObject(this->mesh_.getEntity());
90                this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
91                this->mesh_.setVisible(this->isVisible());
92               
93                //LOD
94                if(this->mesh_.getEntity()->getMesh()->getNumLodLevels()==1
95                    &&this->meshSrc_!="laserbeam.mesh"
96                    &&this->lodLevel_!=0)
97                {
98                    Vector3 scale3d = this->getScale3D();
99                    float scaleFactor = scale3d.x;
100                    if(scale3d.y>scaleFactor)
101                        scaleFactor = scale3d.y;
102                    if(scale3d.z>scaleFactor)
103                        scaleFactor = scale3d.z;
104                   
105                    Level* level_ = this->getLevel();
106                   
107                    MeshLodInformation* lodInfo = level_->getLodInfo(this->meshSrc_);
108                    if(lodInfo!=0)
109                        setLodLevel(lodInfo->getLodLevel());
110                   
111                    COUT(0) << this->meshSrc_<< " lodLevel_: " << this->lodLevel_ <<" scale: "<< scaleFactor << std::endl;
112                    //Fuer Asteroiden perfekt
113
114#if OGRE_VERSION >= 0x010700
115                    Ogre::Mesh::LodValueList distList;
116#else
117                    Ogre::Mesh::LodDistanceList distList;
118#endif
119
120                    float factor = scaleFactor;
121                    COUT(0)<<"scaleFactor:"<<scaleFactor<<std::endl;
122
123                    distList.push_back(70.0f*factor);
124                    distList.push_back(140.0f*factor);
125                    distList.push_back(170.0f*factor);
126                    distList.push_back(200.0f*factor);
127                    distList.push_back(230.0f*factor);
128                    distList.push_back(250.0f*factor);
129                    distList.push_back(270.0f*factor);
130                    distList.push_back(290.0f*factor);
131                    distList.push_back(310.0f*factor);
132                    distList.push_back(330.0f*factor);
133
134                    float reductionValue = 0.2f;
135
136                   
137                    //Generiert LOD-Levels
138                    this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
139                }
140            }
141        }
142    }
143
144    void Model::changedShadows()
145    {
146        this->mesh_.setCastShadows(this->bCastShadows_);
147    }
148
149    void Model::changedVisibility()
150    {
151        SUPER(Model, changedVisibility);
152
153        this->mesh_.setVisible(this->isVisible());
154    }
155}
Note: See TracBrowser for help on using the repository browser.