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 #if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
40 #pragma GCC diagnostic ignored "-Wold-style-cast"
43 #include "OSGColladaInstanceGeometry.h"
45 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
47 #include "OSGColladaLog.h"
49 #include <dom/domInstance_geometry.h>
50 #include <dom/domInstance_material.h>
51 #include <dom/domBind_material.h>
52 #include <dom/domParam.h>
56 ColladaElementRegistrationHelper
ColladaInstanceGeometry::_regHelper(
57 &ColladaInstanceGeometry::create
, "instance_geometry");
60 ColladaElementTransitPtr
61 ColladaInstanceGeometry::create(daeElement
*elem
, ColladaGlobal
*global
)
63 return ColladaElementTransitPtr(new ColladaInstanceGeometry(elem
, global
));
67 ColladaInstanceGeometry::read(ColladaElement
*colElemParent
)
69 OSG_COLLADA_LOG(("ColladaInstanceGeometry::read\n"));
71 ColladaGeometryRefPtr colGeo
= getTargetElem();
75 colGeo
= dynamic_pointer_cast
<ColladaGeometry
>(
76 ColladaElementFactory::the()->create(
77 getTargetDOMElem(), getGlobal()));
82 domInstance_geometryRef instGeo
= getDOMElementAs
<domInstance_geometry
>();
83 domBind_materialRef bindMat
= instGeo
->getBind_material ();
87 SWARNING
<< "ColladaInstanceGeometry::read: "
88 << "No <bind_material> found." << std::endl
;
92 readBindMaterial(bindMat
);
96 ColladaInstanceGeometry::getTargetElem(void) const
98 ColladaGeometry
*retVal
= NULL
;
99 daeElementRef targetElem
= getTargetDOMElem();
101 if(targetElem
!= NULL
)
103 retVal
= getUserDataAs
<ColladaGeometry
>(targetElem
);
110 ColladaInstanceGeometry::getTargetDOMElem(void) const
112 domGeometryRef retVal
= NULL
;
113 domInstance_geometryRef instGeo
= getDOMElementAs
<domInstance_geometry
>();
115 if(instGeo
->getUrl().getElement() != NULL
)
117 retVal
= daeSafeCast
<domGeometry
>(instGeo
->getUrl().getElement());
123 const ColladaInstanceGeometry::MaterialMap
&
124 ColladaInstanceGeometry::getMaterialMap(void) const
129 ColladaInstanceGeometry::ColladaInstanceGeometry(
130 daeElement
*elem
, ColladaGlobal
*global
)
132 : Inherited(elem
, global
)
137 ColladaInstanceGeometry::~ColladaInstanceGeometry(void)
142 ColladaInstanceGeometry::readBindMaterial(domBind_material
*bindMat
)
144 domBind_material::domTechnique_commonRef techCom
=
145 bindMat
->getTechnique_common();
146 const domInstance_material_Array
&instMatArray
=
147 techCom
->getInstance_material_array();
149 for(UInt32 i
= 0; i
< instMatArray
.getCount(); ++i
)
151 ColladaInstanceMaterialRefPtr colInstMat
=
152 getUserDataAs
<ColladaInstanceMaterial
>(instMatArray
[i
]);
154 if(colInstMat
== NULL
)
156 colInstMat
= dynamic_pointer_cast
<ColladaInstanceMaterial
>(
157 ColladaElementFactory::the()->create(
158 instMatArray
[i
], getGlobal()));
160 colInstMat
->read(this);
163 _matMap
[colInstMat
->getSymbol()] = colInstMat
;
165 OSG_COLLADA_LOG(("ColladaInstanceGeometry::readBindMaterial: "
166 "binding symbol [%s] to target [%s]\n",
167 colInstMat
->getSymbol().c_str(),
168 instMatArray
[i
]->getTarget().getURI()));
171 const domParam_Array
¶ms
= bindMat
->getParam_array();
173 if(params
.getCount() > 0)
175 SWARNING
<< "ColladaInstanceGeometry::readBindMaterial: "
176 << "Ignoring [" << params
.getCount()
177 << "] <param> elements." << std::endl
;
183 #endif // OSG_WITH_COLLADA