diff --git a/3rdparty/embree/embree.cmake b/3rdparty/embree/embree.cmake index e0794b55da0..4e93eadf19e 100644 --- a/3rdparty/embree/embree.cmake +++ b/3rdparty/embree/embree.cmake @@ -69,8 +69,8 @@ endif() ExternalProject_Add( ext_embree PREFIX embree - URL https://github.com/embree/embree/archive/refs/tags/v4.3.1.tar.gz - URL_HASH SHA256=824edcbb7a8cd393c5bdb7a16738487b21ecc4e1d004ac9f761e934f97bb02a4 + URL https://github.com/embree/embree/archive/refs/tags/v3.13.3.tar.gz + URL_HASH SHA256=74ec785afb8f14d28ea5e0773544572c8df2e899caccdfc88509f1bfff58716f DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/embree" UPDATE_COMMAND "" CMAKE_ARGS @@ -88,7 +88,7 @@ ExternalProject_Add( -DEMBREE_TASKING_SYSTEM=INTERNAL ${WIN_CMAKE_ARGS} BUILD_BYPRODUCTS - /${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}embree4${CMAKE_STATIC_LIBRARY_SUFFIX} + /${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}embree3${CMAKE_STATIC_LIBRARY_SUFFIX} /${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}simd${CMAKE_STATIC_LIBRARY_SUFFIX} /${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lexers${CMAKE_STATIC_LIBRARY_SUFFIX} /${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}sys${CMAKE_STATIC_LIBRARY_SUFFIX} @@ -100,4 +100,4 @@ ExternalProject_Add( ExternalProject_Get_Property(ext_embree INSTALL_DIR) set(EMBREE_INCLUDE_DIRS ${INSTALL_DIR}/include/ ${INSTALL_DIR}/src/ext_embree/) # "/" is critical. set(EMBREE_LIB_DIR ${INSTALL_DIR}/${Open3D_INSTALL_LIB_DIR}) -set(EMBREE_LIBRARIES embree4 ${ISA_LIBS} simd lexers sys math tasking) +set(EMBREE_LIBRARIES embree3 ${ISA_LIBS} simd lexers sys math tasking) diff --git a/cpp/open3d/t/geometry/RaycastingScene.cpp b/cpp/open3d/t/geometry/RaycastingScene.cpp index 14f9962c26c..af7dd3f1480 100644 --- a/cpp/open3d/t/geometry/RaycastingScene.cpp +++ b/cpp/open3d/t/geometry/RaycastingScene.cpp @@ -12,7 +12,7 @@ #include "open3d/t/geometry/RaycastingScene.h" // This header is in the embree src dir (embree/src/ext_embree/..). -#include +#include #include #include @@ -61,7 +61,7 @@ void AssertTensorDtypeLastDimDeviceMinNDim(const open3d::core::Tensor& tensor, } struct CountIntersectionsContext { - RTCRayQueryContext context; + RTCIntersectContext context; std::vector>* previous_geom_prim_ID_tfar; int* intersections; @@ -111,7 +111,7 @@ void CountIntersectionsFunc(const RTCFilterFunctionNArguments* args) { } struct ListIntersectionsContext { - RTCRayQueryContext context; + RTCIntersectContext context; std::vector>* previous_geom_prim_ID_tfar; unsigned int* ray_ids; @@ -360,6 +360,9 @@ struct RaycastingScene::Impl { const int nthreads) { CommitScene(); + struct RTCIntersectContext context; + rtcInitIntersectContext(&context); + auto LoopFn = [&](const tbb::blocked_range& range) { std::vector rayhits(range.size()); @@ -384,15 +387,16 @@ struct RaycastingScene::Impl { } else { rh.ray.tfar = std::numeric_limits::infinity(); } - rh.ray.mask = -1; + rh.ray.mask = 0; rh.ray.id = i - range.begin(); rh.ray.flags = 0; rh.hit.geomID = RTC_INVALID_GEOMETRY_ID; rh.hit.instID[0] = RTC_INVALID_GEOMETRY_ID; - - rtcIntersect1(scene_, &rh); } + rtcIntersect1M(scene_, &context, &rayhits[0], range.size(), + sizeof(RTCRayHit)); + for (size_t i = range.begin(); i < range.end(); ++i) { RTCRayHit rh = rayhits[i - range.begin()]; size_t idx = rh.ray.id + range.begin(); @@ -442,12 +446,8 @@ struct RaycastingScene::Impl { const int nthreads) { CommitScene(); - struct RTCRayQueryContext context; - rtcInitRayQueryContext(&context); - - RTCOccludedArguments args; - rtcInitOccludedArguments(&args); - args.context = &context; + struct RTCIntersectContext context; + rtcInitIntersectContext(&context); auto LoopFn = [&](const tbb::blocked_range& range) { std::vector rayvec(range.size()); @@ -462,13 +462,14 @@ struct RaycastingScene::Impl { ray.dir_z = r[5]; ray.tnear = tnear; ray.tfar = tfar; - ray.mask = -1; + ray.mask = 0; ray.id = i - range.begin(); ray.flags = 0; - - rtcOccluded1(scene_, &ray, &args); } + rtcOccluded1M(scene_, &context, &rayvec[0], range.size(), + sizeof(RTCRay)); + for (size_t i = range.begin(); i < range.end(); ++i) { RTCRay ray = rayvec[i - range.begin()]; size_t idx = ray.id + range.begin(); @@ -507,15 +508,11 @@ struct RaycastingScene::Impl { 0.f)); CountIntersectionsContext context; - rtcInitRayQueryContext(&context.context); + rtcInitIntersectContext(&context.context); + context.context.filter = CountIntersectionsFunc; context.previous_geom_prim_ID_tfar = &previous_geom_prim_ID_tfar; context.intersections = intersections; - RTCIntersectArguments args; - rtcInitIntersectArguments(&args); - args.filter = CountIntersectionsFunc; - args.context = &context.context; - auto LoopFn = [&](const tbb::blocked_range& range) { std::vector rayhits(range.size()); @@ -530,14 +527,14 @@ struct RaycastingScene::Impl { rh->ray.dir_z = r[5]; rh->ray.tnear = 0; rh->ray.tfar = std::numeric_limits::infinity(); - rh->ray.mask = -1; + rh->ray.mask = 0; rh->ray.flags = 0; rh->ray.id = i; rh->hit.geomID = RTC_INVALID_GEOMETRY_ID; rh->hit.instID[0] = RTC_INVALID_GEOMETRY_ID; - - rtcIntersect1(scene_, rh, &args); } + rtcIntersect1M(scene_, &context.context, &rayhits[0], range.size(), + sizeof(RTCRayHit)); }; if (nthreads > 0) { @@ -582,7 +579,8 @@ struct RaycastingScene::Impl { 0.f)); ListIntersectionsContext context; - rtcInitRayQueryContext(&context.context); + rtcInitIntersectContext(&context.context); + context.context.filter = ListIntersectionsFunc; context.previous_geom_prim_ID_tfar = &previous_geom_prim_ID_tfar; context.ray_ids = ray_ids; context.geometry_ids = geometry_ids; @@ -592,11 +590,6 @@ struct RaycastingScene::Impl { context.cumsum = cumsum; context.track_intersections = track_intersections; - RTCIntersectArguments args; - rtcInitIntersectArguments(&args); - args.filter = ListIntersectionsFunc; - args.context = &context.context; - auto LoopFn = [&](const tbb::blocked_range& range) { std::vector rayhits(range.size()); @@ -611,14 +604,14 @@ struct RaycastingScene::Impl { rh->ray.dir_z = r[5]; rh->ray.tnear = 0; rh->ray.tfar = std::numeric_limits::infinity(); - rh->ray.mask = -1; + rh->ray.mask = 0; rh->ray.flags = 0; rh->ray.id = i; rh->hit.geomID = RTC_INVALID_GEOMETRY_ID; rh->hit.instID[0] = RTC_INVALID_GEOMETRY_ID; - - rtcIntersect1(scene_, rh, &args); } + rtcIntersect1M(scene_, &context.context, &rayhits[0], range.size(), + sizeof(RTCRayHit)); }; if (nthreads > 0) { @@ -702,9 +695,9 @@ RaycastingScene::RaycastingScene(int64_t nthreads) impl_->scene_ = rtcNewScene(impl_->device_); // set flag for better accuracy - rtcSetSceneFlags(impl_->scene_, - RTC_SCENE_FLAG_ROBUST | - RTC_SCENE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS); + rtcSetSceneFlags( + impl_->scene_, + RTC_SCENE_FLAG_ROBUST | RTC_SCENE_FLAG_CONTEXT_FILTER_FUNCTION); impl_->devprop_join_commit = rtcGetDeviceProperty( impl_->device_, RTC_DEVICE_PROPERTY_JOIN_COMMIT_SUPPORTED); @@ -753,7 +746,6 @@ uint32_t RaycastingScene::AddTriangles(const core::Tensor& vertex_positions, memcpy(index_buffer, data.GetDataPtr(), sizeof(uint32_t) * 3 * num_triangles); } - rtcSetGeometryEnableFilterFunctionFromArguments(geom, true); rtcCommitGeometry(geom); uint32_t geom_id = rtcAttachGeometry(impl_->scene_, geom);