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 b5293f78c39c1039430221697186fd781ea3bc55
parent 419fd93ddcbbb5d3df7832d5bcdcabb8176c42ee
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu,  8 Oct 2020 11:35:31 +0200

Fix closest point query on instances

Handle the identityScale factor submitted by Embree to trasform the
computed distance from instance space to world space.

Diffstat:
Msrc/s3d_scene_view_closest_point.c | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/s3d_scene_view_closest_point.c b/src/s3d_scene_view_closest_point.c @@ -217,8 +217,17 @@ closest_point_mesh /* Compute the closest point onto the triangle from the submitted point */ closest_point_triangle(query_pos, v0, v1, v2, closest_point, uv); + /* Compute the distance */ f3_sub(vec, closest_point, query_pos); dst = f3_len(vec); + + /* Adjust the distance in world space */ + if(args->context->instStackSize != 0) { + ASSERT(args->context->instStackSize == 1); + ASSERT(args->similarityScale > 0); + dst /= args->similarityScale; + } + if(dst >= args->query->radius) return 0; /* Compute the triangle normal in world space */ @@ -317,6 +326,13 @@ closest_point_sphere /* Evaluate the distance from the query pos to the sphere surface */ dst = fabsf(len - geom->data.sphere->radius); + if(args->context->instStackSize != 0) { /* It is an instance */ + /* Adjust the distance in world space */ + ASSERT(args->context->instStackSize == 1); + ASSERT(args->similarityScale > 0); + dst /= args->similarityScale; + } + /* The closest point onto the sphere is outside the query radius */ if(dst >= args->query->radius) return 0; @@ -390,7 +406,7 @@ closest_point(struct RTCPointQueryFunctionArguments* args) (ctx->scnview, args->geomID); } else { ASSERT(args->context->instStackSize == 1); - ASSERT(args->similarityScale == 1); + ASSERT(args->similarityScale > 0); inst = scene_view_geometry_from_embree_id (ctx->scnview, args->context->instID[0]); geom = scene_view_geometry_from_embree_id