feat: implemented adding primitive with UI

This commit is contained in:
Sara Gerretsen 2025-12-08 15:33:02 +01:00
parent 670cfa1779
commit b6e8ca9225
8 changed files with 120 additions and 31 deletions

View file

@ -8,14 +8,7 @@
[ext_resource type="Texture2D" uid="uid://bl3gn6qruuy8w" path="res://assets/icons/plane.svg" id="4_xg7d5"]
[ext_resource type="Texture2D" uid="uid://d1te42w7wpkrx" path="res://assets/icons/noise.svg" id="5_eqbpn"]
[sub_resource type="PointPrimitive" id="PointPrimitive_pxqd5"]
slope = -0.7
height = 0.0
[sub_resource type="PointPrimitive" id="PointPrimitive_ba0ut"]
blend_range = 10.0
center = Vector2(50, 0)
slope = -0.7
[sub_resource type="PointPrimitive" id="PointPrimitive_5tm2q"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_pxqd5"]
frequency = 0.015
@ -87,7 +80,7 @@ var rotate_speed := .0015
var zoom_speed := 5.0
var rotating := false
var panning := false
var distance := 50
var distance := 200
var pivot := Vector3.ZERO
func _ready():
@ -106,14 +99,6 @@ func _unhandled_input(event: InputEvent) -> void:
global_position += (global_basis.y * motion.screen_relative.y - global_basis.x * motion.screen_relative.x) * rotate_speed * distance
look_at(pivot)
global_position = (global_position - pivot).normalized() * distance + pivot
elif event is InputEventMouseMotion and panning:
get_viewport().set_input_as_handled()
var backward := Vector3(global_basis.z.x, 0.0, global_basis.z.z).normalized()
var right := Vector3(global_basis.x.x, 0.0, global_basis.x.z).normalized()
var motion := event as InputEventMouseMotion
var translation = -(backward * motion.screen_relative.y + right * motion.screen_relative.x) * pan_speed * distance
pivot += translation
global_position += translation
elif event is InputEventMouseButton and (event as InputEventMouseButton).button_index == MOUSE_BUTTON_WHEEL_UP:
get_viewport().set_input_as_handled()
distance = max(1., distance - zoom_speed)
@ -122,17 +107,32 @@ func _unhandled_input(event: InputEvent) -> void:
get_viewport().set_input_as_handled()
distance = min(1000., distance + zoom_speed)
global_position = (global_position - pivot).normalized() * distance + pivot
elif event is InputEventMouseMotion and panning:
get_viewport().set_input_as_handled()
var backward := Vector3(global_basis.z.x, 0.0, global_basis.z.z).normalized()
var right := Vector3(global_basis.x.x, 0.0, global_basis.x.z).normalized()
var motion := event as InputEventMouseMotion
var translation = -(backward * motion.screen_relative.y + right * motion.screen_relative.x) * pan_speed * distance
pivot += translation
global_position += translation
"
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_xg7d5"]
load_path = "res://.godot/imported/point.svg-e68fd7c1e788d2c48d769cc58eba6e98.ctex"
[sub_resource type="PointPrimitive" id="PointPrimitive_5lcyj"]
[sub_resource type="PlanePrimitive" id="PlanePrimitive_5lcyj"]
[sub_resource type="NoisePrimitive" id="NoisePrimitive_5lcyj"]
[node name="Editor" type="Node3D" unique_id=1027707839]
[node name="TerrainMeshEditor" type="TerrainMeshEditor" parent="." unique_id=1382595562]
primitives = [SubResource("PointPrimitive_pxqd5"), SubResource("PointPrimitive_ba0ut"), SubResource("NoisePrimitive_ba0ut"), SubResource("NoisePrimitive_pxqd5"), SubResource("NoisePrimitive_q68jb"), SubResource("PlanePrimitive_ba0ut")]
primitives = [SubResource("PointPrimitive_5tm2q"), SubResource("NoisePrimitive_ba0ut"), SubResource("NoisePrimitive_pxqd5"), SubResource("NoisePrimitive_q68jb"), SubResource("PlanePrimitive_ba0ut")]
vertex_color_gradient = SubResource("Gradient_b1cmn")
color_gradient_end_height = 100.0
chunk_count = 4
chunk_scene = ExtResource("1_pxqd5")
point_primitive_object = ExtResource("1_b1cmn")
@ -159,58 +159,76 @@ offset_right = 258.0
grow_vertical = 2
theme = ExtResource("3_ba0ut")
[node name="TabContainer" type="TabContainer" parent="LeftPanel" unique_id=2095156888]
[node name="VBoxContainer" type="VBoxContainer" parent="LeftPanel" unique_id=1723457232]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Layers" type="TabContainer" parent="LeftPanel/VBoxContainer" unique_id=2095156888]
layout_mode = 2
size_flags_vertical = 3
current_tab = 0
[node name="Layers" type="VBoxContainer" parent="LeftPanel/TabContainer" unique_id=138865385]
[node name="Layers" type="VBoxContainer" parent="LeftPanel/VBoxContainer/Layers" unique_id=138865385]
layout_mode = 2
metadata/_tab_index = 0
[node name="Tree" type="PrimitiveLayerList" parent="LeftPanel/TabContainer/Layers" unique_id=797700186 node_paths=PackedStringArray("terrain")]
[node name="Tree" type="PrimitiveLayerList" parent="LeftPanel/VBoxContainer/Layers/Layers" unique_id=797700186 node_paths=PackedStringArray("terrain")]
layout_mode = 2
size_flags_vertical = 3
columns = 4
terrain = NodePath("../../../../TerrainMeshEditor")
scroll_horizontal_enabled = false
terrain = NodePath("../../../../../TerrainMeshEditor")
icons = {
&"NoisePrimitive": ExtResource("5_eqbpn"),
&"PlanePrimitive": ExtResource("4_xg7d5"),
&"PointPrimitive": ExtResource("4_5lcyj")
}
[node name="HBoxContainer" type="HBoxContainer" parent="LeftPanel/TabContainer/Layers" unique_id=702489990]
[node name="HBoxContainer" type="HBoxContainer" parent="LeftPanel/VBoxContainer/Layers/Layers" unique_id=702489990]
layout_mode = 2
size_flags_vertical = 8
alignment = 1
[node name="TextureRect" type="TextureRect" parent="LeftPanel/TabContainer/Layers/HBoxContainer" unique_id=1669840346]
[node name="TextureRect" type="TextureRect" parent="LeftPanel/VBoxContainer/Layers/Layers/HBoxContainer" unique_id=1669840346]
custom_minimum_size = Vector2(32, 32)
layout_mode = 2
texture = ExtResource("4_q68jb")
expand_mode = 2
stretch_mode = 4
[node name="AddPointPrimitive" type="Button" parent="LeftPanel/TabContainer/Layers/HBoxContainer" unique_id=535482641]
[node name="AddPointPrimitive" type="AddPrimitiveButton" parent="LeftPanel/VBoxContainer/Layers/Layers/HBoxContainer" unique_id=255935272 node_paths=PackedStringArray("terrain")]
custom_minimum_size = Vector2(32, 32)
layout_mode = 2
icon = SubResource("CompressedTexture2D_xg7d5")
expand_icon = true
primitive_blueprint = SubResource("PointPrimitive_5lcyj")
terrain = NodePath("../../../../../../TerrainMeshEditor")
[node name="AddPlanePrimitive" type="Button" parent="LeftPanel/TabContainer/Layers/HBoxContainer" unique_id=287076599]
[node name="AddPlanePrimitive" type="AddPrimitiveButton" parent="LeftPanel/VBoxContainer/Layers/Layers/HBoxContainer" unique_id=850669113 node_paths=PackedStringArray("terrain")]
custom_minimum_size = Vector2(32, 32)
layout_mode = 2
icon = ExtResource("4_xg7d5")
expand_icon = true
primitive_blueprint = SubResource("PlanePrimitive_5lcyj")
terrain = NodePath("../../../../../../TerrainMeshEditor")
[node name="AddNoisePrimitive" type="Button" parent="LeftPanel/TabContainer/Layers/HBoxContainer" unique_id=769590598]
[node name="AddNoisePrimitive" type="AddPrimitiveButton" parent="LeftPanel/VBoxContainer/Layers/Layers/HBoxContainer" unique_id=761062556 node_paths=PackedStringArray("terrain")]
custom_minimum_size = Vector2(32, 32)
layout_mode = 2
icon = ExtResource("5_eqbpn")
expand_icon = true
primitive_blueprint = SubResource("NoisePrimitive_5lcyj")
terrain = NodePath("../../../../../../TerrainMeshEditor")
[node name="Inspector" type="TabContainer" parent="LeftPanel/VBoxContainer" unique_id=240272030]
layout_mode = 2
size_flags_vertical = 3
current_tab = 0
[node name="Inspector" type="VBoxContainer" parent="LeftPanel/VBoxContainer/Inspector" unique_id=1225013744]
layout_mode = 2
metadata/_tab_index = 0
[connection signal="primitives_changed" from="TerrainMeshEditor" to="TerrainMeshEditor" method="_on_primitives_changed"]