1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 /*****************************************************************************\
40 *****************************************************************************
42 ** This file is automatically generated. **
44 ** Any changes made to this file WILL be lost when it is **
45 ** regenerated, which can become necessary at any time. **
47 ** Do not change this file, changes should be done in the derived **
50 *****************************************************************************
51 \*****************************************************************************/
57 #pragma warning(disable: 4355) // turn off 'this' : used in base member initializer list warning
58 #pragma warning(disable: 4290) // disable exception specification warning
61 #include "OSGConfig.h"
65 #include "OSGNode.h" // Roots Class
66 #include "OSGBaseSkeletonJoint.h" // Joints Class
68 #include "OSGSkeletonBase.h"
69 #include "OSGSkeleton.h"
71 #include <boost/bind.hpp>
75 /***************************************************************************\
77 \***************************************************************************/
79 /*! \class OSG::Skeleton
80 A Skeleton is simply one (or multiple) node hierarchies that contain some
82 Traversal will jump to the roots (MFRoots) of these hierarchies and traverse
83 them, updating the matrix for each joint (MFJointMatrices) in the process.
84 A Skeleton assumes exclusive ownership of its joints, but the Skeleton itself
88 /***************************************************************************\
89 * Field Documentation *
90 \***************************************************************************/
92 /*! \var Node * SkeletonBase::_mfRoots
93 The roots of the joint (or bone) hierarchies for the skeleton.
94 There should be Nodes with SkeletonJoint cores in the pointed-to
98 /*! \var BaseSkeletonJoint * SkeletonBase::_mfJoints
99 The joints (or bones) of the skeleton. Sorted by their jointId.
100 READ ONLY: You should never write to this field, Skeleton scans
101 for joints whenever the set of roots is modified.
104 /*! \var BaseSkeletonJoint * SkeletonBase::_mfParentJoints
105 Stores the parent of each joint at the position of the childs jointId.
106 In other words parentJoints[i] is the parent of the joint with
107 jointId i (which is stored in joints[i]). If the joint has no parent
108 NULL is stored instead.
109 READ ONLY: You should never write to this field, Skeleton scans
110 for joints whenever the set of roots is modified.
113 /*! \var Matrix SkeletonBase::_mfJointMatrices
114 Matrices for all joints of the skeleton. Elements correspond to
115 joints at the same index in _mfJoints.
116 These matrices are absolute, not relative to the parent joint.
117 READ ONLY: You should never write to this field, Skeleton updates
118 it during the RenderActions traversal.
121 /*! \var Matrix SkeletonBase::_mfJointNormalMatrices
122 Normal matrices for all joints of the skeleton (these are the inverse
123 transpose of the jointMatrices). Elements correspond to
124 joints at the same index in _mfJoints.
125 These matrices are absolute, not relative to the parent joint.
126 READ ONLY: You should never write to this field, Skeleton updates
127 it during the RenderActions traversal.
130 /*! \var bool SkeletonBase::_sfUseInvBindMatrix
131 Whether joints should use their SFInvBindMatrix when computing
132 the jointMatrices/jointNormalMatrices.
133 This is normally set automatically by a SkinnedGeometry as for
134 debug rendering of the bones this must be false.
137 /*! \var bool SkeletonBase::_sfCalcNormalMatrices
138 Whether jointNormalMatrices should be calculated when computing the
142 /*! \var OSGAny SkeletonBase::_sfJointsChanged
143 Used by the joints to efficiently notify the Skeleton that they have been
144 modified and matrices need to be recalculated.
145 If the trees starting at 'roots' contain for example Transform cores and
146 you modify those without making changes to any SkeletonJoint cores you will
147 have to call editJointsChanged() manually once per frame to force a
148 recomputation of the joint matrices.
152 /***************************************************************************\
153 * FieldType/FieldTrait Instantiation *
154 \***************************************************************************/
156 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
157 PointerType FieldTraits
<Skeleton
*, nsOSG
>::_type(
159 "AttachmentContainerPtr",
160 Skeleton::getClassType(),
164 OSG_FIELDTRAITS_GETTYPE_NS(Skeleton
*, nsOSG
)
166 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField
,
170 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField
,
174 DataType
&FieldTraits
< Skeleton
*, nsOSG
+ 1 >::getType(void)
176 return FieldTraits
<Skeleton
*, nsOSG
>::getType();
180 OSG_EXPORT_PTR_SFIELD(ChildPointerSField
,
182 UnrecordedRefCountPolicy
,
186 OSG_EXPORT_PTR_MFIELD(ChildPointerMField
,
188 UnrecordedRefCountPolicy
,
192 DataType
&FieldTraits
<Skeleton
*, nsOSG
+ 2 >::getType(void)
194 return FieldTraits
<Skeleton
*, nsOSG
>::getType();
198 OSG_SFIELDTYPE_INST(ParentPointerSField
,
203 OSG_FIELD_DLLEXPORT_DEF3(ParentPointerSField
,
209 OSG_MFIELDTYPE_INST(ParentPointerMField
,
214 OSG_FIELD_DLLEXPORT_DEF3(ParentPointerMField
,
220 /***************************************************************************\
221 * Field Description *
222 \***************************************************************************/
224 void SkeletonBase::classDescInserter(TypeObject
&oType
)
226 Inherited::classDescInserter(oType
);
228 FieldDescriptionBase
*pDesc
= NULL
;
231 pDesc
= new MFUnrecNodePtr::Description(
232 MFUnrecNodePtr::getClassType(),
234 "The roots of the joint (or bone) hierarchies for the skeleton.\n"
235 "There should be Nodes with SkeletonJoint cores in the pointed-to\n"
237 RootsFieldId
, RootsFieldMask
,
239 (Field::MFDefaultFlags
| Field::FStdAccess
),
240 static_cast<FieldEditMethodSig
>(&Skeleton::editHandleRoots
),
241 static_cast<FieldGetMethodSig
>(&Skeleton::getHandleRoots
));
243 oType
.addInitialDesc(pDesc
);
245 pDesc
= new MFUnrecChildBaseSkeletonJointPtr::Description(
246 MFUnrecChildBaseSkeletonJointPtr::getClassType(),
248 "The joints (or bones) of the skeleton. Sorted by their jointId.\n"
249 "READ ONLY: You should never write to this field, Skeleton scans\n"
250 "for joints whenever the set of roots is modified.\n",
251 JointsFieldId
, JointsFieldMask
,
253 (Field::MFDefaultFlags
| Field::FStdAccess
),
254 static_cast<FieldEditMethodSig
>(&Skeleton::editHandleJoints
),
255 static_cast<FieldGetMethodSig
>(&Skeleton::getHandleJoints
));
257 oType
.addInitialDesc(pDesc
);
259 pDesc
= new MFUnrecBaseSkeletonJointPtr::Description(
260 MFUnrecBaseSkeletonJointPtr::getClassType(),
262 "Stores the parent of each joint at the position of the childs jointId.\n"
263 "In other words parentJoints[i] is the parent of the joint with\n"
264 "jointId i (which is stored in joints[i]). If the joint has no parent\n"
265 "NULL is stored instead.\n"
266 "READ ONLY: You should never write to this field, Skeleton scans\n"
267 "for joints whenever the set of roots is modified.\n",
268 ParentJointsFieldId
, ParentJointsFieldMask
,
270 (Field::MFDefaultFlags
| Field::FStdAccess
),
271 static_cast<FieldEditMethodSig
>(&Skeleton::editHandleParentJoints
),
272 static_cast<FieldGetMethodSig
>(&Skeleton::getHandleParentJoints
));
274 oType
.addInitialDesc(pDesc
);
276 pDesc
= new MFMatrix::Description(
277 MFMatrix::getClassType(),
279 "Matrices for all joints of the skeleton. Elements correspond to\n"
280 "joints at the same index in _mfJoints.\n"
281 "These matrices are absolute, not relative to the parent joint.\n"
282 "READ ONLY: You should never write to this field, Skeleton updates\n"
283 "it during the RenderActions traversal.\n",
284 JointMatricesFieldId
, JointMatricesFieldMask
,
286 (Field::MFDefaultFlags
| Field::FStdAccess
),
287 static_cast<FieldEditMethodSig
>(&Skeleton::editHandleJointMatrices
),
288 static_cast<FieldGetMethodSig
>(&Skeleton::getHandleJointMatrices
));
290 oType
.addInitialDesc(pDesc
);
292 pDesc
= new MFMatrix::Description(
293 MFMatrix::getClassType(),
294 "jointNormalMatrices",
295 "Normal matrices for all joints of the skeleton (these are the inverse\n"
296 "transpose of the jointMatrices). Elements correspond to\n"
297 "joints at the same index in _mfJoints.\n"
298 "These matrices are absolute, not relative to the parent joint.\n"
299 "READ ONLY: You should never write to this field, Skeleton updates\n"
300 "it during the RenderActions traversal.\n",
301 JointNormalMatricesFieldId
, JointNormalMatricesFieldMask
,
303 (Field::MFDefaultFlags
| Field::FStdAccess
),
304 static_cast<FieldEditMethodSig
>(&Skeleton::editHandleJointNormalMatrices
),
305 static_cast<FieldGetMethodSig
>(&Skeleton::getHandleJointNormalMatrices
));
307 oType
.addInitialDesc(pDesc
);
309 pDesc
= new SFBool::Description(
310 SFBool::getClassType(),
312 "Whether joints should use their SFInvBindMatrix when computing\n"
313 "the jointMatrices/jointNormalMatrices.\n"
314 "This is normally set automatically by a SkinnedGeometry as for\n"
315 "debug rendering of the bones this must be false.\n",
316 UseInvBindMatrixFieldId
, UseInvBindMatrixFieldMask
,
318 (Field::SFDefaultFlags
| Field::FStdAccess
),
319 static_cast<FieldEditMethodSig
>(&Skeleton::editHandleUseInvBindMatrix
),
320 static_cast<FieldGetMethodSig
>(&Skeleton::getHandleUseInvBindMatrix
));
322 oType
.addInitialDesc(pDesc
);
324 pDesc
= new SFBool::Description(
325 SFBool::getClassType(),
326 "calcNormalMatrices",
327 "Whether jointNormalMatrices should be calculated when computing the\n"
329 CalcNormalMatricesFieldId
, CalcNormalMatricesFieldMask
,
331 (Field::SFDefaultFlags
| Field::FStdAccess
),
332 static_cast<FieldEditMethodSig
>(&Skeleton::editHandleCalcNormalMatrices
),
333 static_cast<FieldGetMethodSig
>(&Skeleton::getHandleCalcNormalMatrices
));
335 oType
.addInitialDesc(pDesc
);
337 pDesc
= new SFOSGAny::Description(
338 SFOSGAny::getClassType(),
340 "Used by the joints to efficiently notify the Skeleton that they have been\n"
341 "modified and matrices need to be recalculated.\n"
342 "If the trees starting at 'roots' contain for example Transform cores and\n"
343 "you modify those without making changes to any SkeletonJoint cores you will\n"
344 "have to call editJointsChanged() manually once per frame to force a\n"
345 "recomputation of the joint matrices.\n",
346 JointsChangedFieldId
, JointsChangedFieldMask
,
348 (Field::SFDefaultFlags
| Field::FStdAccess
),
349 static_cast<FieldEditMethodSig
>(&Skeleton::editHandleJointsChanged
),
350 static_cast<FieldGetMethodSig
>(&Skeleton::getHandleJointsChanged
));
352 oType
.addInitialDesc(pDesc
);
356 SkeletonBase::TypeObject
SkeletonBase::_type(
357 SkeletonBase::getClassname(),
358 Inherited::getClassname(),
361 reinterpret_cast<PrototypeCreateF
>(&SkeletonBase::createEmptyLocal
),
362 reinterpret_cast<InitContainerF
>(&Skeleton::initMethod
),
363 reinterpret_cast<ExitContainerF
>(&Skeleton::exitMethod
),
364 reinterpret_cast<InitalInsertDescFunc
>(
365 reinterpret_cast<void *>(&Skeleton::classDescInserter
)),
368 "<?xml version=\"1.0\"?>\n"
371 " name=\"Skeleton\"\n"
372 " parent=\"AttachmentContainer\"\n"
373 " mixinparent=\"SkeletonParent\"\n"
374 " library=\"Dynamics\"\n"
375 " pointerfieldtypes=\"both\"\n"
376 " structure=\"concrete\"\n"
377 " systemcomponent=\"true\"\n"
378 " parentsystemcomponent=\"true\"\n"
379 " decoratable=\"false\"\n"
380 " childFields=\"both\"\n"
381 " parentFields=\"both\"\n"
383 " A Skeleton is simply one (or multiple) node hierarchies that contain some\n"
384 " SkeletonJoint cores.\n"
385 " Traversal will jump to the roots (MFRoots) of these hierarchies and traverse\n"
386 " them, updating the matrix for each joint (MFJointMatrices) in the process.\n"
387 " A Skeleton assumes exclusive ownership of its joints, but the Skeleton itself\n"
393 " category=\"pointer\"\n"
394 " cardinality=\"multi\"\n"
395 " visibility=\"external\"\n"
396 " access=\"public\"\n"
398 " The roots of the joint (or bone) hierarchies for the skeleton.\n"
399 " There should be Nodes with SkeletonJoint cores in the pointed-to\n"
405 " type=\"BaseSkeletonJoint\"\n"
406 " category=\"childpointer\"\n"
407 " linkParentField=\"Skeleton\"\n"
408 " cardinality=\"multi\"\n"
409 " visibility=\"external\"\n"
410 " access=\"public\"\n"
412 " The joints (or bones) of the skeleton. Sorted by their jointId.\n"
413 " READ ONLY: You should never write to this field, Skeleton scans\n"
414 " for joints whenever the set of roots is modified.\n"
418 " name=\"parentJoints\"\n"
419 " type=\"BaseSkeletonJoint\"\n"
420 " category=\"pointer\"\n"
421 " cardinality=\"multi\"\n"
422 " visibility=\"internal\"\n"
423 " access=\"public\"\n"
425 " Stores the parent of each joint at the position of the childs jointId.\n"
426 " In other words parentJoints[i] is the parent of the joint with\n"
427 " jointId i (which is stored in joints[i]). If the joint has no parent\n"
428 " NULL is stored instead.\n"
429 " READ ONLY: You should never write to this field, Skeleton scans\n"
430 " for joints whenever the set of roots is modified.\n"
434 " name=\"jointMatrices\"\n"
436 " category=\"data\"\n"
437 " cardinality=\"multi\"\n"
438 " visibility=\"internal\"\n"
439 " access=\"public\"\n"
441 " Matrices for all joints of the skeleton. Elements correspond to\n"
442 " joints at the same index in _mfJoints.\n"
443 " These matrices are absolute, not relative to the parent joint.\n"
444 " READ ONLY: You should never write to this field, Skeleton updates\n"
445 " it during the RenderActions traversal.\n"
449 " name=\"jointNormalMatrices\"\n"
451 " category=\"data\"\n"
452 " cardinality=\"multi\"\n"
453 " visibility=\"internal\"\n"
454 " access=\"public\"\n"
456 " Normal matrices for all joints of the skeleton (these are the inverse\n"
457 " transpose of the jointMatrices). Elements correspond to\n"
458 " joints at the same index in _mfJoints.\n"
459 " These matrices are absolute, not relative to the parent joint.\n"
460 " READ ONLY: You should never write to this field, Skeleton updates\n"
461 " it during the RenderActions traversal.\n"
465 " name=\"useInvBindMatrix\"\n"
467 " category=\"data\"\n"
468 " cardinality=\"single\"\n"
469 " visibility=\"external\"\n"
470 " access=\"public\"\n"
471 " defaultValue=\"true\"\n"
473 " Whether joints should use their SFInvBindMatrix when computing\n"
474 " the jointMatrices/jointNormalMatrices.\n"
475 " This is normally set automatically by a SkinnedGeometry as for\n"
476 " debug rendering of the bones this must be false.\n"
480 " name=\"calcNormalMatrices\"\n"
482 " category=\"data\"\n"
483 " cardinality=\"single\"\n"
484 " visibility=\"external\"\n"
485 " access=\"public\"\n"
486 " defaultValue=\"false\"\n"
488 " Whether jointNormalMatrices should be calculated when computing the\n"
493 " name=\"jointsChanged\"\n"
495 " category=\"data\"\n"
496 " cardinality=\"single\"\n"
497 " visibility=\"internal\"\n"
498 " access=\"public\"\n"
500 " Used by the joints to efficiently notify the Skeleton that they have been\n"
501 " modified and matrices need to be recalculated.\n"
502 " If the trees starting at 'roots' contain for example Transform cores and\n"
503 " you modify those without making changes to any SkeletonJoint cores you will\n"
504 " have to call editJointsChanged() manually once per frame to force a\n"
505 " recomputation of the joint matrices.\n"
508 "</FieldContainer>\n",
509 "A Skeleton is simply one (or multiple) node hierarchies that contain some\n"
510 "SkeletonJoint cores.\n"
511 "Traversal will jump to the roots (MFRoots) of these hierarchies and traverse\n"
512 "them, updating the matrix for each joint (MFJointMatrices) in the process.\n"
513 "A Skeleton assumes exclusive ownership of its joints, but the Skeleton itself\n"
517 /*------------------------------ get -----------------------------------*/
519 FieldContainerType
&SkeletonBase::getType(void)
524 const FieldContainerType
&SkeletonBase::getType(void) const
529 UInt32
SkeletonBase::getContainerSize(void) const
531 return sizeof(Skeleton
);
534 /*------------------------- decorator get ------------------------------*/
537 //! Get the Skeleton::_mfRoots field.
538 const MFUnrecNodePtr
*SkeletonBase::getMFRoots(void) const
543 MFUnrecNodePtr
*SkeletonBase::editMFRoots (void)
545 editMField(RootsFieldMask
, _mfRoots
);
549 Node
* SkeletonBase::getRoots(const UInt32 index
) const
551 return _mfRoots
[index
];
554 //! Get the Skeleton::_mfJoints field.
555 const MFUnrecChildBaseSkeletonJointPtr
*SkeletonBase::getMFJoints(void) const
560 MFUnrecChildBaseSkeletonJointPtr
*SkeletonBase::editMFJoints (void)
562 editMField(JointsFieldMask
, _mfJoints
);
566 BaseSkeletonJoint
* SkeletonBase::getJoints(const UInt32 index
) const
568 return _mfJoints
[index
];
571 //! Get the Skeleton::_mfParentJoints field.
572 const MFUnrecBaseSkeletonJointPtr
*SkeletonBase::getMFParentJoints(void) const
574 return &_mfParentJoints
;
577 MFUnrecBaseSkeletonJointPtr
*SkeletonBase::editMFParentJoints (void)
579 editMField(ParentJointsFieldMask
, _mfParentJoints
);
581 return &_mfParentJoints
;
583 BaseSkeletonJoint
* SkeletonBase::getParentJoints(const UInt32 index
) const
585 return _mfParentJoints
[index
];
588 MFMatrix
*SkeletonBase::editMFJointMatrices(void)
590 editMField(JointMatricesFieldMask
, _mfJointMatrices
);
592 return &_mfJointMatrices
;
595 const MFMatrix
*SkeletonBase::getMFJointMatrices(void) const
597 return &_mfJointMatrices
;
601 MFMatrix
*SkeletonBase::editMFJointNormalMatrices(void)
603 editMField(JointNormalMatricesFieldMask
, _mfJointNormalMatrices
);
605 return &_mfJointNormalMatrices
;
608 const MFMatrix
*SkeletonBase::getMFJointNormalMatrices(void) const
610 return &_mfJointNormalMatrices
;
614 SFBool
*SkeletonBase::editSFUseInvBindMatrix(void)
616 editSField(UseInvBindMatrixFieldMask
);
618 return &_sfUseInvBindMatrix
;
621 const SFBool
*SkeletonBase::getSFUseInvBindMatrix(void) const
623 return &_sfUseInvBindMatrix
;
627 SFBool
*SkeletonBase::editSFCalcNormalMatrices(void)
629 editSField(CalcNormalMatricesFieldMask
);
631 return &_sfCalcNormalMatrices
;
634 const SFBool
*SkeletonBase::getSFCalcNormalMatrices(void) const
636 return &_sfCalcNormalMatrices
;
640 SFOSGAny
*SkeletonBase::editSFJointsChanged(void)
642 editSField(JointsChangedFieldMask
);
644 return &_sfJointsChanged
;
647 const SFOSGAny
*SkeletonBase::getSFJointsChanged(void) const
649 return &_sfJointsChanged
;
655 void SkeletonBase::pushToRoots(Node
* const value
)
657 editMField(RootsFieldMask
, _mfRoots
);
659 _mfRoots
.push_back(value
);
662 void SkeletonBase::assignRoots (const MFUnrecNodePtr
&value
)
664 MFUnrecNodePtr ::const_iterator elemIt
=
666 MFUnrecNodePtr ::const_iterator elemEnd
=
669 static_cast<Skeleton
*>(this)->clearRoots();
671 while(elemIt
!= elemEnd
)
673 this->pushToRoots(*elemIt
);
679 void SkeletonBase::removeFromRoots(UInt32 uiIndex
)
681 if(uiIndex
< _mfRoots
.size())
683 editMField(RootsFieldMask
, _mfRoots
);
685 _mfRoots
.erase(uiIndex
);
689 void SkeletonBase::removeObjFromRoots(Node
* const value
)
691 Int32 iElemIdx
= _mfRoots
.findIndex(value
);
695 editMField(RootsFieldMask
, _mfRoots
);
697 _mfRoots
.erase(iElemIdx
);
700 void SkeletonBase::clearRoots(void)
702 editMField(RootsFieldMask
, _mfRoots
);
708 void SkeletonBase::pushToJoints(BaseSkeletonJoint
* const value
)
710 editMField(JointsFieldMask
, _mfJoints
);
712 _mfJoints
.push_back(value
);
715 void SkeletonBase::assignJoints (const MFUnrecChildBaseSkeletonJointPtr
&value
)
717 MFUnrecChildBaseSkeletonJointPtr::const_iterator elemIt
=
719 MFUnrecChildBaseSkeletonJointPtr::const_iterator elemEnd
=
722 static_cast<Skeleton
*>(this)->clearJoints();
724 while(elemIt
!= elemEnd
)
726 this->pushToJoints(*elemIt
);
732 void SkeletonBase::removeFromJoints(UInt32 uiIndex
)
734 if(uiIndex
< _mfJoints
.size())
736 editMField(JointsFieldMask
, _mfJoints
);
738 _mfJoints
.erase(uiIndex
);
742 void SkeletonBase::removeObjFromJoints(BaseSkeletonJoint
* const value
)
744 Int32 iElemIdx
= _mfJoints
.findIndex(value
);
748 editMField(JointsFieldMask
, _mfJoints
);
750 _mfJoints
.erase(iElemIdx
);
753 void SkeletonBase::clearJoints(void)
755 editMField(JointsFieldMask
, _mfJoints
);
761 void SkeletonBase::pushToParentJoints(BaseSkeletonJoint
* const value
)
763 editMField(ParentJointsFieldMask
, _mfParentJoints
);
765 _mfParentJoints
.push_back(value
);
768 void SkeletonBase::assignParentJoints(const MFUnrecBaseSkeletonJointPtr
&value
)
770 MFUnrecBaseSkeletonJointPtr::const_iterator elemIt
=
772 MFUnrecBaseSkeletonJointPtr::const_iterator elemEnd
=
775 static_cast<Skeleton
*>(this)->clearParentJoints();
777 while(elemIt
!= elemEnd
)
779 this->pushToParentJoints(*elemIt
);
785 void SkeletonBase::removeFromParentJoints(UInt32 uiIndex
)
787 if(uiIndex
< _mfParentJoints
.size())
789 editMField(ParentJointsFieldMask
, _mfParentJoints
);
791 _mfParentJoints
.erase(uiIndex
);
795 void SkeletonBase::removeObjFromParentJoints(BaseSkeletonJoint
* const value
)
797 Int32 iElemIdx
= _mfParentJoints
.findIndex(value
);
801 editMField(ParentJointsFieldMask
, _mfParentJoints
);
803 _mfParentJoints
.erase(iElemIdx
);
806 void SkeletonBase::clearParentJoints(void)
808 editMField(ParentJointsFieldMask
, _mfParentJoints
);
811 _mfParentJoints
.clear();
816 /*------------------------------ access -----------------------------------*/
818 SizeT
SkeletonBase::getBinSize(ConstFieldMaskArg whichField
)
820 SizeT returnValue
= Inherited::getBinSize(whichField
);
822 if(FieldBits::NoField
!= (RootsFieldMask
& whichField
))
824 returnValue
+= _mfRoots
.getBinSize();
826 if(FieldBits::NoField
!= (JointsFieldMask
& whichField
))
828 returnValue
+= _mfJoints
.getBinSize();
830 if(FieldBits::NoField
!= (ParentJointsFieldMask
& whichField
))
832 returnValue
+= _mfParentJoints
.getBinSize();
834 if(FieldBits::NoField
!= (JointMatricesFieldMask
& whichField
))
836 returnValue
+= _mfJointMatrices
.getBinSize();
838 if(FieldBits::NoField
!= (JointNormalMatricesFieldMask
& whichField
))
840 returnValue
+= _mfJointNormalMatrices
.getBinSize();
842 if(FieldBits::NoField
!= (UseInvBindMatrixFieldMask
& whichField
))
844 returnValue
+= _sfUseInvBindMatrix
.getBinSize();
846 if(FieldBits::NoField
!= (CalcNormalMatricesFieldMask
& whichField
))
848 returnValue
+= _sfCalcNormalMatrices
.getBinSize();
850 if(FieldBits::NoField
!= (JointsChangedFieldMask
& whichField
))
852 returnValue
+= _sfJointsChanged
.getBinSize();
858 void SkeletonBase::copyToBin(BinaryDataHandler
&pMem
,
859 ConstFieldMaskArg whichField
)
861 Inherited::copyToBin(pMem
, whichField
);
863 if(FieldBits::NoField
!= (RootsFieldMask
& whichField
))
865 _mfRoots
.copyToBin(pMem
);
867 if(FieldBits::NoField
!= (JointsFieldMask
& whichField
))
869 _mfJoints
.copyToBin(pMem
);
871 if(FieldBits::NoField
!= (ParentJointsFieldMask
& whichField
))
873 _mfParentJoints
.copyToBin(pMem
);
875 if(FieldBits::NoField
!= (JointMatricesFieldMask
& whichField
))
877 _mfJointMatrices
.copyToBin(pMem
);
879 if(FieldBits::NoField
!= (JointNormalMatricesFieldMask
& whichField
))
881 _mfJointNormalMatrices
.copyToBin(pMem
);
883 if(FieldBits::NoField
!= (UseInvBindMatrixFieldMask
& whichField
))
885 _sfUseInvBindMatrix
.copyToBin(pMem
);
887 if(FieldBits::NoField
!= (CalcNormalMatricesFieldMask
& whichField
))
889 _sfCalcNormalMatrices
.copyToBin(pMem
);
891 if(FieldBits::NoField
!= (JointsChangedFieldMask
& whichField
))
893 _sfJointsChanged
.copyToBin(pMem
);
897 void SkeletonBase::copyFromBin(BinaryDataHandler
&pMem
,
898 ConstFieldMaskArg whichField
)
900 Inherited::copyFromBin(pMem
, whichField
);
902 if(FieldBits::NoField
!= (RootsFieldMask
& whichField
))
904 editMField(RootsFieldMask
, _mfRoots
);
905 _mfRoots
.copyFromBin(pMem
);
907 if(FieldBits::NoField
!= (JointsFieldMask
& whichField
))
909 editMField(JointsFieldMask
, _mfJoints
);
910 _mfJoints
.copyFromBin(pMem
);
912 if(FieldBits::NoField
!= (ParentJointsFieldMask
& whichField
))
914 editMField(ParentJointsFieldMask
, _mfParentJoints
);
915 _mfParentJoints
.copyFromBin(pMem
);
917 if(FieldBits::NoField
!= (JointMatricesFieldMask
& whichField
))
919 editMField(JointMatricesFieldMask
, _mfJointMatrices
);
920 _mfJointMatrices
.copyFromBin(pMem
);
922 if(FieldBits::NoField
!= (JointNormalMatricesFieldMask
& whichField
))
924 editMField(JointNormalMatricesFieldMask
, _mfJointNormalMatrices
);
925 _mfJointNormalMatrices
.copyFromBin(pMem
);
927 if(FieldBits::NoField
!= (UseInvBindMatrixFieldMask
& whichField
))
929 editSField(UseInvBindMatrixFieldMask
);
930 _sfUseInvBindMatrix
.copyFromBin(pMem
);
932 if(FieldBits::NoField
!= (CalcNormalMatricesFieldMask
& whichField
))
934 editSField(CalcNormalMatricesFieldMask
);
935 _sfCalcNormalMatrices
.copyFromBin(pMem
);
937 if(FieldBits::NoField
!= (JointsChangedFieldMask
& whichField
))
939 editSField(JointsChangedFieldMask
);
940 _sfJointsChanged
.copyFromBin(pMem
);
944 //! create a new instance of the class
945 SkeletonTransitPtr
SkeletonBase::createLocal(BitVector bFlags
)
947 SkeletonTransitPtr fc
;
949 if(getClassType().getPrototype() != NULL
)
951 FieldContainerTransitPtr tmpPtr
=
952 getClassType().getPrototype()-> shallowCopyLocal(bFlags
);
954 fc
= dynamic_pointer_cast
<Skeleton
>(tmpPtr
);
960 //! create a new instance of the class, copy the container flags
961 SkeletonTransitPtr
SkeletonBase::createDependent(BitVector bFlags
)
963 SkeletonTransitPtr fc
;
965 if(getClassType().getPrototype() != NULL
)
967 FieldContainerTransitPtr tmpPtr
=
968 getClassType().getPrototype()-> shallowCopyDependent(bFlags
);
970 fc
= dynamic_pointer_cast
<Skeleton
>(tmpPtr
);
976 //! create a new instance of the class
977 SkeletonTransitPtr
SkeletonBase::create(void)
979 SkeletonTransitPtr fc
;
981 if(getClassType().getPrototype() != NULL
)
983 FieldContainerTransitPtr tmpPtr
=
984 getClassType().getPrototype()-> shallowCopy();
986 fc
= dynamic_pointer_cast
<Skeleton
>(tmpPtr
);
992 Skeleton
*SkeletonBase::createEmptyLocal(BitVector bFlags
)
994 Skeleton
*returnValue
;
996 newPtr
<Skeleton
>(returnValue
, bFlags
);
998 returnValue
->_pFieldFlags
->_bNamespaceMask
&= ~bFlags
;
1003 //! create an empty new instance of the class, do not copy the prototype
1004 Skeleton
*SkeletonBase::createEmpty(void)
1006 Skeleton
*returnValue
;
1008 newPtr
<Skeleton
>(returnValue
, Thread::getCurrentLocalFlags());
1010 returnValue
->_pFieldFlags
->_bNamespaceMask
&=
1011 ~Thread::getCurrentLocalFlags();
1017 FieldContainerTransitPtr
SkeletonBase::shallowCopyLocal(
1018 BitVector bFlags
) const
1022 newPtr(tmpPtr
, dynamic_cast<const Skeleton
*>(this), bFlags
);
1024 FieldContainerTransitPtr
returnValue(tmpPtr
);
1026 tmpPtr
->_pFieldFlags
->_bNamespaceMask
&= ~bFlags
;
1031 FieldContainerTransitPtr
SkeletonBase::shallowCopyDependent(
1032 BitVector bFlags
) const
1036 newPtr(tmpPtr
, dynamic_cast<const Skeleton
*>(this), ~bFlags
);
1038 FieldContainerTransitPtr
returnValue(tmpPtr
);
1040 tmpPtr
->_pFieldFlags
->_bNamespaceMask
= bFlags
;
1045 FieldContainerTransitPtr
SkeletonBase::shallowCopy(void) const
1050 dynamic_cast<const Skeleton
*>(this),
1051 Thread::getCurrentLocalFlags());
1053 tmpPtr
->_pFieldFlags
->_bNamespaceMask
&= ~Thread::getCurrentLocalFlags();
1055 FieldContainerTransitPtr
returnValue(tmpPtr
);
1063 /*------------------------- constructors ----------------------------------*/
1065 SkeletonBase::SkeletonBase(void) :
1070 BaseSkeletonJoint::SkeletonFieldId
),
1072 _mfJointMatrices (),
1073 _mfJointNormalMatrices (),
1074 _sfUseInvBindMatrix (bool(true)),
1075 _sfCalcNormalMatrices (bool(false)),
1080 SkeletonBase::SkeletonBase(const SkeletonBase
&source
) :
1085 BaseSkeletonJoint::SkeletonFieldId
),
1087 _mfJointMatrices (source
._mfJointMatrices
),
1088 _mfJointNormalMatrices (source
._mfJointNormalMatrices
),
1089 _sfUseInvBindMatrix (source
._sfUseInvBindMatrix
),
1090 _sfCalcNormalMatrices (source
._sfCalcNormalMatrices
),
1091 _sfJointsChanged (source
._sfJointsChanged
)
1096 /*-------------------------- destructors ----------------------------------*/
1098 SkeletonBase::~SkeletonBase(void)
1102 /*-------------------------------------------------------------------------*/
1105 bool SkeletonBase::unlinkChild(
1106 FieldContainer
* const pChild
,
1107 UInt16
const childFieldId
)
1109 if(childFieldId
== JointsFieldId
)
1111 BaseSkeletonJoint
* pTypedChild
=
1112 dynamic_cast<BaseSkeletonJoint
*>(pChild
);
1114 if(pTypedChild
!= NULL
)
1116 Int32 iChildIdx
= _mfJoints
.findIndex(pTypedChild
);
1120 editMField(JointsFieldMask
, _mfJoints
);
1122 _mfJoints
.erase(iChildIdx
);
1127 SWARNING
<< "Parent ([" << this
1128 << "] id [" << this->getId()
1129 << "] type [" << this->getType().getCName()
1130 << "] childFieldId [" << childFieldId
1131 << "]) - Child ([" << pChild
1132 << "] id [" << pChild
->getId()
1133 << "] type [" << pChild
->getType().getCName()
1134 << "]): link inconsistent!"
1144 return Inherited::unlinkChild(pChild
, childFieldId
);
1147 void SkeletonBase::onCreate(const Skeleton
*source
)
1149 Inherited::onCreate(source
);
1153 Skeleton
*pThis
= static_cast<Skeleton
*>(this);
1155 MFUnrecNodePtr::const_iterator RootsIt
=
1156 source
->_mfRoots
.begin();
1157 MFUnrecNodePtr::const_iterator RootsEnd
=
1158 source
->_mfRoots
.end ();
1160 while(RootsIt
!= RootsEnd
)
1162 pThis
->pushToRoots(*RootsIt
);
1167 MFUnrecChildBaseSkeletonJointPtr::const_iterator JointsIt
=
1168 source
->_mfJoints
.begin();
1169 MFUnrecChildBaseSkeletonJointPtr::const_iterator JointsEnd
=
1170 source
->_mfJoints
.end ();
1172 while(JointsIt
!= JointsEnd
)
1174 pThis
->pushToJoints(*JointsIt
);
1179 MFUnrecBaseSkeletonJointPtr::const_iterator ParentJointsIt
=
1180 source
->_mfParentJoints
.begin();
1181 MFUnrecBaseSkeletonJointPtr::const_iterator ParentJointsEnd
=
1182 source
->_mfParentJoints
.end ();
1184 while(ParentJointsIt
!= ParentJointsEnd
)
1186 pThis
->pushToParentJoints(*ParentJointsIt
);
1193 GetFieldHandlePtr
SkeletonBase::getHandleRoots (void) const
1195 MFUnrecNodePtr::GetHandlePtr
returnValue(
1196 new MFUnrecNodePtr::GetHandle(
1198 this->getType().getFieldDesc(RootsFieldId
),
1199 const_cast<SkeletonBase
*>(this)));
1204 EditFieldHandlePtr
SkeletonBase::editHandleRoots (void)
1206 MFUnrecNodePtr::EditHandlePtr
returnValue(
1207 new MFUnrecNodePtr::EditHandle(
1209 this->getType().getFieldDesc(RootsFieldId
),
1212 returnValue
->setAddMethod(
1213 boost::bind(&Skeleton::pushToRoots
,
1214 static_cast<Skeleton
*>(this), _1
));
1215 returnValue
->setRemoveMethod(
1216 boost::bind(&Skeleton::removeFromRoots
,
1217 static_cast<Skeleton
*>(this), _1
));
1218 returnValue
->setRemoveObjMethod(
1219 boost::bind(&Skeleton::removeObjFromRoots
,
1220 static_cast<Skeleton
*>(this), _1
));
1221 returnValue
->setClearMethod(
1222 boost::bind(&Skeleton::clearRoots
,
1223 static_cast<Skeleton
*>(this)));
1225 editMField(RootsFieldMask
, _mfRoots
);
1230 GetFieldHandlePtr
SkeletonBase::getHandleJoints (void) const
1232 MFUnrecChildBaseSkeletonJointPtr::GetHandlePtr
returnValue(
1233 new MFUnrecChildBaseSkeletonJointPtr::GetHandle(
1235 this->getType().getFieldDesc(JointsFieldId
),
1236 const_cast<SkeletonBase
*>(this)));
1241 EditFieldHandlePtr
SkeletonBase::editHandleJoints (void)
1243 MFUnrecChildBaseSkeletonJointPtr::EditHandlePtr
returnValue(
1244 new MFUnrecChildBaseSkeletonJointPtr::EditHandle(
1246 this->getType().getFieldDesc(JointsFieldId
),
1249 returnValue
->setAddMethod(
1250 boost::bind(&Skeleton::pushToJoints
,
1251 static_cast<Skeleton
*>(this), _1
));
1252 returnValue
->setRemoveMethod(
1253 boost::bind(&Skeleton::removeFromJoints
,
1254 static_cast<Skeleton
*>(this), _1
));
1255 returnValue
->setRemoveObjMethod(
1256 boost::bind(&Skeleton::removeObjFromJoints
,
1257 static_cast<Skeleton
*>(this), _1
));
1258 returnValue
->setClearMethod(
1259 boost::bind(&Skeleton::clearJoints
,
1260 static_cast<Skeleton
*>(this)));
1262 editMField(JointsFieldMask
, _mfJoints
);
1267 GetFieldHandlePtr
SkeletonBase::getHandleParentJoints (void) const
1269 MFUnrecBaseSkeletonJointPtr::GetHandlePtr
returnValue(
1270 new MFUnrecBaseSkeletonJointPtr::GetHandle(
1272 this->getType().getFieldDesc(ParentJointsFieldId
),
1273 const_cast<SkeletonBase
*>(this)));
1278 EditFieldHandlePtr
SkeletonBase::editHandleParentJoints (void)
1280 MFUnrecBaseSkeletonJointPtr::EditHandlePtr
returnValue(
1281 new MFUnrecBaseSkeletonJointPtr::EditHandle(
1283 this->getType().getFieldDesc(ParentJointsFieldId
),
1286 returnValue
->setAddMethod(
1287 boost::bind(&Skeleton::pushToParentJoints
,
1288 static_cast<Skeleton
*>(this), _1
));
1289 returnValue
->setRemoveMethod(
1290 boost::bind(&Skeleton::removeFromParentJoints
,
1291 static_cast<Skeleton
*>(this), _1
));
1292 returnValue
->setRemoveObjMethod(
1293 boost::bind(&Skeleton::removeObjFromParentJoints
,
1294 static_cast<Skeleton
*>(this), _1
));
1295 returnValue
->setClearMethod(
1296 boost::bind(&Skeleton::clearParentJoints
,
1297 static_cast<Skeleton
*>(this)));
1299 editMField(ParentJointsFieldMask
, _mfParentJoints
);
1304 GetFieldHandlePtr
SkeletonBase::getHandleJointMatrices (void) const
1306 MFMatrix::GetHandlePtr
returnValue(
1307 new MFMatrix::GetHandle(
1309 this->getType().getFieldDesc(JointMatricesFieldId
),
1310 const_cast<SkeletonBase
*>(this)));
1315 EditFieldHandlePtr
SkeletonBase::editHandleJointMatrices (void)
1317 MFMatrix::EditHandlePtr
returnValue(
1318 new MFMatrix::EditHandle(
1320 this->getType().getFieldDesc(JointMatricesFieldId
),
1324 editMField(JointMatricesFieldMask
, _mfJointMatrices
);
1329 GetFieldHandlePtr
SkeletonBase::getHandleJointNormalMatrices (void) const
1331 MFMatrix::GetHandlePtr
returnValue(
1332 new MFMatrix::GetHandle(
1333 &_mfJointNormalMatrices
,
1334 this->getType().getFieldDesc(JointNormalMatricesFieldId
),
1335 const_cast<SkeletonBase
*>(this)));
1340 EditFieldHandlePtr
SkeletonBase::editHandleJointNormalMatrices(void)
1342 MFMatrix::EditHandlePtr
returnValue(
1343 new MFMatrix::EditHandle(
1344 &_mfJointNormalMatrices
,
1345 this->getType().getFieldDesc(JointNormalMatricesFieldId
),
1349 editMField(JointNormalMatricesFieldMask
, _mfJointNormalMatrices
);
1354 GetFieldHandlePtr
SkeletonBase::getHandleUseInvBindMatrix (void) const
1356 SFBool::GetHandlePtr
returnValue(
1357 new SFBool::GetHandle(
1358 &_sfUseInvBindMatrix
,
1359 this->getType().getFieldDesc(UseInvBindMatrixFieldId
),
1360 const_cast<SkeletonBase
*>(this)));
1365 EditFieldHandlePtr
SkeletonBase::editHandleUseInvBindMatrix(void)
1367 SFBool::EditHandlePtr
returnValue(
1368 new SFBool::EditHandle(
1369 &_sfUseInvBindMatrix
,
1370 this->getType().getFieldDesc(UseInvBindMatrixFieldId
),
1374 editSField(UseInvBindMatrixFieldMask
);
1379 GetFieldHandlePtr
SkeletonBase::getHandleCalcNormalMatrices (void) const
1381 SFBool::GetHandlePtr
returnValue(
1382 new SFBool::GetHandle(
1383 &_sfCalcNormalMatrices
,
1384 this->getType().getFieldDesc(CalcNormalMatricesFieldId
),
1385 const_cast<SkeletonBase
*>(this)));
1390 EditFieldHandlePtr
SkeletonBase::editHandleCalcNormalMatrices(void)
1392 SFBool::EditHandlePtr
returnValue(
1393 new SFBool::EditHandle(
1394 &_sfCalcNormalMatrices
,
1395 this->getType().getFieldDesc(CalcNormalMatricesFieldId
),
1399 editSField(CalcNormalMatricesFieldMask
);
1404 GetFieldHandlePtr
SkeletonBase::getHandleJointsChanged (void) const
1406 SFOSGAny::GetHandlePtr
returnValue(
1407 new SFOSGAny::GetHandle(
1409 this->getType().getFieldDesc(JointsChangedFieldId
),
1410 const_cast<SkeletonBase
*>(this)));
1415 EditFieldHandlePtr
SkeletonBase::editHandleJointsChanged (void)
1417 SFOSGAny::EditHandlePtr
returnValue(
1418 new SFOSGAny::EditHandle(
1420 this->getType().getFieldDesc(JointsChangedFieldId
),
1424 editSField(JointsChangedFieldMask
);
1430 #ifdef OSG_MT_CPTR_ASPECT
1431 void SkeletonBase::execSyncV( FieldContainer
&oFrom
,
1432 ConstFieldMaskArg whichField
,
1433 AspectOffsetStore
&oOffsets
,
1434 ConstFieldMaskArg syncMode
,
1435 const UInt32 uiSyncInfo
)
1437 Skeleton
*pThis
= static_cast<Skeleton
*>(this);
1439 pThis
->execSync(static_cast<Skeleton
*>(&oFrom
),
1448 #ifdef OSG_MT_CPTR_ASPECT
1449 FieldContainer
*SkeletonBase::createAspectCopy(
1450 const FieldContainer
*pRefAspect
) const
1452 Skeleton
*returnValue
;
1454 newAspectCopy(returnValue
,
1455 dynamic_cast<const Skeleton
*>(pRefAspect
),
1456 dynamic_cast<const Skeleton
*>(this));
1462 void SkeletonBase::resolveLinks(void)
1464 Inherited::resolveLinks();
1466 static_cast<Skeleton
*>(this)->clearRoots();
1468 static_cast<Skeleton
*>(this)->clearJoints();
1470 static_cast<Skeleton
*>(this)->clearParentJoints();
1472 #ifdef OSG_MT_CPTR_ASPECT
1473 AspectOffsetStore oOffsets
;
1475 _pAspectStore
->fillOffsetArray(oOffsets
, this);
1478 #ifdef OSG_MT_CPTR_ASPECT
1479 _mfJointMatrices
.terminateShare(Thread::getCurrentAspect(),
1482 #ifdef OSG_MT_CPTR_ASPECT
1483 _mfJointNormalMatrices
.terminateShare(Thread::getCurrentAspect(),