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 "OSGColladaAnimationClip.h"
45 #ifdef OSG_WITH_COLLADA
47 #include "OSGColladaLog.h"
48 #include "OSGColladaGlobal.h"
49 #include "OSGColladaElementFactory.h"
50 #include "OSGColladaInstanceAnimation.h"
52 #include <dom/domAnimation_clip.h>
56 ColladaElementRegistrationHelper
ColladaAnimationClip::_regHelper(
57 &ColladaAnimationClip::create
, "animation_clip");
60 ColladaElementTransitPtr
61 ColladaAnimationClip::create(daeElement
*elem
, ColladaGlobal
*global
)
63 return ColladaElementTransitPtr(new ColladaAnimationClip(elem
, global
));
67 ColladaAnimationClip::read(ColladaElement
*colElemParent
)
69 domAnimation_clipRef animClip
= getDOMElementAs
<domAnimation_clip
>();
71 OSG_COLLADA_LOG(("ColladaAnimationClip::read: id [%s]\n",
74 #if !defined(OSG_USE_COLLADA_ANIMCLIP_INSTANCE_HACK)
76 AnimKeyFrameTemplateUnrecPtr animTmpl
= AnimKeyFrameTemplate::create();
77 getGlobal()->getGlobalsAtt()->editMFElements()->push_back(animTmpl
);
79 const domInstanceWithExtra_Array
&animInsts
=
80 animClip
->getInstance_animation_array();
82 for(UInt32 i
= 0; i
< animInsts
.getCount(); ++i
)
84 ColladaInstanceAnimationRefPtr colInstAnim
=
85 getUserDataAs
<ColladaInstanceAnimation
>(animInsts
[i
]);
87 if(colInstAnim
== NULL
)
89 colInstAnim
= dynamic_pointer_cast
<ColladaInstanceAnimation
>(
90 ColladaElementFactory::the()->create(
91 animInsts
[i
], getGlobal(), "instance_animation"));
93 colInstAnim
->read(this);
96 ColladaInstInfoRefPtr animInstInfo
=
97 ColladaAnimation::ColladaAnimationInstInfo::create(
98 this, colInstAnim
, NULL
, animTmpl
);
100 getGlobal()->editInstQueue().push_back(animInstInfo
);
105 // add anim template to the globals attachment
106 AnimKeyFrameTemplateUnrecPtr animTmpl
= AnimKeyFrameTemplate::create();
107 getGlobal()->getGlobalsAtt()->editMFElements()->push_back(animTmpl
);
109 domCOLLADA
*docRoot
= getGlobal()->getDocRoot();
110 const domLibrary_animations_Array
&libAnims
=
111 docRoot
->getLibrary_animations_array();
113 for(UInt32 i
= 0; i
< libAnims
.getCount(); ++i
)
115 const domAnimation_Array
&anims
= libAnims
[i
]->getAnimation_array();
117 for(UInt32 j
= 0; j
< anims
.getCount(); ++j
)
119 ColladaAnimationRefPtr colAnim
=
120 getUserDataAs
<ColladaAnimation
>(anims
[j
]);
124 colAnim
= dynamic_pointer_cast
<ColladaAnimation
>(
125 ColladaElementFactory::the()->create(
126 anims
[j
], getGlobal(), "animation"));
132 ColladaInstInfoRefPtr animInstInfo
=
133 ColladaAnimation::ColladaAnimationInstInfo::create(
134 this, NULL
, colAnim
, animTmpl
);
136 getGlobal()->editInstQueue().push_back(animInstInfo
);
139 #endif // OSG_USE_COLLADA_ANIMCLIP_INSTANCE_HACK
142 ColladaAnimationClip::ColladaAnimationClip(
143 daeElement
*elem
, ColladaGlobal
*global
)
145 : Inherited(elem
, global
)
149 ColladaAnimationClip::~ColladaAnimationClip(void)
155 #endif // OSG_WITH_COLLADA