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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
26 #include "mesh-builder.h"
30 int UtcDaliMeshDataNew(void)
32 TestApplication application;
35 DALI_TEST_EQUALS(meshData.HasNormals(), false, TEST_LOCATION);
36 DALI_TEST_EQUALS(meshData.HasTextureCoords(), false, TEST_LOCATION);
41 int UtcDaliMeshDataSetData(void)
43 TestApplication application;
46 MeshData::VertexContainer vertices;
47 MeshData::FaceIndices faces;
49 ConstructVertices(vertices, 60);
50 ConstructFaces(vertices, faces);
51 Material customMaterial = ConstructMaterial();
52 meshData.SetData(vertices, faces, bones, customMaterial);
54 DALI_TEST_GREATER(meshData.GetVertexCount(), 0u, TEST_LOCATION);
55 DALI_TEST_GREATER(meshData.GetFaceCount(), 0u, TEST_LOCATION);
57 const MeshData::FaceIndices& faces2 = meshData.GetFaces();
58 const MeshData::VertexContainer& verts2 = meshData.GetVertices();
59 DALI_TEST_EQUALS(faces.at(0), faces2.at(0), TEST_LOCATION);
60 DALI_TEST_EQUALS(vertices.at(1).y, verts2.at(1).y, TEST_LOCATION);
61 DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(0), TEST_LOCATION);
65 int UtcDaliMeshDataAddToBoundingVolume(void)
67 TestApplication application;
72 MeshData::VertexContainer vertices;
73 MeshData::FaceIndices faces;
75 ConstructVertices(vertices, sz);
76 ConstructFaces(vertices, faces);
77 Material customMaterial = ConstructMaterial();
78 meshData.SetData(vertices, faces, bones, customMaterial);
80 Vector4 upper(-1e10f, -1e10f, -1e10f, 0.0f);
81 Vector4 lower(1e10f, 1e10f, 1e10f, 0.0f);
83 f.SetIdentityAndScale(Vector3(2.0f, 2.0f, 2.0f));
84 meshData.AddToBoundingVolume(lower, upper, f);
86 Vector4 min(-sz*0.5f, -sz, -sz*0.7f, 0.0f);
87 Vector4 max( sz*0.5f, sz*0.3f, sz*0.5f, 0.0f);
89 // Test that upper and lower bounds are set and transformed
90 DALI_TEST_EQUALS(lower, min*2.0f, 0.001, TEST_LOCATION);
91 DALI_TEST_EQUALS(upper, max*2.0f, 0.001, TEST_LOCATION);
93 // Test that mesh's upper and lower bounds are set and not transformed
94 DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), min, 0.001, TEST_LOCATION);
95 DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), max, 0.001, TEST_LOCATION);
99 int UtcDaliMeshDataBoundingBox(void)
101 TestApplication application;
105 Vector4 min(-1.0f, -2.0f, -3.0f, 0.0f);
106 Vector4 max(1.0f, 2.0f, 3.0f, 0.0f);
107 meshData.SetBoundingBoxMin(min);
108 meshData.SetBoundingBoxMax(max);
109 DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), min, 0.001, TEST_LOCATION);
110 DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), max, 0.001, TEST_LOCATION);
112 MeshData::VertexContainer vertices;
113 MeshData::FaceIndices faces;
115 ConstructVertices(vertices, sz);
116 ConstructFaces(vertices, faces);
117 Material customMaterial = ConstructMaterial();
118 meshData.SetData(vertices, faces, bones, customMaterial);
120 // Check bounding box hasn't changed
121 DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), min, 0.001, TEST_LOCATION);
122 DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), max, 0.001, TEST_LOCATION);
124 Vector4 upper(-1e10f, -1e10f, -1e10f, 0.0f);
125 Vector4 lower(1e10f, 1e10f, 1e10f, 0.0f);
126 meshData.AddToBoundingVolume(lower, upper, Matrix::IDENTITY);
128 // Bounding box should have been update
129 Vector4 bbMin(-sz*0.5f, -sz, -sz*0.7f, 0.0f);
130 Vector4 bbMax( sz*0.5f, sz*0.3f, sz*0.5f, 0.0f);
132 // Test that upper and lower bounds are set and transformed
133 DALI_TEST_EQUALS(lower, bbMin, 0.001, TEST_LOCATION);
134 DALI_TEST_EQUALS(upper, bbMax, 0.001, TEST_LOCATION);
136 // Test that mesh's upper and lower bounds are set and not transformed
137 DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), bbMin, 0.001, TEST_LOCATION);
138 DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), bbMax, 0.001, TEST_LOCATION);
142 int UtcDaliMeshDataGetVertexCount(void)
144 TestApplication application;
147 MeshData::VertexContainer vertices;
148 MeshData::FaceIndices faces;
150 ConstructVertices(vertices, 30);
151 ConstructFaces(vertices, faces);
152 Material customMaterial = ConstructMaterial();
154 DALI_TEST_EQUALS(meshData.GetVertexCount(), static_cast<size_t>(0), TEST_LOCATION);
156 meshData.SetData(vertices, faces, bones, customMaterial);
157 DALI_TEST_EQUALS(meshData.GetVertexCount(), vertices.size(), TEST_LOCATION);
162 int UtcDaliMeshDataGetVertices(void)
164 TestApplication application;
166 const Dali::MeshData::VertexContainer& verts1 = meshData.GetVertices();
167 DALI_TEST_CHECK(verts1.size() == 0);
169 MeshData::VertexContainer vertices;
170 MeshData::FaceIndices faces;
172 ConstructVertices(vertices, 30);
173 ConstructFaces(vertices, faces);
174 Material customMaterial = ConstructMaterial();
175 meshData.SetData(vertices, faces, bones, customMaterial);
177 const Dali::MeshData::VertexContainer& verts2 = meshData.GetVertices();
178 DALI_TEST_CHECK(verts2.size() != 0);
179 DALI_TEST_CHECK(verts2.size() == meshData.GetVertexCount());
183 int UtcDaliMeshDataGetFaceCount(void)
185 TestApplication application;
187 DALI_TEST_EQUALS(meshData.GetFaceCount(), static_cast<size_t>(0), TEST_LOCATION);
189 MeshData::VertexContainer vertices;
190 MeshData::FaceIndices faces;
192 ConstructVertices(vertices, 30);
193 ConstructFaces(vertices, faces);
194 Material customMaterial = ConstructMaterial();
195 meshData.SetData(vertices, faces, bones, customMaterial);
197 DALI_TEST_EQUALS(meshData.GetFaceCount(), faces.size() / 3, TEST_LOCATION);
201 int UtcDaliMeshDataGetFaces(void)
203 TestApplication application;
205 const Dali::MeshData::FaceIndices& faces1 = meshData.GetFaces();
206 DALI_TEST_CHECK(faces1.size() == 0);
208 MeshData::VertexContainer vertices;
209 MeshData::FaceIndices faces;
211 ConstructVertices(vertices, 30);
212 ConstructFaces(vertices, faces);
213 Material customMaterial = ConstructMaterial();
214 meshData.SetData(vertices, faces, bones, customMaterial);
216 const Dali::MeshData::FaceIndices& faces2 = meshData.GetFaces();
217 DALI_TEST_CHECK(faces2.size() != 0);
221 int UtcDaliMeshDataTextureCoords(void)
223 TestApplication application;
225 DALI_TEST_EQUALS(meshData.HasTextureCoords(), false, TEST_LOCATION);
226 meshData.SetHasTextureCoords(true);
227 DALI_TEST_EQUALS(meshData.HasTextureCoords(), true, TEST_LOCATION);
231 int UtcDaliMeshDataNormals(void)
233 TestApplication application;
235 DALI_TEST_EQUALS(meshData.HasNormals(), false, TEST_LOCATION);
236 meshData.SetHasNormals(true);
237 DALI_TEST_EQUALS(meshData.HasNormals(), true, TEST_LOCATION);
241 int UtcDaliMeshDataGetMaterial(void)
243 TestApplication application;
245 Material aMat = meshData.GetMaterial();
246 DALI_TEST_CHECK(!aMat);
248 MeshData::VertexContainer vertices;
249 MeshData::FaceIndices faces;
251 ConstructVertices(vertices, 30);
252 ConstructFaces(vertices, faces);
253 Material customMaterial = ConstructMaterial();
254 meshData.SetData(vertices, faces, bones, customMaterial);
256 aMat = meshData.GetMaterial();
257 DALI_TEST_CHECK(aMat);
261 int UtcDaliMeshDataSetMaterial(void)
263 TestApplication application;
266 Material aMat = meshData.GetMaterial();
267 DALI_TEST_CHECK(!aMat);
269 Material mat1 = ConstructMaterial();
270 meshData.SetMaterial(mat1);
271 aMat = meshData.GetMaterial();
272 DALI_TEST_CHECK(mat1 == aMat);
274 MeshData::VertexContainer vertices;
275 MeshData::FaceIndices faces;
277 ConstructVertices(vertices, 30);
278 ConstructFaces(vertices, faces);
279 Material customMaterial = ConstructMaterial();
280 meshData.SetData(vertices, faces, bones, customMaterial);
282 aMat = meshData.GetMaterial();
284 DALI_TEST_CHECK(aMat == customMaterial);
285 DALI_TEST_CHECK(aMat != mat1);
290 int UtcDaliMeshDataGetBoneCount(void)
292 TestApplication application;
294 DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(0), TEST_LOCATION);
295 DALI_TEST_EQUALS(meshData.HasBones(), false, TEST_LOCATION);
297 MeshData::VertexContainer vertices;
298 MeshData::FaceIndices faces;
300 ConstructVertices(vertices, 30);
301 ConstructFaces(vertices, faces);
302 ConstructBones(bones);
303 Material customMaterial = ConstructMaterial();
304 meshData.SetData(vertices, faces, bones, customMaterial);
306 DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(3), TEST_LOCATION);
307 DALI_TEST_EQUALS(meshData.HasBones(), true, TEST_LOCATION);
312 int UtcDaliMeshDataGetBones(void)
314 TestApplication application;
316 DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(0), TEST_LOCATION);
317 const BoneContainer& bones1 = meshData.GetBones();
318 DALI_TEST_CHECK(bones1.empty());
320 MeshData::VertexContainer vertices;
321 MeshData::FaceIndices faces;
323 ConstructVertices(vertices, 30);
324 ConstructFaces(vertices, faces);
325 ConstructBones(bones);
326 Material customMaterial = ConstructMaterial();
327 meshData.SetData(vertices, faces, bones, customMaterial);
328 const BoneContainer& bones3 = meshData.GetBones();
329 DALI_TEST_CHECK( ! bones3.empty() );