Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/toonshader/src/orxonox/objects/worldentities/Model.cc @ 5656

Last change on this file since 5656 was 2939, checked in by stefalie, 16 years ago

ugly hacks to get shaders up runnin

  • Property svn:eol-style set to native
File size: 4.0 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 "OrxonoxStableHeaders.h"
30
31#include <OgreEntity.h>
32#include <OgreMaterialManager.h>
33#include "Model.h"
34#include "core/GameMode.h"
35#include "core/CoreIncludes.h"
36#include "core/XMLPort.h"
37#include "objects/Scene.h"
38
39namespace orxonox
40{
41    CreateFactory(Model);
42
43    Model::Model(BaseObject* creator) : StaticEntity(creator)
44    {
45        RegisterObject(Model);
46
47        this->bCastShadows_ = true;
48
49        this->registerVariables();
50    }
51
52    Model::~Model()
53    {
54        if (this->isInitialized() && this->mesh_.getEntity())
55            this->detachOgreObject(this->mesh_.getEntity());
56    }
57
58    void Model::XMLPort(Element& xmlelement, XMLPort::Mode mode)
59    {
60        SUPER(Model, XMLPort, xmlelement, mode);
61
62        XMLPortParam(Model, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
63        XMLPortParam(Model, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
64
65        //HACK
66        if (true)//this->meshSrc_ == "assasdfff.mesh")
67        {
68            this->mesh_.getEntity()->setMaterialName("ToonShader");
69            static bool load = true;
70           
71            if (load)
72            {
73                Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().getByName("ToonShader");
74                if (!matPtr.isNull()) {
75                // is this necessary to do here? Someday try it without
76                    matPtr->compile();
77                    matPtr->load();
78                }
79                else
80                    COUT(0) << "frakking shader\n";
81               
82                COUT(0) << "shiiit\n";
83
84                //Ogre::MaterialManager& mm = Ogre::MaterialManager::getSingleton();
85               //Ogre::Material* m = Ogre::Material*(Ogre::MaterialManager::getSingleton().getByName("ToonShader"));
86                load = false;
87            }
88        }
89    }
90
91    void Model::registerVariables()
92    {
93        registerVariable(this->meshSrc_,    variableDirection::toclient, new NetworkCallback<Model>(this, &Model::changedMesh));
94        registerVariable(this->bCastShadows_, variableDirection::toclient, new NetworkCallback<Model>(this, &Model::changedShadows));
95    }
96
97    void Model::changedMesh()
98    {
99        if (GameMode::showsGraphics())
100        {
101            if (this->mesh_.getEntity())
102                this->detachOgreObject(this->mesh_.getEntity());
103
104            this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
105
106            if (this->mesh_.getEntity())
107            {
108                this->attachOgreObject(this->mesh_.getEntity());
109                this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
110                this->mesh_.setVisible(this->isVisible());
111            }
112        }
113        if (true)//this->meshSrc_ == "assasdfff.mesh")
114        {
115            this->mesh_.getEntity()->setMaterialName("ToonShader");
116        }
117    }
118
119    void Model::changedShadows()
120    {
121        this->mesh_.setCastShadows(this->bCastShadows_);
122    }
123
124    void Model::changedVisibility()
125    {
126        SUPER(Model, changedVisibility);
127
128        this->mesh_.setVisible(this->isVisible());
129    }
130}
Note: See TracBrowser for help on using the repository browser.