Skip to content

Instantly share code, notes, and snippets.

@marvk
Created December 22, 2021 19:49
Show Gist options
  • Save marvk/ccffb7ac7928c71ef1908ccb57a0dae8 to your computer and use it in GitHub Desktop.
Save marvk/ccffb7ac7928c71ef1908ccb57a0dae8 to your computer and use it in GitHub Desktop.
import bpy
from mathutils import Vector
import csv
context = bpy.context
collection = context.collection
cuboids = []
with open('cuboids.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
cuboids.append([int(x) for x in row])
def generate_cuboid(cuboid):
verts = []
for z in cuboid[4:6]:
for y in cuboid[2:4]:
for x in cuboid[0:2]:
verts.append(Vector((x, y, z)))
faces = [
(0, 1, 3, 2),
(4, 5, 7, 6),
(0, 1, 5, 4),
(1, 3, 7, 5),
(3, 2, 6, 7),
(2, 0, 4, 6),
]
mesh = bpy.data.meshes.new("mesh")
mesh.from_pydata(verts, [], faces)
obj = bpy.data.objects.new("obj", mesh)
collection.objects.link(obj)
for cuboid in cuboids:
generate_cuboid(cuboid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment