2014-10-06 07:27:06 -07:00
|
|
|
/**
|
2015-02-23 08:59:05 -08:00
|
|
|
* Simple Evas example illustrating .eet import/export
|
|
|
|
*
|
|
|
|
* Take mesh from md2.
|
|
|
|
* Set material to it.
|
|
|
|
* Show it in left side.
|
|
|
|
* Save the first frame of this mesh to eet. (static only)
|
|
|
|
* Take result to another mesh from eet.
|
|
|
|
* Show it in right side.
|
|
|
|
*
|
|
|
|
* @verbatim
|
|
|
|
* gcc -o evas-3d-eet evas-3d-eet.c `pkg-config --libs --cflags efl eina evas ecore ecore-evas ecore-file eo`
|
|
|
|
* @endverbatim
|
|
|
|
*/
|
2014-10-06 07:27:06 -07:00
|
|
|
|
2015-02-20 03:02:08 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#else
|
|
|
|
#define PACKAGE_EXAMPLES_DIR "."
|
2014-10-06 07:27:06 -07:00
|
|
|
#define EFL_EO_API_SUPPORT
|
|
|
|
#define EFL_BETA_API_SUPPORT
|
2015-02-20 08:59:27 -08:00
|
|
|
#endif
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
#include <Eo.h>
|
|
|
|
#include <Evas.h>
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_Evas.h>
|
2015-02-20 08:59:27 -08:00
|
|
|
#include <Ecore_File.h>
|
|
|
|
#include "evas-common.h"
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
#define WIDTH 1024
|
|
|
|
#define HEIGHT 1024
|
|
|
|
|
2015-02-20 08:59:27 -08:00
|
|
|
static const char *input_model_path = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/sonic.md2";
|
|
|
|
static const char *output_model_path = PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES "/saved_Sonic_EET.eet";
|
2015-02-20 03:02:08 -08:00
|
|
|
|
2014-10-06 07:27:06 -07: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 *mesh_node = NULL;
|
|
|
|
Eo *mesh = NULL;
|
|
|
|
Eo *mesh_node2 = NULL;
|
|
|
|
Eo *mesh2 = NULL;
|
|
|
|
Eo *material = NULL;
|
|
|
|
Eo *light = NULL;
|
|
|
|
|
|
|
|
static float angle = 0;
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_animate_eet(void *data)
|
|
|
|
{
|
|
|
|
angle += 0.5;
|
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
eo_do((Evas_Canvas3D_Node *)data,
|
|
|
|
evas_canvas3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
/* Rotate */
|
|
|
|
if (angle > 360.0) angle -= 360.0f;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_animate_md2(void *data)
|
|
|
|
{
|
|
|
|
static int frame = 0;
|
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
eo_do((Evas_Canvas3D_Node *)data, evas_canvas3d_node_mesh_frame_set(mesh, frame));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
frame += 32;
|
|
|
|
|
|
|
|
if (frame > 256 * 50) frame = 0;
|
|
|
|
|
|
|
|
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-10-06 07:27:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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 .*/
|
2015-06-17 07:31:14 -07:00
|
|
|
scene = eo_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
/* Add the root node for the scene. */
|
2015-06-17 07:31:14 -07:00
|
|
|
root_node = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
|
|
|
|
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_NODE));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
/* Add the camera. */
|
2015-06-17 07:31:14 -07:00
|
|
|
camera = eo_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(camera,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
camera_node = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
|
|
|
|
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_CAMERA));
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(camera_node,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_camera_set(camera));
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(root_node,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_member_add(camera_node));
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(camera_node,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_position_set(200.0, 0.0, 40.0),
|
|
|
|
evas_canvas3d_node_look_at_set(EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 20.0,
|
|
|
|
EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 1.0));
|
2014-10-06 07:27:06 -07:00
|
|
|
/* Add the light. */
|
2015-06-17 07:31:14 -07:00
|
|
|
light = eo_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(light,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_light_ambient_set(1.0, 1.0, 1.0, 1.0),
|
|
|
|
evas_canvas3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
|
|
|
|
evas_canvas3d_light_specular_set(1.0, 1.0, 1.0, 1.0),
|
|
|
|
evas_canvas3d_light_directional_set(EINA_TRUE));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
light_node = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
|
|
|
|
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_LIGHT));
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(light_node,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_light_set(light),
|
|
|
|
evas_canvas3d_node_position_set(1000.0, 0.0, 1000.0),
|
|
|
|
evas_canvas3d_node_look_at_set(EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0,
|
|
|
|
EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0));
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(root_node,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_member_add(light_node));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
/* Add the meshes. */
|
2015-06-17 07:31:14 -07:00
|
|
|
mesh = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas);
|
|
|
|
mesh2 = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas);
|
|
|
|
material = eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
eo_do(mesh,
|
2015-02-20 03:02:08 -08:00
|
|
|
efl_file_set(input_model_path, NULL),
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_mesh_frame_material_set(0, material),
|
|
|
|
evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_PHONG));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
eo_do(material,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_AMBIENT, EINA_TRUE),
|
|
|
|
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_DIFFUSE, EINA_TRUE),
|
|
|
|
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_SPECULAR, EINA_TRUE),
|
|
|
|
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_NORMAL, EINA_TRUE),
|
|
|
|
evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_AMBIENT,
|
2014-10-06 07:27:06 -07:00
|
|
|
0.50, 0.50, 0.00, 0.30),
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_DIFFUSE,
|
2014-10-06 07:27:06 -07:00
|
|
|
0.00, 0.50, 0.50, 0.30),
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_SPECULAR,
|
2014-10-06 07:27:06 -07:00
|
|
|
0.50, 0.00, 0.50, 0.30),
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_material_shininess_set(50.0));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
2015-02-20 08:59:27 -08:00
|
|
|
if (!ecore_file_mkpath(PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES))
|
2015-02-20 03:02:08 -08:00
|
|
|
fprintf(stderr, "Failed to create folder %s\n\n",
|
2015-02-20 08:59:27 -08:00
|
|
|
PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES);
|
2015-02-20 03:02:08 -08:00
|
|
|
|
|
|
|
eo_do(mesh, efl_file_save(output_model_path, NULL, NULL));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
eo_do(mesh2,
|
2015-02-20 03:02:08 -08:00
|
|
|
efl_file_set(output_model_path, NULL),
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_PHONG));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
mesh_node = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
|
|
|
|
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_MESH));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
eo_do(root_node,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_member_add(mesh_node));
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(mesh_node,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_mesh_add(mesh),
|
|
|
|
evas_canvas3d_node_position_set(0.0, -40.0, 0.0));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
mesh_node2 = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
|
|
|
|
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_MESH));
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(root_node,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_member_add(mesh_node2));
|
2014-10-06 07:27:06 -07:00
|
|
|
eo_do(mesh_node2,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_mesh_add(mesh2),
|
|
|
|
evas_canvas3d_node_position_set(0.0, 40.0, 0.0));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
/* Set up scene. */
|
|
|
|
eo_do(scene,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_scene_root_node_set(root_node),
|
|
|
|
evas_canvas3d_scene_camera_node_set(camera_node),
|
|
|
|
evas_canvas3d_scene_size_set(WIDTH, HEIGHT));
|
2014-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
/* 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(0, 0, 0, 255),
|
|
|
|
efl_gfx_size_set(WIDTH, HEIGHT),
|
|
|
|
efl_gfx_visible_set(EINA_TRUE));
|
2014-10-06 07:27:06 -07: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-10-06 07:27:06 -07:00
|
|
|
|
|
|
|
/* 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_md2, mesh_node);
|
|
|
|
ecore_timer_add(0.01, _animate_eet, mesh_node2);
|
|
|
|
|
|
|
|
/* Enter main loop. */
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
|
|
|
ecore_evas_free(ecore_evas);
|
|
|
|
ecore_evas_shutdown();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|