mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-05 07:20:07 +01:00
Update contact tests in physics tests for 2D & 3D
- Create bodies by duplicating the ones from the scene to allow custom settings on them for testing purpose - Rename 3D test with multiple groups of bodies "Contact Islands" instead of "Contacts Extended" for clarity - Added "Contact Islands" test for 2D - Fixed log spamming with "Contact Islands" tests due to printing log messages for each group of bodies - Added parameter to randomize spawn positions in order to make contact separation more balanced (avoids artifacts like a huge column for circles in 2D test) - Using smaller shapes and larger amount of objects by default to test more extreme case
This commit is contained in:
@@ -43,8 +43,8 @@ var _tests = [
|
||||
"path": "res://tests/performance/test_perf_contacts.tscn",
|
||||
},
|
||||
{
|
||||
"id" : "Performance Tests/Contacts Extended",
|
||||
"path" : "res://tests/performance/test_perf_contacts_extended.tscn",
|
||||
"id" : "Performance Tests/Contact Islands",
|
||||
"path" : "res://tests/performance/test_perf_contact_islands.tscn",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@@ -6,15 +6,21 @@
|
||||
[ext_resource path="res://tests/static_scene.tscn" type="PackedScene" id=5]
|
||||
|
||||
[sub_resource type="BoxShape" id=1]
|
||||
extents = Vector3( 0.5, 0.5, 0.5 )
|
||||
|
||||
[sub_resource type="CapsuleShape" id=2]
|
||||
radius = 0.5
|
||||
height = 0.5
|
||||
|
||||
[sub_resource type="CylinderShape" id=3]
|
||||
radius = 0.5
|
||||
height = 1.0
|
||||
|
||||
[sub_resource type="ConvexPolygonShape" id=4]
|
||||
points = PoolVector3Array( -0.7, 0, -0.7, -0.3, 0, 0.8, 0.8, 0, -0.3, 0, -1, 0 )
|
||||
|
||||
[sub_resource type="SphereShape" id=5]
|
||||
radius = 0.5
|
||||
|
||||
[sub_resource type="PlaneShape" id=6]
|
||||
|
||||
@@ -22,7 +28,8 @@ points = PoolVector3Array( -0.7, 0, -0.7, -0.3, 0, 0.8, 0.8, 0, -0.3, 0, -1, 0 )
|
||||
script = ExtResource( 1 )
|
||||
_enable_debug_collision = false
|
||||
spawns = [ "SpawnTarget1", "SpawnTarget2", "SpawnTarget3", "SpawnTarget4", "SpawnTarget5", "SpawnTarget6", "SpawnTarget7", "SpawnTarget8", "SpawnTarget9", "SpawnTarget10", "SpawnTarget11", "SpawnTarget12", "SpawnTarget13", "SpawnTarget14", "SpawnTarget15", "SpawnTarget16" ]
|
||||
spawn_count = 50
|
||||
spawn_count = 200
|
||||
spawn_randomize = Vector3( 0.2, 0.2, 0.2 )
|
||||
|
||||
[node name="Options" parent="." instance=ExtResource( 4 )]
|
||||
|
||||
@@ -98,6 +105,7 @@ shape = SubResource( 3 )
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, 0 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="DynamicShapes/RigidBodyConvex"]
|
||||
transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0 )
|
||||
shape = SubResource( 4 )
|
||||
|
||||
[node name="RigidBodySphere" type="RigidBody" parent="DynamicShapes"]
|
||||
@@ -8,8 +8,9 @@ const OPTION_TYPE_CAPSULE = "Shape type/Capsule"
|
||||
const OPTION_TYPE_CYLINDER = "Shape type/Cylinder"
|
||||
const OPTION_TYPE_CONVEX = "Shape type/Convex"
|
||||
|
||||
export(Array) var spawns = Array()
|
||||
export(Array, NodePath) var spawns = Array()
|
||||
export(int) var spawn_count = 100
|
||||
export(Vector3) var spawn_randomize
|
||||
|
||||
var _object_templates = []
|
||||
|
||||
@@ -148,37 +149,47 @@ func _start_all_types():
|
||||
|
||||
func _spawn_objects(type_index):
|
||||
var template_node = _object_templates[type_index]
|
||||
|
||||
Log.print_log("* Spawning: " + template_node.name)
|
||||
|
||||
for spawn in spawns:
|
||||
var spawn_parent = get_node(spawn)
|
||||
|
||||
Log.print_log("* Spawning: " + template_node.name)
|
||||
|
||||
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) as CollisionShape
|
||||
var shape = collision.shape.duplicate()
|
||||
var body = create_rigidbody(shape, false, collision.transform)
|
||||
var collision = template_node.get_child(0).duplicate()
|
||||
collision.shape = collision.shape.duplicate()
|
||||
var body = template_node.duplicate()
|
||||
body.transform = Transform.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)
|
||||
body.remove_child(prev_collision)
|
||||
prev_collision.queue_free()
|
||||
body.add_child(collision)
|
||||
body.set_sleeping(true)
|
||||
spawn_parent.add_child(body)
|
||||
|
||||
|
||||
func _activate_objects():
|
||||
Log.print_log("* Activating")
|
||||
|
||||
for spawn in spawns:
|
||||
var spawn_parent = get_node(spawn)
|
||||
|
||||
Log.print_log("* Activating")
|
||||
|
||||
for node_index in range(spawn_parent.get_child_count()):
|
||||
var node = spawn_parent.get_child(node_index) as RigidBody
|
||||
node.set_sleeping(false)
|
||||
|
||||
|
||||
func _despawn_objects():
|
||||
Log.print_log("* Despawning")
|
||||
|
||||
for spawn in spawns:
|
||||
var spawn_parent = get_node(spawn)
|
||||
|
||||
Log.print_log("* Despawning")
|
||||
|
||||
# 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):
|
||||
|
||||
@@ -23,6 +23,7 @@ script = ExtResource( 2 )
|
||||
_enable_debug_collision = false
|
||||
spawns = [ "SpawnTarget1" ]
|
||||
spawn_count = 500
|
||||
spawn_randomize = Vector3( 0.2, 0.2, 0.2 )
|
||||
|
||||
[node name="Options" parent="." instance=ExtResource( 4 )]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user