Skip to content

Commit 10219a4

Browse files
committed
Add experimental gret.merge
Boolean merge one or more objects, cleaning up the result for normal transfer
1 parent dad7953 commit 10219a4

File tree

3 files changed

+381
-3
lines changed

3 files changed

+381
-3
lines changed

math.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
from numpy.polynomial import polynomial as pl
44
import numpy as np
55

6+
SMALL_NUMBER = 1e-8
7+
KINDA_SMALL_NUMBER = 1e-4
8+
9+
saturate = lambda x: min(1.0, max(0.0, x))
10+
611
def calc_bounds(points):
712
xs, ys, zs = zip(*points)
813
x0, y0, z1, x1, y1, z1 = min(xs), min(ys), min(zs), max(xs), max(ys), max(zs)
@@ -29,17 +34,19 @@ def get_dist(a, b):
2934
"""Returns the distance between two vectors."""
3035
return sqrt(get_dist_sq(a, b))
3136

32-
def get_direction(a, b):
33-
"""Returns the direction from one 3D position to another."""
37+
def get_direction_safe(a, b):
38+
"""Returns the direction from one 3D position to another, or zero vector if they are too close."""
3439
x, y, z = b[0] - a[0], b[1] - a[1], b[2] - a[2]
3540
k = sqrt(x*x + y*y + z*z)
41+
if k <= SMALL_NUMBER:
42+
return Vector()
3643
return Vector((x/k, y/k, z/k))
3744

3845
def get_range_pct(min_value, max_value, value):
3946
"""Calculates the percentage along a line from min_value to max_value."""
4047

4148
divisor = max_value - min_value
42-
if divisor <= 0.0001:
49+
if divisor <= SMALL_NUMBER:
4350
return 1.0 if value >= max_value else 0.0
4451
return (value - min_value) / divisor
4552

mesh/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module_names = [
44
'helpers',
55
'graft', # So it appears at the top, fix this later
6+
'merge',
67
'collision',
78
'extra_objects',
89
'remove_unused_vertex_groups',

0 commit comments

Comments
 (0)