Skip to content
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

move cursor decals to shader #538

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions project/addons/terrain_3d/src/editor_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -157,36 +157,39 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->

_read_input(p_event)

## Setup active camera & viewport
# Always update this for all inputs, as the mouse position can move without
# necessarily being a InputEventMouseMotion object. get_intersection() also
Copy link
Owner

@TokisanGames TokisanGames Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the mouse position can move without necessarily being a InputEventMouseMotion

👀🤯

# returns the last frame position, and should be updated more frequently.

# Snap terrain to current camera
terrain.set_camera(p_viewport_camera)

# Detect if viewport is set to half_resolution
# Structure is: Node3DEditorViewportContainer/Node3DEditorViewport(4)/SubViewportContainer/SubViewport/Camera3D
var editor_vpc: SubViewportContainer = p_viewport_camera.get_parent().get_parent()
var full_resolution: bool = false if editor_vpc.stretch_shrink == 2 else true

## Get mouse location on terrain
# Project 2D mouse position to 3D position and direction
var vp_mouse_pos: Vector2 = editor_vpc.get_local_mouse_position()
var mouse_pos: Vector2 = vp_mouse_pos if full_resolution else vp_mouse_pos / 2
var camera_pos: Vector3 = p_viewport_camera.project_ray_origin(mouse_pos)
var camera_dir: Vector3 = p_viewport_camera.project_ray_normal(mouse_pos)

# If region tool, grab mouse position without considering height
if editor.get_tool() == Terrain3DEditor.REGION:
var t = -Vector3(0, 1, 0).dot(camera_pos) / Vector3(0, 1, 0).dot(camera_dir)
mouse_global_position = (camera_pos + t * camera_dir)
else:
#Else look for intersection with terrain
var intersection_point: Vector3 = terrain.get_intersection(camera_pos, camera_dir, true)
if intersection_point.z > 3.4e38 or is_nan(intersection_point.y): # max double or nan
return AFTER_GUI_INPUT_STOP
mouse_global_position = intersection_point

## Handle mouse movement
if p_event is InputEventMouseMotion:
## Setup active camera & viewport

# Snap terrain to current camera
terrain.set_camera(p_viewport_camera)

# Detect if viewport is set to half_resolution
# Structure is: Node3DEditorViewportContainer/Node3DEditorViewport(4)/SubViewportContainer/SubViewport/Camera3D
var editor_vpc: SubViewportContainer = p_viewport_camera.get_parent().get_parent()
var full_resolution: bool = false if editor_vpc.stretch_shrink == 2 else true

## Get mouse location on terrain

# Project 2D mouse position to 3D position and direction
var mouse_pos: Vector2 = p_event.position if full_resolution else p_event.position/2
var camera_pos: Vector3 = p_viewport_camera.project_ray_origin(mouse_pos)
var camera_dir: Vector3 = p_viewport_camera.project_ray_normal(mouse_pos)

# If region tool, grab mouse position without considering height
if editor.get_tool() == Terrain3DEditor.REGION:
var t = -Vector3(0, 1, 0).dot(camera_pos) / Vector3(0, 1, 0).dot(camera_dir)
mouse_global_position = (camera_pos + t * camera_dir)
else:
# Else look for intersection with terrain
var intersection_point: Vector3 = terrain.get_intersection(camera_pos, camera_dir, true)
if intersection_point.z > 3.4e38 or is_nan(intersection_point.y): # max double or nan
return AFTER_GUI_INPUT_STOP
mouse_global_position = intersection_point

ui.update_decal()

if _input_mode != -1: # Not cam rotation
Expand All @@ -206,8 +209,6 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->

return AFTER_GUI_INPUT_PASS

ui.update_decal()

if p_event is InputEventMouseButton and _input_mode > 0:
if p_event.is_pressed():
# If picking
Expand Down
2 changes: 2 additions & 0 deletions project/addons/terrain_3d/src/tool_settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ func _ready() -> void:
"unit":"γ", "range":Vector3(0.1, 2.0, 0.01) })
add_setting({ "name":"jitter", "type":SettingType.SLIDER, "list":advanced_list, "default":50,
"unit":"%", "range":Vector3(0, 100, 1) })
add_setting({ "name":"crosshair_threshold", "type":SettingType.SLIDER, "list":advanced_list, "default":16.,
"unit":"m", "range":Vector3(0, 200, 1) })


func create_submenu(p_parent: Control, p_button_name: String, p_layout: Layout, p_hover_pop: bool = true) -> Container:
Expand Down
Loading
Loading