3
$\begingroup$

I made a script that turns images into Minecraft .schematic files so they can be imported as pixel art. A simple modification would allow it to use several files stacked up to make a 3D object. The issue is making all those images.

Is it possible to "slice" a 3D object (3D-printer style) into many 2D image files?

For example, slicing a sphere would give many individual image files. When played as a slideshow, they would show a circle expanding, then contracting.

$\endgroup$

1 Answer 1

4
$\begingroup$

It is absolutely possible to do this and I just covered the method in my upcoming book on OSL, in order to address volumetrics (given the pending support of OpenVDB or Field3D for them). It isn't exactly a menu option so much as a technique, but I suppose it could be worked into a plugin at some point.

What you'll want to do is set your scanning camera to face straight down (0, 0, 0 rotation) and put it at location (0, 0, 1). Scale your scanned model down to fit within the (-1, -1, 0)-(1, 1, 1) range. (Basically you'll want your setup to map every single slice of your mesh, and this is the active area for it.) You will want to set that camera to orthographic mode (not perspective) and set its orthographic scale to around 3.0; you may need to tweak this for the sake of your geometry.

Next, you'll want to add a cube to your scene matching that (2.0, 2.0, 1.0) scale, and make the following modifications to it. Set it to bright white, and go into edit mode. Add two slices to the cube with Ctrl+R and then rolling the mouse wheel up, left-click once, and then right-click to use the default adjustment. You'll want to scale them down along z to match your slice width. We're going to call this middle-of-sandwich space the "aperture". Then, select all four internal faces, and delete them; then (F)ill the space left between the edges of your two remaining capping shapes. The gap should typically be very narrow, you'll want it to be roughly 1.0/(number of slices) in height.

I've enclosed a picture of my general setup here.

Example Scanner

The total number of frames rendered should be the number of image slices you want to get.

Now, you'll want to animate the aperture box to go from a starting position at (0.0, 0.0, 1.0) to (0.0, 0.0, 0.0). It should start moving at the beginning of your animation, and stop at the end, on a linear interpolation. Note that your aperture itself should be right on the shape's origin, and directly over the (0.0, 0.0, 1.0) coordinate; otherwise you'll have a skewed scan.

Lastly, you will want to add a Boolean modifier to your mesh, set to Difference mode, with your new clipping cube selected as its object. Here, I've called my modified cube "Clipping". That's effectively what it's doing—the only part of your mesh which will show in the render is the part that's between the two sandwich-slices of the cube, right on the aperture. Everything else is ignored because of this specific modifier.

Boolean modifier properly set up

Now, all you need to do is go to Output Properties and under the Output tab, give it a proper directory (since this is a whole array of images, I suggest a specific single-purpose directory per render). Choose your favorite image file format, and render. You will get an even-stepped set of images, of effective voxel size (2.0/[image width] x 2.0/[image height] x [aperture height]).

Obviously this method is extremely adjustable and tweakable, but this has worked for everything for me so far. The only modification you might need to make is the color of the background, and if you want specific diffuse colors you'll need to map them directly to the surface output in a shader. (Don't bother with emissive or diffuse shaders, just plug the color in directly—unless you want bloom screwing your image up.) By default, this is black on white. And—admitted shameless self promotion here—if you're interested in the full run-down and are interested in learning OSL, the book is "The Warrior Poet's Guide to Open Shading Language", completion and publication pending on Amazon. I'll have my actual Blend file on a public git repo eventually.

My general usage is to create a 3D coordinate space for volumetrics, where S and T map to image coordinate and P to image name. (STPQ is UV, when you need more than two dimensions, so it doesn't bump into W, which would be confusing and annoying.) Handy when you want to, say, map a shape onto a rendering of a cloud, or a liquid volume.

The thing to remember about Blender is that it's effectively a full-featured Python IDE at this point. There isn't a heck of a lot that can't be done with it anymore, if you've got the time and motivation to dig.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .