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 _OSGCOLLADAGEOMETRY_H_
40 #define _OSGCOLLADAGEOMETRY_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 "OSGColladaInstanceMaterial.h"
49 #include "OSGColladaInstInfo.h"
50 #include "OSGColladaSource.h"
52 #include "OSGGeometry.h"
53 #include "OSGGeoVectorProperty.h"
54 #include "OSGGeoIntegralProperty.h"
56 #include <dae/daeDomTypes.h>
57 #include <dom/domInputLocal.h>
58 #include <dom/domInputLocalOffset.h>
59 #include <dom/domSource.h>
61 #ifdef OSG_WITH_COLLADA_NAMESPACE
62 namespace ColladaDOM141
{
75 #ifdef OSG_WITH_COLLADA_NAMESPACE
82 class ColladaInstanceGeometry
;
83 OSG_GEN_MEMOBJPTR(ColladaInstanceGeometry
);
87 /*! \ingroup GrpFileIOCollada
91 class OSG_FILEIO_DLLMAPPING ColladaGeometry
: public ColladaInstantiableElement
93 /*========================== PUBLIC =================================*/
95 /*---------------------------------------------------------------------*/
99 typedef ColladaInstantiableElement Inherited
;
100 typedef ColladaGeometry Self
;
102 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaGeometry
);
104 typedef ColladaInstanceMaterial::BindInfo BindInfo
;
105 typedef ColladaInstanceMaterial::BindStore BindStore
;
107 typedef ColladaInstanceMaterial::BindVertexInfo BindVertexInfo
;
108 typedef ColladaInstanceMaterial::BindVertexStore BindVertexStore
;
110 class ColladaGeometryInstInfo
: public ColladaInstInfo
112 /*========================== PUBLIC =============================*/
114 /*-----------------------------------------------------------------*/
118 typedef ColladaInstInfo Inherited
;
119 typedef ColladaGeometryInstInfo Self
;
121 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaGeometryInstInfo
);
124 /*-----------------------------------------------------------------*/
128 static ColladaInstInfoTransitPtr
129 create(ColladaNode
*colInstParent
,
130 ColladaInstanceGeometry
*colInst
,
134 /*-----------------------------------------------------------------*/
138 inline Node
*getParentNode(void) const;
141 /*-----------------------------------------------------------------*/
145 virtual void process(void);
148 /*========================= PROTECTED ===========================*/
150 /*-----------------------------------------------------------------*/
151 /*! \name Constructors/Destructor */
154 ColladaGeometryInstInfo(
155 ColladaNode
*colInstParent
,
156 ColladaInstanceGeometry
*colInst
,
158 virtual ~ColladaGeometryInstInfo(void );
161 /*-----------------------------------------------------------------*/
163 NodeUnrecPtr _parentN
;
166 OSG_GEN_MEMOBJPTR(ColladaGeometryInstInfo
);
169 /*---------------------------------------------------------------------*/
173 static ColladaElementTransitPtr
174 create(daeElement
*elem
, ColladaGlobal
*global
);
177 /*---------------------------------------------------------------------*/
181 void setDoubleSided(bool value
);
184 /*---------------------------------------------------------------------*/
188 virtual void read (ColladaElement
*colElemParent
);
189 virtual Node
*createInstance(ColladaInstInfo
*colInstInfo
);
192 /*========================= PROTECTED ===============================*/
194 /*---------------------------------------------------------------------*/
195 /*! \name Constructors/Destructor */
198 ColladaGeometry(daeElement
*elem
, ColladaGlobal
*global
);
199 virtual ~ColladaGeometry(void );
202 /*---------------------------------------------------------------------*/
203 /*! \name Internal Types */
207 typedef std::map
<std::string
, ColladaSourceRefPtr
> SourceMap
;
208 typedef SourceMap::iterator SourceMapIt
;
209 typedef SourceMap::const_iterator SourceMapConstIt
;
216 PropInfo(const PropInfo
&source
);
218 std::string _semantic
;
221 GeoVectorPropertyUnrecPtr _prop
;
224 typedef std::vector
<PropInfo
> PropStore
;
225 typedef PropStore::iterator PropStoreIt
;
226 typedef PropStore::const_iterator PropStoreConstIt
;
228 typedef std::vector
<GeoIntegralPropertyUnrecPtr
> IndexStore
;
229 typedef IndexStore::iterator IndexStoreIt
;
230 typedef IndexStore::const_iterator IndexStoreConstIt
;
232 // map <instance_material> target attribute to an index into
233 // the instance store (getInstStore())
234 typedef std::map
<std::string
, UInt32
> InstanceMap
;
235 typedef InstanceMap::iterator InstanceMapIt
;
236 typedef InstanceMap::const_iterator InstanceMapConstIt
;
242 std::string _matSymbol
;
244 PropStore _propStore
;
245 IndexStore _indexStore
;
247 GeoIntegralPropertyUnrecPtr _lengths
;
248 GeoIntegralPropertyUnrecPtr _types
;
250 InstanceMap _instMap
;
261 typedef std::vector
<GeoInfo
> GeoStore
;
262 typedef GeoStore::iterator GeoStoreIt
;
263 typedef GeoStore::const_iterator GeoStoreConstIt
;
266 /*---------------------------------------------------------------------*/
267 /*! \name Helper Functions */
270 void readMesh ( domMesh
*mesh
);
271 void readSources(const domSource_Array
&sources
);
273 void readLines (domMesh
*mesh
, domLines
*lines
);
274 void readLineStrips(domMesh
*mesh
, domLinestrips
*lineStrips
);
275 void readPolygons (domMesh
*mesh
, domPolygons
*polygons
);
276 void readPolyList (domMesh
*mesh
, domPolylist
*polyList
);
277 void readTriangles (domMesh
*mesh
, domTriangles
*triangles
);
278 void readTriFans (domMesh
*mesh
, domTrifans
*triFans
);
279 void readTriStrips (domMesh
*mesh
, domTristrips
*triStrips
);
281 UInt32
mapSemantic (const std::string
&semantic
,
285 void setupProperty(UInt32 geoIdx
,
287 const std::string
&semantic
,
289 const std::string
&sourceId
,
290 GeoIntegralProperty
*idxProp
);
292 UInt32
setupGeometry(const domInputLocal_Array
&vertInputs
,
293 const domInputLocalOffset_Array
&inputs
,
295 IndexStore
&indexStore
);
297 void handleBindMaterial(const GeoInfo
&geoInfo
,
299 ColladaInstanceGeometry
*colInstGeo
);
301 const BindInfo
*findBind (const BindStore
&store
,
302 const std::string
&semantic
,
304 const BindVertexInfo
*findBindVertex(const BindVertexStore
&store
,
305 const std::string
&inSemantic
,
309 UInt16
findFreePropertyIndex(UInt32 geoIdx
);
311 void validateIndices ( UInt32 geoIdx
,
312 const std::vector
<bool> &vIdxValid
,
313 const IndexStore idxStore
);
316 /*---------------------------------------------------------------------*/
318 static ColladaElementRegistrationHelper _regHelper
;
320 SourceMap _sourceMap
;
323 ExtraHandlerStore _extraHandlers
;
327 OSG_GEN_MEMOBJPTR(ColladaGeometry
);
331 #include "OSGColladaGeometry.inl"
333 #endif // OSG_WITH_COLLADA
335 #endif // _OSGCOLLADAGEOMETRY_H_