UV Mapping for Destructable Walls

This commit is contained in:
Relicjamin
2026-01-03 13:06:22 -05:00
committed by Collin Campbell
parent 933bd98a4f
commit 5a1c02aa15
70 changed files with 1762 additions and 1305 deletions

View File

@@ -11,7 +11,9 @@ enum ExtrudeDirection {
@export var verts2d: PackedVector2Array
@export var meshInstance3d: MeshInstance3D
@export var depth: float = 0.1
@export var depth_position_offset: Vector3 = Vector3.ZERO
@export var original_vertices = PackedVector3Array()
@export var original_normals = PackedVector3Array()
@export var original_uvs = PackedVector2Array()
@export_category("TrechBroom User Values")
@export var extrusion_direction: ExtrudeDirection
@export var hole_proximity: float
@@ -28,7 +30,6 @@ var static_body: StaticBody3D
func _ready() -> void:
if Engine.is_editor_hint():
return
parentNode = get_node("..")
inner_polygons = Holes.new()
inner_rtree = RectangleTree.new()
@@ -43,6 +44,9 @@ func _exit_tree() -> void:
func _func_godot_apply_properties(entity_properties: Dictionary) -> void:
meshInstance3d = _find_mesh_body()
var verticies = meshInstance3d.mesh.surface_get_arrays(0)[Mesh.ARRAY_VERTEX]
original_vertices = self.get_meta("func_godot_mesh_data")["vertices"]
original_normals = self.get_meta("func_godot_mesh_data")["normals"]
original_uvs = self.get_meta("func_godot_mesh_data")["uvs"]
extrusion_direction = entity_properties["extrude_direction"]
hole_proximity = entity_properties["hole_proximity"]
@@ -63,8 +67,6 @@ func _func_godot_apply_properties(entity_properties: Dictionary) -> void:
elif d < depth_min:
depth_min = d
depth = -(abs(depth_min) + abs(depth_max))
depth_position_offset = Vector3.BACK * (depth/2)
elif extrusion_direction == ExtrudeDirection.RIGHT:
for vert in verticies:
verts_2d.append(Vector2(vert.z, vert.y))
@@ -76,8 +78,6 @@ func _func_godot_apply_properties(entity_properties: Dictionary) -> void:
elif d < depth_min:
depth_min = d
depth = -(abs(depth_min) + abs(depth_max))
depth_position_offset = Vector3.RIGHT * (depth/2)
elif extrusion_direction == ExtrudeDirection.UP:
for vert in verticies:
verts_2d.append(Vector2(vert.x, vert.z))
@@ -89,8 +89,6 @@ func _func_godot_apply_properties(entity_properties: Dictionary) -> void:
elif d < depth_min:
depth_min = d
depth = -(abs(depth_min) + abs(depth_max))
depth_position_offset = Vector3.UP * (depth/2)
var outer_boudary = Geometry2D.convex_hull(verts_2d)
verts2d = outer_boudary
@@ -102,12 +100,11 @@ func _draw():
vectors.append_array(outer_polygon)
vectors.append_array(inner_polygons.get_hole_verticies())
var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors, extrusion_direction, depth)
var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors, extrusion_direction, original_vertices, original_uvs, original_normals, depth)
var commited_mesh = meshGenerator.commit_mesh(meshInstance3d.get_active_material(0))
meshGenerator.free()
meshInstance3d.mesh = commited_mesh
meshInstance3d.position += depth_position_offset
meshInstance3d.create_trimesh_collision()
static_body = _find_static_body()
@@ -131,7 +128,7 @@ func _deffered_draw(mesh: Mesh, task_id: int):
static_body = _find_static_body()
func _generate_mesh(vector_indexes: PackedInt32Array, vectors: PackedVector2Array):
var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors, extrusion_direction, depth)
var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors, extrusion_direction, original_vertices, original_uvs, original_normals, depth)
var commited_mesh = meshGenerator.commit_mesh(meshInstance3d.get_active_material(0))
meshGenerator.free()