2013-12-26 23:56:30 -08:00
|
|
|
#include "evas_common_private.h"
|
|
|
|
#include "evas_private.h"
|
|
|
|
|
2014-04-25 10:28:38 -07:00
|
|
|
#define MY_CLASS EVAS_3D_NODE_CLASS
|
2014-04-14 03:03:47 -07:00
|
|
|
#define MY_CLASS_NAME "Evas_3D_Node"
|
|
|
|
|
2014-05-27 06:07:28 -07:00
|
|
|
Evas_3D_Mesh_Frame *evas_3d_mesh_frame_find(Evas_3D_Mesh_Data *pd, int frame);
|
|
|
|
|
2013-12-26 23:56:30 -08:00
|
|
|
static inline Evas_3D_Node_Mesh *
|
|
|
|
_node_mesh_new(Evas_3D_Node *node, Evas_3D_Mesh *mesh)
|
|
|
|
{
|
|
|
|
Evas_3D_Node_Mesh *nm = (Evas_3D_Node_Mesh *)malloc(sizeof(Evas_3D_Node_Mesh));
|
|
|
|
|
|
|
|
if (nm == NULL)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nm->node = node;
|
|
|
|
nm->mesh = mesh;
|
|
|
|
nm->frame = 0;
|
|
|
|
|
|
|
|
return nm;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
_node_mesh_free(Evas_3D_Node_Mesh *nm)
|
|
|
|
{
|
|
|
|
free(nm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_node_mesh_free_func(void *data)
|
|
|
|
{
|
|
|
|
_node_mesh_free((Evas_3D_Node_Mesh *)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_node_scene_root_change_notify(const Eina_Hash *hash EINA_UNUSED, const void *key,
|
|
|
|
void *data EINA_UNUSED, void *fdata)
|
|
|
|
{
|
|
|
|
Evas_3D_Scene *s = *(Evas_3D_Scene **)key;
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(s, evas_3d_object_change(EVAS_3D_STATE_SCENE_ROOT_NODE, (Evas_3D_Object *)fdata));
|
2013-12-26 23:56:30 -08:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_node_scene_camera_change_notify(const Eina_Hash *hash EINA_UNUSED, const void *key,
|
|
|
|
void *data EINA_UNUSED, void *fdata)
|
|
|
|
{
|
|
|
|
Evas_3D_Scene *s = *(Evas_3D_Scene **)key;
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(s, evas_3d_object_change(EVAS_3D_STATE_SCENE_CAMERA_NODE, (Evas_3D_Object *)fdata));
|
2013-12-26 23:56:30 -08:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:59:38 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_evas_3d_object_change_notify(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_State state EINA_UNUSED , Evas_3D_Object *ref EINA_UNUSED)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Evas_3D_Node *n;
|
|
|
|
|
|
|
|
/* Notify all scenes using this node that it has changed. */
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->scenes_root)
|
|
|
|
eina_hash_foreach(pd->scenes_root, _node_scene_root_change_notify, obj);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->scenes_camera)
|
|
|
|
eina_hash_foreach(pd->scenes_camera, _node_scene_camera_change_notify, obj);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Notify parent that a member has changed. */
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->parent)
|
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(pd->parent, evas_3d_object_change(EVAS_3D_STATE_NODE_MEMBER, obj));
|
2014-04-14 03:03:47 -07:00
|
|
|
}
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Notify members that the parent has changed. */
|
2014-04-14 03:03:47 -07:00
|
|
|
EINA_LIST_FOREACH(pd->members, l, n)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(n, evas_3d_object_change(EVAS_3D_STATE_NODE_PARENT, obj));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_node_transform_update(Evas_3D_Node *node, void *data EINA_UNUSED)
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(node, MY_CLASS);
|
2014-04-25 10:28:38 -07:00
|
|
|
Eina_Bool transform_dirty = EINA_FALSE, parent_dirty = EINA_FALSE;
|
|
|
|
|
|
|
|
eo_do(node,
|
|
|
|
transform_dirty = evas_3d_object_dirty_get(EVAS_3D_STATE_NODE_TRANSFORM),
|
|
|
|
parent_dirty = evas_3d_object_dirty_get(EVAS_3D_STATE_NODE_PARENT));
|
|
|
|
|
|
|
|
if (transform_dirty || parent_dirty)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->parent)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdparent = eo_data_scope_get(pd->parent, MY_CLASS);
|
|
|
|
const Evas_Vec3 *scale_parent = &pdparent->scale_world;
|
|
|
|
const Evas_Vec4 *orientation_parent = &pdparent->orientation_world;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Orienatation */
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->orientation_inherit)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_vec4_quaternion_multiply(&pd->orientation_world,
|
|
|
|
orientation_parent, &pd->orientation);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->orientation_world = pd->orientation;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Scale */
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->scale_inherit)
|
|
|
|
evas_vec3_multiply(&pd->scale_world, scale_parent, &pd->scale);
|
2013-12-26 23:56:30 -08:00
|
|
|
else
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->scale_world = pd->scale;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Position */
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->position_inherit)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_vec3_multiply(&pd->position_world, &pd->position, scale_parent);
|
|
|
|
evas_vec3_quaternion_rotate(&pd->position_world, &pd->position_world,
|
2013-12-26 23:56:30 -08:00
|
|
|
orientation_parent);
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_vec3_add(&pd->position_world, &pd->position_world,
|
|
|
|
&pdparent->position_world);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->position_world = pd->position;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->position_world = pd->position;
|
|
|
|
pd->orientation_world = pd->orientation;
|
|
|
|
pd->scale_world = pd->scale;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->type == EVAS_3D_NODE_TYPE_CAMERA)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_mat4_inverse_build(&pd->data.camera.matrix_world_to_eye,
|
|
|
|
&pd->position_world, &pd->orientation_world,
|
|
|
|
&pd->scale_world);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
2014-04-14 03:03:47 -07:00
|
|
|
else if (pd->type == EVAS_3D_NODE_TYPE_LIGHT)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
}
|
2014-04-14 03:03:47 -07:00
|
|
|
else if (pd->type == EVAS_3D_NODE_TYPE_MESH)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_mat4_build(&pd->data.mesh.matrix_local_to_world,
|
|
|
|
&pd->position_world, &pd->orientation_world, &pd->scale_world);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
/*
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->parent)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_mat4_nocheck_multiply(&pd->matrix_local_to_world,
|
|
|
|
&pd->parent->matrix_local_to_world,
|
|
|
|
&pd->matrix_local_to_parent);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_mat4_copy(&pd->matrix_local_to_world, &pd->matrix_local_to_parent);
|
2013-12-26 23:56:30 -08:00
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_node_item_update(Evas_3D_Node *node, void *data EINA_UNUSED)
|
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(node, EVAS_3D_NODE_CLASS);
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->type == EVAS_3D_NODE_TYPE_CAMERA)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->data.camera.camera)
|
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(pd->data.camera.camera, evas_3d_object_update());
|
2014-04-14 03:03:47 -07:00
|
|
|
}
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
2014-04-14 03:03:47 -07:00
|
|
|
else if (pd->type == EVAS_3D_NODE_TYPE_LIGHT)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->data.light.light)
|
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(pd->data.light.light, evas_3d_object_update());
|
2014-04-14 03:03:47 -07:00
|
|
|
}
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
2014-04-14 03:03:47 -07:00
|
|
|
else if (pd->type == EVAS_3D_NODE_TYPE_MESH)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Evas_3D_Mesh *m;
|
2014-04-14 03:03:47 -07:00
|
|
|
EINA_LIST_FOREACH(pd->data.mesh.meshes, l, m)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(m, evas_3d_object_update());
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_node_aabb_update(Evas_3D_Node *node, void *data EINA_UNUSED)
|
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(node, EVAS_3D_NODE_CLASS);
|
2014-05-27 06:07:28 -07:00
|
|
|
Eina_Bool transform_dirty = EINA_FALSE, mesh_geom_dirty = EINA_FALSE;
|
|
|
|
Eina_Bool mesh_frame_dirty = EINA_FALSE, member_dirty = EINA_FALSE;
|
|
|
|
Eina_Bool frame_found = EINA_FALSE, is_change_orientation = EINA_FALSE;
|
|
|
|
Eina_List *m, *l;
|
|
|
|
Evas_3D_Mesh *mesh;
|
|
|
|
int frame, count, size, i, j;
|
|
|
|
Evas_3D_Mesh_Frame *f;
|
|
|
|
float minx, miny, minz, maxx, maxy, maxz, vxmin, vymin, vzmin, vxmax, vymax, vzmax;
|
|
|
|
float *minmaxdata;
|
|
|
|
Evas_Vec4 orientation;
|
|
|
|
Evas_Box3 box3;
|
2014-04-25 10:28:38 -07:00
|
|
|
|
|
|
|
eo_do(node,
|
|
|
|
transform_dirty = evas_3d_object_dirty_get(EVAS_3D_STATE_NODE_TRANSFORM),
|
|
|
|
mesh_geom_dirty = evas_3d_object_dirty_get(EVAS_3D_STATE_NODE_MESH_GEOMETRY),
|
|
|
|
mesh_frame_dirty = evas_3d_object_dirty_get(EVAS_3D_STATE_NODE_MESH_FRAME),
|
|
|
|
member_dirty = evas_3d_object_dirty_get(EVAS_3D_STATE_NODE_MEMBER));
|
|
|
|
|
|
|
|
if (transform_dirty ||
|
|
|
|
mesh_geom_dirty ||
|
|
|
|
mesh_frame_dirty ||
|
|
|
|
member_dirty)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-05-27 06:07:28 -07:00
|
|
|
if (pd->type == EVAS_3D_NODE_TYPE_MESH)
|
|
|
|
{
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-05-27 06:07:28 -07:00
|
|
|
if (pd->orientation.x || pd->orientation.y || pd->orientation.z)
|
|
|
|
{
|
|
|
|
evas_vec4_set(&orientation, pd->orientation.x, pd->orientation.y, pd->orientation.z, pd->orientation.w);
|
|
|
|
is_change_orientation = EINA_TRUE;
|
|
|
|
}
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-05-27 06:07:28 -07:00
|
|
|
eo_do (node, m = evas_3d_node_mesh_list_get());
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-05-27 06:07:28 -07:00
|
|
|
EINA_LIST_FOREACH(m, l, mesh)
|
|
|
|
{
|
|
|
|
eo_do(node, frame = evas_3d_node_mesh_frame_get(mesh));
|
|
|
|
Evas_3D_Mesh_Data *mpd = eo_data_scope_get(mesh, EVAS_3D_MESH_CLASS);
|
|
|
|
f = evas_3d_mesh_frame_find(mpd, frame);
|
|
|
|
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
i = 0, j = 0;
|
|
|
|
|
|
|
|
evas_box3_empty_set(&box3);
|
|
|
|
count = f->vertices[EVAS_3D_VERTEX_POSITION].element_count;
|
|
|
|
size = f->vertices[EVAS_3D_VERTEX_POSITION].size;
|
|
|
|
if (!size) size = count * sizeof(float) * mpd->vertex_count;
|
|
|
|
minmaxdata = (float *)malloc(size);
|
|
|
|
|
|
|
|
if (!minmaxdata)
|
|
|
|
{
|
|
|
|
ERR("Not enough memory.");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(minmaxdata, f->vertices[EVAS_3D_VERTEX_POSITION].data, size);
|
|
|
|
|
|
|
|
/*get current coordinates, set orientation and find min/max*/
|
|
|
|
if (is_change_orientation)
|
|
|
|
{
|
|
|
|
Evas_Vec3 rotate;
|
|
|
|
evas_vec3_set(&rotate, minmaxdata[0], minmaxdata[1], minmaxdata[2]);
|
|
|
|
evas_vec3_quaternion_rotate(&rotate, &rotate, &orientation);
|
|
|
|
vxmax = vxmin = minmaxdata[0] = rotate.x;
|
|
|
|
vymax = vymin = minmaxdata[1] = rotate.y;
|
|
|
|
vzmax = vzmin = minmaxdata[2] = rotate.z;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vxmax = vxmin = minmaxdata[0];
|
|
|
|
vymax = vymin = minmaxdata[1];
|
|
|
|
vzmax = vzmin = minmaxdata[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
j += count;
|
|
|
|
|
|
|
|
if (is_change_orientation)
|
|
|
|
{
|
|
|
|
for (i = 1; i < mpd->vertex_count; ++i)
|
|
|
|
{
|
|
|
|
Evas_Vec3 rotate;
|
|
|
|
evas_vec3_set(&rotate, minmaxdata[j], minmaxdata[j + 1], minmaxdata[j + 2]);
|
|
|
|
evas_vec3_quaternion_rotate(&rotate, &rotate, &orientation);
|
|
|
|
minmaxdata[j] = rotate.x;
|
|
|
|
minmaxdata[j + 1] = rotate.y;
|
|
|
|
minmaxdata[j + 2] = rotate.z;
|
|
|
|
vxmin > minmaxdata[j] ? vxmin = minmaxdata[j] : 0;
|
|
|
|
vxmax < minmaxdata[j] ? vxmax = minmaxdata[j] : 0;
|
|
|
|
vymin > minmaxdata[j + 1] ? vymin = minmaxdata[j + 1] : 0;
|
|
|
|
vymax < minmaxdata[j + 1] ? vymax = minmaxdata[j + 1] : 0;
|
|
|
|
vzmin > minmaxdata[j + 2] ? vzmin = minmaxdata[j + 2] : 0;
|
|
|
|
vzmax < minmaxdata[j + 2] ? vzmax = minmaxdata[j + 2] : 0;
|
|
|
|
j += count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 1; i < mpd->vertex_count; ++i)
|
|
|
|
{
|
|
|
|
vxmin > minmaxdata[j] ? vxmin = minmaxdata[j] : 0;
|
|
|
|
vxmax < minmaxdata[j] ? vxmax = minmaxdata[j] : 0;
|
|
|
|
vymin > minmaxdata[j + 1] ? vymin = minmaxdata[j + 1] : 0;
|
|
|
|
vymax < minmaxdata[j + 1] ? vymax = minmaxdata[j + 1] : 0;
|
|
|
|
vzmin > minmaxdata[j + 2] ? vzmin = minmaxdata[j + 2] : 0;
|
|
|
|
vzmax < minmaxdata[j + 2] ? vzmax = minmaxdata[j + 2] : 0;
|
|
|
|
j += count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!frame_found)
|
|
|
|
{
|
|
|
|
evas_box3_empty_set(&pd->aabb);
|
|
|
|
evas_box3_empty_set(&pd->obb);
|
|
|
|
minx = vxmin;
|
|
|
|
miny = vymin;
|
|
|
|
minz = vzmin;
|
|
|
|
maxx = vxmax;
|
|
|
|
maxy = vymax;
|
|
|
|
maxz = vzmax;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
minx > vxmin ? minx = vxmin : 0;
|
|
|
|
maxx < vxmax ? maxx = vxmax : 0;
|
|
|
|
miny > vymin ? miny = vymin : 0;
|
|
|
|
maxy < vymax ? maxy = vymax : 0;
|
|
|
|
minz > vzmin ? minz = vzmin : 0;
|
|
|
|
maxz < vzmax ? maxz = vzmax : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_found = EINA_TRUE;
|
|
|
|
free(minmaxdata);
|
|
|
|
evas_box3_set(&box3, minx, miny, minz, maxx, maxy, maxz);
|
|
|
|
evas_box3_union(&pd->aabb, &pd->aabb, &box3);
|
|
|
|
evas_box3_union(&pd->obb, &pd->obb, &f->aabb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame_found)
|
|
|
|
{
|
|
|
|
if (is_change_orientation)
|
|
|
|
{
|
|
|
|
evas_vec3_quaternion_rotate(&pd->obb.p0, &pd->obb.p0, &orientation);
|
|
|
|
evas_vec3_quaternion_rotate(&pd->obb.p1, &pd->obb.p1, &orientation);
|
|
|
|
}
|
|
|
|
if ((pd->scale.x != 1 || pd->scale.y != 1 || pd->scale.z != 1))
|
|
|
|
{
|
|
|
|
Evas_Vec3 scale;
|
|
|
|
evas_vec3_set(&scale, pd->scale.x, pd->scale.y, pd->scale.z);
|
|
|
|
evas_vec3_multiply(&pd->obb.p0, &scale, &pd->obb.p0);
|
|
|
|
evas_vec3_multiply(&pd->obb.p1, &scale, &pd->obb.p1);
|
|
|
|
evas_vec3_multiply(&pd->aabb.p0, &scale, &pd->aabb.p0);
|
|
|
|
evas_vec3_multiply(&pd->aabb.p1, &scale, &pd->aabb.p1);
|
|
|
|
}
|
|
|
|
if ((pd->position.x || pd->position.y || pd->position.z))
|
|
|
|
{
|
|
|
|
Evas_Vec3 position;
|
|
|
|
evas_vec3_set(&position, pd->position.x, pd->position.y, pd->position.z);
|
|
|
|
evas_vec3_add(&pd->obb.p0, &position, &pd->obb.p0);
|
|
|
|
evas_vec3_add(&pd->obb.p1, &position, &pd->obb.p1);
|
|
|
|
evas_vec3_add(&pd->aabb.p0, &position, &pd->aabb.p0);
|
|
|
|
evas_vec3_add(&pd->aabb.p1, &position, &pd->aabb.p1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-05-27 06:07:28 -07:00
|
|
|
Eina_List *current;
|
|
|
|
Evas_3D_Node *data;
|
|
|
|
|
|
|
|
/* Update AABB and OBB of this node. */
|
|
|
|
evas_box3_empty_set(&pd->aabb);
|
|
|
|
evas_box3_empty_set(&pd->obb);
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(pd->members, current, data)
|
|
|
|
{
|
|
|
|
Evas_3D_Node_Data *datapd = eo_data_scope_get(data, EVAS_3D_NODE_CLASS);
|
|
|
|
evas_box3_union(&pd->obb, &pd->obb, &datapd->obb);
|
|
|
|
evas_box3_union(&pd->aabb, &pd->aabb, &datapd->aabb);
|
|
|
|
}
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2014-04-14 03:59:38 -07:00
|
|
|
_node_update_done(Evas_3D_Node *obj, void *data EINA_UNUSED)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:59:38 -07:00
|
|
|
//@FIXME
|
2014-04-25 10:28:38 -07:00
|
|
|
Evas_3D_Object_Data *pdobject = eo_data_scope_get(obj, EVAS_3D_OBJECT_CLASS);
|
2014-04-14 03:59:38 -07:00
|
|
|
memset(&pdobject->dirty[0], 0x00, sizeof(Eina_Bool) * EVAS_3D_STATE_MAX);
|
2013-12-26 23:56:30 -08:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:59:38 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_evas_3d_object_update_notify(Eo *obj, Evas_3D_Node_Data *pd EINA_UNUSED)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
/* Update transform. */
|
2014-04-14 03:59:38 -07:00
|
|
|
evas_3d_node_tree_traverse(obj, EVAS_3D_TREE_TRAVERSE_LEVEL_ORDER, EINA_FALSE,
|
2013-12-26 23:56:30 -08:00
|
|
|
_node_transform_update, NULL);
|
|
|
|
|
|
|
|
/* Update AABB. */
|
2014-04-14 03:59:38 -07:00
|
|
|
evas_3d_node_tree_traverse(obj, EVAS_3D_TREE_TRAVERSE_POST_ORDER, EINA_FALSE,
|
2013-12-26 23:56:30 -08:00
|
|
|
_node_aabb_update, NULL);
|
|
|
|
|
|
|
|
/* Update node item. */
|
2014-04-14 03:59:38 -07:00
|
|
|
evas_3d_node_tree_traverse(obj, EVAS_3D_TREE_TRAVERSE_ANY_ORDER, EINA_FALSE,
|
2013-12-26 23:56:30 -08:00
|
|
|
_node_item_update, NULL);
|
|
|
|
|
|
|
|
/* Mark all nodes in the tree as up-to-date. */
|
2014-04-14 03:59:38 -07:00
|
|
|
evas_3d_node_tree_traverse(obj, EVAS_3D_TREE_TRAVERSE_ANY_ORDER, EINA_FALSE,
|
2013-12-26 23:56:30 -08:00
|
|
|
_node_update_done, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_node_free(Evas_3D_Object *obj)
|
|
|
|
{
|
2014-04-14 03:59:38 -07:00
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(obj, MY_CLASS);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->members)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Evas_3D_Node *n;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EINA_LIST_FOREACH(pd->members, l, n)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_unref(n);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
eina_list_free(pd->members);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->data.mesh.meshes)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Evas_3D_Mesh *m;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EINA_LIST_FOREACH(pd->data.mesh.meshes, l, m)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
//evas_3d_mesh_node_del(m, node);
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_unref(m);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
eina_list_free(pd->data.mesh.meshes);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->data.mesh.node_meshes)
|
|
|
|
eina_hash_free(pd->data.mesh.node_meshes);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->scenes_root)
|
|
|
|
eina_hash_free(pd->scenes_root);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->scenes_camera)
|
|
|
|
eina_hash_free(pd->scenes_camera);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
//free(node);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_3d_node_scene_root_add(Evas_3D_Node *node, Evas_3D_Scene *scene)
|
|
|
|
{
|
|
|
|
int count = 0;
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(node, MY_CLASS);
|
|
|
|
if (pd->scenes_root == NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->scenes_root = eina_hash_pointer_new(NULL);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->scenes_root == NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Failed to create hash table.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-04-25 05:34:55 -07:00
|
|
|
count = (int)(uintptr_t)eina_hash_find(pd->scenes_root, &scene);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-25 05:34:55 -07:00
|
|
|
eina_hash_set(pd->scenes_root, &scene, (const void *)(uintptr_t)(count + 1));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_3d_node_scene_root_del(Evas_3D_Node *node, Evas_3D_Scene *scene)
|
|
|
|
{
|
|
|
|
int count = 0;
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(node, MY_CLASS);
|
|
|
|
if (pd->scenes_root == NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("No scene to delete.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-25 05:34:55 -07:00
|
|
|
count = (int)(uintptr_t)eina_hash_find(pd->scenes_root, &scene);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
if (count == 1)
|
2014-04-14 03:03:47 -07:00
|
|
|
eina_hash_del(pd->scenes_root, &scene, NULL);
|
2013-12-26 23:56:30 -08:00
|
|
|
else
|
2014-04-25 05:34:55 -07:00
|
|
|
eina_hash_set(pd->scenes_root, &scene, (const void *)(uintptr_t)(count - 1));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_3d_node_scene_camera_add(Evas_3D_Node *node, Evas_3D_Scene *scene)
|
|
|
|
{
|
|
|
|
int count = 0;
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(node, MY_CLASS);
|
|
|
|
if (pd->scenes_camera == NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->scenes_camera = eina_hash_pointer_new(NULL);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->scenes_camera == NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Failed to create hash table.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-04-25 05:34:55 -07:00
|
|
|
count = (int)(uintptr_t)eina_hash_find(pd->scenes_camera, &scene);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-25 05:34:55 -07:00
|
|
|
eina_hash_set(pd->scenes_camera, &scene, (const void *)(uintptr_t)(count + 1));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_3d_node_scene_camera_del(Evas_3D_Node *node, Evas_3D_Scene *scene)
|
|
|
|
{
|
|
|
|
int count = 0;
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(node, MY_CLASS);
|
|
|
|
if (pd->scenes_camera == NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("No scene to delete.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-25 05:34:55 -07:00
|
|
|
count = (int)(uintptr_t)eina_hash_find(pd->scenes_camera, &scene);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
if (count == 1)
|
2014-04-14 03:03:47 -07:00
|
|
|
eina_hash_del(pd->scenes_camera, &scene, NULL);
|
2013-12-26 23:56:30 -08:00
|
|
|
else
|
2014-04-25 05:34:55 -07:00
|
|
|
eina_hash_set(pd->scenes_camera, &scene, (const void *)(uintptr_t)(count - 1));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_3d_node_traverse(Evas_3D_Node *from, Evas_3D_Node *to, Evas_3D_Node_Traverse_Type type,
|
|
|
|
Eina_Bool skip, Evas_3D_Node_Func func, void *data)
|
|
|
|
{
|
|
|
|
Eina_List *nodes = NULL, *n;
|
|
|
|
Evas_3D_Node *node = NULL;
|
|
|
|
|
|
|
|
if (from == NULL || func == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (type == EVAS_3D_NODE_TRAVERSE_DOWNWARD)
|
|
|
|
{
|
|
|
|
if (to == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
node = to;
|
|
|
|
|
|
|
|
do {
|
|
|
|
nodes = eina_list_prepend(nodes, (const void *)node);
|
|
|
|
|
|
|
|
if (node == from)
|
|
|
|
break;
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdnode = eo_data_scope_get(node, MY_CLASS);
|
|
|
|
node = pdnode->parent;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
goto error;
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
else if (type == EVAS_3D_NODE_TRAVERSE_UPWARD)
|
|
|
|
{
|
|
|
|
node = from;
|
|
|
|
|
|
|
|
do {
|
|
|
|
nodes = eina_list_append(nodes, (const void *)node);
|
|
|
|
|
|
|
|
if (node == to)
|
|
|
|
break;
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdnode = eo_data_scope_get(node, MY_CLASS);
|
|
|
|
node = pdnode->parent;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
if (to == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(nodes, n, node)
|
|
|
|
{
|
|
|
|
if (!func(node, data) && skip)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
eina_list_free(nodes);
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
ERR("Node traverse error.");
|
|
|
|
|
|
|
|
if (nodes)
|
|
|
|
eina_list_free(nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_3d_node_tree_traverse(Evas_3D_Node *root, Evas_3D_Tree_Traverse_Type type,
|
|
|
|
Eina_Bool skip, Evas_3D_Node_Func func, void *data)
|
|
|
|
{
|
|
|
|
Eina_List *nodes = NULL, *l;
|
|
|
|
Evas_3D_Node *node = NULL, *n, *last;
|
|
|
|
|
|
|
|
if (root == NULL || func == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (type == EVAS_3D_TREE_TRAVERSE_LEVEL_ORDER)
|
|
|
|
{
|
|
|
|
/* Put the root node in the queue. */
|
|
|
|
nodes = eina_list_append(nodes, root);
|
|
|
|
|
|
|
|
while (eina_list_count(nodes) > 0)
|
|
|
|
{
|
|
|
|
/* Dequeue a node. */
|
|
|
|
node = eina_list_data_get(nodes);
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdnode = eo_data_scope_get(node, MY_CLASS);
|
|
|
|
|
2013-12-26 23:56:30 -08:00
|
|
|
nodes = eina_list_remove_list(nodes, nodes);
|
|
|
|
|
|
|
|
/* Call node function on the node. */
|
|
|
|
if (func(node, data) || !skip)
|
|
|
|
{
|
|
|
|
/* Enqueue member nodes. */
|
2014-04-14 03:03:47 -07:00
|
|
|
EINA_LIST_FOREACH(pdnode->members, l, n)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
nodes = eina_list_append(nodes, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == EVAS_3D_TREE_TRAVERSE_PRE_ORDER)
|
|
|
|
{
|
|
|
|
/* Put the root node in the stack. */
|
|
|
|
nodes = eina_list_append(nodes, root);
|
|
|
|
|
|
|
|
while (eina_list_count(nodes) > 0)
|
|
|
|
{
|
|
|
|
/* Pop a node from the stack. */
|
|
|
|
node = eina_list_data_get(nodes);
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdnode = eo_data_scope_get(node, MY_CLASS);
|
2013-12-26 23:56:30 -08:00
|
|
|
nodes = eina_list_remove_list(nodes, nodes);
|
|
|
|
|
|
|
|
/* Call node function on the node. */
|
|
|
|
if (func(node, data) || !skip)
|
|
|
|
{
|
|
|
|
/* Push member nodes into the stack. */
|
2014-04-14 03:03:47 -07:00
|
|
|
EINA_LIST_REVERSE_FOREACH(pdnode->members, l, n)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
nodes = eina_list_prepend(nodes, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == EVAS_3D_TREE_TRAVERSE_POST_ORDER)
|
|
|
|
{
|
|
|
|
if (skip)
|
|
|
|
{
|
|
|
|
ERR("Using skip with post order traversal has no effect.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put the root node in the stack. */
|
|
|
|
nodes = eina_list_append(nodes, root);
|
|
|
|
last = NULL;
|
|
|
|
|
|
|
|
while (eina_list_count(nodes) > 0)
|
|
|
|
{
|
|
|
|
/* Peek a node from the stack. */
|
|
|
|
node = eina_list_data_get(nodes);
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdnode = eo_data_scope_get(node, MY_CLASS);
|
|
|
|
if (eina_list_count(pdnode->members) == 0)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
/* The peeked node is a leaf node,
|
|
|
|
* so visit it and pop from the stack. */
|
|
|
|
func(node, data);
|
|
|
|
nodes = eina_list_remove_list(nodes, nodes);
|
|
|
|
|
|
|
|
/* Save the last visited node. */
|
|
|
|
last = node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the peeked node is not a leaf node,
|
|
|
|
* there can be only two possible cases.
|
|
|
|
*
|
|
|
|
* 1. the parent of the last visited node.
|
|
|
|
* 2. a sibling of the last visited node.
|
|
|
|
*
|
|
|
|
* If the last visited node is a direct child of the peeked node,
|
|
|
|
* we have no unvisted child nodes for the peeked node, so we have to visit
|
|
|
|
* the peeked node and pop from the stack.
|
|
|
|
*
|
|
|
|
* Otherwise it should be a sibling of the peeked node, so we have to push
|
|
|
|
* its childs into the stack. */
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdlast;
|
|
|
|
if (last )
|
|
|
|
pdlast= eo_data_scope_get(last, MY_CLASS);
|
|
|
|
if (last && pdlast->parent == node)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
/* Visit the node as it doesn't have any unvisited child node. */
|
|
|
|
func(node, data);
|
|
|
|
nodes = eina_list_remove_list(nodes, nodes);
|
|
|
|
|
|
|
|
/* Save the last visited node. */
|
|
|
|
last = node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Push child nodes into the stack. */
|
2014-04-14 03:03:47 -07:00
|
|
|
EINA_LIST_REVERSE_FOREACH(pdnode->members, l, n)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
nodes = eina_list_prepend(nodes, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nodes != NULL)
|
|
|
|
eina_list_free(nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
_node_is_visible(Evas_3D_Node *node EINA_UNUSED, Evas_3D_Node *camera_node EINA_UNUSED)
|
|
|
|
{
|
|
|
|
/* TODO: */
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
evas_3d_node_mesh_collect(Evas_3D_Node *node, void *data)
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Scene_Public_Data *scene_data = (Evas_3D_Scene_Public_Data *)data;
|
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(node, MY_CLASS);
|
2013-12-26 23:56:30 -08:00
|
|
|
if (!_node_is_visible(node, scene_data->camera_node))
|
|
|
|
{
|
|
|
|
/* Skip entire sub-tree of this node. */
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->type == EVAS_3D_NODE_TYPE_MESH)
|
2013-12-26 23:56:30 -08:00
|
|
|
scene_data->mesh_nodes = eina_list_append(scene_data->mesh_nodes, node);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
evas_3d_node_light_collect(Evas_3D_Node *node, void *data)
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Scene_Public_Data *scene_data = (Evas_3D_Scene_Public_Data *)data;
|
|
|
|
Evas_3D_Node_Data *pd = eo_data_scope_get(node, MY_CLASS);
|
|
|
|
if (pd->type == EVAS_3D_NODE_TYPE_LIGHT)
|
2013-12-26 23:56:30 -08:00
|
|
|
scene_data->light_nodes = eina_list_append(scene_data->light_nodes, node);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Evas_3D_Node *
|
|
|
|
evas_3d_node_add(Evas *e, Evas_3D_Node_Type type)
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
MAGIC_CHECK(e, Evas, MAGIC_EVAS);
|
|
|
|
return NULL;
|
|
|
|
MAGIC_CHECK_END();
|
2014-04-25 10:28:38 -07:00
|
|
|
Evas_Object *eo_obj = eo_add_custom(MY_CLASS, e, evas_3d_node_constructor(type));
|
2014-04-14 03:03:47 -07:00
|
|
|
eo_unref(eo_obj);
|
|
|
|
return eo_obj;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_constructor(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Node_Type type)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
eo_do_super(obj, MY_CLASS, eo_constructor());
|
|
|
|
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_type_set(EVAS_3D_OBJECT_TYPE_NODE));
|
2014-04-14 03:03:47 -07:00
|
|
|
|
|
|
|
evas_vec3_set(&pd->position, 0.0, 0.0, 0.0);
|
|
|
|
evas_vec4_set(&pd->orientation, 0.0, 0.0, 0.0, 0.0);
|
|
|
|
evas_vec3_set(&pd->scale, 1.0, 1.0, 1.0);
|
|
|
|
|
|
|
|
evas_vec3_set(&pd->position_world, 0.0, 0.0, 0.0);
|
|
|
|
evas_vec4_set(&pd->orientation_world, 0.0, 0.0, 0.0, 1.0);
|
|
|
|
evas_vec3_set(&pd->scale_world, 1.0, 1.0, 1.0);
|
|
|
|
|
|
|
|
pd->position_inherit = EINA_TRUE;
|
|
|
|
pd->orientation_inherit = EINA_TRUE;
|
|
|
|
pd->scale_inherit = EINA_TRUE;
|
|
|
|
pd->data.mesh.node_meshes = 0;
|
|
|
|
|
|
|
|
evas_box3_set(&pd->aabb, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
pd->type = type;
|
|
|
|
|
|
|
|
if (type == EVAS_3D_NODE_TYPE_MESH)
|
|
|
|
{
|
|
|
|
pd->data.mesh.node_meshes = eina_hash_pointer_new(_node_mesh_free_func);
|
|
|
|
if (pd->data.mesh.node_meshes == NULL)
|
|
|
|
{
|
|
|
|
ERR("Failed to create node mesh table.");
|
2014-04-14 03:59:38 -07:00
|
|
|
_node_free(obj);
|
2014-04-14 03:03:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_eo_base_constructor(Eo *obj, Evas_3D_Node_Data *pd EINA_UNUSED)
|
2014-04-14 03:03:47 -07:00
|
|
|
{
|
|
|
|
eo_error_set(obj);
|
|
|
|
ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_eo_base_destructor(Eo *obj, Evas_3D_Node_Data *pd EINA_UNUSED)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_unref(obj);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static Evas_3D_Node_Type
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_type_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
return pd->type;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_member_add(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Node *member)
|
2014-04-14 03:03:47 -07:00
|
|
|
{
|
|
|
|
if (obj == member)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Failed to add a member node (adding to itself).");
|
|
|
|
return;
|
|
|
|
}
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdmember = eo_data_scope_get(member, MY_CLASS);
|
|
|
|
if (pdmember->parent == obj)
|
2013-12-26 23:56:30 -08:00
|
|
|
return;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pdmember->parent)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
/* Detaching from previous parent. */
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdmemberparent = eo_data_scope_get(pdmember->parent, MY_CLASS);
|
|
|
|
pdmemberparent->members = eina_list_remove(pdmemberparent->members, member);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Mark changed. */
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(pdmember->parent, evas_3d_object_change(EVAS_3D_STATE_NODE_MEMBER, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Should get a new reference. */
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_ref(member);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the member node. */
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->members = eina_list_append(pd->members, (const void *)member);
|
|
|
|
pdmember->parent = obj;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Mark changed. */
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(member, evas_3d_object_change(EVAS_3D_STATE_NODE_PARENT, NULL));
|
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_MEMBER, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_member_del(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Node *member)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
Evas_3D_Node_Data *pdmember = eo_data_scope_get(member, MY_CLASS);
|
|
|
|
if (pdmember->parent != obj)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Failed to delete a member node (not a member of the given node)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete the member node. */
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->members = eina_list_remove(pd->members, member);
|
|
|
|
pdmember->parent = NULL;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Mark modified object as changed. */
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_MEMBER, NULL));
|
|
|
|
eo_do(member, evas_3d_object_change(EVAS_3D_STATE_NODE_PARENT, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Decrease reference count. */
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_unref(member);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static Evas_3D_Node *
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_parent_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
return pd->parent;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static const Eina_List *
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_member_list_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
return pd->members;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_position_set(Eo *obj, Evas_3D_Node_Data *pd, Evas_Real x, Evas_Real y, Evas_Real z)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->position.x = x;
|
|
|
|
pd->position.y = y;
|
|
|
|
pd->position.z = z;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_TRANSFORM, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_orientation_set(Eo *obj, Evas_3D_Node_Data *pd, Evas_Real x, Evas_Real y, Evas_Real z, Evas_Real w)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->orientation.x = x;
|
|
|
|
pd->orientation.y = y;
|
|
|
|
pd->orientation.z = z;
|
|
|
|
pd->orientation.w = w;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_TRANSFORM, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_orientation_angle_axis_set(Eo *obj, Evas_3D_Node_Data *pd,
|
2013-12-26 23:56:30 -08:00
|
|
|
Evas_Real angle, Evas_Real x, Evas_Real y, Evas_Real z)
|
|
|
|
{
|
|
|
|
Evas_Real half_angle = 0.5 * DEGREE_TO_RADIAN(angle);
|
|
|
|
Evas_Real s = sin(half_angle);
|
|
|
|
Evas_Vec3 axis;
|
|
|
|
|
|
|
|
evas_vec3_set(&axis, x, y, z);
|
|
|
|
evas_vec3_normalize(&axis, &axis);
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->orientation.w = cos(half_angle);
|
|
|
|
pd->orientation.x = s * axis.x;
|
|
|
|
pd->orientation.y = s * axis.y;
|
|
|
|
pd->orientation.z = s * axis.z;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_TRANSFORM, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_scale_set(Eo *obj, Evas_3D_Node_Data *pd, Evas_Real x, Evas_Real y, Evas_Real z)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->scale.x = x;
|
|
|
|
pd->scale.y = y;
|
|
|
|
pd->scale.z = z;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_TRANSFORM, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_position_get(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Space space,
|
2013-12-26 23:56:30 -08:00
|
|
|
Evas_Real *x, Evas_Real *y, Evas_Real *z)
|
|
|
|
{
|
|
|
|
if (space == EVAS_3D_SPACE_LOCAL)
|
|
|
|
{
|
|
|
|
if (x) *x = 0.0;
|
|
|
|
if (y) *y = 0.0;
|
|
|
|
if (z) *z = 0.0;
|
|
|
|
}
|
|
|
|
else if (space == EVAS_3D_SPACE_PARENT)
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
if (x) *x = pd->position.x;
|
|
|
|
if (y) *y = pd->position.y;
|
|
|
|
if (z) *z = pd->position.z;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
else if (space == EVAS_3D_SPACE_WORLD)
|
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_update());
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (x) *x = pd->position_world.x;
|
|
|
|
if (y) *y = pd->position_world.y;
|
|
|
|
if (z) *z = pd->position_world.z;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_orientation_get(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Space space,
|
2013-12-26 23:56:30 -08:00
|
|
|
Evas_Real *x, Evas_Real *y, Evas_Real *z, Evas_Real *w)
|
|
|
|
{
|
|
|
|
if (space == EVAS_3D_SPACE_LOCAL)
|
|
|
|
{
|
|
|
|
if (x) *x = 0.0;
|
|
|
|
if (y) *y = 0.0;
|
|
|
|
if (z) *z = 0.0;
|
|
|
|
if (w) *w = 0.0;
|
|
|
|
}
|
|
|
|
else if (space == EVAS_3D_SPACE_PARENT)
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
if (x) *x = pd->orientation.x;
|
|
|
|
if (y) *y = pd->orientation.y;
|
|
|
|
if (z) *z = pd->orientation.z;
|
|
|
|
if (w) *w = pd->orientation.w;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
else if (space == EVAS_3D_SPACE_WORLD)
|
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_update());
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (x) *x = pd->orientation_world.x;
|
|
|
|
if (y) *y = pd->orientation_world.y;
|
|
|
|
if (z) *z = pd->orientation_world.z;
|
|
|
|
if (w) *w = pd->orientation_world.w;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_scale_get(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Space space,
|
2013-12-26 23:56:30 -08:00
|
|
|
Evas_Real *x, Evas_Real *y, Evas_Real *z)
|
|
|
|
{
|
|
|
|
if (space == EVAS_3D_SPACE_LOCAL)
|
|
|
|
{
|
|
|
|
if (x) *x = 0.0;
|
|
|
|
if (y) *y = 0.0;
|
|
|
|
if (z) *z = 0.0;
|
|
|
|
}
|
|
|
|
else if (space == EVAS_3D_SPACE_PARENT)
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
if (x) *x = pd->scale.x;
|
|
|
|
if (y) *y = pd->scale.y;
|
|
|
|
if (z) *z = pd->scale.z;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
else if (space == EVAS_3D_SPACE_WORLD)
|
|
|
|
{
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_update());
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (x) *x = pd->scale_world.x;
|
|
|
|
if (y) *y = pd->scale_world.y;
|
|
|
|
if (z) *z = pd->scale_world.z;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_position_inherit_set(Eo *obj, Evas_3D_Node_Data *pd, Eina_Bool inherit)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->position_inherit = inherit;
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_TRANSFORM, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_orientation_inherit_set(Eo *obj, Evas_3D_Node_Data *pd, Eina_Bool inherit)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->orientation_inherit = inherit;
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_TRANSFORM, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_scale_inherit_set(Eo *obj, Evas_3D_Node_Data *pd, Eina_Bool inherit)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->scale_inherit = inherit;
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_TRANSFORM, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static Eina_Bool
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_position_inherit_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
return pd->position_inherit;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static Eina_Bool
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_orientation_inherit_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
return pd->orientation_inherit;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static Eina_Bool
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_scale_inherit_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
return pd->scale_inherit;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_look_at_set(Eo *obj, Evas_3D_Node_Data *pd,
|
2013-12-26 23:56:30 -08:00
|
|
|
Evas_3D_Space target_space, Evas_Real tx, Evas_Real ty, Evas_Real tz,
|
|
|
|
Evas_3D_Space up_space, Evas_Real ux, Evas_Real uy, Evas_Real uz)
|
|
|
|
{
|
|
|
|
Evas_Vec3 target;
|
|
|
|
Evas_Vec3 up;
|
|
|
|
Evas_Vec3 x, y, z;
|
|
|
|
|
|
|
|
/* Target position in parent space. */
|
|
|
|
if (target_space == EVAS_3D_SPACE_LOCAL)
|
|
|
|
{
|
|
|
|
ERR("TODO:");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (target_space == EVAS_3D_SPACE_PARENT)
|
|
|
|
{
|
|
|
|
evas_vec3_set(&target, tx, ty, tz);
|
|
|
|
}
|
|
|
|
else if (target_space == EVAS_3D_SPACE_WORLD)
|
|
|
|
{
|
|
|
|
ERR("TODO:");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Invalid coordinate space.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (up_space == EVAS_3D_SPACE_LOCAL)
|
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_vec3_set(&up, ux, uy, uz);
|
|
|
|
//ERR("TODO:");
|
|
|
|
//return;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
else if (up_space == EVAS_3D_SPACE_PARENT)
|
|
|
|
{
|
|
|
|
evas_vec3_set(&up, ux, uy, uz);
|
|
|
|
}
|
|
|
|
else if (up_space == EVAS_3D_SPACE_WORLD)
|
|
|
|
{
|
|
|
|
ERR("TODO:");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Invalid coordinate space.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* From now on, everything takes place in parent space. */
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_vec3_subtract(&z, &pd->position, &target);
|
2013-12-26 23:56:30 -08:00
|
|
|
evas_vec3_normalize(&z, &z);
|
|
|
|
|
|
|
|
evas_vec3_cross_product(&x, &up, &z);
|
|
|
|
evas_vec3_normalize(&x, &x);
|
|
|
|
|
|
|
|
evas_vec3_cross_product(&y, &z, &x);
|
|
|
|
evas_vec3_normalize(&y, &y);
|
|
|
|
|
2014-01-05 22:10:59 -08:00
|
|
|
/* Below matrix to quaternion conversion code taken from
|
|
|
|
* http://fabiensanglard.net/doom3_documentation/37726-293748.pdf
|
|
|
|
* When any license issue occurs, use ken shoemake's algorithm instead.
|
|
|
|
*/
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-01-05 22:10:59 -08:00
|
|
|
if (x.x + y.y + z.z > 0.0)
|
|
|
|
{
|
|
|
|
Evas_Real t = x.x + y.y + z.z + 1.0;
|
|
|
|
Evas_Real s = evas_reciprocal_sqrt(t) * 0.5;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->orientation.w = s * t;
|
|
|
|
pd->orientation.z = (x.y - y.x) * s;
|
|
|
|
pd->orientation.y = (z.x - x.z) * s;
|
|
|
|
pd->orientation.x = (y.z - z.y) * s;
|
2014-01-05 22:10:59 -08:00
|
|
|
}
|
|
|
|
else if (x.x > y.y && x.x > z.z)
|
|
|
|
{
|
|
|
|
Evas_Real t = x.x - y.y - z.z + 1.0;
|
|
|
|
Evas_Real s = evas_reciprocal_sqrt(t) * 0.5;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->orientation.x = s * t;
|
|
|
|
pd->orientation.y = (x.y + y.x) * s;
|
|
|
|
pd->orientation.z = (z.x + x.z) * s;
|
|
|
|
pd->orientation.w = (y.z - z.y) * s;
|
2014-01-05 22:10:59 -08:00
|
|
|
}
|
|
|
|
else if (y.y > z.z)
|
|
|
|
{
|
|
|
|
Evas_Real t = -x.x + y.y - z.z + 1.0;
|
|
|
|
Evas_Real s = evas_reciprocal_sqrt(t) * 0.5;
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->orientation.y = s * t;
|
|
|
|
pd->orientation.x = (x.y + y.x) * s;
|
|
|
|
pd->orientation.w = (z.x - x.z) * s;
|
|
|
|
pd->orientation.z = (y.z + z.y) * s;
|
2014-01-05 22:10:59 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Evas_Real t = -x.x - y.y + z.z + 1.0;
|
|
|
|
Evas_Real s = evas_reciprocal_sqrt(t) * 0.5;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->orientation.z = s * t;
|
|
|
|
pd->orientation.w = (x.y - y.x) * s;
|
|
|
|
pd->orientation.x = (z.x + x.z) * s;
|
|
|
|
pd->orientation.y = (y.z + z.y) * s;
|
2014-01-05 22:10:59 -08:00
|
|
|
}
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_TRANSFORM, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_camera_set(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Camera *camera)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->type != EVAS_3D_NODE_TYPE_CAMERA)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Node type mismatch.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->data.camera.camera == camera)
|
2013-12-26 23:56:30 -08:00
|
|
|
return;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->data.camera.camera)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
/* Detach previous camera object. */
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_3d_camera_node_del(pd->data.camera.camera, obj);
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_unref(pd->data.camera.camera);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->data.camera.camera = camera;
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_ref(camera);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Register change notification on the camera for this node. */
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_3d_camera_node_add(camera, obj);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Mark changed. */
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_CAMERA, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static Evas_3D_Camera *
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_camera_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
return pd->data.camera.camera;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_light_set(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Light *light)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->type != EVAS_3D_NODE_TYPE_LIGHT)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Node type mismatch.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->data.light.light == light)
|
2013-12-26 23:56:30 -08:00
|
|
|
return;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->data.light.light)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
/* Detach previous light object. */
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_3d_light_node_del(pd->data.light.light, obj);
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_unref(pd->data.light.light);
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->data.light.light = light;
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_ref(light);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Register change notification on the light for this node. */
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_3d_light_node_add(light, obj);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Mark changed. */
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_LIGHT, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static Evas_3D_Light *
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_light_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
return pd->data.light.light;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_mesh_add(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Mesh *mesh)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
Evas_3D_Node_Mesh *nm = NULL;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->type != EVAS_3D_NODE_TYPE_MESH)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Node type mismatch.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (eina_hash_find(pd->data.mesh.node_meshes, &mesh) != NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("The mesh is already added to the node.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if ((nm = _node_mesh_new(obj, mesh)) == NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Failed to create node mesh.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Find node mesh and add if it does not exist. */
|
2014-04-14 03:03:47 -07:00
|
|
|
if (!eina_hash_add(pd->data.mesh.node_meshes, &mesh, nm))
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Failed to add a mesh to mesh table.");
|
|
|
|
_node_mesh_free(nm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->data.mesh.meshes = eina_list_append(pd->data.mesh.meshes, mesh);
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_ref(mesh);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Register change notification. */
|
2014-04-14 03:03:47 -07:00
|
|
|
evas_3d_mesh_node_add(mesh, obj);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
|
|
|
/* Mark changed. */
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_MESH_GEOMETRY, NULL));
|
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_MESH_MATERIAL, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_mesh_del(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Mesh *mesh)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->type != EVAS_3D_NODE_TYPE_MESH)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Node type mismatch.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (!eina_hash_del(pd->data.mesh.node_meshes, &mesh, NULL))
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("The given mesh doesn't belong to this node.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
pd->data.mesh.meshes = eina_list_remove(pd->data.mesh.meshes, mesh);
|
|
|
|
evas_3d_mesh_node_del(mesh, obj);
|
2014-04-14 03:59:38 -07:00
|
|
|
eo_unref(mesh);
|
2013-12-26 23:56:30 -08:00
|
|
|
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_MESH_GEOMETRY, NULL));
|
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_MESH_MATERIAL, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static const Eina_List *
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_mesh_list_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
2014-04-14 03:03:47 -07:00
|
|
|
return pd->data.mesh.meshes;
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static void
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_mesh_frame_set(Eo *obj, Evas_3D_Node_Data *pd, Evas_3D_Mesh *mesh, int frame)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
Evas_3D_Node_Mesh *nm = NULL;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->type != EVAS_3D_NODE_TYPE_MESH)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Node type mismatch.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if ((nm = eina_hash_find(pd->data.mesh.node_meshes, &mesh)) == NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("The given mesh doesn't belongs to this node.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nm->frame = frame;
|
2014-04-25 10:28:38 -07:00
|
|
|
eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_NODE_MESH_FRAME, NULL));
|
2013-12-26 23:56:30 -08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
EOLIAN static int
|
2014-04-25 10:28:38 -07:00
|
|
|
_evas_3d_node_mesh_frame_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd, Evas_3D_Mesh *mesh)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
Evas_3D_Node_Mesh *nm = NULL;
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if (pd->type != EVAS_3D_NODE_TYPE_MESH)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("Node type mismatch.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
if ((nm = eina_hash_find(pd->data.mesh.node_meshes, &mesh)) == NULL)
|
2013-12-26 23:56:30 -08:00
|
|
|
{
|
|
|
|
ERR("The given mesh doesn't belongs to this node.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nm->frame;
|
|
|
|
}
|
2014-04-14 03:03:47 -07:00
|
|
|
|
2014-05-27 06:07:28 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_evas_3d_node_bounding_box_get(Eo *obj EINA_UNUSED, Evas_3D_Node_Data *pd, Evas_Real *x, Evas_Real *y, Evas_Real *z, Evas_Real *x2, Evas_Real *y2, Evas_Real *z2)
|
|
|
|
{
|
|
|
|
if (x) *x = pd->aabb.p0.x;
|
|
|
|
if (y) *y = pd->aabb.p0.y;
|
|
|
|
if (z) *z = pd->aabb.p0.z;
|
|
|
|
if (x2) *x2 = pd->aabb.p1.x;
|
|
|
|
if (y2) *y2 = pd->aabb.p1.y;
|
|
|
|
if (z2) *z2 = pd->aabb.p1.z;
|
|
|
|
}
|
|
|
|
|
2014-04-14 03:03:47 -07:00
|
|
|
#include "canvas/evas_3d_node.eo.c"
|