Repository: godot
Issue: [PhysicsDirectSpaceState] Impossible to retrieve shape if owner_id has more than one shape
Labels: bug,documentation,topic:physics

### Godot version

3.4.2.stable [Bullet Physics]

### System information

Win10

### Issue description

I've been doing some custom collision stuff, and that has involved using `intersect_shape` from `PhysicsDirectSpaceState`.

Now according to the documentation for this we have the following:
```
Checks the intersections of a shape, given through a PhysicsShapeQueryParameters object, against the space. The intersected shapes are returned in an array containing dictionaries with the following fields:

collider: The colliding object.

collider_id: The colliding object's ID.

rid: The intersecting object's RID.

shape: The shape index of the colliding shape.
```

To retrieve the actual `Shape`, I have this code running:


    var collide_shapes: Array = space_state.intersect_shape(query_params);

    for i in collide_shapes.size():
        var col = collide_shapes[i];
        var s_idx: int = col.shape;
        var shape_owner_id = col.collider.shape_find_owner(s_idx);
        var colshape = col.collider.shape_owner_get_shape(shape_owner_id, s_idx);


In this case, `s_idx` is 500. When I get the `shape_owner_id`, it's also 500. This is expected since I'm using regular CollisionShapes, and they appear to create one owner_id for one Shape.

However it all breaks down in the final line - `shape_owner_get_shape` actually expects the index of the shape _in its own internal array of shapes_, and not the actual shape index that Godot generates for a Shape.

Simple solution, right? Change the last line to:
`
var colshape = col.collider.shape_owner_get_shape(shape_owner_id, 0);
`
and it all works fine. Awesome! 

So what's the issue?
Well according to the documentation on `CollisionObject`, we can read the following:
```
The CollisionObject can have any number of shape owners. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the shape_owner_* methods.
```

Now this is a problem! If we have more than one Shape per `owner_id`, then how do we know what index to pass into `shape_owner_get_shape()`?

For proof that this function is not behaving as documented, I've taken this directly from Godot's C++ source:
```

Ref<Shape3D> CollisionObject3D::shape_owner_get_shape(uint32_t p_owner, int p_shape) const {
	ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape3D>());
	ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape3D>());

	return shapes[p_owner].shapes[p_shape].shape;
}
```

That `shapes` member is a simple Vector, and not a mapping of any kind.

This means there's either an oversight or a bug somewhere. If `intersect_shape` were to return a local array offset index, then we would never be able to get the `owner_id`. But in its current state, we'll never be able to find our Shape if the owner has more than one, assuming that the shape was created with a shape index that's higher than the length of the internally stored array of owned shapes.

### Steps to reproduce

I've attached a minimal example project to demonstrate the following steps:

- Create a bunch of CollisionShapes on a StaticBody
- When the game starts, remove the first owner_id (since one owner_id will be created for each shape)
- Grab the now-unreferenced shape and add it to a different owner_id [There will now be one owner_id with two shapes]

- Perform a intersect_shape against the shapes in the scene
- Try and find a way to obtain the 2nd shape from the owner_id containing multiple shapes using the result of the intersect_shape, the shape index it provides and the CollisionObject.shape_owner_* functions.

You'll quickly notice it's impossible using the methods given to us. 

Of course, there's probably a hackaround by comparing instance_ids, but this seems like a bug or an oversight and I believe it requires some attention.

===
MINIMAL REPRO PROJECT

Please see `multiple_shapes.gs` to see what I'm doing regarding setting up collision shapes and their owners.
Then take a look in `reproduce.gd` to see where the problems lie with intersect_shapes.

### Minimal reproduction project

[shape_id_problem.zip](https://github.com/godotengine/godot/files/7966340/shape_id_problem.zip)