Evas 3D is an extension to support 3D scene graph rendering into 2D Evas canvas supporting typicall tree-based scene graph manipulation and other 3D graphics rendering techniques.
Evas 3D provides 3D objects which are used for describing 3D scene and APIs to connect the scene with an evas image object so that the scene is rendered on that image object.
Construction of a 3D scene is process of locating desired cameras, lights and meshes in the scene. Typically the scene is structured with some hierarchical data structure. Evas 3D support n-ary tree structure for describing the scene. Node is used to build the tree representation of the scene. Other objects, like camera, light and mesh can be located in the scene by being contained in a node.
Like other 3D graphics engine, Evas 3D support standard 3D rendering method like flat shading, phong shading and normal map and other features like texture mapping, triangle meshes.
Besides all the traditional 3D rendering things, one of the key feature of the Evas 3D is that it is able to use existing evas objects as textures inside of the 3D scene. "Existing evas objects" means all the EFL widgets and applications. By supporting this, it is easy to make 3D version of an application without modifying the original source that much.
Also, 3D scene can be located on the canvas naturally stacked with existing evas objects. This can make it possible putting 3D things into existing 2D application layouts.
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define EFL_BETA_API_SUPPORT
#define EFL_EO_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 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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
-1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
};
static const unsigned short cube_indices[] =
{
0, 1, 2, 2, 1, 3,
4, 5, 6, 6, 5, 7,
8, 9, 10, 10, 9, 11,
12, 13, 14, 14, 13, 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_size_set(background, w, h);
efl_gfx_size_set(image, 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 =
eo_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
data->camera_node =
}
static void
_light_setup(Scene_Data *data)
{
data->light =
eo_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
data->light_node =
}
static void
_mesh_setup(Scene_Data *data)
{
data->material =
eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
data->mesh =
eo_add(EVAS_CANVAS3D_MESH_CLASS, evas);
data->mesh_node =
}
static void
_scene_setup(Scene_Data *data)
{
data->scene =
eo_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
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 =
eo_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
efl_gfx_color_set(background, 0, 0, 0, 255);
efl_gfx_size_set(background, WIDTH, HEIGHT);
image =
eo_add(EFL_CANVAS_SCENE3D_CLASS, evas);
efl_gfx_size_set(image, WIDTH, HEIGHT);
efl_canvas_scene3d_set(image, data.scene);
return 0;
}