Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Voxel Mesh From Texture Tool

Discussion in 'Assets and Asset Store' started by kellygravelyn, Feb 13, 2012.

  1. kellygravelyn

    kellygravelyn

    Joined:
    Jan 22, 2009
    Posts:
    143
    Last night I ported some code of mine from XNA that took in bitmaps and generated 3D meshes from them, replacing each pixel with a little cube. It turned out pretty nicely:






    Now I'm trying to finish it up and get it on the Asset Store as I think it could be useful. However I'm coming to the community for a few questions:

    1) Do you think this is cool enough for the asset store? Would you or anyone you know buy something like this?
    2) Are there any features for a tool like this that you'd have to have before considering buying it? Any features that are simply "nice to have"?
    3) What would be a good price? I was thinking $5 or $10 as it's not terribly complicated, but I'm not sure if that's undervaluing the work.

    I still have plans to optimize the meshes a bit (right now it's one box per pixel but I'd like to merge neighboring pixels of the same color into patches to reduce polycount) as well as do a basic animation system, but I'm not sure what else to add after that. Ideas?
     
  2. robin_notts

    robin_notts

    Joined:
    Apr 7, 2010
    Posts:
    86
    Does it color the cubes using the existing texture? That would be good option. This would also mean that you could just create one mesh for the whole object and apply the texture to it. Each object would then only need 1 drawcall, infact if you add support for Texturepacker then all the objects could be one drawcall in total.

    Just some thoughts.
     
  3. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    If it supports animation, that would be very impressive.
     
  4. kellygravelyn

    kellygravelyn

    Joined:
    Jan 22, 2009
    Posts:
    143
    Currently it is one mesh for the whole object. I set the vertex colors and use a custom shader that is just a basic lighting with vertex color. The texture is only used to generate the mesh; it's not used at all in rendering. So it is one draw call per model at this point. I do like the idea of trying to batch up multiple of these into a single draw call. That should definitely help if you wanted to make a whole crowd of people. I'll look into that. :)
     
    Last edited: Feb 13, 2012
  5. kellygravelyn

    kellygravelyn

    Joined:
    Jan 22, 2009
    Posts:
    143
    What kind of animation would you like to see? Initially I was going to do "frame based" where it'd behave just like frame based sprite animations (but with cubes). I am considering seeing how I could manage to do more tween based animation where, for example, the blocks of the feet slide from one position to another. That would give much more control over speed/timing and look a bit nicer. However I'm not sure how to achieve that without making a whole editor for the animations. :)
     
  6. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Hrm - frame based would probably be a simple solution (creating all of the meshes beforehand and just swapping information each frame). As far as tween based animation, you could generate a skinned mesh in the editor using a separate texture map for bones (each separate color corresponding to a bone), which can then be animated through traditional means.
     
  7. runonthespot

    runonthespot

    Joined:
    Sep 29, 2010
    Posts:
    305
  8. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Would it be possible to add some sort of bevel param so that the blocks are not just cubes?

    Very interested in this. Any idea when it will be available?
     
  9. kellygravelyn

    kellygravelyn

    Joined:
    Jan 22, 2009
    Posts:
    143
    That shouldn't be too hard. Maybe a good feature for a first update.

    I'm finishing up some contract work over the next few days and then I can spend more time wrapping this up. Since it seems like there is some interest, I can try to have this ready in the next couple of weeks. I want to do some refactoring and try to get frame based animation in place for the first release.
     
  10. kellygravelyn

    kellygravelyn

    Joined:
    Jan 22, 2009
    Posts:
    143
    Small update. I did some work yesterday to figure out the asset database (or at least get some idea of how it works) so now instead of using an ugly tool window to create objects directly, you now end up with a nice asset that contains the mesh and the description.



    A few nice things here:

    1) Simpler. Just add a new asset, set up the description, and then use the mesh portion on any MeshFilter in your scene.
    2) More powerful. Before your object was just baked out and that was that. Now you can tweak the description and rebuild the mesh anytime you want. Since the same Mesh instance is reused, all references are maintained and any objects in the scene instantly reflect the changes.
    3) More resource friendly. Previously I was making a new mesh for any object you create. Now you can create these assets and use them all over the place so you only end up with one copy of the mesh data rather than one for every object.

    Still working on the code a bit. That said I was thinking about putting it up for $5 now and then doing an update later to add things like better mesh optimization, beveling, and animations (along with probably raising the price to $10). Is that a smart way to go or is that just shooting myself in the foot by not having those features up front?
     
  11. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Hi,

    Sounds like great progress. Looking forward to working with the script.

    I'd put it in the asset store sooner rather than later. You can always raise the price once you add more features.
     
  12. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Very nice!

    a suggestion: Optimize the meshes by combining triangles where the pixel color is the same.
     
  13. kellygravelyn

    kellygravelyn

    Joined:
    Jan 22, 2009
    Posts:
    143
    That's the next thing on my list of stuff to do for the tool.

    I'm thinking I'll probably try to get this ready for the asset store in the next few days and launch at $5. Then I can work on optimizations and more features and bump the price to $10 once some more cool features come online.

    Thanks for all the feedback on this!
     
  14. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Optimization... use Vertex colors from the pixels instead of material colors
     
  15. kellygravelyn

    kellygravelyn

    Joined:
    Jan 22, 2009
    Posts:
    143
    Not sure exactly what you mean. When I construct the mesh I set the Mesh.colors property using the colors pulled from the pixels. The custom material I use doesn't even have a color on it. So there's only one material per object.

    I do plan to move to supporting the standard shaders to ensure you can do things like toon shading, shadows, and more without having to modify the shader to include vertex colors (since most standard shaders don't). That will mean that instead of vertex colors you'll be needing to create a material for the object with the texture used to generate the asset. I'm hoping to find ways to make this more streamlined, but it definitely will make things more flexible down the road.

    And as a status update, I'm working hard on a game project with a close deadline so I haven't spent a lot of time on this. Still hoping to clean it up and get it into the store soon with the basic features. Then I can iterate to add all the new features I've thought of over the last week or two. :)
     
  16. kellygravelyn

    kellygravelyn

    Joined:
    Jan 22, 2009
    Posts:
    143
    Got busy with my game project, but now that we've completed that I'm back to work on this asset. I've got the optimized meshes coming through now. Here's my scene with all the optimized meshes (note that the ground is just a standard Unity plane and the wall is made up of a bunch of standard Unity cubes, hence why they aren't optimized in any way):



    And here's one specific example:



    Quite a reduction in vertices and triangles.

    Also I've revamped the inspector for the asset to be a bit more polished:



    Lastly I moved to using texture coordinates instead of vertex colors, partially because without that change I wouldn't have been able to optimize, but also because now you just use the standard Diffuse shader (or other shader of your choice) and you're good to go. This makes the assets much more flexible in terms of how you render them.

    Working on cleaning up my out-of-date documentation, getting more screenshots, making a little asset icon, and getting it all bundled up for the store. Hoping to have it submitted within the next week or two.
     
    Last edited: Mar 6, 2012
  17. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Very nice! Looking forward to using it.
     
  18. kellygravelyn

    kellygravelyn

    Joined:
    Jan 22, 2009
    Posts:
    143
    Thanks! I actually submitted today so up above I should have said "hoping to have it on the store within the next week or two". :)