Skip to content

Commit

Permalink
Add Convex Hull mesh decimation (#20)
Browse files Browse the repository at this point in the history
* feature: bump version to 1.3.5 and add max_hull_vertices parameter to convex_decomposition function

* fix: Set numpy ==1.23.5 to avoid issues with numpy 2.0.0 release

* Fix issue with multiple testpypi version conflicts
  • Loading branch information
aelmiger committed Jul 17, 2024
1 parent b0107f3 commit f4742fd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy_to_pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip_existing: true
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"
requires-python = ">=3.8"
license = {text = "GPLv3"}

version = "1.3.4"
version = "1.3.5"

dynamic = ["dependencies"]

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ filelock==3.9.0
GitPython==3.1.29
jsonschema==4.17.3
opencv-python==4.6.0.66
numpy==1.23.5
Pillow==9.4.0
PyYAML==6.0.1
requests==2.27.1
Expand Down
12 changes: 11 additions & 1 deletion syclops/utility/blender_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,15 @@ def convex_decomposition(
obj_pointer: ObjPointer,
conv_hull_collection_pointer: ObjPointer,
quality: float = 90,
max_hull_vertices: int = 100,
) -> List[bpy.types.Object]:
"""Decompose an object into convex hulls for physics simulation.
Args:
obj_pointer (ObjPointer): Pointer to object to decompose.
conv_hull_collection_pointer (ObjPointer): Pointer to collection to store convex hulls in.
quality (float, optional): Quality of the convex decomposition. Defaults to 90.
max_hull_vertices (int, optional): Maximum number of vertices in a convex hull. Defaults to 256.
Returns:
list[bpy.types.Object]: List of convex hulls.
"""
Expand Down Expand Up @@ -436,6 +437,15 @@ def convex_decomposition(
# Create the mesh data
mesh.from_pydata(convex_hull[0], [], convex_hull[1])

# Num vertices of mesh
num_vertices = len(mesh.vertices)
if num_vertices > max_hull_vertices:
decimate_factor = max_hull_vertices / num_vertices

# Decimate the mesh if it has too many vertices
decimate_mesh(convex_obj, decimate_factor)


# Update the mesh and object
mesh.update()
convex_obj.select_set(True)
Expand Down

0 comments on commit f4742fd

Please sign in to comment.