commit 3442d7452b5139e47a9b2f0adfc98f097eb7ee68
parent a1ac617b29739bd07dcf84cf94da2e8d521355c2
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 6 Mar 2017 09:48:40 +0100
Merge branch 'develop' into feature_hyperbols
Diffstat:
4 files changed, 106 insertions(+), 1 deletion(-)
diff --git a/src/ssol.h b/src/ssol.h
@@ -480,6 +480,12 @@ ssol_scene_detach_instance
(struct ssol_scene* scn,
struct ssol_instance* instance);
+SSOL_API res_T
+ssol_scene_compute_aabb
+ (const struct ssol_scene* scn,
+ float lower[3],
+ float upper[3]);
+
/* Detach all the instances from the scene and release the reference that the
* scene takes onto them.
* Also detach the attached sun if any. */
diff --git a/src/ssol_scene.c b/src/ssol_scene.c
@@ -188,6 +188,30 @@ ssol_scene_detach_instance
}
res_T
+ssol_scene_compute_aabb
+ (const struct ssol_scene* scene, float lower[3], float upper[3])
+{
+ struct s3d_scene_view* view = NULL;
+ res_T res = RES_OK;
+
+ if(!scene || !lower || !upper) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ res = s3d_scene_view_create(scene->scn_rt, S3D_GET_PRIMITIVE, &view);
+ if(res != RES_OK) goto error;
+ res = s3d_scene_view_get_aabb(view, lower, upper);
+ if(res != RES_OK) goto error;
+
+exit:
+ if(view) S3D(scene_view_ref_put(view));
+ return res;
+error:
+ goto exit;
+}
+
+res_T
ssol_scene_clear(struct ssol_scene* scene)
{
struct htable_instance_iterator it, it_end;
@@ -469,7 +493,7 @@ hit_filter_function
if(inst == rdata->inst_from && hit_side != rdata->side_from) {
/* The intersected instance is the one from which the ray starts,
* ensure that the ray does not intersect the opposite side of the
- * quadric
+ * quadric
*
* Note that reversed_ray is intentionally not considered here! */
return 1;
diff --git a/src/test_ssol_draw.c b/src/test_ssol_draw.c
@@ -18,6 +18,7 @@
#include "test_ssol_geometries.h"
#include "test_ssol_materials.h"
+#include <rsys/float3.h>
#include <rsys/image.h>
#include <rsys/math.h>
@@ -116,6 +117,8 @@ setup_cornell_box(struct ssol_device* dev, struct ssol_scene* scn)
struct ssol_mirror_shader shader = SSOL_MIRROR_SHADER_NULL;
struct ssol_vertex_data vdata;
struct desc desc;
+ float lower[3], upper[3];
+ float tmp[3];
shader.normal = get_shader_normal;
shader.reflectivity = get_shader_reflectivity;
@@ -164,6 +167,10 @@ setup_cornell_box(struct ssol_device* dev, struct ssol_scene* scn)
CHECK(ssol_object_ref_put(obj), RES_OK);
CHECK(ssol_material_ref_put(mtl), RES_OK);
+
+ CHECK(ssol_scene_compute_aabb(scn, lower, upper), RES_OK);
+ CHECK(f3_eq_eps(lower, f3(tmp, 0, 0, 0), 1.e-6f), 1);
+ CHECK(f3_eq_eps(upper, f3(tmp, 552.f, 559.f, 548.f), 1.e-6f), 1);
}
int
diff --git a/src/test_ssol_scene.c b/src/test_ssol_scene.c
@@ -15,6 +15,9 @@
#include "ssol.h"
#include "test_ssol_utils.h"
+#include "test_ssol_geometries.h"
+
+#include <rsys/float3.h>
struct scene_ctx {
struct ssol_instance* instance;
@@ -56,6 +59,23 @@ get_wlen(const size_t i, double* wlen, double* data, void* ctx)
int
main(int argc, char** argv)
{
+ const float tall_block[] = {
+ 423.f, 247.f, 0.f,
+ 265.f, 296.f, 0.f,
+ 314.f, 456.f, 0.f,
+ 472.f, 406.f, 0.f,
+ 423.f, 247.f, 330.f,
+ 265.f, 296.f, 330.f,
+ 314.f, 456.f, 330.f,
+ 472.f, 406.f, 330.f
+ };
+ const unsigned block_ids[] = {
+ 4, 5, 6, 6, 7, 4,
+ 1, 2, 6, 6, 5, 1,
+ 0, 3, 7, 7, 4, 0,
+ 2, 3, 7, 7, 6, 2,
+ 0, 1, 5, 5, 4, 0
+ };
struct mem_allocator allocator;
struct ssol_device* dev;
struct ssol_shape* shape;
@@ -70,8 +90,11 @@ main(int argc, char** argv)
struct ssol_spectrum* spectrum;
struct ssol_atmosphere* atm;
struct ssol_atmosphere* atm2;
+ struct ssol_vertex_data vdata;
struct scene_ctx ctx;
+ struct desc desc;
double transform[12];
+ float lower[3], upper[3], tmp[3];
(void) argc, (void) argv;
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
@@ -192,6 +215,51 @@ main(int argc, char** argv)
CHECK(ssol_scene_ref_put(scene), RES_OK);
CHECK(ssol_scene_ref_put(scene2), RES_OK);
+ CHECK(ssol_shape_ref_put(shape), RES_OK);
+ CHECK(ssol_object_ref_put(object), RES_OK);
+ CHECK(ssol_instance_ref_put(instance), RES_OK);
+
+ CHECK(ssol_scene_create(dev, &scene), RES_OK);
+ CHECK(ssol_shape_create_mesh(dev, &shape), RES_OK);
+ CHECK(ssol_object_create(dev, &object), RES_OK);
+
+ vdata.usage = SSOL_POSITION;
+ vdata.get = get_position;
+ desc.vertices = tall_block;;
+ desc.indices = block_ids;
+
+ CHECK(ssol_mesh_setup(shape, 10, get_ids, 8, &vdata, 1, &desc), RES_OK);
+ CHECK(ssol_object_add_shaded_shape(object, shape, material, material), RES_OK);
+ CHECK(ssol_object_instantiate(object, &instance), RES_OK);
+
+ CHECK(ssol_scene_compute_aabb(NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(ssol_scene_compute_aabb(scene, NULL, NULL), RES_BAD_ARG);
+ CHECK(ssol_scene_compute_aabb(NULL, lower, NULL), RES_BAD_ARG);
+ CHECK(ssol_scene_compute_aabb(scene, lower, NULL), RES_BAD_ARG);
+ CHECK(ssol_scene_compute_aabb(NULL, NULL, upper), RES_BAD_ARG);
+ CHECK(ssol_scene_compute_aabb(scene, NULL, upper), RES_BAD_ARG);
+ CHECK(ssol_scene_compute_aabb(NULL, lower, upper), RES_BAD_ARG);
+ CHECK(ssol_scene_compute_aabb(scene, lower, upper), RES_OK);
+
+ /* Empty scene */
+ CHECK(lower[0] > upper[0], 1);
+ CHECK(lower[1] > upper[1], 1);
+ CHECK(lower[2] > upper[2], 1);
+
+ CHECK(ssol_scene_attach_instance(scene, instance), RES_OK);
+ CHECK(ssol_scene_compute_aabb(scene, lower, upper), RES_OK);
+ CHECK(f3_eq_eps(lower, f3(tmp, 265.f, 247.f, 0.f), 1.e-6f), 1);
+ CHECK(f3_eq_eps(upper, f3(tmp, 472.f, 456.f, 330.f), 1.e-6f), 1);
+
+ CHECK(ssol_scene_clear(scene), RES_OK);
+ CHECK(ssol_scene_compute_aabb(scene, lower, upper), RES_OK);
+
+ /* Empty scene */
+ CHECK(lower[0] > upper[0], 1);
+ CHECK(lower[1] > upper[1], 1);
+ CHECK(lower[2] > upper[2], 1);
+
+ CHECK(ssol_scene_ref_put(scene), RES_OK);
CHECK(ssol_instance_ref_put(instance), RES_OK);
CHECK(ssol_instance_ref_put(instance2), RES_OK);