Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shader_HS18/src/libraries/tools/Mesh.cc @ 12076

Last change on this file since 12076 was 12076, checked in by wiesep, 3 years ago

Added tangent vector generating

  • Property svn:eol-style set to native
File size: 4.5 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 "Mesh.h"
30
31#include <cassert>
32#include <sstream>
33#include <string>
34#include <OgreEntity.h>
35#include <OgreSubEntity.h>
36#include <OgreSceneManager.h>
37#include <OgreHardwareVertexBuffer.h>
38
39#include "util/Convert.h"
40#include "core/GameMode.h"
41
42namespace orxonox
43{
44    unsigned int Mesh::meshCounter_s = 0;
45
46    Mesh::Mesh()
47    {
48        this->entity_ = nullptr;
49        this->bCastShadows_ = true;
50    }
51
52    Mesh::~Mesh()
53    {
54        if (this->entity_ && this->scenemanager_)
55            this->scenemanager_->destroyEntity(this->entity_);
56    }
57
58    void Mesh::setMeshSource(Ogre::SceneManager* scenemanager, const std::string& meshsource)
59    {
60        assert(scenemanager);
61
62        this->scenemanager_ = scenemanager;
63
64        if (this->entity_)
65            this->scenemanager_->destroyEntity(this->entity_);
66
67   
68        if (GameMode::showsGraphics())
69        {
70            try
71            {
72                this->entity_ = this->scenemanager_->createEntity("Mesh" + multi_cast<std::string>(Mesh::meshCounter_s++), meshsource);
73                this->entity_->setCastShadows(this->bCastShadows_);
74
75               
76                unsigned short src, dest;
77                if (!this->entity_->getMesh()->suggestTangentVectorBuildParams(Ogre::VertexElementSemantic::VES_TANGENT, src, dest))
78                {
79                    orxout() << "Generate Tanget for \"" << meshsource << '"' << endl;
80                    this->entity_->getMesh()->buildTangentVectors(Ogre::VertexElementSemantic::VES_TANGENT, src, dest);
81                    // this version cleans mirrored and rotated UVs but requires quality models
82                    // mesh->buildTangentVectors(VES_TANGENT, src, dest, true, true);
83                }
84
85            }
86            catch (...)
87            {
88                orxout(internal_error) << "Couldn't load mesh \"" << meshsource << '"' << endl;
89                this->entity_ = nullptr;
90            }
91        }
92    }
93
94    void Mesh::setCastShadows(bool bCastShadows)
95    {
96        this->bCastShadows_ = bCastShadows;
97        if (this->entity_)
98            this->entity_->setCastShadows(this->bCastShadows_);
99    }
100
101    const std::string& Mesh::getName() const
102    {
103        if (this->entity_)
104            return this->entity_->getName();
105        else
106            return BLANKSTRING;
107    }
108
109    void Mesh::setMaterial(const std::string& name)
110    {
111        if (this->entity_)
112            this->entity_->setMaterialName(name);
113    }
114
115    // PRE: a valid  Ogre::Entity* entity with a valid subentity at index
116    // POST: changed material of subentity at index to name
117    void Mesh::setSubMaterial(const std::string& name, const int index){
118         if (this->entity_ && this->entity_->getSubEntity(index))
119        {
120                this->entity_->getSubEntity(index)->setMaterialName(name);
121        }
122        else 
123            orxout() << "ERROR at Index " << index << endl;
124    }
125
126    const std::string& Mesh::getMaterial() const
127    {
128        if (this->entity_)
129        {
130            if(this->entity_->getSubEntity(0))
131                return this->entity_->getSubEntity(0)->getMaterialName(); //return the Material of the first SubEntity, should be enough for now
132            else
133                return BLANKSTRING;
134        }
135        else
136            return BLANKSTRING;
137    }
138
139    void Mesh::setVisible(bool bVisible)
140    {
141        if (this->entity_)
142            this->entity_->setVisible(bVisible);
143    }
144
145    bool Mesh::isVisible() const
146    {
147        if (this->entity_)
148            return this->entity_->getVisible();
149        else
150            return false;
151    }
152}
Note: See TracBrowser for help on using the repository browser.