2014-12-12 07:23:49 -08:00
|
|
|
/**
|
2015-02-23 08:59:05 -08:00
|
|
|
* Simple Evas example illustrating import from mmap.
|
|
|
|
*
|
|
|
|
* Open files to Eina_Files.
|
|
|
|
* Read meshes from Eina_Files.
|
|
|
|
* Show the results.
|
|
|
|
*
|
|
|
|
* @verbatim
|
2015-04-15 03:16:48 -07:00
|
|
|
* gcc -o evas-3d-mmap-set evas-3d-mmap-set.c `pkg-config --libs --cflags efl evas ecore ecore-evas eina eo` -lm
|
2015-02-23 08:59:05 -08:00
|
|
|
* @endverbatim
|
|
|
|
*/
|
2014-12-12 07:23:49 -08:00
|
|
|
|
2015-02-20 03:02:08 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#else
|
|
|
|
#define PACKAGE_EXAMPLES_DIR "."
|
2014-12-12 07:23:49 -08:00
|
|
|
#define EFL_EO_API_SUPPORT
|
|
|
|
#define EFL_BETA_API_SUPPORT
|
2015-02-20 08:59:27 -08:00
|
|
|
#endif
|
2014-12-12 07:23:49 -08:00
|
|
|
|
|
|
|
#include <Eo.h>
|
|
|
|
#include <Evas.h>
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_Evas.h>
|
2015-02-20 08:59:27 -08:00
|
|
|
#include "evas-common.h"
|
2014-12-12 07:23:49 -08:00
|
|
|
|
2014-12-17 05:48:00 -08:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define WIDTH 1000
|
|
|
|
#define HEIGHT 1000
|
|
|
|
|
|
|
|
#define LOAD_AND_ADD_MESH(extention, number) \
|
2015-02-20 03:02:08 -08:00
|
|
|
snprintf(buffer, PATH_MAX, "%s%s", template_path, #extention); \
|
|
|
|
extention##_file = eina_file_open(buffer , 0); \
|
2014-12-17 05:48:00 -08:00
|
|
|
mesh_##extention = eo_add(EVAS_3D_MESH_CLASS, evas); \
|
|
|
|
eo_do(mesh_##extention, \
|
2015-04-03 07:30:47 -07:00
|
|
|
efl_file_mmap_set(extention##_file, NULL), \
|
2014-12-17 05:48:00 -08:00
|
|
|
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);
|
2014-12-12 07:23:49 -08:00
|
|
|
|
2015-02-20 08:59:27 -08:00
|
|
|
static const char *template_path = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/mesh_for_mmap.";
|
2015-02-20 03:02:08 -08:00
|
|
|
|
2014-12-12 07:23:49 -08:00
|
|
|
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 *material = NULL;
|
|
|
|
Eo *light = NULL;
|
|
|
|
|
2014-12-17 05:48:00 -08:00
|
|
|
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;
|
2015-03-02 18:23:54 -08:00
|
|
|
static float md2_animation_velocity = 1.0;
|
2014-12-17 05:48:00 -08:00
|
|
|
|
|
|
|
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_obj(void *data)
|
|
|
|
{
|
|
|
|
obj_animation_parameter += obj_animation_velocity;
|
|
|
|
float oap = obj_animation_parameter/200;
|
|
|
|
|
|
|
|
eo_do((Evas_3D_Node *)data,
|
2015-03-02 18:23:54 -08:00
|
|
|
evas_3d_node_scale_set(oap, oap, oap),
|
2014-12-17 05:48:00 -08:00
|
|
|
evas_3d_node_orientation_angle_axis_set(obj_animation_parameter, 0.0, 1.0, 0.0));
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2014-12-12 07:23:49 -08:00
|
|
|
|
|
|
|
static Eina_Bool
|
2014-12-17 05:48:00 -08:00
|
|
|
_animate_ply(void *data)
|
2014-12-12 07:23:49 -08:00
|
|
|
{
|
2014-12-17 05:48:00 -08:00
|
|
|
ply_animation_parameter += ply_animation_velocity;
|
2014-12-12 07:23:49 -08:00
|
|
|
|
2014-12-17 05:48:00 -08:00
|
|
|
eo_do((Evas_3D_Node *)data,
|
|
|
|
evas_3d_node_orientation_angle_axis_set(ply_animation_parameter, 1.0, 0.0, 0.0));
|
2014-12-12 07:23:49 -08:00
|
|
|
|
2014-12-17 05:48:00 -08:00
|
|
|
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));
|
|
|
|
|
2015-03-02 18:23:54 -08:00
|
|
|
if (md2_animation_parameter >= 360.0 || md2_animation_parameter <= 0.0)
|
|
|
|
md2_animation_velocity *= -1.0;
|
2014-12-12 07:23:49 -08:00
|
|
|
|
|
|
|
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);
|
2015-04-03 07:30:47 -07:00
|
|
|
eo_do(background, efl_gfx_size_set(w, h));
|
|
|
|
eo_do(image, efl_gfx_size_set(w, h));
|
2014-12-12 07:23:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2015-02-20 03:02:08 -08:00
|
|
|
char buffer[PATH_MAX];
|
2014-12-17 05:48:00 -08:00
|
|
|
Eina_File *obj_file, *ply_file, *eet_file, *md2_file;
|
|
|
|
|
2014-12-12 07:23:49 -08:00
|
|
|
//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,
|
2014-12-17 05:48:00 -08:00
|
|
|
evas_3d_camera_projection_perspective_set(10.0, 1.0, 1.0, 500.0));
|
2014-12-12 07:23:49 -08:00
|
|
|
|
|
|
|
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,
|
2014-12-17 05:48:00 -08:00
|
|
|
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));
|
2014-12-12 07:23:49 -08:00
|
|
|
/* 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),
|
2014-12-17 05:48:00 -08:00
|
|
|
evas_3d_node_position_set(1.0, 0.0, 100.0),
|
2014-12-12 07:23:49 -08:00
|
|
|
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));
|
|
|
|
|
|
|
|
material = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
|
|
|
|
|
|
|
|
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),
|
|
|
|
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,
|
2014-12-17 05:48:00 -08:00
|
|
|
1.0, 1.0, 0.0, 1.0),
|
2014-12-12 07:23:49 -08:00
|
|
|
evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR,
|
2014-12-17 05:48:00 -08:00
|
|
|
0.5, 0.0, 1.0, 1.0),
|
2014-12-12 07:23:49 -08:00
|
|
|
evas_3d_material_shininess_set(50.0));
|
|
|
|
|
2014-12-17 05:48:00 -08:00
|
|
|
/* 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);
|
2014-12-12 07:23:49 -08:00
|
|
|
|
|
|
|
/* 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,
|
2015-04-03 07:30:47 -07:00
|
|
|
efl_gfx_color_set(20, 20, 200, 255),
|
|
|
|
efl_gfx_size_set(WIDTH, HEIGHT),
|
|
|
|
efl_gfx_visible_set(EINA_TRUE));
|
2014-12-12 07:23:49 -08:00
|
|
|
|
|
|
|
/* Add an image object for 3D scene rendering. */
|
|
|
|
image = evas_object_image_filled_add(evas);
|
|
|
|
eo_do(image,
|
2015-04-03 07:30:47 -07:00
|
|
|
efl_gfx_size_set(WIDTH, HEIGHT),
|
|
|
|
efl_gfx_visible_set(EINA_TRUE));
|
2014-12-12 07:23:49 -08:00
|
|
|
|
|
|
|
/* Set the image object as render target for 3D scene. */
|
|
|
|
eo_do(image, evas_obj_image_scene_set(scene));
|
|
|
|
|
|
|
|
/* Enter main loop. */
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
|
|
|
ecore_evas_free(ecore_evas);
|
|
|
|
ecore_evas_shutdown();
|
|
|
|
|
|
|
|
eina_file_close(obj_file);
|
|
|
|
eina_file_close(ply_file);
|
|
|
|
eina_file_close(eet_file);
|
|
|
|
eina_file_close(md2_file);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|