summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2015-01-29 16:17:42 +0200
committerBogdan Devichev <b.devichev@samsung.com>2015-01-29 16:17:42 +0200
commit23c3cd9489c32093226124aa0efb5f4853230302 (patch)
tree47ac720589ceb987e65b9c818c4ad6ea1e52ae05
parent5bcc44953bca32958c7515b05cbd46d288fbf1f3 (diff)
Obj_io. Step 4. Now _read_point works correctly for obj files saves without normals or/and tex_coords too.
-rw-r--r--src/modules/evas/model_loaders/obj/evas_model_load_obj.c61
1 files changed, 48 insertions, 13 deletions
diff --git a/src/modules/evas/model_loaders/obj/evas_model_load_obj.c b/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
index 953789e998..1c9c9c426f 100644
--- a/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
+++ b/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
@@ -12,19 +12,19 @@
12#define ARRAY_2D(name, x, y, count_y) (*(name + x * count_y + y)) 12#define ARRAY_2D(name, x, y, count_y) (*(name + x * count_y + y))
13 13
14/* read 3 float values in string and put it in array */ 14/* read 3 float values in string and put it in array */
15#define PUT_DATA_TO_ARRAY(array_name, name) \ 15#define PUT_DATA_TO_ARRAY(array_name, name) \
16 sscanf (current,"%f %f %f", \ 16 sscanf (current,"%f %f %f", \
17 &ARRAY_2D(_##array_name##_obj, counts.current_##name##_counter, 0, 3), \ 17 &ARRAY_2D(_##array_name##_obj, counts.current_##name##_counter, 0, 3), \
18 &ARRAY_2D(_##array_name##_obj, counts.current_##name##_counter, 1, 3), \ 18 &ARRAY_2D(_##array_name##_obj, counts.current_##name##_counter, 1, 3), \
19 &ARRAY_2D(_##array_name##_obj, counts.current_##name##_counter, 2, 3)); \ 19 &ARRAY_2D(_##array_name##_obj, counts.current_##name##_counter, 2, 3)); \
20 counts.current_##name##_counter++; 20 counts.current_##name##_counter++;
21 21
22#define AFTER_NEXT_SPACE(pointer)\ 22#define AFTER_NEXT_SPACE(pointer)\
23 do\ 23 do \
24 {\ 24 { \
25 pointer++;\ 25 pointer++; \
26 i++;\ 26 i++; \
27 }\ 27 } \
28 while (*pointer != ' '); 28 while (*pointer != ' ');
29 29
30/* Structures for reading data from file. */ 30/* Structures for reading data from file. */
@@ -188,14 +188,44 @@ _count_elements(char *map)//count elements of mesh in .obj
188void 188void
189_read_point(int *triangles, 189_read_point(int *triangles,
190 int num, 190 int num,
191 OBJ_Counts counts EINA_UNUSED, 191 OBJ_Counts counts,
192 int num_cur, 192 int num_cur,
193 char *pointer) 193 char *pointer)
194{ 194{
195 sscanf(pointer, "%i/%i/%i", 195 if (counts.existence_of_normal)
196 &ARRAY_2D(triangles, num_cur, (num - 1) * 3, 9), 196 {
197 &ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 1, 9), 197 if (counts.existence_of_tex_point)
198 &ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 2, 9)); 198 {
199 sscanf(pointer, "%i/%i/%i",
200 &ARRAY_2D(triangles, num_cur, (num - 1) * 3, 9),
201 &ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 1, 9),
202 &ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 2, 9));
203 }
204 else
205 {
206 sscanf(pointer, "%i//%i",
207 &ARRAY_2D(triangles, num_cur, (num - 1) * 3, 9),
208 &ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 2, 9));
209 ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 1, 9) = 1;
210 }
211 }
212 else
213 {
214 if (counts.existence_of_tex_point)
215 {
216 sscanf(pointer, "%i/%i",
217 &ARRAY_2D(triangles, num_cur, (num - 1) * 3, 9),
218 &ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 1, 9));
219 ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 2, 9) = 1;
220 }
221 else
222 {
223 sscanf(pointer, "%i",
224 &ARRAY_2D(triangles, num_cur, (num - 1) * 3, 9));
225 ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 1, 9) = 1;
226 ARRAY_2D(triangles, num_cur, (num - 1) * 3 + 2, 9) = 1;
227 }
228 }
199} 229}
200 230
201void 231void
@@ -240,7 +270,12 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Eina_File *file)
240 270
241 current = map; 271 current = map;
242 i = 0; 272 i = 0;
243 273 ARRAY_2D(_tex_coords_obj, 0, 0, 3) = 0.0;
274 ARRAY_2D(_tex_coords_obj, 0, 1, 3) = 0.0;
275 ARRAY_2D(_tex_coords_obj, 0, 2, 3) = 0.0;
276 ARRAY_2D(_normales_obj, 0, 0, 3) = 1.0;
277 ARRAY_2D(_normales_obj, 0, 1, 3) = 0.0;
278 ARRAY_2D(_normales_obj, 0, 2, 3) = 0.0;
244 /* put data to arrays */ 279 /* put data to arrays */
245 for (; *current != '\00'; i++) 280 for (; *current != '\00'; i++)
246 { 281 {