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 "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"
52 #include "OSGNameAttachment.h"
54 #include <dom/domVisual_scene.h>
58 ColladaInstInfoTransitPtr
59 ColladaVisualScene::ColladaVisualSceneInstInfo::create(
60 ColladaScene
*colInstParent
, ColladaInstanceVisualScene
*colInst
)
62 return ColladaInstInfoTransitPtr(
63 new ColladaVisualSceneInstInfo(colInstParent
, colInst
));
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
,
89 // ===========================================================================
91 ColladaElementTransitPtr
92 ColladaVisualScene::create(daeElement
*elem
, ColladaGlobal
*global
)
94 return ColladaElementTransitPtr(new ColladaVisualScene(elem
, global
));
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
]);
118 colNode
= dynamic_pointer_cast
<ColladaNode
>(
119 ColladaElementFactory::the()->create(nodes
[i
], getGlobal()));
123 ColladaInstInfoRefPtr colInstInfo
=
124 ColladaNode::ColladaNodeInstInfo::create(this, NULL
, rootN
);
126 colNode
->createInstance(colInstInfo
);
128 if(childN
->getParent() != NULL
)
131 << "ColladaVisualScene::read: <node> [" << i
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
);
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)
171 #endif // OSG_WITH_COLLADA