Spaces:
Sleeping
Sleeping
File size: 6,146 Bytes
6b56a65 d286231 6b56a65 d286231 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
@tool
extends EditorScript
var data:Dictionary = {"bathroom1": [9.507042253521128, 5.422535211267606, 7.464788732394367, 5.422535211267606, 7.464788732394367, 3.3098591549295775, 9.507042253521128, 3.3098591549295775], "bedroom1": [11.619718309859156, 4.366197183098592, 9.507042253521128, 4.366197183098592, 9.507042253521128, 1.267605633802817, 11.619718309859156, 1.267605633802817], "living_room": [9.507042253521128, 8.52112676056338, 4.366197183098592, 8.52112676056338, 4.366197183098592, 5.422535211267606, 9.507042253521128, 5.422535211267606], "kitchen": [9.507042253521128, 12.605633802816902, 7.464788732394367, 12.605633802816902, 7.464788732394367, 8.52112676056338, 9.507042253521128, 8.52112676056338], "bathroom2": [11.619718309859156, 9.507042253521128, 9.507042253521128, 9.507042253521128, 9.507042253521128, 6.408450704225352, 11.619718309859156, 6.408450704225352], "bedroom2": [12.605633802816902, 6.408450704225352, 9.507042253521128, 6.408450704225352, 9.507042253521128, 4.366197183098592, 12.605633802816902, 4.366197183098592], "bedroom3": [12.605633802816902, 14.71830985915493, 9.507042253521128, 14.71830985915493, 9.507042253521128, 11.619718309859156, 12.605633802816902, 11.619718309859156], "bathroom3": [9.507042253521128, 16.760563380281692, 7.464788732394367, 16.760563380281692, 7.464788732394367, 12.605633802816902, 9.507042253521128, 12.605633802816902], "bedroom4": [13.661971830985916, 11.619718309859156, 9.507042253521128, 11.619718309859156, 9.507042253521128, 9.507042253521128, 13.661971830985916, 9.507042253521128]}
const architext_colors = [[0, 0, 0], [249, 222, 182], [195, 209, 217], [250, 120, 128], [126, 202, 234], [190, 0, 198], [255, 255, 255],
[6, 53, 17], [17, 33, 58], [132, 151, 246], [197, 203, 159], [6, 53, 17],]
const housegan_labels = {"living_room": 1, "kitchen": 2, "bedroom": 3, "bathroom": 4, "missing": 5, "closet": 6,
"balcony": 7, "hallway": 8, "dining_room": 9, "laundry_room": 10, "corridor": 8}
func create_room(name: String, coords: Array, parent: Node, root: Node, depth: float = 0.1, inset: float = 0.0, operation: int = CSGPolygon3D.OPERATION_UNION) -> void:
# Calculate the center of the room
var center = Vector2.ZERO
for i in range(0, coords.size(), 2):
center += Vector2(coords[i], coords[i+1])
center /= (coords.size() / 2)
# Create vertices for the room with inset
var verts = PackedVector2Array()
for i in range(0, coords.size(), 2):
var vertex = Vector2(coords[i], coords[i+1])
var direction = (vertex - center).normalized()
verts.append(vertex + direction * inset)
# Create a new CSGPolygon3D with given name
var polygon = CSGPolygon3D.new()
polygon.polygon = verts
polygon.name = name
polygon.mode = CSGPolygon3D.MODE_DEPTH
polygon.depth = depth
polygon.operation = operation
polygon.rotate_x(deg_to_rad(90))
# Apply color coding
var material: StandardMaterial3D = StandardMaterial3D.new()
for room_name in housegan_labels.keys():
if not name.begins_with(room_name):
continue
var color_values = architext_colors[housegan_labels[room_name]]
material.albedo_color = Color(color_values[0]/255.0, color_values[1]/255.0, color_values[2]/255.0).srgb_to_linear()
polygon.material = material
# Add polygons to the parent node
parent.add_child(polygon, true)
polygon.owner = root
func create_corridor(name: String, coords: Array, parent: Node, root: Node, depth: float = 0.1, inset: float = 0.0, operation: int = CSGPolygon3D.OPERATION_SUBTRACTION) -> void:
# Calculate the center of the corridor
var center = Vector2.ZERO
for i in range(0, coords.size(), 2):
center += Vector2(coords[i], coords[i+1])
center /= (coords.size() / 2)
# Create vertices for the corridor with inset
var verts = PackedVector2Array()
for i in range(0, coords.size(), 2):
var vertex = Vector2(coords[i], coords[i+1])
var direction = (vertex - center).normalized()
verts.append(vertex + direction * inset)
# Create a new CSGPolygon3D with given name
var polygon = CSGPolygon3D.new()
polygon.polygon = verts
polygon.name = name
polygon.mode = CSGPolygon3D.MODE_DEPTH
polygon.depth = depth
polygon.operation = CSGPolygon3D.OPERATION_SUBTRACTION # Set operation to subtraction
polygon.operation = operation
polygon.rotate_x(deg_to_rad(90))
# Apply color coding
var material = StandardMaterial3D.new()
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).srgb_to_linear()
polygon.material = material
# Add polygons to the parent node
parent.add_child(polygon, true)
polygon.owner = root
func _run():
var root = get_scene()
for child in root.get_children():
child.queue_free()
var csg_combiner: CSGCombiner3D = CSGCombiner3D.new()
csg_combiner.name = "CSGCombiner3D"
root.add_child(csg_combiner, true)
csg_combiner.owner = root
for room_name in data.keys():
if room_name != "corridor":
create_room(room_name, data[room_name], csg_combiner, root, -2.74)
for room_name in data.keys():
if room_name == "corridor":
create_corridor(room_name, data[room_name], csg_combiner, root, -2.74)
for room_name in data.keys():
if room_name != "corridor":
create_room(room_name + "Inset", data[room_name], csg_combiner, root, -(2.74 + 0.4), -0.12, CSGPolygon3D.OPERATION_SUBTRACTION)
for room_name in data.keys():
if room_name == "corridor":
create_corridor(room_name + "Inset", data[room_name], csg_combiner, root, -(2.74 + 0.4), -0.12, CSGPolygon3D.OPERATION_SUBTRACTION)
for room_name in data.keys():
if room_name != "corridor":
create_room(room_name + "Inset", data[room_name], csg_combiner, root, .1, 0.06, CSGPolygon3D.OPERATION_UNION)
|