# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

mesh_mrm_instance.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std3d.h"
00027 
00028 #include "3d/mesh_mrm_instance.h"
00029 #include "3d/mesh_mrm.h"
00030 #include "3d/skeleton_model.h"
00031 #include "3d/raw_skin.h"
00032 #include "3d/shifted_triangle_cache.h"
00033 
00034 
00035 using namespace NLMISC;
00036 
00037 namespace NL3D 
00038 {
00039 
00040 
00041 // ***************************************************************************
00042 CMeshMRMInstance::~CMeshMRMInstance()
00043 {
00044         // Auto detach me from skeleton. Must do it here, not in ~CTransform().
00045         if(_FatherSkeletonModel)
00046         {
00047                 // detach me from the skeleton.
00048                 // Observers hierarchy is modified.
00049                 _FatherSkeletonModel->detachSkeletonSon(this);
00050                 nlassert(_FatherSkeletonModel==NULL);
00051                 // If skinned, setApplySkin(false) should have been called through detachSkeletonSon()
00052                 nlassert(_RawSkinCache== NULL);
00053                 nlassert(_ShiftedTriangleCache== NULL);
00054         }
00055 }
00056 
00057 
00058 // ***************************************************************************
00059 void            CMeshMRMInstance::registerBasic()
00060 {
00061         CMOT::registerModel(MeshMRMInstanceId, MeshBaseInstanceId, CMeshMRMInstance::creator);
00062 }
00063 
00064 
00065 // ***************************************************************************
00066 void            CMeshMRMInstance::clearRawSkinCache()
00067 {
00068         delete  _RawSkinCache;
00069         _RawSkinCache= NULL;
00070 }
00071 
00072 // ***************************************************************************
00073 void            CMeshMRMInstance::clearShiftedTriangleCache()
00074 {
00075         delete  _ShiftedTriangleCache;
00076         _ShiftedTriangleCache= NULL;
00077 }
00078 
00079 // ***************************************************************************
00080 void            CMeshMRMInstance::setApplySkin(bool state)
00081 {
00082         // Call parents method
00083         CMeshBaseInstance::setApplySkin (state);
00084 
00085         // Get a pointer on the shape
00086         CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00087 
00088         // Recompute the id
00089         if (state)
00090         {
00091                 pMesh->computeBonesId (_FatherSkeletonModel);
00092         }
00093 
00094         // update the skeleton usage according to the mesh.
00095         pMesh->updateSkeletonUsage(_FatherSkeletonModel, state);
00096 
00097         // If unbinded, clean all the cache.
00098         if(state==false)
00099         {
00100                 clearRawSkinCache();
00101                 clearShiftedTriangleCache();
00102         }
00103 }
00104 
00105 
00106 // ***************************************************************************
00107 void            CMeshMRMInstance::changeMRMDistanceSetup(float distanceFinest, float distanceMiddle, float distanceCoarsest)
00108 {
00109         if(Shape)
00110         {
00111                 // Get a pointer on the shape.
00112                 CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00113                 // Affect the mesh directly.
00114                 pMesh->changeMRMDistanceSetup(distanceFinest, distanceMiddle, distanceCoarsest);
00115         }
00116 }
00117 
00118 
00119 // ***************************************************************************
00120 const std::vector<sint32>       *CMeshMRMInstance::getSkinBoneUsage() const
00121 {
00122         // Get a pointer on the shape
00123         CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00124 
00125         // Recompute the id
00126         pMesh->computeBonesId (_FatherSkeletonModel);
00127 
00128         // get ids.
00129         return &pMesh->getMeshGeom().getSkinBoneUsage();
00130 }
00131 
00132 
00133 // ***************************************************************************
00134 bool    CMeshMRMInstance::isSkinnable() const
00135 {
00136         if(Shape==NULL)
00137                 return false;
00138 
00139         // Get a pointer on the shape
00140         CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00141 
00142         // true if the mesh is skinned
00143         return pMesh->getMeshGeom().isSkinned();
00144 }
00145 
00146 
00147 // ***************************************************************************
00148 void    CMeshMRMInstance::renderSkin(float alphaMRM)
00149 {
00150         // Don't setup lighting or matrix in Skin. Done by the skeleton
00151 
00152         if(Shape && getVisibility() != CHrcTrav::Hide)
00153         {
00154                 // Get a pointer on the shape
00155                 CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00156 
00157                 // render the meshGeom
00158                 CMeshMRMGeom    &meshGeom= const_cast<CMeshMRMGeom&>(pMesh->getMeshGeom ());
00159                 meshGeom.renderSkin( this, alphaMRM );
00160         }
00161 }
00162 
00163 
00164 // ***************************************************************************
00165 const   CMRMLevelDetail         *CMeshMRMInstance::getMRMLevelDetail() const
00166 {
00167         if(Shape)
00168         {
00169                 CMeshMRM        *meshMrm= safe_cast<CMeshMRM*>((IShape*)Shape);
00170                 return &meshMrm->getMeshGeom().getLevelDetail();
00171         }
00172         else
00173                 return NULL;
00174 }
00175 
00176 // ***************************************************************************
00177 bool                    CMeshMRMInstance::supportSkinGrouping() const
00178 {
00179         if(Shape)
00180         {
00181                 CMeshMRM        *meshMrm= safe_cast<CMeshMRM*>((IShape*)Shape);
00182                 return  meshMrm->getMeshGeom().supportSkinGrouping();
00183         }
00184         else
00185                 return false;
00186 }
00187 // ***************************************************************************
00188 sint                    CMeshMRMInstance::renderSkinGroupGeom(float alphaMRM, uint remainingVertices, uint8 *dest)
00189 {
00190         // Get a pointer on the shape
00191         CMeshMRM                *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00192         // render the meshGeom
00193         CMeshMRMGeom    &meshGeom= const_cast<CMeshMRMGeom&>(pMesh->getMeshGeom ());
00194         return meshGeom.renderSkinGroupGeom(this, alphaMRM, remainingVertices, dest);
00195 }
00196 // ***************************************************************************
00197 void                    CMeshMRMInstance::renderSkinGroupPrimitives(uint baseVertex)
00198 {
00199         // Get a pointer on the shape
00200         CMeshMRM                *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00201         // render the meshGeom
00202         CMeshMRMGeom    &meshGeom= const_cast<CMeshMRMGeom&>(pMesh->getMeshGeom ());
00203         meshGeom.renderSkinGroupPrimitives(this, baseVertex);
00204 }
00205 
00206 } // NL3D