changed: gcc8 base update
[opensg.git] / Source / System / FileIO / Collada / OSGColladaVisualScene.cpp
blob7a12f3ac538b4cd5d328fa1b79be3cf5a63b9f04
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 "OSGColladaVisualScene.h"
45 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
47 #include "OSGColladaLog.h"
48 #include "OSGColladaInstanceVisualScene.h"
49 #include "OSGColladaNode.h"
50 #include "OSGColladaScene.h"
51 #include "OSGGroup.h"
52 #include "OSGNameAttachment.h"
54 #include <dom/domVisual_scene.h>
56 OSG_BEGIN_NAMESPACE
58 ColladaInstInfoTransitPtr
59 ColladaVisualScene::ColladaVisualSceneInstInfo::create(
60 ColladaScene *colInstParent, ColladaInstanceVisualScene *colInst)
62 return ColladaInstInfoTransitPtr(
63 new ColladaVisualSceneInstInfo(colInstParent, colInst));
66 void
67 ColladaVisualScene::ColladaVisualSceneInstInfo::process(void)
69 SFATAL << "ColladaVisualSceneInstInfo::process called!" << std::endl;
72 ColladaVisualScene::ColladaVisualSceneInstInfo::ColladaVisualSceneInstInfo(
73 ColladaScene *colInstParent, ColladaInstanceVisualScene *colInst)
75 : Inherited(colInstParent, colInst)
79 ColladaVisualScene::ColladaVisualSceneInstInfo::~ColladaVisualSceneInstInfo(void)
83 // ===========================================================================
85 ColladaElementRegistrationHelper ColladaVisualScene::_regHelper(
86 &ColladaVisualScene::create,
87 "visual_scene" );
89 // ===========================================================================
91 ColladaElementTransitPtr
92 ColladaVisualScene::create(daeElement *elem, ColladaGlobal *global)
94 return ColladaElementTransitPtr(new ColladaVisualScene(elem, global));
97 void
98 ColladaVisualScene::read(ColladaElement *colElemParent)
100 OSG_COLLADA_LOG(("ColladaVisualScene::read\n"));
102 domVisual_sceneRef visScene = getDOMElementAs<domVisual_scene>();
103 const domNode_Array &nodes = visScene->getNode_array ();
104 NodeUnrecPtr rootN = makeCoredNode<Group> ();
106 if(getGlobal()->getOptions()->getCreateNameAttachments() == true &&
107 visScene->getName() != NULL )
109 setName(rootN, visScene->getName());
112 for(UInt32 i = 0; i < nodes.getCount(); ++i)
114 ColladaNodeRefPtr colNode = getUserDataAs<ColladaNode>(nodes[i]);
116 if(colNode == NULL)
118 colNode = dynamic_pointer_cast<ColladaNode>(
119 ColladaElementFactory::the()->create(nodes[i], getGlobal()));
121 colNode->read(this);
123 ColladaInstInfoRefPtr colInstInfo =
124 ColladaNode::ColladaNodeInstInfo::create(this, NULL, rootN);
125 Node *childN =
126 colNode->createInstance(colInstInfo);
128 if(childN->getParent() != NULL)
130 SWARNING
131 << "ColladaVisualScene::read: <node> [" << i
132 << "] name ["
133 << (getName(childN) != NULL ? getName(childN) : "")
134 << "] already has a parent ["
135 << (getName(childN->getParent()) != NULL ?
136 getName(childN->getParent()) : "")
137 << "]." << std::endl;
140 // don't add joints to the scene hierarchy
142 if(colNode->isJoint() == false)
143 rootN->addChild(childN);
146 editInstStore().push_back(rootN);
149 Node *
150 ColladaVisualScene::createInstance(ColladaInstInfo *colInstInfo)
152 OSG_COLLADA_LOG(("ColladaVisualScene::createInstance\n"));
154 // can only have one <instance_visual_scene> tag
155 OSG_ASSERT(getInstStore().size() == 1);
157 return dynamic_pointer_cast<Node>(editInstStore().front());
160 ColladaVisualScene::ColladaVisualScene(daeElement *elem, ColladaGlobal *global)
161 : Inherited(elem, global)
165 ColladaVisualScene::~ColladaVisualScene(void)
169 OSG_END_NAMESPACE
171 #endif // OSG_WITH_COLLADA