Now About Social Code
summaryrefslogtreecommitdiff
path: root/scripts/marching_cubes.gd
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2023-09-12 07:43:44 -0400
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2023-09-12 07:43:44 -0400
commit53210af9660d90774b981fe00b616ec53fb72f1b (patch)
tree95c64db1def1cebe998874234c4f81341412d8b6 /scripts/marching_cubes.gd
parent4f1c7a600bc3f5b6210b0b2a16c45d22c9fd5e15 (diff)
Try to smooth normals
Something still seems off
Diffstat (limited to 'scripts/marching_cubes.gd')
-rw-r--r--scripts/marching_cubes.gd16
1 files changed, 1 insertions, 15 deletions
diff --git a/scripts/marching_cubes.gd b/scripts/marching_cubes.gd
index 984f63d..6c5296c 100644
--- a/scripts/marching_cubes.gd
+++ b/scripts/marching_cubes.gd
@@ -12,7 +12,7 @@ class Cell:
position.resize(8)
value.resize(8)
-func march_cube(cell: Cell, triangles: PackedInt32Array, verticies: PackedVector3Array, normals: PackedVector3Array):
+func march_cube(cell: Cell, triangles: PackedInt32Array, verticies: PackedVector3Array):
var cube_index : int = 0
var vertex_list: Array[Vector3] = []
@@ -71,27 +71,13 @@ func march_cube(cell: Cell, triangles: PackedInt32Array, verticies: PackedVector
var vert = new_vertex_list[i]
verticies.push_back(vert)
- var normal_list: Array[Vector4] = []
- normal_list.resize(new_vertex_count)
- normal_list.fill(Vector4(0,0,0,0))
tri_index = 0
while mc._tri_table[cube_index][tri_index] != -1:
- var p1: Vector3 = new_vertex_list[local_remap[mc._tri_table[cube_index][tri_index + 0]]]
- var p2: Vector3 = new_vertex_list[local_remap[mc._tri_table[cube_index][tri_index + 1]]]
- var p3: Vector3 = new_vertex_list[local_remap[mc._tri_table[cube_index][tri_index + 2]]]
- var normal = (p2 - p1).cross(p3 - p1).normalized();
- var normal_4 = Vector4(normal.x, normal.y, normal.z, 1)
- normal_list[local_remap[mc._tri_table[cube_index][tri_index + 0]]] += normal_4
- normal_list[local_remap[mc._tri_table[cube_index][tri_index + 1]]] += normal_4
- normal_list[local_remap[mc._tri_table[cube_index][tri_index + 2]]] += normal_4
triangles.push_back(local_remap[mc._tri_table[cube_index][tri_index + 0]] + starting_vertex_count)
triangles.push_back(local_remap[mc._tri_table[cube_index][tri_index + 1]] + starting_vertex_count)
triangles.push_back(local_remap[mc._tri_table[cube_index][tri_index + 2]] + starting_vertex_count)
tri_index += 3
- for normal in normal_list:
- var new_normal = Vector3(normal.x, normal.y, normal.z) / normal.w
- normals.push_back(new_normal.normalized())
func vertex_interpolate(p1: Vector3, p2: Vector3, val1: float, val2: float):
return (p1 + (-val1 / (val2 - val1)) * (p2 - p1))