fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Collada / OSGColladaInstanceGeometry.cpp
blobe5fc2f35f0869dd2aa714373a425ec5a71e1e2ed
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 #if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
40 #pragma GCC diagnostic ignored "-Wold-style-cast"
41 #endif
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>
54 OSG_BEGIN_NAMESPACE
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));
66 void
67 ColladaInstanceGeometry::read(ColladaElement *colElemParent)
69 OSG_COLLADA_LOG(("ColladaInstanceGeometry::read\n"));
71 ColladaGeometryRefPtr colGeo = getTargetElem();
73 if(colGeo == NULL)
75 colGeo = dynamic_pointer_cast<ColladaGeometry>(
76 ColladaElementFactory::the()->create(
77 getTargetDOMElem(), getGlobal()));
79 colGeo->read(this);
82 domInstance_geometryRef instGeo = getDOMElementAs<domInstance_geometry>();
83 domBind_materialRef bindMat = instGeo->getBind_material ();
85 if(bindMat == NULL)
87 SWARNING << "ColladaInstanceGeometry::read: "
88 << "No <bind_material> found." << std::endl;
89 return;
92 readBindMaterial(bindMat);
95 ColladaGeometry *
96 ColladaInstanceGeometry::getTargetElem(void) const
98 ColladaGeometry *retVal = NULL;
99 daeElementRef targetElem = getTargetDOMElem();
101 if(targetElem != NULL)
103 retVal = getUserDataAs<ColladaGeometry>(targetElem);
106 return retVal;
109 daeElement *
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());
120 return retVal;
123 const ColladaInstanceGeometry::MaterialMap &
124 ColladaInstanceGeometry::getMaterialMap(void) const
126 return _matMap;
129 ColladaInstanceGeometry::ColladaInstanceGeometry(
130 daeElement *elem, ColladaGlobal *global)
132 : Inherited(elem, global)
133 , _matMap ()
137 ColladaInstanceGeometry::~ColladaInstanceGeometry(void)
141 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 &params = bindMat->getParam_array();
173 if(params.getCount() > 0)
175 SWARNING << "ColladaInstanceGeometry::readBindMaterial: "
176 << "Ignoring [" << params.getCount()
177 << "] <param> elements." << std::endl;
181 OSG_END_NAMESPACE
183 #endif // OSG_WITH_COLLADA