star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit 6423486c5bc0e451bd7c3a13d68e203948c371e8
parent 25dc3f8917156a7ce84106c89d5b410cac3f5005
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 20 Mar 2015 11:55:54 +0100

Test the scene instantiation

Diffstat:
Msrc/s3d_scene.c | 18++++++++++++++----
Msrc/s3d_shape.c | 6+++---
Msrc/test_s3d_scene.c | 11+++++++++++
Msrc/test_s3d_trace_ray.c | 41++++++++++++++++++++++++++++++++++++-----
4 files changed, 64 insertions(+), 12 deletions(-)

diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -118,14 +118,22 @@ shape_instance_setup(struct s3d_scene* scn, struct s3d_shape* shape) ASSERT(scn && shape && shape->type == SHAPE_INSTANCE); /* Recursuvely update the scene */ - res = scene_setup(shape->data.instance.scene); - if(res != RES_OK) return res; + S3D(scene_build(shape->data.instance.scene)); mutex_rw_rlock(shape->lock); if(shape->rtc_geom == RTC_INVALID_GEOMETRY_ID) { shape->rtc_geom = rtcNewInstance (scn->rtc_scn, shape->data.instance.scene->rtc_scn); + + if(shape->rtc_geom >= darray_geom2shape_size_get(&scn->geom2shape)) { + res = darray_geom2shape_resize(&scn->geom2shape, shape->rtc_geom+1); + if(res != RES_OK) { + mutex_rw_unlock(shape->lock); + return res; + } + } + darray_geom2shape_data_get(&scn->geom2shape)[shape->rtc_geom] = shape; } if(shape->data.instance.update_transform) { rtcSetTransform @@ -133,16 +141,18 @@ shape_instance_setup(struct s3d_scene* scn, struct s3d_shape* shape) shape->rtc_geom, RTC_MATRIX_COLUMN_MAJOR, shape->data.instance.transform); + shape->data.instance.update_transform = 1; } mutex_rw_unlock(shape->lock); + return RES_OK; } res_T scene_setup(struct s3d_scene* scn) { struct list_node* node; - res_T res; + res_T res = RES_OK; ASSERT(scn); LIST_FOR_EACH(node, &scn->shapes) { @@ -150,7 +160,7 @@ scene_setup(struct s3d_scene* scn) (node, struct s3d_shape, scene_attachment); switch(shape->type) { case SHAPE_INSTANCE: - FATAL("Unsupported shape type\n"); + res = shape_instance_setup(scn, shape); break; case SHAPE_MESH: res = shape_mesh_setup(scn, shape); diff --git a/src/s3d_shape.c b/src/s3d_shape.c @@ -386,11 +386,11 @@ s3d_shape_instance_set_position return RES_BAD_ARG; mutex_rw_wlock(shape->lock); shape->data.instance.transform[9] = - -f3_dot(f33_row(axis, shape->data.instance.transform, 0), position); + f3_dot(f33_row(axis, shape->data.instance.transform, 0), position); shape->data.instance.transform[10] = - -f3_dot(f33_row(axis, shape->data.instance.transform, 1), position); + f3_dot(f33_row(axis, shape->data.instance.transform, 1), position); shape->data.instance.transform[11] = - -f3_dot(f33_row(axis, shape->data.instance.transform, 2), position); + f3_dot(f33_row(axis, shape->data.instance.transform, 2), position); shape->data.instance.update_transform = 1; if(shape->scn) ATOMIC_SET(&shape->scn->is_outdated, 1); diff --git a/src/test_s3d_scene.c b/src/test_s3d_scene.c @@ -66,11 +66,22 @@ main(int argc, char** argv) CHECK(s3d_shape_ref_put(shapes[i]), RES_OK); } + CHECK(s3d_scene_instantiate(NULL, NULL), RES_BAD_ARG); + CHECK(s3d_scene_instantiate(scn, NULL), RES_BAD_ARG); + CHECK(s3d_scene_instantiate(NULL, shapes + 1), RES_BAD_ARG); + CHECK(s3d_scene_instantiate(scn, shapes + 1), RES_OK); + CHECK(s3d_scene_clear(NULL), RES_BAD_ARG); CHECK(s3d_scene_clear(scn), RES_OK); CHECK(s3d_scene_clear(scn), RES_OK); + CHECK(s3d_scene_instantiate(scn, shapes + 2), RES_OK); + + CHECK(s3d_scene_build(NULL), RES_BAD_ARG); + CHECK(s3d_scene_build(scn), RES_OK); CHECK(s3d_shape_ref_put(shapes[0]), RES_OK); + CHECK(s3d_shape_ref_put(shapes[1]), RES_OK); + CHECK(s3d_shape_ref_put(shapes[2]), RES_OK); CHECK(s3d_scene_ref_get(NULL), RES_BAD_ARG); CHECK(s3d_scene_ref_get(scn), RES_OK); diff --git a/src/test_s3d_trace_ray.c b/src/test_s3d_trace_ray.c @@ -37,8 +37,8 @@ #include <rsys/image.h> #include <rsys/float3.h> -#define IMG_WIDTH 640 -#define IMG_HEIGHT 480 +#define IMG_WIDTH 512 +#define IMG_HEIGHT 512 struct camera { float pos[3]; @@ -48,8 +48,8 @@ struct camera { static void camera_init(struct camera* cam) { - const float pos[3] = { 178.f, -1000.f, 273.f }; - const float tgt[3] = { 178.f, 0.f, 273.f }; + const float pos[3] = { 0.f, -1500.f, 0.f }; + const float tgt[3] = { 0.f, 0.f, 0.f }; const float up[3] = { 0.f, 0.f, 1.f }; const float proj_ratio = (float)IMG_WIDTH/(float)IMG_HEIGHT; const float fov_x = (float)PI * 0.25f; @@ -88,6 +88,7 @@ main(int argc, char** argv) struct s3d_device* dev; struct s3d_hit hit; struct s3d_scene* scn; + struct s3d_scene* scn2; struct s3d_shape* shape; struct s3d_vertex_data attribs[4]; struct camera cam; @@ -155,6 +156,35 @@ main(int argc, char** argv) f3(dir, 1.f, 1.f, 1.f); CHECK(s3d_scene_trace_ray(scn, org, dir, range, &hit), RES_BAD_ARG); + + CHECK(s3d_scene_create(dev, &scn2), RES_OK); + + f3(org, -555.f, 0.f, -551.f); + CHECK(s3d_shape_ref_put(shape), RES_OK); + CHECK(s3d_scene_instantiate(scn, &shape), RES_OK); + CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK); + CHECK(s3d_shape_instance_set_position(shape, org), RES_OK); + + f3(org, 3.f, 0.f, -551.f); + CHECK(s3d_shape_ref_put(shape), RES_OK); + CHECK(s3d_scene_instantiate(scn, &shape), RES_OK); + CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK); + CHECK(s3d_shape_instance_set_position(shape, org), RES_OK); + + f3(org, -555.f, 0.f, 3.f); + CHECK(s3d_shape_ref_put(shape), RES_OK); + CHECK(s3d_scene_instantiate(scn, &shape), RES_OK); + CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK); + CHECK(s3d_shape_instance_set_position(shape, org), RES_OK); + + f3(org, 3.f, 0.f, 3.f); + CHECK(s3d_shape_ref_put(shape), RES_OK); + CHECK(s3d_scene_instantiate(scn, &shape), RES_OK); + CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK); + CHECK(s3d_shape_instance_set_position(shape, org), RES_OK); + + CHECK(s3d_scene_build(scn2), RES_OK); + camera_init(&cam); FOR_EACH(iy, 0, IMG_HEIGHT) { float pixel[2]; @@ -165,7 +195,7 @@ main(int argc, char** argv) pixel[0] = (float)ix/(float)IMG_WIDTH; camera_ray(&cam, pixel, org, dir); - CHECK(s3d_scene_trace_ray(scn, org, dir, range, &hit), RES_OK); + CHECK(s3d_scene_trace_ray(scn2, org, dir, range, &hit), RES_OK); if(!img) continue; @@ -194,6 +224,7 @@ main(int argc, char** argv) CHECK(s3d_device_ref_put(dev), RES_OK); CHECK(s3d_shape_ref_put(shape), RES_OK); CHECK(s3d_scene_ref_put(scn), RES_OK); + CHECK(s3d_scene_ref_put(scn2), RES_OK); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator);