forked from TokisanGames/Terrain3D
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add slope sculpting tool TokisanGames#96
- Loading branch information
Showing
13 changed files
with
579 additions
and
29 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
project/addons/terrain_3d/editor/components/gradient_operation_builder.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
extends "res://addons/terrain_3d/editor/components/operation_builder.gd" | ||
|
||
|
||
const PointPicker: Script = preload("res://addons/terrain_3d/editor/components/point_picker.gd") | ||
|
||
|
||
func _get_point_picker() -> PointPicker: | ||
return tool_settings.settings["gradient_points"] | ||
|
||
|
||
func _get_brush_size() -> float: | ||
return tool_settings.get_setting("size") | ||
|
||
|
||
func _is_drawable() -> bool: | ||
return tool_settings.get_setting("drawable") | ||
|
||
|
||
func is_picking() -> bool: | ||
return not _get_point_picker().all_points_selected() | ||
|
||
|
||
func pick(p_global_position: Vector3, p_terrain: Terrain3D) -> void: | ||
if not _get_point_picker().all_points_selected(): | ||
_get_point_picker().add_point(p_global_position) | ||
|
||
|
||
func is_ready() -> bool: | ||
return _get_point_picker().all_points_selected() and not _is_drawable() | ||
|
||
|
||
func apply_operation(p_editor: Terrain3DEditor, p_global_position: Vector3, p_camera_direction: float) -> void: | ||
var points: PackedVector3Array = _get_point_picker().get_points() | ||
assert(points.size() == 2) | ||
assert(not _is_drawable()) | ||
|
||
var brush_size: float = _get_brush_size() | ||
assert(brush_size > 0.0) | ||
|
||
var start: Vector3 = points[0] | ||
var end: Vector3 = points[1] | ||
|
||
p_editor.start_operation(start) | ||
|
||
var dir: Vector3 = (end - start).normalized() | ||
|
||
var pos: Vector3 = start | ||
while dir.dot(end - pos) > 0.0: | ||
p_editor.operate(pos, p_camera_direction) | ||
pos += dir * brush_size * 0.333 | ||
|
||
p_editor.stop_operation() | ||
|
||
_get_point_picker().clear() | ||
|
23 changes: 23 additions & 0 deletions
23
project/addons/terrain_3d/editor/components/operation_builder.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
extends RefCounted | ||
|
||
|
||
const ToolSettings: Script = preload("res://addons/terrain_3d/editor/components/tool_settings.gd") | ||
|
||
|
||
var tool_settings: ToolSettings | ||
|
||
|
||
func is_picking() -> bool: | ||
return false | ||
|
||
|
||
func pick(p_global_position: Vector3, p_terrain: Terrain3D) -> void: | ||
pass | ||
|
||
|
||
func is_ready() -> bool: | ||
return false | ||
|
||
|
||
func apply_operation(editor: Terrain3DEditor, p_global_position: Vector3, p_camera_direction: float) -> void: | ||
pass |
89 changes: 89 additions & 0 deletions
89
project/addons/terrain_3d/editor/components/point_picker.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
extends HBoxContainer | ||
|
||
|
||
signal pressed | ||
signal value_changed | ||
|
||
|
||
const ICON_PICKER: String = "res://addons/terrain_3d/icons/icon_picker.svg" | ||
const ICON_PICKER_CHECKED: String = "res://addons/terrain_3d/icons/icon_picker_checked.svg" | ||
const MAX_POINTS: int = 2 | ||
|
||
|
||
var icon_picker: Texture2D | ||
var icon_picker_checked: Texture2D | ||
var points: PackedVector3Array | ||
var picking_index: int = -1 | ||
|
||
|
||
func _init() -> void: | ||
icon_picker = load(ICON_PICKER) | ||
icon_picker_checked = load(ICON_PICKER_CHECKED) | ||
|
||
var label := Label.new() | ||
label.text = "Points:" | ||
add_child(label) | ||
|
||
points.resize(MAX_POINTS) | ||
|
||
for i in range(MAX_POINTS): | ||
var button := Button.new() | ||
button.icon = icon_picker | ||
button.tooltip_text = "Pick point on the Terrain" | ||
button.set_meta(&"point_index", i) | ||
button.pressed.connect(_on_button_pressed.bind(i)) | ||
add_child(button) | ||
|
||
_update_buttons() | ||
|
||
|
||
func _on_button_pressed(button_index: int) -> void: | ||
points[button_index] = Vector3.ZERO | ||
picking_index = button_index | ||
_update_buttons() | ||
pressed.emit() | ||
|
||
|
||
func _update_buttons() -> void: | ||
for child in get_children(): | ||
if child is Button: | ||
_update_button(child) | ||
|
||
|
||
func _update_button(button: Button) -> void: | ||
var index: int = button.get_meta(&"point_index") | ||
|
||
if points[index] != Vector3.ZERO: | ||
button.icon = icon_picker_checked | ||
else: | ||
button.icon = icon_picker | ||
|
||
|
||
func clear() -> void: | ||
points.fill(Vector3.ZERO) | ||
_update_buttons() | ||
value_changed.emit() | ||
|
||
|
||
func all_points_selected() -> bool: | ||
return points.count(Vector3.ZERO) == 0 | ||
|
||
|
||
func add_point(p_value: Vector3) -> void: | ||
if points.has(p_value): | ||
return | ||
|
||
if picking_index != -1: | ||
points[picking_index] = p_value | ||
picking_index = -1 | ||
else: | ||
for i in range(MAX_POINTS): | ||
if points[i] == Vector3.ZERO: | ||
points[i] = p_value | ||
break | ||
_update_buttons() | ||
value_changed.emit() | ||
|
||
|
||
func get_points() -> PackedVector3Array: | ||
return points |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.