2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/public-api/geometry/mesh-data.h>
22 #include <dali/public-api/math/matrix.h>
23 #include <dali/integration-api/debug.h>
30 namespace // unnamed namespace
32 static const float kBoundsDefault = 1e10f;
33 } // unnamed namespace
39 : mGeometryType(TRIANGLES),
40 mUseTextureCoords(false),
43 mMin( kBoundsDefault, kBoundsDefault, kBoundsDefault, 0.0f),
44 mMax(-kBoundsDefault, -kBoundsDefault, -kBoundsDefault, 0.0f)
48 MeshData::MeshData( const MeshData& meshData )
49 : mVertices( meshData.mVertices ),
50 mFaces( meshData.mFaces ),
51 mGeometryType( meshData.mGeometryType ),
52 mUseTextureCoords( meshData.mUseTextureCoords ),
53 mUseNormals( meshData.mUseNormals ),
54 mUseColor( meshData.mUseColor ),
55 mBones( meshData.mBones ),
56 mMaterial( meshData.mMaterial ),
57 mMin( meshData.mMin ),
62 MeshData& MeshData::operator=(const MeshData& rhs)
64 mVertices = rhs.mVertices;
66 mGeometryType = rhs.mGeometryType;
67 mUseTextureCoords = rhs.mUseTextureCoords;
68 mUseNormals = rhs.mUseNormals;
69 mUseColor = rhs.mUseColor;
71 mMaterial = rhs.mMaterial;
82 void MeshData::SetData(
83 const VertexContainer& vertices,
84 const FaceIndices& faceIndices,
85 const BoneContainer& bones,
88 DALI_ASSERT_ALWAYS( !vertices.empty() && "VertexContainer is empty" );
89 DALI_ASSERT_ALWAYS( !faceIndices.empty() && "FaceIndices is empty" );
90 DALI_ASSERT_ALWAYS( material && "Material handle is empty" );
92 mGeometryType = TRIANGLES;
99 void MeshData::SetLineData(
100 const VertexContainer& vertices,
101 const FaceIndices& lineIndices,
104 DALI_ASSERT_ALWAYS( !vertices.empty() && "VertexContainer is empty" );
105 DALI_ASSERT_ALWAYS( !lineIndices.empty() && "FaceIndices is empty" );
106 DALI_ASSERT_ALWAYS( material && "Material handle is empty" );
108 mGeometryType = LINES;
109 mVertices = vertices;
110 mFaces = lineIndices;
111 mMaterial = material;
114 void MeshData::SetPointData(
115 const VertexContainer& vertices,
118 DALI_ASSERT_ALWAYS( !vertices.empty() && "VertexContainer is empty" );
119 DALI_ASSERT_ALWAYS( material && "Material handle is empty" );
121 mGeometryType = POINTS;
122 mVertices = vertices;
123 mMaterial = material;
126 void MeshData::SetVertices( const VertexContainer& vertices )
128 DALI_ASSERT_ALWAYS( !vertices.empty() && "VertexContainer is empty" );
130 mVertices = vertices;
133 void MeshData::SetFaceIndices( const FaceIndices& faceIndices )
135 DALI_ASSERT_ALWAYS( !faceIndices.empty() && "FaceIndices is empty" );
137 mFaces = faceIndices;
140 void MeshData::AddToBoundingVolume(Vector4& min, Vector4& max, const Dali::Matrix& transform)
142 DALI_LOG_TRACE_METHOD(Debug::Filter::gModel);
144 for (VertexConstIter iter = mVertices.begin(); iter != mVertices.end(); ++iter)
146 const Vertex& vertex = *iter;
147 Vector4 point = Vector4(vertex.x, vertex.y, vertex.z, 0.0f);
149 mMin = Min(mMin, point);
150 mMax = Max(mMax, point);
152 // mMin/mMax are accessed through public API, so have chosen to set w to zero
153 // ( They should really be Vector3's )
157 // For the matrix multiplication below to work correctly, the w needs to be 1.
158 Vector4 tmpMin(mMin);
159 Vector4 tmpMax(mMax);
163 min = Min(min, transform * tmpMin);
164 max = Max(max, transform * tmpMax);
166 // Ensure the bounding volume out parameters also have w=0. (They should also
172 MeshData::VertexGeometryType MeshData::GetVertexGeometryType() const
174 return mGeometryType;
177 size_t MeshData::GetVertexCount() const
179 return mVertices.size();
182 const MeshData::VertexContainer& MeshData::GetVertices() const
187 size_t MeshData::GetFaceCount() const
189 size_t faceCount = 0;
191 switch( mGeometryType )
194 faceCount = mVertices.size();
197 faceCount = mFaces.size() / 2;
200 faceCount = mFaces.size() / 3;
206 const MeshData::FaceIndices& MeshData::GetFaces() const
211 void MeshData::SetHasTextureCoords(bool hasTexCoords)
213 mUseTextureCoords = hasTexCoords;
216 bool MeshData::HasTextureCoords() const
218 return mUseTextureCoords;
221 void MeshData::SetHasNormals(bool hasNormals)
223 mUseNormals = hasNormals;
226 // Enforce mutual exclusivity
231 bool MeshData::HasNormals() const
236 void MeshData::SetHasColor(bool hasColor)
238 mUseColor = hasColor;
241 // Enforce mutual exclusivity
246 bool MeshData::HasColor() const
251 Material MeshData::GetMaterial() const
256 void MeshData::SetMaterial(Material material)
258 mMaterial = material;
261 size_t MeshData::GetBoneCount() const
263 return mBones.size();
266 bool MeshData::HasBones() const
268 return mBones.size() > 0;
271 const BoneContainer& MeshData::GetBones() const
276 const Vector4& MeshData::GetBoundingBoxMin() const
281 void MeshData::SetBoundingBoxMin(const Vector4& bounds)
286 const Vector4& MeshData::GetBoundingBoxMax() const
292 void MeshData::SetBoundingBoxMax(const Vector4& bounds)