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

« back to all changes in this revision

Viewing changes to COLLADAFramework/src/COLLADAFWMesh.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 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
#include "COLLADAFWStableHeaders.h"
 
12
#include "COLLADAFWMesh.h"
 
13
#include "COLLADAFWTristrips.h"
 
14
#include "COLLADAFWLinestrips.h"
 
15
 
 
16
namespace COLLADAFW
 
17
{
 
18
 
 
19
    //----------------------------------
 
20
    Mesh::Mesh( const UniqueId& uniqueId )
 
21
        : Geometry ( uniqueId, Geometry::GEO_TYPE_MESH )
 
22
        , mMeshPrimitives(MeshPrimitiveArray::OWNER)
 
23
    {
 
24
 
 
25
    }
 
26
 
 
27
    //----------------------------------
 
28
        Mesh::~Mesh()
 
29
        {
 
30
                for ( size_t i = 0, count = mMeshPrimitives.getCount(); i < count; ++i)
 
31
                        delete mMeshPrimitives[i];
 
32
        }
 
33
 
 
34
    //----------------------------------
 
35
        size_t Mesh::getTrianglesTriangleCount()
 
36
        {
 
37
                return getPrimitiveCount(MeshPrimitive::TRIANGLES);
 
38
        }
 
39
 
 
40
        //---------------------------------------------------------------
 
41
        size_t Mesh::getTristripsTriangleCount()
 
42
        {
 
43
                return getFaceCount(MeshPrimitive::TRIANGLE_STRIPS);
 
44
        }
 
45
 
 
46
        //---------------------------------------------------------------
 
47
        size_t Mesh::getTrifansTriangleCount()
 
48
        {
 
49
                return getFaceCount(MeshPrimitive::TRIANGLE_FANS);
 
50
        }
 
51
 
 
52
        //---------------------------------------------------------------
 
53
        size_t Mesh::getPolygonsPolygonCount()
 
54
        {
 
55
                return getPrimitiveCount(MeshPrimitive::POLYGONS);
 
56
        }
 
57
 
 
58
        //---------------------------------------------------------------
 
59
        size_t Mesh::getPolylistPolygonCount()
 
60
        {
 
61
                return getPrimitiveCount(MeshPrimitive::POLYLIST);
 
62
        }
 
63
 
 
64
        //---------------------------------------------------------------
 
65
        size_t Mesh::getPrimitiveCount( MeshPrimitive::PrimitiveType primitiveType )
 
66
        {
 
67
                size_t primitiveCount = 0;
 
68
                for ( size_t i = 0, count = mMeshPrimitives.getCount(); i < count; ++i)
 
69
                {
 
70
                        MeshPrimitive* primitive = mMeshPrimitives[i];
 
71
 
 
72
                        if ( primitive && ( primitive->getPrimitiveType() == primitiveType ) )
 
73
                        {
 
74
                                switch ( primitiveType )
 
75
                                {
 
76
                                case MeshPrimitive::TRIANGLES:
 
77
                case MeshPrimitive::LINES:
 
78
                                case MeshPrimitive::POLYGONS:
 
79
                                case MeshPrimitive::POLYLIST:
 
80
                                        primitiveCount += primitive->getFaceCount();
 
81
                                        break;
 
82
                                case MeshPrimitive::TRIANGLE_STRIPS:
 
83
                                        {
 
84
                                                Tristrips* tristrips = (Tristrips*)primitive;
 
85
                                                primitiveCount += tristrips->getTristripCount();
 
86
                                        }
 
87
                    break;
 
88
                                case MeshPrimitive::TRIANGLE_FANS:
 
89
                                        {
 
90
 
 
91
                                                // TODO not implemented
 
92
                                                //Tristrips* tristrips = (Tristrips*)primitive;
 
93
                                                //primitiveCount += tristrips->getTristripCount();
 
94
                                        }
 
95
                    break;
 
96
                case MeshPrimitive::LINE_STRIPS:
 
97
                    {
 
98
                        Linestrips* linestrips = (Linestrips*)primitive;
 
99
                        primitiveCount += linestrips->getLinestripCount ();
 
100
                    }
 
101
                    break;
 
102
                                case MeshPrimitive::UNDEFINED_PRIMITIVE_TYPE:
 
103
                                default:
 
104
                                        break;
 
105
                                }
 
106
                        }
 
107
                }
 
108
                return primitiveCount;
 
109
        }
 
110
 
 
111
    //----------------------------------
 
112
        size_t Mesh::getFaceCount( MeshPrimitive::PrimitiveType primitiveType )
 
113
        {
 
114
                size_t faceCount = 0;
 
115
                for ( size_t i = 0, count = mMeshPrimitives.getCount(); i < count; ++i)
 
116
                {
 
117
                        MeshPrimitive* primitive = mMeshPrimitives[i];
 
118
 
 
119
                        if ( primitive && ( primitive->getPrimitiveType() == primitiveType ) )
 
120
                                faceCount += primitive->getFaceCount();
 
121
                }
 
122
                return faceCount;
 
123
        }
 
124
 
 
125
 
 
126
        //---------------------------------------------------------------
 
127
        size_t Mesh::getTrianglesCount()
 
128
        {
 
129
                return getPrimitiveCount(MeshPrimitive::TRIANGLES);
 
130
        }
 
131
 
 
132
        //---------------------------------------------------------------
 
133
        size_t Mesh::getTristripsCount()
 
134
        {
 
135
                return getPrimitiveCount(MeshPrimitive::TRIANGLE_STRIPS);
 
136
        }
 
137
 
 
138
        //---------------------------------------------------------------
 
139
        size_t Mesh::getTrifansCount()
 
140
        {
 
141
                return getPrimitiveCount(MeshPrimitive::TRIANGLE_FANS);
 
142
        }
 
143
 
 
144
        //---------------------------------------------------------------
 
145
        size_t Mesh::getPolygonsCount()
 
146
        {
 
147
                return getPrimitiveCount(MeshPrimitive::POLYGONS);
 
148
        }
 
149
 
 
150
 
 
151
        //---------------------------------------------------------------
 
152
        size_t Mesh::getMeshPrimitiveCount( MeshPrimitive::PrimitiveType primitiveType )
 
153
        {
 
154
                size_t primitiveCount = 0;
 
155
                for ( size_t i = 0, count = mMeshPrimitives.getCount(); i < count; ++i)
 
156
                {
 
157
                        MeshPrimitive* primitive = mMeshPrimitives[i];
 
158
 
 
159
                        if ( primitive && ( primitive->getPrimitiveType() == primitiveType ) )
 
160
                                primitiveCount++;
 
161
                }
 
162
                return primitiveCount;
 
163
        }
 
164
 
 
165
    //----------------------------------
 
166
        bool Mesh::hasNormals( )const
 
167
        {
 
168
                return getNormals().getValuesCount() != 0;
 
169
        }
 
170
 
 
171
    //----------------------------------
 
172
    const size_t Mesh::getNormalsCount() const
 
173
    {
 
174
        // The number of normals in the current mesh.
 
175
        size_t numNormals = 0;
 
176
 
 
177
        // We have to go through every mesh primitive.
 
178
        const MeshPrimitiveArray& meshPrimitives = this->getMeshPrimitives ();
 
179
        size_t count = meshPrimitives.getCount ();
 
180
        for ( size_t i=0; i<count; ++i )
 
181
        {
 
182
            // Get the current primitive element.
 
183
            const MeshPrimitive* meshPrimitive = meshPrimitives [ i ];
 
184
 
 
185
            // Get the normal indices of the current primitive.
 
186
            const UIntValuesArray& normalIndices = meshPrimitive->getNormalIndices ();
 
187
 
 
188
            switch ( meshPrimitive->getPrimitiveType () )
 
189
            {
 
190
            case COLLADAFW::MeshPrimitive::TRIANGLE_FANS:
 
191
            case COLLADAFW::MeshPrimitive::TRIANGLE_STRIPS:
 
192
                {
 
193
                    COLLADAFW::MeshPrimitiveWithFaceVertexCount<unsigned int>* trifans = (COLLADAFW::MeshPrimitiveWithFaceVertexCount<unsigned int>*) meshPrimitive;
 
194
                    COLLADAFW::MeshPrimitiveWithFaceVertexCount<unsigned int>::VertexCountArray& vertexCountArray = trifans->getGroupedVerticesVertexCountArray ();
 
195
                    size_t groupedVtxCount = vertexCountArray.getCount ();
 
196
                    for ( size_t groupedVtxIndex=0; groupedVtxIndex<groupedVtxCount; ++groupedVtxIndex )
 
197
                    {
 
198
                        // Iterate over the indices and write their normal values into the maya file.
 
199
                        size_t indexCount = vertexCountArray[groupedVtxIndex]; //normalIndices.getCount();
 
200
                        numNormals += (indexCount - 2) * 3;
 
201
                    }
 
202
                }
 
203
                break;
 
204
            default:
 
205
                {
 
206
                    // Add the normals to the sum of normals
 
207
                    numNormals += normalIndices.getCount ();
 
208
                }
 
209
            }
 
210
        }
 
211
 
 
212
        return numNormals;
 
213
    }
 
214
 
 
215
    //----------------------------------
 
216
    const size_t Mesh::getFacesCount() const
 
217
    {
 
218
        // The number of faces in the current mesh.
 
219
        size_t numFaces = 0;
 
220
 
 
221
        // We have to go through every mesh primitive.
 
222
        const MeshPrimitiveArray& meshPrimitives = this->getMeshPrimitives ();
 
223
        size_t count = meshPrimitives.getCount ();
 
224
        for ( size_t i=0; i<count; ++i )
 
225
        {
 
226
            // Get the current primitive element.
 
227
            const MeshPrimitive* meshPrimitive = meshPrimitives [ i ];
 
228
 
 
229
            // Add the face count to the sum of faces
 
230
            numFaces += meshPrimitive->getFaceCount ();
 
231
        }
 
232
 
 
233
        return numFaces;
 
234
    }
 
235
 
 
236
} // namespace COLLADAFW