1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2009 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 #ifndef _OSGCOLLADANODE_H_
40 #define _OSGCOLLADANODE_H_
42 #include "OSGConfig.h"
44 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
46 #include "OSGColladaInstantiableElement.h"
47 #include "OSGColladaElementFactoryHelper.h"
48 #include "OSGColladaInstInfo.h"
50 #include "OSGSkeleton.h"
52 #ifdef OSG_WITH_COLLADA_NAMESPACE
53 namespace ColladaDOM141
{
64 class domInstance_node
;
65 class domInstance_light
;
66 class domInstance_geometry
;
67 class domInstance_controller
;
69 #ifdef OSG_WITH_COLLADA_NAMESPACE
76 class ColladaVisualScene
;
77 class ColladaInstanceNode
;
78 class ColladaInstanceLight
;
79 class ColladaInstanceGeometry
;
80 class ColladaInstanceController
;
83 OSG_GEN_MEMOBJPTR(ColladaNode
);
86 /*! \ingroup GrpFileIOCollada
90 class OSG_FILEIO_DLLMAPPING ColladaNode
: public ColladaInstantiableElement
92 /*========================== PUBLIC =================================*/
94 /*---------------------------------------------------------------------*/
98 typedef ColladaInstantiableElement Inherited
;
99 typedef ColladaNode Self
;
101 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaNode
);
103 typedef std::vector
<std::string
> NodePath
;
104 typedef NodePath::iterator NodePathIt
;
105 typedef NodePath::const_iterator NodePathConstIt
;
108 class ColladaNodeInstInfo
: public ColladaInstInfo
110 /*========================== PUBLIC =============================*/
112 /*-----------------------------------------------------------------*/
116 typedef ColladaInstInfo Inherited
;
117 typedef ColladaNodeInstInfo Self
;
119 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaNodeInstInfo
);
122 /*-----------------------------------------------------------------*/
126 static ColladaInstInfoTransitPtr
127 create(ColladaElement
*colInstParent
,
128 ColladaInstanceNode
*colInst
,
132 /*-----------------------------------------------------------------*/
136 inline Node
*getParentNode(void) const;
139 /*-----------------------------------------------------------------*/
143 virtual void process(void);
146 /*========================= PROTECTED ===========================*/
148 /*-----------------------------------------------------------------*/
149 /*! \name Constructors/Destructor */
153 ColladaElement
*colInstParent
,
154 ColladaInstanceNode
*colInst
,
156 virtual ~ColladaNodeInstInfo(void );
159 /*-----------------------------------------------------------------*/
161 ColladaNodeRefPtr _colInstTarget
;
162 NodeUnrecPtr _parentN
;
165 OSG_GEN_MEMOBJPTR(ColladaNodeInstInfo
);
168 /*---------------------------------------------------------------------*/
172 static ColladaElementTransitPtr
173 create(daeElement
*elem
, ColladaGlobal
*global
);
176 /*---------------------------------------------------------------------*/
180 virtual void read (ColladaElement
*colElemParent
);
181 virtual Node
*createInstance(ColladaInstInfo
*colInstInfo
);
184 /*---------------------------------------------------------------------*/
188 bool isJoint (void ) const;
189 Skeleton
*getSkeleton (void ) const;
191 Node
*getTopNode (UInt32 instIdx
) const;
192 Node
*getBottomNode(UInt32 instIdx
) const;
194 Node
*getNodeBySid (UInt32 instIdx
, const std::string
&sid
) const;
197 /*========================= PROTECTED ===============================*/
199 /*---------------------------------------------------------------------*/
203 class NodeLoaderState
;
204 OSG_GEN_MEMOBJPTR(NodeLoaderState
);
206 class NodeLoaderState
: public ColladaLoaderState
208 /*========================== PUBLIC =============================*/
210 /*-----------------------------------------------------------------*/
214 typedef ColladaLoaderState Inherited
;
215 typedef NodeLoaderState Self
;
217 OSG_GEN_INTERNAL_MEMOBJPTR(NodeLoaderState
);
219 typedef std::vector
<Matrix
> MatrixStack
;
220 typedef MatrixStack::iterator MatrixStackIt
;
221 typedef MatrixStack::const_iterator MatrixStackConstIt
;
224 /*-----------------------------------------------------------------*/
228 static NodeLoaderStateTransitPtr
create(void);
231 /*-----------------------------------------------------------------*/
235 void pushNodePath(const std::string
&nodeId
);
236 void popNodePath (void );
237 const NodePath
&getNodePath (void ) const;
238 void dumpNodePath(void ) const;
240 void pushMatrix (const Matrix
&matrix
);
241 void popMatrix (void );
242 const Matrix
&getWorldMatrix(void ) const;
244 Skeleton
*getSkeleton(void ) const;
245 void setSkeleton(Skeleton
*skel
);
247 Int16
getJointId (void ) const;
248 void setJointId (Int16 jointId
);
251 /*========================= PROTECTED ===========================*/
253 /*-----------------------------------------------------------------*/
254 /*! \name Constructors/Destructor */
257 NodeLoaderState(void);
258 virtual ~NodeLoaderState(void);
261 /*-----------------------------------------------------------------*/
264 SkeletonUnrecPtr _skel
;
268 MatrixStack _matrixStack
;
271 typedef std::map
<std::string
, Node
*> SIdNodeMap
;
272 typedef SIdNodeMap::iterator SIdNodeMapIt
;
273 typedef SIdNodeMap::const_iterator SIdNodeMapConstIt
;
283 SkeletonUnrecPtr _skel
;
285 NodeUnrecPtr _bottomN
;
289 typedef std::vector
<InstData
> InstDataStore
;
290 typedef InstDataStore::iterator InstDataStoreIt
;
291 typedef InstDataStore::const_iterator InstDataStoreConstIt
;
294 /*---------------------------------------------------------------------*/
295 /*! \name Constructors/Destructor */
298 ColladaNode(daeElement
*elem
,
299 ColladaGlobal
*global
);
300 virtual ~ColladaNode(void );
303 /*---------------------------------------------------------------------*/
307 Node
*createInstanceNode (ColladaInstInfo
*colInstInfo
, domNode
*node
);
308 Node
*createInstanceJoint(ColladaInstInfo
*colInstInfo
, domNode
*node
);
310 void handleLookAt (domLookat
*lookat
,
311 InstData
&instData
);
312 void handleMatrix (domMatrix
*matrix
,
313 InstData
&instData
);
314 void handleRotate (domRotate
*rotate
,
315 InstData
&instData
);
316 void handleScale (domScale
*scale
,
317 InstData
&instData
);
318 void handleSkew (domSkew
*skew
,
319 InstData
&instData
);
320 void handleTranslate(domTranslate
*translate
,
321 InstData
&instData
);
323 void appendXForm (const Matrix
&m
,
324 const std::string
&xformSID
,
325 InstData
&instData
);
326 void appendChild (domNode
*child
,
328 InstData
&instData
);
330 void readNode (domNode
*child
);
331 void handleNode (domNode
*child
,
332 InstData
&instData
);
334 void readInstanceNode (domInstance_node
*instNode
);
335 void handleInstanceNode (domInstance_node
*instNode
,
336 InstData
&instData
);
338 void readInstanceLight (domInstance_light
*instLight
);
339 void handleInstanceLight (domInstance_light
*instLight
,
340 InstData
&instData
);
342 void readInstanceGeometry (domInstance_geometry
*instGeo
);
343 void handleInstanceGeometry (domInstance_geometry
*instGeo
,
344 InstData
&instData
);
346 void readInstanceController (domInstance_controller
*instCtrl
);
347 void handleInstanceController (domInstance_controller
*instCtrl
,
348 InstData
&instData
);
350 static ColladaElementRegistrationHelper _regHelper
;
351 static const std::string _loaderStateName
;
353 InstDataStore _instDataStore
;
358 #include "OSGColladaNode.inl"
360 #endif // OSG_WITH_COLLADA
362 #endif // _OSGCOLLADANODE_H_