Creating geometry/mesh from .png

Hi all,



I’m looking for any information regarding the creation of geometry or mesh data from an image file.



Ideally, I would like to be able to load a transparent .png - perhaps a solid white circle/any shape with an alpha 0 background - and extrude that shape along the z-axis to form the mesh.



What I am really looking for is a way to take a .png image file of a characters front and back, and make him stand up in 3d. Best comparison is a popup book. I had some success with texturing quads with transparent .pngs, but it had some bad problems rendering shadows, so I’m hoping to create the mesh from the image instead of having a square mesh with a transparent texture.

You might look into doing this by creating a heightmap

So I’ve screwed around with the heightmap a bit more, and I’m wondering if there is some way for me to remove any geometry with a value of 0 in the .png, so that I don’t end up with a shape bulging out of a square.



Any idea how I’d tackle this? Is there a way to only render a certain chunk of geometry?

You can generate an alphamap that will have values of zero where the heightmap is zero. So the mesh will be transparent where you want it to be.

The alpha map was the first thing I tried, before I got into heightmaps at all. What I really want is just a paper-cutout version of my .png file.



When I add the alphamap to a quad with a diffuse map of my image, it works to some extent - i can see ‘through’ the quad, but shadows and skydomes fail horribly - shadows are in the shape of a square (it’s using mesh data, not mat data I’m assuming) and you can’t see the shadow or skydome through the quad, even though you can see the rest of the world through it.



Long story short, I was hoping for a way to make a mesh with vertices based off of image data, and if there was an alpha 0 part of the image data, it wouldn’t render any vertices/faces.



One solution I though of would be to loop through all the pixels in the image and draw a corresponding quad in jMonkey, but this would probably make animating the character a nightmare, as I’d have to rebuild the geometry on every frame from a new image/different section of the image. Anyone have any experience doing something like this?



I know getting transparency to work with shadows is on the jMonkey to-do list. Maybe I should just wait till it gets done and focus on other things. Anyone have any feeling of when support for this will be added?

Okay I see. I don’t exactly understand why you’re generating and animating a character from a heightmap though, it does not make much sense to me.

Generating a heightmap mesh with all positions with zero removed might be a bit complex, but it is worth a try. You could try looking at how the terrain system generates a mesh from a heightmap and work from that.

I’d rather not create and animate via heightmap, it’s really a workaround for the limitations of the current shadow implementation - it doesn’t support transparent materials.



I’m hoping to take a transparent png, and generate a ‘cardboard cutout’ in 3d space - imagine a popup book.



This works fine using a transparent material/texture, except for the shadows, which are generated using the mesh data - with no regard for transparent materials - ie I get a square shadow, instead of a shadow in the shape of the non-transparent pixels in the png.



My thinking was that if I could create an actual mesh from a png file, the shading would work properly, but maybe I should just avoid this whole vein of thought until the shading of transparent materials is fully implemented.

It might be easier to modify the shadow shader, (at least if you want to learn shaders anyway, as they are really cool ^^)

I’d love to get into screwing around with shaders, but am worried that they are over my head at this point.



Read through the shader doc a few times without much understanding of what I would need to do. Any tips?

I am adding transparency support for the shadow mapping implementation.

You are using the Lighting.j3md material, right?

You rock! Some day, I swear I’ll be able to help!



I am using Lighting.j3md.



On a slightly related note, I seem to have similar problems with transparent materials and the skybox created in the sky tutorial - not sure if it’s the same problem or completely unrelated, but I thought it was worth a mention.



Thanks again!

Make sure all transparent objects are in the transparent queue (model.setQueueBucket(Bucket.Transparent))