Group Holes with Hull Convex
This commit is contained in:
@@ -10,10 +10,11 @@ enum ExtrudeDirection {
|
||||
@export_category("TrechBroom Generated Values")
|
||||
@export var verts2d: PackedVector2Array
|
||||
@export var meshInstance3d: MeshInstance3D
|
||||
@export var extrusion_direction: ExtrudeDirection
|
||||
@export var depth: float = 0.1
|
||||
@export var depth_position_offset: Vector3 = Vector3.ZERO
|
||||
@export_category("User Defined Values")
|
||||
@export_category("TrechBroom User Values")
|
||||
@export var extrusion_direction: ExtrudeDirection
|
||||
@export var hole_proximity: float
|
||||
@export var edge_non_fracture: float = 0.1
|
||||
|
||||
var parentNode
|
||||
@@ -44,6 +45,8 @@ func _func_godot_apply_properties(entity_properties: Dictionary) -> void:
|
||||
var verticies = meshInstance3d.mesh.surface_get_arrays(0)[Mesh.ARRAY_VERTEX]
|
||||
|
||||
extrusion_direction = entity_properties["extrude_direction"]
|
||||
hole_proximity = entity_properties["hole_proximity"]
|
||||
edge_non_fracture = entity_properties["edge_non_fractured"]
|
||||
|
||||
var depth_min: float
|
||||
var depth_max: float
|
||||
@@ -192,6 +195,24 @@ func _add_hole(new_hole: PackedVector2Array) -> bool:
|
||||
var bound_rect = UTIL.get_bounding_rect(merged)
|
||||
inner_rtree.add(bound_rect.position, bound_rect.end, hole.hole_id)
|
||||
|
||||
var hole_prox_boundary = bound_rect.grow(hole.area * 4)
|
||||
var prox_holes_ids = inner_rtree.query_rect(hole_prox_boundary.position, hole_prox_boundary.end)
|
||||
|
||||
# any holes that are close in proximity convex hull
|
||||
if len(prox_holes_ids) <= 1: # needs to be length 2 or more because it will always return the hole just created
|
||||
return true
|
||||
|
||||
var proxmity_hole_vectors = []
|
||||
for id in prox_holes_ids:
|
||||
proxmity_hole_vectors.append_array(inner_polygons.get_hole(id).vectors)
|
||||
inner_rtree.remove(id)
|
||||
inner_polygons.remove_hole(id)
|
||||
|
||||
var convex_vectors = Geometry2D.convex_hull(proxmity_hole_vectors)
|
||||
hole = inner_polygons.add_hole(convex_vectors)
|
||||
bound_rect = UTIL.get_bounding_rect(convex_vectors)
|
||||
inner_rtree.add(bound_rect.position, bound_rect.end, hole.hole_id)
|
||||
|
||||
return true
|
||||
|
||||
func _find_static_body():
|
||||
|
||||
Reference in New Issue
Block a user