Evas 3D is an extension to support 3D scene graph rendering into 2D Evas canvases, with tree-based scene graph manipulation and other typical 3D rendering techniques.
3D objects are used to describe three dimensional scenes and to provide interfaces to connect the scene to an Evas image object for rendering.
Scenes are constructed by locating cameras and lights and selecting desired meshes, and organizing Node objects into hierarchical n-ary tree data structures. The scene is stacked on the canvas with existing Evas objects, which permits intermingling 3D rendered content in existing 2D application layouts.
Rendering techniques supported by Evas 3D include flat and phong shading, normal and texture mapping, and triangle meshes. Existing Evas objects may also be used as textures inside the 3D scene, including EFL widgets and even application windows. This latter capability makes it possible to create a 3D version of an arbitrary EFL application with minimal code changes.
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define EFL_BETA_API_SUPPORT
#endif
#include <Eo.h>
#include <Evas.h>
#include <Ecore.h>
#define WIDTH 400
#define HEIGHT 400
typedef struct _Scene_Data
{
} Scene_Data;
static Ecore_Evas *ecore_evas = NULL;
static Evas *evas = NULL;
static Eo *background = NULL;
static const float cube_vertices[] =
{
-1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0,
1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
-1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
-1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
-1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
-1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 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, 15,
16, 17, 18, 18, 17, 19,
20, 21, 22, 22, 21, 23
};
static void
_on_delete(Ecore_Evas *ee EINA_UNUSED)
{
}
static void
_on_canvas_resize(Ecore_Evas *ee)
{
int w, h;
efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
}
_animate_scene(void *data)
{
static float angle = 0.0f;
Scene_Data *scene = (Scene_Data *)data;
angle += 0.5;
if (angle > 360.0) angle -= 360.0f;
}
static void
_camera_setup(Scene_Data *data)
{
data->camera_node =
}
static void
_light_setup(Scene_Data *data)
{
data->light_node =
}
static void
_mesh_setup(Scene_Data *data)
{
data->mesh_node =
}
static void
_scene_setup(Scene_Data *data)
{
data->root_node =
_camera_setup(data);
_light_setup(data);
_mesh_setup(data);
}
int
main(void)
{
setenv(
"ECORE_EVAS_ENGINE",
"opengl_x11", 1);
Scene_Data data;
if (!ecore_evas) return 0;
_scene_setup(&data);
background =
efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
efl_gfx_color_set(background, 0, 0, 0, 255);
efl_gfx_entity_size_set(background, EINA_SIZE2D(WIDTH, HEIGHT));
efl_gfx_entity_visible_set(background,
EINA_TRUE);
image =
efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
efl_gfx_entity_size_set(image, EINA_SIZE2D(WIDTH, HEIGHT));
efl_gfx_entity_visible_set(image,
EINA_TRUE);
efl_canvas_scene3d_set(image, data.scene);
return 0;
}