0

There are a ton of ways to convert images to 3D models, but I'm interested going the other way: from a 3D model to a series of images.

I need many images generated from one 3D model, the more the better, from every possible angle, and every possible scale.

For example, I have a 3D model of a pencil. I need to generate 100,000 images from this 3D pencil model from every angle (x,y,z), including the smallest scale to the largest scale.

I'm using Python and working with Blender at the moment and wondering if there is a simpler approach to solve this.

  • 1
    Let's assume you can rotate a 3D shape in 1 degree increments and scale it to 1...500 pixels high in every viewing angle, you will have 23328000000 images. If you can handle one in 1 microsecond, you need only 6,5 hours to walk through them all. If they are well packed, say 100kBytes /image, you can even store them if you have 2122 terabytes available for each 3D model. Many of us are curious, so maybe you can reveal the actual goal, other than fill 2122 terabytes per model. – user287001 Aug 16 at 21:10
  • 1
    This answer includes a script that will import an obj and animate a camera rotating around it. For stl use bpy.ops.import_mesh.stl(). You can easily adjust the number of images for each turnaround as well as moving the camera up/down for different angled turnarounds. Put that into a loop with os.listdir() or glob.glob() to repeat it for folders full of stl/obj files. You may also be interested in the clevr-dataset-gen repo which generates multiple images for machine learning. – sambler Aug 18 at 8:57
  • out of curiosity why would you need one hundred thousand images of this model? With varying scale, like zooming in / out: can't you just post process the images to resize them? What are you trying to do? – Luciano Aug 19 at 8:55
  • I'm also very curious about why you want to do this. Does it have anything to do with the name of your profile? – Wolff Aug 21 at 17:11
  • Hi everyone thanks for answering. These images will be used for artificial intelligence training. – Machine Learning Aug 22 at 22:12
2

This question has no sense. There can be an infinite number of angles and camera positions. There is no such thing as every angle.

Some angles and scales can be just a flat image, sowing an extreme close up of yellow paint of a pencil.

There is not one application that needs this kind of approach. Not any video game, product display, video or scientific approach.

It will have a humongous set of images, barely differentiable one from other, you can add to that different lighting conditions... I can keep saying more ideas on why this is a bad approach to whatever you are doing, especially in this era of real-time 3D rendering.

But if you still need to do this. The concept is simply "Render" your 3D model. Import your model in Blender, Add a camera that rotates around the object, and put in in a helicoidal path. Then change the camera settings and keep doing this year after year...

Or import the object on a realtime render engine and let the user play with the object.

*To watch "only" 100,000 frames of the pencil... You will be making a movie of 1.2 hours... This will be a World record of the most boring movie ever.

0

I've created outlines from an STL file by using the free multi-platform program known as OpenSCAD.

The feature within the program is called projection.

OpenSCAD also supports scripting which means you may be able to create a script using Python (or stand-alone) that will position the object appropriately to create the desired profile/projection.

The original STL:

stl file

A slice of the file based on the position of the object at the origin:

sliced stl

An additional "shadow" projection:

another projection

There is one other example showing rotation of the STL presenting a different image. You can then script the export of the files as you require to attain your goal.

I'm not sure what the reference to scale means, as the model in the work space will be one scale, unless you use the scale() feature of OpenSCAD to change that aspect as well.

EDIT: As suggested in the comment, if your objective is a screen capture sort of thing, OpenSCAD also supports camera positioning. You can create command line captures to cover the angles, with incremental positioning.

  • I'm not sure the question is about projection, more like rendering different camera angles. – Luciano Aug 19 at 8:57
0

Thanks everyone, I have tried all that was posted and didn't get far :(

In case someone is interested I was able to research the following script that imports a 3D model and rotates it around it's axis programmatically and creates a GIF

#pip install numpy-stl

from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot
import matplotlib.animation as animation

figure = pyplot.figure()
axes = mplot3d.Axes3D(figure)
axes.grid(False)
axes._axis3don=False

your_mesh = mesh.Mesh.from_file('C:<path_to_stl_3d_model_goes_here>.stl')
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors))

def animate(i):
    axes.view_init(elev=10,azim=i*4)
    return axes
    # for i in range(100):
    #     axes.elev = i
    #     axes.azim = -180
    #     axes.dist = 10

scale = your_mesh.points.flatten(-1)
axes.auto_scale_xyz(scale, scale, scale)

ani = animation.FuncAnimation(figure, animate)
ani.save('test.gif',writer='imagemagick',fps=30)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.