I just wanted the Path3D to bind to the surface of the MeshInstance. Maybe there is a easier way?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ivan643

I made a small plugin to turn a Path3d into a MeshInstance to draw the level geometry. (Grey box)
But I wanted a fast tool, and Path3d points appear at some distance from the camera, which is inconvenient.

Editor’s camera need me only to cast surface. In Godo 3.5.1 I can use forward_spatial_gui_input in plugin, but In 4.0 it replaced by _forward_3d_gui_input(viewport_camera: Camera3D, event: InputEvent) and just don’t work.


Edited. Found the answer as soon as I asked the question.

func _forward_3d_gui_input(p_camera: Camera3D, p_event: InputEvent):
	if p_event is InputEventMouseButton:
		if p_event.button_index == MOUSE_BUTTON_LEFT:
			var viewport = p_camera.get_viewport()
			var viewport_container = viewport.get_parent()
			var screen_pos = viewport.get_mouse_position()
			var origin = p_camera.project_ray_origin(screen_pos)
			var dir = p_camera.project_ray_normal(screen_pos)
			var ray_distance := p_camera.far
			
			var cast = PhysicsRayQueryParameters3D.new()
			cast.from = origin
			cast.to = origin + dir * ray_distance
			
			var root = get_tree().get_edited_scene_root()
			var space = root.get_world_3d().direct_space_state
			
			# Transfer to the selected object.
			now_obj.raycast_result = space.intersect_ray(cast)
			# Or save local to use.
			# _raycast_result = space.intersect_ray(cast)


func _handles(object: Object):
	if object is Path3D:
		now_obj = object
		return true
	return false

editing because i can’t delete

clarkfilio | 2023-04-28 14:18