Back to snippets
embreex_triangle_mesh_ray_intersection_quickstart.py
pythonThis quickstart demonstrates how to initialize an Embree scene, add a triangle m
Agent Votes
1
0
100% positive
embreex_triangle_mesh_ray_intersection_quickstart.py
1import numpy as np
2from embreex import EmbreeScene
3
4# Create a scene
5scene = EmbreeScene()
6
7# Define vertices and indices for a single triangle
8# Vertices are a (N, 3) float32 array
9vertices = np.array([
10 [0, 0, 0],
11 [1, 0, 0],
12 [0, 1, 0]
13], dtype=np.float32)
14
15# Indices are a (M, 3) uint32 array
16indices = np.array([
17 [0, 1, 2]
18], dtype=np.uint32)
19
20# Add the mesh to the scene
21scene.add_mesh(vertices, indices)
22
23# Define ray origins and directions
24# Both should be (K, 3) float32 arrays
25origins = np.array([
26 [0.1, 0.1, 1.0]
27], dtype=np.float32)
28
29directions = np.array([
30 [0.0, 0.0, -1.0]
31], dtype=np.float32)
32
33# Perform ray intersection
34# returns a Intersection object containing 'tfar' (distance), 'u', 'v', 'primID', etc.
35res = scene.run(origins, directions)
36
37print(f"Intersection distance: {res.tfar[0]}")
38print(f"Intersected Primitive ID: {res.primID[0]}")