Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreSubEntity.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreStableHeaders.h"
    00026 #include "OgreSubEntity.h"
    00027
    00028 #include "OgreEntity.h"
    00029 #include "OgreSceneManager.h"
    00030 #include "OgreMaterialManager.h"
    00031 #include "OgreSubMesh.h"
    00032 #include "OgreTagPoint.h"
    00033 #include "OgreLogManager.h"
    00034 #include "OgreMesh.h"
    00035 #include "OgreException.h"
    00036
    00037 namespace Ogre {
    00038     //-----------------------------------------------------------------------
    00039     SubEntity::SubEntity (Entity* parent, SubMesh* subMeshBasis)
    00040         :mParentEntity(parent), mSubMesh(subMeshBasis)
    00041     {
    00042         mpMaterial = static_cast<Material*>(MaterialManager::getSingleton().getByName("BaseWhite"));
    00043         mMaterialLodIndex = 0;
    00044         mRenderDetail = SDL_SOLID;
    00045         mVisible = true;
    00046         mBlendedVertexData = 0;
    00047         mBlendedVertexData = NULL;
    00048
    00049
    00050
    00051     }
    00052     //-----------------------------------------------------------------------
    00053     SubEntity::~SubEntity()
    00054     {
    00055         if (mBlendedVertexData)
    00056             delete mBlendedVertexData;
    00057     }
    00058     //-----------------------------------------------------------------------
    00059     SubMesh* SubEntity::getSubMesh(void)
    00060     {
    00061         return mSubMesh;
    00062     }
    00063     //-----------------------------------------------------------------------
    00064     const String& SubEntity::getMaterialName(void) const
    00065     {
    00066         return mMaterialName;
    00067     }
    00068     //-----------------------------------------------------------------------
    00069     void SubEntity::setMaterialName( const String& name)
    00070     {
    00071
    00072         //String oldName = mMaterialName;
    00073         mMaterialName = name;
    00074         // Update SceneManager re material change
    00075         //mParentEntity->mCreatorSceneManager->_notifyMaterialUsage(oldName, mMaterialName, this);
    00076         mpMaterial = (Material*)MaterialManager::getSingleton().getByName(mMaterialName);
    00077
    00078         if (!mpMaterial)
    00079         {
    00080             LogManager::getSingleton().logMessage("Can't assign material " + name +
    00081                 " to SubEntity of " + mParentEntity->getName() + " because this "
    00082                 "Material does not exist. Have you forgotten to define it in a "
    00083                 ".material script?");
    00084             mpMaterial = (Material*)MaterialManager::getSingleton().getByName("BaseWhite");
    00085             if (!mpMaterial)
    00086             {
    00087                 Except(Exception::ERR_INTERNAL_ERROR, "Can't assign default material "
    00088                     "to SubEntity of " + mParentEntity->getName() + ". Did "
    00089                     "you forget to call MaterialManager::initialise()?",
    00090                     "SubEntity.setMaterialName");
    00091             }
    00092         }
    00093         // Ensure new material loaded (will not load again if already loaded)
    00094         mpMaterial->load();
    00095
    00096         // tell parent to reconsider material vertex processing options
    00097         mParentEntity->reevaluateVertexProcessing();
    00098
    00099
    00100     }
    00101     //-----------------------------------------------------------------------
    00102     Material* SubEntity::getMaterial(void) const
    00103     {
    00104         return mpMaterial;
    00105     }
    00106     //-----------------------------------------------------------------------
    00107     Technique* SubEntity::getTechnique(void) const
    00108     {
    00109         return mpMaterial->getBestTechnique(mMaterialLodIndex);
    00110     }
    00111     //-----------------------------------------------------------------------
    00112     void SubEntity::getRenderOperation(RenderOperation& op)
    00113     {
    00114         // Use LOD
    00115         mSubMesh->_getRenderOperation(op, mParentEntity->mMeshLodIndex);
    00116         // Do we need to use software skinned vertex data?
    00117         if (mParentEntity->hasSkeleton() && !mParentEntity->mHardwareSkinning)
    00118         {
    00119             op.vertexData = mSubMesh->useSharedVertices ?
    00120                 mParentEntity->mSharedBlendedVertexData : mBlendedVertexData;
    00121
    00122         }
    00123     }
    00124     //-----------------------------------------------------------------------
    00125     void SubEntity::getWorldTransforms(Matrix4* xform) const
    00126     {
    00127         if (!mParentEntity->mNumBoneMatrices)
    00128         {
    00129             *xform = mParentEntity->_getParentNodeFullTransform();
    00130         }
    00131         else
    00132         {
    00133             if (!mParentEntity->isHardwareSkinningEnabled())
    00134             {
    00135                 // Software skinning involves pretransforming
    00136                 // No transform required
    00137                 *xform = Matrix4::IDENTITY;
    00138             }
    00139             else
    00140             {
    00141                 // Bones, use cached matrices built when Entity::_updateRenderQueue was called
    00142                 int i;
    00143                 for (i = 0; i < mParentEntity->mNumBoneMatrices; ++i)
    00144                 {
    00145                     *xform = mParentEntity->mBoneMatrices[i];
    00146                     ++xform;
    00147                 }
    00148             }
    00149         }
    00150     }
    00151     //-----------------------------------------------------------------------
    00152     const Quaternion& SubEntity::getWorldOrientation(void) const
    00153     {
    00154         return mParentEntity->mParentNode->_getDerivedOrientation();
    00155     }
    00156     //-----------------------------------------------------------------------
    00157     const Vector3& SubEntity::getWorldPosition(void) const
    00158     {
    00159         return mParentEntity->mParentNode->_getDerivedPosition();
    00160     }
    00161
    00162     //-----------------------------------------------------------------------
    00163     unsigned short SubEntity::getNumWorldTransforms(void) const
    00164     {
    00165         if (!mParentEntity->mNumBoneMatrices ||
    00166             !mParentEntity->isHardwareSkinningEnabled())
    00167         {
    00168             // No skeletal animation, or software skinning (pretransformed)
    00169             return 1;
    00170         }
    00171         else
    00172         {
    00173             // Hardware skinning, pass all matrices
    00174             return mParentEntity->mNumBoneMatrices;
    00175         }
    00176     }
    00177     //-----------------------------------------------------------------------
    00178     Real SubEntity::getSquaredViewDepth(const Camera* cam) const
    00179     {
    00180         Node* n = mParentEntity->getParentNode();
    00181         assert(n);
    00182         return n->getSquaredViewDepth(cam);
    00183     }
    00184     //-----------------------------------------------------------------------
    00185     bool SubEntity::getNormaliseNormals(void) const
    00186     {
    00187         return mParentEntity->mNormaliseNormals;
    00188     }
    00189     //-----------------------------------------------------------------------
    00190     const LightList& SubEntity::getLights(void) const
    00191     {
    00192         SceneNode* n = mParentEntity->getParentSceneNode();
    00193         assert(n);
    00194         return n->findLights(mParentEntity->getBoundingRadius());
    00195     }
    00196     //-----------------------------------------------------------------------
    00197     void SubEntity::setVisible(bool visible)
    00198     {
    00199         mVisible = visible;
    00200     }
    00201     //-----------------------------------------------------------------------
    00202     bool SubEntity::isVisible(void) const
    00203     {
    00204         return mVisible;
    00205
    00206     }
    00207     //-----------------------------------------------------------------------
    00208     void SubEntity::prepareTempBlendBuffers(void)
    00209     {
    00210         if (mBlendedVertexData)
    00211         {
    00212             delete mBlendedVertexData;
    00213             mBlendedVertexData = 0;
    00214         }
    00215         // Clone without copying data
    00216         mBlendedVertexData =
    00217             mParentEntity->cloneVertexDataRemoveBlendInfo(mSubMesh->vertexData);
    00218         mParentEntity->extractTempBufferInfo(mBlendedVertexData, &mTempBlendedBuffer);
    00219     }
    00220     //-----------------------------------------------------------------------
    00221     bool SubEntity::getCastsShadows(void) const
    00222     {
    00223         return mParentEntity->getCastShadows();
    00224     }
    00225
    00226 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:47 2004