Skip to content

Commit

Permalink
v 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dwastberg committed Oct 8, 2024
1 parent 24f942d commit 3b5cf70
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 36 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Build SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
with:
submodules: true

Expand All @@ -27,17 +27,17 @@ jobs:
name: Build Wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
fail-fast: true
matrix:
os: [ ubuntu-latest, macOS-latest]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install cibuildwheel twine nanobind
python -m pip install cibuildwheel twine nanobind
- uses: pypa/[email protected]
env:
Expand All @@ -52,7 +52,7 @@ jobs:

publish_wheels:
name: Publish Wheels to PyPI
needs: [ build_wheels, build_sdist ]
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment:
name: pypi
Expand All @@ -73,3 +73,4 @@ jobs:
# password: ${{ secrets.PYPI_TOKEN }}
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository-url: https://test.pypi.org/legacy/
verbose: true
17 changes: 4 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,23 @@ project(pymeshray)
set(CMAKE_CXX_STANDARD 20)
set(BINDINGS _bvh_bind_ext)


if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif ()
endif()

find_package(Python 3.10 COMPONENTS Interpreter Development.Module REQUIRED)

execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_DIR)
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_DIR)

message(STATUS "nanobind_DIR: ${nanobind_DIR}")
find_package(nanobind CONFIG REQUIRED)

include_directories(${CMAKE_SOURCE_DIR}/src/cpp/include)
include_directories(${CMAKE_SOURCE_DIR}/src/cpp/contrib)


nanobind_add_module(${BINDINGS} ${CMAKE_SOURCE_DIR}/src/cpp/bvh_bind_ext.cpp)
# if(DEFINED ENV{GITHUB_ACTIONS})
# install(TARGETS ${BINDINGS} LIBRARY DESTINATION pyraymesh)
# else()
# install(TARGETS ${BINDINGS} DESTINATION ${CMAKE_SOURCE_DIR}/src/pyraymesh)
# endif()


install(TARGETS ${BINDINGS} LIBRARY DESTINATION pyraymesh)

16 changes: 4 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
[project]
name = "pyraymesh"
version = "0.1.0"
version = "0.1.1"
description = "A library for ray-mesh intersections on triangular meshes"
readme = "README.md"
requires-python = ">=3.10"
license = { text = "MIT" }
authors = [
{ name = "Dag Wästberg", email = "[email protected]" }
]
authors = [{ name = "Dag Wästberg", email = "[email protected]" }]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
Expand All @@ -17,9 +15,7 @@ classifiers = [
]


dependencies = [
"numpy",
]
dependencies = ["numpy"]


[project.urls]
Expand All @@ -35,8 +31,4 @@ build.verbose = true
sdist.exclude = ["*.whl", "*.egg-info", "build", "dist"]

[tool.uv]
dev-dependencies = [
"nanobind>=2.1.0",
"pytest>=8.1.0",
"trimesh>=4.4.1",
]
dev-dependencies = ["nanobind>=2.1.0", "pytest>=8.1.0", "trimesh>=4.4.1"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


@dataclass
class MeshRayResults:
class IntersectionResult:
"""
A class to store the intersection results of a ray with a mesh.
Expand Down
11 changes: 7 additions & 4 deletions src/pyraymesh/Mesh.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from . import _bvh_bind_ext
from .MeshRayResults import MeshRayResults
from .IntersectionResult import IntersectionResult
from typing import List, Iterable, Union


Expand Down Expand Up @@ -74,7 +74,8 @@ def build(self, quality: str = "medium"):
quality = quality.lower()
if quality not in ["low", "medium", "high"]:
raise ValueError("Quality must be one of 'low', 'medium' or 'high'")

if len(self.vertices) == 0 or len(self.faces) == 0:
raise ValueError("Mesh is empty")
self._bvh = _bvh_bind_ext.build_bvh(self.vertices, self.faces, quality)

def intersect(
Expand All @@ -83,7 +84,7 @@ def intersect(
ray_direction: Iterable[float],
tnear: float = 0,
tfar: float = np.inf,
) -> MeshRayResults:
) -> IntersectionResult:
"""
Intersects the rays with the BVH (Bounding Volume Hierarchy) of the mesh.
Expand All @@ -102,13 +103,15 @@ def intersect(
if not self.is_built:
print("BVH not built, building now with medium quality")
self.build("medium")
if not self.is_built:
raise ValueError("failed to build BVH")
ray_origin, ray_direction = prep_rays(ray_origin, ray_direction, tnear, tfar)

coords, tri_ids, distances = _bvh_bind_ext.intersect_bvh(
self._bvh, ray_origin, ray_direction, tnear, tfar
)

return MeshRayResults(coords, tri_ids, distances)
return IntersectionResult(coords, tri_ids, distances)

def occlusion(
self,
Expand Down
2 changes: 2 additions & 0 deletions src/pyraymesh/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .Mesh import Mesh

__version__ = "0.1.1"
4 changes: 4 additions & 0 deletions tests/test_basic_mesh_ray_intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def test_import_Mesh():
assert m is not None
assert isinstance(m, Mesh)

def test_empty_mesh():
m = Mesh([], [])
with pytest.raises(ValueError):
m.build("medium")

def test_build_low_bvh():
m = mesh_plane()
Expand Down

0 comments on commit 3b5cf70

Please sign in to comment.