1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
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 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
47 #include "OSGSkinnedGeometry.h"
49 #include "OSGSkeleton.h"
50 #include "OSGAnimBindAction.h"
51 #include "OSGCPUSkinningAlgorithm.h"
52 #include "OSGGPUSkinningAlgorithm.h"
53 #include "OSGIntersectAction.h"
54 #include "OSGSkeletonSkinningAlgorithm.h"
55 #include "OSGUnskinnedSkinningAlgorithm.h"
57 #include <boost/cast.hpp>
61 // Documentation for this class is emitted in the
62 // OSGSkinnedGeometryBase.cpp file.
63 // To modify it, please change the .fcd file (OSGSkinnedGeometry.fcd) and
64 // regenerate the base file.
66 /***************************************************************************\
68 \***************************************************************************/
70 /***************************************************************************\
72 \***************************************************************************/
74 void SkinnedGeometry::initMethod(InitPhase ePhase
)
76 Inherited::initMethod(ePhase
);
78 if(ePhase
== TypeObject::SystemPost
)
80 RenderAction::registerEnterDefault(
81 SkinnedGeometry::getClassType(),
82 reinterpret_cast<Action::Callback
>(&SkinnedGeometry::renderEnter
));
83 RenderAction::registerLeaveDefault(
84 SkinnedGeometry::getClassType(),
85 reinterpret_cast<Action::Callback
>(&SkinnedGeometry::renderLeave
));
87 IntersectAction::registerEnterDefault(
88 SkinnedGeometry::getClassType(),
89 reinterpret_cast<Action::Callback
>(
90 &SkinnedGeometry::intersectEnter
));
92 AnimBindAction::registerEnterDefault(
93 SkinnedGeometry::getClassType(),
94 reinterpret_cast<Action::Callback
>(
95 &SkinnedGeometry::animBindEnter
));
100 /***************************************************************************\
102 \***************************************************************************/
104 /*-------------------------------------------------------------------------*\
106 \*-------------------------------------------------------------------------*/
108 /*----------------------- constructors & destructors ----------------------*/
110 SkinnedGeometry::SkinnedGeometry(void) :
115 SkinnedGeometry::SkinnedGeometry(const SkinnedGeometry
&source
) :
120 SkinnedGeometry::~SkinnedGeometry(void)
124 /*----------------------------- class specific ----------------------------*/
126 void SkinnedGeometry::changed(ConstFieldMaskArg whichField
,
130 if((RenderModeFieldMask
& whichField
) != 0)
132 if(_sfSkinningAlgorithm
.getValue() == NULL
||
133 _sfSkinningAlgorithm
.getValue()->getRenderMode() !=
134 RenderModeE(_sfRenderMode
.getValue()) )
136 switch(_sfRenderMode
.getValue())
140 UnskinnedSkinningAlgorithmUnrecPtr algo
=
141 UnskinnedSkinningAlgorithm::create();
142 setSkinningAlgorithm(algo
);
144 if(_sfSkeleton
.getValue() != NULL
)
145 algo
->setSkeleton(_sfSkeleton
.getValue());
151 SkeletonSkinningAlgorithmUnrecPtr algo
=
152 SkeletonSkinningAlgorithm::create();
153 setSkinningAlgorithm(algo
);
155 if(_sfSkeleton
.getValue() != NULL
)
157 algo
->setSkeleton(_sfSkeleton
.getValue());
158 _sfSkeleton
.getValue()->setUseInvBindMatrix(false);
165 CPUSkinningAlgorithmUnrecPtr algo
=
166 CPUSkinningAlgorithm::create();
167 setSkinningAlgorithm(algo
);
169 if(_sfSkeleton
.getValue() != NULL
)
171 algo
->setSkeleton(_sfSkeleton
.getValue());
172 _sfSkeleton
.getValue()->setUseInvBindMatrix(true);
179 GPUSkinningAlgorithmUnrecPtr algo
=
180 GPUSkinningAlgorithm::create();
181 setSkinningAlgorithm(algo
);
183 if(_sfSkeleton
.getValue() != NULL
)
185 algo
->setSkeleton(_sfSkeleton
.getValue());
186 _sfSkeleton
.getValue()->setUseInvBindMatrix(true);
196 if((SkeletonFieldMask
& whichField
) != 0)
198 if(_sfSkinningAlgorithm
.getValue() != NULL
)
200 _sfSkinningAlgorithm
.getValue()->setSkeleton(
201 _sfSkeleton
.getValue());
205 Inherited::changed(whichField
, origin
, details
);
209 SkinnedGeometry::renderEnter(Action
*action
)
211 if(_sfRenderMode
.getValue() != RMUnskinned
&&
212 _sfSkeleton
.getValue() == NULL
)
214 SWARNING
<< "SkinnedGeometry::renderEnter: No skeleton." << std::endl
;
216 return Action::Continue
;
219 if(_sfSkinningAlgorithm
.getValue() == NULL
)
221 SWARNING
<< "SkinnedGeometry::renderEnter: No SkinningAlgorithm."
223 return Action::Continue
;
226 return _sfSkinningAlgorithm
.getValue()->renderEnter(action
);
230 SkinnedGeometry::renderLeave(Action
*action
)
232 if(_sfRenderMode
.getValue() != RMUnskinned
&&
233 _sfSkeleton
.getValue() == NULL
)
235 SWARNING
<< "SkinnedGeometry::renderLeave: No skeleton." << std::endl
;
237 return Action::Continue
;
240 if(_sfSkinningAlgorithm
.getValue() == NULL
)
242 SWARNING
<< "SkinnedGeometry::renderLeave: No SkinningAlgorithm."
244 return Action::Continue
;
247 return _sfSkinningAlgorithm
.getValue()->renderLeave(action
);
251 SkinnedGeometry::intersectEnter(Action
*action
)
253 if(_sfRenderMode
.getValue() != RMUnskinned
&&
254 _sfSkeleton
.getValue() == NULL
)
256 SWARNING
<< "SkinnedGeometry::intersectEnter: No skeleton."
259 return Action::Continue
;
262 if(_sfSkinningAlgorithm
.getValue() == NULL
)
264 SWARNING
<< "SkinnedGeometry::intersectEnter: No SkinningAlgorithm"
267 return Action::Continue
;
270 return _sfSkinningAlgorithm
.getValue()->intersectEnter(action
);
274 SkinnedGeometry::fill(DrawableStatsAttachment
*drawStats
)
276 Inherited::fill(drawStats
);
279 void SkinnedGeometry::adjustVolume(Volume
&volume
)
281 if(_sfSkinningAlgorithm
.getValue() != NULL
)
283 _sfSkinningAlgorithm
.getValue()->adjustVolume(volume
);
287 Inherited::adjustVolume(volume
);
288 volume
.transform (_sfBindShapeMatrix
.getValue());
290 SLOG
<< "SkinnedGeometry::adjustVolume: Using Mesh vol "
295 void SkinnedGeometry::dump( UInt32
,
296 const BitVector
) const
298 SLOG
<< "Dump SkinnedGeometry NI" << std::endl
;
302 SkinnedGeometry::animBindEnter(Action
*action
)
304 Action::ResultE res
= Action::Continue
;
306 if(_sfSkeleton
.getValue() != NULL
)
308 res
= _sfSkeleton
.getValue()->animBindEnter(action
, this);
312 SWARNING
<< "SkinnedGeometry::animBindEnter: No skeleton."