Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / 3d / u_skeleton.cpp
blobe5dd29f4d619ecf18c63faa23a29e976d1b066a3
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "std3d.h"
19 #include "nel/3d/u_skeleton.h"
20 #include "nel/3d/u_instance.h"
21 #include "nel/3d/u_bone.h"
22 #include "nel/3d/play_list_user.h"
23 #include "nel/3d/skeleton_model.h"
24 #include "nel/3d/skeleton_model.h"
25 #include "nel/3d/mesh_base_instance.h"
26 #include "nel/misc/hierarchical_timer.h"
27 #include "nel/3d/scene.h"
28 #include "nel/3d/shape_bank.h"
30 #ifdef DEBUG_NEW
31 #define new DEBUG_NEW
32 #endif
34 namespace NL3D
37 H_AUTO_DECL( NL3D_UI_Skeleton )
39 #define NL3D_HAUTO_UI_SKELETON H_AUTO_USE( NL3D_UI_Skeleton )
41 // ***************************************************************************
43 uint USkeleton::getNumBoneComputed() const
45 NL3D_HAUTO_UI_SKELETON;
47 CSkeletonModel *object = getObjectPtr();
49 return object->getNumBoneComputed();
52 // ***************************************************************************
54 void USkeleton::setInterpolationDistance(float dist)
56 NL3D_HAUTO_UI_SKELETON;
58 CSkeletonModel *object = getObjectPtr();
59 object->setInterpolationDistance(dist);
62 // ***************************************************************************
64 float USkeleton::getInterpolationDistance() const
66 NL3D_HAUTO_UI_SKELETON;
68 CSkeletonModel *object = getObjectPtr();
69 return object->getInterpolationDistance();
72 // ***************************************************************************
74 void USkeleton::setShapeDistMax(float distMax)
76 NL3D_HAUTO_UI_SKELETON;
77 CSkeletonModel *object = getObjectPtr();
79 if(object && object->Shape)
81 object->Shape->setDistMax(distMax);
85 // ***************************************************************************
87 float USkeleton::getShapeDistMax() const
89 NL3D_HAUTO_UI_SKELETON;
90 CSkeletonModel *object = getObjectPtr();
92 if(object && object->Shape)
94 return object->Shape->getDistMax();
96 else
97 return -1;
100 // ***************************************************************************
102 bool USkeleton::bindSkin(UInstance mi)
104 NL3D_HAUTO_UI_SKELETON;
106 if(mi.empty())
108 nlerror("USkeleton::bindSkin(): mi is NULL");
109 return false;
111 CTransform *trans= dynamic_cast<CTransform*>(mi.getObjectPtr());
112 CMeshBaseInstance *meshi= dynamic_cast<CMeshBaseInstance*>(trans);
113 if(meshi==NULL)
115 nlerror("USkeleton::bindSkin(): mi is not a MeshInstance or MeshMRMInstance");
116 return false;
118 CSkeletonModel *object = getObjectPtr();
119 return object->bindSkin(meshi);
122 // ***************************************************************************
124 void USkeleton::stickObject(UTransform mi, uint boneId)
126 NL3D_HAUTO_UI_SKELETON;
127 CSkeletonModel *object = getObjectPtr();
129 if(mi.empty())
130 nlerror("USkeleton::stickObject(): mi is NULL");
131 CTransform *trans= dynamic_cast<CTransform*>(mi.getObjectPtr());
132 object->stickObject(trans, boneId);
135 // ***************************************************************************
137 void USkeleton::stickObjectEx(UTransform mi, uint boneId, bool forceCLod)
139 NL3D_HAUTO_UI_SKELETON;
140 CSkeletonModel *object = getObjectPtr();
142 if(mi.empty())
143 nlerror("USkeleton::stickObject(): mi is NULL");
144 CTransform *trans= dynamic_cast<CTransform*>(mi.getObjectPtr());
145 object->stickObjectEx(trans, boneId, forceCLod);
148 // ***************************************************************************
150 void USkeleton::detachSkeletonSon(UTransform mi)
152 NL3D_HAUTO_UI_SKELETON;
153 CSkeletonModel *object = getObjectPtr();
155 if(mi.empty())
156 nlerror("USkeleton::detachSkeletonSon(): mi is NULL");
157 CTransform *trans= dynamic_cast<CTransform*>(mi.getObjectPtr());
158 object->detachSkeletonSon(trans);
161 // ***************************************************************************
163 uint USkeleton::getNumBones() const
165 NL3D_HAUTO_UI_SKELETON;
166 CSkeletonModel *object = getObjectPtr();
167 return (uint)object->Bones.size();
170 // ***************************************************************************
172 UBone USkeleton::getBone(uint boneId) const
174 NL3D_HAUTO_UI_SKELETON;
175 CSkeletonModel *object = getObjectPtr();
177 if(boneId>=object->Bones.size())
178 nlerror("getBone(): bad boneId");
179 return UBone (&(object->Bones[boneId]));
182 // ***************************************************************************
184 sint USkeleton::getBoneIdByName(const std::string &boneName) const
186 NL3D_HAUTO_UI_SKELETON;
188 CSkeletonModel *object = getObjectPtr();
189 return object->getBoneIdByName(boneName);
192 // ***************************************************************************
194 bool USkeleton::isBoneComputed(uint boneId) const
196 NL3D_HAUTO_UI_SKELETON;
198 CSkeletonModel *object = getObjectPtr();
199 return object->isBoneComputed(boneId);
202 // ***************************************************************************
204 bool USkeleton::forceComputeBone(uint boneId)
206 NL3D_HAUTO_UI_SKELETON;
208 CSkeletonModel *object = getObjectPtr();
209 return object->forceComputeBone(boneId);
212 // ***************************************************************************
214 void USkeleton::setLodCharacterShape(sint shapeId)
216 NL3D_HAUTO_UI_SKELETON;
217 CSkeletonModel *object = getObjectPtr();
218 object->setLodCharacterShape(shapeId);
221 // ***************************************************************************
223 sint USkeleton::getLodCharacterShape() const
225 NL3D_HAUTO_UI_SKELETON;
226 CSkeletonModel *object = getObjectPtr();
227 return object->getLodCharacterShape();
230 // ***************************************************************************
232 void USkeleton::enableLOD(bool isEnable)
234 NL3D_HAUTO_UI_SKELETON;
235 CSkeletonModel *object = getObjectPtr();
236 object->enableLOD(isEnable);
239 // ***************************************************************************
241 void USkeleton::setLodCharacterAnimId(uint animId)
243 NL3D_HAUTO_UI_SKELETON;
244 CSkeletonModel *object = getObjectPtr();
245 object->setLodCharacterAnimId(animId);
248 // ***************************************************************************
250 uint USkeleton::getLodCharacterAnimId() const
252 NL3D_HAUTO_UI_SKELETON;
253 CSkeletonModel *object = getObjectPtr();
254 return object->getLodCharacterAnimId();
257 // ***************************************************************************
259 void USkeleton::setLodCharacterAnimTime(TGlobalAnimationTime time)
261 NL3D_HAUTO_UI_SKELETON;
262 CSkeletonModel *object = getObjectPtr();
263 object->setLodCharacterAnimTime(time);
266 // ***************************************************************************
268 TGlobalAnimationTime USkeleton::getLodCharacterAnimTime() const
270 NL3D_HAUTO_UI_SKELETON;
271 CSkeletonModel *object = getObjectPtr();
272 return object->getLodCharacterAnimTime();
275 // ***************************************************************************
277 bool USkeleton::isDisplayedAsLodCharacter() const
279 NL3D_HAUTO_UI_SKELETON;
280 CSkeletonModel *object = getObjectPtr();
281 return object->isDisplayedAsLodCharacter();
284 // ***************************************************************************
286 void USkeleton::setLodCharacterDistance(float dist)
288 NL3D_HAUTO_UI_SKELETON;
289 CSkeletonModel *object = getObjectPtr();
290 object->setLodCharacterDistance(dist);
293 // ***************************************************************************
295 float USkeleton::getLodCharacterDistance() const
297 NL3D_HAUTO_UI_SKELETON;
298 CSkeletonModel *object = getObjectPtr();
299 return object->getLodCharacterDistance();
302 // ***************************************************************************
304 void USkeleton::setLodCharacterWrapMode(bool wrapMode)
306 NL3D_HAUTO_UI_SKELETON;
307 CSkeletonModel *object = getObjectPtr();
308 object->setLodCharacterWrapMode(wrapMode);
311 // ***************************************************************************
313 bool USkeleton::getLodCharacterWrapMode() const
315 NL3D_HAUTO_UI_SKELETON;
316 CSkeletonModel *object = getObjectPtr();
317 return object->getLodCharacterWrapMode();
320 // ***************************************************************************
322 void USkeleton::changeMRMDistanceSetup(float distanceFinest, float distanceMiddle, float distanceCoarsest)
324 NL3D_HAUTO_UI_SKELETON;
325 CSkeletonModel *object = getObjectPtr();
326 object->changeMRMDistanceSetup(distanceFinest, distanceMiddle, distanceCoarsest);
329 // ***************************************************************************
331 bool USkeleton::computeRenderedBBox(NLMISC::CAABBox &bbox, bool computeInWorld)
333 NL3D_HAUTO_UI_SKELETON;
334 CSkeletonModel *object = getObjectPtr();
335 return object->computeRenderedBBox(bbox, computeInWorld);
338 // ***************************************************************************
339 bool USkeleton::computeRenderedBBoxWithBoneSphere(NLMISC::CAABBox &bbox, bool computeInWorld)
341 NL3D_HAUTO_UI_SKELETON;
342 CSkeletonModel *object = getObjectPtr();
343 return object->computeRenderedBBoxWithBoneSphere(bbox, computeInWorld);
346 // ***************************************************************************
348 bool USkeleton::computeCurrentBBox(NLMISC::CAABBox &bbox, UPlayList *playList, double playTime, bool forceCompute /* = false */, bool computeInWorld)
350 NL3D_HAUTO_UI_SKELETON;
351 CSkeletonModel *object = getObjectPtr();
353 if(playList!=NULL)
355 CPlayListUser *plUser= static_cast<CPlayListUser*>(playList);
356 plUser->evalPlayList(playTime);
359 return object->computeCurrentBBox(bbox, forceCompute, computeInWorld);
362 // ***************************************************************************
364 void USkeleton::computeLodTexture()
366 NL3D_HAUTO_UI_SKELETON;
368 CSkeletonModel *object = getObjectPtr();
369 object->computeLodTexture();
372 // ***************************************************************************
374 void USkeleton::setBoneAnimCtrl(uint boneId, IAnimCtrl *ctrl)
376 NL3D_HAUTO_UI_SKELETON;
378 CSkeletonModel *object = getObjectPtr();
379 object->setBoneAnimCtrl(boneId, ctrl);
382 // ***************************************************************************
384 IAnimCtrl *USkeleton::getBoneAnimCtrl(uint boneId) const
386 NL3D_HAUTO_UI_SKELETON;
388 CSkeletonModel *object = getObjectPtr();
389 return object->getBoneAnimCtrl(boneId);
392 // ***************************************************************************
393 void USkeleton::setSSSWOPos(const NLMISC::CVector &pos)
395 NL3D_HAUTO_UI_SKELETON;
396 CSkeletonModel *object = getObjectPtr();
397 object->setSSSWOPos(pos);
400 // ***************************************************************************
401 const NLMISC::CVector &USkeleton::getSSSWOPos() const
403 NL3D_HAUTO_UI_SKELETON;
404 CSkeletonModel *object = getObjectPtr();
405 return object->getSSSWOPos();
408 // ***************************************************************************
409 void USkeleton::setSSSWODir(const NLMISC::CVector &dir)
411 NL3D_HAUTO_UI_SKELETON;
412 CSkeletonModel *object = getObjectPtr();
413 object->setSSSWODir(dir);
416 // ***************************************************************************
417 const NLMISC::CVector &USkeleton::getSSSWODir() const
419 NL3D_HAUTO_UI_SKELETON;
420 CSkeletonModel *object = getObjectPtr();
421 return object->getSSSWODir();
424 // ***************************************************************************
425 const std::string &USkeleton::getShapeName() const
427 NL3D_HAUTO_UI_SKELETON;
429 static std::string emptyStr;
431 CSkeletonModel *object = getObjectPtr();
432 if(!object)
433 return emptyStr;
435 // get the shape bank
436 CScene *scene= object->getOwnerScene();
437 CShapeBank *sb= scene->getShapeBank();
438 if(!sb)
439 return emptyStr;
441 // get the shape name
442 const std::string *str= sb->getShapeNameFromShapePtr(object->Shape);
443 if(str)
444 return *str;
445 else
446 return emptyStr;
450 // ***************************************************************************
451 void USkeleton::getStickedObjects(std::vector<UTransform> &sticks)
453 NL3D_HAUTO_UI_SKELETON;
455 sticks.clear();
457 CSkeletonModel *sm= getObjectPtr();
458 if(!sm)
459 return;
461 const std::set<CTransform*> &stickSet= sm->getStickedObjects();
462 std::set<CTransform*>::const_iterator it= stickSet.begin();
463 sticks.reserve(stickSet.size());
464 for(;it!=stickSet.end();it++)
466 sticks.push_back(*it);
470 // ***************************************************************************
471 void USkeleton::cast(UTransform object)
473 attach(dynamic_cast<CSkeletonModel*>(object.getObjectPtr()));
476 // ***************************************************************************
477 void USkeleton::setLodEmit(NLMISC::CRGBA emit)
479 getObjectPtr()->setLodEmit(emit);
482 // ***************************************************************************
483 NLMISC::CRGBA USkeleton::getLodEmit() const
485 return getObjectPtr()->getLodEmit();
489 } // NL3D