changed: gcc8 base update
[opensg.git] / Source / System / FileIO / Collada / ExtraHandler / OSGColladaMayaExtraHandler.cpp
blobb4880360f1d2f4858e96ca896018fa19551c8ad5
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 "OSGColladaMayaExtraHandler.h"
44 #include "OSGColladaLog.h"
45 #include "OSGColladaGeometry.h"
46 #include "OSGColladaTexture.h"
48 #ifdef OSG_WITH_COLLADA
51 OSG_BEGIN_NAMESPACE
53 ColladaExtraHandlerRegHelper ColladaMayaExtraHandler::_regHelper(
54 &ColladaMayaExtraHandler::create);
56 ColladaExtraHandlerTransitPtr ColladaMayaExtraHandler::create(void)
58 ColladaExtraHandlerTransitPtr returnValue(new ColladaMayaExtraHandler);
60 return returnValue;
63 void ColladaMayaExtraHandler::readTextureExtraElements(
64 ColladaTexture *texture,
65 const domExtra *extra )
67 OSG_COLLADA_LOG(("ColladaMayaExtraHandler::readTextureParams %p %p\n",
68 texture,
69 extra ));
71 const domTechnique_Array &extraTechniques = extra->getTechnique_array();
73 for(UInt32 j = 0; j < extraTechniques.getCount(); ++j)
75 xsNMTOKEN extraProfile = extraTechniques[j]->getProfile();
77 OSG_COLLADA_LOG(("Found extra profile %s\n",
78 extraProfile ));
80 if(osgStringNCmp(extraProfile, "OpenCOLLADAMaya", 15) == 0)
82 OSG_COLLADA_LOG(("processing OpenCOLLADAMaya\n"));
84 const daeElementRefArray &profileElements =
85 extraTechniques[j]->getContents();
87 Vec3f t(0.f, 0.f, 0.f);
88 Vec3f s(1.f, 1.f, 1.f);
89 Quaternion r(0.f, 0.f, 0.f, 1.f);
91 bool bMatrixModified = false;
93 for(UInt32 k = 0; k < profileElements.getCount(); ++k)
95 OSG_COLLADA_LOG(("prElemName : %s | %s\n",
96 profileElements[k]->getElementName(),
97 profileElements[k]->getCharData().c_str()));
99 if(osgStringNCmp(profileElements[k]->getElementName(),
100 "blend_mode",
101 10 ) == 0)
104 else if(osgStringNCmp(profileElements[k]->getElementName(),
105 "coverageU",
106 9 ) == 0)
109 else if(osgStringNCmp(profileElements[k]->getElementName(),
110 "coverageV",
111 9 ) == 0)
114 else if(osgStringNCmp(profileElements[k]->getElementName(),
115 "fast",
116 4 ) == 0)
119 else if(osgStringNCmp(profileElements[k]->getElementName(),
120 "mirrorU",
121 7 ) == 0)
123 UInt32 mirrorU = TypeTraits<UInt32>::getFromCString(
124 profileElements[k]->getCharData().c_str());
126 if(mirrorU == 1)
128 s[0] *= -1.f;
131 bMatrixModified = true;
133 else if(osgStringNCmp(profileElements[k]->getElementName(),
134 "mirrorV",
135 7 ) == 0)
137 UInt32 mirrorV = TypeTraits<UInt32>::getFromCString(
138 profileElements[k]->getCharData().c_str());
140 if(mirrorV == 1)
142 s[1] *= -1.f;
145 bMatrixModified = true;
147 else if(osgStringNCmp(profileElements[k]->getElementName(),
148 "noiseU",
149 6 ) == 0)
152 else if(osgStringNCmp(profileElements[k]->getElementName(),
153 "noiseV",
154 6 ) == 0)
157 else if(osgStringNCmp(profileElements[k]->getElementName(),
158 "offsetU",
159 7 ) == 0)
161 t[0] = TypeTraits<Real32>::getFromCString(
162 profileElements[k]->getCharData().c_str());
164 bMatrixModified = true;
166 else if(osgStringNCmp(profileElements[k]->getElementName(),
167 "offsetV",
168 7 ) == 0)
170 t[1] = TypeTraits<Real32>::getFromCString(
171 profileElements[k]->getCharData().c_str());
173 bMatrixModified = true;
175 else if(osgStringNCmp(profileElements[k]->getElementName(),
176 "repeatU",
177 7 ) == 0)
179 s[0] *= TypeTraits<Real32>::getFromCString(
180 profileElements[k]->getCharData().c_str());
182 bMatrixModified = true;
184 else if(osgStringNCmp(profileElements[k]->getElementName(),
185 "repeatV",
186 7 ) == 0)
188 s[1] *= TypeTraits<Real32>::getFromCString(
189 profileElements[k]->getCharData().c_str());
191 bMatrixModified = true;
193 else if(osgStringNCmp(profileElements[k]->getElementName(),
194 "rotateFrame",
195 11 ) == 0)
198 else if(osgStringNCmp(profileElements[k]->getElementName(),
199 "rotateUV",
200 8 ) == 0)
202 r.setValueAsAxisDeg(
203 0.f, 1.f, 0.f,
204 TypeTraits<Real32>::getFromCString(
205 profileElements[k]->getCharData().c_str()));
207 else if(osgStringNCmp(profileElements[k]->getElementName(),
208 "stagger",
209 7 ) == 0)
212 else if(osgStringNCmp(profileElements[k]->getElementName(),
213 "translateFrameU",
214 15 ) == 0)
217 else if(osgStringNCmp(profileElements[k]->getElementName(),
218 "translateFrameV",
219 15 ) == 0)
222 else if(osgStringNCmp(profileElements[k]->getElementName(),
223 "wrapU",
224 5 ) == 0)
226 UInt32 wrapU = TypeTraits<UInt32>::getFromCString(
227 profileElements[k]->getCharData().c_str());
229 TextureObjChunk *pTex = texture->getTexture();
231 if(wrapU == 1)
233 pTex->setWrapS(GL_REPEAT);
235 else
237 pTex->setWrapS(GL_CLAMP_TO_BORDER);
240 else if(osgStringNCmp(profileElements[k]->getElementName(),
241 "wrapV",
242 5 ) == 0)
244 UInt32 wrapV = TypeTraits<UInt32>::getFromCString(
245 profileElements[k]->getCharData().c_str());
247 TextureObjChunk *pTex = texture->getTexture();
249 if(wrapV == 1)
251 pTex->setWrapT(GL_REPEAT);
253 else
255 pTex->setWrapT(GL_CLAMP_TO_BORDER);
258 else
260 OSG_COLLADA_LOG(("ColladaMayaExtraHandler::readTexParam: "
261 "unknown OpenColladaMaya parameter %s\n",
262 profileElements[k]->getElementName()));
266 if(bMatrixModified == true)
268 TextureTransformChunk *pTexTr = texture->editTexTransform();
270 pTexTr->editMatrix().setTransform(t, r, s);
273 else if(osgStringNCmp(extraProfile, "MAYA", 4) == 0)
275 OSG_COLLADA_LOG(("processing MAYA\n"));
277 const daeElementRefArray &profileElements =
278 extraTechniques[j]->getContents();
280 for(UInt32 k = 0; k < profileElements.getCount(); ++k)
282 OSG_COLLADA_LOG(("prElemName : %s | %s\n",
283 profileElements[k]->getElementName(),
284 profileElements[k]->getCharData().c_str()));
286 if(osgStringNCmp(profileElements[k]->getElementName(),
287 "wrapU",
288 5 ) == 0)
290 bool wrapU = TypeTraits<bool>::getFromCString(
291 profileElements[k]->getCharData().c_str());
293 TextureObjChunk *pTex = texture->getTexture();
295 if(wrapU == true)
297 pTex->setWrapS(GL_REPEAT);
299 else
301 pTex->setWrapS(GL_CLAMP_TO_BORDER);
304 else if(osgStringNCmp(profileElements[k]->getElementName(),
305 "wrapV",
306 5 ) == 0)
308 bool wrapV = TypeTraits<bool>::getFromCString(
309 profileElements[k]->getCharData().c_str());
311 TextureObjChunk *pTex = texture->getTexture();
313 if(wrapV == true)
315 pTex->setWrapT(GL_REPEAT);
317 else
319 pTex->setWrapT(GL_CLAMP_TO_BORDER);
322 else
324 OSG_COLLADA_LOG(("ColladaMayaExtraHandler::readTexParam:"
325 "MAYA : unknown parameter %s\n",
326 profileElements[k]->getElementName()));
333 void ColladaMayaExtraHandler::readTechniqueExtraElements(
334 ColladaEffect *effect,
335 const domExtra *extra )
339 void ColladaMayaExtraHandler::readProfileExtraElements(
340 ColladaEffect *effect,
341 const domExtra *extra )
345 void ColladaMayaExtraHandler::readGeometryExtraElements(
346 ColladaGeometry *geometry,
347 const domExtra *extra )
349 OSG_COLLADA_LOG(("ColladaMayaExtraHandler::readGeoExtraElems %p %p\n",
350 geometry,
351 extra ));
353 const domTechnique_Array &extraTechniques = extra->getTechnique_array();
355 for(UInt32 j = 0; j < extraTechniques.getCount(); ++j)
357 xsNMTOKEN extraProfile = extraTechniques[j]->getProfile();
359 OSG_COLLADA_LOG(("Found extra profile %s\n",
360 extraProfile ));
362 if(osgStringNCmp(extraProfile, "OpenCOLLADAMaya", 15) == 0)
364 OSG_COLLADA_LOG(("processing\n"));
366 const daeElementRefArray &profileElements =
367 extraTechniques[j]->getContents();
369 for(UInt32 k = 0; k < profileElements.getCount(); ++k)
371 OSG_COLLADA_LOG(("prElemName : %s | %s\n",
372 profileElements[k]->getElementName(),
373 profileElements[k]->getCharData().c_str()));
376 if(osgStringNCmp(profileElements[k]->getElementName(),
377 "double_sided",
378 12 ) == 0)
380 bool doubleSided =
381 TypeTraits<UInt32>::getFromCString(
382 profileElements[k]->getCharData().c_str()) != 0;
384 geometry->setDoubleSided(doubleSided);
391 void ColladaMayaExtraHandler::instProfileExtraElements(ColladaEffect *effect,
392 Material *pMat )
397 ColladaMayaExtraHandler::ColladaMayaExtraHandler(void) :
398 Inherited()
402 ColladaMayaExtraHandler::~ColladaMayaExtraHandler(void)
406 OSG_END_NAMESPACE
408 #endif // OSG_WITH_COLLADA