fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Collada / OSGColladaAnimationClip.cpp
blobd88da5347364af18bd66d567022d97c627571c11
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 "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>
54 OSG_BEGIN_NAMESPACE
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));
66 void
67 ColladaAnimationClip::read(ColladaElement *colElemParent)
69 domAnimation_clipRef animClip = getDOMElementAs<domAnimation_clip>();
71 OSG_COLLADA_LOG(("ColladaAnimationClip::read: id [%s]\n",
72 animClip->getId()));
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);
103 #else
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]);
122 if(colAnim == NULL)
124 colAnim = dynamic_pointer_cast<ColladaAnimation>(
125 ColladaElementFactory::the()->create(
126 anims[j], getGlobal(), "animation"));
128 colAnim->read(this);
131 // queue an instance
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)
153 OSG_END_NAMESPACE
155 #endif // OSG_WITH_COLLADA