Anchor beetles to generated tree surfaces
This commit is contained in:
parent
f1c952f5d6
commit
5ed4cccf76
18 changed files with 446 additions and 71 deletions
|
|
@ -1131,49 +1131,36 @@ func _validate_tree_gatherable_anchors(
|
|||
decorations: Node3D,
|
||||
anchors: GatherableAnchorSet3D,
|
||||
) -> void:
|
||||
var eligible_props: Array[Node3D] = []
|
||||
var eligible_props: Dictionary[StringName, Node3D] = {}
|
||||
for child: Node in decorations.get_children():
|
||||
var prop := child as Node3D
|
||||
if prop == null:
|
||||
continue
|
||||
var prop_id := StringName(prop.get_meta(&"terrain_prop_id", &""))
|
||||
var definition := region.get_prop_catalog().definition_for_id(prop_id)
|
||||
if definition != null and definition.gatherable_anchor_height > 0.0:
|
||||
eligible_props.append(prop)
|
||||
if definition != null and definition.has_gatherable_surface():
|
||||
eligible_props[prop.name] = prop
|
||||
var positions := anchors.get_spawn_positions()
|
||||
assert(positions.size() == eligible_props.size())
|
||||
for prop: Node3D in eligible_props:
|
||||
assert(positions.size() >= 12)
|
||||
for child: Node in anchors.get_children():
|
||||
var anchor := child as Marker3D
|
||||
assert(anchor != null)
|
||||
assert(bool(anchor.get_meta(&"mesh_surface_sampled", false)))
|
||||
var prop_name := StringName(anchor.get_meta(&"terrain_prop_name", &""))
|
||||
assert(eligible_props.has(prop_name))
|
||||
var prop: Node3D = eligible_props[prop_name]
|
||||
var prop_id := StringName(prop.get_meta(&"terrain_prop_id", &""))
|
||||
var definition := region.get_prop_catalog().definition_for_id(prop_id)
|
||||
var visual_scale := float(
|
||||
prop.get_meta(&"terrain_prop_visual_scale", 1.0)
|
||||
)
|
||||
var nearest_anchor := Vector3(INF, INF, INF)
|
||||
var nearest_distance_squared := INF
|
||||
for position: Vector3 in positions:
|
||||
var distance_squared := position.distance_squared_to(
|
||||
prop.global_position
|
||||
)
|
||||
if distance_squared < nearest_distance_squared:
|
||||
nearest_distance_squared = distance_squared
|
||||
nearest_anchor = position
|
||||
assert(nearest_anchor.is_finite())
|
||||
var horizontal_distance := Vector2(
|
||||
nearest_anchor.x - prop.global_position.x,
|
||||
nearest_anchor.z - prop.global_position.z,
|
||||
).length()
|
||||
assert(definition != null and definition.has_gatherable_surface())
|
||||
var local_anchor := prop.to_local(anchor.global_position)
|
||||
assert(
|
||||
horizontal_distance
|
||||
>= definition.gatherable_anchor_surface_radius() * visual_scale
|
||||
local_anchor.y
|
||||
>= definition.gatherable_surface_minimum_height - 0.001
|
||||
)
|
||||
assert(
|
||||
absf(
|
||||
nearest_anchor.y
|
||||
- (
|
||||
prop.global_position.y
|
||||
+ definition.gatherable_anchor_height * visual_scale
|
||||
)
|
||||
) <= 0.001
|
||||
local_anchor.y
|
||||
<= definition.gatherable_surface_maximum_height + 0.001
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue