fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Dynamics / Skeleton / OSGSkinnedGeometry.cpp
blob4b80f9d31f8a986644b34afb3cbc15b51a0dbd65
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
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>
59 OSG_BEGIN_NAMESPACE
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 /***************************************************************************\
67 * Class variables *
68 \***************************************************************************/
70 /***************************************************************************\
71 * Class methods *
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 /***************************************************************************\
101 * Instance methods *
102 \***************************************************************************/
104 /*-------------------------------------------------------------------------*\
105 - private -
106 \*-------------------------------------------------------------------------*/
108 /*----------------------- constructors & destructors ----------------------*/
110 SkinnedGeometry::SkinnedGeometry(void) :
111 Inherited()
115 SkinnedGeometry::SkinnedGeometry(const SkinnedGeometry &source) :
116 Inherited(source)
120 SkinnedGeometry::~SkinnedGeometry(void)
124 /*----------------------------- class specific ----------------------------*/
126 void SkinnedGeometry::changed(ConstFieldMaskArg whichField,
127 UInt32 origin,
128 BitVector details)
130 if((RenderModeFieldMask & whichField) != 0)
132 if(_sfSkinningAlgorithm.getValue() == NULL ||
133 _sfSkinningAlgorithm.getValue()->getRenderMode() !=
134 RenderModeE(_sfRenderMode.getValue()) )
136 switch(_sfRenderMode.getValue())
138 case RMUnskinned:
140 UnskinnedSkinningAlgorithmUnrecPtr algo =
141 UnskinnedSkinningAlgorithm::create();
142 setSkinningAlgorithm(algo);
144 if(_sfSkeleton.getValue() != NULL)
145 algo->setSkeleton(_sfSkeleton.getValue());
147 break;
149 case RMSkeleton:
151 SkeletonSkinningAlgorithmUnrecPtr algo =
152 SkeletonSkinningAlgorithm::create();
153 setSkinningAlgorithm(algo);
155 if(_sfSkeleton.getValue() != NULL)
157 algo->setSkeleton(_sfSkeleton.getValue());
158 _sfSkeleton.getValue()->setUseInvBindMatrix(false);
161 break;
163 case RMSkinnedCPU:
165 CPUSkinningAlgorithmUnrecPtr algo =
166 CPUSkinningAlgorithm::create();
167 setSkinningAlgorithm(algo);
169 if(_sfSkeleton.getValue() != NULL)
171 algo->setSkeleton(_sfSkeleton.getValue());
172 _sfSkeleton.getValue()->setUseInvBindMatrix(true);
175 break;
177 case RMSkinnedGPU:
179 GPUSkinningAlgorithmUnrecPtr algo =
180 GPUSkinningAlgorithm::create();
181 setSkinningAlgorithm(algo);
183 if(_sfSkeleton.getValue() != NULL)
185 algo->setSkeleton(_sfSkeleton.getValue());
186 _sfSkeleton.getValue()->setUseInvBindMatrix(true);
189 break;
192 invalidateVolume();
196 if((SkeletonFieldMask & whichField) != 0)
198 if(_sfSkinningAlgorithm.getValue() != NULL)
200 _sfSkinningAlgorithm.getValue()->setSkeleton(
201 _sfSkeleton.getValue());
205 Inherited::changed(whichField, origin, details);
208 Action::ResultE
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."
222 << std::endl;
223 return Action::Continue;
226 return _sfSkinningAlgorithm.getValue()->renderEnter(action);
229 Action::ResultE
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."
243 << std::endl;
244 return Action::Continue;
247 return _sfSkinningAlgorithm.getValue()->renderLeave(action);
250 Action::ResultE
251 SkinnedGeometry::intersectEnter(Action *action)
253 if(_sfRenderMode.getValue() != RMUnskinned &&
254 _sfSkeleton .getValue() == NULL )
256 SWARNING << "SkinnedGeometry::intersectEnter: No skeleton."
257 << std::endl;
259 return Action::Continue;
262 if(_sfSkinningAlgorithm.getValue() == NULL)
264 SWARNING << "SkinnedGeometry::intersectEnter: No SkinningAlgorithm"
265 << std::endl;
267 return Action::Continue;
270 return _sfSkinningAlgorithm.getValue()->intersectEnter(action);
273 void
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);
285 else
287 Inherited::adjustVolume(volume );
288 volume.transform (_sfBindShapeMatrix.getValue());
290 SLOG << "SkinnedGeometry::adjustVolume: Using Mesh vol "
291 << std::endl;
295 void SkinnedGeometry::dump( UInt32 ,
296 const BitVector ) const
298 SLOG << "Dump SkinnedGeometry NI" << std::endl;
301 Action::ResultE
302 SkinnedGeometry::animBindEnter(Action *action)
304 Action::ResultE res = Action::Continue;
306 if(_sfSkeleton.getValue() != NULL)
308 res = _sfSkeleton.getValue()->animBindEnter(action, this);
310 else
312 SWARNING << "SkinnedGeometry::animBindEnter: No skeleton."
313 << std::endl;
316 return res;
319 OSG_END_NAMESPACE