~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to COLLADAStreamWriter/src/COLLADASWLibraryAnimations.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
        This file is part of COLLADAStreamWriter.
 
5
        
 
6
    Licensed under the MIT Open Source License, 
 
7
    for details please see LICENSE file or the website
 
8
    http://www.opensource.org/licenses/mit-license.php
 
9
*/
 
10
 
 
11
#include "COLLADASWStreamWriter.h"
 
12
#include "COLLADASWLibraryAnimations.h"
 
13
#include "COLLADASWConstants.h"
 
14
#include "COLLADABUUtils.h"
 
15
 
 
16
namespace COLLADASW
 
17
{
 
18
 
 
19
    const String LibraryAnimations::LINEAR_NAME = "LINEAR";
 
20
    const String LibraryAnimations::BEZIER_NAME = "BEZIER";
 
21
    const String LibraryAnimations::CARDINAL_NAME = "CARDINAL";
 
22
    const String LibraryAnimations::HERMITE_NAME = "HERMITE";
 
23
    const String LibraryAnimations::BSPLINE_NAME = "BSPLINE";
 
24
    const String LibraryAnimations::TCB_NAME = "TCB";
 
25
    const String LibraryAnimations::STEP_NAME = "STEP";
 
26
 
 
27
 
 
28
    const String LibraryAnimations::INPUT_SOURCE_ID_SUFFIX = "-input";
 
29
    const String LibraryAnimations::OUTPUT_SOURCE_ID_SUFFIX = "-output";
 
30
    const String LibraryAnimations::INTANGENT_SOURCE_ID_SUFFIX = "-intangent";
 
31
    const String LibraryAnimations::OUTTANGENT_SOURCE_ID_SUFFIX = "-outtangent";
 
32
    const String LibraryAnimations::INTERPOLATION_SOURCE_ID_SUFFIX = "-interpolation";
 
33
    const String LibraryAnimations::TCBS_SOURCE_ID_SUFFIX = "-tcbs";
 
34
    const String LibraryAnimations::EASES_SOURCE_ID_SUFFIX = "-eases";
 
35
    const String LibraryAnimations::ARRAY_ID_SUFFIX = "-array";
 
36
 
 
37
    const String LibraryAnimations::SAMPLER_ID_SUFFIX = "-sampler";
 
38
 
 
39
 
 
40
    //---------------------------------------------------------------
 
41
    void Animation::openAnimation ( const String & id, const String & name )
 
42
    {
 
43
        // Open a <animation> element
 
44
        mAnimationCloser = mSW->openElement ( CSWC::CSW_ELEMENT_ANIMATION );
 
45
 
 
46
        // Write the id and the name, if they are set.
 
47
 
 
48
        if ( !id.empty() )
 
49
            mSW->appendAttribute ( CSWC::CSW_ATTRIBUTE_ID, id );
 
50
 
 
51
        if ( !name.empty() )
 
52
            mSW->appendAttribute ( CSWC::CSW_ATTRIBUTE_NAME, name );
 
53
    }
 
54
 
 
55
 
 
56
    //---------------------------------------------------------------
 
57
    void Animation::closeAnimation()
 
58
    {
 
59
        mAnimationCloser.close();
 
60
    }
 
61
 
 
62
    //---------------------------------------------------------------
 
63
    LibraryAnimations::LibraryAnimations ( COLLADASW::StreamWriter * streamWriter )
 
64
            : Library ( streamWriter, CSWC::CSW_ELEMENT_LIBRARY_ANIMATIONS ), mOpenAnimations ( NULL )
 
65
    {}
 
66
 
 
67
    //---------------------------------------------------------------
 
68
    void LibraryAnimations::openAnimation ( const String& animationId, const String& animationName )
 
69
    {
 
70
        // Open the tag <library_animations> if it is not already open
 
71
        openLibrary();
 
72
 
 
73
        Animation* animation = new Animation ( mSW );
 
74
        animation->openAnimation ( animationId, animationName );
 
75
 
 
76
        mOpenAnimations.push_back ( animation );
 
77
    }
 
78
 
 
79
    //---------------------------------------------------------------
 
80
    void LibraryAnimations::closeAnimation()
 
81
    {
 
82
        Animation* animation = mOpenAnimations.back();
 
83
        animation->closeAnimation();
 
84
        delete animation;
 
85
 
 
86
        // Erases the animation element from the list.
 
87
        mOpenAnimations.pop_back();
 
88
    }
 
89
 
 
90
    //---------------------------------------------------------------
 
91
    const String & LibraryAnimations::getNameOfInterpolation ( const InterpolationType & type )
 
92
    {
 
93
        switch ( type )
 
94
        {
 
95
 
 
96
        case LINEAR:
 
97
            return LINEAR_NAME;
 
98
 
 
99
        case BEZIER:
 
100
            return BEZIER_NAME;
 
101
 
 
102
        case CARDINAL:
 
103
            return CARDINAL_NAME;
 
104
 
 
105
        case HERMITE:
 
106
            return HERMITE_NAME;
 
107
 
 
108
        case BSPLINE:
 
109
            return BSPLINE_NAME;
 
110
 
 
111
        case STEP:
 
112
            return STEP_NAME;
 
113
 
 
114
        default:
 
115
            return EMPTY_STRING;
 
116
        }
 
117
    }
 
118
 
 
119
    //---------------------------------------------------------------
 
120
    void LibraryAnimations::addSampler ( const Sampler & sampler )
 
121
    {
 
122
 
 
123
        mSW->openElement ( CSWC::CSW_ELEMENT_SAMPLER );
 
124
        mSW->appendAttribute ( CSWC::CSW_ATTRIBUTE_ID, sampler.getId() );
 
125
 
 
126
        const InputList & inputList = sampler.getInputList();
 
127
 
 
128
                inputList.add();
 
129
 
 
130
        mSW->closeElement();
 
131
    }
 
132
 
 
133
    //---------------------------------------------------------------
 
134
    void LibraryAnimations::addChannel ( const URI& source, const String& target )
 
135
    {
 
136
        mSW->openElement ( CSWC::CSW_ELEMENT_CHANNEL );
 
137
        mSW->appendURIAttribute ( CSWC::CSW_ATTRIBUTE_SOURCE, source );
 
138
        mSW->appendAttribute ( CSWC::CSW_ATTRIBUTE_TARGET, target );
 
139
        mSW->closeElement();
 
140
    }
 
141
 
 
142
    //---------------------------------------------------------------
 
143
        void LibraryAnimations::Sampler::addInput ( InputSemantic::Semantics semantic, const URI& source )
 
144
    {
 
145
        Input input(semantic, source);
 
146
        mInputList.push_back ( input );
 
147
    }
 
148
 
 
149
        //------------------------------
 
150
        LibraryAnimations::Sampler::Sampler( StreamWriter * streamWriter, const String& id ) 
 
151
                : mId ( id )
 
152
                , mInputList(streamWriter)
 
153
        {
 
154
 
 
155
        }
 
156
 
 
157
} //namespace COLLADASW