generate mesh from room walls

This commit is contained in:
Nitwel 2023-11-18 15:32:37 +01:00
parent 836380f6a4
commit 03ba7acef3
6 changed files with 90 additions and 5 deletions

View File

@ -94,6 +94,7 @@ func _call_fn(collider: Object, fn_name: String, node: Node3D = null, event = nu
if result != null && result is Dictionary:
result.merge(event, true)
event = result
if result != null && result is bool && result == false:
# Stop the event from bubbling up

View File

@ -4,6 +4,7 @@ extends Node3D
@onready var nav_edit: Button3D = $Navigation/Edit
@onready var menu_edit: Node3D = $Content/EditMenu
@onready var nav_room = $Navigation/Room
@onready var menu_room: Node3D = $Content/RoomMenu
@onready var nav_automate = $Navigation/Automate
@onready var nav_settings = $Navigation/Settings
@ -18,7 +19,7 @@ enum Menu {
var selected_menu := Menu.EDIT
func _ready():
pass
select_menu(selected_menu)
func _on_click(event):
if event.target == nav_view:
@ -36,7 +37,7 @@ func select_menu(menu: Menu):
selected_menu = menu
for child in $Content.get_children():
if child.is_visible():
child.hide()
$Content.remove_child(child)
var menu_node = enum_to_menu(menu)
var nav_node = enum_to_nav(menu)
@ -45,7 +46,7 @@ func select_menu(menu: Menu):
nav_node.disabled = true
if menu_node != null:
menu_node.show()
$Content.add_child(menu_node)
for child in $Navigation.get_children():
if child.active && child != nav_node:
@ -72,7 +73,7 @@ func enum_to_menu(menu: Menu):
Menu.EDIT:
return menu_edit
Menu.ROOM:
return null
return menu_room
Menu.AUTOMATE:
return null
Menu.SETTINGS:

View File

@ -23,6 +23,7 @@ mesh = SubResource("BoxMesh_08du6")
[node name="ImmersiveHomePanels" type="MeshInstance3D" parent="."]
transform = Transform3D(-4.37114e-10, 0, 0.01, 0, 0.01, 0, -0.01, 0, -4.37114e-10, 0.32, 0, -0.0500001)
visible = false
mesh = ExtResource("7_f4u4o")
[node name="Navigation" type="Node3D" parent="."]
@ -40,6 +41,7 @@ texture = ExtResource("5_8o1rb")
[node name="Edit" parent="Navigation" instance=ExtResource("5_w4i01")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.09)
toggleable = true
initial_active = true
[node name="Sprite3D" type="Sprite3D" parent="Navigation/Edit"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.012, 0)

View File

@ -6,24 +6,72 @@ const wall_edge_scene = preload("res://content/ui/menu/room/wall_edge.tscn")
@onready var teleport_root = $TeleportRoot
@onready var wall_corners = $TeleportRoot/WallCorners
@onready var wall_edges = $TeleportRoot/WallEdges
@onready var wall_mesh = $TeleportRoot/WallMesh
@onready var toggle_edit_button = $Interface/ToggleEdit
var moving = null
var ground_plane = Plane(Vector3.UP, Vector3.ZERO)
var edit_enabled = false
func _ready():
remove_child(teleport_root)
get_tree().get_root().get_node("Main").add_child.call_deferred(teleport_root)
teleport_root.get_node("Ground/Clickable").on_click.connect(func(event):
if !edit_enabled:
return
add_corner(event.ray.get_collision_point())
)
toggle_edit_button.get_node("Clickable").on_click.connect(func(event):
edit_enabled = event.active
if edit_enabled == false:
wall_corners.visible = false
wall_edges.visible = false
generate_mesh()
wall_mesh.visible = true
else:
wall_corners.visible = true
wall_edges.visible = true
wall_mesh.visible = false
)
func generate_mesh():
var st = SurfaceTool.new()
var wall_up = Vector3.UP * 3
st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
for i in range(wall_corners.get_child_count()):
var corner = get_corner(i)
print(corner.position, " ", corner.position + wall_up)
st.add_vertex(corner.position)
st.add_vertex(corner.position + wall_up)
var first_corner = get_corner(0)
st.add_vertex(first_corner.position)
st.add_vertex(first_corner.position + wall_up)
st.index()
st.generate_normals()
st.generate_tangents()
var mesh = st.commit()
wall_mesh.mesh = mesh
func add_corner(position: Vector3):
var corner = wall_corner_scene.instantiate()
corner.position = position
corner.get_node("Clickable").on_grab_down.connect(func(event):
if !edit_enabled:
return
moving = event.target
)

View File

@ -1,10 +1,17 @@
[gd_scene load_steps=4 format=3 uid="uid://c01gkeldvjwtr"]
[gd_scene load_steps=8 format=3 uid="uid://c01gkeldvjwtr"]
[ext_resource type="Script" path="res://content/ui/menu/room/room_menu.gd" id="1_ch4jb"]
[ext_resource type="Script" path="res://content/functions/clickable.gd" id="2_elugy"]
[ext_resource type="Material" uid="uid://bbx6fv7jq50tr" path="res://content/ui/menu/room/walls.tres" id="3_fke3j"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="3_whl7a"]
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_08sv0"]
[sub_resource type="ArrayMesh" id="ArrayMesh_7dibq"]
[sub_resource type="BoxMesh" id="BoxMesh_e37nn"]
size = Vector3(0.3, 0.01, 0.3)
[node name="RoomMenu" type="Node3D"]
script = ExtResource("1_ch4jb")
@ -21,3 +28,26 @@ script = ExtResource("2_elugy")
[node name="WallCorners" type="Node3D" parent="TeleportRoot"]
[node name="WallEdges" type="Node3D" parent="TeleportRoot"]
[node name="WallMesh" type="MeshInstance3D" parent="TeleportRoot"]
material_override = ExtResource("3_fke3j")
mesh = SubResource("ArrayMesh_7dibq")
[node name="Background" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.15)
mesh = SubResource("BoxMesh_e37nn")
[node name="Interface" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.01, 0)
[node name="ToggleEdit" parent="Interface" instance=ExtResource("3_whl7a")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.05, 0, 0.05)
toggleable = true
[node name="Clickable" type="Node" parent="Interface/ToggleEdit"]
script = ExtResource("2_elugy")
[node name="Label3D" type="Label3D" parent="Interface"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.17, -1.86265e-09, 0.05)
pixel_size = 0.001
text = "Edit Room"

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a84837d131d1a1676286c56bc80fc1dde59dc234ca68dc089b86d19c2aefc5a7
size 101