godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.92k stars 20.17k forks source link

PhysicsDirectSpaceState3D.intersect_shape is limited to 2048 results #83541

Open kubecz3k opened 11 months ago

kubecz3k commented 11 months ago

Godot version

4.2 beta, dce1aab174369e9124507f4614fc007301df52e7

System information

Godot v4.2.beta (dce1aab17) - Ubuntu 22.04.1 LTS 22.04 - X11 - Vulkan (Forward+) - dedicated AMD RADV NAVY_FLOUNDER () - AMD Ryzen 9 3900X 12-Core Processor (24 Threads)

Issue description

It's impossible to perform a physic engine query that would return more then 2048 results, max_results argument is simply ignored.

Things that were tested:

Steps to reproduce

  1. Create new scene
  2. In ready add let's say 10 000 areas using PhysicsServer3D together with sphere shapes
    const SCALE = 0.1
    func _ready() -> void:
    space_id = PhysicsServer3D.space_create()
    for idx_x in range(1000):
        for idx_y in range(1000):
            var area_id: RID = PhysicsServer3D.area_create()
            var position: Vector3 = Vector3(idx_x, idx_y, 0)
            var transform: Transform3D = Transform3D(Basis(), Vector3(idx_x*SCALE, idx_y*SCALE, 0))
            var shape_id: RID = PhysicsServer3D.sphere_shape_create()
            PhysicsServer3D.shape_set_data(shape_id, 0.5 * SCALE)
            PhysicsServer3D.area_set_space(area_id, space_id)
            PhysicsServer3D.area_add_shape(area_id, shape_id)
            PhysicsServer3D.area_set_transform(area_id, transform)
            PhysicsServer3D.area_set_collision_layer(area_id, 1)
            PhysicsServer3D.area_set_collision_mask(area_id, 0)
  3. In _physics_process perform a PhysicsServer3D query using PhysicsShapeQueryParameters3D
    func _physics_process(delta: float) -> void:
    var physics_direct_state: PhysicsDirectSpaceState3D = PhysicsServer3D.space_get_direct_state(space_id)
    var box_shape_query: PhysicsShapeQueryParameters3D = PhysicsShapeQueryParameters3D.new()
    var box_shape: BoxShape3D = BoxShape3D.new()
    box_shape_query.collide_with_areas = true
    box_shape_query.collide_with_bodies = false
    box_shape_query.collision_mask = 1
    box_shape.size = Vector3(1000,1000,100)
    box_shape_query.shape = box_shape
    var result = physics_direct_state.intersect_shape(box_shape_query, 100000)
    print("results nmb: ", result.size())
  4. Notice the nmb of results in a query is 2048 while it should be 100000

Minimal reproduction project

PhysicQueryResultsCountIssue.zip

AThousandShips commented 11 months ago

This is in fact a hard coded limit, should be documented at minimum

kubecz3k commented 11 months ago

I expected it's hard-coded, I think it should be a setting in ProjectSettings