Search Unity

Has anyone ever written a mesh melter?

Discussion in 'General Discussion' started by Nanako, Mar 16, 2015.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    so i have a neat idea for melting meshes. Given a point where the heat is concentrated, vertices all around it would be moved away from that point (by an amount depending on how close they are) with a maximum range beyond which they won't be affected. and vertices would also be moved to some degree, in the direction of gravity.

    I'm not very familiar with mesh morphing, but this doesn't sound too hard to me, is it?

    Other problems i see:

    1. Finding where on the uvmap to apply a glowy red/hot metal effect to the heated parts
    2, Finding where the melting cuts right through a mesh, and splitting it at that point into two smaller meshes
    3, Creating new vertices where the current resolution is inadequate (maybe not necessary with proper asset design)
    3. Making all this fast enough to work in realtime, and generate at least 2-4 melted copies of a mesh per second.

    So yeah, this sounds hard. Have any of you ever attempted it? is there a p[reexisting package out there for such a thing? I don't have an absolute need, but i'd certainly be curious to implement this in my game if i could, i have a use case for it
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    some random ideas,
    1. With shader, adjust color/material based on the distance to heat point (vertex or in pixel),
    or in script just increase (or recrease) nearby vertex colors (= temperature) and then colors will change with shader

    This comes to mind too, but might not work well if the object needs to be specific 3D model shape..
    http://wiki.unity3d.com/index.php?title=MetaBalls
     
    Nanako likes this.
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    Kind of interesting effect, but probably easier to do melt extrusion in script also (to avoid intersecting faces etc)

    This one is using vertex extrude shader, 2 textures lerp, each vertex color gets adjusted by script (from distance to point)

    http://pasteboard.co/1QARh81p.gif (animated gif)
    sphereblob.jpg
     
    Nanako, Samuel411 and Ostwind like this.
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,656
    If you could guarantee a limit on the number of 'heat sources' affecting an object, you could probably do most of what you're describing in a vertex shader. You'd store a set of Vector4 values in the shader, recording the XYZ coordinates of each heat source 'point' along with something like 'total energy emitted by this point', and then in the vertex shader you could calculate the distance to each heat source point and apply deformation and colouring accordingly. It definitely wouldn't be as accurate or flexible as full CPU mesh deformation but it might be good enough depending on what you want, and definitely quick to render.
     
    angrypenguin likes this.
  5. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    wow, this was pretty impressive. I noticed some odd things in there through:

    1. no matter how much you melted it, it seemed to contract to a slightly smaller sphere, rather than deform in any non spherical way. I'm not sure what was going on ther

    2. Cooled parts bulged back out to their original position when you took the heat source away

    Fwiw, my interest with this would be in permanantly deforming and changing meshes, and having a melted mess after it cools down. Possibly also in cutting through metal beams with concentrated heat (like a blowtorch, or a lightsaber)

    i could guarantee a limit of only one heat source ever
     
  6. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    If you check out Unity's procedural content scenes, one of them has sculpting. If you modify that example, you can change extrusion to be toward the model instead of outward. Having a heat point where the heat value affects the range, you can move vertices within that range.
     
  7. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    also any chance of seeing the source code for this shader? i'd like to poke around with it
     
  8. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    procedural content scenes? what/where are these, i've never heard of it x
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    Yes, posting sources soon (hopefully within next week).
     
    Nanako likes this.
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    there's always megafiers which is exceptional for this sort of thing.
     
    derkoi and Ony like this.
  11. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    http://u3d.as/content/unity-technologies/procedural-examples/3zu

    It's advertised as creating special effects with procedural stuff, but one of the examples includes sculpting by deforming meshes realtime with your mouse. Seems like it would be useful for making something melt and then adjusting its collider.
     
  12. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    theres another ominous sounding word i've never heard of
     
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It's just an asset on the asset store. It's relatively expensive but does all sorts of melty/mesh deforming wonders.
     
    Ony likes this.
  14. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    The one I posted just above @Nanako is free and created by UT :p I hope it still works in 5.x though lol. It should since it's primarily code/scripts instead of editor specifics.Yours sounds a lot more useful though if it's going to be a very involved project (and there will be more projects) involving melty things.
     
    Nanako likes this.
  15. Ony

    Ony

    Joined:
    Apr 26, 2009
    Posts:
    1,977
    Megafiers is awesome and it's the first thing I thought of when I saw this thread.
     
  16. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    Yup, another thumbs up for Megafiers. In fact all of Chris's (@SpookyCat) assets are very useful. I'm sure he'll let you know if his assets can do what you need.
     
    Ony likes this.
  17. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    What I've found is modifying a mesh is quite fast. But when adding or removing vertices there is a bit of a bottleneck if you have to update the mesh collider with the new mesh. This bit:

    Code (CSharp):
    1. MeshCollider collider = mainObject.GetComponent<MeshCollider>();
    2.                     collider.sharedMesh = null;
    3.                     collider.sharedMesh = newMesh;    
    I haven't tested this in Unity 5 to see if that's improved. But generally in Unity 4.x updating the colliders seems to take a long time. Unless anyone knows a faster way?

    Out of interest is there a way to get the triangle of a mesh that a user clicks on without using a collider? If I'm not interested in any of the other physics? e.g. Is there a way to turn off PhysX mesh collider optimisation so it doesn't take so long to update?
     
    Last edited: Mar 21, 2015
  18. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    you know, i really hate mesh colliders anyway.

    There's got to be some nice library to generate an approximate collider out of boxes and spheres, wouldn't that be more efficient?
     
  19. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    @yoonitee , @Nanako when you're going to deform a mesh, it's best to start with a higher poly model. It's going to end up high poly anyway from the deform, and you'll do less math in adding vertices in real time. And nanako you can do a box / sphere collider, just keep in mind it's going to throw off your results when you raycast and any physics you have if things interact with the melted object.

    If you're melting something from influence of a vector3 point, you don't need a collider at all ;) the collider is strictly for detecting something near your vertices to deform the ones around the hit point. If that point is controlled in any way and you don't need to collide with melted stuff, don't put a collider.
     
  20. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    "Dynamic" melting can be achieved through shaders or by using the Mesh.vertex or a combination.
    I would prefer to save some morphs as Maya blendshapes - or use a similar program.
    Combining these blendshapes could give semi - procedural, less resource intensive and more artistic friendly result.
     
  21. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    Nanako likes this.
  22. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408