source: OGRE/trunk/ogrenew/OgreMain/src/OgreSubEntity.cpp @ 657

Revision 657, 8.7 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26#include "OgreSubEntity.h"
27
28#include "OgreEntity.h"
29#include "OgreSceneManager.h"
30#include "OgreMaterialManager.h"
31#include "OgreSubMesh.h"
32#include "OgreTagPoint.h"
33#include "OgreLogManager.h"
34#include "OgreMesh.h"
35#include "OgreException.h"
36
37namespace Ogre {
38    //-----------------------------------------------------------------------
39    SubEntity::SubEntity (Entity* parent, SubMesh* subMeshBasis)
40        : Renderable(), mParentEntity(parent), mMaterialName("BaseWhite"),
41                mSubMesh(subMeshBasis)
42    {
43        mpMaterial = MaterialManager::getSingleton().getByName(mMaterialName);
44        mMaterialLodIndex = 0;
45        mRenderDetail = SDL_SOLID;
46        mVisible = true;
47        mBlendedVertexData = 0;
48        mBlendedVertexData = NULL;
49
50
51
52    }
53    //-----------------------------------------------------------------------
54    SubEntity::~SubEntity()
55    {
56        if (mBlendedVertexData)
57            delete mBlendedVertexData;
58    }
59    //-----------------------------------------------------------------------
60    SubMesh* SubEntity::getSubMesh(void)
61    {
62        return mSubMesh;
63    }
64    //-----------------------------------------------------------------------
65    const String& SubEntity::getMaterialName(void) const
66    {
67        return mMaterialName;
68    }
69    //-----------------------------------------------------------------------
70    void SubEntity::setMaterialName( const String& name)
71    {
72
73        //String oldName = mMaterialName;
74        mMaterialName = name;
75        // Update SceneManager re material change
76        //mParentEntity->mCreatorSceneManager->_notifyMaterialUsage(oldName, mMaterialName, this);
77        mpMaterial = MaterialManager::getSingleton().getByName(mMaterialName);
78
79        if (mpMaterial.isNull())
80        {
81            LogManager::getSingleton().logMessage("Can't assign material " + name +
82                " to SubEntity of " + mParentEntity->getName() + " because this "
83                "Material does not exist. Have you forgotten to define it in a "
84                ".material script?");
85            mpMaterial = MaterialManager::getSingleton().getByName("BaseWhite");
86            if (mpMaterial.isNull())
87            {
88                OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Can't assign default material "
89                    "to SubEntity of " + mParentEntity->getName() + ". Did "
90                    "you forget to call MaterialManager::initialise()?",
91                    "SubEntity.setMaterialName");
92            }
93        }
94        // Ensure new material loaded (will not load again if already loaded)
95        mpMaterial->load();
96
97        // tell parent to reconsider material vertex processing options
98        mParentEntity->reevaluateVertexProcessing();
99
100
101    }
102    //-----------------------------------------------------------------------
103    const MaterialPtr& SubEntity::getMaterial(void) const
104    {
105        return mpMaterial;
106    }
107    //-----------------------------------------------------------------------
108    Technique* SubEntity::getTechnique(void) const
109    {
110        return mpMaterial->getBestTechnique(mMaterialLodIndex);
111    }
112    //-----------------------------------------------------------------------
113    void SubEntity::getRenderOperation(RenderOperation& op)
114    {
115                // Use LOD
116        mSubMesh->_getRenderOperation(op, mParentEntity->mMeshLodIndex);
117        // Do we need to use software skinned vertex data?
118        if (mParentEntity->hasSkeleton() && !mParentEntity->mHardwareSkinning)
119        {
120            op.vertexData = mSubMesh->useSharedVertices ?
121                mParentEntity->mSharedBlendedVertexData : mBlendedVertexData;
122
123        }
124    }
125    //-----------------------------------------------------------------------
126    void SubEntity::getWorldTransforms(Matrix4* xform) const
127    {
128        if (!mParentEntity->mNumBoneMatrices)
129        {
130            *xform = mParentEntity->_getParentNodeFullTransform();
131        }
132        else
133        {
134            if (!mParentEntity->isHardwareSkinningEnabled())
135            {
136                // Software skinning involves pretransforming
137                // No transform required
138                *xform = Matrix4::IDENTITY;
139            }
140            else
141            {
142                // Bones, use cached matrices built when Entity::_updateRenderQueue was called
143                int i;
144                for (i = 0; i < mParentEntity->mNumBoneMatrices; ++i)
145                {
146                    *xform = mParentEntity->mBoneMatrices[i];
147                    ++xform;
148                }
149            }
150        }
151    }
152    //-----------------------------------------------------------------------
153    const Quaternion& SubEntity::getWorldOrientation(void) const
154    {
155        return mParentEntity->mParentNode->_getDerivedOrientation();
156    }
157    //-----------------------------------------------------------------------
158    const Vector3& SubEntity::getWorldPosition(void) const
159    {
160        return mParentEntity->mParentNode->_getDerivedPosition();
161    }
162
163    //-----------------------------------------------------------------------
164    unsigned short SubEntity::getNumWorldTransforms(void) const
165    {
166        if (!mParentEntity->mNumBoneMatrices ||
167            !mParentEntity->isHardwareSkinningEnabled())
168        {
169            // No skeletal animation, or software skinning (pretransformed)
170            return 1;
171        }
172        else
173        {
174            // Hardware skinning, pass all matrices
175            return mParentEntity->mNumBoneMatrices;
176        }
177    }
178    //-----------------------------------------------------------------------
179    Real SubEntity::getSquaredViewDepth(const Camera* cam) const
180    {
181        Node* n = mParentEntity->getParentNode();
182        assert(n);
183        return n->getSquaredViewDepth(cam);
184    }
185    //-----------------------------------------------------------------------
186    bool SubEntity::getNormaliseNormals(void) const
187    {
188        return mParentEntity->mNormaliseNormals;
189    }
190    //-----------------------------------------------------------------------
191    const LightList& SubEntity::getLights(void) const
192    {
193        SceneNode* n = mParentEntity->getParentSceneNode();
194        assert(n);
195        return n->findLights(mParentEntity->getBoundingRadius());
196    }
197    //-----------------------------------------------------------------------
198    void SubEntity::setVisible(bool visible)
199    {
200        mVisible = visible;
201    }
202    //-----------------------------------------------------------------------
203    bool SubEntity::isVisible(void) const
204    {
205        return mVisible;
206
207    }
208    //-----------------------------------------------------------------------
209    void SubEntity::prepareTempBlendBuffers(void)
210    {
211        if (mBlendedVertexData)
212        {
213            delete mBlendedVertexData;
214            mBlendedVertexData = 0;
215        }
216                if (!mSubMesh->useSharedVertices)
217                {
218                        // Clone without copying data
219                        mBlendedVertexData =
220                mParentEntity->cloneVertexDataRemoveBlendInfo(
221                                        mSubMesh->vertexData);
222                        mParentEntity->extractTempBufferInfo(
223                                mBlendedVertexData, &mTempBlendedBuffer);
224                }
225    }
226    //-----------------------------------------------------------------------
227    bool SubEntity::getCastsShadows(void) const
228    {
229        return mParentEntity->getCastShadows();
230    }
231        //-----------------------------------------------------------------------
232        const VertexData* SubEntity::_getBlendedVertexData(void) const
233        {
234                assert (mBlendedVertexData && "Not software skinned!");
235                return mBlendedVertexData;
236        }
237
238}
Note: See TracBrowser for help on using the repository browser.