summaryrefslogtreecommitdiff
path: root/src/examples/evas/evas-3d-obj.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/evas/evas-3d-obj.c')
-rw-r--r--src/examples/evas/evas-3d-obj.c129
1 files changed, 53 insertions, 76 deletions
diff --git a/src/examples/evas/evas-3d-obj.c b/src/examples/evas/evas-3d-obj.c
index 0d40a41..b9a6b69 100644
--- a/src/examples/evas/evas-3d-obj.c
+++ b/src/examples/evas/evas-3d-obj.c
@@ -46,49 +46,43 @@
46#define ADD_OBJ_MESH(path, Y, Z, num, shade_mode, name_of_material) \ 46#define ADD_OBJ_MESH(path, Y, Z, num, shade_mode, name_of_material) \
47 mesh[num] = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas); \ 47 mesh[num] = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas); \
48 snprintf(full_file_path, PATH_MAX, "%s%s", path, ".obj"); \ 48 snprintf(full_file_path, PATH_MAX, "%s%s", path, ".obj"); \
49 eo_do(mesh[num], \ 49 efl_file_set(mesh[num], full_file_path, NULL); \
50 efl_file_set(full_file_path, NULL), \ 50 evas_canvas3d_mesh_frame_material_set(mesh[num], 0, name_of_material); \
51 evas_canvas3d_mesh_frame_material_set(0, name_of_material), \ 51 evas_canvas3d_mesh_shade_mode_set(mesh[num], shade_mode); \
52 evas_canvas3d_mesh_shade_mode_set(shade_mode)); \ 52 mesh_node[num] = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_MESH)); \
53 mesh_node[num] = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, \ 53 evas_canvas3d_node_member_add(root_node, mesh_node[num]); \
54 evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_MESH)); \ 54 evas_canvas3d_node_mesh_add(mesh_node[num], mesh[num]); \
55 eo_do(root_node, \ 55 evas_canvas3d_node_position_set(mesh_node[num], 0, Y, Z); \
56 evas_canvas3d_node_member_add(mesh_node[num])); \
57 eo_do(mesh_node[num], \
58 evas_canvas3d_node_mesh_add(mesh[num]), \
59 evas_canvas3d_node_position_set(0, Y, Z)); \
60 56
61#define ADD_OBJ_MESH_AND_SAVED_COPY(path, Y, Z, num, shade_mode, name_of_material)\ 57#define ADD_OBJ_MESH_AND_SAVED_COPY(path, Y, Z, num, shade_mode, name_of_material)\
62 snprintf(buffer, PATH_MAX, "%s%s", input_template, #path); \ 58 snprintf(buffer, PATH_MAX, "%s%s", input_template, #path); \
63 ADD_OBJ_MESH(buffer, Y, Z, num, shade_mode, name_of_material) \ 59 ADD_OBJ_MESH(buffer, Y, Z, num, shade_mode, name_of_material) \
64 snprintf(buffer, PATH_MAX, "%s%s%s", output_template, #path, ".obj"); \ 60 snprintf(buffer, PATH_MAX, "%s%s%s", output_template, #path, ".obj"); \
65 eo_do(mesh[num], efl_file_save(buffer, NULL, NULL)); \ 61 efl_file_save(mesh[num], buffer, NULL, NULL); \
66 snprintf(buffer, PATH_MAX, "%s%s", output_template, #path); \ 62 snprintf(buffer, PATH_MAX, "%s%s", output_template, #path); \
67 ADD_OBJ_MESH(buffer, Y + COPY_OFFSET, Z, num + 4, shade_mode, name_of_material) 63 ADD_OBJ_MESH(buffer, Y + COPY_OFFSET, Z, num + 4, shade_mode, name_of_material)
68 64
69#define ADD_TEXTURE(name, path) \ 65#define ADD_TEXTURE(name, path) \
70 name = eo_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas); \ 66 name = eo_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas); \
71 eo_do(name, \ 67 evas_canvas3d_texture_file_set(name, path, NULL); \
72 evas_canvas3d_texture_file_set(path, NULL), \ 68 evas_canvas3d_texture_filter_set(name, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST, \
73 evas_canvas3d_texture_filter_set(EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST, \ 69 EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST); \
74 EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST), \ 70 evas_canvas3d_texture_wrap_set(name, EVAS_CANVAS3D_WRAP_MODE_REPEAT, \
75 evas_canvas3d_texture_wrap_set(EVAS_CANVAS3D_WRAP_MODE_REPEAT, \ 71 EVAS_CANVAS3D_WRAP_MODE_REPEAT);
76 EVAS_CANVAS3D_WRAP_MODE_REPEAT));
77 72
78#define ADD_MATERIAL(name) \ 73#define ADD_MATERIAL(name) \
79 name = eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas); \ 74 name = eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas); \
80 eo_do(name, \ 75 evas_canvas3d_material_enable_set(name, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE); \
81 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE), \ 76 evas_canvas3d_material_enable_set(name, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE); \
82 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE), \ 77 evas_canvas3d_material_enable_set(name, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE); \
83 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE),\ 78 evas_canvas3d_material_enable_set(name, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE); \
84 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE), \ 79 evas_canvas3d_material_color_set(name, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, \
85 evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, \ 80 COL_RED, 0.5); \
86 COL_RED, 0.5), \ 81 evas_canvas3d_material_color_set(name, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, \
87 evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, \ 82 COL_GREEN, 0.5); \
88 COL_GREEN, 0.5), \ 83 evas_canvas3d_material_color_set(name, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, \
89 evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, \ 84 COL_BLUE, 0.5); \
90 COL_BLUE, 0.5), \ 85 evas_canvas3d_material_shininess_set(name, 100.0);
91 evas_canvas3d_material_shininess_set(100.0));
92 86
93static const char *texture_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/sweet_home_reversed.png"; 87static const char *texture_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/sweet_home_reversed.png";
94static const char *output_template = PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES "/saved_"; 88static const char *output_template = PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES "/saved_";
@@ -118,8 +112,7 @@ _animate_scene(void *data)
118{ 112{
119 angle += 0.2; 113 angle += 0.2;
120 114
121 eo_do((Evas_Canvas3D_Node *)data, 115 evas_canvas3d_node_orientation_angle_axis_set((Evas_Canvas3D_Node *)data, angle, 1.0, 1.0, -1.0);
122 evas_canvas3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, -1.0));
123 116
124 /* Rotate */ 117 /* Rotate */
125 if (angle > 360.0) angle -= 360.0f; 118 if (angle > 360.0) angle -= 360.0f;
@@ -139,8 +132,8 @@ _on_canvas_resize(Ecore_Evas *ee)
139 int w, h; 132 int w, h;
140 133
141 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); 134 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
142 eo_do(background, efl_gfx_size_set(w, h)); 135 efl_gfx_size_set(background, w, h);
143 eo_do(image, efl_gfx_size_set(w, h)); 136 efl_gfx_size_set(image, w, h);
144} 137}
145 138
146int 139int
@@ -167,51 +160,38 @@ main(void)
167 scene = eo_add(EVAS_CANVAS3D_SCENE_CLASS, evas); 160 scene = eo_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
168 161
169 /* Add the root node for the scene. */ 162 /* Add the root node for the scene. */
170 root_node = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, 163 root_node = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_NODE));
171 evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_NODE));
172 164
173 /* Add the camera. */ 165 /* Add the camera. */
174 camera = eo_add(EVAS_CANVAS3D_CAMERA_CLASS, evas); 166 camera = eo_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
175 eo_do(camera, 167 evas_canvas3d_camera_projection_perspective_set(camera, 20.0, 1.0, 1.0, 500.0);
176 evas_canvas3d_camera_projection_perspective_set(20.0, 1.0, 1.0, 500.0));
177 168
178 camera_node = 169 camera_node =
179 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, 170 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
180 evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_CAMERA)); 171 evas_canvas3d_node_camera_set(camera_node, camera);
181 eo_do(camera_node, 172 evas_canvas3d_node_member_add(root_node, camera_node);
182 evas_canvas3d_node_camera_set(camera)); 173 evas_canvas3d_node_position_set(camera_node, 100.0, 0.0, 0.0);
183 eo_do(root_node, 174 evas_canvas3d_node_look_at_set(camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 1.0);
184 evas_canvas3d_node_member_add(camera_node));
185 eo_do(camera_node,
186 evas_canvas3d_node_position_set(100.0, 0.0, 0.0),
187 evas_canvas3d_node_look_at_set(EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0,
188 EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 1.0));
189 /* Add the light. */ 175 /* Add the light. */
190 light = eo_add(EVAS_CANVAS3D_LIGHT_CLASS, evas); 176 light = eo_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
191 eo_do(light, 177 evas_canvas3d_light_ambient_set(light, 1.0, 1.0, 1.0, 1.0);
192 evas_canvas3d_light_ambient_set(1.0, 1.0, 1.0, 1.0), 178 evas_canvas3d_light_diffuse_set(light, 1.0, 1.0, 1.0, 1.0);
193 evas_canvas3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0), 179 evas_canvas3d_light_specular_set(light, 1.0, 1.0, 1.0, 1.0);
194 evas_canvas3d_light_specular_set(1.0, 1.0, 1.0, 1.0), 180 evas_canvas3d_light_directional_set(light, EINA_TRUE);
195 evas_canvas3d_light_directional_set(EINA_TRUE));
196 181
197 light_node = 182 light_node =
198 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, 183 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
199 evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_LIGHT)); 184 evas_canvas3d_node_light_set(light_node, light);
200 eo_do(light_node, 185 evas_canvas3d_node_position_set(light_node, 10.0, 0.0, 0.0);
201 evas_canvas3d_node_light_set(light), 186 evas_canvas3d_node_look_at_set(light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
202 evas_canvas3d_node_position_set(10.0, 0.0, 0.0), 187 evas_canvas3d_node_member_add(root_node, light_node);
203 evas_canvas3d_node_look_at_set(EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0,
204 EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0));
205 eo_do(root_node,
206 evas_canvas3d_node_member_add(light_node));
207 188
208 ADD_TEXTURE(texture, texture_path) 189 ADD_TEXTURE(texture, texture_path)
209 190
210 ADD_MATERIAL(material) 191 ADD_MATERIAL(material)
211 192
212 ADD_MATERIAL(material_with_tex) 193 ADD_MATERIAL(material_with_tex)
213 eo_do(material_with_tex, 194 evas_canvas3d_material_texture_set(material_with_tex, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, texture);
214 evas_canvas3d_material_texture_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, texture));
215 195
216 if (!ecore_file_mkpath(PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES)) 196 if (!ecore_file_mkpath(PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES))
217 fprintf(stderr, "Failed to create folder %s\n\n", 197 fprintf(stderr, "Failed to create folder %s\n\n",
@@ -227,26 +207,23 @@ main(void)
227 EVAS_CANVAS3D_SHADE_MODE_SHADOW_MAP_RENDER, NULL) 207 EVAS_CANVAS3D_SHADE_MODE_SHADOW_MAP_RENDER, NULL)
228 208
229 /* Set up scene. */ 209 /* Set up scene. */
230 eo_do(scene, 210 evas_canvas3d_scene_root_node_set(scene, root_node);
231 evas_canvas3d_scene_root_node_set(root_node), 211 evas_canvas3d_scene_camera_node_set(scene, camera_node);
232 evas_canvas3d_scene_camera_node_set(camera_node), 212 evas_canvas3d_scene_size_set(scene, WIDTH, HEIGHT);
233 evas_canvas3d_scene_size_set(WIDTH, HEIGHT));
234 213
235 /* Add a background rectangle MESHES. */ 214 /* Add a background rectangle MESHES. */
236 background = eo_add(EVAS_RECTANGLE_CLASS, evas); 215 background = eo_add(EVAS_RECTANGLE_CLASS, evas);
237 eo_do(background, 216 efl_gfx_color_set(background, 0, 0, 0, 255);
238 efl_gfx_color_set(0, 0, 0, 255), 217 efl_gfx_size_set(background, WIDTH, HEIGHT);
239 efl_gfx_size_set(WIDTH, HEIGHT), 218 efl_gfx_visible_set(background, EINA_TRUE);
240 efl_gfx_visible_set(EINA_TRUE));
241 219
242 /* Add an image object for 3D scene rendering. */ 220 /* Add an image object for 3D scene rendering. */
243 image = evas_object_image_filled_add(evas); 221 image = evas_object_image_filled_add(evas);
244 eo_do(image, 222 efl_gfx_size_set(image, WIDTH, HEIGHT);
245 efl_gfx_size_set(WIDTH, HEIGHT), 223 efl_gfx_visible_set(image, EINA_TRUE);
246 efl_gfx_visible_set(EINA_TRUE));
247 224
248 /* Set the image object as render target for 3D scene. */ 225 /* Set the image object as render target for 3D scene. */
249 eo_do(image, evas_obj_image_scene_set(scene)); 226 evas_obj_image_scene_set(image, scene);
250 227
251 for (i = 0; i < NUMBER_OF_MESHES; i++) 228 for (i = 0; i < NUMBER_OF_MESHES; i++)
252 ecore_timer_add(ANIM_SPEED, _animate_scene, mesh_node[i]); 229 ecore_timer_add(ANIM_SPEED, _animate_scene, mesh_node[i]);