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 "OSGColladaInstanceMaterial.h"
45 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
47 #include "OSGColladaLog.h"
48 #include "OSGColladaInstanceEffect.h"
50 #include <dom/domInstance_material.h>
54 ColladaElementRegistrationHelper
ColladaInstanceMaterial::_regHelper(
55 &ColladaInstanceMaterial::create
, "instance_material");
57 ColladaElementTransitPtr
58 ColladaInstanceMaterial::create(daeElement
*elem
, ColladaGlobal
*global
)
60 return ColladaElementTransitPtr(new ColladaInstanceMaterial(elem
, global
));
64 ColladaInstanceMaterial::read(ColladaElement
*colElemParent
)
66 OSG_COLLADA_LOG(("ColladaInstanceMaterial::read\n"));
68 domInstance_materialRef instMat
=
69 getDOMElementAs
<domInstance_material
>();
70 ColladaMaterialRefPtr colMat
= getTargetElem();
74 colMat
= dynamic_pointer_cast
<ColladaMaterial
>(
75 ColladaElementFactory::the()->create(
76 getTargetDOMElem(), getGlobal()));
81 if(instMat
->getSymbol() != NULL
)
83 _symbol
= instMat
->getSymbol();
87 SFATAL
<< "ColladaInstanceMaterial::read: No symbol."
91 _target
= instMat
->getTarget().str();
93 const domInstance_material::domBind_Array
&binds
=
94 instMat
->getBind_array();
96 _bindStore
.resize(binds
.getCount());
98 for(UInt32 i
= 0; i
< binds
.getCount(); ++i
)
100 std::string target
= binds
[i
]->getTarget();
101 std::string semantic
;
103 if(binds
[i
]->getSemantic() != NULL
)
105 semantic
= binds
[i
]->getSemantic();
108 OSG_COLLADA_LOG(("ColladaInstanceMaterial::read: "
109 "<bind> semantic [%s] target [%s]\n",
110 semantic
.c_str(), target
.c_str()));
112 _bindStore
[i
].semantic
= semantic
;
113 _bindStore
[i
].target
= target
;
116 const domInstance_material::domBind_vertex_input_Array
&bindVerts
=
117 instMat
->getBind_vertex_input_array();
119 _bindVertexStore
.resize(bindVerts
.getCount());
121 for(UInt32 i
= 0; i
< bindVerts
.getCount(); ++i
)
123 std::string semantic
= bindVerts
[i
]->getSemantic ();
124 std::string inSemantic
= bindVerts
[i
]->getInput_semantic();
125 UInt32 inSet
= bindVerts
[i
]->getInput_set ();
127 OSG_COLLADA_LOG(("ColladaInstanceMaterial::read "
128 "<bind_vertex_input> semantic [%s] "
129 "inSemantic [%s] inSet [%d]\n",
130 semantic
.c_str(), inSemantic
.c_str(), inSet
));
132 _bindVertexStore
[i
].semantic
= semantic
;
133 _bindVertexStore
[i
].inSemantic
= inSemantic
;
134 _bindVertexStore
[i
].inSet
= inSet
;
139 ColladaInstanceMaterial::getTargetElem(void) const
141 ColladaMaterial
*retVal
= NULL
;
142 domMaterialRef targetElem
= getTargetDOMElem();
144 if(targetElem
!= NULL
)
146 retVal
= getUserDataAs
<ColladaMaterial
>(targetElem
);
153 ColladaInstanceMaterial::getTargetDOMElem(void) const
155 domMaterialRef retVal
= NULL
;
156 domInstance_materialRef instMat
= getDOMElementAs
<domInstance_material
>();
158 if(instMat
->getTarget().getElement() != NULL
)
160 retVal
= daeSafeCast
<domMaterial
>(instMat
->getTarget().getElement());
167 ColladaInstanceMaterial::getSymbol(void) const
173 ColladaInstanceMaterial::getTarget(void) const
178 const ColladaInstanceMaterial::BindStore
&
179 ColladaInstanceMaterial::getBindStore(void) const
184 const ColladaInstanceMaterial::BindInfo
*
185 ColladaInstanceMaterial::findBindInfo(const std::string
&semantic
) const
187 const BindInfo
*retVal
= NULL
;
189 for(UInt32 i
= 0; i
< _bindStore
.size(); ++i
)
191 if(_bindStore
[i
].semantic
== semantic
)
193 retVal
= &_bindStore
[i
];
201 const ColladaInstanceMaterial::BindVertexStore
&
202 ColladaInstanceMaterial::getBindVertexStore(void) const
204 return _bindVertexStore
;
207 const ColladaInstanceMaterial::BindVertexInfo
*
208 ColladaInstanceMaterial::findBindVertexInfo(
209 const std::string
&inSemantic
, UInt32 inSet
) const
211 const BindVertexInfo
*retVal
= NULL
;
213 for(UInt32 i
= 0; i
< _bindVertexStore
.size(); ++i
)
215 if(_bindVertexStore
[i
].inSemantic
== inSemantic
&&
216 _bindVertexStore
[i
].inSet
== inSet
)
218 retVal
= &_bindVertexStore
[i
];
226 ColladaInstanceEffect
*
227 ColladaInstanceMaterial::getInstanceEffect(void) const
229 domMaterialRef material
= getTargetDOMElem ();
230 domInstance_effectRef instEffect
= material
->getInstance_effect();
232 return getUserDataAs
<ColladaInstanceEffect
>(instEffect
);
235 ColladaInstanceMaterial::ColladaInstanceMaterial(
236 daeElement
*elem
, ColladaGlobal
*global
)
238 : Inherited (elem
, global
)
246 ColladaInstanceMaterial::~ColladaInstanceMaterial(void)
252 #endif // OSG_WITH_COLLADA