Bitmap2Mesh (release v3.0)

Bitmap to 3D Extruded Mesh-script. Related to this forum topic (unity forum link)

What it is?
It reads bitmap pixel by pixel, checks if pixel alpha value is > 0, then add vertice there (but skip adding, if we are going the same direction) (it follows the shape border, currently just 1 shape is scanned..)

Then it uses Triangulator from unifywiki and This extrude script from unity forums to make it 3D.*
*Re-wrote the extrusion connection, now its using Unity Examples Procedural-extrusion. (which can be also used to extrude in multiple sections)

Optimization, clean up (or dont add) too many vertices, if its a straight line (done, using kind of “RLE”)
UV mapping.. problem if you try to add textures to this version (Planar UV map works, not sure how to make others, * Testing Custom UV mapping, works bit better)
Some error checking, havent tried yet what happens if you make multiple objects in the bitmap..or holes..? (It only detects the first object that it hits, when scanning pixels)
Pivot location (see update note #2)
Scaling (currently its 1pixel = 1unit..) (see update note #2)
Last vertice / triangle /uv is sometimes broken? (hopefully fixed, 1.2.2012, see update note #1)
– Model is mirrored / upside down?
– Proper UV mapping / texturing (bake vertex colors? special shader: 2 materials, use vertex color as mask?)
– Support multiple shapes (submeshes, combine meshes?)
– Use bitmap image as texture directly (possible after proper UV’s are done?) (works, just need to remove extra variable..)
Fix scanning: breaks if there is not atleast 1 pixel empty margin around the image.. (done)
Cannot scan diagonal pixels or too thin lines.. (Now works)
– Single pixels coming out from the shape are not correctly square (need to add extra vertex function there later..)
– Need to do scaling for gameObject, instead of pixels..(?)
– Make the whole thing as a function/class.. so you can call it and pass the bitmap image, settings  as a variables

Make pixel texture painter script, so you can paint your weapon and click “extrude to 3D” (test version done, not so useful yet..)
– Take extrude depth from alpha or color value? So you could make it a bit less blocky?
– Bake texture to vertex colors? (would need more vertices..?)
– Make it as unity editor script?
– Make it as online page (you draw / upload bitmap, it creates you the mesh to download, as .obj or …)

*Update#1 (1.2.2012)
This fixed the uv/triangle problem in some cases,
Find these 2 lines:

triangles[count_tris+4] = n + poly.Length;
triangles[count_tris+5] = i + poly.Length;

replace with these 2 lines: (swaps 4 and 5)

triangles[count_tris+5] = n + poly.Length;
triangles[count_tris+4] = i + poly.Length;

*Update#2 (2.2.2012)
If you want to set pivot point to first encountered pixel(vertex)
and to set the scale (currently 1 pixel = 1 unit), do it here:

Find line:


Replace with: (you could make the “0.1” (=pixelscale) as public variable, so you can easily adjust it later


*Update#2 (4.2.2012)
Custom UV mapping & texturing.. (see image#3)
need to clean it up a bit and do testing before upload..

*Update#3 (5.2.2012)
Updated the pixel scanning system, now its more robust and takes the outer edge of pixel as vertex location (not the pixel midpoint..)
See image#4, original minecraft sword extruded & textured.
Added v2 download for testing..

*Update#4 (9.2.2012)
Now UV mapping works on most cases
Added v3 download link to the toolbar

Download source: (js + c#)

mBitmapToMesh,unitypackage  v1.0
mBitmap2Meshv20,unitypackage  v2.0
mBitmap2Meshv30.unityPackage v3.0

Additional images:
Image#2: Optimized vertices (compare to the main image)

Image#3: Automatic UV mapping and texturing (using the original bitmap).. bit off, but close enough for now..

: Original minecraft sword .png, extruded to 3D (same image as texture) *Sword image  © Mojang/Minecraft
(Sides still have UV mapping problems..)

10 Comments + Add Comment

Leave a comment


Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.