Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Wiskam | |
Old Version | Published before Godot 3 was released. |
Hi.
I would like to check if some 3D meshes are behind a 2D TextureFrame.
I’m using the TextureFrame like a “Selection Rectangle”, in the hope of selecting meshes. It’s surely not the better way to do this, but I didn’t find something else with my skill.
The code isn’t optimized and cleaned at all, unfortunately it’s something I planned to do later.
func_process(delta):
## Add a verification if the mouse LEFT button is pressed (see select rectangle code)
if(Input.is_mouse_button_pressed(BUTTON_LEFT)):
mouseleftclic = true
if not (Input.is_mouse_button_pressed(BUTTON_LEFT)):
mouseleftclic = false
## Launch the selection rectangle if selection is active
if (selecactive == true):
## If no SelectRect, create a new one
if (mouseleftclic == true) && (newrectvisible == false):
newrect = TextureFrame.new()
newrect.set_texture(load("res://tex/rect.tex"))
newrect.set_global_pos(Vector2(selecfrom.x, selecfrom.y))
newrect.set_size(Vector2(0,0))
newrect.set_expand(true)
newrect.set_name("SelectRect")
get_node("Node2D").add_child(newrect)
newrectvisible = true
## If SelectRect exists, delete it when the clic is over
elif (mouseleftclic == false):
selecactive = false
if (newrectvisible == true):
if << "3D MESHES ARE BEHIND 2D TEXTURE FRAME" >> :
get_node("PlanetOrbite/Planet/SpatialTree1").queue_free()
get_node("Node2D/SelectRect").queue_free()
newrectvisible = false
func _input(event):
## LEFT CLIC FOR SELECTION RECTANGLE
if(event.type == InputEvent.MOUSE_BUTTON):
if(Input.is_mouse_button_pressed(BUTTON_LEFT)):
## Because I have several Cameras in my Scene
if (camera3d.is_current()):
selecfrom = event.pos
selecactive = true
The << “3D MESHES ARE BEHIND 2D TEXTURE FRAME” >> is what I would like to do if some 3D meshes (one for the moment) is behind my 2D TextureFrame which is the selection rectangle.
Here is a screenshot of my Scene when nothing happens:
Here is my Scene when I’m dragging the mouse left clic:
I checked a bit the doc for the Raycasting things but not sure to figure out how it’s working, I feel it’s what I need but I can’t really understand it for my problem.
Thanks !