Is it possible to select 3D Meshes with a 2D TextureFrame ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Wiskam
:warning: 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 !

:bust_in_silhouette: Reply From: volzhs

If I were you, I would like to do this way.

  1. get screen coordination of all pickable object and save to array when click start
  2. check if coordination is in rect while dragging
  3. make it selected when click end

Thanks for your reply.
Yep that would be what I would like to do but how I can check the screen coordination of theses objects ? I can’t figure out how to get the pos on screen.

Wiskam | 2016-05-07 15:34

:bust_in_silhouette: Reply From: TheoXD

Based on how box selection works in the editor, here’s the same done in GDscript: http://blenderstars.com/uploads/tmp/BoxSelect.zip Might add it to demos soon.

:bust_in_silhouette: Reply From: Sakaki

Hey, I made an example you can easily implement on your project
You can download it here