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

Add Color & Roughness painting #91

Merged
merged 10 commits into from
Jul 4, 2023
Merged
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
260 changes: 196 additions & 64 deletions project/addons/terrain/editor/components/tool_settings.gd

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions project/addons/terrain/editor/components/toolbar.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extends VBoxContainer


signal tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation)

const ICON_REGION_ADD: Texture2D = preload("res://addons/terrain/icons/icon_map_add.svg")
Expand All @@ -11,12 +12,15 @@ const ICON_HEIGHT_FLAT: Texture2D = preload("res://addons/terrain/icons/icon_hei
const ICON_PAINT_TEXTURE: Texture2D = preload("res://addons/terrain/icons/icon_brush.svg")
const ICON_SPRAY_TEXTURE: Texture2D = preload("res://addons/terrain/icons/icon_spray.svg")
const ICON_PAINT_COLOR: Texture2D = preload("res://addons/terrain/icons/icon_color.svg")
const ICON_PAINT_ROUGHNESS: Texture2D = preload("res://addons/terrain/icons/icon_roughness.svg")

var tool_group: ButtonGroup = ButtonGroup.new()


func _init() -> void:
set_custom_minimum_size(Vector2(32, 0))


func _ready() -> void:
tool_group.connect("pressed", _on_tool_selected)

Expand All @@ -32,10 +36,12 @@ func _ready() -> void:
add_tool_button(Terrain3DEditor.TEXTURE, Terrain3DEditor.ADD, "Spray Texture", ICON_SPRAY_TEXTURE, tool_group)
add_child(HSeparator.new())
add_tool_button(Terrain3DEditor.COLOR, Terrain3DEditor.REPLACE, "Paint Color", ICON_PAINT_COLOR, tool_group)
add_tool_button(Terrain3DEditor.ROUGHNESS, Terrain3DEditor.REPLACE, "Paint Roughness", ICON_PAINT_ROUGHNESS, tool_group)

var buttons: Array[BaseButton] = tool_group.get_buttons()
buttons[0].set_pressed(true)


func add_tool_button(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation,
p_tip: String, p_icon: Texture2D, p_group: ButtonGroup) -> void:

Expand All @@ -50,6 +56,7 @@ func add_tool_button(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.
button.set_h_size_flags(SIZE_SHRINK_END)
add_child(button)


func _on_tool_selected(p_button: BaseButton) -> void:
emit_signal("tool_changed", p_button.get_meta("Tool", -1), p_button.get_meta("Operation", -1))

121 changes: 121 additions & 0 deletions project/addons/terrain/editor/components/ui.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
extends Node
class_name Terrain3DUI


# Includes
const Toolbar: Script = preload("res://addons/terrain/editor/components/toolbar.gd")
const ToolSettings: Script = preload("res://addons/terrain/editor/components/tool_settings.gd")

var plugin: Terrain3DEditorPlugin
var toolbar: Toolbar
var toolbar_settings: ToolSettings
var setting_has_changed: bool = false
var visible: bool = false
var picking: int = Terrain3DEditor.TOOL_MAX
var picking_callback: Callable


func _enter_tree() -> void:
toolbar = Toolbar.new()
toolbar.hide()
toolbar.connect("tool_changed", _on_tool_changed)

toolbar_settings = ToolSettings.new()
toolbar_settings.connect("setting_changed", _on_setting_changed)
toolbar_settings.connect("picking", _on_picking)
toolbar_settings.hide()

plugin.add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, toolbar)
plugin.add_control_to_bottom(toolbar_settings)


func _exit_tree() -> void:
plugin.remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, toolbar)
toolbar_settings.get_parent().remove_child(toolbar_settings)
toolbar.queue_free()
toolbar_settings.queue_free()


func set_visible(p_visible: bool) -> void:
visible = p_visible
toolbar.set_visible(p_visible)

if p_visible:
p_visible = plugin.editor.get_tool() != Terrain3DEditor.REGION
toolbar_settings.set_visible(p_visible)


func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation) -> void:
if not visible:
return

if plugin.editor:
plugin.editor.set_tool(p_tool)
plugin.editor.set_operation(p_operation)
print_debug("Setting tool: %s, operation: %s" % [ p_tool, p_operation ])

if p_tool != Terrain3DEditor.REGION:
# Select which settings to hide. Options:
# size, opactiy, height, slope, color, roughness, (height|color|roughness) picker
var to_hide: PackedStringArray = []

if p_tool == Terrain3DEditor.HEIGHT:
to_hide.push_back("slope")
to_hide.push_back("color")
to_hide.push_back("color picker")
to_hide.push_back("roughness")
to_hide.push_back("roughness picker")
to_hide.push_back("slope")

elif p_tool == Terrain3DEditor.TEXTURE:
to_hide.push_back("height")
to_hide.push_back("height picker")
to_hide.push_back("color")
to_hide.push_back("color picker")
to_hide.push_back("roughness")
to_hide.push_back("roughness picker")
to_hide.push_back("slope")

elif p_tool == Terrain3DEditor.COLOR:
to_hide.push_back("height")
to_hide.push_back("height picker")
to_hide.push_back("roughness")
to_hide.push_back("roughness picker")
to_hide.push_back("slope")

elif p_tool == Terrain3DEditor.ROUGHNESS:
to_hide.push_back("height")
to_hide.push_back("height picker")
to_hide.push_back("color")
to_hide.push_back("color picker")
to_hide.push_back("slope")

toolbar_settings.hide_settings(to_hide)

toolbar_settings.set_visible(p_tool != Terrain3DEditor.REGION)
_on_setting_changed()
plugin.update_grid()


func _on_setting_changed() -> void:
if not visible:
return
var brush_data: Dictionary = {
"size": int(toolbar_settings.get_setting("size")),
"opacity": toolbar_settings.get_setting("opacity") / 100.0,
"color": toolbar_settings.get_setting("color"),
"roughness": toolbar_settings.get_setting("roughness"),
"gamma": toolbar_settings.get_setting("gamma"),
"height": toolbar_settings.get_setting("height"),
"jitter": toolbar_settings.get_setting("jitter"),
"image": toolbar_settings.get_setting("brush"),
"automatic_regions": toolbar_settings.get_setting("automatic_regions"),
"align_with_view": toolbar_settings.get_setting("align_with_view"),
"index": plugin.surface_list.get_selected_index(),
}
plugin.editor.set_brush_data(brush_data)


func _on_picking(type: int, callback: Callable) -> void:
picking = type
picking_callback = callback
Loading