00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00045 if(_FatherSkeletonModel)
00046 {
00047
00048
00049 _FatherSkeletonModel->detachSkeletonSon(this);
00050 nlassert(_FatherSkeletonModel==NULL);
00051
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
00083 CMeshBaseInstance::setApplySkin (state);
00084
00085
00086 CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00087
00088
00089 if (state)
00090 {
00091 pMesh->computeBonesId (_FatherSkeletonModel);
00092 }
00093
00094
00095 pMesh->updateSkeletonUsage(_FatherSkeletonModel, state);
00096
00097
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
00112 CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00113
00114 pMesh->changeMRMDistanceSetup(distanceFinest, distanceMiddle, distanceCoarsest);
00115 }
00116 }
00117
00118
00119
00120 const std::vector<sint32> *CMeshMRMInstance::getSkinBoneUsage() const
00121 {
00122
00123 CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00124
00125
00126 pMesh->computeBonesId (_FatherSkeletonModel);
00127
00128
00129 return &pMesh->getMeshGeom().getSkinBoneUsage();
00130 }
00131
00132
00133
00134 bool CMeshMRMInstance::isSkinnable() const
00135 {
00136 if(Shape==NULL)
00137 return false;
00138
00139
00140 CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00141
00142
00143 return pMesh->getMeshGeom().isSkinned();
00144 }
00145
00146
00147
00148 void CMeshMRMInstance::renderSkin(float alphaMRM)
00149 {
00150
00151
00152 if(Shape && getVisibility() != CHrcTrav::Hide)
00153 {
00154
00155 CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00156
00157
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
00191 CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00192
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
00200 CMeshMRM *pMesh = NLMISC::safe_cast<CMeshMRM *>((IShape*)Shape);
00201
00202 CMeshMRMGeom &meshGeom= const_cast<CMeshMRMGeom&>(pMesh->getMeshGeom ());
00203 meshGeom.renderSkinGroupPrimitives(this, baseVertex);
00204 }
00205
00206 }