-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Viewport.push_input's second parameter: in_local_coords not working #72657
Comments
Why close? |
my bad, reopened |
The difference between In As far as I can tell this is a problem with the coordinate systems. And you are missing the transformation from the mouse-click within the 3D-world to the 2D local coordinates of the Texture. In order to make
Maybe we could improve the |
I see. Thank you very much. Do you have any plan to make an out-of-the-box method to deal with such cases? And I'm curious about the exception of embedded Windows and SubViewports in InputEvent process.
and
btw, I notice there isn't a 3D version SubViewportContainer. Any problem prevents Viewports to send events to its SubViewports? (complex, no need and no time for this at the moment, maybe?) I ask this because it's kind of counter-intuitive and it might break the simplicity and coherence of Godot's node-based design concept. |
It was a design decision, that Embedded Windows only receive input events, if they are focused, so there is a different mechanism for them and the above mentioned restriction is actually a necessity. (See step 2 in the cited InputEvent tutorial) I believe, that a 3D-variant of |
I have created a small project file that shows the general idea of how to implement event propagation for 3D. SubViewportEventPropagationTutorial.zip Advanced features like Drag and Drop would probably need more work. This function does the heavy lifting of the coordinate-transforms. func _on_input_event(_camera: Camera3D, event: InputEvent, pos: Vector3, _normal: Vector3, _shape_idx: int):
# Position of the event in Sprite3D local coordinates.
var texture_3d_position = s.get_global_transform().affine_inverse() * pos
if !is_zero_approx(texture_3d_position.z):
# Discard event because event didn't happen on the side of the Sprite3D.
return
# Position of the event relative to the texture.
var texture_position: Vector2 = Vector2(texture_3d_position.x, -texture_3d_position.y) / s.pixel_size - s.get_item_rect().position
# Send mouse event.
if event is InputEventMouse:
var e: InputEvent = event.duplicate()
e.set_position(texture_position)
e.set_global_position(texture_position)
v.push_input(e) |
Thx again! A lot to learn from your turorial. |
I just found, that there is already a proposal for a similar use-case: godotengine/godot-proposals#4093 |
hope there wil be more progresses made to break totally the wall of 2D world and 3D world : P |
Godot version
v4.0.beta17.official.c40020513
System information
Windows 10, Forward+, NVIDIA GeForce GTX 860M
Issue description
I use a SubViewport as the Sprite3D's texture to render a 2D-scene in this 3D scene.
In order to trigger mouse event into the 2D scene, I use this script:
The second parameter of
push_input
behaves like having no effect whether it'strue
orfalse
.this function's information in GODOT API DOC:
https://docs.godotengine.org/en/latest/classes/class_viewport.html#class-viewport-method-push-input
Steps to reproduce
$SubViewport.push_input(event, false)
second parameter to true or falseMinimal reproduction project
test for viewport.zip
The text was updated successfully, but these errors were encountered: