Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6828 was 6828, checked in by scheusso, 14 years ago

level pointer for the baseobject

  • Property svn:eol-style set to native
File size: 4.8 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#include <OGRE/OgreEntity.h>
32
33#include "core/CoreIncludes.h"
34#include "core/GameMode.h"
35#include "core/XMLPort.h"
36#include "Scene.h"
37
38namespace orxonox
39{
40    CreateFactory(Model);
41
42    Model::Model(BaseObject* creator) : StaticEntity(creator)
43    {
44        RegisterObject(Model);
45
46        this->bCastShadows_ = true;
47
48        this->registerVariables();
49    }
50
51    Model::~Model()
52    {
53        if (this->isInitialized() && this->mesh_.getEntity())
54            this->detachOgreObject(this->mesh_.getEntity());
55    }
56
57    void Model::XMLPort(Element& xmlelement, XMLPort::Mode mode)
58    {
59        SUPER(Model, XMLPort, xmlelement, mode);
60               
61                //LoD
62        XMLPortParam(Model, "lodLevel", setLodLevel, getLodLevel, xmlelement, mode).defaultValues(5);
63               
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    {
70        registerVariable(this->meshSrc_,    VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedMesh));
71        registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedShadows));
72    }
73
74    void Model::changedMesh()
75    {
76        if (GameMode::showsGraphics())
77        {
78            if (this->mesh_.getEntity())
79                this->detachOgreObject(this->mesh_.getEntity());
80           
81            this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
82
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());
88               
89                //LOD
90                if(this->mesh_.getEntity()->getMesh()->getNumLodLevels()==1
91                    &&this->meshSrc_!="laserbeam.mesh"
92                    &&this->lodLevel_!=0)
93                {
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
101                    COUT(0) << this->meshSrc_<< " lodLevel_: " << this->lodLevel_ <<" scale: "<< scaleFactor << std::endl;
102                    //Fuer Asteroiden perfekt
103
104#if OGRE_VERSION >= 0x010700
105                    Ogre::Mesh::LodValueList distList;
106#else
107                    Ogre::Mesh::LodDistanceList distList;
108#endif
109
110                    float factor = scaleFactor;
111                    COUT(0)<<"scaleFactor:"<<scaleFactor<<std::endl;
112
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);
123
124                    float reductionValue = 0.2f;
125
126                   
127                    //Generiert LOD-Levels
128                    this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
129                }
130            }
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}
Note: See TracBrowser for help on using the repository browser.