Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mergeFS18/src/libraries/tools/Mesh.cc @ 12206

Last change on this file since 12206 was 12197, checked in by merholzl, 6 years ago

Shader merge

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