Spaces:
Sleeping
Sleeping
Stephen commited on
Commit ·
b51d036
1
Parent(s): 7805e3b
re-add scaling
Browse files- sdf_export.py +19 -0
sdf_export.py
CHANGED
|
@@ -12,6 +12,25 @@ def mesh_to_sdf_glsl(path, resolution=32):
|
|
| 12 |
print(f" Bounds: {mesh.bounds}")
|
| 13 |
print(f" Extents: {mesh.extents}")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Convert vertices and faces to the correct types
|
| 16 |
vertices = mesh.vertices.astype(np.float32)
|
| 17 |
faces = mesh.faces.astype(np.uint32)
|
|
|
|
| 12 |
print(f" Bounds: {mesh.bounds}")
|
| 13 |
print(f" Extents: {mesh.extents}")
|
| 14 |
|
| 15 |
+
# Center the mesh
|
| 16 |
+
bounds = mesh.bounds
|
| 17 |
+
center = (bounds[0] + bounds[1]) / 2.0
|
| 18 |
+
mesh.vertices -= center
|
| 19 |
+
print(f"\nAfter centering:")
|
| 20 |
+
print(f" Center: {center}")
|
| 21 |
+
print(f" Bounds: {mesh.bounds}")
|
| 22 |
+
print(f" Extents: {mesh.extents}")
|
| 23 |
+
|
| 24 |
+
# Scale the mesh to fit in a reasonable size for SDF computation
|
| 25 |
+
max_extent = np.max(mesh.extents)
|
| 26 |
+
scale = 1.0 / max_extent
|
| 27 |
+
mesh.vertices *= scale
|
| 28 |
+
print(f"\nAfter scaling:")
|
| 29 |
+
print(f" Scale factor: {scale}")
|
| 30 |
+
print(f" Bounds: {mesh.bounds}")
|
| 31 |
+
print(f" Extents: {mesh.extents}")
|
| 32 |
+
print(f" Vertex range: [{np.min(mesh.vertices)}, {np.max(mesh.vertices)}]")
|
| 33 |
+
|
| 34 |
# Convert vertices and faces to the correct types
|
| 35 |
vertices = mesh.vertices.astype(np.float32)
|
| 36 |
faces = mesh.faces.astype(np.uint32)
|