# How to render voxels?

I have a voxel representation of a model of the human body in numpy and would like to render it directly in Blender. Is there a file format for this? Most of the ones I've seen use polygonal meshes (ie. .obj files). In other words, could one render Minecraft directly in Blender? (or if not, in Unity3D, Maya, UnrealEngine, or any other popular modeling 3-D software?)

• I don't know if there are any voxel based interchange file formats or standards, never heard of any myself, but if there are any, there might not be an imported or exporter for Blender so you would probably have to write your own – Duarte Farrajota Ramos Aug 5 '18 at 22:55

While there are several file formats used for voxel data, they are used for volumetric data, such as smoke and fluid, which I doubt will help you.

As you have the data in numpy, I would suggest letting numpy save the data to file using numpy.save, but if you are using numpy to generate the data you can use numpy in blender and not use a file format at all.

By creating your selection of block types, you can then use a script to duplicate a block into each position.

import bpy
import numpy as np

objs = bpy.data.objects
scn = bpy.context.scene

scene_objs = [
objs['sand'],
objs['grass'],
objs['water'],
]

voxel_data = np.array([
[1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 2, 0, 2, 0, 1],
[1, 0, 2, 0, 2, 0, 1],
[1, 1, 0, 1, 0, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
])

for x in range(voxel_data.shape[0]):
for y in range(voxel_data.shape[1]):
obj = scene_objs[voxel_data[x,y]].copy()
obj.location = (x*2.1, y*2.1, 0)

• Great! Is there a way to smooth the edges and have Blender intelligently understand where to smooth? I'm trying to model the human body in Blender. – Nathan Aug 6 '18 at 22:47
• Also, I appreciate you reading between the lines and solving my actual problem, rather than the one that was literally stated. Perhaps I should edit the original question – Nathan Aug 6 '18 at 23:01
• @frank I would think if you can detect the spots to smooth, use a different block that has a beveled edge, or you could have modifiers in place and adjust settings for each object. obj.modifiers['Subsurf].levels = 2 – sambler Aug 7 '18 at 3:06
import bpy
import numpy as np

objs = bpy.data.objects
scn = bpy.context.scene

scene_objs = [
objs['sand'],
objs['grass'],
objs['water'],
]

voxel_data = np.array([
[1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 2, 0, 2, 0, 1],
[1, 0, 2, 0, 2, 0, 1],
[1, 1, 0, 1, 0, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
])

for x in range(voxel_data.shape[0]):
for y in range(voxel_data.shape[1]):
obj = scene_objs[voxel_data[x,y]].copy()