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>
28 namespace // unnamed namespace
30 const float kBoundsDefault = 1e10f;
31 } // unnamed namespace
37 : mGeometryType(TRIANGLES),
38 mUseTextureCoords(false),
41 mMin( kBoundsDefault, kBoundsDefault, kBoundsDefault, 0.0f),
42 mMax(-kBoundsDefault, -kBoundsDefault, -kBoundsDefault, 0.0f)
46 MeshData::MeshData( const MeshData& meshData )
47 : mVertices( meshData.mVertices ),
48 mFaces( meshData.mFaces ),
49 mGeometryType( meshData.mGeometryType ),
50 mUseTextureCoords( meshData.mUseTextureCoords ),
51 mUseNormals( meshData.mUseNormals ),
52 mUseColor( meshData.mUseColor ),
53 mBones( meshData.mBones ),
54 mMaterial( meshData.mMaterial ),
55 mMin( meshData.mMin ),
60 MeshData& MeshData::operator=(const MeshData& rhs)
62 mVertices = rhs.mVertices;
64 mGeometryType = rhs.mGeometryType;
65 mUseTextureCoords = rhs.mUseTextureCoords;
66 mUseNormals = rhs.mUseNormals;
67 mUseColor = rhs.mUseColor;
69 mMaterial = rhs.mMaterial;
80 void MeshData::SetData(
81 const VertexContainer& vertices,
82 const FaceIndices& faceIndices,
83 const BoneContainer& bones,
86 DALI_ASSERT_ALWAYS( !vertices.empty() && "VertexContainer is empty" );
87 DALI_ASSERT_ALWAYS( !faceIndices.empty() && "FaceIndices is empty" );
88 DALI_ASSERT_ALWAYS( material && "Material handle is empty" );
90 mGeometryType = TRIANGLES;
97 void MeshData::SetLineData(
98 const VertexContainer& vertices,
99 const FaceIndices& lineIndices,
102 DALI_ASSERT_ALWAYS( !vertices.empty() && "VertexContainer is empty" );
103 DALI_ASSERT_ALWAYS( !lineIndices.empty() && "FaceIndices is empty" );
104 DALI_ASSERT_ALWAYS( material && "Material handle is empty" );
106 mGeometryType = LINES;
107 mVertices = vertices;
108 mFaces = lineIndices;
109 mMaterial = material;
112 void MeshData::SetPointData(
113 const VertexContainer& vertices,
116 DALI_ASSERT_ALWAYS( !vertices.empty() && "VertexContainer is empty" );
117 DALI_ASSERT_ALWAYS( material && "Material handle is empty" );
119 mGeometryType = POINTS;
120 mVertices = vertices;
121 mMaterial = material;
124 void MeshData::SetVertices( const VertexContainer& vertices )
126 DALI_ASSERT_ALWAYS( !vertices.empty() && "VertexContainer is empty" );
128 mVertices = vertices;
131 void MeshData::SetFaceIndices( const FaceIndices& faceIndices )
133 DALI_ASSERT_ALWAYS( !faceIndices.empty() && "FaceIndices is empty" );
135 mFaces = faceIndices;
138 void MeshData::AddToBoundingVolume(Vector4& min, Vector4& max, const Dali::Matrix& transform)
140 DALI_LOG_TRACE_METHOD(Debug::Filter::gModel);
142 for (VertexConstIter iter = mVertices.begin(); iter != mVertices.end(); ++iter)
144 const Vertex& vertex = *iter;
145 Vector4 point = Vector4(vertex.x, vertex.y, vertex.z, 0.0f);
147 mMin = Min(mMin, point);
148 mMax = Max(mMax, point);
150 // mMin/mMax are accessed through public API, so have chosen to set w to zero
151 // ( They should really be Vector3's )
155 // For the matrix multiplication below to work correctly, the w needs to be 1.
156 Vector4 tmpMin(mMin);
157 Vector4 tmpMax(mMax);
161 min = Min(min, transform * tmpMin);
162 max = Max(max, transform * tmpMax);
164 // Ensure the bounding volume out parameters also have w=0. (They should also
170 MeshData::VertexGeometryType MeshData::GetVertexGeometryType() const
172 return mGeometryType;
175 size_t MeshData::GetVertexCount() const
177 return mVertices.size();
180 const MeshData::VertexContainer& MeshData::GetVertices() const
185 size_t MeshData::GetFaceCount() const
187 size_t faceCount = 0;
189 switch( mGeometryType )
192 faceCount = mVertices.size();
195 faceCount = mFaces.size() / 2;
198 faceCount = mFaces.size() / 3;
204 const MeshData::FaceIndices& MeshData::GetFaces() const
209 void MeshData::SetHasTextureCoords(bool hasTexCoords)
211 mUseTextureCoords = hasTexCoords;
214 bool MeshData::HasTextureCoords() const
216 return mUseTextureCoords;
219 void MeshData::SetHasNormals(bool hasNormals)
221 mUseNormals = hasNormals;
224 // Enforce mutual exclusivity
229 bool MeshData::HasNormals() const
234 void MeshData::SetHasColor(bool hasColor)
236 mUseColor = hasColor;
239 // Enforce mutual exclusivity
244 bool MeshData::HasColor() const
249 Material MeshData::GetMaterial() const
254 void MeshData::SetMaterial(Material material)
256 mMaterial = material;
259 size_t MeshData::GetBoneCount() const
261 return mBones.size();
264 bool MeshData::HasBones() const
266 return mBones.size() > 0;
269 const BoneContainer& MeshData::GetBones() const
274 const Vector4& MeshData::GetBoundingBoxMin() const
279 void MeshData::SetBoundingBoxMin(const Vector4& bounds)
284 const Vector4& MeshData::GetBoundingBoxMax() const
290 void MeshData::SetBoundingBoxMax(const Vector4& bounds)