2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADAFramework.
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
11
#include "COLLADAFWStableHeaders.h"
12
#include "COLLADAFWMesh.h"
13
#include "COLLADAFWTristrips.h"
14
#include "COLLADAFWLinestrips.h"
19
//----------------------------------
20
Mesh::Mesh( const UniqueId& uniqueId )
21
: Geometry ( uniqueId, Geometry::GEO_TYPE_MESH )
22
, mMeshPrimitives(MeshPrimitiveArray::OWNER)
27
//----------------------------------
30
for ( size_t i = 0, count = mMeshPrimitives.getCount(); i < count; ++i)
31
delete mMeshPrimitives[i];
34
//----------------------------------
35
size_t Mesh::getTrianglesTriangleCount()
37
return getPrimitiveCount(MeshPrimitive::TRIANGLES);
40
//---------------------------------------------------------------
41
size_t Mesh::getTristripsTriangleCount()
43
return getFaceCount(MeshPrimitive::TRIANGLE_STRIPS);
46
//---------------------------------------------------------------
47
size_t Mesh::getTrifansTriangleCount()
49
return getFaceCount(MeshPrimitive::TRIANGLE_FANS);
52
//---------------------------------------------------------------
53
size_t Mesh::getPolygonsPolygonCount()
55
return getPrimitiveCount(MeshPrimitive::POLYGONS);
58
//---------------------------------------------------------------
59
size_t Mesh::getPolylistPolygonCount()
61
return getPrimitiveCount(MeshPrimitive::POLYLIST);
64
//---------------------------------------------------------------
65
size_t Mesh::getPrimitiveCount( MeshPrimitive::PrimitiveType primitiveType )
67
size_t primitiveCount = 0;
68
for ( size_t i = 0, count = mMeshPrimitives.getCount(); i < count; ++i)
70
MeshPrimitive* primitive = mMeshPrimitives[i];
72
if ( primitive && ( primitive->getPrimitiveType() == primitiveType ) )
74
switch ( primitiveType )
76
case MeshPrimitive::TRIANGLES:
77
case MeshPrimitive::LINES:
78
case MeshPrimitive::POLYGONS:
79
case MeshPrimitive::POLYLIST:
80
primitiveCount += primitive->getFaceCount();
82
case MeshPrimitive::TRIANGLE_STRIPS:
84
Tristrips* tristrips = (Tristrips*)primitive;
85
primitiveCount += tristrips->getTristripCount();
88
case MeshPrimitive::TRIANGLE_FANS:
91
// TODO not implemented
92
//Tristrips* tristrips = (Tristrips*)primitive;
93
//primitiveCount += tristrips->getTristripCount();
96
case MeshPrimitive::LINE_STRIPS:
98
Linestrips* linestrips = (Linestrips*)primitive;
99
primitiveCount += linestrips->getLinestripCount ();
102
case MeshPrimitive::UNDEFINED_PRIMITIVE_TYPE:
108
return primitiveCount;
111
//----------------------------------
112
size_t Mesh::getFaceCount( MeshPrimitive::PrimitiveType primitiveType )
114
size_t faceCount = 0;
115
for ( size_t i = 0, count = mMeshPrimitives.getCount(); i < count; ++i)
117
MeshPrimitive* primitive = mMeshPrimitives[i];
119
if ( primitive && ( primitive->getPrimitiveType() == primitiveType ) )
120
faceCount += primitive->getFaceCount();
126
//---------------------------------------------------------------
127
size_t Mesh::getTrianglesCount()
129
return getPrimitiveCount(MeshPrimitive::TRIANGLES);
132
//---------------------------------------------------------------
133
size_t Mesh::getTristripsCount()
135
return getPrimitiveCount(MeshPrimitive::TRIANGLE_STRIPS);
138
//---------------------------------------------------------------
139
size_t Mesh::getTrifansCount()
141
return getPrimitiveCount(MeshPrimitive::TRIANGLE_FANS);
144
//---------------------------------------------------------------
145
size_t Mesh::getPolygonsCount()
147
return getPrimitiveCount(MeshPrimitive::POLYGONS);
151
//---------------------------------------------------------------
152
size_t Mesh::getMeshPrimitiveCount( MeshPrimitive::PrimitiveType primitiveType )
154
size_t primitiveCount = 0;
155
for ( size_t i = 0, count = mMeshPrimitives.getCount(); i < count; ++i)
157
MeshPrimitive* primitive = mMeshPrimitives[i];
159
if ( primitive && ( primitive->getPrimitiveType() == primitiveType ) )
162
return primitiveCount;
165
//----------------------------------
166
bool Mesh::hasNormals( )const
168
return getNormals().getValuesCount() != 0;
171
//----------------------------------
172
const size_t Mesh::getNormalsCount() const
174
// The number of normals in the current mesh.
175
size_t numNormals = 0;
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 )
182
// Get the current primitive element.
183
const MeshPrimitive* meshPrimitive = meshPrimitives [ i ];
185
// Get the normal indices of the current primitive.
186
const UIntValuesArray& normalIndices = meshPrimitive->getNormalIndices ();
188
switch ( meshPrimitive->getPrimitiveType () )
190
case COLLADAFW::MeshPrimitive::TRIANGLE_FANS:
191
case COLLADAFW::MeshPrimitive::TRIANGLE_STRIPS:
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 )
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;
206
// Add the normals to the sum of normals
207
numNormals += normalIndices.getCount ();
215
//----------------------------------
216
const size_t Mesh::getFacesCount() const
218
// The number of faces in the current mesh.
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 )
226
// Get the current primitive element.
227
const MeshPrimitive* meshPrimitive = meshPrimitives [ i ];
229
// Add the face count to the sum of faces
230
numFaces += meshPrimitive->getFaceCount ();
236
} // namespace COLLADAFW