Obj_io. Step 2. Example to see fix on step 1.

This commit is contained in:
Bogdan Devichev 2015-01-28 18:49:03 +02:00
parent 199ea77b4e
commit 6053e67310
4 changed files with 330 additions and 0 deletions

View File

@ -0,0 +1,197 @@
/**
* Temporary example to explain what changed in obj.
*
* @verbatim
* gcc -o example_to_explain_fixes example_to_explain_fixes.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo`
* @endverbatim
*/
#define EFL_EO_API_SUPPORT
#define EFL_BETA_API_SUPPORT
#include <Eo.h>
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#define WIDTH 1900
#define HEIGHT 1080
Ecore_Evas *ecore_evas = NULL;
Evas *evas = NULL;
Eo *background = NULL;
Eo *image = NULL;
Eo *scene = NULL;
Eo *root_node = NULL;
Eo *camera_node = NULL;
Eo *light_node = NULL;
Eo *camera = NULL;
Eo *mesh_node = NULL;
Eo *mesh = NULL;
Eo *material = NULL;
Eo *texture = NULL;
Eo *light = NULL;
static float angle = 0;
static Eina_Bool
_animate_scene(void *data)
{
angle += 0.5;
eo_do((Evas_3D_Node *)data, evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, -1.0));
/* Rotate */
if (angle > 360.0) angle -= 360.0f;
return EINA_TRUE;
}
static void
_on_delete(Ecore_Evas *ee EINA_UNUSED)
{
ecore_main_loop_quit();
}
static void
_on_canvas_resize(Ecore_Evas *ee)
{
int w, h;
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
eo_do(background, evas_obj_size_set(w, h));
eo_do(image, evas_obj_size_set(w, h));
}
int
main(void)
{
//Unless Evas 3D supports Software renderer, we set gl backened forcely.
setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
if (!ecore_evas_init()) return 0;
ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
if (!ecore_evas) return 0;
ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
ecore_evas_show(ecore_evas);
evas = ecore_evas_get(ecore_evas);
/* Add a scene object .*/
scene = eo_add(EVAS_3D_SCENE_CLASS, evas);
/* Add the root node for the scene. */
root_node = eo_add(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE));
/* Add the camera. */
camera = eo_add(EVAS_3D_CAMERA_CLASS, evas);
eo_do(camera,
evas_3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0));
camera_node =
eo_add(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_CAMERA));
eo_do(camera_node,
evas_3d_node_camera_set(camera));
eo_do(root_node,
evas_3d_node_member_add(camera_node));
eo_do(camera_node,
evas_3d_node_position_set(10.0, 0.0, 2.0),
evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 2.0,
EVAS_3D_SPACE_PARENT, 0.0, 0.0, 1.0));
/* Add the light. */
light = eo_add(EVAS_3D_LIGHT_CLASS, evas);
eo_do(light,
evas_3d_light_ambient_set(1.0, 1.0, 1.0, 1.0),
evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0),
evas_3d_light_directional_set(EINA_TRUE));
light_node =
eo_add(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_LIGHT));
eo_do(light_node,
evas_3d_node_light_set(light),
evas_3d_node_position_set(10.0, 0.0, 2.0),
evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0,
EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0));
eo_do(root_node,
evas_3d_node_member_add(light_node));
/* Add the mesh. */
mesh = eo_add(EVAS_3D_MESH_CLASS, evas);
material = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
eo_do(mesh,
efl_file_set("sweet_home.obj", NULL),
evas_3d_mesh_frame_material_set(0, material),
evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
texture = eo_add(EVAS_3D_TEXTURE_CLASS, evas);
eo_do(texture,
evas_3d_texture_file_set("sweet_home_temp.png", NULL),
evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_NEAREST,
EVAS_3D_TEXTURE_FILTER_NEAREST),
evas_3d_texture_wrap_set(EVAS_3D_WRAP_MODE_REPEAT,
EVAS_3D_WRAP_MODE_REPEAT));
eo_do(material,
evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, texture),
evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT,
0.01, 0.01, 0.01, 1.0),
evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE,
1.0, 1.0, 1.0, 1.0),
evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR,
1.0, 1.0, 1.0, 1.0),
evas_3d_material_shininess_set(50.0));
eo_do(mesh, efl_file_save("saved_home.obj", NULL, NULL));
mesh_node = eo_add(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
eo_do(root_node,
evas_3d_node_member_add(mesh_node));
eo_do(mesh_node,
evas_3d_node_mesh_add(mesh));
/* Set up scene. */
eo_do(scene,
evas_3d_scene_root_node_set(root_node),
evas_3d_scene_camera_node_set(camera_node),
evas_3d_scene_size_set(WIDTH, HEIGHT));
/* Add a background rectangle objects. */
background = eo_add(EVAS_RECTANGLE_CLASS, evas);
eo_do(background,
evas_obj_color_set(0, 0, 0, 255),
evas_obj_size_set(WIDTH, HEIGHT),
evas_obj_visibility_set(EINA_TRUE));
/* Add an image object for 3D scene rendering. */
image = evas_object_image_filled_add(evas);
eo_do(image,
evas_obj_size_set(WIDTH, HEIGHT),
evas_obj_visibility_set(EINA_TRUE));
/* Set the image object as render target for 3D scene. */
eo_do(image, evas_obj_image_scene_set(scene));
ecore_timer_add(0.01, _animate_scene, mesh_node);
/* Enter main loop. */
ecore_main_loop_begin();
ecore_evas_free(ecore_evas);
ecore_evas_shutdown();
return 0;
}

View File

@ -0,0 +1,22 @@
# Blender MTL File: 'sweet_home.blend'
# Material Count: 2
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd /home/bdevichev/Desktop/rect.png
newmtl Material_Untitled
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd /home/bdevichev/Desktop/sweet_home.png

View File

@ -0,0 +1,111 @@
# Blender v2.69 (sub 0) OBJ File: 'sweet_home.blend'
# www.blender.org
mtllib sweet_home.mtl
o Cube
v 1.000003 -0.999997 0.000002
v -0.999997 -1.000003 0.000002
v -1.000002 0.999998 0.000002
v 0.999998 1.000002 0.000002
v 1.000002 -0.999998 2.000002
v -0.999998 -1.000002 2.000002
v -1.000002 0.999998 2.000002
v 0.999997 1.000003 2.000002
v 0.000002 -1.000000 3.075149
v -0.000002 1.000000 3.075149
v 0.666668 -0.644449 2.358384
v 0.333335 -0.644450 2.716766
v 0.666667 -0.293067 2.358384
v 0.333334 -0.293068 2.716766
v 0.662209 -0.629904 2.991038
v 0.337794 -0.629904 2.980731
v 0.662208 -0.307612 2.991038
v 0.337793 -0.307613 2.980731
vt 0.013689 0.608350
vt 0.285640 0.608350
vt 0.285640 0.978776
vt 0.013689 0.978776
vt 0.564957 0.983606
vt 0.293719 0.983606
vt 0.293719 0.613180
vt 0.564957 0.613180
vt 0.646856 0.021326
vt 0.083404 0.021326
vt 0.083369 0.584801
vt 0.646820 0.584801
vt 0.949735 0.303064
vt 0.654355 0.022016
vt 0.957234 0.303753
vt 0.654320 0.585490
vt 0.090869 0.585491
vt 0.090904 0.022016
vt 0.820337 0.692442
vt 0.820337 0.803140
vt 0.740863 0.803140
vt 0.740863 0.692442
vt 0.695284 0.903159
vt 0.695284 0.830265
vt 0.768687 0.830265
vt 0.768687 0.903159
vt 0.874667 0.789013
vt 0.874667 0.893367
vt 0.979009 0.893367
vt 0.979009 0.789013
vt 0.567834 0.981515
vt 0.567834 0.611089
vt 0.768686 0.903159
vt 0.768687 0.823686
vt 0.811715 0.826975
vt 0.811715 0.899870
vt 0.591196 0.903159
vt 0.591196 0.823686
vt 0.695284 0.826975
vt 0.695284 0.899870
vt 0.666035 0.721564
vt 0.667476 0.661838
vt 0.740863 0.660019
vt 0.591196 0.741571
vt 0.666035 0.660015
vt 0.666035 0.803140
vt 0.592658 0.801339
vt 0.013481 0.981515
vt 0.104078 0.915663
vt 0.194676 0.915663
vt 0.285274 0.981515
vt 0.194676 0.850582
vt 0.285274 0.611089
vt 0.104078 0.850582
vt 0.013481 0.611089
vn -0.732233 -0.000002 0.681054
vn 1.000000 0.000002 0.000000
vn 0.000002 -1.000000 0.000000
vn -0.000002 1.000000 -0.000000
vn -0.732233 -0.000001 -0.681054
vn -0.031755 -0.000000 0.999496
vn -0.000000 0.000000 -1.000000
vn -1.000000 -0.000002 -0.000000
vn -0.999857 -0.000002 0.016891
vn 0.999975 0.000002 0.007049
vn 0.017155 0.999327 0.032422
vn 0.017160 -0.999327 0.032422
vn 0.732233 0.000001 0.681054
vn 0.732233 0.000002 0.681054
vn 0.732234 0.000002 0.681053
usemtl Material
s off
f 6/1/1 9/2/1 10/3/1 7/4/1
usemtl Material_Untitled
f 4/5/2 8/6/2 5/7/2 1/8/2
f 6/9/3 2/10/3 1/11/3 5/12/3 9/13/3
f 7/14/4 10/15/4 8/16/4 4/17/4 3/18/4
f 11/19/5 12/20/5 14/21/5 13/22/5
f 15/23/6 17/24/6 18/25/6 16/26/6
f 2/27/7 3/28/7 4/29/7 1/30/7
f 6/2/8 7/3/8 3/31/8 2/32/8
f 14/33/9 12/34/9 16/35/9 18/36/9
f 11/37/10 13/38/10 17/39/10 15/40/10
f 13/21/11 14/41/11 18/42/11 17/43/11
f 12/44/12 11/45/12 15/46/12 16/47/12
f 5/48/13 11/49/13 12/50/13 9/51/13
f 9/51/14 12/50/14 14/52/14 10/53/14
f 13/54/14 8/55/14 10/53/14 14/52/14
f 11/49/15 5/48/15 8/55/15 13/54/15

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 KiB