This commit is contained in:
Guillaume Vern
2025-10-10 15:46:35 +02:00
parent 80a4c128cc
commit a2385360db
225 changed files with 5490 additions and 314 deletions
+85
View File
@@ -16,6 +16,9 @@ extends XRToolsSceneBase
## This property specifies the persistent zone information
@export var zone_info : PersistentZoneInfo
signal numberOfFiresSignal(number: int)
var numberOfFires = 0;
# Add support for is_xr_class
func is_xr_class(p_name : String) -> bool:
@@ -24,6 +27,11 @@ func is_xr_class(p_name : String) -> bool:
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var fire_scene = preload("res://assets/fire/fire.tscn")
var ground = $World/Ground/MeshInstance3D
for i in range(30):
spawn_on_surface(ground, fire_scene)
numberOfFiresSignal.emit(numberOfFires)
# call the base
super()
@@ -219,6 +227,83 @@ static func is_item_held_by_zone(node : Node) -> bool:
push_warning("Item ", node.item_id, " held by non-persistent ", node.get_picked_up_by())
return true
func spawn_on_surface(target_mesh_instance: MeshInstance3D, scene_to_spawn: PackedScene):
var original_mesh = target_mesh_instance.mesh
if original_mesh == null:
print("Mesh is missing.")
return
var mesh : ArrayMesh
# Handle QuadMesh or other primitive Meshes
if original_mesh is PrimitiveMesh:
mesh = ArrayMesh.new()
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, original_mesh.get_mesh_arrays())
elif original_mesh is ArrayMesh:
mesh = original_mesh
else:
print("Unsupported mesh type.")
return
# Get surface data (assuming surface 0)
if mesh.get_surface_count() == 0:
print("Mesh has no surfaces.")
return
var arrays = mesh.surface_get_arrays(0)
var vertices = arrays[Mesh.ARRAY_VERTEX]
var indices = arrays[Mesh.ARRAY_INDEX]
if vertices.is_empty() or indices.is_empty():
print("Mesh has no usable vertices or indices.")
return
# Try finding a face pointing mostly upwards
var found_point = false
var point = Vector3.ZERO
var max_attempts = 100 # prevent infinite loops
var attempts = 0
while not found_point and attempts < max_attempts:
attempts += 1
# Choose a random triangle
var tri_index = randi() % (indices.size() / 3)
var i0 = indices[tri_index * 3]
var i1 = indices[tri_index * 3 + 1]
var i2 = indices[tri_index * 3 + 2]
var a = vertices[i0]
var b = vertices[i1]
var c = vertices[i2]
# Calculate the face normal
var normal = ((b - a).cross(c - a)).normalized()
# Check if face normal points mostly up (adjust threshold as needed)
if normal.dot(Vector3.UP) > 0.7:
# Get random point in triangle (barycentric coordinates)
var r1 = randf()
var r2 = randf()
if r1 + r2 >= 1.0:
r1 = 1.0 - r1
r2 = 1.0 - r2
point = a + (b - a) * r1 + (c - a) * r2
found_point = true
numberOfFires += 1
if not found_point:
print("No upward facing face found after", max_attempts, "attempts.")
return
# Transform to world space
point = target_mesh_instance.global_transform * point
# Instance and place your object
var new_object = scene_to_spawn.instantiate()
new_object.global_transform.origin = point
new_object.scale = Vector3(3.0, 3.0, 3.0)
get_tree().current_scene.add_child(new_object)
# This method returns the persistent item primarily held by the pickup
static func _get_held_persistent_item(pickup : XRToolsFunctionPickup) -> PersistentItem: