added terrain3d
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# Asset Dock for Terrain3D
|
||||
@tool
|
||||
extends PanelContainer
|
||||
#class_name Terrain3DAssetDock
|
||||
|
||||
signal confirmation_closed
|
||||
signal confirmation_confirmed
|
||||
@@ -444,9 +445,6 @@ class ListContainer extends Container:
|
||||
func _ready() -> void:
|
||||
set_v_size_flags(SIZE_EXPAND_FILL)
|
||||
set_h_size_flags(SIZE_EXPAND_FILL)
|
||||
focus_style = get_theme_stylebox("focus", "Button").duplicate()
|
||||
focus_style.set_border_width_all(2)
|
||||
focus_style.set_border_color(Color(1, 1, 1, .67))
|
||||
|
||||
|
||||
func clear() -> void:
|
||||
@@ -588,17 +586,13 @@ class ListContainer extends Container:
|
||||
last_offset = 3
|
||||
set_selected_id(clamp(selected_id, 0, entries.size() - last_offset))
|
||||
|
||||
# Update editor with selected brush
|
||||
plugin.ui._on_setting_changed()
|
||||
|
||||
|
||||
func get_selected_id() -> int:
|
||||
return selected_id
|
||||
|
||||
|
||||
|
||||
func set_entry_width(value: float) -> void:
|
||||
width = clamp(value, 56, 230)
|
||||
width = clamp(value, 66, 230)
|
||||
redraw()
|
||||
|
||||
|
||||
@@ -651,45 +645,86 @@ class ListEntry extends VBoxContainer:
|
||||
var is_selected: bool = false
|
||||
var asset_list: Terrain3DAssets
|
||||
|
||||
var button_clear: TextureButton
|
||||
var button_edit: TextureButton
|
||||
var name_label: Label
|
||||
|
||||
@onready var add_icon: Texture2D = get_theme_icon("Add", "EditorIcons")
|
||||
@onready var button_row := HBoxContainer.new()
|
||||
@onready var button_clear := TextureButton.new()
|
||||
@onready var button_edit := TextureButton.new()
|
||||
@onready var spacer := Control.new()
|
||||
@onready var button_enabled := TextureButton.new()
|
||||
@onready var clear_icon: Texture2D = get_theme_icon("Close", "EditorIcons")
|
||||
@onready var edit_icon: Texture2D = get_theme_icon("Edit", "EditorIcons")
|
||||
@onready var enabled_icon: Texture2D = get_theme_icon("GuiVisibilityVisible", "EditorIcons")
|
||||
@onready var disabled_icon: Texture2D = get_theme_icon("GuiVisibilityHidden", "EditorIcons")
|
||||
|
||||
var name_label: Label
|
||||
@onready var add_icon: Texture2D = get_theme_icon("Add", "EditorIcons")
|
||||
@onready var background: StyleBox = get_theme_stylebox("pressed", "Button")
|
||||
var focus_style: StyleBox
|
||||
@onready var focus_style: StyleBox = get_theme_stylebox("focus", "Button").duplicate()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
setup_buttons()
|
||||
setup_label()
|
||||
focus_style.set_border_width_all(2)
|
||||
focus_style.set_border_color(Color(1, 1, 1, .67))
|
||||
|
||||
|
||||
func setup_buttons() -> void:
|
||||
var icon_size: Vector2 = Vector2(12, 12)
|
||||
var margin_container := MarginContainer.new()
|
||||
margin_container.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
margin_container.add_theme_constant_override("margin_top", 5)
|
||||
margin_container.add_theme_constant_override("margin_left", 5)
|
||||
margin_container.add_theme_constant_override("margin_right", 5)
|
||||
add_child(margin_container)
|
||||
|
||||
button_clear = TextureButton.new()
|
||||
button_clear.set_texture_normal(clear_icon)
|
||||
button_clear.set_custom_minimum_size(icon_size)
|
||||
button_clear.set_h_size_flags(Control.SIZE_SHRINK_END)
|
||||
button_clear.set_visible(resource != null)
|
||||
button_clear.pressed.connect(clear)
|
||||
add_child(button_clear)
|
||||
button_row.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
button_row.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
button_row.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
margin_container.add_child(button_row)
|
||||
|
||||
if type == Terrain3DAssets.TYPE_MESH:
|
||||
button_enabled.set_texture_normal(enabled_icon)
|
||||
button_enabled.set_texture_pressed(disabled_icon)
|
||||
button_enabled.set_custom_minimum_size(icon_size)
|
||||
button_enabled.set_h_size_flags(Control.SIZE_SHRINK_END)
|
||||
button_enabled.set_visible(resource != null)
|
||||
button_enabled.toggle_mode = true
|
||||
button_enabled.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
button_enabled.pressed.connect(enable)
|
||||
button_row.add_child(button_enabled)
|
||||
|
||||
button_edit = TextureButton.new()
|
||||
button_edit.set_texture_normal(edit_icon)
|
||||
button_edit.set_custom_minimum_size(icon_size)
|
||||
button_edit.set_h_size_flags(Control.SIZE_SHRINK_END)
|
||||
button_edit.set_visible(resource != null)
|
||||
button_edit.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
button_edit.pressed.connect(edit)
|
||||
add_child(button_edit)
|
||||
button_row.add_child(button_edit)
|
||||
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
spacer.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
button_row.add_child(spacer)
|
||||
|
||||
button_clear.set_texture_normal(clear_icon)
|
||||
button_clear.set_custom_minimum_size(icon_size)
|
||||
button_clear.set_h_size_flags(Control.SIZE_SHRINK_END)
|
||||
button_clear.set_visible(resource != null)
|
||||
button_clear.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
button_clear.pressed.connect(clear)
|
||||
button_row.add_child(button_clear)
|
||||
|
||||
|
||||
func setup_label() -> void:
|
||||
name_label = Label.new()
|
||||
add_child(name_label, true)
|
||||
name_label.visible = false
|
||||
name_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
name_label.vertical_alignment = VERTICAL_ALIGNMENT_BOTTOM
|
||||
name_label.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
name_label.add_theme_color_override("font_color", Color.WHITE)
|
||||
name_label.add_theme_color_override("font_shadow_color", Color.BLACK)
|
||||
name_label.add_theme_constant_override("shadow_offset_x", 1)
|
||||
name_label.add_theme_constant_override("shadow_offset_y", 1)
|
||||
name_label.add_theme_constant_override("shadow_offset_x", 1.)
|
||||
name_label.add_theme_constant_override("shadow_offset_y", 1.)
|
||||
name_label.add_theme_font_size_override("font_size", 15)
|
||||
name_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
name_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
@@ -702,6 +737,9 @@ class ListEntry extends VBoxContainer:
|
||||
func _notification(p_what) -> void:
|
||||
match p_what:
|
||||
NOTIFICATION_DRAW:
|
||||
# Hide spacer if icons are crowding small textures
|
||||
spacer.visible = size.x > 70 or type == Terrain3DAssets.TYPE_TEXTURE
|
||||
|
||||
var rect: Rect2 = Rect2(Vector2.ZERO, get_size())
|
||||
if !resource:
|
||||
draw_style_box(background, rect)
|
||||
@@ -723,6 +761,7 @@ class ListEntry extends VBoxContainer:
|
||||
texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
||||
else:
|
||||
draw_rect(rect, Color(.15, .15, .15, 1.))
|
||||
button_enabled.set_pressed_no_signal(!resource.is_enabled())
|
||||
name_label.add_theme_font_size_override("font_size", 4 + rect.size.x/10)
|
||||
if drop_data:
|
||||
draw_style_box(focus_style, rect)
|
||||
@@ -791,8 +830,8 @@ class ListEntry extends VBoxContainer:
|
||||
var ma := Terrain3DMeshAsset.new()
|
||||
if resource is Terrain3DMeshAsset:
|
||||
ma.id = resource.id
|
||||
ma.set_scene_file(res)
|
||||
set_edited_resource(ma, false)
|
||||
ma.set_scene_file(res)
|
||||
resource = ma
|
||||
elif res is Terrain3DMeshAsset and type == Terrain3DAssets.TYPE_MESH:
|
||||
if resource is Terrain3DMeshAsset:
|
||||
@@ -808,6 +847,8 @@ class ListEntry extends VBoxContainer:
|
||||
if resource:
|
||||
resource.setting_changed.connect(_on_resource_changed)
|
||||
resource.file_changed.connect(_on_resource_changed)
|
||||
if resource is Terrain3DMeshAsset:
|
||||
resource.instancer_setting_changed.connect(_on_resource_changed)
|
||||
|
||||
if button_clear:
|
||||
button_clear.set_visible(resource != null)
|
||||
@@ -818,6 +859,7 @@ class ListEntry extends VBoxContainer:
|
||||
|
||||
|
||||
func _on_resource_changed() -> void:
|
||||
queue_redraw()
|
||||
emit_signal("changed", resource)
|
||||
|
||||
|
||||
@@ -834,3 +876,8 @@ class ListEntry extends VBoxContainer:
|
||||
func edit() -> void:
|
||||
emit_signal("selected")
|
||||
emit_signal("inspected", resource)
|
||||
|
||||
|
||||
func enable() -> void:
|
||||
if resource is Terrain3DMeshAsset:
|
||||
resource.set_enabled(!resource.is_enabled())
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://bcfr30tpffi5o
|
||||
uid://bgoifepft1hjw
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dkb6hii5e48m2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bcfr30tpffi5o" path="res://addons/terrain_3d/src/asset_dock.gd" id="1_e23pg"]
|
||||
[ext_resource type="Script" path="res://addons/terrain_3d/src/asset_dock.gd" id="1_e23pg"]
|
||||
|
||||
[node name="Terrain3D" type="PanelContainer"]
|
||||
custom_minimum_size = Vector2(256, 95)
|
||||
@@ -40,10 +40,9 @@ custom_minimum_size = Vector2(80, 30)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
item_count = 9
|
||||
selected = 7
|
||||
item_count = 9
|
||||
popup/item_0/text = "Left_UL"
|
||||
popup/item_0/id = 0
|
||||
popup/item_1/text = "Left_BL"
|
||||
popup/item_1/id = 1
|
||||
popup/item_2/text = "Left_UR"
|
||||
@@ -65,7 +64,7 @@ popup/item_8/id = 8
|
||||
custom_minimum_size = Vector2(80, 10)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
min_value = 56.0
|
||||
min_value = 66.0
|
||||
max_value = 230.0
|
||||
value = 83.0
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
@tool
|
||||
extends ConfirmationDialog
|
||||
|
||||
var lod: int = 0
|
||||
var description: String = ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_unparent_when_invisible(true)
|
||||
about_to_popup.connect(_on_about_to_popup)
|
||||
visibility_changed.connect(_on_visibility_changed)
|
||||
%LodBox.value_changed.connect(_on_lod_box_value_changed)
|
||||
|
||||
|
||||
func _on_about_to_popup() -> void:
|
||||
lod = %LodBox.value
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
# Change text on the autowrap label only when the popup is visible.
|
||||
# Works around Godot issue #47005:
|
||||
# https://github.com/godotengine/godot/issues/47005
|
||||
if visible:
|
||||
%DescriptionLabel.text = description
|
||||
|
||||
|
||||
func _on_lod_box_value_changed(p_value: float) -> void:
|
||||
lod = %LodBox.value
|
||||
@@ -1 +0,0 @@
|
||||
uid://dft2g3p2pjw12
|
||||
@@ -1,43 +0,0 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bhvrrmb8bk1bt"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dft2g3p2pjw12" path="res://addons/terrain_3d/src/bake_lod_dialog.gd" id="1_sf76d"]
|
||||
|
||||
[node name="bake_lod_dialog" type="ConfirmationDialog"]
|
||||
title = "Bake Terrain3D Mesh"
|
||||
position = Vector2i(0, 36)
|
||||
size = Vector2i(400, 155)
|
||||
visible = true
|
||||
script = ExtResource("1_sf76d")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
offset_left = 8.0
|
||||
offset_top = 8.0
|
||||
offset_right = 392.0
|
||||
offset_bottom = 106.0
|
||||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_top = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 20
|
||||
|
||||
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "LOD:"
|
||||
|
||||
[node name="LodBox" type="SpinBox" parent="MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
max_value = 8.0
|
||||
value = 4.0
|
||||
|
||||
[node name="DescriptionLabel" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
autowrap_mode = 2
|
||||
@@ -1,400 +0,0 @@
|
||||
extends Node
|
||||
|
||||
const BakeLodDialog: PackedScene = preload("res://addons/terrain_3d/src/bake_lod_dialog.tscn")
|
||||
const BAKE_MESH_DESCRIPTION: String = "This will create a child MeshInstance3D. LOD4+ is recommended. LOD0 is slow and dense with vertices every 1 unit. It is not an optimal mesh."
|
||||
const BAKE_OCCLUDER_DESCRIPTION: String = "This will create a child OccluderInstance3D. LOD4+ is recommended and will take 5+ seconds per region to generate. LOD0 is unnecessarily dense and slow."
|
||||
const SET_UP_NAVIGATION_DESCRIPTION: String = "This operation will:
|
||||
|
||||
- Create a NavigationRegion3D node,
|
||||
- Assign it a blank NavigationMesh resource,
|
||||
- Move the Terrain3D node to be a child of the new node,
|
||||
- And bake the nav mesh.
|
||||
|
||||
Once setup is complete, you can modify the settings on your nav mesh, and rebake
|
||||
without having to run through the setup again.
|
||||
|
||||
If preferred, this setup can be canceled and the steps performed manually. For
|
||||
the best results, adjust the settings on the NavigationMesh resource to match
|
||||
the settings of your navigation agents and collisions."
|
||||
|
||||
var plugin: EditorPlugin
|
||||
var bake_method: Callable
|
||||
var bake_lod_dialog: ConfirmationDialog
|
||||
var confirm_dialog: ConfirmationDialog
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
bake_lod_dialog = BakeLodDialog.instantiate()
|
||||
bake_lod_dialog.hide()
|
||||
bake_lod_dialog.confirmed.connect(func(): bake_method.call())
|
||||
bake_lod_dialog.set_unparent_when_invisible(true)
|
||||
|
||||
confirm_dialog = ConfirmationDialog.new()
|
||||
confirm_dialog.hide()
|
||||
confirm_dialog.confirmed.connect(func(): bake_method.call())
|
||||
confirm_dialog.set_unparent_when_invisible(true)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
bake_lod_dialog.queue_free()
|
||||
confirm_dialog.queue_free()
|
||||
|
||||
|
||||
func bake_mesh_popup() -> void:
|
||||
if plugin.terrain:
|
||||
bake_method = _bake_mesh
|
||||
bake_lod_dialog.description = BAKE_MESH_DESCRIPTION
|
||||
EditorInterface.popup_dialog_centered(bake_lod_dialog)
|
||||
|
||||
|
||||
func _bake_mesh() -> void:
|
||||
if plugin.terrain.data.get_region_count() == 0:
|
||||
push_error("Terrain3D has no active regions to bake")
|
||||
return
|
||||
var mesh: Mesh = plugin.terrain.bake_mesh(bake_lod_dialog.lod, Terrain3DData.HEIGHT_FILTER_NEAREST)
|
||||
if !mesh:
|
||||
push_error("Failed to bake mesh from Terrain3D")
|
||||
return
|
||||
|
||||
var undo: EditorUndoRedoManager = plugin.get_undo_redo()
|
||||
undo.create_action("Terrain3D Bake ArrayMesh")
|
||||
|
||||
var mesh_instance := plugin.terrain.get_node_or_null(^"MeshInstance3D") as MeshInstance3D
|
||||
if !mesh_instance:
|
||||
mesh_instance = MeshInstance3D.new()
|
||||
mesh_instance.name = &"MeshInstance3D"
|
||||
mesh_instance.set_skeleton_path(NodePath())
|
||||
mesh_instance.mesh = mesh
|
||||
|
||||
undo.add_do_method(plugin.terrain, &"add_child", mesh_instance, true)
|
||||
undo.add_undo_method(plugin.terrain, &"remove_child", mesh_instance)
|
||||
undo.add_do_property(mesh_instance, &"owner", EditorInterface.get_edited_scene_root())
|
||||
undo.add_do_reference(mesh_instance)
|
||||
|
||||
else:
|
||||
undo.add_do_property(mesh_instance, &"mesh", mesh)
|
||||
undo.add_undo_property(mesh_instance, &"mesh", mesh_instance.mesh)
|
||||
|
||||
if mesh_instance.mesh.resource_path:
|
||||
var path := mesh_instance.mesh.resource_path
|
||||
undo.add_do_method(mesh, &"take_over_path", path)
|
||||
undo.add_undo_method(mesh_instance.mesh, &"take_over_path", path)
|
||||
undo.add_do_method(ResourceSaver, &"save", mesh)
|
||||
undo.add_undo_method(ResourceSaver, &"save", mesh_instance.mesh)
|
||||
|
||||
undo.commit_action()
|
||||
|
||||
|
||||
func bake_occluder_popup() -> void:
|
||||
if plugin.terrain:
|
||||
bake_method = _bake_occluder
|
||||
bake_lod_dialog.description = BAKE_OCCLUDER_DESCRIPTION
|
||||
EditorInterface.popup_dialog_centered(bake_lod_dialog)
|
||||
|
||||
|
||||
func _bake_occluder() -> void:
|
||||
if plugin.terrain.data.get_region_count() == 0:
|
||||
push_error("Terrain3D has no active regions to bake")
|
||||
return
|
||||
var mesh: Mesh = plugin.terrain.bake_mesh(bake_lod_dialog.lod, Terrain3DData.HEIGHT_FILTER_MINIMUM)
|
||||
if !mesh:
|
||||
push_error("Failed to bake mesh from Terrain3D")
|
||||
return
|
||||
assert(mesh.get_surface_count() == 1)
|
||||
|
||||
var undo: EditorUndoRedoManager = plugin.get_undo_redo()
|
||||
undo.create_action("Terrain3D Bake Occluder3D")
|
||||
|
||||
var occluder := ArrayOccluder3D.new()
|
||||
var arrays: Array = mesh.surface_get_arrays(0)
|
||||
assert(arrays.size() > Mesh.ARRAY_INDEX)
|
||||
assert(arrays[Mesh.ARRAY_INDEX] != null)
|
||||
occluder.set_arrays(arrays[Mesh.ARRAY_VERTEX], arrays[Mesh.ARRAY_INDEX])
|
||||
|
||||
var occluder_instance := plugin.terrain.get_node_or_null(^"OccluderInstance3D") as OccluderInstance3D
|
||||
if !occluder_instance:
|
||||
occluder_instance = OccluderInstance3D.new()
|
||||
occluder_instance.name = &"OccluderInstance3D"
|
||||
occluder_instance.occluder = occluder
|
||||
|
||||
undo.add_do_method(plugin.terrain, &"add_child", occluder_instance, true)
|
||||
undo.add_undo_method(plugin.terrain, &"remove_child", occluder_instance)
|
||||
undo.add_do_property(occluder_instance, &"owner", EditorInterface.get_edited_scene_root())
|
||||
undo.add_do_reference(occluder_instance)
|
||||
|
||||
else:
|
||||
undo.add_do_property(occluder_instance, &"occluder", occluder)
|
||||
undo.add_undo_property(occluder_instance, &"occluder", occluder_instance.occluder)
|
||||
|
||||
if occluder_instance.occluder.resource_path:
|
||||
var path := occluder_instance.occluder.resource_path
|
||||
undo.add_do_method(occluder, &"take_over_path", path)
|
||||
undo.add_undo_method(occluder_instance.occluder, &"take_over_path", path)
|
||||
undo.add_do_method(ResourceSaver, &"save", occluder)
|
||||
undo.add_undo_method(ResourceSaver, &"save", occluder_instance.occluder)
|
||||
|
||||
undo.commit_action()
|
||||
|
||||
|
||||
func find_nav_region_terrains(p_nav_region: NavigationRegion3D) -> Array[Terrain3D]:
|
||||
var result: Array[Terrain3D] = []
|
||||
if not p_nav_region.navigation_mesh:
|
||||
return result
|
||||
|
||||
var source_mode: NavigationMesh.SourceGeometryMode
|
||||
source_mode = p_nav_region.navigation_mesh.geometry_source_geometry_mode
|
||||
if source_mode == NavigationMesh.SOURCE_GEOMETRY_ROOT_NODE_CHILDREN:
|
||||
result.append_array(p_nav_region.find_children("", "Terrain3D", true, true))
|
||||
return result
|
||||
|
||||
var group_nodes: Array = p_nav_region.get_tree().get_nodes_in_group(p_nav_region.navigation_mesh.geometry_source_group_name)
|
||||
for node in group_nodes:
|
||||
if node is Terrain3D:
|
||||
result.push_back(node)
|
||||
if source_mode == NavigationMesh.SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN:
|
||||
result.append_array(node.find_children("", "Terrain3D", true, true))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
func find_terrain_nav_regions(p_terrain: Terrain3D) -> Array[NavigationRegion3D]:
|
||||
var result: Array[NavigationRegion3D] = []
|
||||
var root: Node = EditorInterface.get_edited_scene_root()
|
||||
if not root:
|
||||
return result
|
||||
for nav_region in root.find_children("", "NavigationRegion3D", true, true):
|
||||
if find_nav_region_terrains(nav_region).has(p_terrain):
|
||||
result.push_back(nav_region)
|
||||
return result
|
||||
|
||||
|
||||
func bake_nav_mesh() -> void:
|
||||
if plugin.nav_region:
|
||||
# A NavigationRegion3D is selected. We only need to bake that one navmesh.
|
||||
_bake_nav_region_nav_mesh(plugin.nav_region)
|
||||
print("Terrain3DNavigation: Finished baking 1 NavigationMesh.")
|
||||
|
||||
elif plugin.terrain:
|
||||
if plugin.terrain.data.get_region_count() == 0:
|
||||
push_error("Terrain3D has no active regions to bake")
|
||||
return
|
||||
# A Terrain3D is selected. There are potentially multiple navmeshes to bake and we need to
|
||||
# find them all. (The multiple navmesh use-case is likely on very large scenes with lots of
|
||||
# geometry. Each navmesh in this case would define its own, non-overlapping, baking AABB, to
|
||||
# cut down on the amount of geometry to bake. In a large open-world RPG, for instance, there
|
||||
# could be a navmesh for each town.)
|
||||
var nav_regions: Array[NavigationRegion3D] = find_terrain_nav_regions(plugin.terrain)
|
||||
for nav_region in nav_regions:
|
||||
_bake_nav_region_nav_mesh(nav_region)
|
||||
print("Terrain3DNavigation: Finished baking %d NavigationMesh(es)." % nav_regions.size())
|
||||
|
||||
|
||||
func _bake_nav_region_nav_mesh(p_nav_region: NavigationRegion3D) -> void:
|
||||
var nav_mesh: NavigationMesh = p_nav_region.navigation_mesh
|
||||
assert(nav_mesh != null)
|
||||
|
||||
var source_geometry_data := NavigationMeshSourceGeometryData3D.new()
|
||||
NavigationMeshGenerator.parse_source_geometry_data(nav_mesh, source_geometry_data, p_nav_region)
|
||||
|
||||
for terrain in find_nav_region_terrains(p_nav_region):
|
||||
var aabb: AABB = nav_mesh.filter_baking_aabb
|
||||
aabb.position += nav_mesh.filter_baking_aabb_offset
|
||||
aabb = p_nav_region.global_transform * aabb
|
||||
var faces: PackedVector3Array = terrain.generate_nav_mesh_source_geometry(aabb)
|
||||
if not faces.is_empty():
|
||||
source_geometry_data.add_faces(faces, Transform3D.IDENTITY)
|
||||
|
||||
NavigationMeshGenerator.bake_from_source_geometry_data(nav_mesh, source_geometry_data)
|
||||
|
||||
_postprocess_nav_mesh(nav_mesh)
|
||||
|
||||
# Assign null first to force the debug display to actually update:
|
||||
p_nav_region.set_navigation_mesh(null)
|
||||
p_nav_region.set_navigation_mesh(nav_mesh)
|
||||
|
||||
# Trigger save to disk if it is saved as an external file
|
||||
if not nav_mesh.get_path().is_empty():
|
||||
ResourceSaver.save(nav_mesh, nav_mesh.get_path(), ResourceSaver.FLAG_COMPRESS)
|
||||
|
||||
# Let other editor plugins and tool scripts know the nav mesh was just baked:
|
||||
p_nav_region.bake_finished.emit()
|
||||
|
||||
|
||||
func _postprocess_nav_mesh(p_nav_mesh: NavigationMesh) -> void:
|
||||
# Post-process the nav mesh to work around Godot issue #85548
|
||||
|
||||
# Round all the vertices in the nav_mesh to the nearest cell_size/cell_height so that it doesn't
|
||||
# contain any edges shorter than cell_size/cell_height (one cause of #85548).
|
||||
var vertices: PackedVector3Array = _postprocess_nav_mesh_round_vertices(p_nav_mesh)
|
||||
|
||||
# Rounding vertices can collapse some edges to 0 length. We remove these edges, and any polygons
|
||||
# that have been reduced to 0 area.
|
||||
var polygons: Array[PackedInt32Array] = _postprocess_nav_mesh_remove_empty_polygons(p_nav_mesh, vertices)
|
||||
|
||||
# Another cause of #85548 is baking producing overlapping polygons. We remove these.
|
||||
_postprocess_nav_mesh_remove_overlapping_polygons(p_nav_mesh, vertices, polygons)
|
||||
|
||||
p_nav_mesh.clear_polygons()
|
||||
p_nav_mesh.set_vertices(vertices)
|
||||
for polygon in polygons:
|
||||
p_nav_mesh.add_polygon(polygon)
|
||||
|
||||
|
||||
func _postprocess_nav_mesh_round_vertices(p_nav_mesh: NavigationMesh) -> PackedVector3Array:
|
||||
assert(p_nav_mesh != null)
|
||||
assert(p_nav_mesh.cell_size > 0.0)
|
||||
assert(p_nav_mesh.cell_height > 0.0)
|
||||
|
||||
var cell_size: Vector3 = Vector3(p_nav_mesh.cell_size, p_nav_mesh.cell_height, p_nav_mesh.cell_size)
|
||||
|
||||
# Round a little harder to avoid rounding errors with non-power-of-two cell_size/cell_height
|
||||
# causing the navigation map to put two non-matching edges in the same cell:
|
||||
var round_factor := cell_size * 1.001
|
||||
|
||||
var vertices: PackedVector3Array = p_nav_mesh.get_vertices()
|
||||
for i in range(vertices.size()):
|
||||
vertices[i] = (vertices[i] / round_factor).floor() * round_factor
|
||||
return vertices
|
||||
|
||||
|
||||
func _postprocess_nav_mesh_remove_empty_polygons(p_nav_mesh: NavigationMesh, p_vertices: PackedVector3Array) -> Array[PackedInt32Array]:
|
||||
var polygons: Array[PackedInt32Array] = []
|
||||
|
||||
for i in range(p_nav_mesh.get_polygon_count()):
|
||||
var old_polygon: PackedInt32Array = p_nav_mesh.get_polygon(i)
|
||||
var new_polygon: PackedInt32Array = []
|
||||
|
||||
# Remove duplicate vertices (introduced by rounding) from the polygon:
|
||||
var polygon_vertices: PackedVector3Array = []
|
||||
for index in old_polygon:
|
||||
var vertex: Vector3 = p_vertices[index]
|
||||
if polygon_vertices.has(vertex):
|
||||
continue
|
||||
polygon_vertices.push_back(vertex)
|
||||
new_polygon.push_back(index)
|
||||
|
||||
# If we removed some vertices, we might be able to remove the polygon too:
|
||||
if new_polygon.size() <= 2:
|
||||
continue
|
||||
polygons.push_back(new_polygon)
|
||||
|
||||
return polygons
|
||||
|
||||
|
||||
func _postprocess_nav_mesh_remove_overlapping_polygons(p_nav_mesh: NavigationMesh, p_vertices: PackedVector3Array, p_polygons: Array[PackedInt32Array]) -> void:
|
||||
# Occasionally, a baked nav mesh comes out with overlapping polygons:
|
||||
# https://github.com/godotengine/godot/issues/85548#issuecomment-1839341071
|
||||
# Until the bug is fixed in the engine, this function attempts to detect and remove overlapping
|
||||
# polygons.
|
||||
|
||||
# This function has to make a choice of which polygon to remove when an overlap is detected,
|
||||
# because in this case the nav mesh is ambiguous. To do this it uses a heuristic:
|
||||
# (1) an 'overlap' is defined as an edge that is shared by 3 or more polygons.
|
||||
# (2) a 'bad polygon' is defined as a polygon that contains 2 or more 'overlaps'.
|
||||
# The function removes the 'bad polygons', which in practice seems to be enough to remove all
|
||||
# overlaps without creating holes in the nav mesh.
|
||||
|
||||
var cell_size: Vector3 = Vector3(p_nav_mesh.cell_size, p_nav_mesh.cell_height, p_nav_mesh.cell_size)
|
||||
|
||||
# `edges` is going to map edges (vertex pairs) to arrays of polygons that contain that edge.
|
||||
var edges: Dictionary = {}
|
||||
|
||||
for polygon_index in range(p_polygons.size()):
|
||||
var polygon: PackedInt32Array = p_polygons[polygon_index]
|
||||
for j in range(polygon.size()):
|
||||
var vertex: Vector3 = p_vertices[polygon[j]]
|
||||
var next_vertex: Vector3 = p_vertices[polygon[(j + 1) % polygon.size()]]
|
||||
|
||||
# edge_key is a key we can use in the edges dictionary that uniquely identifies the
|
||||
# edge. We use cell coordinates here (Vector3i) because with a non-power-of-two
|
||||
# cell_size, rounding errors can cause Vector3 vertices to not be equal.
|
||||
# Array.sort IS defined for vector types - see the Godot docs. It's necessary here
|
||||
# because polygons that share an edge can have their vertices in a different order.
|
||||
var edge_key: Array = [Vector3i(vertex / cell_size), Vector3i(next_vertex / cell_size)]
|
||||
edge_key.sort()
|
||||
|
||||
if !edges.has(edge_key):
|
||||
edges[edge_key] = []
|
||||
edges[edge_key].push_back(polygon_index)
|
||||
|
||||
var overlap_count: Dictionary = {}
|
||||
for connections in edges.values():
|
||||
if connections.size() <= 2:
|
||||
continue
|
||||
for polygon_index in connections:
|
||||
overlap_count[polygon_index] = overlap_count.get(polygon_index, 0) + 1
|
||||
|
||||
var bad_polygons: Array = []
|
||||
for polygon_index in overlap_count.keys():
|
||||
if overlap_count[polygon_index] >= 2:
|
||||
bad_polygons.push_back(polygon_index)
|
||||
|
||||
bad_polygons.sort()
|
||||
for i in range(bad_polygons.size() - 1, -1, -1):
|
||||
p_polygons.remove_at(bad_polygons[i])
|
||||
|
||||
|
||||
func set_up_navigation_popup() -> void:
|
||||
if plugin.terrain:
|
||||
bake_method = _set_up_navigation
|
||||
confirm_dialog.dialog_text = SET_UP_NAVIGATION_DESCRIPTION
|
||||
EditorInterface.popup_dialog_centered(confirm_dialog)
|
||||
|
||||
|
||||
func _set_up_navigation() -> void:
|
||||
assert(plugin.terrain)
|
||||
if plugin.terrain == EditorInterface.get_edited_scene_root():
|
||||
push_error("Terrain3D Navigation setup not possible if Terrain3D node is scene root")
|
||||
return
|
||||
if plugin.terrain.data.get_region_count() == 0:
|
||||
push_error("Terrain3D has no active regions")
|
||||
return
|
||||
var terrain: Terrain3D = plugin.terrain
|
||||
|
||||
var nav_region := NavigationRegion3D.new()
|
||||
nav_region.name = &"NavigationRegion3D"
|
||||
nav_region.navigation_mesh = NavigationMesh.new()
|
||||
|
||||
var undo_redo: EditorUndoRedoManager = plugin.get_undo_redo()
|
||||
|
||||
undo_redo.create_action("Terrain3D Set up Navigation")
|
||||
undo_redo.add_do_method(self, &"_do_set_up_navigation", nav_region, terrain)
|
||||
undo_redo.add_undo_method(self, &"_undo_set_up_navigation", nav_region, terrain)
|
||||
undo_redo.add_do_reference(nav_region)
|
||||
undo_redo.commit_action()
|
||||
|
||||
EditorInterface.inspect_object(nav_region)
|
||||
assert(plugin.nav_region == nav_region)
|
||||
|
||||
bake_nav_mesh()
|
||||
|
||||
|
||||
func _do_set_up_navigation(p_nav_region: NavigationRegion3D, p_terrain: Terrain3D) -> void:
|
||||
var parent: Node = p_terrain.get_parent()
|
||||
var index: int = p_terrain.get_index()
|
||||
var t_owner: Node = p_terrain.owner
|
||||
|
||||
parent.remove_child(p_terrain)
|
||||
p_nav_region.add_child(p_terrain)
|
||||
|
||||
parent.add_child(p_nav_region, true)
|
||||
parent.move_child(p_nav_region, index)
|
||||
|
||||
p_nav_region.owner = t_owner
|
||||
p_terrain.owner = t_owner
|
||||
|
||||
|
||||
func _undo_set_up_navigation(p_nav_region: NavigationRegion3D, p_terrain: Terrain3D) -> void:
|
||||
assert(p_terrain.get_parent() == p_nav_region)
|
||||
|
||||
var parent: Node = p_nav_region.get_parent()
|
||||
var index: int = p_nav_region.get_index()
|
||||
var t_owner: Node = p_nav_region.get_owner()
|
||||
|
||||
parent.remove_child(p_nav_region)
|
||||
p_nav_region.remove_child(p_terrain)
|
||||
|
||||
parent.add_child(p_terrain, true)
|
||||
parent.move_child(p_terrain, index)
|
||||
|
||||
p_terrain.owner = t_owner
|
||||
@@ -1 +0,0 @@
|
||||
uid://byi465tyumga0
|
||||
@@ -1,463 +0,0 @@
|
||||
extends RefCounted
|
||||
|
||||
const WINDOW_SCENE: String = "res://addons/terrain_3d/src/channel_packer.tscn"
|
||||
const TEMPLATE_PATH: String = "res://addons/terrain_3d/src/channel_packer_import_template.txt"
|
||||
const DRAG_DROP_SCRIPT: String = "res://addons/terrain_3d/src/channel_packer_dragdrop.gd"
|
||||
enum {
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR,
|
||||
}
|
||||
|
||||
enum {
|
||||
IMAGE_ALBEDO,
|
||||
IMAGE_HEIGHT,
|
||||
IMAGE_NORMAL,
|
||||
IMAGE_ROUGHNESS
|
||||
}
|
||||
|
||||
var plugin: EditorPlugin
|
||||
var window: Window
|
||||
var save_file_dialog: EditorFileDialog
|
||||
var open_file_dialog: EditorFileDialog
|
||||
var invert_green_checkbox: CheckBox
|
||||
var invert_smooth_checkbox: CheckBox
|
||||
var invert_height_checkbox: CheckBox
|
||||
var lumin_height_button: Button
|
||||
var generate_mipmaps_checkbox: CheckBox
|
||||
var high_quality_checkbox: CheckBox
|
||||
var align_normals_checkbox: CheckBox
|
||||
var resize_toggle_checkbox: CheckBox
|
||||
var resize_option_box: SpinBox
|
||||
var height_channel: Array[Button]
|
||||
var height_channel_selected: int = 0
|
||||
var roughness_channel: Array[Button]
|
||||
var roughness_channel_selected: int = 0
|
||||
var last_opened_directory: String
|
||||
var last_saved_directory: String
|
||||
var packing_albedo: bool = false
|
||||
var queue_pack_normal_roughness: bool = false
|
||||
var images: Array[Image] = [null, null, null, null]
|
||||
var status_label: Label
|
||||
var no_op: Callable = func(): pass
|
||||
var last_file_selected_fn: Callable = no_op
|
||||
var normal_vector: Vector3
|
||||
|
||||
|
||||
func pack_textures_popup() -> void:
|
||||
if window != null:
|
||||
window.show()
|
||||
window.move_to_foreground()
|
||||
window.move_to_center()
|
||||
return
|
||||
window = (load(WINDOW_SCENE) as PackedScene).instantiate()
|
||||
window.close_requested.connect(_on_close_requested)
|
||||
window.window_input.connect(func(event:InputEvent):
|
||||
if event is InputEventKey:
|
||||
if event.pressed and event.keycode == KEY_ESCAPE:
|
||||
_on_close_requested()
|
||||
)
|
||||
window.find_child("CloseButton").pressed.connect(_on_close_requested)
|
||||
|
||||
status_label = window.find_child("StatusLabel") as Label
|
||||
invert_green_checkbox = window.find_child("InvertGreenChannelCheckBox") as CheckBox
|
||||
invert_smooth_checkbox = window.find_child("InvertSmoothCheckBox") as CheckBox
|
||||
invert_height_checkbox = window.find_child("ConvertDepthToHeight") as CheckBox
|
||||
lumin_height_button = window.find_child("LuminanceAsHeightButton") as Button
|
||||
generate_mipmaps_checkbox = window.find_child("GenerateMipmapsCheckBox") as CheckBox
|
||||
high_quality_checkbox = window.find_child("HighQualityCheckBox") as CheckBox
|
||||
align_normals_checkbox = window.find_child("AlignNormalsCheckBox") as CheckBox
|
||||
resize_toggle_checkbox = window.find_child("ResizeToggle") as CheckBox
|
||||
resize_option_box = window.find_child("ResizeOptionButton") as SpinBox
|
||||
height_channel = [
|
||||
window.find_child("HeightChannelR") as Button,
|
||||
window.find_child("HeightChannelG") as Button,
|
||||
window.find_child("HeightChannelB") as Button,
|
||||
window.find_child("HeightChannelA") as Button
|
||||
]
|
||||
roughness_channel = [
|
||||
window.find_child("RoughnessChannelR") as Button,
|
||||
window.find_child("RoughnessChannelG") as Button,
|
||||
window.find_child("RoughnessChannelB") as Button,
|
||||
window.find_child("RoughnessChannelA") as Button
|
||||
]
|
||||
|
||||
height_channel[0].pressed.connect(func() -> void: height_channel_selected = 0)
|
||||
height_channel[1].pressed.connect(func() -> void: height_channel_selected = 1)
|
||||
height_channel[2].pressed.connect(func() -> void: height_channel_selected = 2)
|
||||
height_channel[3].pressed.connect(func() -> void: height_channel_selected = 3)
|
||||
|
||||
roughness_channel[0].pressed.connect(func() -> void: roughness_channel_selected = 0)
|
||||
roughness_channel[1].pressed.connect(func() -> void: roughness_channel_selected = 1)
|
||||
roughness_channel[2].pressed.connect(func() -> void: roughness_channel_selected = 2)
|
||||
roughness_channel[3].pressed.connect(func() -> void: roughness_channel_selected = 3)
|
||||
|
||||
plugin.add_child(window)
|
||||
_init_file_dialogs()
|
||||
|
||||
# the dialog disables the parent window "on top" so, restore it after 1 frame to alow the dialog to clear.
|
||||
var set_on_top_fn: Callable = func(_file: String = "") -> void:
|
||||
await RenderingServer.frame_post_draw
|
||||
window.always_on_top = true
|
||||
save_file_dialog.file_selected.connect(set_on_top_fn)
|
||||
save_file_dialog.canceled.connect(set_on_top_fn)
|
||||
open_file_dialog.file_selected.connect(set_on_top_fn)
|
||||
open_file_dialog.canceled.connect(set_on_top_fn)
|
||||
|
||||
_init_texture_picker(window.find_child("AlbedoVBox"), IMAGE_ALBEDO)
|
||||
_init_texture_picker(window.find_child("HeightVBox"), IMAGE_HEIGHT)
|
||||
_init_texture_picker(window.find_child("NormalVBox"), IMAGE_NORMAL)
|
||||
_init_texture_picker(window.find_child("RoughnessVBox"), IMAGE_ROUGHNESS)
|
||||
|
||||
var pack_button_path: String = "Panel/MarginContainer/VBoxContainer/PackButton"
|
||||
(window.get_node(pack_button_path) as Button).pressed.connect(_on_pack_button_pressed)
|
||||
|
||||
|
||||
func _on_close_requested() -> void:
|
||||
last_file_selected_fn = no_op
|
||||
images = [null, null, null, null]
|
||||
window.queue_free()
|
||||
window = null
|
||||
|
||||
|
||||
func _init_file_dialogs() -> void:
|
||||
save_file_dialog = EditorFileDialog.new()
|
||||
save_file_dialog.set_filters(PackedStringArray(["*.png"]))
|
||||
save_file_dialog.set_file_mode(EditorFileDialog.FILE_MODE_SAVE_FILE)
|
||||
save_file_dialog.access = EditorFileDialog.ACCESS_FILESYSTEM
|
||||
save_file_dialog.file_selected.connect(_on_save_file_selected)
|
||||
save_file_dialog.ok_button_text = "Save"
|
||||
save_file_dialog.size = Vector2i(550, 550)
|
||||
#save_file_dialog.transient = false
|
||||
#save_file_dialog.exclusive = false
|
||||
#save_file_dialog.popup_window = true
|
||||
|
||||
open_file_dialog = EditorFileDialog.new()
|
||||
open_file_dialog.set_filters(PackedStringArray(
|
||||
["*.png", "*.bmp", "*.exr", "*.hdr", "*.jpg", "*.jpeg", "*.tga", "*.svg", "*.webp", "*.ktx", "*.dds"]))
|
||||
open_file_dialog.set_file_mode(EditorFileDialog.FILE_MODE_OPEN_FILE)
|
||||
open_file_dialog.access = EditorFileDialog.ACCESS_FILESYSTEM
|
||||
open_file_dialog.ok_button_text = "Open"
|
||||
open_file_dialog.size = Vector2i(550, 550)
|
||||
#open_file_dialog.transient = false
|
||||
#open_file_dialog.exclusive = false
|
||||
#open_file_dialog.popup_window = true
|
||||
|
||||
window.add_child(save_file_dialog)
|
||||
window.add_child(open_file_dialog)
|
||||
|
||||
|
||||
func _init_texture_picker(p_parent: Node, p_image_index: int) -> void:
|
||||
var line_edit: LineEdit = p_parent.find_child("LineEdit") as LineEdit
|
||||
var file_pick_button: Button = p_parent.find_child("PickButton") as Button
|
||||
var clear_button: Button = p_parent.find_child("ClearButton") as Button
|
||||
var texture_rect: TextureRect = p_parent.find_child("TextureRect") as TextureRect
|
||||
var texture_button: Button = p_parent.find_child("TextureButton") as Button
|
||||
texture_button.set_script(load(DRAG_DROP_SCRIPT) as GDScript)
|
||||
|
||||
var set_channel_fn: Callable = func(used_channels: int) -> void:
|
||||
var channel_count: int = 4
|
||||
# enum Image.UsedChannels
|
||||
match used_channels:
|
||||
Image.USED_CHANNELS_L, Image.USED_CHANNELS_R: channel_count = 1
|
||||
Image.USED_CHANNELS_LA, Image.USED_CHANNELS_RG: channel_count = 2
|
||||
Image.USED_CHANNELS_RGB: channel_count = 3
|
||||
Image.USED_CHANNELS_RGBA: channel_count = 4
|
||||
if p_image_index == IMAGE_HEIGHT:
|
||||
for i in 4:
|
||||
height_channel[i].visible = i < channel_count
|
||||
height_channel[0].button_pressed = true
|
||||
height_channel[0].pressed.emit()
|
||||
elif p_image_index == IMAGE_ROUGHNESS:
|
||||
for i in 4:
|
||||
roughness_channel[i].visible = i < channel_count
|
||||
roughness_channel[0].button_pressed = true
|
||||
roughness_channel[0].pressed.emit()
|
||||
|
||||
var load_image_fn: Callable = func(path: String):
|
||||
var image: Image = Image.new()
|
||||
var error: int = OK
|
||||
# Special case for dds files
|
||||
if path.get_extension() == "dds":
|
||||
image = ResourceLoader.load(path).get_image()
|
||||
if not image.is_empty():
|
||||
# if the dds file is loaded, we must clear any mipmaps and
|
||||
# decompress if needed in order to do per pixel operations.
|
||||
image.clear_mipmaps()
|
||||
image.decompress()
|
||||
else:
|
||||
error = FAILED
|
||||
else:
|
||||
error = image.load(path)
|
||||
if error != OK:
|
||||
_show_message(ERROR, "Failed to load texture '" + path + "'")
|
||||
texture_rect.texture = null
|
||||
images[p_image_index] = null
|
||||
else:
|
||||
_show_message(INFO, "Loaded texture '" + path + "'")
|
||||
texture_rect.texture = ImageTexture.create_from_image(image)
|
||||
images[p_image_index] = image
|
||||
_set_wh_labels(p_image_index, image.get_width(), image.get_height())
|
||||
if p_image_index == IMAGE_NORMAL:
|
||||
_set_normal_vector(image)
|
||||
if p_image_index == IMAGE_HEIGHT or p_image_index == IMAGE_ROUGHNESS:
|
||||
set_channel_fn.call(image.detect_used_channels())
|
||||
|
||||
var os_drop_fn: Callable = func(files: PackedStringArray) -> void:
|
||||
# OS drag drop holds mouse focus until released,
|
||||
# Get mouse pos and check directly if inside texture_rect
|
||||
var rect = texture_button.get_global_rect()
|
||||
var mouse_position = texture_button.get_global_mouse_position()
|
||||
if rect.has_point(mouse_position):
|
||||
if files.size() != 1:
|
||||
_show_message(ERROR, "Cannot load multiple files")
|
||||
else:
|
||||
line_edit.text = files[0]
|
||||
load_image_fn.call(files[0])
|
||||
|
||||
var godot_drop_fn: Callable = func(path: String) -> void:
|
||||
path = ProjectSettings.globalize_path(path)
|
||||
line_edit.text = path
|
||||
load_image_fn.call(path)
|
||||
|
||||
var open_fn: Callable = func() -> void:
|
||||
open_file_dialog.current_path = last_opened_directory
|
||||
if last_file_selected_fn != no_op:
|
||||
open_file_dialog.file_selected.disconnect(last_file_selected_fn)
|
||||
last_file_selected_fn = func(path: String) -> void:
|
||||
line_edit.text = path
|
||||
load_image_fn.call(path)
|
||||
open_file_dialog.file_selected.connect(last_file_selected_fn)
|
||||
open_file_dialog.popup_centered_ratio()
|
||||
|
||||
var line_edit_submit_fn: Callable = func(path: String) -> void:
|
||||
line_edit.text = path
|
||||
load_image_fn.call(path)
|
||||
|
||||
var clear_fn: Callable = func() -> void:
|
||||
line_edit.text = ""
|
||||
texture_rect.texture = null
|
||||
images[p_image_index] = null
|
||||
_set_wh_labels(p_image_index, -1, -1)
|
||||
|
||||
line_edit.text_submitted.connect(line_edit_submit_fn)
|
||||
file_pick_button.pressed.connect(open_fn)
|
||||
texture_button.pressed.connect(open_fn)
|
||||
clear_button.pressed.connect(clear_fn)
|
||||
texture_button.dropped.connect(godot_drop_fn)
|
||||
window.files_dropped.connect(os_drop_fn)
|
||||
|
||||
if p_image_index == IMAGE_HEIGHT:
|
||||
var lumin_fn: Callable = func() -> void:
|
||||
if !images[IMAGE_ALBEDO]:
|
||||
_show_message(ERROR, "Albedo Image Required for Operation")
|
||||
else:
|
||||
line_edit.text = "Generated Height"
|
||||
var height_texture: Image = Terrain3DUtil.luminance_to_height(images[IMAGE_ALBEDO])
|
||||
if height_texture.is_empty():
|
||||
_show_message(ERROR, "Height Texture Generation error")
|
||||
# blur the image by resizing down and back..
|
||||
var w: int = height_texture.get_width()
|
||||
var h: int = height_texture.get_height()
|
||||
height_texture.resize(w / 4, h / 4)
|
||||
height_texture.resize(w, h, Image.INTERPOLATE_CUBIC)
|
||||
# "Load" the height texture
|
||||
images[IMAGE_HEIGHT] = height_texture
|
||||
texture_rect.texture = ImageTexture.create_from_image(images[IMAGE_HEIGHT])
|
||||
_set_wh_labels(IMAGE_HEIGHT, height_texture.get_width(), height_texture.get_height())
|
||||
set_channel_fn.call(Image.USED_CHANNELS_R)
|
||||
_show_message(INFO, "Height Texture generated sucsessfully")
|
||||
lumin_height_button.pressed.connect(lumin_fn)
|
||||
plugin.ui.set_button_editor_icon(file_pick_button, "Folder")
|
||||
plugin.ui.set_button_editor_icon(clear_button, "Remove")
|
||||
|
||||
|
||||
func _set_wh_labels(p_image_index: int, width: int, height: int) -> void:
|
||||
var w: String = ""
|
||||
var h: String = ""
|
||||
if width > 0 and height > 0:
|
||||
w = "w: " + str(width)
|
||||
h = "h: " + str(height)
|
||||
match p_image_index:
|
||||
0:
|
||||
window.find_child("AlbedoW").text = w
|
||||
window.find_child("AlbedoH").text = h
|
||||
1:
|
||||
window.find_child("HeightW").text = w
|
||||
window.find_child("HeightH").text = h
|
||||
2:
|
||||
window.find_child("NormalW").text = w
|
||||
window.find_child("NormalH").text = h
|
||||
3:
|
||||
window.find_child("RoughnessW").text = w
|
||||
window.find_child("RoughnessH").text = h
|
||||
|
||||
|
||||
func _show_message(p_level: int, p_text: String) -> void:
|
||||
status_label.text = p_text
|
||||
match p_level:
|
||||
INFO:
|
||||
print("Terrain3DChannelPacker: " + p_text)
|
||||
status_label.add_theme_color_override("font_color", Color(0, 0.82, 0.14))
|
||||
WARN:
|
||||
push_warning("Terrain3DChannelPacker: " + p_text)
|
||||
status_label.add_theme_color_override("font_color", Color(0.9, 0.9, 0))
|
||||
ERROR,_:
|
||||
push_error("Terrain3DChannelPacker: " + p_text)
|
||||
status_label.add_theme_color_override("font_color", Color(0.9, 0, 0))
|
||||
|
||||
|
||||
func _create_import_file(png_path: String) -> void:
|
||||
var dst_import_path: String = png_path + ".import"
|
||||
var file: FileAccess = FileAccess.open(TEMPLATE_PATH, FileAccess.READ)
|
||||
var template_content: String = file.get_as_text()
|
||||
file.close()
|
||||
template_content = template_content.replace(
|
||||
"$SOURCE_FILE", png_path).replace(
|
||||
"$HIGH_QUALITY", str(high_quality_checkbox.button_pressed)).replace(
|
||||
"$GENERATE_MIPMAPS", str(generate_mipmaps_checkbox.button_pressed)
|
||||
)
|
||||
var import_content: String = template_content
|
||||
file = FileAccess.open(dst_import_path, FileAccess.WRITE)
|
||||
file.store_string(import_content)
|
||||
file.close()
|
||||
|
||||
|
||||
func _on_pack_button_pressed() -> void:
|
||||
packing_albedo = images[IMAGE_ALBEDO] != null and images[IMAGE_HEIGHT] != null
|
||||
var packing_normal_roughness: bool = images[IMAGE_NORMAL] != null and images[IMAGE_ROUGHNESS] != null
|
||||
|
||||
if not packing_albedo and not packing_normal_roughness:
|
||||
_show_message(WARN, "Please select an albedo and height texture or a normal and roughness texture")
|
||||
return
|
||||
if packing_albedo:
|
||||
save_file_dialog.current_path = last_saved_directory + "packed_albedo_height"
|
||||
save_file_dialog.title = "Save Packed Albedo/Height Texture"
|
||||
save_file_dialog.popup_centered_ratio()
|
||||
if packing_normal_roughness:
|
||||
queue_pack_normal_roughness = true
|
||||
return
|
||||
if packing_normal_roughness:
|
||||
save_file_dialog.current_path = last_saved_directory + "packed_normal_roughness"
|
||||
save_file_dialog.title = "Save Packed Normal/Roughness Texture"
|
||||
save_file_dialog.popup_centered_ratio()
|
||||
|
||||
|
||||
func _on_save_file_selected(p_dst_path) -> void:
|
||||
last_saved_directory = p_dst_path.get_base_dir() + "/"
|
||||
var error: int
|
||||
if packing_albedo:
|
||||
error = _pack_textures(images[IMAGE_ALBEDO], images[IMAGE_HEIGHT], p_dst_path, false,
|
||||
invert_height_checkbox.button_pressed, false, height_channel_selected)
|
||||
else:
|
||||
error = _pack_textures(images[IMAGE_NORMAL], images[IMAGE_ROUGHNESS], p_dst_path,
|
||||
invert_green_checkbox.button_pressed, invert_smooth_checkbox.button_pressed,
|
||||
align_normals_checkbox.button_pressed, roughness_channel_selected)
|
||||
|
||||
if error == OK:
|
||||
EditorInterface.get_resource_filesystem().scan()
|
||||
if window.visible:
|
||||
window.hide()
|
||||
await EditorInterface.get_resource_filesystem().resources_reimported
|
||||
# wait 1 extra frame, to ensure the UI is responsive.
|
||||
await RenderingServer.frame_post_draw
|
||||
window.show()
|
||||
|
||||
if queue_pack_normal_roughness:
|
||||
queue_pack_normal_roughness = false
|
||||
packing_albedo = false
|
||||
save_file_dialog.current_path = last_saved_directory + "packed_normal_roughness"
|
||||
save_file_dialog.title = "Save Packed Normal/Roughness Texture"
|
||||
|
||||
save_file_dialog.call_deferred("popup_centered_ratio")
|
||||
save_file_dialog.call_deferred("move_to_foreground")
|
||||
|
||||
|
||||
func _alignment_basis(normal: Vector3) -> Basis:
|
||||
var up: Vector3 = Vector3(0, 0, 1)
|
||||
var v: Vector3 = normal.cross(up)
|
||||
var c: float = normal.dot(up)
|
||||
var k: float = 1.0 / (1.0 + c)
|
||||
|
||||
var vxy: float = v.x * v.y * k
|
||||
var vxz: float = v.x * v.z * k
|
||||
var vyz: float = v.y * v.z * k
|
||||
|
||||
return Basis(Vector3(v.x * v.x * k + c, vxy - v.z, vxz + v.y),
|
||||
Vector3(vxy + v.z, v.y * v.y * k + c, vyz - v.x),
|
||||
Vector3(vxz - v.y, vyz + v.x, v.z * v.z * k + c)
|
||||
)
|
||||
|
||||
|
||||
func _set_normal_vector(source: Image, quiet: bool = false) -> void:
|
||||
# Calculate texture normal sum direction
|
||||
var normal: Image = source
|
||||
var sum: Color = Color(0.0, 0.0, 0.0, 0.0)
|
||||
for x in normal.get_height():
|
||||
for y in normal.get_width():
|
||||
sum += normal.get_pixel(x, y)
|
||||
var div: float = normal.get_height() * normal.get_width()
|
||||
sum /= Color(div, div, div)
|
||||
sum *= 2.0
|
||||
sum -= Color(1.0, 1.0, 1.0)
|
||||
normal_vector = Vector3(sum.r, sum.g, sum.b).normalized()
|
||||
if normal_vector.dot(Vector3(0.0, 0.0, 1.0)) < 0.999 && !quiet:
|
||||
_show_message(WARN, "Normal Texture Not Orthoganol to UV plane.\nFor Compatability with Detiling and Rotation, Select Orthoganolize Normals")
|
||||
|
||||
|
||||
func _align_normals(source: Image, iteration: int = 0) -> void:
|
||||
# generate matrix to re-align the normalmap
|
||||
var mat3: Basis = _alignment_basis(normal_vector)
|
||||
# re-align the normal map pixels
|
||||
for x in source.get_height():
|
||||
for y in source.get_width():
|
||||
var old_pixel: Color = source.get_pixel(x, y)
|
||||
var vector_pixel: Vector3 = Vector3(old_pixel.r, old_pixel.g, old_pixel.b)
|
||||
vector_pixel *= 2.0
|
||||
vector_pixel -= Vector3.ONE
|
||||
vector_pixel = vector_pixel.normalized()
|
||||
vector_pixel = vector_pixel * mat3
|
||||
vector_pixel += Vector3.ONE
|
||||
vector_pixel *= 0.5
|
||||
var new_pixel: Color = Color(vector_pixel.x, vector_pixel.y, vector_pixel.z, old_pixel.a)
|
||||
source.set_pixel(x, y, new_pixel)
|
||||
_set_normal_vector(source, true)
|
||||
if normal_vector.dot(Vector3(0.0, 0.0, 1.0)) < 0.999 && iteration < 3:
|
||||
++iteration
|
||||
_align_normals(source, iteration)
|
||||
|
||||
|
||||
func _pack_textures(p_rgb_image: Image, p_a_image: Image, p_dst_path: String, p_invert_green: bool,
|
||||
p_invert_smooth: bool, p_align_normals : bool, p_alpha_channel: int) -> Error:
|
||||
if p_rgb_image and p_a_image:
|
||||
if p_rgb_image.get_size() != p_a_image.get_size() and !resize_toggle_checkbox.button_pressed:
|
||||
_show_message(ERROR, "Textures must be the same size.\nEnable resize to override image dimensions")
|
||||
return FAILED
|
||||
|
||||
if resize_toggle_checkbox.button_pressed:
|
||||
var size: int = max(128, resize_option_box.value)
|
||||
p_rgb_image.resize(size, size, Image.INTERPOLATE_CUBIC)
|
||||
p_a_image.resize(size, size, Image.INTERPOLATE_CUBIC)
|
||||
|
||||
if p_align_normals and normal_vector.dot(Vector3(0.0, 0.0, 1.0)) < 0.999:
|
||||
_align_normals(p_rgb_image)
|
||||
elif p_align_normals:
|
||||
_show_message(INFO, "Alignment OK, skipping Normal Orthogonalization")
|
||||
|
||||
var output_image: Image = Terrain3DUtil.pack_image(p_rgb_image, p_a_image,
|
||||
p_invert_green, p_invert_smooth, p_alpha_channel)
|
||||
|
||||
if not output_image:
|
||||
_show_message(ERROR, "Failed to pack textures")
|
||||
return FAILED
|
||||
if output_image.detect_used_channels() != 5:
|
||||
_show_message(ERROR, "Packing Error, Alpha Channel empty")
|
||||
return FAILED
|
||||
|
||||
output_image.save_png(p_dst_path)
|
||||
_create_import_file(p_dst_path)
|
||||
_show_message(INFO, "Packed to " + p_dst_path + ".")
|
||||
return OK
|
||||
else:
|
||||
_show_message(ERROR, "Failed to load one or more textures")
|
||||
return FAILED
|
||||
@@ -1 +0,0 @@
|
||||
uid://y7pm2ndr5k2m
|
||||
@@ -1,553 +0,0 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://nud6dwjcnj5v"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ysabf"]
|
||||
bg_color = Color(0.211765, 0.239216, 0.290196, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_lcvna"]
|
||||
bg_color = Color(0.168627, 0.211765, 0.266667, 1)
|
||||
border_width_left = 3
|
||||
border_width_top = 3
|
||||
border_width_right = 3
|
||||
border_width_bottom = 3
|
||||
border_color = Color(0.270588, 0.435294, 0.580392, 1)
|
||||
corner_radius_top_left = 5
|
||||
corner_radius_top_right = 5
|
||||
corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_cb0xf"]
|
||||
bg_color = Color(0.137255, 0.137255, 0.137255, 1)
|
||||
draw_center = false
|
||||
border_width_left = 3
|
||||
border_width_top = 3
|
||||
border_width_right = 3
|
||||
border_width_bottom = 3
|
||||
border_color = Color(0.784314, 0.784314, 0.784314, 1)
|
||||
corner_radius_top_left = 5
|
||||
corner_radius_top_right = 5
|
||||
corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_7qdas"]
|
||||
|
||||
[sub_resource type="ButtonGroup" id="ButtonGroup_wnxik"]
|
||||
|
||||
[sub_resource type="ButtonGroup" id="ButtonGroup_bs6ki"]
|
||||
|
||||
[node name="Window" type="Window"]
|
||||
title = "Terrain3D Channel Packer"
|
||||
initial_position = 1
|
||||
size = Vector2i(680, 835)
|
||||
unresizable = true
|
||||
always_on_top = true
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_ysabf")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 5.0
|
||||
offset_top = 5.0
|
||||
offset_right = -5.0
|
||||
offset_bottom = 5.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 5
|
||||
theme_override_constants/margin_top = 5
|
||||
theme_override_constants/margin_right = 5
|
||||
theme_override_constants/margin_bottom = 5
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/MarginContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 10
|
||||
|
||||
[node name="AlbedoHeightPanel" type="Panel" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 290)
|
||||
layout_mode = 2
|
||||
mouse_filter = 1
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_lcvna")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_top = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="AlbedoVBox" type="VBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="AlbedoLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox"]
|
||||
layout_mode = 2
|
||||
text = "Albedo texture"
|
||||
|
||||
[node name="AlbedoHBox" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox/AlbedoHBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="PickButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox/AlbedoHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ClearButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox/AlbedoHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
theme_override_constants/margin_top = 10
|
||||
|
||||
[node name="Panel" type="Panel" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox/MarginContainer"]
|
||||
custom_minimum_size = Vector2(110, 110)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_cb0xf")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox/MarginContainer/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -50.0
|
||||
offset_top = -50.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = 50.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
expand_mode = 1
|
||||
|
||||
[node name="TextureButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox/MarginContainer/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/normal = SubResource("StyleBoxEmpty_7qdas")
|
||||
|
||||
[node name="AlbedoWHHBox" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="AlbedoW" type="Label" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox/AlbedoWHHBox"]
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="AlbedoH" type="Label" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox/AlbedoWHHBox"]
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="LuminanceAsHeightButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/AlbedoVBox/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = " Generate Height from Luminance"
|
||||
icon_alignment = 2
|
||||
|
||||
[node name="HeightVBox" type="VBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="HeightLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox"]
|
||||
layout_mode = 2
|
||||
text = "Height texture"
|
||||
|
||||
[node name="HeightHBox" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HeightHBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="PickButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HeightHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ClearButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HeightHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
theme_override_constants/margin_top = 10
|
||||
|
||||
[node name="Panel" type="Panel" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/MarginContainer"]
|
||||
custom_minimum_size = Vector2(110, 110)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_cb0xf")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/MarginContainer/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -50.0
|
||||
offset_top = -50.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = 50.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
expand_mode = 1
|
||||
|
||||
[node name="TextureButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/MarginContainer/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/normal = SubResource("StyleBoxEmpty_7qdas")
|
||||
|
||||
[node name="HeightWHHBox" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="HeightW" type="Label" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HeightWHHBox"]
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="HeightH" type="Label" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HeightWHHBox"]
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="ConvertDepthToHeight" type="CheckBox" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = " Convert Depth to Height"
|
||||
icon_alignment = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="HeightChannelLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = " Source Channel: "
|
||||
horizontal_alignment = 2
|
||||
|
||||
[node name="HeightChannelR" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
button_pressed = true
|
||||
button_group = SubResource("ButtonGroup_wnxik")
|
||||
text = "R"
|
||||
|
||||
[node name="HeightChannelB" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_wnxik")
|
||||
text = "G"
|
||||
|
||||
[node name="HeightChannelG" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_wnxik")
|
||||
text = "B"
|
||||
|
||||
[node name="HeightChannelA" type="Button" parent="Panel/MarginContainer/VBoxContainer/AlbedoHeightPanel/MarginContainer/HBoxContainer/HeightVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_wnxik")
|
||||
text = "A"
|
||||
|
||||
[node name="NormalRoughnessPanel" type="Panel" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 290)
|
||||
layout_mode = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_lcvna")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_top = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="NormalVBox" type="VBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="NormalLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox"]
|
||||
layout_mode = 2
|
||||
text = "Normal texture"
|
||||
|
||||
[node name="NormalHBox" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/NormalHBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="PickButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/NormalHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ClearButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/NormalHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
theme_override_constants/margin_top = 10
|
||||
|
||||
[node name="Panel" type="Panel" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/MarginContainer"]
|
||||
custom_minimum_size = Vector2(110, 110)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_cb0xf")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/MarginContainer/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -50.0
|
||||
offset_top = -50.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = 50.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
expand_mode = 1
|
||||
|
||||
[node name="TextureButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/MarginContainer/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/normal = SubResource("StyleBoxEmpty_7qdas")
|
||||
|
||||
[node name="NormalWHHBox" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="NormalW" type="Label" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/NormalWHHBox"]
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="NormalH" type="Label" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/NormalWHHBox"]
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="InvertGreenChannelCheckBox" type="CheckBox" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = " Convert DirectX to OpenGL"
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="AlignNormalsCheckBox" type="CheckBox" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/NormalVBox/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = " Orthoganolise Normals"
|
||||
|
||||
[node name="RoughnessVBox" type="VBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="RoughnessLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox"]
|
||||
layout_mode = 2
|
||||
text = "Roughness texture"
|
||||
|
||||
[node name="RoughnessHBox" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/RoughnessHBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="PickButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/RoughnessHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ClearButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/RoughnessHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
theme_override_constants/margin_top = 10
|
||||
|
||||
[node name="Panel" type="Panel" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/MarginContainer"]
|
||||
custom_minimum_size = Vector2(110, 110)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_cb0xf")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/MarginContainer/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -50.0
|
||||
offset_top = -50.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = 50.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
expand_mode = 1
|
||||
|
||||
[node name="TextureButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/MarginContainer/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/normal = SubResource("StyleBoxEmpty_7qdas")
|
||||
|
||||
[node name="RoughnessWHHBox" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="RoughnessW" type="Label" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/RoughnessWHHBox"]
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="RoughnessH" type="Label" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/RoughnessWHHBox"]
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="InvertSmoothCheckBox" type="CheckBox" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = " Convert Smoothness to Roughness"
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="RoughnessChannelLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = " Source Channel: "
|
||||
horizontal_alignment = 2
|
||||
|
||||
[node name="RoughnessChannelR" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
button_pressed = true
|
||||
button_group = SubResource("ButtonGroup_bs6ki")
|
||||
text = "R"
|
||||
|
||||
[node name="RoughnessChannelG" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_bs6ki")
|
||||
text = "G"
|
||||
|
||||
[node name="RoughnessChannelB" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_bs6ki")
|
||||
text = "B"
|
||||
|
||||
[node name="RoughnessChannelA" type="Button" parent="Panel/MarginContainer/VBoxContainer/NormalRoughnessPanel/MarginContainer/HBoxContainer/RoughnessVBox/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_bs6ki")
|
||||
text = "A"
|
||||
|
||||
[node name="GeneralOptionsLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "General Options"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="GeneralOptionsHBox" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 35)
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="ResizeToggle" type="CheckBox" parent="Panel/MarginContainer/VBoxContainer/GeneralOptionsHBox"]
|
||||
layout_mode = 2
|
||||
text = " Resize Packed Image"
|
||||
|
||||
[node name="ResizeOptionButton" type="SpinBox" parent="Panel/MarginContainer/VBoxContainer/GeneralOptionsHBox"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
tooltip_text = "A value of 0 disables resizing."
|
||||
min_value = 128.0
|
||||
max_value = 4096.0
|
||||
step = 128.0
|
||||
value = 1024.0
|
||||
|
||||
[node name="VSeparator" type="VSeparator" parent="Panel/MarginContainer/VBoxContainer/GeneralOptionsHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="GenerateMipmapsCheckBox" type="CheckBox" parent="Panel/MarginContainer/VBoxContainer/GeneralOptionsHBox"]
|
||||
layout_mode = 2
|
||||
button_pressed = true
|
||||
text = "Generate Mipmaps"
|
||||
|
||||
[node name="HighQualityCheckBox" type="CheckBox" parent="Panel/MarginContainer/VBoxContainer/GeneralOptionsHBox"]
|
||||
layout_mode = 2
|
||||
text = "Import High Quality"
|
||||
|
||||
[node name="PackButton" type="Button" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Pack textures as..."
|
||||
|
||||
[node name="StatusLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 60)
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="CloseButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Close"
|
||||
|
||||
[connection signal="toggled" from="Panel/MarginContainer/VBoxContainer/GeneralOptionsHBox/ResizeToggle" to="Panel/MarginContainer/VBoxContainer/GeneralOptionsHBox/ResizeOptionButton" method="set_visible"]
|
||||
@@ -1,15 +0,0 @@
|
||||
@tool
|
||||
extends Button
|
||||
|
||||
signal dropped
|
||||
|
||||
func _can_drop_data(p_position, p_data) -> bool:
|
||||
if typeof(p_data) == TYPE_DICTIONARY:
|
||||
if p_data.files.size() == 1:
|
||||
match p_data.files[0].get_extension():
|
||||
"png", "bmp", "exr", "hdr", "jpg", "jpeg", "tga", "svg", "webp", "ktx", "dds":
|
||||
return true
|
||||
return false
|
||||
|
||||
func _drop_data(p_position, p_data) -> void:
|
||||
dropped.emit(p_data.files[0])
|
||||
@@ -1 +0,0 @@
|
||||
uid://r0eex2idvm56
|
||||
@@ -1,32 +0,0 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="$SOURCE_FILE"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=$HIGH_QUALITY
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=2
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=$GENERATE_MIPMAPS
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
@@ -1,116 +0,0 @@
|
||||
extends Node
|
||||
|
||||
const DIRECTORY_SETUP: String = "res://addons/terrain_3d/src/directory_setup.tscn"
|
||||
|
||||
var plugin: EditorPlugin
|
||||
var dialog: ConfirmationDialog
|
||||
var select_dir_btn: Button
|
||||
var selected_dir_le: LineEdit
|
||||
var select_upg_btn: Button
|
||||
var upgrade_file_le: LineEdit
|
||||
var editor_file_dialog: EditorFileDialog
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
editor_file_dialog = EditorFileDialog.new()
|
||||
editor_file_dialog.set_filters(PackedStringArray(["*.res"]))
|
||||
editor_file_dialog.set_file_mode(EditorFileDialog.FILE_MODE_SAVE_FILE)
|
||||
editor_file_dialog.access = EditorFileDialog.ACCESS_RESOURCES
|
||||
editor_file_dialog.ok_button_text = "Open"
|
||||
editor_file_dialog.title = "Open a folder or file"
|
||||
editor_file_dialog.file_selected.connect(_on_file_selected)
|
||||
editor_file_dialog.dir_selected.connect(_on_dir_selected)
|
||||
editor_file_dialog.size = Vector2i(850, 550)
|
||||
editor_file_dialog.transient = false
|
||||
editor_file_dialog.exclusive = false
|
||||
editor_file_dialog.popup_window = true
|
||||
add_child(editor_file_dialog)
|
||||
|
||||
|
||||
func directory_setup_popup() -> void:
|
||||
dialog = load(DIRECTORY_SETUP).instantiate()
|
||||
dialog.hide()
|
||||
|
||||
# Nodes
|
||||
select_dir_btn = dialog.get_node("Margin/VBox/DirHBox/SelectDir")
|
||||
selected_dir_le = dialog.get_node("Margin/VBox/DirHBox/LineEdit")
|
||||
select_upg_btn = dialog.get_node("Margin/VBox/UpgradeHBox/SelectResFile")
|
||||
upgrade_file_le = dialog.get_node("Margin/VBox/UpgradeHBox/LineEdit")
|
||||
upgrade_file_le.text = ""
|
||||
|
||||
if plugin.terrain.data_directory:
|
||||
selected_dir_le.text = plugin.terrain.data_directory
|
||||
|
||||
if plugin.terrain.storage:
|
||||
upgrade_file_le.text = plugin.terrain.storage.get_path()
|
||||
|
||||
# Icons
|
||||
plugin.ui.set_button_editor_icon(select_upg_btn, "Folder")
|
||||
plugin.ui.set_button_editor_icon(select_dir_btn, "Folder")
|
||||
|
||||
#Signals
|
||||
select_upg_btn.pressed.connect(_on_select_file_pressed.bind(EditorFileDialog.FILE_MODE_OPEN_FILE))
|
||||
select_dir_btn.pressed.connect(_on_select_file_pressed.bind(EditorFileDialog.FILE_MODE_OPEN_DIR))
|
||||
dialog.confirmed.connect(_on_close_requested)
|
||||
dialog.canceled.connect(_on_close_requested)
|
||||
dialog.get_ok_button().pressed.connect(_on_ok_pressed)
|
||||
|
||||
# Popup
|
||||
EditorInterface.popup_dialog_centered(dialog)
|
||||
|
||||
|
||||
func _on_close_requested() -> void:
|
||||
dialog.queue_free()
|
||||
dialog = null
|
||||
|
||||
|
||||
func _on_select_file_pressed(file_mode: EditorFileDialog.FileMode) -> void:
|
||||
editor_file_dialog.file_mode = file_mode
|
||||
editor_file_dialog.popup_centered()
|
||||
|
||||
|
||||
func _on_dir_selected(path: String) -> void:
|
||||
selected_dir_le.text = path
|
||||
|
||||
|
||||
func _on_file_selected(path: String) -> void:
|
||||
upgrade_file_le.text = path
|
||||
|
||||
|
||||
func _on_ok_pressed() -> void:
|
||||
if not plugin.terrain:
|
||||
push_error("Not connected terrain. Click the Terrain3D node first")
|
||||
return
|
||||
if selected_dir_le.text.is_empty():
|
||||
push_error("No data directory specified")
|
||||
return
|
||||
if not DirAccess.dir_exists_absolute(selected_dir_le.text):
|
||||
push_error("Directory doesn't exist: ", selected_dir_le.text)
|
||||
return
|
||||
# Check if directory empty of terrain files
|
||||
var data_found: bool = false
|
||||
var files: Array = DirAccess.get_files_at(selected_dir_le.text)
|
||||
for file in files:
|
||||
if file.begins_with("terrain3d") || file.ends_with(".res"):
|
||||
data_found = true
|
||||
break
|
||||
|
||||
print("Setting terrain directory: ", selected_dir_le.text)
|
||||
plugin.terrain.data_directory = selected_dir_le.text
|
||||
|
||||
if not upgrade_file_le.text.is_empty():
|
||||
if data_found:
|
||||
push_warning("Target directory already has terrain data. Specify an empty directory to upgrade")
|
||||
return
|
||||
if not FileAccess.file_exists(upgrade_file_le.text):
|
||||
push_error("File doesn't exist: ", upgrade_file_le.text)
|
||||
return
|
||||
|
||||
if not plugin.terrain.storage or \
|
||||
( plugin.terrain.storage and plugin.terrain.storage.get_path() != upgrade_file_le.text):
|
||||
print("Loading storage file: ", upgrade_file_le.text)
|
||||
plugin.terrain.set_storage(load(upgrade_file_le.text))
|
||||
|
||||
if plugin.terrain.storage:
|
||||
print("Begining upgrade of: ", upgrade_file_le.text)
|
||||
plugin.terrain.split_storage()
|
||||
@@ -1 +0,0 @@
|
||||
uid://dt80i8xsj8tun
|
||||
@@ -1,66 +0,0 @@
|
||||
[gd_scene format=3 uid="uid://by3kr2nqbqr67"]
|
||||
|
||||
[node name="DirectorySetup" type="ConfirmationDialog"]
|
||||
title = "Terrain3D Data Directory Setup"
|
||||
position = Vector2i(0, 36)
|
||||
size = Vector2i(750, 574)
|
||||
visible = true
|
||||
|
||||
[node name="Margin" type="MarginContainer" parent="."]
|
||||
offset_left = 8.0
|
||||
offset_top = 8.0
|
||||
offset_right = 742.0
|
||||
offset_bottom = 525.0
|
||||
theme_override_constants/margin_left = 20
|
||||
theme_override_constants/margin_top = 20
|
||||
theme_override_constants/margin_right = 20
|
||||
theme_override_constants/margin_bottom = 20
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="Margin"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Instructions" type="Label" parent="Margin/VBox"]
|
||||
custom_minimum_size = Vector2(400, 0)
|
||||
layout_mode = 2
|
||||
text = "Terrain3D now stores data in a directory instead of a single file. Each region is stored in a separate file named `terrain3d[-_]##[-_]##.res`. For instance, the region at location (-1, 1) would be named `terrain3d-01_01.res`. Enable Terrain3D / Debug / Show Region Labels for a visual display."
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="DirectoryLabel" type="Label" parent="Margin/VBox"]
|
||||
custom_minimum_size = Vector2(400, 0)
|
||||
layout_mode = 2
|
||||
text = "
|
||||
Specify the directory to store your data. Any existing region files will be loaded."
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="DirHBox" type="HBoxContainer" parent="Margin/VBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="Margin/VBox/DirHBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "Data directory"
|
||||
|
||||
[node name="SelectDir" type="Button" parent="Margin/VBox/DirHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="UpgradeLabel" type="Label" parent="Margin/VBox"]
|
||||
custom_minimum_size = Vector2(400, 0)
|
||||
layout_mode = 2
|
||||
text = "
|
||||
If you wish to upgrade a storage file from v0.8.4 - v0.9.2, specify it below. Data will be stored in the directory above upon save. The original file will not be touched."
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="UpgradeHBox" type="HBoxContainer" parent="Margin/VBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="Margin/VBox/UpgradeHBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "Storage .res to upgrade"
|
||||
|
||||
[node name="SelectResFile" type="Button" parent="Margin/VBox/UpgradeHBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Spacer" type="Control" parent="Margin/VBox"]
|
||||
custom_minimum_size = Vector2(0, 40)
|
||||
layout_mode = 2
|
||||
@@ -1,3 +1,6 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# DoubleSlider for Terrain3D
|
||||
# Should work for other UIs
|
||||
@tool
|
||||
class_name DoubleSlider
|
||||
extends Control
|
||||
@@ -10,9 +13,23 @@ var min_value: float = 0.0
|
||||
var max_value: float = 100.0
|
||||
var step: float = 1.0
|
||||
var range := Vector2(0, 100)
|
||||
var display_scale: float = 1.
|
||||
var position_x: float = 0.
|
||||
var minimum_x: float = 60.
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# Setup Display Scale
|
||||
# 0 auto, 1 75%, 2 100%, 3 125%, 4 150%, 5 175%, 6 200%, 7 custom
|
||||
var es: EditorSettings = EditorInterface.get_editor_settings()
|
||||
var ds: int = es.get_setting("interface/editor/display_scale")
|
||||
if ds == 0:
|
||||
ds = 2
|
||||
elif ds == 7:
|
||||
display_scale = es.get_setting("interface/editor/custom_display_scale")
|
||||
else:
|
||||
display_scale = float(ds + 2) * .25
|
||||
|
||||
update_label()
|
||||
|
||||
|
||||
@@ -68,11 +85,21 @@ func get_value() -> Vector2:
|
||||
func update_label() -> void:
|
||||
if label:
|
||||
label.set_text(str(range.x) + suffix + "/" + str(range.y) + suffix)
|
||||
|
||||
if position_x == 0:
|
||||
position_x = label.position.x
|
||||
else:
|
||||
label.position.x = position_x + 5 * display_scale
|
||||
label.custom_minimum_size.x = minimum_x + 5 * display_scale
|
||||
|
||||
|
||||
func _get_handle() -> int:
|
||||
return 1
|
||||
|
||||
|
||||
func _gui_input(p_event: InputEvent) -> void:
|
||||
if p_event is InputEventMouseButton:
|
||||
if p_event.get_button_index() == MOUSE_BUTTON_LEFT:
|
||||
var button: int = p_event.get_button_index()
|
||||
if button in [ MOUSE_BUTTON_LEFT, MOUSE_BUTTON_WHEEL_UP, MOUSE_BUTTON_WHEEL_DOWN ]:
|
||||
if p_event.is_pressed():
|
||||
var mid_point = (range.x + range.y) / 2.0
|
||||
var xpos: float = p_event.get_position().x * 2.0
|
||||
@@ -80,7 +107,13 @@ func _gui_input(p_event: InputEvent) -> void:
|
||||
grabbed_handle = 1
|
||||
else:
|
||||
grabbed_handle = -1
|
||||
set_slider(p_event.get_position().x)
|
||||
match button:
|
||||
MOUSE_BUTTON_LEFT:
|
||||
set_slider(p_event.get_position().x)
|
||||
MOUSE_BUTTON_WHEEL_DOWN:
|
||||
set_slider(-1., true)
|
||||
MOUSE_BUTTON_WHEEL_UP:
|
||||
set_slider(1., true)
|
||||
else:
|
||||
grabbed_handle = 0
|
||||
|
||||
@@ -89,14 +122,20 @@ func _gui_input(p_event: InputEvent) -> void:
|
||||
set_slider(p_event.get_position().x)
|
||||
|
||||
|
||||
func set_slider(p_xpos: float) -> void:
|
||||
func set_slider(p_xpos: float, p_relative: bool = false) -> void:
|
||||
if grabbed_handle == 0:
|
||||
return
|
||||
var xpos_step: float = clamp(snappedf((p_xpos / size.x) * max_value, step), min_value, max_value)
|
||||
if(grabbed_handle < 0):
|
||||
range.x = xpos_step
|
||||
if p_relative:
|
||||
range.x += p_xpos
|
||||
else:
|
||||
range.x = xpos_step
|
||||
else:
|
||||
range.y = xpos_step
|
||||
if p_relative:
|
||||
range.y += p_xpos
|
||||
else:
|
||||
range.y = xpos_step
|
||||
set_value(range)
|
||||
|
||||
|
||||
@@ -111,14 +150,15 @@ func _notification(p_what: int) -> void:
|
||||
# Draw foreground bar
|
||||
var handle: Texture2D = get_theme_icon("grabber", "HSlider")
|
||||
var area: StyleBox = get_theme_stylebox("grabber_area", "HSlider")
|
||||
var h: float = size.y / 2 - handle.get_size().y / 2
|
||||
var startx: float = (range.x / max_value) * size.x
|
||||
var endx: float = (range.y / max_value) * size.x #- startx
|
||||
var endx: float = (range.y / max_value) * size.x
|
||||
draw_style_box(area, Rect2(Vector2(startx, mid_y), Vector2(endx - startx, bg_height)))
|
||||
|
||||
# Draw handles, slightly in so they don't get on the outside edges
|
||||
var handle_pos: Vector2
|
||||
handle_pos.x = clamp(startx - handle.get_size().x/2, -5, size.x)
|
||||
handle_pos.x = clamp(startx - handle.get_size().x/2, -10, size.x)
|
||||
handle_pos.y = clamp(endx - handle.get_size().x/2, 0, size.x - 10)
|
||||
draw_texture(handle, Vector2(handle_pos.x, -mid_y))
|
||||
draw_texture(handle, Vector2(handle_pos.y, -mid_y))
|
||||
draw_texture(handle, Vector2(handle_pos.x, -mid_y - 10 * (display_scale - 1.)))
|
||||
draw_texture(handle, Vector2(handle_pos.y, -mid_y - 10 * (display_scale - 1.)))
|
||||
|
||||
update_label()
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://cd6164a8pp48f
|
||||
uid://stro0p1oawfb
|
||||
|
||||
397
addons/terrain_3d/src/editor_plugin.gd
Normal file
397
addons/terrain_3d/src/editor_plugin.gd
Normal file
@@ -0,0 +1,397 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# Editor Plugin for Terrain3D
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
|
||||
# Includes
|
||||
const UI: Script = preload("res://addons/terrain_3d/src/ui.gd")
|
||||
const RegionGizmo: Script = preload("res://addons/terrain_3d/src/region_gizmo.gd")
|
||||
const ASSET_DOCK: String = "res://addons/terrain_3d/src/asset_dock.tscn"
|
||||
|
||||
var modifier_ctrl: bool
|
||||
var modifier_alt: bool
|
||||
var modifier_shift: bool
|
||||
var _last_modifiers: int = 0
|
||||
var _input_mode: int = 0 # -1: camera move, 0: none, 1: operating
|
||||
var _use_meta: bool = false
|
||||
|
||||
var terrain: Terrain3D
|
||||
var _last_terrain: Terrain3D
|
||||
var nav_region: NavigationRegion3D
|
||||
|
||||
var editor: Terrain3DEditor
|
||||
var editor_settings: EditorSettings
|
||||
var ui: Node # Terrain3DUI see Godot #75388
|
||||
var asset_dock: PanelContainer
|
||||
var region_gizmo: RegionGizmo
|
||||
var current_region_position: Vector2
|
||||
var mouse_global_position: Vector3 = Vector3.ZERO
|
||||
var godot_editor_window: Window # The Godot Editor window
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
if OS.get_name() == "macOS":
|
||||
_use_meta = true
|
||||
|
||||
# Get the Godot Editor window. Structure is root:Window/EditorNode/Base Control
|
||||
godot_editor_window = EditorInterface.get_base_control().get_parent().get_parent()
|
||||
godot_editor_window.focus_entered.connect(_on_godot_focus_entered)
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
editor = Terrain3DEditor.new()
|
||||
setup_editor_settings()
|
||||
ui = UI.new()
|
||||
ui.plugin = self
|
||||
add_child(ui)
|
||||
|
||||
region_gizmo = RegionGizmo.new()
|
||||
|
||||
scene_changed.connect(_on_scene_changed)
|
||||
|
||||
asset_dock = load(ASSET_DOCK).instantiate()
|
||||
asset_dock.initialize(self)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
asset_dock.remove_dock(true)
|
||||
asset_dock.queue_free()
|
||||
ui.queue_free()
|
||||
editor.free()
|
||||
|
||||
scene_changed.disconnect(_on_scene_changed)
|
||||
godot_editor_window.focus_entered.disconnect(_on_godot_focus_entered)
|
||||
|
||||
|
||||
func _on_godot_focus_entered() -> void:
|
||||
_read_input()
|
||||
ui.update_decal()
|
||||
|
||||
|
||||
## EditorPlugin selection function call chain isn't consistent. Here's the map of calls:
|
||||
## Assume we handle Terrain3D and NavigationRegion3D
|
||||
# Click Terrain3D: _handles(Terrain3D), _make_visible(true), _edit(Terrain3D)
|
||||
# Deselect: _make_visible(false), _edit(null)
|
||||
# Click other node: _handles(OtherNode)
|
||||
# Click NavRegion3D: _handles(NavReg3D), _make_visible(true), _edit(NavReg3D)
|
||||
# Click NavRegion3D, Terrain3D: _handles(Terrain3D), _edit(Terrain3D)
|
||||
# Click Terrain3D, NavRegion3D: _handles(NavReg3D), _edit(NavReg3D)
|
||||
func _handles(p_object: Object) -> bool:
|
||||
if p_object is Terrain3D:
|
||||
return true
|
||||
elif p_object is NavigationRegion3D and is_instance_valid(_last_terrain):
|
||||
return true
|
||||
|
||||
# Terrain3DObjects requires access to EditorUndoRedoManager. The only way to make sure it
|
||||
# always has it, is to pass it in here. _edit is NOT called if the node is cut and pasted.
|
||||
elif p_object is Terrain3DObjects:
|
||||
p_object.editor_setup(self)
|
||||
elif p_object is Node3D and p_object.get_parent() is Terrain3DObjects:
|
||||
p_object.get_parent().editor_setup(self)
|
||||
|
||||
return false
|
||||
|
||||
|
||||
func _make_visible(p_visible: bool, p_redraw: bool = false) -> void:
|
||||
if p_visible and is_selected():
|
||||
ui.set_visible(true)
|
||||
asset_dock.update_dock()
|
||||
else:
|
||||
ui.set_visible(false)
|
||||
|
||||
|
||||
func _edit(p_object: Object) -> void:
|
||||
if !p_object:
|
||||
_clear()
|
||||
|
||||
if p_object is Terrain3D:
|
||||
if p_object == terrain:
|
||||
return
|
||||
terrain = p_object
|
||||
_last_terrain = terrain
|
||||
terrain.set_plugin(self)
|
||||
terrain.set_editor(editor)
|
||||
editor.set_terrain(terrain)
|
||||
region_gizmo.set_node_3d(terrain)
|
||||
terrain.add_gizmo(region_gizmo)
|
||||
ui.set_visible(true)
|
||||
terrain.set_meta("_edit_lock_", true)
|
||||
|
||||
# Get alerted when a new asset list is loaded
|
||||
if not terrain.assets_changed.is_connected(asset_dock.update_assets):
|
||||
terrain.assets_changed.connect(asset_dock.update_assets)
|
||||
asset_dock.update_assets()
|
||||
# Get alerted when the region map changes
|
||||
if not terrain.data.region_map_changed.is_connected(update_region_grid):
|
||||
terrain.data.region_map_changed.connect(update_region_grid)
|
||||
update_region_grid()
|
||||
else:
|
||||
_clear()
|
||||
|
||||
if is_terrain_valid(_last_terrain):
|
||||
if p_object is NavigationRegion3D:
|
||||
ui.set_visible(true, true)
|
||||
nav_region = p_object
|
||||
else:
|
||||
nav_region = null
|
||||
|
||||
|
||||
func _clear() -> void:
|
||||
if is_terrain_valid():
|
||||
if terrain.data.region_map_changed.is_connected(update_region_grid):
|
||||
terrain.data.region_map_changed.disconnect(update_region_grid)
|
||||
|
||||
terrain.clear_gizmos()
|
||||
terrain = null
|
||||
editor.set_terrain(null)
|
||||
|
||||
ui.clear_picking()
|
||||
|
||||
region_gizmo.clear()
|
||||
|
||||
|
||||
func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) -> int:
|
||||
if not is_terrain_valid():
|
||||
return AFTER_GUI_INPUT_PASS
|
||||
|
||||
_read_input(p_event)
|
||||
ui.update_decal()
|
||||
|
||||
## 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
|
||||
# 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_PASS
|
||||
mouse_global_position = intersection_point
|
||||
|
||||
## Handle mouse movement
|
||||
if p_event is InputEventMouseMotion:
|
||||
|
||||
if _input_mode != -1: # Not cam rotation
|
||||
## Update region highlight
|
||||
var region_position: Vector2 = ( Vector2(mouse_global_position.x, mouse_global_position.z) \
|
||||
/ (terrain.get_region_size() * terrain.get_vertex_spacing()) ).floor()
|
||||
if current_region_position != region_position:
|
||||
current_region_position = region_position
|
||||
update_region_grid()
|
||||
|
||||
if _input_mode > 0 and editor.is_operating():
|
||||
# Inject pressure - Relies on C++ set_brush_data() using same dictionary instance
|
||||
ui.brush_data["mouse_pressure"] = p_event.pressure
|
||||
|
||||
editor.operate(mouse_global_position, p_viewport_camera.rotation.y)
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
return AFTER_GUI_INPUT_PASS
|
||||
|
||||
if p_event is InputEventMouseButton and _input_mode > 0:
|
||||
if p_event.is_pressed():
|
||||
# If picking
|
||||
if ui.is_picking():
|
||||
ui.pick(mouse_global_position)
|
||||
if not ui.operation_builder or not ui.operation_builder.is_ready():
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
if modifier_ctrl and editor.get_tool() == Terrain3DEditor.HEIGHT:
|
||||
var height: float = terrain.data.get_height(mouse_global_position)
|
||||
ui.brush_data["height"] = height
|
||||
ui.tool_settings.set_setting("height", height)
|
||||
|
||||
# If adjusting regions
|
||||
if editor.get_tool() == Terrain3DEditor.REGION:
|
||||
# Skip regions that already exist or don't
|
||||
var has_region: bool = terrain.data.has_regionp(mouse_global_position)
|
||||
var op: int = editor.get_operation()
|
||||
if ( has_region and op == Terrain3DEditor.ADD) or \
|
||||
( not has_region and op == Terrain3DEditor.SUBTRACT ):
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
# If an automatic operation is ready to go (e.g. gradient)
|
||||
if ui.operation_builder and ui.operation_builder.is_ready():
|
||||
ui.operation_builder.apply_operation(editor, mouse_global_position, p_viewport_camera.rotation.y)
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
# Mouse clicked, start editing
|
||||
editor.start_operation(mouse_global_position)
|
||||
editor.operate(mouse_global_position, p_viewport_camera.rotation.y)
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
# _input_apply released, save undo data
|
||||
elif editor.is_operating():
|
||||
editor.stop_operation()
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
return AFTER_GUI_INPUT_PASS
|
||||
|
||||
|
||||
func _read_input(p_event: InputEvent = null) -> void:
|
||||
## Determine if user is moving camera or applying
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) or \
|
||||
p_event is InputEventMouseButton and p_event.is_released() and \
|
||||
p_event.get_button_index() == MOUSE_BUTTON_LEFT:
|
||||
_input_mode = 1
|
||||
else:
|
||||
_input_mode = 0
|
||||
|
||||
match get_setting("editors/3d/navigation/navigation_scheme", 0):
|
||||
2, 1: # Modo, Maya
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or \
|
||||
( Input.is_key_pressed(KEY_ALT) and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) ):
|
||||
_input_mode = -1
|
||||
if p_event is InputEventMouseButton and p_event.is_released() and \
|
||||
( p_event.get_button_index() == MOUSE_BUTTON_RIGHT or \
|
||||
( Input.is_key_pressed(KEY_ALT) and p_event.get_button_index() == MOUSE_BUTTON_LEFT )):
|
||||
ui.last_rmb_time = Time.get_ticks_msec()
|
||||
0, _: # Godot
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or \
|
||||
Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
|
||||
_input_mode = -1
|
||||
if p_event is InputEventMouseButton and p_event.is_released() and \
|
||||
( p_event.get_button_index() == MOUSE_BUTTON_RIGHT or \
|
||||
p_event.get_button_index() == MOUSE_BUTTON_MIDDLE ):
|
||||
ui.last_rmb_time = Time.get_ticks_msec()
|
||||
if _input_mode < 0:
|
||||
return
|
||||
|
||||
## Determine modifiers pressed
|
||||
modifier_shift = Input.is_key_pressed(KEY_SHIFT)
|
||||
modifier_ctrl = Input.is_key_pressed(KEY_META) if _use_meta else Input.is_key_pressed(KEY_CTRL)
|
||||
# Keybind enum: Alt,Space,Meta,Capslock
|
||||
var alt_key: int
|
||||
match get_setting("terrain3d/config/alt_key_bind", 0):
|
||||
3: alt_key = KEY_CAPSLOCK
|
||||
2: alt_key = KEY_META
|
||||
1: alt_key = KEY_SPACE
|
||||
0, _: alt_key = KEY_ALT
|
||||
modifier_alt = Input.is_key_pressed(alt_key)
|
||||
|
||||
# Return if modifiers haven't changed AND brush_data has them;
|
||||
# modifiers disappear from brush_data when clicking asset_dock (Why?)
|
||||
var current_mods: int = int(modifier_shift) | int(modifier_ctrl) << 1 | int(modifier_alt) << 2
|
||||
if _last_modifiers == current_mods and ui.brush_data.has("modifier_shift"):
|
||||
return
|
||||
|
||||
_last_modifiers = current_mods
|
||||
ui.brush_data["modifier_shift"] = modifier_shift
|
||||
ui.brush_data["modifier_ctrl"] = modifier_ctrl
|
||||
ui.brush_data["modifier_alt"] = modifier_alt
|
||||
ui.update_modifiers()
|
||||
|
||||
|
||||
func update_region_grid() -> void:
|
||||
if not region_gizmo:
|
||||
return
|
||||
region_gizmo.set_hidden(not ui.visible)
|
||||
|
||||
if is_terrain_valid():
|
||||
region_gizmo.show_rect = editor.get_tool() == Terrain3DEditor.REGION
|
||||
region_gizmo.use_secondary_color = editor.get_operation() == Terrain3DEditor.SUBTRACT
|
||||
region_gizmo.region_position = current_region_position
|
||||
region_gizmo.region_size = terrain.get_region_size() * terrain.get_vertex_spacing()
|
||||
region_gizmo.grid = terrain.get_data().get_region_locations()
|
||||
|
||||
terrain.update_gizmos()
|
||||
return
|
||||
|
||||
region_gizmo.show_rect = false
|
||||
region_gizmo.region_size = 1024
|
||||
region_gizmo.grid = [Vector2i.ZERO]
|
||||
|
||||
|
||||
func _on_scene_changed(scene_root: Node) -> void:
|
||||
if not scene_root:
|
||||
return
|
||||
|
||||
for node in scene_root.find_children("", "Terrain3DObjects"):
|
||||
node.editor_setup(self)
|
||||
|
||||
asset_dock.update_assets()
|
||||
await get_tree().create_timer(2).timeout
|
||||
asset_dock.update_thumbnails()
|
||||
|
||||
|
||||
func is_terrain_valid(p_terrain: Terrain3D = null) -> bool:
|
||||
var t: Terrain3D
|
||||
if p_terrain:
|
||||
t = p_terrain
|
||||
else:
|
||||
t = terrain
|
||||
if is_instance_valid(t) and t.is_inside_tree() and t.data:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func is_selected() -> bool:
|
||||
var selected: Array[Node] = EditorInterface.get_selection().get_selected_nodes()
|
||||
for node in selected:
|
||||
if ( is_instance_valid(_last_terrain) and node.get_instance_id() == _last_terrain.get_instance_id() ) or \
|
||||
node is Terrain3D:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func select_terrain() -> void:
|
||||
if is_instance_valid(_last_terrain) and is_terrain_valid(_last_terrain) and not is_selected():
|
||||
var es: EditorSelection = EditorInterface.get_selection()
|
||||
es.clear()
|
||||
es.add_node(_last_terrain)
|
||||
|
||||
|
||||
## Editor Settings
|
||||
|
||||
|
||||
func setup_editor_settings() -> void:
|
||||
editor_settings = EditorInterface.get_editor_settings()
|
||||
if not editor_settings.has_setting("terrain3d/config/alt_key_bind"):
|
||||
editor_settings.set("terrain3d/config/alt_key_bind", 0)
|
||||
var property_info = {
|
||||
"name": "terrain3d/config/alt_key_bind",
|
||||
"type": TYPE_INT,
|
||||
"hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": "Alt,Space,Meta,Capslock"
|
||||
}
|
||||
editor_settings.add_property_info(property_info)
|
||||
|
||||
|
||||
func set_setting(p_str: String, p_value: Variant) -> void:
|
||||
editor_settings.set_setting(p_str, p_value)
|
||||
|
||||
|
||||
func get_setting(p_str: String, p_default: Variant) -> Variant:
|
||||
if editor_settings.has_setting(p_str):
|
||||
return editor_settings.get_setting(p_str)
|
||||
else:
|
||||
return p_default
|
||||
|
||||
|
||||
func has_setting(p_str: String) -> bool:
|
||||
return editor_settings.has_setting(p_str)
|
||||
|
||||
|
||||
func erase_setting(p_str: String) -> void:
|
||||
editor_settings.erase(p_str)
|
||||
1
addons/terrain_3d/src/editor_plugin.gd.uid
Normal file
1
addons/terrain_3d/src/editor_plugin.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bsgxo1qywjdf3
|
||||
@@ -1,3 +1,5 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# Gradient Operation Builder for Terrain3D
|
||||
extends "res://addons/terrain_3d/src/operation_builder.gd"
|
||||
|
||||
|
||||
@@ -52,4 +54,3 @@ func apply_operation(p_editor: Terrain3DEditor, p_global_position: Vector3, p_ca
|
||||
p_editor.stop_operation()
|
||||
|
||||
_get_point_picker().clear()
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://b1qt62vc3vnx7
|
||||
uid://def7sych6dp8b
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# Multipicker for Terrain3D
|
||||
extends HBoxContainer
|
||||
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://dqwxbfvjra3p3
|
||||
uid://dvdtoa32h6xdn
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# Operation Builder for Terrain3D
|
||||
extends RefCounted
|
||||
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://3rphgkvw2bi1
|
||||
uid://bu5cm0eh052rm
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# Editor Region Gizmos for Terrain3D
|
||||
extends EditorNode3DGizmo
|
||||
|
||||
var material: StandardMaterial3D
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://ddnxpafte8kb7
|
||||
uid://bh6qwe1ok4cx3
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
extends HBoxContainer
|
||||
|
||||
|
||||
const DirectoryWizard: Script = preload("res://addons/terrain_3d/src/directory_setup.gd")
|
||||
const Packer: Script = preload("res://addons/terrain_3d/src/channel_packer.gd")
|
||||
const Baker: Script = preload("res://addons/terrain_3d/src/baker.gd")
|
||||
|
||||
var plugin: EditorPlugin
|
||||
var menu_button: MenuButton = MenuButton.new()
|
||||
var directory_setup: DirectoryWizard = DirectoryWizard.new()
|
||||
var packer: Packer = Packer.new()
|
||||
var baker: Baker = Baker.new()
|
||||
|
||||
# These are IDs and order must be consistent with add_item and set_disabled IDs
|
||||
enum {
|
||||
MENU_DIRECTORY_SETUP,
|
||||
MENU_PACK_TEXTURES,
|
||||
MENU_SEPARATOR,
|
||||
MENU_BAKE_ARRAY_MESH,
|
||||
MENU_BAKE_OCCLUDER,
|
||||
MENU_SEPARATOR2,
|
||||
MENU_SET_UP_NAVIGATION,
|
||||
MENU_BAKE_NAV_MESH,
|
||||
}
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
directory_setup.plugin = plugin
|
||||
packer.plugin = plugin
|
||||
baker.plugin = plugin
|
||||
add_child(directory_setup)
|
||||
add_child(baker)
|
||||
|
||||
menu_button.text = "Terrain3D Tools"
|
||||
menu_button.get_popup().add_item("Directory Setup...", MENU_DIRECTORY_SETUP)
|
||||
menu_button.get_popup().add_item("Pack Textures...", MENU_PACK_TEXTURES)
|
||||
menu_button.get_popup().add_separator("", MENU_SEPARATOR)
|
||||
menu_button.get_popup().add_item("Bake ArrayMesh...", MENU_BAKE_ARRAY_MESH)
|
||||
menu_button.get_popup().add_item("Bake Occluder3D...", MENU_BAKE_OCCLUDER)
|
||||
menu_button.get_popup().add_separator("", MENU_SEPARATOR2)
|
||||
menu_button.get_popup().add_item("Set up Navigation...", MENU_SET_UP_NAVIGATION)
|
||||
menu_button.get_popup().add_item("Bake NavMesh...", MENU_BAKE_NAV_MESH)
|
||||
|
||||
menu_button.get_popup().id_pressed.connect(_on_menu_pressed)
|
||||
menu_button.about_to_popup.connect(_on_menu_about_to_popup)
|
||||
add_child(menu_button)
|
||||
|
||||
|
||||
func _on_menu_pressed(p_id: int) -> void:
|
||||
match p_id:
|
||||
MENU_DIRECTORY_SETUP:
|
||||
directory_setup.directory_setup_popup()
|
||||
MENU_PACK_TEXTURES:
|
||||
packer.pack_textures_popup()
|
||||
MENU_BAKE_ARRAY_MESH:
|
||||
baker.bake_mesh_popup()
|
||||
MENU_BAKE_OCCLUDER:
|
||||
baker.bake_occluder_popup()
|
||||
MENU_SET_UP_NAVIGATION:
|
||||
baker.set_up_navigation_popup()
|
||||
MENU_BAKE_NAV_MESH:
|
||||
baker.bake_nav_mesh()
|
||||
|
||||
|
||||
func _on_menu_about_to_popup() -> void:
|
||||
menu_button.get_popup().set_item_disabled(MENU_DIRECTORY_SETUP, not plugin.terrain)
|
||||
menu_button.get_popup().set_item_disabled(MENU_PACK_TEXTURES, not plugin.terrain)
|
||||
menu_button.get_popup().set_item_disabled(MENU_BAKE_ARRAY_MESH, not plugin.terrain)
|
||||
menu_button.get_popup().set_item_disabled(MENU_BAKE_OCCLUDER, not plugin.terrain)
|
||||
|
||||
if plugin.terrain:
|
||||
var nav_regions: Array[NavigationRegion3D] = baker.find_terrain_nav_regions(plugin.terrain)
|
||||
menu_button.get_popup().set_item_disabled(MENU_BAKE_NAV_MESH, nav_regions.size() == 0)
|
||||
menu_button.get_popup().set_item_disabled(MENU_SET_UP_NAVIGATION, nav_regions.size() != 0)
|
||||
elif plugin.nav_region:
|
||||
var terrains: Array[Terrain3D] = baker.find_nav_region_terrains(plugin.nav_region)
|
||||
menu_button.get_popup().set_item_disabled(MENU_BAKE_NAV_MESH, terrains.size() == 0)
|
||||
menu_button.get_popup().set_item_disabled(MENU_SET_UP_NAVIGATION, true)
|
||||
else:
|
||||
menu_button.get_popup().set_item_disabled(MENU_BAKE_NAV_MESH, true)
|
||||
menu_button.get_popup().set_item_disabled(MENU_SET_UP_NAVIGATION, true)
|
||||
@@ -1 +0,0 @@
|
||||
uid://cbtr86lrjls7a
|
||||
@@ -1,3 +1,5 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# Tool settings bar for Terrain3D
|
||||
extends PanelContainer
|
||||
|
||||
signal picking(type, callback)
|
||||
@@ -39,6 +41,7 @@ const NO_SAVE: int = 0x20 # Don't save this in EditorSettings
|
||||
var plugin: EditorPlugin # Actually Terrain3DEditorPlugin, but Godot still has CRC errors
|
||||
var brush_preview_material: ShaderMaterial
|
||||
var select_brush_button: Button
|
||||
var selected_brush_imgs: Array
|
||||
var main_list: HFlowContainer
|
||||
var advanced_list: VBoxContainer
|
||||
var height_list: VBoxContainer
|
||||
@@ -86,6 +89,9 @@ func _ready() -> void:
|
||||
add_setting({ "name":"enable_texture", "label":"Texture", "type":SettingType.CHECKBOX,
|
||||
"list":main_list, "default":true, "flags":ADD_SEPARATOR })
|
||||
|
||||
add_setting({ "name":"texture_filter", "label":"Texture Filter", "type":SettingType.CHECKBOX,
|
||||
"list":main_list, "default":false, "flags":ADD_SEPARATOR })
|
||||
|
||||
add_setting({ "name":"margin", "type":SettingType.SLIDER, "list":main_list, "default":0,
|
||||
"unit":"", "range":Vector3(-50, 50, 1), "flags":ALLOW_OUT_OF_BOUNDS })
|
||||
|
||||
@@ -171,6 +177,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:
|
||||
@@ -267,29 +275,33 @@ func add_brushes(p_parent: Control) -> void:
|
||||
while file_name != "":
|
||||
if !dir.current_is_dir() and file_name.ends_with(".exr"):
|
||||
var img: Image = Image.load_from_file(BRUSH_PATH + "/" + file_name)
|
||||
img = Terrain3DUtil.black_to_alpha(img)
|
||||
if img.get_width() < 1024 and img.get_height() < 1024:
|
||||
img.resize(1024, 1024, Image.INTERPOLATE_CUBIC)
|
||||
var tex: ImageTexture = ImageTexture.create_from_image(img)
|
||||
var thumbimg: Image = img.duplicate()
|
||||
img.convert(Image.FORMAT_RF)
|
||||
|
||||
var btn: Button = Button.new()
|
||||
btn.set_custom_minimum_size(Vector2.ONE * 100)
|
||||
btn.set_button_icon(tex)
|
||||
btn.set_meta("image", img)
|
||||
btn.set_expand_icon(true)
|
||||
btn.set_material(_get_brush_preview_material())
|
||||
btn.set_toggle_mode(true)
|
||||
btn.set_button_group(brush_button_group)
|
||||
btn.mouse_entered.connect(_on_brush_hover.bind(true, btn))
|
||||
btn.mouse_exited.connect(_on_brush_hover.bind(false, btn))
|
||||
brush_list.add_child(btn, true)
|
||||
if thumbimg.get_width() != 100 and thumbimg.get_height() != 100:
|
||||
thumbimg.resize(100, 100, Image.INTERPOLATE_CUBIC)
|
||||
thumbimg = Terrain3DUtil.black_to_alpha(thumbimg)
|
||||
thumbimg.convert(Image.FORMAT_LA8)
|
||||
var thumbtex: ImageTexture = ImageTexture.create_from_image(thumbimg)
|
||||
|
||||
var brush_btn: Button = Button.new()
|
||||
brush_btn.set_custom_minimum_size(Vector2.ONE * 100)
|
||||
brush_btn.set_button_icon(thumbtex)
|
||||
brush_btn.set_meta("image", img)
|
||||
brush_btn.set_expand_icon(true)
|
||||
brush_btn.set_material(_get_brush_preview_material())
|
||||
brush_btn.set_toggle_mode(true)
|
||||
brush_btn.set_button_group(brush_button_group)
|
||||
brush_btn.mouse_entered.connect(_on_brush_hover.bind(true, brush_btn))
|
||||
brush_btn.mouse_exited.connect(_on_brush_hover.bind(false, brush_btn))
|
||||
brush_list.add_child(brush_btn, true)
|
||||
if file_name == DEFAULT_BRUSH:
|
||||
default_brush_btn = btn
|
||||
default_brush_btn = brush_btn
|
||||
|
||||
var lbl: Label = Label.new()
|
||||
btn.name = file_name.get_basename().to_pascal_case()
|
||||
btn.add_child(lbl, true)
|
||||
lbl.text = btn.name
|
||||
brush_btn.name = file_name.get_basename().to_pascal_case()
|
||||
brush_btn.add_child(lbl, true)
|
||||
lbl.text = brush_btn.name
|
||||
lbl.visible = false
|
||||
lbl.position.y = 70
|
||||
lbl.add_theme_color_override("font_shadow_color", Color.BLACK)
|
||||
@@ -304,6 +316,7 @@ func add_brushes(p_parent: Control) -> void:
|
||||
if not default_brush_btn:
|
||||
default_brush_btn = brush_button_group.get_buttons()[0]
|
||||
default_brush_btn.set_pressed(true)
|
||||
_generate_brush_texture(default_brush_btn)
|
||||
|
||||
settings["brush"] = brush_button_group
|
||||
|
||||
@@ -443,7 +456,7 @@ func add_setting(p_args: Dictionary) -> void:
|
||||
pending_children.push_back(option)
|
||||
control = option
|
||||
|
||||
SettingType.SLIDER, SettingType.DOUBLE_SLIDER:
|
||||
SettingType.SLIDER, SettingType.DOUBLE_SLIDER:
|
||||
var slider: Control
|
||||
if p_type == SettingType.SLIDER:
|
||||
# Create an editable value box
|
||||
@@ -473,7 +486,7 @@ func add_setting(p_args: Dictionary) -> void:
|
||||
else: # DOUBLE_SLIDER
|
||||
var label := Label.new()
|
||||
label.set_custom_minimum_size(Vector2(60, 0))
|
||||
label.set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
label.set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER)
|
||||
slider = DoubleSlider.new()
|
||||
slider.label = label
|
||||
slider.suffix = p_suffix
|
||||
@@ -560,9 +573,7 @@ func get_setting(p_setting: String) -> Variant:
|
||||
elif object is DoubleSlider:
|
||||
value = object.get_value()
|
||||
elif object is ButtonGroup: # "brush"
|
||||
var img: Image = object.get_pressed_button().get_meta("image")
|
||||
var tex: Texture2D = object.get_pressed_button().get_button_icon()
|
||||
value = [ img, tex ]
|
||||
value = selected_brush_imgs
|
||||
elif object is CheckBox:
|
||||
value = object.is_pressed()
|
||||
elif object is ColorPickerButton:
|
||||
@@ -610,19 +621,30 @@ func show_settings(p_settings: PackedStringArray) -> void:
|
||||
select_brush_button.show()
|
||||
|
||||
|
||||
func _on_setting_changed(p_data: Variant = null) -> void:
|
||||
# If a button was clicked on a submenu
|
||||
if p_data is Button and p_data.get_parent().get_parent() is PopupPanel:
|
||||
if p_data.get_parent().name == "BrushList":
|
||||
# Optionally Set selected brush texture in main brush button
|
||||
p_data.get_parent().get_parent().get_parent().set_button_icon(p_data.get_button_icon())
|
||||
# Hide popup
|
||||
p_data.get_parent().get_parent().set_visible(false)
|
||||
# Hide label
|
||||
if p_data.get_child_count() > 0:
|
||||
p_data.get_child(0).visible = false
|
||||
func _on_setting_changed(p_object: Variant = null) -> void:
|
||||
# If a brush was selected
|
||||
if p_object is Button and p_object.get_parent().name == "BrushList":
|
||||
_generate_brush_texture(p_object)
|
||||
# Optionally Set selected brush texture in main brush button
|
||||
if select_brush_button:
|
||||
select_brush_button.set_button_icon(p_object.get_button_icon())
|
||||
# Hide popup
|
||||
p_object.get_parent().get_parent().set_visible(false)
|
||||
# Hide label
|
||||
if p_object.get_child_count() > 0:
|
||||
p_object.get_child(0).visible = false
|
||||
emit_signal("setting_changed")
|
||||
|
||||
|
||||
|
||||
func _generate_brush_texture(p_btn: Button) -> void:
|
||||
if p_btn is Button:
|
||||
var img: Image = p_btn.get_meta("image")
|
||||
if img.get_width() < 1024 and img.get_height() < 1024:
|
||||
img = img.duplicate()
|
||||
img.resize(1024, 1024, Image.INTERPOLATE_CUBIC)
|
||||
var tex: ImageTexture = ImageTexture.create_from_image(img)
|
||||
selected_brush_imgs = [ img, tex ]
|
||||
|
||||
|
||||
func _on_drawable_toggled(p_button_pressed: bool) -> void:
|
||||
if not p_button_pressed:
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://b0hs7rbtc8jfy
|
||||
uid://ciskaaennrffu
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# Toolbar for Terrain3D
|
||||
extends VFlowContainer
|
||||
|
||||
signal tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation)
|
||||
@@ -26,8 +28,8 @@ func _init() -> void:
|
||||
set_custom_minimum_size(Vector2(20, 0))
|
||||
|
||||
func _ready() -> void:
|
||||
add_tool_group.connect("pressed", _on_tool_selected)
|
||||
sub_tool_group.connect("pressed", _on_tool_selected)
|
||||
add_tool_group.pressed.connect(_on_tool_selected)
|
||||
sub_tool_group.pressed.connect(_on_tool_selected)
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.REGION,
|
||||
"add_text":"Add Region", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_REGION_ADD,
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://bthdcp8t4awsk
|
||||
uid://b1j37u6utjbom
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# UI for Terrain3D
|
||||
extends Node
|
||||
#class_name Terrain3DUI Cannot be named until Godot #75388
|
||||
|
||||
|
||||
# Includes
|
||||
const TerrainMenu: Script = preload("res://addons/terrain_3d/menu/terrain_menu.gd")
|
||||
const Toolbar: Script = preload("res://addons/terrain_3d/src/toolbar.gd")
|
||||
const ToolSettings: Script = preload("res://addons/terrain_3d/src/tool_settings.gd")
|
||||
const TerrainMenu: Script = preload("res://addons/terrain_3d/src/terrain_menu.gd")
|
||||
const OperationBuilder: Script = preload("res://addons/terrain_3d/src/operation_builder.gd")
|
||||
const GradientOperationBuilder: Script = preload("res://addons/terrain_3d/src/gradient_operation_builder.gd")
|
||||
const COLOR_RAISE := Color.WHITE
|
||||
const COLOR_LOWER := Color(.02, .02, .02)
|
||||
const COLOR_SMOOTH := Color(0.5, 0, .1)
|
||||
const COLOR_LOWER := Color.BLACK
|
||||
const COLOR_SMOOTH := Color(0.5, 0, .2)
|
||||
const COLOR_LIFT := Color.ORANGE
|
||||
const COLOR_FLATTEN := Color.BLUE_VIOLET
|
||||
const COLOR_HEIGHT := Color(0., 0.32, .4)
|
||||
@@ -20,7 +21,7 @@ const COLOR_SPRAY := Color.PALE_GREEN
|
||||
const COLOR_ROUGHNESS := Color.ROYAL_BLUE
|
||||
const COLOR_AUTOSHADER := Color.DODGER_BLUE
|
||||
const COLOR_HOLES := Color.BLACK
|
||||
const COLOR_NAVIGATION := Color(.15, .0, .255)
|
||||
const COLOR_NAVIGATION := Color(.28, .0, .25)
|
||||
const COLOR_INSTANCER := Color.CRIMSON
|
||||
const COLOR_PICK_COLOR := Color.WHITE
|
||||
const COLOR_PICK_HEIGHT := Color.DARK_RED
|
||||
@@ -31,8 +32,13 @@ const OP_POSITIVE_ONLY: int = 0x01
|
||||
const OP_NEGATIVE_ONLY: int = 0x02
|
||||
|
||||
const RING1: String = "res://addons/terrain_3d/brushes/ring1.exr"
|
||||
@onready var ring_texture := ImageTexture.create_from_image(Terrain3DUtil.black_to_alpha(Image.load_from_file(RING1)))
|
||||
|
||||
var ring_texture : ImageTexture
|
||||
@onready var region_texture := ImageTexture.new() :
|
||||
set(value):
|
||||
var image: Image = Image.create_empty(1, 1, false, Image.FORMAT_R8)
|
||||
image.fill(Color.WHITE)
|
||||
value.create_from_image(image)
|
||||
region_texture = value
|
||||
var plugin: EditorPlugin # Actually Terrain3DEditorPlugin, but Godot still has CRC errors
|
||||
var toolbar: Toolbar
|
||||
var tool_settings: ToolSettings
|
||||
@@ -41,31 +47,42 @@ var setting_has_changed: bool = false
|
||||
var visible: bool = false
|
||||
var picking: int = Terrain3DEditor.TOOL_MAX
|
||||
var picking_callback: Callable
|
||||
var decal: Decal
|
||||
var decal_timer: Timer
|
||||
var gradient_decals: Array[Decal]
|
||||
var brush_data: Dictionary
|
||||
var operation_builder: OperationBuilder
|
||||
var last_tool: Terrain3DEditor.Tool
|
||||
var last_operation: Terrain3DEditor.Operation
|
||||
var last_rmb_time: int = 0 # Set in editor.gd
|
||||
|
||||
# Compatibility decals, indices; 0 = main brush, 1 = slope point A, 2 = slope point B
|
||||
var editor_decal_position: Array[Vector2]
|
||||
var editor_decal_rotation: Array[float]
|
||||
var editor_decal_size: Array[float]
|
||||
var editor_decal_color: Array[Color]
|
||||
var editor_decal_visible: Array[bool]
|
||||
# Editor decals, indices; 0 = main brush, 1 = slope point A, 2 = slope point B
|
||||
var mat_rid: RID
|
||||
var editor_decal_position: Array[Vector2] = [Vector2(), Vector2(), Vector2()]
|
||||
var editor_decal_rotation: Array[float] = [float(), float(), float()]
|
||||
var editor_decal_size: Array[float] = [float(), float(), float()]
|
||||
var editor_decal_color: Array[Color] = [Color(), Color(), Color()]
|
||||
var editor_decal_visible: Array[bool] = [bool(), bool(), bool()]
|
||||
var editor_brush_texture_rid: RID = RID()
|
||||
var editor_decal_timer: Timer
|
||||
var editor_decal_fade: float :
|
||||
set(value):
|
||||
editor_decal_fade = value
|
||||
if editor_decal_color.size() > 0:
|
||||
editor_decal_color[0].a = value
|
||||
if is_shader_valid():
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_color", editor_decal_color)
|
||||
if value < 0.001:
|
||||
var r_map: PackedInt32Array = plugin.terrain.data.get_region_map()
|
||||
RenderingServer.material_set_param(mat_rid, "_region_map", r_map)
|
||||
var editor_ring_texture_rid: RID
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
toolbar = Toolbar.new()
|
||||
toolbar.hide()
|
||||
toolbar.connect("tool_changed", _on_tool_changed)
|
||||
toolbar.tool_changed.connect(_on_tool_changed)
|
||||
|
||||
tool_settings = ToolSettings.new()
|
||||
tool_settings.connect("setting_changed", _on_setting_changed)
|
||||
tool_settings.connect("picking", _on_picking)
|
||||
tool_settings.setting_changed.connect(_on_setting_changed)
|
||||
tool_settings.picking.connect(_on_picking)
|
||||
tool_settings.plugin = plugin
|
||||
tool_settings.hide()
|
||||
|
||||
@@ -79,15 +96,19 @@ func _enter_tree() -> void:
|
||||
|
||||
_on_tool_changed(Terrain3DEditor.REGION, Terrain3DEditor.ADD)
|
||||
|
||||
decal = Decal.new()
|
||||
add_child(decal)
|
||||
decal_timer = Timer.new()
|
||||
decal_timer.wait_time = .5
|
||||
decal_timer.one_shot = true
|
||||
decal_timer.timeout.connect(Callable(func(node):
|
||||
if node:
|
||||
get_tree().create_tween().tween_property(node, "albedo_mix", 0.0, 0.15)).bind(decal))
|
||||
add_child(decal_timer)
|
||||
editor_decal_timer = Timer.new()
|
||||
editor_decal_timer.wait_time = .5
|
||||
editor_decal_timer.one_shot = true
|
||||
editor_decal_timer.timeout.connect(func():
|
||||
get_tree().create_tween().tween_property(self, "editor_decal_fade", 0.0, 0.15))
|
||||
add_child(editor_decal_timer)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var img: Image = Image.load_from_file(RING1)
|
||||
img.convert(Image.FORMAT_R8)
|
||||
ring_texture = ImageTexture.create_from_image(img)
|
||||
editor_ring_texture_rid = ring_texture.get_rid()
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
@@ -96,11 +117,7 @@ func _exit_tree() -> void:
|
||||
toolbar.queue_free()
|
||||
tool_settings.queue_free()
|
||||
terrain_menu.queue_free()
|
||||
decal.queue_free()
|
||||
decal_timer.queue_free()
|
||||
for gradient_decal in gradient_decals:
|
||||
gradient_decal.queue_free()
|
||||
gradient_decals.clear()
|
||||
editor_decal_timer.queue_free()
|
||||
|
||||
|
||||
func set_visible(p_visible: bool, p_menu_only: bool = false) -> void:
|
||||
@@ -117,7 +134,7 @@ func set_visible(p_visible: bool, p_menu_only: bool = false) -> void:
|
||||
|
||||
if(plugin.editor):
|
||||
if(p_visible):
|
||||
await get_tree().create_timer(.01).timeout # Won't work, otherwise.
|
||||
await get_tree().create_timer(.01).timeout # Won't work, otherwise
|
||||
_on_tool_changed(last_tool, last_operation)
|
||||
else:
|
||||
plugin.editor.set_tool(Terrain3DEditor.TOOL_MAX)
|
||||
@@ -185,7 +202,7 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
|
||||
to_show.push_back("color")
|
||||
to_show.push_back("color_picker")
|
||||
to_show.push_back("slope")
|
||||
to_show.push_back("enable_texture")
|
||||
to_show.push_back("texture_filter")
|
||||
to_show.push_back("margin")
|
||||
to_show.push_back("remove")
|
||||
|
||||
@@ -196,7 +213,7 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
|
||||
to_show.push_back("roughness")
|
||||
to_show.push_back("roughness_picker")
|
||||
to_show.push_back("slope")
|
||||
to_show.push_back("enable_texture")
|
||||
to_show.push_back("texture_filter")
|
||||
to_show.push_back("margin")
|
||||
to_show.push_back("remove")
|
||||
|
||||
@@ -236,6 +253,7 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
|
||||
to_show.push_back("show_cursor_while_painting")
|
||||
to_show.push_back("gamma")
|
||||
to_show.push_back("jitter")
|
||||
to_show.push_back("crosshair_threshold")
|
||||
tool_settings.show_settings(to_show)
|
||||
|
||||
operation_builder = null
|
||||
@@ -258,9 +276,9 @@ func _on_setting_changed() -> void:
|
||||
return
|
||||
brush_data = tool_settings.get_settings()
|
||||
brush_data["asset_id"] = plugin.asset_dock.get_current_list().get_selected_id()
|
||||
update_decal()
|
||||
plugin.editor.set_brush_data(brush_data)
|
||||
plugin.editor.set_operation(_modify_operation(plugin.editor.get_operation()))
|
||||
update_decal()
|
||||
|
||||
|
||||
func update_modifiers() -> void:
|
||||
@@ -299,195 +317,211 @@ func _invert_operation(p_operation: Terrain3DEditor.Operation, flags: int = OP_N
|
||||
|
||||
|
||||
func update_decal() -> void:
|
||||
if not plugin.terrain or brush_data.size() <= 3:
|
||||
return
|
||||
mat_rid = plugin.terrain.material.get_material_rid()
|
||||
editor_decal_timer.start()
|
||||
|
||||
# If not a state that should show the decal, hide everything and return
|
||||
if not visible or \
|
||||
not plugin.terrain or \
|
||||
plugin._input_mode < 0 or \
|
||||
# Wait for cursor to recenter after moving camera before revealing
|
||||
# See https://github.com/godotengine/godot/issues/70098
|
||||
Time.get_ticks_msec() - last_rmb_time <= 30 or \
|
||||
brush_data.is_empty() or \
|
||||
plugin.editor.get_tool() == Terrain3DEditor.REGION or \
|
||||
(plugin._input_mode > 0 and not brush_data["show_cursor_while_painting"]):
|
||||
decal.visible = false
|
||||
for gradient_decal in gradient_decals:
|
||||
gradient_decal.visible = false
|
||||
hide_decal()
|
||||
return
|
||||
|
||||
decal.position = plugin.mouse_global_position
|
||||
decal.visible = true
|
||||
decal.size = Vector3.ONE * maxf(brush_data["size"], .5)
|
||||
if brush_data["align_to_view"]:
|
||||
var cam: Camera3D = plugin.terrain.get_camera();
|
||||
if (cam):
|
||||
decal.rotation.y = cam.rotation.y
|
||||
else:
|
||||
decal.rotation.y = 0
|
||||
|
||||
|
||||
reset_decal_arrays()
|
||||
editor_decal_position[0] = Vector2(plugin.mouse_global_position.x, plugin.mouse_global_position.z)
|
||||
editor_decal_visible[0] = true
|
||||
# Set region size, and modify region map for none background mode.
|
||||
var r_map: PackedInt32Array = plugin.terrain.data.get_region_map()
|
||||
if plugin.editor.get_tool() == Terrain3DEditor.REGION:
|
||||
var r_size: float = float(plugin.terrain.get_region_size()) * plugin.terrain.get_vertex_spacing()
|
||||
var map_size: int = plugin.terrain.data.REGION_MAP_SIZE
|
||||
var half_r_size: float = r_size * 0.5
|
||||
var pos: Vector2 = (Vector2(plugin.mouse_global_position.x, plugin.mouse_global_position.z) +
|
||||
Vector2(half_r_size, half_r_size)).snappedf(r_size) - Vector2(half_r_size, half_r_size)
|
||||
editor_brush_texture_rid = region_texture.get_rid()
|
||||
editor_decal_position[0] = pos
|
||||
editor_decal_size[0] = r_size
|
||||
editor_decal_rotation[0] = 0.0
|
||||
|
||||
var loc: Vector2i = plugin.terrain.data.get_region_location(plugin.mouse_global_position)
|
||||
loc += Vector2i(map_size / 2, map_size / 2)
|
||||
if !(loc.x < 0 or loc.x > map_size - 1 or loc.y < 0 or loc.y > map_size - 1):
|
||||
var index: int = clampi(loc.y * map_size + loc.x, 0, map_size * map_size - 1)
|
||||
if plugin.terrain.material.get_world_background() == Terrain3DMaterial.WorldBackground.NONE:
|
||||
if r_map[index] == 0 and plugin.editor.get_operation() == Terrain3DEditor.ADD:
|
||||
r_map[index] = -index - 1
|
||||
else:
|
||||
r_map[index] = r_map[index]
|
||||
|
||||
match plugin.editor.get_operation():
|
||||
Terrain3DEditor.ADD:
|
||||
if r_map[index] <= 0:
|
||||
editor_decal_color[0] = Color.WHITE
|
||||
editor_decal_color[0].a = 0.25
|
||||
else:
|
||||
hide_decal()
|
||||
|
||||
Terrain3DEditor.SUBTRACT:
|
||||
if r_map[index] > 0:
|
||||
editor_decal_color[0] = Color.WHITE * .15
|
||||
editor_decal_color[0].a = 0.75
|
||||
else:
|
||||
hide_decal()
|
||||
else:
|
||||
hide_decal()
|
||||
# Set texture and color
|
||||
if picking != Terrain3DEditor.TOOL_MAX:
|
||||
decal.texture_albedo = ring_texture
|
||||
decal.size = Vector3.ONE * 10. * plugin.terrain.get_vertex_spacing()
|
||||
elif picking != Terrain3DEditor.TOOL_MAX:
|
||||
editor_brush_texture_rid = ring_texture.get_rid()
|
||||
editor_decal_size[0] = 10. * plugin.terrain.get_vertex_spacing()
|
||||
match picking:
|
||||
Terrain3DEditor.HEIGHT:
|
||||
decal.modulate = COLOR_PICK_HEIGHT
|
||||
editor_decal_color[0] = COLOR_PICK_HEIGHT
|
||||
Terrain3DEditor.COLOR:
|
||||
decal.modulate = COLOR_PICK_COLOR
|
||||
editor_decal_color[0] = COLOR_PICK_COLOR
|
||||
Terrain3DEditor.ROUGHNESS:
|
||||
decal.modulate = COLOR_PICK_ROUGH
|
||||
decal.modulate.a = 1.0
|
||||
editor_decal_color[0] = COLOR_PICK_ROUGH
|
||||
editor_decal_color[0].a = 1.0
|
||||
else:
|
||||
decal.texture_albedo = brush_data["brush"][1]
|
||||
editor_brush_texture_rid = brush_data["brush"][1].get_rid()
|
||||
editor_decal_size[0] = maxf(brush_data["size"], .5)
|
||||
if brush_data["align_to_view"]:
|
||||
var cam: Camera3D = plugin.terrain.get_camera();
|
||||
if (cam):
|
||||
editor_decal_rotation[0] = cam.rotation.y
|
||||
else:
|
||||
editor_decal_rotation[0] = 0.
|
||||
match plugin.editor.get_tool():
|
||||
Terrain3DEditor.SCULPT:
|
||||
match plugin.editor.get_operation():
|
||||
Terrain3DEditor.ADD:
|
||||
if plugin.modifier_alt:
|
||||
decal.modulate = COLOR_LIFT
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5)
|
||||
editor_decal_color[0] = COLOR_LIFT
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .2, .5)
|
||||
else:
|
||||
decal.modulate = COLOR_RAISE
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5)
|
||||
editor_decal_color[0] = COLOR_RAISE
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .25, .5)
|
||||
Terrain3DEditor.SUBTRACT:
|
||||
if plugin.modifier_alt:
|
||||
decal.modulate = COLOR_FLATTEN
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5)
|
||||
editor_decal_color[0] = COLOR_FLATTEN
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .25, .5) + .1
|
||||
else:
|
||||
decal.modulate = COLOR_LOWER
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5) + .5
|
||||
editor_decal_color[0] = COLOR_LOWER
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .2, .5) + .25
|
||||
Terrain3DEditor.AVERAGE:
|
||||
decal.modulate = COLOR_SMOOTH
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5) + .2
|
||||
editor_decal_color[0] = COLOR_SMOOTH
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .2, .5) + .25
|
||||
Terrain3DEditor.GRADIENT:
|
||||
decal.modulate = COLOR_SLOPE
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5)
|
||||
editor_decal_color[0] = COLOR_SLOPE
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .2, .4)
|
||||
Terrain3DEditor.HEIGHT:
|
||||
decal.modulate = COLOR_HEIGHT
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5)
|
||||
editor_decal_color[0] = COLOR_HEIGHT
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .2, .5) + .25
|
||||
Terrain3DEditor.TEXTURE:
|
||||
match plugin.editor.get_operation():
|
||||
Terrain3DEditor.REPLACE:
|
||||
decal.modulate = COLOR_PAINT
|
||||
decal.modulate.a = .7
|
||||
editor_decal_color[0] = COLOR_PAINT
|
||||
editor_decal_color[0].a = .6
|
||||
Terrain3DEditor.SUBTRACT:
|
||||
decal.modulate = COLOR_PAINT
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5)
|
||||
editor_decal_color[0] = COLOR_PAINT
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .2, .5) + .1
|
||||
Terrain3DEditor.ADD:
|
||||
decal.modulate = COLOR_SPRAY
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5)
|
||||
editor_decal_color[0] = COLOR_SPRAY
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .15, .4)
|
||||
Terrain3DEditor.COLOR:
|
||||
decal.modulate = brush_data["color"].srgb_to_linear()
|
||||
decal.modulate.a *= clamp(brush_data["strength"], .2, .5)
|
||||
editor_decal_color[0] = brush_data["color"].srgb_to_linear()
|
||||
editor_decal_color[0].a *= clamp(brush_data["strength"], .2, .5)
|
||||
Terrain3DEditor.ROUGHNESS:
|
||||
decal.modulate = COLOR_ROUGHNESS
|
||||
decal.modulate.a = clamp(brush_data["strength"], .2, .5)
|
||||
editor_decal_color[0] = COLOR_ROUGHNESS
|
||||
editor_decal_color[0].a = clamp(brush_data["strength"], .2, .5) + .1
|
||||
Terrain3DEditor.AUTOSHADER:
|
||||
decal.modulate = COLOR_AUTOSHADER
|
||||
decal.modulate.a = .7
|
||||
editor_decal_color[0] = COLOR_AUTOSHADER
|
||||
editor_decal_color[0].a = .6
|
||||
Terrain3DEditor.HOLES:
|
||||
decal.modulate = COLOR_HOLES
|
||||
decal.modulate.a = .85
|
||||
editor_decal_color[0] = COLOR_HOLES
|
||||
editor_decal_color[0].a = .75
|
||||
Terrain3DEditor.NAVIGATION:
|
||||
decal.modulate = COLOR_NAVIGATION
|
||||
decal.modulate.a = .85
|
||||
editor_decal_color[0] = COLOR_NAVIGATION
|
||||
editor_decal_color[0].a = .80
|
||||
Terrain3DEditor.INSTANCER:
|
||||
decal.texture_albedo = ring_texture
|
||||
decal.modulate = COLOR_INSTANCER
|
||||
decal.modulate.a = 1.0
|
||||
decal.size.y = max(1000, decal.size.y)
|
||||
decal.albedo_mix = 1.0
|
||||
decal.cull_mask = 1 << ( plugin.terrain.get_mouse_layer() - 1 )
|
||||
decal_timer.start()
|
||||
|
||||
for gradient_decal in gradient_decals:
|
||||
gradient_decal.visible = false
|
||||
editor_brush_texture_rid = ring_texture.get_rid()
|
||||
editor_decal_color[0] = COLOR_INSTANCER
|
||||
editor_decal_color[0].a = .75
|
||||
|
||||
editor_decal_visible[1] = false
|
||||
editor_decal_visible[2] = false
|
||||
|
||||
if plugin.editor.get_operation() == Terrain3DEditor.GRADIENT:
|
||||
var index := 0
|
||||
for point in brush_data["gradient_points"]:
|
||||
if point != Vector3.ZERO:
|
||||
var point_decal: Decal = _get_gradient_decal(index)
|
||||
point_decal.visible = true
|
||||
point_decal.position = point
|
||||
index += 1
|
||||
|
||||
update_compatibility_decal()
|
||||
|
||||
|
||||
func _get_gradient_decal(index: int) -> Decal:
|
||||
if gradient_decals.size() > index:
|
||||
return gradient_decals[index]
|
||||
var point1: Vector3 = brush_data["gradient_points"][0]
|
||||
if point1 != Vector3.ZERO:
|
||||
editor_decal_color[1] = COLOR_SLOPE
|
||||
editor_decal_size[1] = 10. * plugin.terrain.get_vertex_spacing()
|
||||
editor_decal_visible[1] = true
|
||||
editor_decal_position[1] = Vector2(point1.x, point1.z)
|
||||
var point2: Vector3 = brush_data["gradient_points"][1]
|
||||
if point2 != Vector3.ZERO:
|
||||
editor_decal_color[2] = COLOR_SLOPE
|
||||
editor_decal_size[2] = 10. * plugin.terrain.get_vertex_spacing()
|
||||
editor_decal_visible[2] = true
|
||||
editor_decal_position[2] = Vector2(point2.x, point2.z)
|
||||
|
||||
var gradient_decal := Decal.new()
|
||||
gradient_decal = Decal.new()
|
||||
gradient_decal.texture_albedo = ring_texture
|
||||
gradient_decal.modulate = COLOR_SLOPE
|
||||
gradient_decal.size = Vector3.ONE * 10. * plugin.terrain.get_vertex_spacing()
|
||||
gradient_decal.size.y = 1000.
|
||||
gradient_decal.cull_mask = decal.cull_mask
|
||||
add_child(gradient_decal)
|
||||
if RenderingServer.get_current_rendering_method().contains("gl_compatibility"):
|
||||
for i in editor_decal_color.size():
|
||||
editor_decal_color[i].a = maxf(0.1, editor_decal_color[i].a - .25)
|
||||
|
||||
gradient_decals.push_back(gradient_decal)
|
||||
return gradient_decal
|
||||
editor_decal_fade = editor_decal_color[0].a
|
||||
# Update Shader params
|
||||
if is_shader_valid():
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_brush_texture", editor_brush_texture_rid)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_ring_texture", editor_ring_texture_rid)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_position", editor_decal_position)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_rotation", editor_decal_rotation)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_size", editor_decal_size)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_color", editor_decal_color)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_visible", editor_decal_visible)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_crosshair_threshold", brush_data["crosshair_threshold"] + 0.1)
|
||||
RenderingServer.material_set_param(mat_rid, "_region_map", r_map)
|
||||
|
||||
|
||||
func update_compatibility_decal() -> void:
|
||||
if not plugin.terrain.is_compatibility_mode():
|
||||
return
|
||||
func is_shader_valid() -> bool:
|
||||
# As long as the compiled shader contains at least 1 uniform, we can use it to check
|
||||
# if the shader compilation has failed, as this will then return an empty dictionary.
|
||||
if not plugin.terrain:
|
||||
return false
|
||||
var params = RenderingServer.get_shader_parameter_list(plugin.terrain.material.get_shader_rid())
|
||||
if params.is_empty():
|
||||
return false
|
||||
else:
|
||||
return true
|
||||
|
||||
# Verify setup
|
||||
if editor_decal_position.size() != 3:
|
||||
editor_decal_position.resize(3)
|
||||
editor_decal_rotation.resize(3)
|
||||
editor_decal_size.resize(3)
|
||||
editor_decal_color.resize(3)
|
||||
editor_decal_visible.resize(3)
|
||||
decal_timer.timeout.connect(func():
|
||||
var mat_rid: RID = plugin.terrain.material.get_material_rid()
|
||||
editor_decal_visible[0] = false
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_visible", editor_decal_visible)
|
||||
)
|
||||
|
||||
# Update compatibility decal
|
||||
var mat_rid: RID = plugin.terrain.material.get_material_rid()
|
||||
if decal.visible:
|
||||
editor_decal_position[0] = Vector2(decal.global_position.x, decal.global_position.z)
|
||||
editor_decal_rotation[0] = decal.rotation.y
|
||||
editor_decal_size[0] = brush_data.get("size")
|
||||
editor_decal_color[0] = decal.modulate
|
||||
editor_decal_visible[0] = decal.visible
|
||||
RenderingServer.material_set_param(
|
||||
mat_rid, "_editor_decal_0", decal.texture_albedo.get_rid()
|
||||
)
|
||||
if gradient_decals.size() >= 1:
|
||||
editor_decal_position[1] = Vector2(gradient_decals[0].global_position.x,
|
||||
gradient_decals[0].global_position.z)
|
||||
editor_decal_rotation[1] = gradient_decals[0].rotation.y
|
||||
editor_decal_size[1] = 10.0
|
||||
editor_decal_color[1] = gradient_decals[0].modulate
|
||||
editor_decal_visible[1] = gradient_decals[0].visible
|
||||
RenderingServer.material_set_param(
|
||||
mat_rid, "_editor_decal_1", gradient_decals[0].texture_albedo.get_rid()
|
||||
)
|
||||
if gradient_decals.size() >= 2:
|
||||
editor_decal_position[2] = Vector2(gradient_decals[1].global_position.x,
|
||||
gradient_decals[1].global_position.z)
|
||||
editor_decal_rotation[2] = gradient_decals[1].rotation.y
|
||||
editor_decal_size[2] = 10.0
|
||||
editor_decal_color[2] = gradient_decals[1].modulate
|
||||
editor_decal_visible[2] = gradient_decals[1].visible
|
||||
RenderingServer.material_set_param(
|
||||
mat_rid, "_editor_decal_2", gradient_decals[1].texture_albedo.get_rid()
|
||||
)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_position", editor_decal_position)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_rotation", editor_decal_rotation)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_size", editor_decal_size)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_color", editor_decal_color)
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_visible", editor_decal_visible)
|
||||
func hide_decal() -> void:
|
||||
editor_decal_visible = [false, false, false]
|
||||
if is_shader_valid():
|
||||
var r_map: PackedInt32Array = plugin.terrain.data.get_region_map()
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_visible", editor_decal_visible)
|
||||
RenderingServer.material_set_param(mat_rid, "_region_map", r_map)
|
||||
|
||||
|
||||
# These array sizes are reset to 0 when closing scenes for some unknown reason, so check and reset
|
||||
func reset_decal_arrays() -> void:
|
||||
if editor_decal_color.size() < 3:
|
||||
editor_decal_position = [Vector2(), Vector2(), Vector2()]
|
||||
editor_decal_rotation = [float(), float(), float()]
|
||||
editor_decal_size = [float(), float(), float()]
|
||||
editor_decal_color = [Color(), Color(), Color()]
|
||||
editor_decal_visible = [false, false, false]
|
||||
editor_brush_texture_rid = RID()
|
||||
|
||||
|
||||
func set_decal_rotation(p_rot: float) -> void:
|
||||
decal.rotation.y = p_rot
|
||||
editor_decal_rotation[0] = p_rot
|
||||
if is_shader_valid():
|
||||
RenderingServer.material_set_param(mat_rid, "_editor_decal_rotation", editor_decal_rotation)
|
||||
|
||||
|
||||
func _on_picking(p_type: int, p_callback: Callable) -> void:
|
||||
@@ -515,7 +549,7 @@ func pick(p_global_position: Vector3) -> void:
|
||||
var color: Color
|
||||
match picking:
|
||||
Terrain3DEditor.HEIGHT, Terrain3DEditor.SCULPT:
|
||||
color = plugin.terrain.data.get_pixel(Terrain3DRegion.TYPE_HEIGHT, p_global_position)
|
||||
color = Color(plugin.terrain.data.get_height(p_global_position), 0., 0., 1.)
|
||||
Terrain3DEditor.ROUGHNESS:
|
||||
color = plugin.terrain.data.get_pixel(Terrain3DRegion.TYPE_COLOR, p_global_position)
|
||||
Terrain3DEditor.COLOR:
|
||||
@@ -527,7 +561,9 @@ func pick(p_global_position: Vector3) -> void:
|
||||
_:
|
||||
push_error("Unsupported picking type: ", picking)
|
||||
return
|
||||
picking_callback.call(picking, color, p_global_position)
|
||||
if picking_callback.is_valid():
|
||||
picking_callback.call(picking, color, p_global_position)
|
||||
picking_callback = Callable()
|
||||
picking = Terrain3DEditor.TOOL_MAX
|
||||
|
||||
elif operation_builder and operation_builder.is_picking():
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://bv4lj2cvubl7p
|
||||
uid://bpad72s36mwkx
|
||||
|
||||
Reference in New Issue
Block a user