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?)
-
$\begingroup$ 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 $\endgroup$– Duarte Farrajota Ramos ♦Aug 5, 2018 at 22:55
2 Answers
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()
scn.objects.link(obj)
obj.location = (x*2.1, y*2.1, 0)
-
$\begingroup$ 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. $\endgroup$– NathanAug 6, 2018 at 22:47
-
$\begingroup$ 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 $\endgroup$– NathanAug 6, 2018 at 23:01
-
1$\begingroup$ @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
$\endgroup$– samblerAug 7, 2018 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()
scn.objects.link(obj)
obj.location = (x*2.1, y*2.1, 0)