fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Collada / OSGColladaNode.h
blobdca0c8f684b1c03a5b4f6b60d727397f27bb8186
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2009 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 #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"
49 #include "OSGNode.h"
50 #include "OSGSkeleton.h"
52 #ifdef OSG_WITH_COLLADA_NAMESPACE
53 namespace ColladaDOM141 {
54 #endif
56 // forward decl
57 class domLookat;
58 class domMatrix;
59 class domRotate;
60 class domScale;
61 class domSkew;
62 class domTranslate;
63 class domNode;
64 class domInstance_node;
65 class domInstance_light;
66 class domInstance_geometry;
67 class domInstance_controller;
69 #ifdef OSG_WITH_COLLADA_NAMESPACE
71 #endif
73 OSG_BEGIN_NAMESPACE
75 // forward decl
76 class ColladaVisualScene;
77 class ColladaInstanceNode;
78 class ColladaInstanceLight;
79 class ColladaInstanceGeometry;
80 class ColladaInstanceController;
82 class ColladaNode;
83 OSG_GEN_MEMOBJPTR(ColladaNode);
86 /*! \ingroup GrpFileIOCollada
87 \nohierarchy
90 class OSG_FILEIO_DLLMAPPING ColladaNode : public ColladaInstantiableElement
92 /*========================== PUBLIC =================================*/
93 public:
94 /*---------------------------------------------------------------------*/
95 /*! \name Types */
96 /*! \{ */
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 =============================*/
111 public:
112 /*-----------------------------------------------------------------*/
113 /*! \name Types */
114 /*! \{ */
116 typedef ColladaInstInfo Inherited;
117 typedef ColladaNodeInstInfo Self;
119 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaNodeInstInfo);
121 /*! \} */
122 /*-----------------------------------------------------------------*/
123 /*! \name Create */
124 /*! \{ */
126 static ColladaInstInfoTransitPtr
127 create(ColladaElement *colInstParent,
128 ColladaInstanceNode *colInst,
129 Node *parentN );
131 /*! \} */
132 /*-----------------------------------------------------------------*/
133 /*! \name Access */
134 /*! \{ */
136 inline Node *getParentNode(void) const;
138 /*! \} */
139 /*-----------------------------------------------------------------*/
140 /*! \name Process */
141 /*! \{ */
143 virtual void process(void);
145 /*! \} */
146 /*========================= PROTECTED ===========================*/
147 protected:
148 /*-----------------------------------------------------------------*/
149 /*! \name Constructors/Destructor */
150 /*! \{ */
152 ColladaNodeInstInfo(
153 ColladaElement *colInstParent,
154 ColladaInstanceNode *colInst,
155 Node *parentN );
156 virtual ~ColladaNodeInstInfo(void );
158 /*! \} */
159 /*-----------------------------------------------------------------*/
161 ColladaNodeRefPtr _colInstTarget;
162 NodeUnrecPtr _parentN;
165 OSG_GEN_MEMOBJPTR(ColladaNodeInstInfo);
167 /*! \} */
168 /*---------------------------------------------------------------------*/
169 /*! \name Create */
170 /*! \{ */
172 static ColladaElementTransitPtr
173 create(daeElement *elem, ColladaGlobal *global);
175 /*! \} */
176 /*---------------------------------------------------------------------*/
177 /*! \name Reading */
178 /*! \{ */
180 virtual void read (ColladaElement *colElemParent);
181 virtual Node *createInstance(ColladaInstInfo *colInstInfo );
183 /*! \} */
184 /*---------------------------------------------------------------------*/
185 /*! \name Access */
186 /*! \{ */
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;
196 /*! \} */
197 /*========================= PROTECTED ===============================*/
198 protected:
199 /*---------------------------------------------------------------------*/
200 /*! \name Types */
201 /*! \{ */
203 class NodeLoaderState;
204 OSG_GEN_MEMOBJPTR(NodeLoaderState);
206 class NodeLoaderState : public ColladaLoaderState
208 /*========================== PUBLIC =============================*/
209 public:
210 /*-----------------------------------------------------------------*/
211 /*! \name Types */
212 /*! \{ */
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;
223 /*! \} */
224 /*-----------------------------------------------------------------*/
225 /*! \name Create */
226 /*! \{ */
228 static NodeLoaderStateTransitPtr create(void);
230 /*! \} */
231 /*-----------------------------------------------------------------*/
232 /*! \name Access */
233 /*! \{ */
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);
250 /*! \} */
251 /*========================= PROTECTED ===========================*/
252 protected:
253 /*-----------------------------------------------------------------*/
254 /*! \name Constructors/Destructor */
255 /*! \{ */
257 NodeLoaderState(void);
258 virtual ~NodeLoaderState(void);
260 /*! \} */
261 /*-----------------------------------------------------------------*/
263 NodePath _nodePath;
264 SkeletonUnrecPtr _skel;
265 Int16 _jointId;
267 Matrix _worldMatrix;
268 MatrixStack _matrixStack;
271 typedef std::map<std::string, Node *> SIdNodeMap;
272 typedef SIdNodeMap::iterator SIdNodeMapIt;
273 typedef SIdNodeMap::const_iterator SIdNodeMapConstIt;
275 struct InstData
277 InstData(void);
278 ~InstData(void);
280 NodePath _nodePath;
281 Matrix _localMatrix;
283 SkeletonUnrecPtr _skel;
284 NodeUnrecPtr _topN;
285 NodeUnrecPtr _bottomN;
286 SIdNodeMap _sidMap;
289 typedef std::vector<InstData> InstDataStore;
290 typedef InstDataStore::iterator InstDataStoreIt;
291 typedef InstDataStore::const_iterator InstDataStoreConstIt;
293 /*! \} */
294 /*---------------------------------------------------------------------*/
295 /*! \name Constructors/Destructor */
296 /*! \{ */
298 ColladaNode(daeElement *elem,
299 ColladaGlobal *global);
300 virtual ~ColladaNode(void );
302 /*! \} */
303 /*---------------------------------------------------------------------*/
304 /*! \name Types */
305 /*! \{ */
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,
327 Node *childN,
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;
356 OSG_END_NAMESPACE
358 #include "OSGColladaNode.inl"
360 #endif // OSG_WITH_COLLADA
362 #endif // _OSGCOLLADANODE_H_