mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 23:10:08 +01:00
Use static typing in all demos (#1063)
This leads to code that is easier to understand and runs faster thanks to GDScript's typed instructions. The untyped declaration warning is now enabled on all projects where type hints were added. All projects currently run without any untyped declration warnings. Dodge the Creeps and Squash the Creeps demos intentionally don't use type hints to match the documentation, where type hints haven't been adopted yet (given its beginner focus).
This commit is contained in:
@@ -47,10 +47,12 @@ anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 10.0
|
||||
offset_top = -19.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = -5.0
|
||||
offset_top = -36.0
|
||||
offset_right = 55.0
|
||||
offset_bottom = -13.0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 4
|
||||
text = "FPS: 0"
|
||||
script = ExtResource("1")
|
||||
|
||||
@@ -60,10 +62,12 @@ anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 10.0
|
||||
offset_top = -39.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = -25.0
|
||||
offset_top = -64.0
|
||||
offset_right = 128.0
|
||||
offset_bottom = -41.0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 4
|
||||
text = "Physics engine:"
|
||||
script = ExtResource("3")
|
||||
|
||||
@@ -73,10 +77,12 @@ anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 10.0
|
||||
offset_top = -59.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = -45.0
|
||||
offset_top = -92.0
|
||||
offset_right = 125.0
|
||||
offset_bottom = -69.0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 4
|
||||
text = "Godot Version:"
|
||||
script = ExtResource("2")
|
||||
|
||||
@@ -86,10 +92,12 @@ anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 10.0
|
||||
offset_top = -79.0
|
||||
offset_top = -120.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = -65.0
|
||||
offset_bottom = -97.0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 4
|
||||
text = "Test:"
|
||||
script = ExtResource("5")
|
||||
|
||||
|
||||
@@ -21,6 +21,10 @@ config/icon="res://icon.webp"
|
||||
Log="*res://utils/system_log.gd"
|
||||
System="*res://utils/system.gd"
|
||||
|
||||
[debug]
|
||||
|
||||
gdscript/warnings/untyped_declaration=1
|
||||
|
||||
[display]
|
||||
|
||||
window/stretch/mode="canvas_items"
|
||||
@@ -51,7 +55,7 @@ toggle_full_screen={
|
||||
}
|
||||
exit={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":16777217,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
toggle_debug_collision={
|
||||
@@ -71,19 +75,20 @@ toggle_pause={
|
||||
}
|
||||
character_right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":16777233,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":68,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
character_left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":16777231,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":65,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":113,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
character_jump={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":16777232,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":87,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":122,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,41 +1,39 @@
|
||||
class_name Test
|
||||
extends Node
|
||||
|
||||
|
||||
signal wait_done()
|
||||
|
||||
@export var _enable_debug_collision = true
|
||||
@export var _enable_debug_collision := true
|
||||
|
||||
var _timer
|
||||
var _timer_started = false
|
||||
var _timer: Timer
|
||||
var _timer_started := false
|
||||
|
||||
var _wait_physics_ticks_counter = 0
|
||||
var _wait_physics_ticks_counter := 0
|
||||
|
||||
var _drawn_nodes = []
|
||||
var _drawn_nodes: Array[Node3D] = []
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
func _enter_tree() -> void:
|
||||
if not _enable_debug_collision:
|
||||
get_tree().debug_collisions_hint = false
|
||||
|
||||
|
||||
func _physics_process(_delta):
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if _wait_physics_ticks_counter > 0:
|
||||
_wait_physics_ticks_counter -= 1
|
||||
if _wait_physics_ticks_counter == 0:
|
||||
wait_done.emit()
|
||||
|
||||
|
||||
func add_sphere(pos, radius, color):
|
||||
var sphere = MeshInstance3D.new()
|
||||
func add_sphere(pos: Vector3, radius: float, color: Color) -> void:
|
||||
var sphere := MeshInstance3D.new()
|
||||
|
||||
var sphere_mesh = SphereMesh.new()
|
||||
var sphere_mesh := SphereMesh.new()
|
||||
sphere_mesh.radius = radius
|
||||
sphere_mesh.height = radius * 2.0
|
||||
sphere.mesh = sphere_mesh
|
||||
|
||||
var material = StandardMaterial3D.new()
|
||||
material.flags_unshaded = true
|
||||
var material := StandardMaterial3D.new()
|
||||
material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
material.albedo_color = color
|
||||
sphere.set_surface_override_material(0, material)
|
||||
|
||||
@@ -45,14 +43,14 @@ func add_sphere(pos, radius, color):
|
||||
sphere.global_transform.origin = pos
|
||||
|
||||
|
||||
func add_shape(shape, transform, color):
|
||||
var debug_mesh = shape.get_debug_mesh()
|
||||
func add_shape(shape: Shape3D, transform: Transform3D, color: Color) -> void:
|
||||
var debug_mesh := shape.get_debug_mesh()
|
||||
|
||||
var mesh_instance = MeshInstance3D.new()
|
||||
var mesh_instance := MeshInstance3D.new()
|
||||
mesh_instance.transform = transform
|
||||
mesh_instance.mesh = debug_mesh
|
||||
|
||||
var material = StandardMaterial3D.new()
|
||||
var material := StandardMaterial3D.new()
|
||||
material.flags_unshaded = true
|
||||
material.albedo_color = color
|
||||
mesh_instance.set_surface_override_material(0, material)
|
||||
@@ -61,36 +59,37 @@ func add_shape(shape, transform, color):
|
||||
_drawn_nodes.push_back(mesh_instance)
|
||||
|
||||
|
||||
func clear_drawn_nodes():
|
||||
func clear_drawn_nodes() -> void:
|
||||
for node in _drawn_nodes:
|
||||
remove_child(node)
|
||||
node.queue_free()
|
||||
|
||||
_drawn_nodes.clear()
|
||||
|
||||
|
||||
func create_rigidbody(shape, pickable = false, transform = Transform3D.IDENTITY):
|
||||
var collision = CollisionShape3D.new()
|
||||
func create_rigidbody(shape: Shape3D, pickable: bool = false, transform: Transform3D = Transform3D.IDENTITY) -> RigidBody3D:
|
||||
var collision := CollisionShape3D.new()
|
||||
collision.shape = shape
|
||||
collision.transform = transform
|
||||
|
||||
var body = RigidBody3D.new()
|
||||
var body := RigidBody3D.new()
|
||||
body.add_child(collision)
|
||||
|
||||
if pickable:
|
||||
var script = load("res://utils/rigidbody_pick.gd")
|
||||
var script := load("res://utils/rigidbody_pick.gd")
|
||||
body.set_script(script)
|
||||
|
||||
return body
|
||||
|
||||
|
||||
func create_rigidbody_box(size, pickable = false, transform = Transform3D.IDENTITY):
|
||||
var shape = BoxShape3D.new()
|
||||
func create_rigidbody_box(size: Vector3, pickable: bool = false, transform: Transform3D = Transform3D.IDENTITY) -> RigidBody3D:
|
||||
var shape := BoxShape3D.new()
|
||||
shape.size = size
|
||||
|
||||
return create_rigidbody(shape, pickable, transform)
|
||||
|
||||
|
||||
func start_timer(timeout):
|
||||
func start_timer(timeout: float) -> Timer:
|
||||
if _timer == null:
|
||||
_timer = Timer.new()
|
||||
_timer.one_shot = true
|
||||
@@ -105,21 +104,21 @@ func start_timer(timeout):
|
||||
return _timer
|
||||
|
||||
|
||||
func cancel_timer():
|
||||
func cancel_timer() -> void:
|
||||
if _timer_started:
|
||||
_timer.paused = true
|
||||
_timer.timeout.emit()
|
||||
_timer.paused = false
|
||||
|
||||
|
||||
func is_timer_canceled():
|
||||
func is_timer_canceled() -> bool:
|
||||
return _timer.paused
|
||||
|
||||
|
||||
func wait_for_physics_ticks(tick_count):
|
||||
func wait_for_physics_ticks(tick_count: int) -> Test:
|
||||
_wait_physics_ticks_counter = tick_count
|
||||
return self
|
||||
|
||||
|
||||
func _on_timer_done():
|
||||
func _on_timer_done() -> void:
|
||||
_timer_started = false
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
extends Node
|
||||
|
||||
|
||||
var _tests = [
|
||||
var _tests: Array[Dictionary] = [
|
||||
{
|
||||
"id": "Functional Tests/Shapes",
|
||||
"path": "res://tests/functional/test_shapes.tscn",
|
||||
@@ -61,7 +60,7 @@ var _tests = [
|
||||
]
|
||||
|
||||
|
||||
func _ready():
|
||||
var test_menu = $TestsMenu
|
||||
func _ready() -> void:
|
||||
var test_menu: OptionMenu = $TestsMenu
|
||||
for test in _tests:
|
||||
test_menu.add_test(test.id, test.path)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
extends Test
|
||||
|
||||
|
||||
const OPTION_TYPE_BOX = "Collision type/Box (1)"
|
||||
const OPTION_TYPE_SPHERE = "Collision type/Sphere (2)"
|
||||
const OPTION_TYPE_CAPSULE = "Collision type/Capsule (3)"
|
||||
@@ -16,15 +15,13 @@ const OPTION_SHAPE_CONCAVE_POLYGON = "Shape type/Concave Polygon"
|
||||
|
||||
const OFFSET_RANGE = 3.0
|
||||
|
||||
@export var offset = Vector3.ZERO
|
||||
@export var offset := Vector3.ZERO
|
||||
|
||||
var _update_collision = false
|
||||
var _collision_test_index = 0
|
||||
var _current_offset = Vector3.ZERO
|
||||
var _collision_shapes = []
|
||||
var _update_collision := false
|
||||
var _collision_test_index := 0
|
||||
var _collision_shapes: Array[Shape3D] = []
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
_initialize_collision_shapes()
|
||||
|
||||
$Options.add_menu_item(OPTION_TYPE_BOX)
|
||||
@@ -50,22 +47,21 @@ func _ready():
|
||||
_update_collision = true
|
||||
|
||||
|
||||
func _input(event):
|
||||
var key_event = event as InputEventKey
|
||||
if key_event and not key_event.pressed:
|
||||
if key_event.keycode == KEY_1:
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and event.pressed:
|
||||
if event.keycode == KEY_1:
|
||||
_on_option_selected(OPTION_TYPE_BOX)
|
||||
elif key_event.keycode == KEY_2:
|
||||
elif event.keycode == KEY_2:
|
||||
_on_option_selected(OPTION_TYPE_SPHERE)
|
||||
elif key_event.keycode == KEY_3:
|
||||
elif event.keycode == KEY_3:
|
||||
_on_option_selected(OPTION_TYPE_CAPSULE)
|
||||
elif key_event.keycode == KEY_4:
|
||||
elif event.keycode == KEY_4:
|
||||
_on_option_selected(OPTION_TYPE_CYLINDER)
|
||||
elif key_event.keycode == KEY_5:
|
||||
elif event.keycode == KEY_5:
|
||||
_on_option_selected(OPTION_TYPE_CONVEX_POLYGON)
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
func _physics_process(delta: float) -> void:
|
||||
super._physics_process(delta)
|
||||
|
||||
if not _update_collision:
|
||||
@@ -76,71 +72,69 @@ func _physics_process(delta):
|
||||
_do_collision_test()
|
||||
|
||||
|
||||
func set_x_offset(value):
|
||||
func set_x_offset(value: float) -> void:
|
||||
offset.x = value * OFFSET_RANGE
|
||||
_update_collision = true
|
||||
|
||||
|
||||
func set_y_offset(value):
|
||||
func set_y_offset(value: float) -> void:
|
||||
offset.y = value * OFFSET_RANGE
|
||||
_update_collision = true
|
||||
|
||||
|
||||
func set_z_offset(value):
|
||||
func set_z_offset(value: float) -> void:
|
||||
offset.z = value * OFFSET_RANGE
|
||||
_update_collision = true
|
||||
|
||||
|
||||
func _initialize_collision_shapes():
|
||||
func _initialize_collision_shapes() -> void:
|
||||
_collision_shapes.clear()
|
||||
|
||||
for node in $Shapes.get_children():
|
||||
var body = node as PhysicsBody3D
|
||||
var shape = body.shape_owner_get_shape(0, 0)
|
||||
var body: PhysicsBody3D = node
|
||||
var shape: Shape3D = body.shape_owner_get_shape(0, 0)
|
||||
shape.resource_name = String(node.name).substr("RigidBody".length())
|
||||
|
||||
_collision_shapes.push_back(shape)
|
||||
|
||||
|
||||
func _do_collision_test():
|
||||
func _do_collision_test() -> void:
|
||||
clear_drawn_nodes()
|
||||
|
||||
var shape = _collision_shapes[_collision_test_index]
|
||||
var shape: Shape3D = _collision_shapes[_collision_test_index]
|
||||
|
||||
Log.print_log("* Start %s collision tests..." % shape.resource_name)
|
||||
|
||||
var shape_query = PhysicsShapeQueryParameters3D.new()
|
||||
var shape_query := PhysicsShapeQueryParameters3D.new()
|
||||
shape_query.set_shape(shape)
|
||||
var shape_scale = Vector3(0.5, 0.5, 0.5)
|
||||
var shape_scale := Vector3(0.5, 0.5, 0.5)
|
||||
shape_query.transform = Transform3D.IDENTITY.scaled(shape_scale)
|
||||
|
||||
for node in $Shapes.get_children():
|
||||
if not node.visible:
|
||||
continue
|
||||
|
||||
var body = node as PhysicsBody3D
|
||||
var space_state = body.get_world_3d().direct_space_state
|
||||
var body: PhysicsBody3D = node
|
||||
var space_state := body.get_world_3d().direct_space_state
|
||||
|
||||
Log.print_log("* Testing: %s" % body.name)
|
||||
|
||||
var center = body.global_transform.origin
|
||||
var center := body.global_transform.origin
|
||||
|
||||
# Collision at the center inside.
|
||||
var res = _add_collision(space_state, center, shape, shape_query)
|
||||
var res := _add_collision(space_state, center, shape, shape_query)
|
||||
Log.print_log("Collision center inside: %s" % ("NO HIT" if res.is_empty() else "HIT"))
|
||||
|
||||
Log.print_log("* Done.")
|
||||
|
||||
|
||||
func _add_collision(space_state, pos, shape, shape_query):
|
||||
func _add_collision(space_state: PhysicsDirectSpaceState3D, pos: Vector3, shape: Shape3D, shape_query: PhysicsShapeQueryParameters3D) -> Array[Vector3]:
|
||||
shape_query.transform.origin = pos + offset
|
||||
var results = space_state.collide_shape(shape_query)
|
||||
var results := space_state.collide_shape(shape_query)
|
||||
|
||||
var color
|
||||
var color := Color.GREEN
|
||||
if results.is_empty():
|
||||
color = Color.WHITE.darkened(0.5)
|
||||
else:
|
||||
color = Color.GREEN
|
||||
|
||||
# Draw collision query shape.
|
||||
add_shape(shape, shape_query.transform, color)
|
||||
@@ -152,7 +146,7 @@ func _add_collision(space_state, pos, shape, shape_query):
|
||||
return results
|
||||
|
||||
|
||||
func _on_option_selected(option):
|
||||
func _on_option_selected(option: String) -> void:
|
||||
match option:
|
||||
OPTION_TYPE_BOX:
|
||||
_collision_test_index = _find_type_index("Box")
|
||||
@@ -171,9 +165,9 @@ func _on_option_selected(option):
|
||||
_update_collision = true
|
||||
|
||||
|
||||
func _find_type_index(type_name):
|
||||
for type_index in range(_collision_shapes.size()):
|
||||
var type_shape = _collision_shapes[type_index]
|
||||
func _find_type_index(type_name: String) -> int:
|
||||
for type_index in _collision_shapes.size():
|
||||
var type_shape := _collision_shapes[type_index]
|
||||
if type_shape.resource_name.find(type_name) > -1:
|
||||
return type_index
|
||||
|
||||
@@ -181,8 +175,8 @@ func _find_type_index(type_name):
|
||||
return -1
|
||||
|
||||
|
||||
func _on_option_changed(option, checked):
|
||||
var node
|
||||
func _on_option_changed(option: String, checked: bool) -> void:
|
||||
var node: RigidBody3D
|
||||
|
||||
match option:
|
||||
OPTION_SHAPE_BOX:
|
||||
@@ -204,8 +198,8 @@ func _on_option_changed(option, checked):
|
||||
_update_collision = true
|
||||
|
||||
|
||||
func _find_shape_node(type_name):
|
||||
var node = $Shapes.find_node("RigidBody%s" % type_name)
|
||||
func _find_shape_node(type_name: String) -> RigidBody3D:
|
||||
var node: RigidBody3D = $Shapes.find_child("RigidBody%s" % type_name)
|
||||
|
||||
if not node:
|
||||
Log.print_error("Invalid shape type: " + type_name)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
extends Test
|
||||
|
||||
|
||||
const OPTION_JOINT_TYPE = "Joint Type/%s Joint (%d)"
|
||||
|
||||
const OPTION_TEST_CASE_BODIES_COLLIDE = "Test case/Attached bodies collide"
|
||||
@@ -11,28 +10,27 @@ const OPTION_TEST_CASE_CHANGE_POSITIONS = "Test case/Set body positions after ad
|
||||
|
||||
const BOX_SIZE = Vector3(1.0, 1.0, 1.0)
|
||||
|
||||
var _update_joint = false
|
||||
var _selected_joint = null
|
||||
var _update_joint := false
|
||||
var _selected_joint: Joint3D
|
||||
|
||||
var _bodies_collide = false
|
||||
var _world_attachement = false
|
||||
var _dynamic_attachement = false
|
||||
var _destroy_body = false
|
||||
var _change_positions = false
|
||||
var _bodies_collide := false
|
||||
var _world_attachement := false
|
||||
var _dynamic_attachement := false
|
||||
var _destroy_body := false
|
||||
var _change_positions := false
|
||||
|
||||
var _joint_types = {}
|
||||
var _joint_types := {}
|
||||
|
||||
func _ready() -> void:
|
||||
var options: OptionMenu = $Options
|
||||
|
||||
func _ready():
|
||||
var options = $Options
|
||||
|
||||
var joints = $Joints
|
||||
var joints: Node3D = $Joints
|
||||
for joint_index in joints.get_child_count():
|
||||
var joint_node = joints.get_child(joint_index)
|
||||
var joint_node := joints.get_child(joint_index)
|
||||
joint_node.visible = false
|
||||
var joint_name = String(joint_node.name)
|
||||
var joint_short = joint_name.substr(0, joint_name.length() - 5)
|
||||
var option_name = OPTION_JOINT_TYPE % [joint_short, joint_index + 1]
|
||||
var joint_name := String(joint_node.name)
|
||||
var joint_short := joint_name.substr(0, joint_name.length() - 5)
|
||||
var option_name := OPTION_JOINT_TYPE % [joint_short, joint_index + 1]
|
||||
options.add_menu_item(option_name)
|
||||
_joint_types[option_name] = joint_node
|
||||
|
||||
@@ -49,29 +47,28 @@ func _ready():
|
||||
_update_joint = true
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float) -> void:
|
||||
if _update_joint:
|
||||
_update_joint = false
|
||||
await _create_joint()
|
||||
$LabelJointType.text = "Joint Type: " + String(_selected_joint.name)
|
||||
|
||||
|
||||
func _input(event):
|
||||
var key_event = event as InputEventKey
|
||||
if key_event and not key_event.pressed:
|
||||
var joint_index = key_event.keycode - KEY_1
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and event.pressed:
|
||||
var joint_index: int = event.keycode - KEY_1
|
||||
if joint_index >= 0 and joint_index < _joint_types.size():
|
||||
_selected_joint = _joint_types.values()[joint_index]
|
||||
_update_joint = true
|
||||
|
||||
|
||||
func _on_option_selected(option):
|
||||
func _on_option_selected(option: String) -> void:
|
||||
if _joint_types.has(option):
|
||||
_selected_joint = _joint_types[option]
|
||||
_update_joint = true
|
||||
|
||||
|
||||
func _on_option_changed(option, checked):
|
||||
func _on_option_changed(option: String, checked: bool) -> void:
|
||||
match option:
|
||||
OPTION_TEST_CASE_BODIES_COLLIDE:
|
||||
_bodies_collide = checked
|
||||
@@ -90,18 +87,18 @@ func _on_option_changed(option, checked):
|
||||
_update_joint = true
|
||||
|
||||
|
||||
func _create_joint():
|
||||
func _create_joint() -> void:
|
||||
cancel_timer()
|
||||
|
||||
var root = $Objects
|
||||
var root: Node3D = $Objects
|
||||
|
||||
while root.get_child_count():
|
||||
var last_child_index = root.get_child_count() - 1
|
||||
var last_child = root.get_child(last_child_index)
|
||||
var last_child_index := root.get_child_count() - 1
|
||||
var last_child := root.get_child(last_child_index)
|
||||
root.remove_child(last_child)
|
||||
last_child.queue_free()
|
||||
|
||||
var child_body = create_rigidbody_box(BOX_SIZE, true)
|
||||
var child_body := create_rigidbody_box(BOX_SIZE, true)
|
||||
if _change_positions:
|
||||
root.add_child(child_body)
|
||||
child_body.transform.origin = Vector3(0.0, -1.5, 0.0)
|
||||
@@ -109,7 +106,7 @@ func _create_joint():
|
||||
child_body.transform.origin = Vector3(0.0, -1.5, 0.0)
|
||||
root.add_child(child_body)
|
||||
|
||||
var parent_body = null
|
||||
var parent_body: RigidBody3D
|
||||
if not _world_attachement:
|
||||
parent_body = create_rigidbody_box(BOX_SIZE, true)
|
||||
if _dynamic_attachement:
|
||||
@@ -124,7 +121,7 @@ func _create_joint():
|
||||
parent_body.transform.origin = Vector3(0.0, 1.5, 0.0)
|
||||
root.add_child(parent_body)
|
||||
|
||||
var joint = _selected_joint.duplicate()
|
||||
var joint := _selected_joint.duplicate()
|
||||
joint.visible = true
|
||||
joint.set_exclude_nodes_from_collision(not _bodies_collide)
|
||||
root.add_child(joint)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
extends Test
|
||||
|
||||
|
||||
const OPTION_BODY_TYPE = "Body Type/%s (%d)"
|
||||
|
||||
const OPTION_SLOPE = "Physics options/Stop on slope (Character only)"
|
||||
@@ -15,29 +14,28 @@ const SHAPE_CYLINDER = "Collision shapes/Cylinder"
|
||||
const SHAPE_SPHERE = "Collision shapes/Sphere"
|
||||
const SHAPE_CONVEX = "Collision shapes/Convex"
|
||||
|
||||
var _slope = false
|
||||
var _snap = false
|
||||
var _friction = false
|
||||
var _rough = false
|
||||
var _animation_physics = false
|
||||
var _slope := false
|
||||
var _snap := false
|
||||
var _friction := false
|
||||
var _rough := false
|
||||
var _animation_physics := false
|
||||
|
||||
var _body_scene = {}
|
||||
var _key_list = []
|
||||
var _current_body_index = 0
|
||||
var _current_body_key = ""
|
||||
var _body_scene := {}
|
||||
var _key_list := []
|
||||
var _current_body_index := 0
|
||||
var _current_body_key := ""
|
||||
var _current_body: PhysicsBody3D = null
|
||||
var _body_type = ["CharacterBody3D", "RigidBody"]
|
||||
var _body_type := ["CharacterBody3D", "RigidBody"]
|
||||
|
||||
var _shapes = {}
|
||||
var _current_shape = ""
|
||||
var _shapes := {}
|
||||
var _current_shape := ""
|
||||
|
||||
|
||||
func _ready():
|
||||
var options = $Options
|
||||
var bodies = $Bodies.get_children()
|
||||
func _ready() -> void:
|
||||
var options: OptionMenu = $Options
|
||||
var bodies := $Bodies.get_children()
|
||||
for i in bodies.size():
|
||||
var body = bodies[i]
|
||||
var option_name = OPTION_BODY_TYPE % [body.name, i + 1]
|
||||
var body := bodies[i]
|
||||
var option_name := OPTION_BODY_TYPE % [body.name, i + 1]
|
||||
options.add_menu_item(option_name)
|
||||
_key_list.append(option_name)
|
||||
_body_scene[option_name] = get_packed_scene(body)
|
||||
@@ -68,15 +66,14 @@ func _ready():
|
||||
spawn_body_index(_current_body_index)
|
||||
|
||||
|
||||
func _input(event):
|
||||
var key_event = event as InputEventKey
|
||||
if key_event and not key_event.pressed:
|
||||
var _index = key_event.keycode - KEY_1
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and not event.pressed:
|
||||
var _index: int = event.keycode - KEY_1
|
||||
if _index >= 0 and _index < _key_list.size():
|
||||
spawn_body_index(_index)
|
||||
|
||||
|
||||
func _on_option_selected(option):
|
||||
func _on_option_selected(option: String) -> void:
|
||||
if _body_scene.has(option):
|
||||
spawn_body_key(option)
|
||||
else:
|
||||
@@ -98,7 +95,7 @@ func _on_option_selected(option):
|
||||
spawn_body_index(_current_body_index)
|
||||
|
||||
|
||||
func _on_option_changed(option, checked):
|
||||
func _on_option_changed(option: String, checked: bool) -> void:
|
||||
match option:
|
||||
OPTION_SLOPE:
|
||||
_slope = checked
|
||||
@@ -117,33 +114,33 @@ func _on_option_changed(option, checked):
|
||||
spawn_body_index(_current_body_index)
|
||||
|
||||
|
||||
func spawn_body_index(body_index):
|
||||
func spawn_body_index(body_index: int) -> void:
|
||||
if _current_body:
|
||||
_current_body.queue_free()
|
||||
_current_body_index = body_index
|
||||
_current_body_key = _key_list[body_index]
|
||||
var body_parent = $Bodies
|
||||
var body = _body_scene[_key_list[body_index]].instantiate()
|
||||
var body_parent := $Bodies
|
||||
var body: PhysicsBody3D = _body_scene[_key_list[body_index]].instantiate()
|
||||
_current_body = body
|
||||
init_body()
|
||||
body_parent.add_child(body)
|
||||
start_test()
|
||||
|
||||
|
||||
func spawn_body_key(body_key):
|
||||
func spawn_body_key(body_key: String) -> void:
|
||||
if _current_body:
|
||||
_current_body.queue_free()
|
||||
_current_body_key = body_key
|
||||
_current_body_index = _key_list.find(body_key)
|
||||
var body_parent = $Bodies
|
||||
var body = _body_scene[body_key].instantiate()
|
||||
var body_parent := $Bodies
|
||||
var body: PhysicsBody3D = _body_scene[body_key].instantiate()
|
||||
_current_body = body
|
||||
init_body()
|
||||
body_parent.add_child(body)
|
||||
start_test()
|
||||
|
||||
|
||||
func init_body():
|
||||
func init_body() -> void:
|
||||
if _current_body is CharacterBody3D:
|
||||
_current_body._stop_on_slopes = _slope
|
||||
_current_body.use_snap = _snap
|
||||
@@ -156,8 +153,8 @@ func init_body():
|
||||
shape.queue_free()
|
||||
|
||||
|
||||
func start_test():
|
||||
var animation_player = $Platforms/MovingPlatform/AnimationPlayer
|
||||
func start_test() -> void:
|
||||
var animation_player: AnimationPlayer = $Platforms/MovingPlatform/AnimationPlayer
|
||||
animation_player.stop()
|
||||
if _animation_physics:
|
||||
animation_player.playback_process_mode = AnimationPlayer.ANIMATION_PROCESS_PHYSICS
|
||||
@@ -168,9 +165,10 @@ func start_test():
|
||||
$LabelBodyType.text = "Body Type: " + _body_type[_current_body_index] + " \nCollision Shape: " + _current_shape
|
||||
|
||||
|
||||
func get_packed_scene(node):
|
||||
func get_packed_scene(node: Node) -> PackedScene:
|
||||
for child in node.get_children():
|
||||
child.owner = node
|
||||
var packed_scene = PackedScene.new()
|
||||
|
||||
var packed_scene := PackedScene.new()
|
||||
packed_scene.pack(node)
|
||||
return packed_scene
|
||||
|
||||
@@ -1,43 +1,41 @@
|
||||
extends Test
|
||||
|
||||
@export_range(1, 100) var height := 10
|
||||
@export_range(1, 100) var width_max := 100
|
||||
@export_range(1, 100) var depth_max := 1
|
||||
@export var box_size := Vector3(1.0, 1.0, 1.0)
|
||||
@export var box_spacing := Vector3(0.0, 0.0, 0.0)
|
||||
|
||||
@export_range(1, 100) var height = 10
|
||||
@export_range(1, 100) var width_max = 100
|
||||
@export_range(1, 100) var depth_max = 1
|
||||
@export var box_size = Vector3(1.0, 1.0, 1.0)
|
||||
@export var box_spacing = Vector3(0.0, 0.0, 0.0)
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
_create_pyramid()
|
||||
|
||||
|
||||
func _create_pyramid():
|
||||
var root_node = $Pyramid
|
||||
func _create_pyramid() -> void:
|
||||
var root_node: Node3D = $Pyramid
|
||||
|
||||
var template_body = create_rigidbody_box(box_size, true)
|
||||
var template_body := create_rigidbody_box(box_size, true)
|
||||
|
||||
var pos_y = 0.5 * box_size.y + box_spacing.y
|
||||
var pos_y := 0.5 * box_size.y + box_spacing.y
|
||||
|
||||
for level in height:
|
||||
var level_index = height - level - 1
|
||||
var num_boxes = 2 * level_index + 1
|
||||
var num_boxes_width = min(num_boxes, width_max)
|
||||
var num_boxes_depth = min(num_boxes, depth_max)
|
||||
var level_index := height - level - 1
|
||||
var num_boxes := 2 * level_index + 1
|
||||
var num_boxes_width := mini(num_boxes, width_max)
|
||||
var num_boxes_depth := mini(num_boxes, depth_max)
|
||||
|
||||
var row_node = Node3D.new()
|
||||
var row_node := Node3D.new()
|
||||
row_node.transform.origin = Vector3(0.0, pos_y, 0.0)
|
||||
row_node.name = "Row%02d" % (level + 1)
|
||||
root_node.add_child(row_node)
|
||||
|
||||
var pos_x = -0.5 * (num_boxes_width - 1) * (box_size.x + box_spacing.x)
|
||||
var pos_x := -0.5 * (num_boxes_width - 1) * (box_size.x + box_spacing.x)
|
||||
|
||||
for box_index_x in num_boxes_width:
|
||||
var pos_z = -0.5 * (num_boxes_depth - 1) * (box_size.z + box_spacing.z)
|
||||
var pos_z := -0.5 * (num_boxes_depth - 1) * (box_size.z + box_spacing.z)
|
||||
|
||||
for box_index_z in num_boxes_depth:
|
||||
var box_index = box_index_x * box_index_z
|
||||
var box = template_body.duplicate()
|
||||
var box_index := box_index_x * box_index_z
|
||||
var box := template_body.duplicate()
|
||||
box.transform.origin = Vector3(pos_x, 0.0, pos_z)
|
||||
box.name = "Box%02d" % (box_index + 1)
|
||||
row_node.add_child(box)
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
extends Test
|
||||
|
||||
|
||||
const OPTION_TEST_CASE_HIT_FROM_INSIDE = "Test case/Hit from inside"
|
||||
|
||||
var _hit_from_inside = false
|
||||
var _do_raycasts = false
|
||||
var _hit_from_inside := false
|
||||
var _do_raycasts := false
|
||||
|
||||
@onready var _raycast_visuals = ImmediateMesh.new()
|
||||
@onready var _material = StandardMaterial3D.new()
|
||||
@onready var _raycast_visuals := ImmediateMesh.new()
|
||||
@onready var _material := StandardMaterial3D.new()
|
||||
|
||||
|
||||
func _ready():
|
||||
var options = $Options
|
||||
func _ready() -> void:
|
||||
var options: OptionMenu = $Options
|
||||
|
||||
options.add_menu_item(OPTION_TEST_CASE_HIT_FROM_INSIDE, true, false)
|
||||
|
||||
options.option_changed.connect(_on_option_changed)
|
||||
|
||||
_material.flags_unshaded = true
|
||||
_material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
_material.vertex_color_use_as_albedo = true
|
||||
|
||||
var raycast_mesh_instance = MeshInstance3D.new()
|
||||
var raycast_mesh_instance := MeshInstance3D.new()
|
||||
raycast_mesh_instance.mesh = _raycast_visuals
|
||||
add_child(raycast_mesh_instance)
|
||||
move_child(raycast_mesh_instance, get_child_count())
|
||||
@@ -32,7 +31,7 @@ func _ready():
|
||||
_do_raycasts = true
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
func _physics_process(delta: float) -> void:
|
||||
super._physics_process(delta)
|
||||
|
||||
if not _do_raycasts:
|
||||
@@ -46,15 +45,15 @@ func _physics_process(delta):
|
||||
_raycast_visuals.surface_begin(Mesh.PRIMITIVE_LINES)
|
||||
|
||||
for shape in $Shapes.get_children():
|
||||
var body = shape as PhysicsBody3D
|
||||
var space_state = body.get_world_3d().direct_space_state
|
||||
var body: PhysicsBody3D = shape
|
||||
var space_state := body.get_world_3d().direct_space_state
|
||||
|
||||
Log.print_log("* Testing: %s" % body.name)
|
||||
|
||||
var center = body.global_transform.origin
|
||||
var center := body.global_transform.origin
|
||||
|
||||
# Raycast entering from the top.
|
||||
var res = _add_raycast(space_state, center + Vector3(0.0, 2.0, 0.0), center)
|
||||
var res := _add_raycast(space_state, center + Vector3(0.0, 2.0, 0.0), center)
|
||||
Log.print_log("Raycast in: %s" % ("HIT" if res else "NO HIT"))
|
||||
|
||||
# Raycast exiting from inside.
|
||||
@@ -72,20 +71,20 @@ func _physics_process(delta):
|
||||
_raycast_visuals.surface_set_material(0, _material)
|
||||
|
||||
|
||||
func _on_option_changed(option, checked):
|
||||
func _on_option_changed(option: String, checked: bool) -> void:
|
||||
match option:
|
||||
OPTION_TEST_CASE_HIT_FROM_INSIDE:
|
||||
_hit_from_inside = checked
|
||||
_do_raycasts = true
|
||||
|
||||
|
||||
func _add_raycast(space_state, pos_start, pos_end):
|
||||
var params = PhysicsRayQueryParameters3D.new()
|
||||
func _add_raycast(space_state: PhysicsDirectSpaceState3D, pos_start: Vector3, pos_end: Vector3) -> Dictionary:
|
||||
var params := PhysicsRayQueryParameters3D.new()
|
||||
params.from = pos_start
|
||||
params.to = pos_end
|
||||
params.hit_from_inside = _hit_from_inside
|
||||
|
||||
var result = space_state.intersect_ray(params)
|
||||
var result := space_state.intersect_ray(params)
|
||||
if result:
|
||||
_raycast_visuals.surface_set_color(Color.GREEN)
|
||||
else:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
extends Test
|
||||
|
||||
|
||||
const OPTION_BIG = "Floor options/Big"
|
||||
const OPTION_SMALL = "Floor options/Small"
|
||||
|
||||
@@ -8,17 +7,16 @@ const SHAPE_CONCAVE = "Collision shapes/Concave"
|
||||
const SHAPE_CONVEX = "Collision shapes/Convex"
|
||||
const SHAPE_BOX = "Collision shapes/Box"
|
||||
|
||||
var _dynamic_shapes_scene
|
||||
var _floor_shapes = {}
|
||||
var _floor_size = "Small"
|
||||
var _dynamic_shapes_scene: PackedScene
|
||||
var _floor_shapes := {}
|
||||
var _floor_size := "Small"
|
||||
|
||||
var _current_floor_name = SHAPE_CONCAVE
|
||||
var _current_bodies
|
||||
var _current_floor
|
||||
var _current_floor_name := SHAPE_CONCAVE
|
||||
var _current_bodies: Node3D
|
||||
var _current_floor: Node3D
|
||||
|
||||
|
||||
func _ready():
|
||||
var options = $Options
|
||||
func _ready() -> void:
|
||||
var options: OptionMenu = $Options
|
||||
_dynamic_shapes_scene = get_packed_scene($DynamicShapes/Bodies)
|
||||
_floor_shapes[SHAPE_CONVEX + "Small"] = get_packed_scene($"Floors/ConvexSmall")
|
||||
_floor_shapes[SHAPE_CONVEX + "Big"] = get_packed_scene($"Floors/ConvexBig")
|
||||
@@ -40,7 +38,7 @@ func _ready():
|
||||
restart_scene()
|
||||
|
||||
|
||||
func _on_option_selected(option):
|
||||
func _on_option_selected(option: String) -> void:
|
||||
match option:
|
||||
OPTION_BIG:
|
||||
_floor_size = "Big"
|
||||
@@ -51,30 +49,31 @@ func _on_option_selected(option):
|
||||
restart_scene()
|
||||
|
||||
|
||||
func restart_scene():
|
||||
func restart_scene() -> void:
|
||||
if _current_bodies:
|
||||
_current_bodies.queue_free()
|
||||
if _current_floor:
|
||||
_current_floor.queue_free()
|
||||
|
||||
var dynamic_bodies = _dynamic_shapes_scene.instantiate()
|
||||
var dynamic_bodies := _dynamic_shapes_scene.instantiate()
|
||||
_current_bodies = dynamic_bodies
|
||||
add_child(dynamic_bodies)
|
||||
|
||||
var floor_inst = _floor_shapes[_current_floor_name + _floor_size].instantiate()
|
||||
var floor_inst: Node3D = _floor_shapes[_current_floor_name + _floor_size].instantiate()
|
||||
_current_floor = floor_inst
|
||||
$Floors.add_child(floor_inst)
|
||||
|
||||
$LabelBodyType.text = "Floor Type: " + _current_floor_name.rsplit("/", true, 1)[1] + "\nSize: " + _floor_size
|
||||
|
||||
|
||||
func get_packed_scene(node):
|
||||
func get_packed_scene(node: Node) -> PackedScene:
|
||||
for child in node.get_children():
|
||||
child.owner = node
|
||||
for child1 in child.get_children():
|
||||
child1.owner = node
|
||||
for child2 in child1.get_children():
|
||||
child2.owner = node
|
||||
var packed_scene = PackedScene.new()
|
||||
|
||||
var packed_scene := PackedScene.new()
|
||||
packed_scene.pack(node)
|
||||
return packed_scene
|
||||
|
||||
@@ -35,12 +35,13 @@ points = PackedVector3Array(-0.7, 0, -0.7, -0.3, 0, 0.8, 0.8, 0, -0.3, 0, -1, 0)
|
||||
[sub_resource type="ArrayMesh" id="15"]
|
||||
_surfaces = [{
|
||||
"aabb": AABB(-0.7, -1, -0.7, 1.5, 1.00001, 1.5),
|
||||
"format": 4099,
|
||||
"format": 34359742467,
|
||||
"index_count": 12,
|
||||
"index_data": PackedByteArray(0, 0, 1, 0, 3, 0, 1, 0, 2, 0, 3, 0, 2, 0, 0, 0, 3, 0, 2, 0, 1, 0, 0, 0),
|
||||
"primitive": 3,
|
||||
"uv_scale": Vector4(0, 0, 0, 0),
|
||||
"vertex_count": 4,
|
||||
"vertex_data": PackedByteArray(51, 51, 51, 191, 0, 0, 0, 0, 51, 51, 51, 191, 0, 0, 0, 0, 154, 153, 153, 190, 0, 0, 0, 0, 205, 204, 76, 63, 0, 0, 96, 59, 205, 204, 76, 63, 0, 0, 0, 0, 154, 153, 153, 190, 182, 3, 0, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
"vertex_data": PackedByteArray(51, 51, 51, 191, 0, 0, 0, 0, 51, 51, 51, 191, 154, 153, 153, 190, 0, 0, 0, 0, 205, 204, 76, 63, 205, 204, 76, 63, 0, 0, 0, 0, 154, 153, 153, 190, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 59, 182, 3, 0, 0, 0, 0, 0, 0)
|
||||
}]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="17"]
|
||||
@@ -75,19 +76,16 @@ size = Vector3(100, 2, 40)
|
||||
size = Vector3(200, 2, 200)
|
||||
|
||||
[node name="Test" type="Node3D"]
|
||||
script = ExtResource( "3" )
|
||||
script = ExtResource("3")
|
||||
|
||||
[node name="LabelBodyType" type="Label" parent="."]
|
||||
offset_left = 14.0
|
||||
offset_top = 78.0
|
||||
offset_top = 62.0
|
||||
offset_right = 171.0
|
||||
offset_bottom = 92.0
|
||||
offset_bottom = 85.0
|
||||
text = "Floor Type: "
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Options" parent="." instance=ExtResource( "2" )]
|
||||
[node name="Options" parent="." instance=ExtResource("2")]
|
||||
offset_top = 120.0
|
||||
offset_bottom = 140.0
|
||||
focus_mode = 2
|
||||
@@ -97,79 +95,79 @@ focus_mode = 2
|
||||
[node name="Bodies" type="Node3D" parent="DynamicShapes"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.2912, 0)
|
||||
|
||||
[node name="RigidBodyBox" type="RigidDynamicBody3D" parent="DynamicShapes/Bodies"]
|
||||
[node name="RigidBodyBox" type="RigidBody3D" parent="DynamicShapes/Bodies"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6, 0, 0)
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_y = true
|
||||
axis_lock_angular_z = true
|
||||
physics_material_override = SubResource( "1" )
|
||||
script = ExtResource( "1" )
|
||||
physics_material_override = SubResource("1")
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="DynamicShapes/Bodies/RigidBodyBox"]
|
||||
transform = Transform3D(0.6, 0, 0, 0, 1, 0, 0, 0, 0.6, 0, 0, 0)
|
||||
shape = SubResource( "2" )
|
||||
shape = SubResource("2")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DynamicShapes/Bodies/RigidBodyBox/CollisionShape"]
|
||||
mesh = SubResource( "3" )
|
||||
mesh = SubResource("3")
|
||||
|
||||
[node name="RigidBodyCapsule" type="RigidDynamicBody3D" parent="DynamicShapes/Bodies"]
|
||||
[node name="RigidBodyCapsule" type="RigidBody3D" parent="DynamicShapes/Bodies"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3, 0, 0)
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_y = true
|
||||
axis_lock_angular_z = true
|
||||
physics_material_override = SubResource( "5" )
|
||||
script = ExtResource( "1" )
|
||||
physics_material_override = SubResource("5")
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="DynamicShapes/Bodies/RigidBodyCapsule"]
|
||||
transform = Transform3D(0.8, 0, 0, 0, 0.8, 0, 0, 0, 0.8, 0, 0, 0)
|
||||
shape = SubResource( "6" )
|
||||
shape = SubResource("6")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DynamicShapes/Bodies/RigidBodyCapsule/CollisionShape"]
|
||||
mesh = SubResource( "7" )
|
||||
mesh = SubResource("7")
|
||||
|
||||
[node name="RigidBodyCylinder" type="RigidDynamicBody3D" parent="DynamicShapes/Bodies"]
|
||||
[node name="RigidBodyCylinder" type="RigidBody3D" parent="DynamicShapes/Bodies"]
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_y = true
|
||||
axis_lock_angular_z = true
|
||||
physics_material_override = SubResource( "9" )
|
||||
script = ExtResource( "1" )
|
||||
physics_material_override = SubResource("9")
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="DynamicShapes/Bodies/RigidBodyCylinder"]
|
||||
transform = Transform3D(0.8, 0, 0, 0, 1, 0, 0, 0, 0.8, 0, 0, 0)
|
||||
shape = SubResource( "10" )
|
||||
shape = SubResource("10")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DynamicShapes/Bodies/RigidBodyCylinder/CollisionShape"]
|
||||
mesh = SubResource( "11" )
|
||||
mesh = SubResource("11")
|
||||
|
||||
[node name="RigidBodyConvex" type="RigidDynamicBody3D" parent="DynamicShapes/Bodies"]
|
||||
[node name="RigidBodyConvex" type="RigidBody3D" parent="DynamicShapes/Bodies"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3, 0.974548, 0)
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_y = true
|
||||
axis_lock_angular_z = true
|
||||
physics_material_override = SubResource( "13" )
|
||||
script = ExtResource( "1" )
|
||||
physics_material_override = SubResource("13")
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="DynamicShapes/Bodies/RigidBodyConvex"]
|
||||
transform = Transform3D(1.5, 0, 0, 0, 2, 0, 0, 0, 1.5, 0, 0, 0)
|
||||
shape = SubResource( "14" )
|
||||
shape = SubResource("14")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DynamicShapes/Bodies/RigidBodyConvex/CollisionShape"]
|
||||
mesh = SubResource( "15" )
|
||||
mesh = SubResource("15")
|
||||
|
||||
[node name="RigidBodySphere" type="RigidDynamicBody3D" parent="DynamicShapes/Bodies"]
|
||||
[node name="RigidBodySphere" type="RigidBody3D" parent="DynamicShapes/Bodies"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, 0)
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_y = true
|
||||
axis_lock_angular_z = true
|
||||
physics_material_override = SubResource( "17" )
|
||||
script = ExtResource( "1" )
|
||||
physics_material_override = SubResource("17")
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="DynamicShapes/Bodies/RigidBodySphere"]
|
||||
transform = Transform3D(0.8, 0, 0, 0, 0.8, 0, 0, 0, 0.8, 0, 0, 0)
|
||||
shape = SubResource( "18" )
|
||||
shape = SubResource("18")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DynamicShapes/Bodies/RigidBodySphere/CollisionShape"]
|
||||
mesh = SubResource( "19" )
|
||||
mesh = SubResource("19")
|
||||
|
||||
[node name="Floors" type="Node3D" parent="."]
|
||||
|
||||
@@ -180,20 +178,20 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -10)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floors/ConvexSmall/ConvexFloor"]
|
||||
visible = false
|
||||
mesh = SubResource( "23" )
|
||||
mesh = SubResource("23")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="Floors/ConvexSmall/ConvexFloor"]
|
||||
shape = SubResource( "24" )
|
||||
shape = SubResource("24")
|
||||
|
||||
[node name="ConvexFloor2" type="StaticBody3D" parent="Floors/ConvexSmall"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 10)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floors/ConvexSmall/ConvexFloor2"]
|
||||
visible = false
|
||||
mesh = SubResource( "23" )
|
||||
mesh = SubResource("23")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="Floors/ConvexSmall/ConvexFloor2"]
|
||||
shape = SubResource( "25" )
|
||||
shape = SubResource("25")
|
||||
|
||||
[node name="ConvexBig" type="Node3D" parent="Floors"]
|
||||
|
||||
@@ -201,10 +199,10 @@ shape = SubResource( "25" )
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floors/ConvexBig/ConvexFloor"]
|
||||
visible = false
|
||||
mesh = SubResource( "23" )
|
||||
mesh = SubResource("23")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="Floors/ConvexBig/ConvexFloor"]
|
||||
shape = SubResource( "26" )
|
||||
shape = SubResource("26")
|
||||
|
||||
[node name="ConcaveSmall" type="Node3D" parent="Floors"]
|
||||
|
||||
@@ -213,22 +211,22 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -10)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floors/ConcaveSmall/ConcaveFloor"]
|
||||
visible = false
|
||||
mesh = SubResource( "23" )
|
||||
mesh = SubResource("23")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="Floors/ConcaveSmall/ConcaveFloor"]
|
||||
transform = Transform3D(25, 0, 0, 0, 1, 0, 0, 0, 10, 0, 0, 0)
|
||||
shape = SubResource( "27" )
|
||||
shape = SubResource("27")
|
||||
|
||||
[node name="ConcaveFloor2" type="StaticBody3D" parent="Floors/ConcaveSmall"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 10)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floors/ConcaveSmall/ConcaveFloor2"]
|
||||
visible = false
|
||||
mesh = SubResource( "23" )
|
||||
mesh = SubResource("23")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="Floors/ConcaveSmall/ConcaveFloor2"]
|
||||
transform = Transform3D(25, 0, 0, 0, 1, 0, 0, 0, 10, 0, 0, 0)
|
||||
shape = SubResource( "27" )
|
||||
shape = SubResource("27")
|
||||
|
||||
[node name="ConcaveBig" type="Node3D" parent="Floors"]
|
||||
|
||||
@@ -236,10 +234,10 @@ shape = SubResource( "27" )
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floors/ConcaveBig/ConcaveFloor"]
|
||||
visible = false
|
||||
mesh = SubResource( "23" )
|
||||
mesh = SubResource("23")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="Floors/ConcaveBig/ConcaveFloor"]
|
||||
shape = SubResource( "28" )
|
||||
shape = SubResource("28")
|
||||
|
||||
[node name="BoxSmall" type="Node3D" parent="Floors"]
|
||||
|
||||
@@ -248,22 +246,22 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -10)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floors/BoxSmall/BoxFloor"]
|
||||
visible = false
|
||||
mesh = SubResource( "23" )
|
||||
mesh = SubResource("23")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="Floors/BoxSmall/BoxFloor"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
|
||||
shape = SubResource( "29" )
|
||||
shape = SubResource("29")
|
||||
|
||||
[node name="BoxFloor2" type="StaticBody3D" parent="Floors/BoxSmall"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 10)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floors/BoxSmall/BoxFloor2"]
|
||||
visible = false
|
||||
mesh = SubResource( "23" )
|
||||
mesh = SubResource("23")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="Floors/BoxSmall/BoxFloor2"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
|
||||
shape = SubResource( "29" )
|
||||
shape = SubResource("29")
|
||||
|
||||
[node name="BoxBig" type="Node3D" parent="Floors"]
|
||||
|
||||
@@ -271,16 +269,16 @@ shape = SubResource( "29" )
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floors/BoxBig/BoxFloor"]
|
||||
visible = false
|
||||
mesh = SubResource( "23" )
|
||||
mesh = SubResource("23")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="Floors/BoxBig/BoxFloor"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
|
||||
shape = SubResource( "30" )
|
||||
shape = SubResource("30")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.604, 22.124)
|
||||
far = 1000.0
|
||||
script = ExtResource( "4" )
|
||||
script = ExtResource("4")
|
||||
|
||||
[node name="OmniLight" type="OmniLight3D" parent="Camera3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 14.6965, -5.95932)
|
||||
|
||||
@@ -1,38 +1,36 @@
|
||||
extends Test
|
||||
|
||||
@export_range(1, 100) var height := 10
|
||||
@export_range(1, 100) var width := 1
|
||||
@export_range(1, 100) var depth := 1
|
||||
@export var box_size := Vector3(1.0, 1.0, 1.0)
|
||||
@export var box_spacing := Vector3(0.0, 0.0, 0.0)
|
||||
|
||||
@export_range(1, 100) var height = 10
|
||||
@export_range(1, 100) var width = 1
|
||||
@export_range(1, 100) var depth = 1
|
||||
@export var box_size = Vector3(1.0, 1.0, 1.0)
|
||||
@export var box_spacing = Vector3(0.0, 0.0, 0.0)
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
_create_stack()
|
||||
|
||||
|
||||
func _create_stack():
|
||||
var root_node = $Stack
|
||||
func _create_stack() -> void:
|
||||
var root_node: Node3D = $Stack
|
||||
|
||||
var template_body = create_rigidbody_box(box_size, true)
|
||||
var template_body := create_rigidbody_box(box_size, true)
|
||||
|
||||
var pos_y = 0.5 * box_size.y + box_spacing.y
|
||||
var pos_y := 0.5 * box_size.y + box_spacing.y
|
||||
|
||||
for level in height:
|
||||
var row_node = Node3D.new()
|
||||
var row_node := Node3D.new()
|
||||
row_node.transform.origin = Vector3(0.0, pos_y, 0.0)
|
||||
row_node.name = "Row%02d" % (level + 1)
|
||||
root_node.add_child(row_node)
|
||||
|
||||
var pos_x = -0.5 * (width - 1) * (box_size.x + box_spacing.x)
|
||||
var pos_x := -0.5 * (width - 1) * (box_size.x + box_spacing.x)
|
||||
|
||||
for box_index_x in width:
|
||||
var pos_z = -0.5 * (depth - 1) * (box_size.z + box_spacing.z)
|
||||
var pos_z := -0.5 * (depth - 1) * (box_size.z + box_spacing.z)
|
||||
|
||||
for box_index_z in depth:
|
||||
var box_index = box_index_x * box_index_z
|
||||
var box = template_body.duplicate()
|
||||
var box_index := box_index_x * box_index_z
|
||||
var box := template_body.duplicate()
|
||||
box.transform.origin = Vector3(pos_x, 0.0, pos_z)
|
||||
box.name = "Box%02d" % (box_index + 1)
|
||||
row_node.add_child(box)
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
[ext_resource type="Script" path="res://utils/camera_orbit.gd" id="4"]
|
||||
|
||||
[node name="Test" type="Node3D"]
|
||||
script = ExtResource( "1" )
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="Stack" type="Node3D" parent="."]
|
||||
|
||||
[node name="StaticBodyPlane" parent="." instance=ExtResource( "2" )]
|
||||
[node name="StaticBodyPlane" parent="." instance=ExtResource("2")]
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.53602, 12.2684)
|
||||
current = true
|
||||
script = ExtResource( "4" )
|
||||
script = ExtResource("4")
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
extends Test
|
||||
|
||||
|
||||
const BOX_SIZE = Vector3(0.8, 0.8, 0.8)
|
||||
const BOX_SPACE = Vector3(1.0, 1.0, 1.0)
|
||||
|
||||
@export_range(1, 1000) var row_size = 20
|
||||
@export_range(1, 1000) var column_size = 20
|
||||
@export_range(1, 1000) var depth_size = 20
|
||||
@export_range(1, 1000) var row_size := 20
|
||||
@export_range(1, 1000) var column_size := 20
|
||||
@export_range(1, 1000) var depth_size := 20
|
||||
|
||||
var _objects = []
|
||||
var _objects: Array[Node3D] = []
|
||||
|
||||
var _log_physics = false
|
||||
var _log_physics_time = 0
|
||||
var _log_physics_time_start = 0
|
||||
var _log_physics := false
|
||||
var _log_physics_time := 0
|
||||
var _log_physics_time_start := 0
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
await start_timer(1.0).timeout
|
||||
if is_timer_canceled():
|
||||
return
|
||||
@@ -67,49 +65,49 @@ func _ready():
|
||||
Log.print_log("* Done.")
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
func _exit_tree() -> void:
|
||||
for object in _objects:
|
||||
object.free()
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
func _physics_process(delta: float) -> void:
|
||||
super._physics_process(delta)
|
||||
|
||||
if _log_physics:
|
||||
var time = Time.get_ticks_usec()
|
||||
var time_delta = time - _log_physics_time
|
||||
var time_total = time - _log_physics_time_start
|
||||
var time := Time.get_ticks_usec()
|
||||
var time_delta := time - _log_physics_time
|
||||
var time_total := time - _log_physics_time_start
|
||||
_log_physics_time = time
|
||||
Log.print_log(" Physics Tick: %.3f ms (total = %.3f ms)" % [0.001 * time_delta, 0.001 * time_total])
|
||||
|
||||
|
||||
func _log_physics_start():
|
||||
func _log_physics_start() -> void:
|
||||
_log_physics = true
|
||||
_log_physics_time_start = Time.get_ticks_usec()
|
||||
_log_physics_time = _log_physics_time_start
|
||||
|
||||
|
||||
func _log_physics_stop():
|
||||
func _log_physics_stop() -> void:
|
||||
_log_physics = false
|
||||
|
||||
|
||||
func _create_objects():
|
||||
func _create_objects() -> void:
|
||||
_objects.clear()
|
||||
|
||||
Log.print_log("* Creating objects...")
|
||||
var timer = Time.get_ticks_usec()
|
||||
var timer := Time.get_ticks_usec()
|
||||
|
||||
var pos_x = -0.5 * (row_size - 1) * BOX_SPACE.x
|
||||
var pos_x := -0.5 * (row_size - 1) * BOX_SPACE.x
|
||||
|
||||
for row in row_size:
|
||||
var pos_y = -0.5 * (column_size - 1) * BOX_SPACE.y
|
||||
var pos_y := -0.5 * (column_size - 1) * BOX_SPACE.y
|
||||
|
||||
for column in column_size:
|
||||
var pos_z = -0.5 * (depth_size - 1) * BOX_SPACE.z
|
||||
var pos_z := -0.5 * (depth_size - 1) * BOX_SPACE.z
|
||||
|
||||
for depth in depth_size:
|
||||
# Create a new object and shape every time to avoid the overhead of connecting many bodies to the same shape.
|
||||
var box = create_rigidbody_box(BOX_SIZE)
|
||||
var box: RigidBody3D = create_rigidbody_box(BOX_SIZE)
|
||||
box.gravity_scale = 0.0
|
||||
box.transform.origin = Vector3(pos_x, pos_y, pos_z)
|
||||
_objects.push_back(box)
|
||||
@@ -124,11 +122,11 @@ func _create_objects():
|
||||
Log.print_log(" Create Time: %.3f ms" % (0.001 * timer))
|
||||
|
||||
|
||||
func _add_objects():
|
||||
var root_node = $Objects
|
||||
func _add_objects() -> void:
|
||||
var root_node: Node3D = $Objects
|
||||
|
||||
Log.print_log("* Adding objects...")
|
||||
var timer = Time.get_ticks_usec()
|
||||
var timer := Time.get_ticks_usec()
|
||||
|
||||
for object in _objects:
|
||||
root_node.add_child(object)
|
||||
@@ -137,9 +135,9 @@ func _add_objects():
|
||||
Log.print_log(" Add Time: %.3f ms" % (0.001 * timer))
|
||||
|
||||
|
||||
func _move_objects():
|
||||
func _move_objects() -> void:
|
||||
Log.print_log("* Moving objects...")
|
||||
var timer = Time.get_ticks_usec()
|
||||
var timer := Time.get_ticks_usec()
|
||||
|
||||
for object in _objects:
|
||||
object.transform.origin += BOX_SPACE
|
||||
@@ -148,15 +146,15 @@ func _move_objects():
|
||||
Log.print_log(" Move Time: %.3f ms" % (0.001 * timer))
|
||||
|
||||
|
||||
func _remove_objects():
|
||||
var root_node = $Objects
|
||||
func _remove_objects() -> void:
|
||||
var root_node: Node3D = $Objects
|
||||
|
||||
Log.print_log("* Removing objects...")
|
||||
var timer = Time.get_ticks_usec()
|
||||
var timer := Time.get_ticks_usec()
|
||||
|
||||
# Remove objects in reversed order to avoid the overhead of changing children index in parent.
|
||||
var object_count = _objects.size()
|
||||
for object_index in range(object_count):
|
||||
var object_count := _objects.size()
|
||||
for object_index in object_count:
|
||||
root_node.remove_child(_objects[object_count - object_index - 1])
|
||||
|
||||
timer = Time.get_ticks_usec() - timer
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
extends Test
|
||||
|
||||
|
||||
const OPTION_TYPE_ALL = "Shape type/All"
|
||||
const OPTION_TYPE_BOX = "Shape type/Box"
|
||||
const OPTION_TYPE_SPHERE = "Shape type/Sphere"
|
||||
@@ -8,24 +7,23 @@ const OPTION_TYPE_CAPSULE = "Shape type/Capsule"
|
||||
const OPTION_TYPE_CYLINDER = "Shape type/Cylinder"
|
||||
const OPTION_TYPE_CONVEX = "Shape type/Convex"
|
||||
|
||||
@export var spawns = []
|
||||
@export var spawn_count = 100
|
||||
@export var spawn_randomize = Vector3.ZERO
|
||||
@export var spawns: Array[NodePath] = []
|
||||
@export var spawn_count := 100
|
||||
@export var spawn_randomize := Vector3.ZERO
|
||||
|
||||
var _object_templates = []
|
||||
var _object_templates: Array[Node3D] = []
|
||||
|
||||
var _log_physics = false
|
||||
var _log_physics_time = 0
|
||||
var _log_physics_time_start = 0
|
||||
var _log_physics := false
|
||||
var _log_physics_time := 0
|
||||
var _log_physics_time_start := 0
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
await start_timer(0.5).timeout
|
||||
if is_timer_canceled():
|
||||
return
|
||||
|
||||
while $DynamicShapes.get_child_count():
|
||||
var type_node = $DynamicShapes.get_child(0)
|
||||
var type_node: Node3D = $DynamicShapes.get_child(0)
|
||||
_object_templates.push_back(type_node)
|
||||
$DynamicShapes.remove_child(type_node)
|
||||
|
||||
@@ -40,33 +38,33 @@ func _ready():
|
||||
await _start_all_types()
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
func _exit_tree() -> void:
|
||||
for object_template in _object_templates:
|
||||
object_template.free()
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
func _physics_process(delta: float) -> void:
|
||||
super._physics_process(delta)
|
||||
|
||||
if _log_physics:
|
||||
var time = Time.get_ticks_usec()
|
||||
var time_delta = time - _log_physics_time
|
||||
var time_total = time - _log_physics_time_start
|
||||
var time := Time.get_ticks_usec()
|
||||
var time_delta := time - _log_physics_time
|
||||
var time_total := time - _log_physics_time_start
|
||||
_log_physics_time = time
|
||||
Log.print_log(" Physics Tick: %.3f ms (total = %.3f ms)" % [0.001 * time_delta, 0.001 * time_total])
|
||||
|
||||
|
||||
func _log_physics_start():
|
||||
func _log_physics_start() -> void:
|
||||
_log_physics = true
|
||||
_log_physics_time_start = Time.get_ticks_usec()
|
||||
_log_physics_time = _log_physics_time_start
|
||||
|
||||
|
||||
func _log_physics_stop():
|
||||
func _log_physics_stop() -> void:
|
||||
_log_physics = false
|
||||
|
||||
|
||||
func _on_option_selected(option):
|
||||
func _on_option_selected(option: String) -> void:
|
||||
cancel_timer()
|
||||
|
||||
_despawn_objects()
|
||||
@@ -86,9 +84,9 @@ func _on_option_selected(option):
|
||||
await _start_type(_find_type_index("Convex"))
|
||||
|
||||
|
||||
func _find_type_index(type_name):
|
||||
func _find_type_index(type_name: String) -> int:
|
||||
for type_index in range(_object_templates.size()):
|
||||
var type_node = _object_templates[type_index]
|
||||
var type_node := _object_templates[type_index]
|
||||
if String(type_node.name).find(type_name) > -1:
|
||||
return type_index
|
||||
|
||||
@@ -96,7 +94,7 @@ func _find_type_index(type_name):
|
||||
return -1
|
||||
|
||||
|
||||
func _start_type(type_index):
|
||||
func _start_type(type_index: int) -> void:
|
||||
if type_index < 0:
|
||||
return
|
||||
if type_index >= _object_templates.size():
|
||||
@@ -138,10 +136,10 @@ func _start_type(type_index):
|
||||
await start_timer(1.0).timeout
|
||||
|
||||
|
||||
func _start_all_types():
|
||||
func _start_all_types() -> void:
|
||||
Log.print_log("* Start all types.")
|
||||
|
||||
for type_index in range(_object_templates.size()):
|
||||
for type_index in _object_templates.size():
|
||||
await _start_type(type_index)
|
||||
if is_timer_canceled():
|
||||
return
|
||||
@@ -149,25 +147,25 @@ func _start_all_types():
|
||||
Log.print_log("* Done all types.")
|
||||
|
||||
|
||||
func _spawn_objects(type_index):
|
||||
var template_node = _object_templates[type_index]
|
||||
func _spawn_objects(type_index: int) -> void:
|
||||
var template_node := _object_templates[type_index]
|
||||
|
||||
Log.print_log("* Spawning: " + String(template_node.name))
|
||||
|
||||
for spawn in spawns:
|
||||
var spawn_parent = get_node(spawn)
|
||||
var spawn_parent := get_node(spawn)
|
||||
|
||||
for _node_index in range(spawn_count):
|
||||
# Create a new object and shape every time to avoid the overhead of connecting many bodies to the same shape.
|
||||
var collision = template_node.get_child(0).duplicate()
|
||||
var collision := template_node.get_child(0).duplicate()
|
||||
collision.shape = collision.shape.duplicate()
|
||||
var body = template_node.duplicate()
|
||||
var body := template_node.duplicate()
|
||||
body.transform = Transform3D.IDENTITY
|
||||
if spawn_randomize != Vector3.ZERO:
|
||||
body.transform.origin.x = randf() * spawn_randomize.x
|
||||
body.transform.origin.y = randf() * spawn_randomize.y
|
||||
body.transform.origin.z = randf() * spawn_randomize.z
|
||||
var prev_collision = body.get_child(0)
|
||||
var prev_collision := body.get_child(0)
|
||||
body.remove_child(prev_collision)
|
||||
prev_collision.queue_free()
|
||||
body.add_child(collision)
|
||||
@@ -175,26 +173,26 @@ func _spawn_objects(type_index):
|
||||
spawn_parent.add_child(body)
|
||||
|
||||
|
||||
func _activate_objects():
|
||||
func _activate_objects() -> void:
|
||||
Log.print_log("* Activating")
|
||||
|
||||
for spawn in spawns:
|
||||
var spawn_parent = get_node(spawn)
|
||||
var spawn_parent := get_node(spawn)
|
||||
|
||||
for node_index in range(spawn_parent.get_child_count()):
|
||||
var node = spawn_parent.get_child(node_index) as RigidBody3D
|
||||
for node_index in spawn_parent.get_child_count():
|
||||
var node: RigidBody3D = spawn_parent.get_child(node_index)
|
||||
node.set_sleeping(false)
|
||||
|
||||
|
||||
func _despawn_objects():
|
||||
func _despawn_objects() -> void:
|
||||
Log.print_log("* Despawning")
|
||||
|
||||
for spawn in spawns:
|
||||
var spawn_parent = get_node(spawn)
|
||||
var spawn_parent := get_node(spawn)
|
||||
|
||||
# Remove objects in reversed order to avoid the overhead of changing children index in parent.
|
||||
var object_count = spawn_parent.get_child_count()
|
||||
for object_index in range(object_count):
|
||||
var node = spawn_parent.get_child(object_count - object_index - 1)
|
||||
var object_count := spawn_parent.get_child_count()
|
||||
for object_index in object_count:
|
||||
var node := spawn_parent.get_child(object_count - object_index - 1)
|
||||
spawn_parent.remove_child(node)
|
||||
node.queue_free()
|
||||
|
||||
@@ -2,28 +2,28 @@ extends OptionMenu
|
||||
|
||||
|
||||
class TestData:
|
||||
var id
|
||||
var scene_path
|
||||
var id := ""
|
||||
var scene_path := ""
|
||||
|
||||
|
||||
var _test_list = []
|
||||
var _test_list: Array[TestData] = []
|
||||
|
||||
var _current_test = null
|
||||
var _current_test: TestData = null
|
||||
var _current_test_scene: Node = null
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
option_selected.connect(_on_option_selected)
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed(&"restart_test"):
|
||||
if _current_test:
|
||||
_start_test(_current_test)
|
||||
|
||||
|
||||
func add_test(id, scene_path):
|
||||
var test_data = TestData.new()
|
||||
func add_test(id: String, scene_path: String) -> void:
|
||||
var test_data := TestData.new()
|
||||
test_data.id = id
|
||||
test_data.scene_path = scene_path
|
||||
_test_list.append(test_data)
|
||||
@@ -31,13 +31,13 @@ func add_test(id, scene_path):
|
||||
add_menu_item(id)
|
||||
|
||||
|
||||
func _on_option_selected(item_path):
|
||||
func _on_option_selected(item_path: String) -> void:
|
||||
for test in _test_list:
|
||||
if test.id == item_path:
|
||||
_start_test(test)
|
||||
|
||||
|
||||
func _start_test(test):
|
||||
func _start_test(test: TestData) -> void:
|
||||
_current_test = test
|
||||
|
||||
if _current_test_scene:
|
||||
@@ -45,9 +45,9 @@ func _start_test(test):
|
||||
_current_test_scene = null
|
||||
|
||||
Log.print_log("*** STARTING TEST: " + test.id)
|
||||
var scene = load(test.scene_path)
|
||||
var scene := load(test.scene_path)
|
||||
_current_test_scene = scene.instantiate()
|
||||
get_tree().root.add_child(_current_test_scene)
|
||||
|
||||
var label_test = get_node(^"../LabelTest")
|
||||
var label_test: Label = $"../LabelTest"
|
||||
label_test.test_name = test.id
|
||||
|
||||
@@ -1,35 +1,32 @@
|
||||
extends Camera3D
|
||||
|
||||
|
||||
const ROTATION_COEFF = 0.02
|
||||
|
||||
var _rotation_enabled = false
|
||||
var _rotation_pivot
|
||||
var _rotation_enabled := false
|
||||
var _rotation_pivot: Node3D
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
_initialize_pivot.call_deferred()
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
var mouse_button_event = event as InputEventMouseButton
|
||||
if mouse_button_event:
|
||||
if mouse_button_event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
_rotation_enabled = mouse_button_event.pressed
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
_rotation_enabled = event.pressed
|
||||
|
||||
return
|
||||
|
||||
if not _rotation_enabled:
|
||||
return
|
||||
|
||||
var mouse_motion_event = event as InputEventMouseMotion
|
||||
if mouse_motion_event:
|
||||
var rotation_delta = mouse_motion_event.relative.x
|
||||
if event is InputEventMouseMotion:
|
||||
var rotation_delta: float = event.relative.x
|
||||
_rotation_pivot.rotate(Vector3.UP, -rotation_delta * ROTATION_COEFF)
|
||||
|
||||
|
||||
func _initialize_pivot():
|
||||
func _initialize_pivot() -> void:
|
||||
_rotation_pivot = Node3D.new()
|
||||
var camera_parent = get_parent()
|
||||
var camera_parent := get_parent()
|
||||
camera_parent.add_child(_rotation_pivot)
|
||||
camera_parent.remove_child(self)
|
||||
_rotation_pivot.add_child(self)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
@export var _stop_on_slopes := false
|
||||
@export var use_snap := false
|
||||
|
||||
@export var _stop_on_slopes = false
|
||||
@export var use_snap = false
|
||||
var _gravity := 20.0
|
||||
|
||||
var _gravity = 20.0
|
||||
|
||||
func _physics_process(delta):
|
||||
func _physics_process(delta: float) -> void:
|
||||
if is_on_floor():
|
||||
floor_snap_length = 0.2
|
||||
else:
|
||||
|
||||
@@ -1,40 +1,39 @@
|
||||
extends Control
|
||||
|
||||
|
||||
const MAX_ENTRIES = 100
|
||||
|
||||
var _entry_template
|
||||
var _entry_template: Label
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
func _enter_tree() -> void:
|
||||
Log.entry_logged.connect(_on_log_entry)
|
||||
|
||||
_entry_template = get_child(0) as Label
|
||||
_entry_template = get_child(0)
|
||||
remove_child(_entry_template)
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
func _exit_tree() -> void:
|
||||
_entry_template.free()
|
||||
|
||||
|
||||
func clear():
|
||||
func clear() -> void:
|
||||
while get_child_count():
|
||||
var entry = get_child(get_child_count() - 1)
|
||||
var entry: Label = get_child(get_child_count() - 1)
|
||||
remove_child(entry)
|
||||
entry.queue_free()
|
||||
|
||||
|
||||
func _on_log_entry(message, type):
|
||||
var new_entry = _entry_template.duplicate() as Label
|
||||
func _on_log_entry(message: String, type: Log.LogType) -> void:
|
||||
var new_entry: Label = _entry_template.duplicate()
|
||||
|
||||
new_entry.set_text(message)
|
||||
new_entry.text = message
|
||||
if type == Log.LogType.ERROR:
|
||||
new_entry.modulate = Color.RED
|
||||
else:
|
||||
new_entry.modulate = Color.WHITE
|
||||
|
||||
if get_child_count() >= MAX_ENTRIES:
|
||||
var first_entry = get_child(0) as Label
|
||||
var first_entry: Label = get_child(0)
|
||||
remove_child(first_entry)
|
||||
first_entry.queue_free()
|
||||
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
extends Control
|
||||
|
||||
@export var world_offset := Vector3.ZERO
|
||||
|
||||
@export var world_offset = Vector3.ZERO
|
||||
var _pos_offset: Vector2
|
||||
var _attachment: Node3D
|
||||
|
||||
var _pos_offset
|
||||
var _attachment
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
_pos_offset = position
|
||||
_attachment = get_parent() as Node3D
|
||||
_attachment = get_parent()
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float) -> void:
|
||||
if _attachment == null:
|
||||
return
|
||||
|
||||
var viewport = get_viewport()
|
||||
var viewport := get_viewport()
|
||||
if viewport == null:
|
||||
return
|
||||
|
||||
var camera = viewport.get_camera_3d()
|
||||
var camera := viewport.get_camera_3d()
|
||||
if camera == null:
|
||||
return
|
||||
|
||||
var world_pos = world_offset + _attachment.global_transform.origin
|
||||
var screen_pos = camera.unproject_position(world_pos)
|
||||
var world_pos := world_offset + _attachment.global_transform.origin
|
||||
var screen_pos := camera.unproject_position(world_pos)
|
||||
|
||||
position = _pos_offset + screen_pos - 0.5 * size
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
extends Label
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
var engine_name = ""
|
||||
func _ready() -> void:
|
||||
var engine_name := ""
|
||||
match System.get_physics_engine():
|
||||
System.PhysicsEngine.GODOT_PHYSICS:
|
||||
engine_name = "GodotPhysics 3D"
|
||||
System.PhysicsEngine.OTHER:
|
||||
var engine_setting = ProjectSettings.get_setting("physics/3d/physics_engine")
|
||||
var engine_setting := str(ProjectSettings.get_setting("physics/3d/physics_engine"))
|
||||
engine_name = "Other (%s)" % engine_setting
|
||||
set_text("Physics engine: %s" % engine_name)
|
||||
|
||||
text = "Physics engine: %s" % engine_name
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
extends Label
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
set_text("FPS: %d" % Engine.get_frames_per_second())
|
||||
func _process(_delta: float) -> void:
|
||||
text = "%d FPS (%.2f mspf)" % [Engine.get_frames_per_second(), 1000.0 / Engine.get_frames_per_second()]
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
extends Label
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float) -> void:
|
||||
visible = get_tree().paused
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
extends Label
|
||||
|
||||
|
||||
var test_name = "":
|
||||
var test_name := "":
|
||||
set(value):
|
||||
if (test_name != value):
|
||||
return
|
||||
test_name = value
|
||||
set_text("Test: %s" % test_name)
|
||||
text = "Test: %s" % test_name
|
||||
|
||||
|
||||
func _ready():
|
||||
set_text("Select a test from the menu to start it")
|
||||
func _ready() -> void:
|
||||
text = "Select a test from the menu to start it"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
extends Label
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float) -> void:
|
||||
set_text("Godot Version: %s" % Engine.get_version_info().string)
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
class_name OptionMenu
|
||||
extends MenuButton
|
||||
|
||||
signal option_selected(item_path: String)
|
||||
signal option_changed(item_path: String, checked: bool)
|
||||
|
||||
signal option_selected(item_path)
|
||||
signal option_changed(item_path, checked)
|
||||
|
||||
|
||||
func add_menu_item(item_path, checkbox = false, checked = false):
|
||||
var path_elements = item_path.split("/", false)
|
||||
var path_element_count = path_elements.size()
|
||||
func add_menu_item(item_path: String, checkbox: bool = false, checked: bool = false) -> void:
|
||||
var path_elements := item_path.split("/", false)
|
||||
var path_element_count := path_elements.size()
|
||||
assert(path_element_count > 0)
|
||||
|
||||
var path = ""
|
||||
var popup = get_popup()
|
||||
for element_index in range(path_element_count - 1):
|
||||
var popup_label = path_elements[element_index]
|
||||
var path := ""
|
||||
var popup := get_popup()
|
||||
for element_index in path_element_count - 1:
|
||||
var popup_label := path_elements[element_index]
|
||||
path += popup_label + "/"
|
||||
popup = _add_popup(popup, path, popup_label)
|
||||
|
||||
var label = path_elements[path_element_count - 1]
|
||||
var label := path_elements[path_element_count - 1]
|
||||
if checkbox:
|
||||
popup.add_check_item(label)
|
||||
popup.set_item_checked(popup.get_item_count() - 1, checked)
|
||||
@@ -26,18 +24,18 @@ func add_menu_item(item_path, checkbox = false, checked = false):
|
||||
popup.add_item(label)
|
||||
|
||||
|
||||
func _add_item(parent_popup, label):
|
||||
func _add_item(parent_popup: PopupMenu, label: String) -> void:
|
||||
parent_popup.add_item(label)
|
||||
|
||||
|
||||
func _add_popup(parent_popup, path, label):
|
||||
func _add_popup(parent_popup: PopupMenu, path: String, label: String) -> PopupMenu:
|
||||
if parent_popup.has_node(label):
|
||||
var popup_node = parent_popup.get_node(label)
|
||||
var popup_menu = popup_node as PopupMenu
|
||||
assert(popup_menu)
|
||||
return popup_menu
|
||||
var popup_node := parent_popup.get_node(label)
|
||||
var new_popup_menu: PopupMenu = popup_node
|
||||
assert(new_popup_menu)
|
||||
return new_popup_menu
|
||||
|
||||
var popup_menu = PopupMenu.new()
|
||||
var popup_menu := PopupMenu.new()
|
||||
popup_menu.name = label
|
||||
popup_menu.hide_on_checkable_item_selection = false
|
||||
|
||||
@@ -49,11 +47,11 @@ func _add_popup(parent_popup, path, label):
|
||||
return popup_menu
|
||||
|
||||
|
||||
func _on_item_pressed(item_index, popup_menu, path):
|
||||
var item_path = path + popup_menu.get_item_text(item_index)
|
||||
func _on_item_pressed(item_index: int, popup_menu: PopupMenu, path: String) -> void:
|
||||
var item_path := path + popup_menu.get_item_text(item_index)
|
||||
|
||||
if popup_menu.is_item_checkable(item_index):
|
||||
var checked = not popup_menu.is_item_checked(item_index)
|
||||
var checked := not popup_menu.is_item_checked(item_index)
|
||||
popup_menu.set_item_checked(item_index, checked)
|
||||
option_changed.emit(item_path, checked)
|
||||
else:
|
||||
|
||||
@@ -1,33 +1,31 @@
|
||||
extends RigidBody3D
|
||||
|
||||
var _dir := 1.0
|
||||
var _distance := 10.0
|
||||
var _walk_spd := 100.0
|
||||
var _acceleration := 22.0
|
||||
var _is_on_floor := false
|
||||
|
||||
@onready var _forward = -transform.basis.z
|
||||
@onready var _collision_shape = $CollisionShape
|
||||
@onready var _material = $CollisionShape/MeshInstance3D.get_active_material(0)
|
||||
@onready var _forward := -transform.basis.z
|
||||
@onready var _collision_shape := $CollisionShape
|
||||
@onready var _material: StandardMaterial3D = $CollisionShape/MeshInstance3D.get_active_material(0)
|
||||
|
||||
var _dir = 1.0
|
||||
var _distance = 10.0
|
||||
var _walk_spd = 100.0
|
||||
var _acceleration = 22.0
|
||||
var _is_on_floor = false
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
if not _material:
|
||||
_material = StandardMaterial3D.new()
|
||||
$CollisionShape/MeshInstance3D.set_surface_override_material(0, _material)
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float) -> void:
|
||||
if _is_on_floor:
|
||||
_material.albedo_color = Color.WHITE
|
||||
else:
|
||||
_material.albedo_color = Color.RED
|
||||
|
||||
|
||||
func _integrate_forces(state):
|
||||
var delta = state.step
|
||||
var velocity = (_forward * _dir * _walk_spd * delta) + (state.linear_velocity * Vector3.UP)
|
||||
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
||||
var delta := state.step
|
||||
var velocity := (_forward * _dir * _walk_spd * delta) + (state.linear_velocity * Vector3.UP)
|
||||
state.linear_velocity = state.linear_velocity.move_toward(velocity, _acceleration * delta)
|
||||
|
||||
if state.transform.origin.z < -_distance:
|
||||
@@ -38,13 +36,13 @@ func _integrate_forces(state):
|
||||
ground_check()
|
||||
|
||||
|
||||
func ground_check():
|
||||
var space_state = get_world_3d().direct_space_state
|
||||
var shape = PhysicsShapeQueryParameters3D.new()
|
||||
func ground_check() -> void:
|
||||
var space_state := get_world_3d().direct_space_state
|
||||
var shape := PhysicsShapeQueryParameters3D.new()
|
||||
shape.transform = _collision_shape.global_transform
|
||||
shape.shape_rid = _collision_shape.shape.get_rid()
|
||||
shape.collision_mask = 2
|
||||
var result = space_state.get_rest_info(shape)
|
||||
var result := space_state.get_rest_info(shape)
|
||||
if result:
|
||||
_is_on_floor = true
|
||||
else:
|
||||
|
||||
@@ -1,53 +1,49 @@
|
||||
extends RigidBody3D
|
||||
|
||||
|
||||
const MOUSE_DELTA_COEFFICIENT = 0.01
|
||||
const CAMERA_DISTANCE_COEFFICIENT = 0.2
|
||||
|
||||
var _picked = false
|
||||
var _last_mouse_pos = Vector2.ZERO
|
||||
var _mouse_pos = Vector2.ZERO
|
||||
var _picked := false
|
||||
var _last_mouse_pos := Vector2.ZERO
|
||||
var _mouse_pos := Vector2.ZERO
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
input_ray_pickable = true
|
||||
|
||||
|
||||
func _input(event):
|
||||
var mouse_event = event as InputEventMouseButton
|
||||
if mouse_event and not mouse_event.pressed:
|
||||
if mouse_event.button_index == MOUSE_BUTTON_LEFT:
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
if not event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
_picked = false
|
||||
|
||||
var mouse_motion = event as InputEventMouseMotion
|
||||
if mouse_motion:
|
||||
_mouse_pos = mouse_motion.position
|
||||
if event is InputEventMouseMotion:
|
||||
_mouse_pos = event.position
|
||||
|
||||
|
||||
func _input_event(_viewport, event, _click_pos, _click_normal, _shape_idx):
|
||||
var mouse_event = event as InputEventMouseButton
|
||||
if mouse_event and mouse_event.pressed:
|
||||
if mouse_event.button_index == MOUSE_BUTTON_LEFT:
|
||||
func _input_event(_camera: Camera3D, event: InputEvent, _position: Vector3, _normal: Vector3, _shape_idx: int) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
if event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
_picked = true
|
||||
_mouse_pos = mouse_event.position
|
||||
_mouse_pos = event.position
|
||||
_last_mouse_pos = _mouse_pos
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
func _physics_process(delta: float) -> void:
|
||||
if _picked:
|
||||
var mouse_delta = _mouse_pos - _last_mouse_pos
|
||||
var mouse_delta := _mouse_pos - _last_mouse_pos
|
||||
|
||||
var world_delta := Vector3.ZERO
|
||||
world_delta.x = mouse_delta.x * MOUSE_DELTA_COEFFICIENT
|
||||
world_delta.y = -mouse_delta.y * MOUSE_DELTA_COEFFICIENT
|
||||
|
||||
var camera = get_viewport().get_camera_3d()
|
||||
var camera := get_viewport().get_camera_3d()
|
||||
if camera:
|
||||
var camera_basis = camera.global_transform.basis
|
||||
var camera_basis := camera.global_transform.basis
|
||||
world_delta = camera_basis * world_delta
|
||||
|
||||
var camera_dist = camera.global_transform.origin.distance_to(global_transform.origin)
|
||||
var fov_coefficient = camera.fov / 70.0
|
||||
var camera_dist := camera.global_transform.origin.distance_to(global_transform.origin)
|
||||
const DEFAULT_CAMERA_FOV = 75.0
|
||||
var fov_coefficient := camera.fov / DEFAULT_CAMERA_FOV
|
||||
world_delta *= CAMERA_DISTANCE_COEFFICIENT * camera_dist * fov_coefficient
|
||||
|
||||
if freeze:
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
extends ScrollContainer
|
||||
|
||||
@export var auto_scroll := false
|
||||
|
||||
@export var auto_scroll: bool = false
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float) -> void:
|
||||
if auto_scroll:
|
||||
var scrollbar = get_v_scroll_bar()
|
||||
var scrollbar := get_v_scroll_bar()
|
||||
scrollbar.value = scrollbar.max_value
|
||||
|
||||
|
||||
func _on_check_box_scroll_toggled(button_pressed):
|
||||
func _on_check_box_scroll_toggled(button_pressed: bool) -> void:
|
||||
auto_scroll = button_pressed
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
extends Node
|
||||
|
||||
|
||||
enum PhysicsEngine {
|
||||
GODOT_PHYSICS,
|
||||
OTHER,
|
||||
}
|
||||
|
||||
var _engine = PhysicsEngine.OTHER
|
||||
var _engine := PhysicsEngine.OTHER
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
func _enter_tree() -> void:
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
|
||||
# Always enable visible collision shapes on startup
|
||||
# (same as the Debug > Visible Collision Shapes option).
|
||||
get_tree().debug_collisions_hint = true
|
||||
|
||||
var engine_string = ProjectSettings.get_setting("physics/3d/physics_engine")
|
||||
var engine_string: String = ProjectSettings.get_setting("physics/3d/physics_engine")
|
||||
match engine_string:
|
||||
"DEFAULT":
|
||||
_engine = PhysicsEngine.GODOT_PHYSICS
|
||||
@@ -24,7 +24,7 @@ func _enter_tree():
|
||||
_engine = PhysicsEngine.OTHER
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed(&"toggle_full_screen"):
|
||||
if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
||||
@@ -32,7 +32,7 @@ func _process(_delta):
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
||||
|
||||
if Input.is_action_just_pressed(&"toggle_debug_collision"):
|
||||
var debug_collision_enabled = not _is_debug_collision_enabled()
|
||||
var debug_collision_enabled := not _is_debug_collision_enabled()
|
||||
_set_debug_collision_enabled(debug_collision_enabled)
|
||||
if debug_collision_enabled:
|
||||
Log.print_log("Debug Collision ON")
|
||||
@@ -46,13 +46,13 @@ func _process(_delta):
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func get_physics_engine():
|
||||
func get_physics_engine() -> PhysicsEngine:
|
||||
return _engine
|
||||
|
||||
|
||||
func _set_debug_collision_enabled(enabled):
|
||||
func _set_debug_collision_enabled(enabled: bool) -> void:
|
||||
get_tree().debug_collisions_hint = enabled
|
||||
|
||||
|
||||
func _is_debug_collision_enabled():
|
||||
func _is_debug_collision_enabled() -> bool:
|
||||
return get_tree().debug_collisions_hint
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
extends Node
|
||||
|
||||
|
||||
enum LogType {
|
||||
LOG,
|
||||
ERROR,
|
||||
}
|
||||
|
||||
signal entry_logged(message, type)
|
||||
signal entry_logged(message: String, type: LogType)
|
||||
|
||||
|
||||
func print_log(message):
|
||||
func print_log(message: String) -> void:
|
||||
print(message)
|
||||
entry_logged.emit(message, LogType.LOG)
|
||||
|
||||
|
||||
func print_error(message):
|
||||
func print_error(message: String) -> void:
|
||||
push_error(message)
|
||||
printerr(message)
|
||||
entry_logged.emit(message, LogType.ERROR)
|
||||
|
||||
Reference in New Issue
Block a user