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

« back to all changes in this revision

Viewing changes to COLLADAFramework/include/COLLADAFWMeshVertexData.h

  • 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 COLLADAFramework.
 
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
#ifndef __COLLADAFW_MESHINPUTS_H__
 
12
#define __COLLADAFW_MESHINPUTS_H__
 
13
 
 
14
#include "COLLADAFWPrerequisites.h"
 
15
#include "COLLADAFWArrayPrimitiveType.h"
 
16
#include "COLLADAFWFloatOrDoubleArray.h"
 
17
 
 
18
#include <assert.h>
 
19
 
 
20
 
 
21
namespace COLLADAFW
 
22
{
 
23
 
 
24
    /** Base class for mesh input elements, like positions, normals, colors, texcoord, ... */
 
25
        class MeshVertexData : public FloatOrDoubleArray
 
26
    {
 
27
    public:
 
28
 
 
29
        /**
 
30
        * Additional informations about multiple inputs.
 
31
        */
 
32
        struct InputInfos
 
33
        {
 
34
            String mName;
 
35
            size_t mStride;
 
36
            size_t mLength;
 
37
        };
 
38
        typedef ArrayPrimitiveType<InputInfos*> InputInfosArray;
 
39
 
 
40
    private:
 
41
 
 
42
        /** Array with additional informations about multiple input elements. */
 
43
        InputInfosArray mInputInfosArray;
 
44
 
 
45
        public:
 
46
 
 
47
        /** Constructor. */
 
48
        MeshVertexData ()
 
49
            : FloatOrDoubleArray()
 
50
                        , mInputInfosArray (0)
 
51
        {}
 
52
 
 
53
        /** Constructor. */
 
54
                MeshVertexData ( DataType type )
 
55
            : FloatOrDoubleArray(type)
 
56
                        , mInputInfosArray (0)
 
57
        {}
 
58
 
 
59
        /** Destructor. */
 
60
        virtual ~MeshVertexData()
 
61
        {
 
62
            for ( size_t i=0; i<mInputInfosArray.getCount(); ++i )
 
63
            {
 
64
                delete mInputInfosArray [i];
 
65
            }
 
66
            mInputInfosArray.releaseMemory ();
 
67
        }
 
68
 
 
69
        /**
 
70
        * Returns the number of uv sets.
 
71
        */
 
72
        size_t getNumInputInfos () const { return mInputInfosArray.getCount (); }
 
73
 
 
74
                /** Returns the InputInfosArray.*/
 
75
                const InputInfosArray& getInputInfosArray() const { return mInputInfosArray; }
 
76
 
 
77
        /**
 
78
        * Appends the values in the array on the list of values and stores the information
 
79
        * of the current input.
 
80
        * @param const FloatArray& valuesArray The list of values.
 
81
        * @param const String& name The name of the current element.
 
82
        * @param const size_t stride The data stride.
 
83
        */
 
84
        void appendValues ( const FloatArray& valuesArray, const String& name, const size_t stride )
 
85
        {
 
86
            setType ( DATA_TYPE_FLOAT );
 
87
                        FloatOrDoubleArray::appendValues ( valuesArray );
 
88
 
 
89
            InputInfos* info = new InputInfos();
 
90
            info->mLength = valuesArray.getCount ();
 
91
            info->mName = name;
 
92
            info->mStride = stride;
 
93
 
 
94
            mInputInfosArray.append ( info );
 
95
        }
 
96
 
 
97
        /**
 
98
        * Appends the values in the array on the list of values and stores the information
 
99
        * of the current input.
 
100
        * @param const FloatArray& valuesArray The list of values.
 
101
        * @param const String& name The name of the current element.
 
102
        * @param const size_t stride The data stride.
 
103
        */
 
104
        void appendValues ( const DoubleArray& valuesArray, const String& name, const size_t stride )
 
105
        {
 
106
            setType ( DATA_TYPE_DOUBLE );
 
107
                        FloatOrDoubleArray::appendValues ( valuesArray );
 
108
 
 
109
            InputInfos* info = new InputInfos();
 
110
            info->mLength = valuesArray.getCount ();
 
111
            info->mName = name;
 
112
            info->mStride = stride;
 
113
 
 
114
            mInputInfosArray.append ( info );
 
115
        }
 
116
 
 
117
        /** The stride at the specified index. */
 
118
        String getName ( size_t index ) const
 
119
        {
 
120
                        COLLADABU_ASSERT ( index <= mInputInfosArray.getCount() );
 
121
            if ( index >= mInputInfosArray.getCount () ) return 0;
 
122
            return mInputInfosArray[index]->mName;
 
123
        }
 
124
 
 
125
        /** The stride at the specified index. */
 
126
        size_t getStride ( size_t index ) const
 
127
        {
 
128
            COLLADABU_ASSERT ( index <= mInputInfosArray.getCount() );
 
129
            if ( index >= mInputInfosArray.getCount () ) return 0;
 
130
            return mInputInfosArray[index]->mStride;
 
131
        }
 
132
 
 
133
        /** The stride can differ, so we have to set. */
 
134
        size_t getLength ( size_t index ) const
 
135
        {
 
136
            COLLADABU_ASSERT ( index <= mInputInfosArray.getCount() );
 
137
            if ( index >= mInputInfosArray.getCount () ) return 0;
 
138
            return mInputInfosArray[index]->mLength;
 
139
        }
 
140
 
 
141
 
 
142
                /** Appends the values of the input array to the end of values array.
 
143
                The programmer must ensure, that the memory allocated,
 
144
                was large enough to hold another element. No new memory is allocated.*/
 
145
                bool appendValues ( const FloatArray& valuesArray )
 
146
                {
 
147
                        return FloatOrDoubleArray::appendValues ( valuesArray );
 
148
                }
 
149
 
 
150
                /** Appends the values of the input array to the end of values array.
 
151
                The programmer must ensure, that the memory allocated,
 
152
                was large enough to hold another element. No new memory is allocated.*/
 
153
                bool appendValues ( const DoubleArray& valuesArray )
 
154
                {
 
155
                        return FloatOrDoubleArray::appendValues ( valuesArray );
 
156
                }
 
157
 
 
158
 
 
159
        private:
 
160
 
 
161
                /** Disable default copy ctor. */
 
162
                MeshVertexData( const MeshVertexData& pre );
 
163
 
 
164
                /** Disable default assignment operator. */
 
165
                const MeshVertexData& operator= ( const MeshVertexData& pre );
 
166
 
 
167
        };
 
168
 
 
169
} // namespace COLLADAFW
 
170
 
 
171
#endif // __COLLADAFW_MESHINPUTS_H__