Spaces:
Runtime error
Runtime error
Generate a blender scene.
Browse files- blender.py +38 -0
blender.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import bpy
|
| 2 |
+
|
| 3 |
+
# Your input data
|
| 4 |
+
data = { "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 |
+
def create_room(name, coords):
|
| 7 |
+
# Create vertices for the room
|
| 8 |
+
verts = [(coords[i], coords[i+1], 0) for i in range(0, len(coords), 2)]
|
| 9 |
+
edges = [(i, (i+1)%len(verts)) for i in range(len(verts))]
|
| 10 |
+
|
| 11 |
+
# Create a new mesh with a given name
|
| 12 |
+
mesh = bpy.data.meshes.new(name)
|
| 13 |
+
|
| 14 |
+
# Load the room data into the mesh
|
| 15 |
+
mesh.from_pydata(verts, edges, [])
|
| 16 |
+
|
| 17 |
+
# Create a new object with the mesh
|
| 18 |
+
obj = bpy.data.objects.new(name, mesh)
|
| 19 |
+
|
| 20 |
+
# Link the object to the scene
|
| 21 |
+
bpy.context.scene.collection.objects.link(obj)
|
| 22 |
+
|
| 23 |
+
# Set the object as the active object
|
| 24 |
+
bpy.context.view_layer.objects.active = obj
|
| 25 |
+
obj.select_set(True)
|
| 26 |
+
|
| 27 |
+
# Switch to edit mode
|
| 28 |
+
bpy.ops.object.mode_set(mode='EDIT')
|
| 29 |
+
|
| 30 |
+
# Select all mesh elements
|
| 31 |
+
bpy.ops.mesh.select_all(action='SELECT')
|
| 32 |
+
|
| 33 |
+
# Switch back to object mode
|
| 34 |
+
bpy.ops.object.mode_set(mode='OBJECT')
|
| 35 |
+
|
| 36 |
+
# Create rooms from the data
|
| 37 |
+
for room_name, room_coords in data.items():
|
| 38 |
+
create_room(room_name, room_coords)
|