XImage2Mesh

From GPWiki

Files:GUITutorial_warn.gif The Game Programming Wiki has moved! Files:GUITutorial_warn.gif

The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server.

However, the GPWiki forums are still active! Come say hello.

Contents

Download

XImage2Mesh.zip 29Kb (Release 1 - Feb 16, 2006)

Code written in VB.NET 2005. Requires .NET Framework 2.0 to run.

Information

xImage2Mesh is a application that takes a 2D image and generates MAXScript code. This MAXScript code is then used in tools such as discreets 3DS MAX or gMAX to generate a Multi\Sub object material and a 2D plane mesh. The material is also applied to the mesh.

The result is a 3D mesh object that can be used in games or video generated by 3ds max, as well as the ability to then export that mesh into a DirectX *.X file or 3D Studio *.3ds file to be used in other applications.

How it works

xImage2Mesh works by calculating the number of uniqe colors that are used in the image to generate the proper maxscript code that will create the Multi\Sub object material when the maxscript code is run in 3ds MAX or gMAX.

The next thing xImage2Mesh does is to construct a vertex along the x/y axis at the location of each pixel in the selected image. The number of vertexes that are created is computed as VertexCount = ImageWidth * ImageHeight

The next this it does is to construct two polygons, 3 vertexes per poly, and associates a material id that was generated in the previous step. It continues to create 2 polygon faces for each pixel in the image.

The result is MAXScript code that can be run in 3ds MAX or gMAX to recreate the image as a 3D Mesh.

How to use

  • First you run the app and open a image file (a preview of the image will be presented)
  • Second you click the Generate button to begin generating the MAXScript code
  • After the maxscript code has been generated you can save the code to a file by clicking "File->Save"
  • The next step to to start 3DS MAX or gMAX
  • Within 3ds MAX program select the "MAXScript" menu item, then "Run Script" a dialog will appear allowing you to browse for the script file you generated in the previous step.
  • The script will then run and you should see a 3D mesh representation of your image in the form of a Editable_Mesh object.

Known issues

Specifying a image that is too large will result in a unknown exception being trown by 3DS MAX (tested on version 7). The reason for this I suspect is that because the maxscript code that generates the mesh is stored on one line. And when 3DS MAX/gMAX reads that line and passes it to the "execute" method, it is unable to handle a line of that size resulting in the entire line to be dumped out to the listener window twice, and reporting the unknown exception.

The work around to this is to use smaller image sizes. Or break up your image into smaller parts then generate and run each script in 3ds MAX or gMAX and attach the meshes together.