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 "OSGColladaInstanceController.h"
45 #ifdef OSG_WITH_COLLADA
47 #include "OSGColladaLog.h"
49 #include <dom/domInstance_controller.h>
50 #include <dom/domNode.h>
51 #include <dom/domInstance_node.h>
52 #include <dae/daeSIDResolver.h>
56 ColladaElementRegistrationHelper
ColladaInstanceController::_regHelper(
57 &ColladaInstanceController::create
, "instance_controller");
60 ColladaElementTransitPtr
61 ColladaInstanceController::create(daeElement
*elem
, ColladaGlobal
*global
)
63 return ColladaElementTransitPtr(
64 new ColladaInstanceController(elem
, global
));
68 ColladaInstanceController::read(ColladaElement
*colElemParent
)
70 OSG_COLLADA_LOG(("ColladaInstanceController::read\n"));
72 ColladaControllerRefPtr colCtrl
= getTargetElem();
76 colCtrl
= dynamic_pointer_cast
<ColladaController
>(
77 ColladaElementFactory::the()->create(
78 getTargetDOMElem(), getGlobal()));
83 domInstance_controllerRef instCtrl
=
84 getDOMElementAs
<domInstance_controller
>();
85 domBind_materialRef bindMat
= instCtrl
->getBind_material();
89 Inherited::readBindMaterial(bindMat
);
94 SWARNING
<< "ColladaInstanceController::read: "
95 << "No <bind_material> found." << std::endl
;
101 const ColladaInstanceController::SkeletonRootStore
&
102 ColladaInstanceController::getSkeletonRoots(void)
108 ColladaInstanceController::findJointNode(const std::string
&jointSid
)
110 domNode
*retVal
= NULL
;
111 SkeletonRootStoreConstIt sIt
= _skelRoots
.begin();
112 SkeletonRootStoreConstIt sEnd
= _skelRoots
.end ();
114 for(UInt32 i
= 0; sIt
!= sEnd
; ++sIt
, ++i
)
116 daeSidRef
jointRef(jointSid
, *sIt
);
118 retVal
= daeSafeCast
<domNode
>(jointRef
.resolve().elt
);
122 OSG_COLLADA_LOG(("ColladaInstanceController::findJointNode: "
123 "Found joint [%s] relative to root [%d][%s]\n",
125 ((*sIt
)->getId() != NULL
? (*sIt
)->getId() : "")));
131 OSG_COLLADA_LOG(("ColladaInstanceController::findJointNode: "
132 "joint [%s] not found below root [%d][%s]\n",
134 ((*sIt
)->getId() != NULL
? (*sIt
)->getId() : "")));
142 ColladaInstanceController::getTargetElem(void) const
144 ColladaController
*retVal
= NULL
;
145 daeElementRef targetElem
= getTargetDOMElem();
147 if(targetElem
!= NULL
)
149 retVal
= getUserDataAs
<ColladaController
>(targetElem
);
156 ColladaInstanceController::getTargetDOMElem(void) const
158 domControllerRef retVal
= NULL
;
159 domInstance_controllerRef instCtrl
=
160 getDOMElementAs
<domInstance_controller
>();
162 if(instCtrl
->getUrl().getElement() != NULL
)
164 retVal
= daeSafeCast
<domController
>(instCtrl
->getUrl().getElement());
170 ColladaInstanceController::ColladaInstanceController(
171 daeElement
*elem
, ColladaGlobal
*global
)
173 : Inherited (elem
, global
)
178 ColladaInstanceController::~ColladaInstanceController(void)
183 ColladaInstanceController::readSkeleton(void)
185 domInstance_controllerRef instCtrl
=
186 getDOMElementAs
<domInstance_controller
>();
187 const domInstance_controller::domSkeleton_Array
&skels
=
188 instCtrl
->getSkeleton_array();
190 for(UInt32 i
= 0; i
< skels
.getCount(); ++i
)
192 OSG_COLLADA_LOG(("ColladaInstanceController::readSkeleton: "
193 "Skeleton root node: [%s]\n",
194 skels
[i
]->getValue().getURI()));
196 daeURI skelURI
= skels
[i
]->getValue();
197 domNode
*skelNode
= daeSafeCast
<domNode
>(skelURI
.getElement());
201 SWARNING
<< "ColladaInstanceController::readSkeleton: "
202 << "<skeleton> tag does not refer to a <node>, URI ["
203 << skelURI
.str() << "]. Ignored." << std::endl
;
207 _skelRoots
.push_back(skelNode
);
211 #if 0 // obsolete, using daeSidRef instead
213 ColladaInstanceController::findJointNode(
214 const std::string
&jointSid
, domNode
*currNode
)
219 domNode
*retVal
= NULL
;
220 std::string currSid
= currNode
->getSid();
222 if(jointSid
== currSid
)
228 const daeElementRefArray
&contents
= currNode
->getContents();
230 for(UInt32 i
= 0; i
< contents
.getCount(); ++i
)
232 if(contents
[i
]->typeID() == domNode::ID())
234 retVal
= findJointNode(
235 jointSid
, daeSafeCast
<domNode
>(contents
[i
]));
238 else if(contents
[i
]->typeID() == domInstance_node::ID())
240 retVal
= findJointNode(
241 jointSid
, daeSafeCast
<domInstance_node
>(contents
[i
]));
253 ColladaInstanceController::findJointNode(
254 const std::string
&jointSid
, domInstance_node
*currNode
)
259 domNode
*targetNode
=
260 daeSafeCast
<domNode
>(currNode
->getUrl().getElement());
262 return findJointNode(jointSid
, targetNode
);
264 #endif // obsolete, using daeSidRef instead
268 #endif // OSG_WITH_COLLADA