Stephen commited on
Commit
eb4d6e4
·
1 Parent(s): 85773e1

try use 0..1 range

Browse files
Files changed (1) hide show
  1. sdf_export.py +6 -4
sdf_export.py CHANGED
@@ -28,10 +28,12 @@ def mesh_to_sdf_glsl(path, resolution=32):
28
  print(f" Per-dimension extents: {extents}")
29
  print(f" Max extent: {max_extent}")
30
 
31
- # Scale to fit in [-1, 1] cube while preserving aspect ratio
32
  scale = 0.9 / max_extent
33
  mesh.vertices *= scale
34
- print(f"\nAfter scaling:")
 
 
35
  print(f" Scale factor: {scale}")
36
  print(f" Bounds: {mesh.bounds}")
37
  print(f" Extents: {mesh.extents}")
@@ -103,9 +105,9 @@ float sdfData{i}[{len(chunks[i].split(','))}] = float[](
103
  # Add the SDF function that combines chunks
104
  glsl_code += f"""
105
  float SDF(vec3 p) {{
106
- // Map from [-1,1] to [0,resolution-1]
107
  vec3 dim = vec3({resolution}.0);
108
- vec3 uv = (p + 1.0) * 0.5 * (dim - 1.0);
109
 
110
  // Add a small offset to avoid boundary issues
111
  uv = clamp(uv, vec3(0.0), dim - 1.0);
 
28
  print(f" Per-dimension extents: {extents}")
29
  print(f" Max extent: {max_extent}")
30
 
31
+ # Scale to fit in [0, 1] cube while preserving aspect ratio
32
  scale = 0.9 / max_extent
33
  mesh.vertices *= scale
34
+ # Shift to [0, 1] space
35
+ mesh.vertices += 0.5
36
+ print(f"\nAfter scaling and shifting:")
37
  print(f" Scale factor: {scale}")
38
  print(f" Bounds: {mesh.bounds}")
39
  print(f" Extents: {mesh.extents}")
 
105
  # Add the SDF function that combines chunks
106
  glsl_code += f"""
107
  float SDF(vec3 p) {{
108
+ // Map from [0,1] to [0,resolution-1]
109
  vec3 dim = vec3({resolution}.0);
110
+ vec3 uv = p * (dim - 1.0);
111
 
112
  // Add a small offset to avoid boundary issues
113
  uv = clamp(uv, vec3(0.0), dim - 1.0);