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 00036 namespace Ogre { 00037 //----------------------------------------------------------------------- 00038 SubEntity::SubEntity (Entity* parent, SubMesh* subMeshBasis) 00039 :mParentEntity(parent), mSubMesh(subMeshBasis) 00040 { 00041 mpMaterial = static_cast<Material*>(MaterialManager::getSingleton().getByName("BaseWhite")); 00042 mMaterialLodIndex = 0; 00043 mRenderDetail = SDL_SOLID; 00044 mVisible = true; 00045 mBlendedVertexData = 0; 00046 mBlendedVertexData = NULL; 00047 00048 00049 00050 } 00051 //----------------------------------------------------------------------- 00052 SubEntity::~SubEntity() 00053 { 00054 if (mBlendedVertexData) 00055 delete mBlendedVertexData; 00056 } 00057 //----------------------------------------------------------------------- 00058 SubMesh* SubEntity::getSubMesh(void) 00059 { 00060 return mSubMesh; 00061 } 00062 //----------------------------------------------------------------------- 00063 const String& SubEntity::getMaterialName(void) const 00064 { 00065 return mMaterialName; 00066 } 00067 //----------------------------------------------------------------------- 00068 void SubEntity::setMaterialName( const String& name) 00069 { 00070 00071 //String oldName = mMaterialName; 00072 mMaterialName = name; 00073 // Update SceneManager re material change 00074 //mParentEntity->mCreatorSceneManager->_notifyMaterialUsage(oldName, mMaterialName, this); 00075 mpMaterial = (Material*)MaterialManager::getSingleton().getByName(mMaterialName); 00076 00077 if (!mpMaterial) 00078 { 00079 LogManager::getSingleton().logMessage("Can't assign material " + name + 00080 " to SubEntity of " + mParentEntity->getName() + " because this " 00081 "Material does not exist. Have you forgotten to define it in a " 00082 ".material script?"); 00083 mpMaterial = (Material*)MaterialManager::getSingleton().getByName("BaseWhite"); 00084 } 00085 // Ensure new material loaded (will not load again if already loaded) 00086 mpMaterial->load(); 00087 00088 // tell parent to reconsider material vertex processing options 00089 mParentEntity->reevaluateVertexProcessing(); 00090 00091 00092 } 00093 //----------------------------------------------------------------------- 00094 Material* SubEntity::getMaterial(void) const 00095 { 00096 return mpMaterial; 00097 } 00098 //----------------------------------------------------------------------- 00099 Technique* SubEntity::getTechnique(void) const 00100 { 00101 return mpMaterial->getBestTechnique(mMaterialLodIndex); 00102 } 00103 //----------------------------------------------------------------------- 00104 void SubEntity::getRenderOperation(RenderOperation& op) 00105 { 00106 // Use LOD 00107 mSubMesh->_getRenderOperation(op, mParentEntity->mMeshLodIndex); 00108 // Do we need to use software skinned vertex data? 00109 if (mParentEntity->hasSkeleton() && !mParentEntity->mHardwareSkinning) 00110 { 00111 op.vertexData = mSubMesh->useSharedVertices ? 00112 mParentEntity->mSharedBlendedVertexData : mBlendedVertexData; 00113 00114 } 00115 } 00116 //----------------------------------------------------------------------- 00117 void SubEntity::getWorldTransforms(Matrix4* xform) const 00118 { 00119 if (!mParentEntity->mNumBoneMatrices) 00120 { 00121 *xform = mParentEntity->_getParentNodeFullTransform(); 00122 } 00123 else 00124 { 00125 // Bones, use cached matrices built when Entity::_updateRenderQueue was called 00126 int i; 00127 for (i = 0; i < mParentEntity->mNumBoneMatrices; ++i) 00128 { 00129 *xform = mParentEntity->mBoneMatrices[i]; 00130 ++xform; 00131 } 00132 } 00133 } 00134 //----------------------------------------------------------------------- 00135 const Quaternion& SubEntity::getWorldOrientation(void) const 00136 { 00137 return mParentEntity->mParentNode->_getDerivedOrientation(); 00138 } 00139 //----------------------------------------------------------------------- 00140 const Vector3& SubEntity::getWorldPosition(void) const 00141 { 00142 return mParentEntity->mParentNode->_getDerivedPosition(); 00143 } 00144 00145 //----------------------------------------------------------------------- 00146 unsigned short SubEntity::getNumWorldTransforms(void) const 00147 { 00148 if (!mParentEntity->mNumBoneMatrices) 00149 return 1; 00150 else 00151 return mParentEntity->mNumBoneMatrices; 00152 } 00153 //----------------------------------------------------------------------- 00154 Real SubEntity::getSquaredViewDepth(const Camera* cam) const 00155 { 00156 Node* n = mParentEntity->getParentNode(); 00157 assert(n); 00158 return n->getSquaredViewDepth(cam); 00159 } 00160 //----------------------------------------------------------------------- 00161 bool SubEntity::getNormaliseNormals(void) const 00162 { 00163 return mParentEntity->mNormaliseNormals; 00164 } 00165 //----------------------------------------------------------------------- 00166 const LightList& SubEntity::getLights(void) const 00167 { 00168 Node* n = mParentEntity->getParentNode(); 00169 assert(n); 00170 return n->getLights(); 00171 } 00172 //----------------------------------------------------------------------- 00173 void SubEntity::setVisible(bool visible) 00174 { 00175 mVisible = visible; 00176 } 00177 //----------------------------------------------------------------------- 00178 bool SubEntity::isVisible(void) const 00179 { 00180 return mVisible; 00181 00182 } 00183 //----------------------------------------------------------------------- 00184 void SubEntity::prepareTempBlendBuffers(void) 00185 { 00186 if (mBlendedVertexData) 00187 { 00188 delete mBlendedVertexData; 00189 mBlendedVertexData = 0; 00190 } 00191 // Clone without copying data 00192 mBlendedVertexData = 00193 mParentEntity->cloneVertexDataRemoveBlendInfo(mSubMesh->vertexData); 00194 mParentEntity->extractTempBufferInfo(mBlendedVertexData, &mTempBlendedBuffer); 00195 } 00196 //----------------------------------------------------------------------- 00197 bool SubEntity::getCastsShadows(void) const 00198 { 00199 return mParentEntity->getCastShadows(); 00200 } 00201 00202 }
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:49 2004