File size: 3,528 Bytes
6b56a65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@tool
extends EditorScript

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]}

func create_room(name: String, coords: Array, parent: Node, root: Node) -> void:
	# Create vertices for the room
	var verts = PackedVector2Array()
	for i in range(0, coords.size(), 2):
		verts.append(Vector2(coords[i], coords[i+1]))
	
	# Create a new CSGPolygon3D with given name
	var polygon = CSGPolygon3D.new()
	polygon.polygon = verts
	polygon.name = name
	polygon.mode = CSGPolygon3D.MODE_DEPTH
	polygon.depth = 3.0  # Set the depth of the room
	
	# Create a smaller CSGPolygon3D for the inside cutout
	var inner_polygon = CSGPolygon3D.new()
	inner_polygon.name = name + "_inner"
	inner_polygon.operation = CSGCombiner3D.OPERATION_SUBTRACTION
	inner_polygon.polygon = verts
	inner_polygon.mode = CSGPolygon3D.MODE_DEPTH
	inner_polygon.depth = 2.9  # Set the depth of the cutout
	inner_polygon.scale = Vector3(0.9, 0.9, 1.0)  # Scale down to create a cutout
	
	parent.add_child(polygon, true)
	polygon.owner = root
	polygon.add_child(inner_polygon, true)
	inner_polygon.owner = root
	

func _run():
	var root = get_scene()
	var csg_combiner: CSGCombiner3D = CSGCombiner3D.new()
	csg_combiner.name = "CSGCombiner3D"
	root.add_child(csg_combiner, true)
	csg_combiner.owner = root
	
	# Create rooms from the data
	for room_name in data.keys():
		create_room(room_name, data[room_name], csg_combiner, root)

	csg_combiner.owner = root
	
	# Create rooms from the data
	for room_name in data.keys():
		create_room(room_name, data[room_name], csg_combiner, root)

	csg_combiner.rotate_x(deg_to_rad(-90))