Spaces:
Runtime error
Runtime error
Update the godot script to generate a mesh.
Browse files
godot.gd
CHANGED
|
@@ -3,6 +3,12 @@ extends EditorScript
|
|
| 3 |
|
| 4 |
var data:Dictionary = { "bathroom1": [8.52112676056338, 8.52112676056338, 6.408450704225352, 8.52112676056338, 6.408450704225352, 6.408450704225352, 8.52112676056338, 6.408450704225352], "bedroom1": [9.507042253521128, 5.422535211267606, 6.408450704225352, 5.422535211267606, 6.408450704225352, 3.3098591549295775, 9.507042253521128, 3.3098591549295775], "living_room": [14.71830985915493, 10.563380281690142, 10.563380281690142, 10.563380281690142, 10.563380281690142, 7.464788732394367, 14.71830985915493, 7.464788732394367], "kitchen": [9.507042253521128, 12.605633802816902, 4.366197183098592, 12.605633802816902, 4.366197183098592, 10.563380281690142, 9.507042253521128, 10.563380281690142], "bedroom2": [13.661971830985916, 7.464788732394367, 10.563380281690142, 7.464788732394367, 10.563380281690142, 6.408450704225352, 9.507042253521128, 6.408450704225352, 9.507042253521128, 4.366197183098592, 13.661971830985916, 4.366197183098592], "bedroom3": [12.605633802816902, 14.71830985915493, 9.507042253521128, 14.71830985915493, 9.507042253521128, 11.619718309859156, 10.563380281690142, 11.619718309859156, 10.563380281690142, 10.563380281690142, 12.605633802816902, 10.563380281690142], "bathroom2": [9.507042253521128, 10.563380281690142, 6.408450704225352, 10.563380281690142, 6.408450704225352, 8.52112676056338, 9.507042253521128, 8.52112676056338], "bedroom4": [5.422535211267606, 9.507042253521128, 3.3098591549295775, 9.507042253521128, 3.3098591549295775, 5.422535211267606, 5.422535211267606, 5.422535211267606], "corridor": [9.507042253521128, 11.619718309859156, 9.507042253521128, 8.52112676056338, 8.52112676056338, 8.52112676056338, 8.52112676056338, 6.408450704225352, 6.408450704225352, 6.408450704225352, 6.408450704225352, 9.507042253521128, 5.422535211267606, 9.507042253521128, 5.422535211267606, 5.422535211267606, 9.507042253521128, 5.422535211267606, 9.507042253521128, 6.408450704225352, 10.563380281690142, 6.408450704225352, 10.563380281690142, 11.619718309859156]}
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
func create_room(name: String, coords: Array, parent: Node, root: Node) -> void:
|
| 7 |
# Create vertices for the room
|
| 8 |
var verts = PackedVector2Array()
|
|
@@ -14,22 +20,50 @@ func create_room(name: String, coords: Array, parent: Node, root: Node) -> void:
|
|
| 14 |
polygon.polygon = verts
|
| 15 |
polygon.name = name
|
| 16 |
polygon.mode = CSGPolygon3D.MODE_DEPTH
|
| 17 |
-
polygon.depth =
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
parent
|
|
|
|
| 29 |
polygon.owner = root
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
func _run():
|
| 35 |
var root = get_scene()
|
|
@@ -40,12 +74,30 @@ func _run():
|
|
| 40 |
|
| 41 |
# Create rooms from the data
|
| 42 |
for room_name in data.keys():
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
for
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
var data:Dictionary = { "bathroom1": [8.52112676056338, 8.52112676056338, 6.408450704225352, 8.52112676056338, 6.408450704225352, 6.408450704225352, 8.52112676056338, 6.408450704225352], "bedroom1": [9.507042253521128, 5.422535211267606, 6.408450704225352, 5.422535211267606, 6.408450704225352, 3.3098591549295775, 9.507042253521128, 3.3098591549295775], "living_room": [14.71830985915493, 10.563380281690142, 10.563380281690142, 10.563380281690142, 10.563380281690142, 7.464788732394367, 14.71830985915493, 7.464788732394367], "kitchen": [9.507042253521128, 12.605633802816902, 4.366197183098592, 12.605633802816902, 4.366197183098592, 10.563380281690142, 9.507042253521128, 10.563380281690142], "bedroom2": [13.661971830985916, 7.464788732394367, 10.563380281690142, 7.464788732394367, 10.563380281690142, 6.408450704225352, 9.507042253521128, 6.408450704225352, 9.507042253521128, 4.366197183098592, 13.661971830985916, 4.366197183098592], "bedroom3": [12.605633802816902, 14.71830985915493, 9.507042253521128, 14.71830985915493, 9.507042253521128, 11.619718309859156, 10.563380281690142, 11.619718309859156, 10.563380281690142, 10.563380281690142, 12.605633802816902, 10.563380281690142], "bathroom2": [9.507042253521128, 10.563380281690142, 6.408450704225352, 10.563380281690142, 6.408450704225352, 8.52112676056338, 9.507042253521128, 8.52112676056338], "bedroom4": [5.422535211267606, 9.507042253521128, 3.3098591549295775, 9.507042253521128, 3.3098591549295775, 5.422535211267606, 5.422535211267606, 5.422535211267606], "corridor": [9.507042253521128, 11.619718309859156, 9.507042253521128, 8.52112676056338, 8.52112676056338, 8.52112676056338, 8.52112676056338, 6.408450704225352, 6.408450704225352, 6.408450704225352, 6.408450704225352, 9.507042253521128, 5.422535211267606, 9.507042253521128, 5.422535211267606, 5.422535211267606, 9.507042253521128, 5.422535211267606, 9.507042253521128, 6.408450704225352, 10.563380281690142, 6.408450704225352, 10.563380281690142, 11.619718309859156]}
|
| 5 |
|
| 6 |
+
|
| 7 |
+
const architext_colors = [[0, 0, 0], [249, 222, 182], [195, 209, 217], [250, 120, 128], [126, 202, 234], [190, 0, 198], [255, 255, 255],
|
| 8 |
+
[6, 53, 17], [17, 33, 58], [132, 151, 246], [197, 203, 159], [6, 53, 17],]
|
| 9 |
+
const housegan_labels = {"living_room": 1, "kitchen": 2, "bedroom": 3, "bathroom": 4, "missing": 5, "closet": 6,
|
| 10 |
+
"balcony": 7, "hallway": 8, "dining_room": 9, "laundry_room": 10, "corridor": 8}
|
| 11 |
+
|
| 12 |
func create_room(name: String, coords: Array, parent: Node, root: Node) -> void:
|
| 13 |
# Create vertices for the room
|
| 14 |
var verts = PackedVector2Array()
|
|
|
|
| 20 |
polygon.polygon = verts
|
| 21 |
polygon.name = name
|
| 22 |
polygon.mode = CSGPolygon3D.MODE_DEPTH
|
| 23 |
+
polygon.depth = 2.0 # Set the depth of the room
|
| 24 |
+
|
| 25 |
+
# Apply rotation
|
| 26 |
+
polygon.rotate_x(deg_to_rad(-90))
|
| 27 |
+
|
| 28 |
+
# Apply color coding
|
| 29 |
+
var material: StandardMaterial3D = StandardMaterial3D.new()
|
| 30 |
+
for room_name in housegan_labels.keys():
|
| 31 |
+
if not name.begins_with(room_name):
|
| 32 |
+
continue
|
| 33 |
+
var color_values = architext_colors[housegan_labels[room_name]]
|
| 34 |
+
material.albedo_color = Color(color_values[0]/255.0, color_values[1]/255.0, color_values[2]/255.0)
|
| 35 |
+
polygon.material = material
|
| 36 |
|
| 37 |
+
# Add polygons to the parent node
|
| 38 |
+
parent.add_child(polygon)
|
| 39 |
polygon.owner = root
|
| 40 |
+
|
| 41 |
+
func create_corridor(name: String, coords: Array, parent: Node, root: Node) -> void:
|
| 42 |
+
# Create vertices for the corridor
|
| 43 |
+
var verts = PackedVector2Array()
|
| 44 |
+
for i in range(0, coords.size(), 2):
|
| 45 |
+
verts.append(Vector2(coords[i], coords[i+1]))
|
| 46 |
|
| 47 |
+
# Create a new CSGPolygon3D with given name
|
| 48 |
+
var polygon = CSGPolygon3D.new()
|
| 49 |
+
polygon.polygon = verts
|
| 50 |
+
polygon.name = name
|
| 51 |
+
polygon.mode = CSGPolygon3D.MODE_DEPTH
|
| 52 |
+
polygon.depth = 2.0 # Set the depth of the corridor
|
| 53 |
+
polygon.operation = CSGPolygon3D.OPERATION_SUBTRACTION # Set operation to subtraction
|
| 54 |
+
|
| 55 |
+
# Apply rotation
|
| 56 |
+
polygon.rotate_x(deg_to_rad(-90))
|
| 57 |
+
|
| 58 |
+
# Apply color coding
|
| 59 |
+
var material = StandardMaterial3D.new()
|
| 60 |
+
material.albedo_color = Color(architext_colors[housegan_labels[name]][0]/255.0, architext_colors[housegan_labels[name]][1]/255.0, architext_colors[housegan_labels[name]][2]/255.0)
|
| 61 |
+
polygon.material = material
|
| 62 |
+
|
| 63 |
+
# Add polygons to the parent node
|
| 64 |
+
parent.add_child(polygon)
|
| 65 |
+
polygon.owner = root
|
| 66 |
+
|
| 67 |
|
| 68 |
func _run():
|
| 69 |
var root = get_scene()
|
|
|
|
| 74 |
|
| 75 |
# Create rooms from the data
|
| 76 |
for room_name in data.keys():
|
| 77 |
+
if room_name == "corridor":
|
| 78 |
+
create_corridor(room_name, data[room_name], csg_combiner, root)
|
| 79 |
+
else:
|
| 80 |
+
create_room(room_name, data[room_name], csg_combiner, root)
|
| 81 |
+
|
| 82 |
+
# After creating all rooms and corridors
|
| 83 |
+
var aabb : AABB = csg_combiner.get_aabb()
|
| 84 |
|
| 85 |
+
# Expand the aabb slightly on x and z axis (width and depth)
|
| 86 |
+
aabb.expand(Vector3(0.1, 0, 0.1))
|
| 87 |
+
|
| 88 |
+
# Create a new CSGBox for the baseplate
|
| 89 |
+
var baseplate: CSGBox3D = CSGBox3D.new()
|
| 90 |
+
baseplate.name = "Baseplate"
|
| 91 |
+
|
| 92 |
+
# Set the size of the baseplate to match the expanded aabb
|
| 93 |
+
baseplate.size.x = aabb.size.x
|
| 94 |
+
baseplate.size.z = aabb.size.z
|
| 95 |
+
# You can adjust the height as per your requirement
|
| 96 |
+
baseplate.size.y = 0.1
|
| 97 |
+
|
| 98 |
+
# Position the baseplate at the center of the aabb
|
| 99 |
+
baseplate.transform.origin = aabb.position + aabb.size / 2 - Vector3(0, baseplate.size.y / 2, 0)
|
| 100 |
|
| 101 |
+
# Add the baseplate to the root node
|
| 102 |
+
csg_combiner.add_child(baseplate)
|
| 103 |
+
baseplate.owner = root
|