Model_save_load. Step 11. Better example of _mmap_set and resources for it are added.

This commit is contained in:
Bogdan Devichev 2014-12-17 15:48:00 +02:00
parent f751141009
commit c908c654f5
6 changed files with 36815 additions and 89 deletions

View File

@ -6,10 +6,9 @@
* Show the results.
*
* @verbatim
* gcc -o evas-3d-mmap-set evas-3d-mmap-set.c `pkg-config --libs --cflags evas ecore ecore-evas eina eo`
* gcc -o evas-3d-mmap-set evas-3d-mmap-set.c `pkg-config --libs --cflags evas ecore ecore-evas eina eo` -lm
* @endverbatim
*/
//TODO This example will be cool in nearest future
#define EFL_EO_API_SUPPORT
#define EFL_BETA_API_SUPPORT
@ -19,8 +18,33 @@
#include <Ecore.h>
#include <Ecore_Evas.h>
#define WIDTH 400
#define HEIGHT 400
#include <math.h>
#define WIDTH 1000
#define HEIGHT 1000
#define LOAD_AND_ADD_MESH(extention, number) \
extention##_file = eina_file_open("mesh_mmap_set/mesh."#extention, 0); \
mesh_##extention = eo_add(EVAS_3D_MESH_CLASS, evas); \
eo_do(mesh_##extention, \
evas_3d_mesh_mmap_set(extention##_file, NULL), \
evas_3d_mesh_frame_material_set(0, material), \
evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG)); \
node_##extention = 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(node_##extention)); \
eo_do(node_##extention, evas_3d_node_mesh_add(mesh_##extention), \
evas_3d_node_position_set(initial_node_data[number * 10], \
initial_node_data[number * 10 + 1], \
initial_node_data[number * 10 + 2]), \
evas_3d_node_scale_set(initial_node_data[number * 10 + 3], \
initial_node_data[number * 10 + 4], \
initial_node_data[number * 10 + 5]), \
evas_3d_node_orientation_angle_axis_set(initial_node_data[number * 10 + 6], \
initial_node_data[number * 10 + 7], \
initial_node_data[number * 10 + 8], \
initial_node_data[number * 10 + 9]));\
ecore_timer_add(0.01, _animate_##extention, node_##extention);
Ecore_Evas *ecore_evas = NULL;
Evas *evas = NULL;
@ -32,28 +56,85 @@ Eo *root_node = NULL;
Eo *camera_node = NULL;
Eo *light_node = NULL;
Eo *camera = NULL;
Eo *mesh_node_obj = NULL;
Eo *mesh_obj = NULL;
Eo *mesh_node_ply = NULL;
Eo *mesh_ply = NULL;
Eo *mesh_node_eet = NULL;
Eo *mesh_eet = NULL;
Eo *mesh_node_md2 = NULL;
Eo *mesh_md2 = NULL;
Eo *material = NULL;
Eo *light = NULL;
static float angle = 0;
Eo *node_obj = NULL, *node_ply = NULL, *node_eet = NULL, *node_md2 = NULL;
Eo *mesh_obj = NULL, *mesh_ply = NULL, *mesh_eet = NULL, *mesh_md2 = NULL;
static float obj_animation_parameter = 1.0;
static float ply_animation_parameter = 180.0;
static float eet_animation_parameter = 0.0;
static float md2_animation_parameter = 0.0;
static float obj_animation_velocity = 1.0;
static float ply_animation_velocity = 1.0;
static float eet_animation_velocity = 1.0;
static float md2_animation_velocity = 32.0;
static const float initial_node_data[] =
/*position scale rotation*/
{
/*obj*/
3.0, 3.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
/*ply*/
-3.0, 3.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
/*eet*/
3.0, -3.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
/*md2*/
-3.0, -3.0, 0.0, 0.001, 0.001, 0.001, 180.0, 0.0, 1.0, 0.0
};
static Eina_Bool
_animate_scene(void *data)
_animate_obj(void *data)
{
angle += 0.5;
obj_animation_parameter += obj_animation_velocity;
float oap = obj_animation_parameter/200;
eo_do((Evas_3D_Node *)data, evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
eo_do((Evas_3D_Node *)data,
evas_3d_node_scale_set(oap, oap, pow(obj_animation_parameter, 2) / 2000),
evas_3d_node_orientation_angle_axis_set(obj_animation_parameter, 0.0, 1.0, 0.0));
/* Rotate */
if (angle > 360.0) angle -= 360.0f;
if (obj_animation_parameter >= 360.0 || obj_animation_parameter <= 0.0)
obj_animation_velocity *= -1.0;
return EINA_TRUE;
}
static Eina_Bool
_animate_eet(void *data)
{
eet_animation_parameter += eet_animation_velocity;
eo_do((Evas_3D_Node *)data,
evas_3d_node_orientation_angle_axis_set(eet_animation_parameter, 1.0, 0.0, 0.0));
eet_animation_velocity = sin(eet_animation_parameter / 180 * M_PI) + 1.1;
return EINA_TRUE;
}
static Eina_Bool
_animate_ply(void *data)
{
ply_animation_parameter += ply_animation_velocity;
eo_do((Evas_3D_Node *)data,
evas_3d_node_orientation_angle_axis_set(ply_animation_parameter, 1.0, 0.0, 0.0));
if (ply_animation_parameter > 360.0) ply_animation_parameter -= 180.0f;
return EINA_TRUE;
}
static Eina_Bool
_animate_md2(void *data)
{
md2_animation_parameter += md2_animation_velocity;
eo_do((Evas_3D_Node *)data,
evas_3d_node_mesh_frame_set(mesh_md2, md2_animation_parameter));
if (md2_animation_parameter > 256 * 100) md2_animation_parameter = 0;
return EINA_TRUE;
}
@ -77,6 +158,8 @@ _on_canvas_resize(Ecore_Evas *ee)
int
main(void)
{
Eina_File *obj_file, *ply_file, *eet_file, *md2_file;
//Unless Evas 3D supports Software renderer, we set gl backened forcely.
setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
@ -86,16 +169,6 @@ main(void)
if (!ecore_evas) return 0;
Eina_File *obj_file;
Eina_File *ply_file;
Eina_File *eet_file;
Eina_File *md2_file;
obj_file = eina_file_open("man_mesh.obj", 0);
ply_file = eina_file_open("ply_files/Normal_UVs_Colors.ply", 0);
eet_file = eina_file_open("sonic.eet", 0);
md2_file = eina_file_open("sonic.md2", 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);
@ -112,7 +185,7 @@ main(void)
/* 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));
evas_3d_camera_projection_perspective_set(10.0, 1.0, 1.0, 500.0));
camera_node =
eo_add(EVAS_3D_NODE_CLASS, evas,
@ -122,9 +195,9 @@ main(void)
eo_do(root_node,
evas_3d_node_member_add(camera_node));
eo_do(camera_node,
evas_3d_node_position_set(100.0, 0.0, 20.0),
evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 20.0,
EVAS_3D_SPACE_PARENT, 0.0, 0.0, 1.0));
evas_3d_node_position_set(0.0, 0.0, 100.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));
/* Add the light. */
light = eo_add(EVAS_3D_LIGHT_CLASS, evas);
eo_do(light,
@ -138,7 +211,7 @@ main(void)
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_LIGHT));
eo_do(light_node,
evas_3d_node_light_set(light),
evas_3d_node_position_set(1000.0, 0.0, 1000.0),
evas_3d_node_position_set(1.0, 0.0, 100.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,
@ -146,32 +219,6 @@ main(void)
material = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
/* Add the meshes. */
mesh_obj = eo_add(EVAS_3D_MESH_CLASS, evas);
mesh_ply = eo_add(EVAS_3D_MESH_CLASS, evas);
mesh_eet = eo_add(EVAS_3D_MESH_CLASS, evas);
mesh_md2 = eo_add(EVAS_3D_MESH_CLASS, evas);
eo_do(mesh_obj,
evas_3d_mesh_mmap_set(obj_file, NULL),
evas_3d_mesh_frame_material_set(0, material),
evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
eo_do(mesh_ply,
evas_3d_mesh_mmap_set(ply_file, NULL),
evas_3d_mesh_frame_material_set(0, material),
evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
eo_do(mesh_eet,
evas_3d_mesh_mmap_set(eet_file, NULL),
evas_3d_mesh_frame_material_set(0, material),
evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
eo_do(mesh_md2,
evas_3d_mesh_mmap_set(md2_file, NULL),
evas_3d_mesh_frame_material_set(0, material),
evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
eo_do(material,
evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
@ -180,33 +227,16 @@ main(void)
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),
1.0, 1.0, 0.0, 1.0),
evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR,
1.0, 1.0, 1.0, 1.0),
0.5, 0.0, 1.0, 1.0),
evas_3d_material_shininess_set(50.0));
mesh_node_obj = eo_add(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
mesh_node_ply = eo_add(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
mesh_node_eet = eo_add(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
mesh_node_md2 = 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_obj));
eo_do(root_node, evas_3d_node_member_add(mesh_node_ply));
eo_do(root_node, evas_3d_node_member_add(mesh_node_md2));
eo_do(root_node, evas_3d_node_member_add(mesh_node_eet));
eo_do(mesh_node_obj, evas_3d_node_mesh_add(mesh_obj),
evas_3d_node_position_set(0, -30, 0));
eo_do(mesh_node_ply, evas_3d_node_mesh_add(mesh_ply),
evas_3d_node_position_set(0, -10, 0));
eo_do(mesh_node_eet, evas_3d_node_mesh_add(mesh_eet),
evas_3d_node_position_set(0, 10, 0));
eo_do(mesh_node_md2, evas_3d_node_mesh_add(mesh_md2),
evas_3d_node_position_set(0, 30, 0));
/* Add the meshes */
LOAD_AND_ADD_MESH(obj, 0);
LOAD_AND_ADD_MESH(eet, 1);
LOAD_AND_ADD_MESH(ply, 2);
LOAD_AND_ADD_MESH(md2, 3);
/* Set up scene. */
eo_do(scene,
@ -217,7 +247,7 @@ main(void)
/* 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_color_set(20, 20, 200, 255),
evas_obj_size_set(WIDTH, HEIGHT),
evas_obj_visibility_set(EINA_TRUE));
@ -230,11 +260,6 @@ main(void)
/* 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_obj);
ecore_timer_add(0.01, _animate_scene, mesh_node_ply);
ecore_timer_add(0.01, _animate_scene, mesh_node_eet);
ecore_timer_add(0.01, _animate_scene, mesh_node_md2);
/* Enter main loop. */
ecore_main_loop_begin();

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,11 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material.001
Ns 90.196078
Ka 0.000000 0.000000 0.000000
Kd 0.124158 0.125842 0.000000
Ks 0.025297 0.000000 1.000000
Ni 1.000000
d 1.000000
illum 2

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff