How to Create a 3D Mesh From an Image File
14384 Views, 9 Favorites, 0 Comments
How to Create a 3D Mesh From an Image File
In this Instructable, we'll look at one way to take an image and use it to create a three-dimensional mesh. This 3D mesh will be based on the contents of the image. By then end of a few short steps, we'll be able to import images and use them to quickly create 3D meshes. You can then either find interesting images to convert into meshes, or use your own drawing tools to create new meshes.
To do this, we'll be using the creative-coding software framework openFrameworks.
Find an Image File
After looking for a while, I chose to use an image by VJ Voodoo. I thought there was enough regularity yet variety in the image to create an interesting mesh. (If you'd like to see more of his work, head to http://www.vjvoodoo.com/).
Load the Provided Application Into OpenFrameworks
openFrameworks has several high-quality and up-to-date walkthrough on getting your application running. If you'd like to follow along and interact with the software, I recommend pausing this Instructable now and heading over to the openFrameworks site. It has detailed instructions on downloading, compiling demos apps, and several other things. Once finished, return to this Instructable.
Now that you've got openFrameworks installed, you can get the application from its GitHub Page. Place it into your "myApps" directory and compile it.
Wrap the Image File Around a Simple 3D Object
The application comes with VJ Voodoo's image file preloaded. If you'd like to use your own, replace the "inputImage.jpg" file with your own or alter the code to point to a different image file.
With the application running, the first thing you'll see if your image wrapped around a sphere. This will be the starting point for creating the 3D mesh. It's not necessary to use a sphere. You can use a plane, cube, or another mesh. However, the way we're altering the mesh is assuming we're using a sphere. But this is a swappable piece of code.
You'll notice you can grab and move around the sphere to examine it. Notice where the areas with the lighter and darker colors lie.
Displace the Vertices of the Mesh by the Contents of the Image
Press "G" to bring up a small control panel. This is where we enable displacement of the vertices. Click on the "Enable Displace" button. You'll see some around starting to expand then contract. Congratulations, you've not created a 3D mesh based on the contents of the image.
But what exactly is happening? At each vertex, the application looks at which pixel of the image is on top of it. The brighter the pixel, the more the displacement. So we're driving 3D mesh creation by the brightness of the pixels. The actual part of the software that does this is quite short. Here it is commented to see exactly what's going on.
Explore Some More
Here is a video file showing my explorations of this image. I'm altering the other two sliders, which controls how fast the mesh displaces and how much it displaces.
Try adding your own images or even altering the code to use different ways to displace your meshes. Have fun.