Skip to content

lcp29/trimesh-ray-optix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Triro - A Python Ray-Mesh Intersector in OptiX

Triro is a mesh ray tracing library implemented with NVIDIA OptiX. It has compatible interface with trimesh.ray and provides other convenient functions.

🔧️ Installation

You may need to enable unicode UTF-8 global support in Windows for some character set problems.

You need an OptiX SDK (>=7.7) installed to get to use Triro. If you are running Windows you also need an MSVC installation. First

# if you are running in Windows set the system variable
export OptiX_INSTALL_DIR=<Your Optix SDK installation directory>

Then

pip install git+https://github.com/lcp29/trimesh-ray-optix

or

git clone https://github.com/lcp29/trimesh-ray-optix
cd trimesh-ray-optix
pip install .

📖️ Example

import torch
import trimesh
import matplotlib.pyplot as plt
from triro.ray.ray_optix import RayMeshIntersector

# creating mesh and intersector
mesh = trimesh.creation.icosphere()
intersector = RayMeshIntersector(mesh)

# generating rays
y, x = torch.meshgrid([torch.linspace(1, -1, 800), 
                       torch.linspace(-1, 1, 800)], indexing='ij')
z = -torch.ones_like(x)
ray_directions = torch.stack([x, y, z], dim=-1).cuda()
ray_origins = torch.Tensor([0, 0, 3]).cuda().broadcast_to(ray_directions.shape)

# OptiX, Launch!
hit, front, ray_idx, tri_idx, location, uv = intersector.intersects_closest(
    ray_origins, ray_directions, stream_compaction=True
)

# drawing result
locs = torch.zeros((800, 800, 3)).cuda()
locs[hit] = location
plt.imshow(locs.cpu())
plt.show()

The above code generates the following result:

🕊️ TODOs

  • Installation on Windows
  • Supporting Tensor strides

🚀️ Performance Comparison

Scene closest-hit ray tracing tested under Ubuntu 22.04, i5-13490F and RTX 3090 (performance_test.py):

GPU time: 8.362 s / 100000 iters
Trimesh & PyEmbree CPU time: 18.175 s / 100 iters
speedup: 2173x

🔍️ Documentation

The Trimesh document is here.

For detailed document see here or the wiki.

About

Triro - An in-place replacement for trimesh.ray in OptiX

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published