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 "OSGColladaMaterial.h"
45 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
47 #include "OSGColladaGlobal.h"
48 #include "OSGColladaInstanceEffect.h"
49 #include "OSGColladaInstanceMaterial.h"
50 #include "OSGColladaLog.h"
51 #include "OSGNameAttachment.h"
53 #include <dom/domMaterial.h>
54 #include <dom/domInstance_effect.h>
58 ColladaInstInfoTransitPtr
59 ColladaMaterial::ColladaMaterialInstInfo::create(
60 ColladaElement
*colInstParent
, ColladaInstanceMaterial
*colInst
)
62 return ColladaInstInfoTransitPtr(
63 new ColladaMaterialInstInfo(colInstParent
, colInst
));
67 ColladaMaterial::ColladaMaterialInstInfo::process(void)
69 SFATAL
<< "ColladaMaterialInstInfo::process called!" << std::endl
;
72 ColladaMaterial::ColladaMaterialInstInfo::ColladaMaterialInstInfo(
73 ColladaElement
*colInstParent
, ColladaInstanceMaterial
*colInst
)
75 : Inherited(colInstParent
, colInst
)
79 ColladaMaterial::ColladaMaterialInstInfo::~ColladaMaterialInstInfo(void)
83 // ===========================================================================
85 ColladaElementRegistrationHelper
ColladaMaterial::_regHelper(
86 &ColladaMaterial::create
, "material");
89 ColladaElementTransitPtr
90 ColladaMaterial::create(daeElement
*elem
, ColladaGlobal
*global
)
92 return ColladaElementTransitPtr(new ColladaMaterial(elem
, global
));
96 ColladaMaterial::read(ColladaElement
*colElemParent
)
98 OSG_COLLADA_LOG(("ColladaMaterial::read\n"));
100 domMaterialRef material
= getDOMElementAs
<domMaterial
>();
101 domInstance_effectRef instEffect
= material
->getInstance_effect();
102 ColladaInstanceEffectRefPtr colInstEffect
=
103 getUserDataAs
<ColladaInstanceEffect
>(instEffect
);
105 if(colInstEffect
== NULL
)
107 colInstEffect
= dynamic_pointer_cast
<ColladaInstanceEffect
>(
108 ColladaElementFactory::the()->create(instEffect
, getGlobal()));
110 colInstEffect
->read(this);
115 ColladaMaterial::createInstance(ColladaInstInfo
*colInstInfo
)
117 OSG_COLLADA_LOG(("ColladaMaterial::createInstance\n"));
119 MaterialUnrecPtr retVal
= NULL
;
120 domMaterialRef material
= getDOMElementAs
<domMaterial
>();
121 domInstance_effectRef instEffect
= material
->getInstance_effect();
122 ColladaInstanceEffectRefPtr colInstEffect
=
123 getUserDataAs
<ColladaInstanceEffect
>(instEffect
);
125 if(getInstStore().empty() == true)
127 OSG_ASSERT(colInstEffect
!= NULL
);
128 OSG_ASSERT(colInstEffect
->getTargetElem() != NULL
);
130 ColladaInstInfoRefPtr colEffectInstInfo
=
131 ColladaEffect::ColladaEffectInstInfo::create(this, colInstEffect
);
133 retVal
= colInstEffect
->getTargetElem()->createInstance(
136 if(getGlobal()->getOptions()->getCreateNameAttachments() == true &&
137 material
->getName() != NULL
)
139 setName(retVal
, material
->getName());
142 editInstStore().push_back(retVal
);
146 retVal
= dynamic_pointer_cast
<Material
>(getInstStore()[0]);
148 getGlobal()->getStatCollector()->getElem(
149 ColladaGlobal::statNMaterialUsed
)->inc();
155 ColladaMaterial::ColladaMaterial(daeElement
*elem
, ColladaGlobal
*global
)
156 : Inherited(elem
, global
)
160 ColladaMaterial::~ColladaMaterial(void)
166 #endif // OSG_WITH_COLLADA