From b02b36e5ec90fa8350c4d7b9e3abf40111b38dc4 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 27 Apr 2014 14:57:13 +1000 Subject: Added stuff cut and pasted from the new Evas_3d examples, but they are broken anyway. Just leaving it commented out for now. --- src/GuiLua/GuiLua.c | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/GuiLua/GuiLua.h | 15 ++++ 2 files changed, 243 insertions(+) diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index c7a368c..8dbc2ff 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -143,10 +143,209 @@ and ordinary elementary widgets. Proper introspection can come later. #include "GuiLua.h" +typedef struct _Scene_Data +{ + Evas_3D_Scene *scene; + Evas_3D_Node *root_node; + Evas_3D_Node *camera_node; + Evas_3D_Node *light_node; + Evas_3D_Node *mesh_node; + + Evas_3D_Camera *camera; + Evas_3D_Light *light; + Evas_3D_Mesh *mesh; + Evas_3D_Material *material; +} Scene_Data; + +static const float cube_vertices[] = +{ + /* Front */ + -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, + + /* Back */ + 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,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, 1.0, 0.0, +}; + +static const unsigned short cube_indices[] = +{ + /* Front */ + 0, 1, 2, 2, 1, 3, + + /* Back */ + 4, 5, 6, 6, 5, 7, + + /* Left */ + 8, 9, 10, 10, 9, 11, + + /* Right */ + 12, 13, 14, 14, 13, 15, + + /* Top */ + 16, 17, 18, 18, 17, 19, + + /* Bottom */ + 20, 21, 22, 22, 21, 23 +}; + + globals ourGlobals; static const char *globName = "ourGlobals"; +static Scene_Data data; + +static Eina_Bool +_animate_scene(void *data) +{ + static float angle = 0.0f; +/* + Scene_Data *scene = (Scene_Data *)data; + + angle += 0.5; + + evas_3d_node_orientation_angle_axis_set(scene->mesh_node, angle, 1.0, 1.0, 1.0); +*/ + + /* Rotate */ + if (angle > 360.0) + angle -= 360.0f; + return EINA_TRUE; +} + +static void +_camera_setup(Scene_Data *data) +{ +/* + data->camera = evas_3d_camera_add(evas); + evas_3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0); + + data->camera_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_CAMERA); + evas_3d_node_camera_set(data->camera_node, data->camera); + evas_3d_node_member_add(data->root_node, data->camera_node); + evas_3d_node_position_set(data->camera_node, 0.0, 0.0, 10.0); + evas_3d_node_look_at_set(data->camera_node, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, + EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0); +*/ +} + +static void +_light_setup(Scene_Data *data) +{ +/* + data->light = evas_3d_light_add(evas); + evas_3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0); + evas_3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0); + evas_3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0); + + data->light_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_LIGHT); + evas_3d_node_light_set(data->light_node, data->light); + evas_3d_node_member_add(data->root_node, data->light_node); + evas_3d_node_position_set(data->light_node, 0.0, 0.0, 10.0); + evas_3d_node_look_at_set(data->light_node, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, + EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0); +*/ +} + +static void +_mesh_setup(Scene_Data *data) +{ + /* Setup material. */ +/* + data->material = evas_3d_material_add(evas); + + evas_3d_material_enable_set(data->material, EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE); + evas_3d_material_enable_set(data->material, EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE); + evas_3d_material_enable_set(data->material, EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE); + + evas_3d_material_color_set(data->material, EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0); + evas_3d_material_color_set(data->material, EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0); + evas_3d_material_color_set(data->material, EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0); + evas_3d_material_shininess_set(data->material, 100.0); +*/ + + /* Setup mesh. */ +/* + data->mesh = evas_3d_mesh_add(evas); + evas_3d_mesh_vertex_count_set(data->mesh, 24); + evas_3d_mesh_frame_add(data->mesh, 0); + + evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_POSITION, + 12 * sizeof(float), &cube_vertices[ 0]); + evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_NORMAL, + 12 * sizeof(float), &cube_vertices[ 3]); + evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_COLOR, + 12 * sizeof(float), &cube_vertices[ 6]); + evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_TEXCOORD, + 12 * sizeof(float), &cube_vertices[10]); + + evas_3d_mesh_index_data_set(data->mesh, EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, + 36, &cube_indices[0]); + evas_3d_mesh_vertex_assembly_set(data->mesh, EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES); + + evas_3d_mesh_shade_mode_set(data->mesh, EVAS_3D_SHADE_MODE_PHONG); + + evas_3d_mesh_frame_material_set(data->mesh, 0, data->material); + + data->mesh_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_MESH); + evas_3d_node_member_add(data->root_node, data->mesh_node); + evas_3d_node_mesh_add(data->mesh_node, data->mesh); +*/ +} + +static void +_scene_setup(globals *ourGlobals, Scene_Data *data) +{ +/* + data->scene = evas_3d_scene_add(ourGlobals->evas); + evas_3d_scene_size_set(data->scene, WIDTH, HEIGHT); + evas_3d_scene_background_color_set(data->scene, 0.0, 0.0, 0.0, 0.0); + + data->root_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_NODE); +*/ + + _camera_setup(data); + _light_setup(data); + _mesh_setup(data); + +/* + evas_3d_scene_root_node_set(data->scene, data->root_node); + evas_3d_scene_camera_node_set(data->scene, data->camera_node); +*/ +} + + + + // TODO - These functions should be able to deal with multiple windows. // TODO - Should be able to open external and internal windows, and even switch between them on the fly. static void _on_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) @@ -282,6 +481,35 @@ static int window(lua_State *L) evas_object_move(ourGlobals->win, 0, 0); evas_object_show(ourGlobals->win); + // Get the Evas / canvas from the elm window (that the Evas_Object "lives on"), which is itself an Evas_Object created by Elm, so not sure if it was created internally with Ecore_Evas. + ourGlobals->evas = evas_object_evas_get(ourGlobals->win); + // An Ecore_Evas holds an Evas. + // Get the Ecore_Evas that wraps an Evas. +// ourGlobals->ecore_evas = ecore_evas_ecore_evas_get(ourGlobals->evas); // Only use this on Evas that was created with Ecore_Evas. + + _scene_setup(ourGlobals, &data); + + /* Add an image object for 3D scene rendering. */ +/* + ourGlobals->image = elm_image_add(ourGlobals->win); + elm_image_no_scale_set(ourGlobals->image, EINA_TRUE); + elm_image_resizable_set(ourGlobals->image, EINA_FALSE, EINA_TRUE); + elm_image_smooth_set(ourGlobals->image, EINA_FALSE); + elm_image_orient_set(ourGlobals->image, ELM_IMAGE_FLIP_HORIZONTAL); + elm_image_aspect_fixed_set(ourGlobals->image, EINA_TRUE); + elm_image_fill_outside_set(ourGlobals->image, EINA_TRUE); + elm_image_editable_set(ourGlobals->image, EINA_TRUE); + evas_object_size_hint_weight_set(ourGlobals->image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(ourGlobals->win, ourGlobals->image); + evas_object_show(ourGlobals->image); + + // Set the image object as render target for 3D scene. + evas_object_image_scene_set(ourGlobals->image, data.scene); +*/ + + // Add animation timer callback. + ecore_timer_add(0.016, _animate_scene, &data); + lua_pushlightuserdata(L, &ourGlobals->win); return 1; } diff --git a/src/GuiLua/GuiLua.h b/src/GuiLua/GuiLua.h index 156fa1a..95353fb 100644 --- a/src/GuiLua/GuiLua.h +++ b/src/GuiLua/GuiLua.h @@ -1,9 +1,19 @@ +#define EFL_API_OVERRIDE 1 +/* Enable access to unstable EFL API that are still in beta */ +#define EFL_BETA_API_SUPPORT 1 +/* Enable access to unstable EFL EO API. */ +#define EFL_EO_API_SUPPORT 1 + #include #include #include +// This got left out. +//EAPI Evas_3D_Scene *evas_3d_scene_add(Evas *e); + + #include #include #include @@ -28,6 +38,11 @@ struct _globals { Evas_Object *win; // Our Elm window. int logDom; // Our logging domain. + +//Ecore_Evas *ecore_evas; +Evas *evas; +//Evas_Object *background; +Evas_Object *image; }; -- cgit v1.1