Embreex

2.17.7.post7 · active · verified Sat Apr 11

Embreex is a Python binding for Intel's high-performance Embree ray tracing kernel. It is a fork of `scopatz/pyembree`, created to provide pre-built wheels for Intel Mac, Windows, and Linux across various Python versions (3.8+), aiming for minimal dependencies. The library is actively maintained with regular updates and includes a release candidate for a new major version.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic triangular mesh, initialize an `EmbreeTrimesh` object, create a `RayMeshIntersector`, and perform a ray-mesh intersection query to check for hits and retrieve hit details.

import embreex
import numpy as np

# Define a simple mesh (e.g., a triangle)
vertices = np.array([
    [0.0, 0.0, 0.0],
    [1.0, 0.0, 0.0],
    [0.0, 1.0, 0.0]
], dtype=np.float32)
faces = np.array([
   
], dtype=np.int32)

# Create an Embree mesh object
mesh = embreex.EmbreeTrimesh(vertices, faces)

# Create a ray intersector from the mesh
intersector = embreex.RayMeshIntersector(mesh)

# Define a single ray (origin and direction)
ray_origins = np.array([[0.1, 0.1, 1.0]], dtype=np.float32)
ray_directions = np.array([[0.0, 0.0, -1.0]], dtype=np.float32)

# Check if the ray hits the mesh
hits = intersector.intersects_any(ray_origins, ray_directions)
print(f"Ray hits mesh: {hits}")

# Find the first hit location and triangle index
index_tri, u, v, t = intersector.intersects_first(ray_origins, ray_directions)
if index_tri != -1:
    print(f"\nFirst hit details:")
    print(f"  Hit triangle index: {index_tri}")
    print(f"  Barycentric coordinates (U, V): {u:.4f}, {v:.4f}")
    print(f"  Distance along ray (t): {t:.4f}")
else:
    print("\nNo hit found for the ray.")

view raw JSON →