Skip to content

RC0: Embree 4 Support#1

Merged
mikedh merged 19 commits intomainfrom
feat/e4
Mar 8, 2026
Merged

RC0: Embree 4 Support#1
mikedh merged 19 commits intomainfrom
feat/e4

Conversation

@mikedh
Copy link
Collaborator

@mikedh mikedh commented Jun 13, 2023

Not working, plumbing hooked up.

@alisoufali-trendplus
Copy link

Not working, plumbing hooked up.

Hi, I've seen that you are trying to make embree 4 working. There is a code named raybender which managed to make python bindings for the embree the other way. It might work

https://github.com/cvg/raybender

@schwarrx
Copy link

@mikedh would love to see this working. Let me know how I can help. Excited to use embreex with Embree 4 on Apple M2!

mikedh pushed a commit that referenced this pull request Oct 22, 2025
…reeDevice

pytest + gdb backtrace output, with embree v2.17.7 compiled with `-DCMAKE_BUILD_TYPE=RelWithDebInfo`:

    ============================= test session starts ==============================
    platform linux -- Python 3.12.9, pytest-8.3.5, pluggy-1.5.0 -- /nix/store/fqm9bqqlmaqqr02qbalm1bazp810qfiw-python3-3.12.9/bin/python3.12
    cachedir: .pytest_cache
    rootdir: /build/source
    configfile: pyproject.toml
    collected 13 items

    tests/test_intersection.py::TestPyEmbree::test_pyembree_should_be_able_to_create_a_device_if_not_provided PASSED [  7%]
    tests/test_intersection.py::TestPyEmbree::test_pyembree_should_be_able_to_create_a_scene PASSED [ 15%]
    tests/test_intersection.py::TestPyEmbree::test_pyembree_should_be_able_to_create_several_scenes PASSED [ 23%]
    tests/test_intersection.py::TestPyEmbree::test_pyembree_should_be_able_to_display_embree_version PASSED [ 30%]
    tests/test_intersection.py::TestIntersectionTriangles::test_intersect PASSED [ 38%]
    Thread 1 "python3.12" received signal SIGSEGV, Segmentation fault.
    0x0000000000000000 in ?? ()
    #0  0x0000000000000000 in ?? ()
    #1  0x00007fffb1e7e76f in embree::APIBuffer<embree::Vec3fa>::free (this=0x8cb7b0) at /build/source/kernels/common/buffer.h:212
    #2  embree::APIBuffer<embree::Vec3fa>::~APIBuffer (this=0x8cb7b0, __in_chrg=<optimized out>) at /build/source/kernels/common/buffer.h:137
    #3  std::__new_allocator<embree::APIBuffer<embree::Vec3fa> >::destroy<embree::APIBuffer<embree::Vec3fa> > (this=0x9357a8, __p=0x8cb7b0) at /nix/store/qs54xir5n4vhhbi22aydbkvyyq4v8p0l-gcc-14.2.1.20250322/include/c++/14.2.1.20250322/bits/new_allocator.h:198
    #4  embree::vector_t<embree::APIBuffer<embree::Vec3fa>, std::allocator<embree::APIBuffer<embree::Vec3fa> > >::clear (this=0x9357a8) at /build/source/kernels/common/../../common/sys/vector.h:148
            i = 0
    #5  embree::vector_t<embree::APIBuffer<embree::Vec3fa>, std::allocator<embree::APIBuffer<embree::Vec3fa> > >::~vector_t (this=0x9357a8, __in_chrg=<optimized out>) at /build/source/kernels/common/../../common/sys/vector.h:42
    #6  embree::TriangleMesh::~TriangleMesh (this=0x9356b0, __in_chrg=<optimized out>) at /build/source/kernels/common/scene_triangle_mesh.h:25
    #7  embree::avx::TriangleMeshISA::~TriangleMeshISA (this=0x9356b0, __in_chrg=<optimized out>) at /build/source/kernels/common/scene_triangle_mesh.h:220
    #8  embree::avx::TriangleMeshISA::~TriangleMeshISA (this=0x9356b0, __in_chrg=<optimized out>) at /build/source/kernels/common/scene_triangle_mesh.h:220
    scopatz#9  0x00007fffb174744f in embree::Scene::~Scene (this=0xb45dc0, __in_chrg=<optimized out>) at /build/source/kernels/common/scene.cpp:594
            i = 0
            i = <optimized out>
    scopatz#10 0x00007fffb17475e9 in embree::Scene::~Scene (this=0xb45dc0, __in_chrg=<optimized out>) at /build/source/kernels/common/scene.cpp:599
            i = <optimized out>
    scopatz#11 0x00007ffff3565de8 in __pyx_pf_8pyembree_12rtcore_scene_11EmbreeScene_4__dealloc__ (__pyx_v_self=0x7fffb3055e00) at pyembree/rtcore_scene.cpp:3957

(ported from e64a2fa)
@LeeJB-48
Copy link

LeeJB-48 commented Dec 4, 2025

Hi, i'm using trimesh and apple silicon macos.
I needed to do huge amount of ray intersection on mesh but embreex didn't support macos arm64,
so i forked embreex repository and made upgrade to embree4
I used ai to make those upgrade.

And it works well in both linux and macos arm64.

Feel free to use my code

https://github.com/LeeJB-48/embreex4

@mikedh
Copy link
Collaborator Author

mikedh commented Dec 4, 2025

Great point! It's probably OK to let Claude finish 3 year old PR's haha. I fixed the build and the wheels are usable (https://github.com/trimesh/embreex/actions/runs/19942366491) and they were performing well, however it was failing the upstream trimesh test_ray.py:

INFO           test_ray.py:50    Measured [791512.52099 684504.93676] rays/second with embree 1
INFO            generic.py:257   loading mesh from: /home/mikedh/trimesh/models/unit_sphere.STL
INFO           test_ray.py:50    Measured [48734.76568 48177.4972 ] rays/second with embree 0
.
======================================================================
FAIL: test_multiple_hits (__main__.RayTests.test_multiple_hits)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mikedh/trimesh/tests/test_ray.py", line 154, in test_multiple_hits
    assert len(g.np.unique(index_triangles)) == 2
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

----------------------------------------------------------------------
Ran 9 tests in 5.351s

FAILED (failures=1)

If I had to guess it's probably that the new robust flag doesn't like rays starting inside a solid? @LeeJB-48 does your branch pass test_ray.py?

I had also forked the upstream raybender and got it to build wheels (https://github.com/mikedh/raybender) as it has a nicer structure (pybind11 stuff is easier to maintain vs Cython stuff imo) but I didn't get it over the line as I was hoping to have an API that actually worked on Scenes, not just triangle soups.

We should probably get embreex over the line as-is.

@mikedh mikedh changed the title [WIP] Embree 4 Support RC0: Embree 4 Support Mar 8, 2026
@mikedh mikedh merged commit 5f9342d into main Mar 8, 2026
8 checks passed
@mikedh mikedh deleted the feat/e4 branch March 8, 2026 04:00
@LeeJB-48
Copy link

LeeJB-48 commented Mar 9, 2026

Thanks for making embree 4 support !
I really appreciate it !

@mikedh
Copy link
Collaborator Author

mikedh commented Mar 9, 2026

Thanks for the follow up on this ancient PR! Anyone watching if you want to test the release candidate with pip install --pre --upgrade embreex that would be awesome. It's still failing the 1 out of 9 upstream trimesh tests but that case is for undefined behavior (hit-on-crest-edge) and I think is fine. I'll try to do a non-candidate release of this in a month or two after running on this more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants