Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Mesh Explosion - Easily blast any mesh into pieces

Discussion in 'Assets and Asset Store' started by JJC1138, Nov 26, 2012.

  1. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Hi there.

    I'd like to introduce my new script asset 'Mesh Explosion'. It's a super-easy-to-use script that takes any mesh and explodes it out into triangles. To use it you just add a single script onto your GameObject, and then at the appropriate time call its Explode() method (or send it an "Explode" message), and it will take the mesh, split it into its component triangles and animate them flying away.

    It works on Unity Free and Pro, and on all platforms including mobile. Obviously on mobile it performs best with lower-poly models, but it works beautifully for exploding simple things like crates. It's compatible with Unity 3.5 and 4, and in 4 or above it works with animated skinned meshes (Mecanim or legacy) as well as static ones.

    The script is on the Asset Store now, and there's a web player demo, and a YouTube demo/tutorial.

    Here's a screenshot of exploding the barrel model by SFC Paul Ray Smith Simulation Training Technology Center and licensed under the Creative Commons Attribution License.:



    And here's a screenshot of exploding the 'Space Robot Kyle' model (you can see this moving at about 5:20 in the YouTube video):



    Any comments or questions are very welcome of course. Thanks!
     
    Serkanj likes this.
  2. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Awesome! Definitely on my next shopping list!
    Bookmarked!
     
  3. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Glad to hear it. Thanks! :)
     
  4. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,196
    Possible to have forces / gravity on the fragments?
     
  5. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Not yet, but that's high on my to-do list.

    There's two way I can think of doing it: one would be to just add gravity to the visuals so that things fall nicely, and the other would be to make a new GameObject for each fragment with a collider and rigid body so that the fragments actually collide with the scene. Obviously that would be massively more expensive performance-wise, but might work well for low-poly things.

    Did you have one or other of those in mind? Or something else?
     
  6. mr_Necturus

    mr_Necturus

    Joined:
    May 17, 2010
    Posts:
    2,956
    Very nice!
    Need to make something like random shell to add thickness for every broken fragment. Next update maybe? :)
     
  7. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,196
    No solution in my mind, just would be nice to have (I would prefer the more performant solution as long as it looks kind of real).
     
  8. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Yeah, I think so. I guess it would either be a mesh collider or a slim box collider. I'll do some tests and see what performs best. I think I'll try it out now. :)
     
  9. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Are you splitting them by their triangles? , meaning the object must be highly triangulated to get the effect in your robot video.
     
  10. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Yes that's right, the objects are split into their triangles, so the effect looks best on objects with lots of them. Just to be clear, though, you don't have to manually add a bunch of redundant vertices to your model to make the triangles separate from each other, because the script does that automatically.

    Perhaps for objects with simpler geometries I could add an option to tesselate large triangles until they're no larger than a given area so that the pieces are smaller. Would that be of interest?
     
  11. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Is there an option to only explode lower amount of polygons? Or is it just easier to swap in a lower res LOD model for explosion for this? Because I think exploding a full detail model seems kinda excessive - most explosion you only get few piece of shrapnels and chunks of original object. So what I am asking is - is it possible to break object into chunks and bits of that are shrapnels?

    Let's take the barrel for example - if the explosion is at the middle - it will rip the barrel apart and the top chunk most likely to fly off while bottom chunk explode into several pieces and the middle bit are little shrapnels.
     
  12. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    I've added an option to apply gravity to the exploding fragments. This is just the simple visual effect that I described as the first option in my earlier post, but I think it looks quite nice. Here's a very quick video demo of it in action:



    It's been submitted to the Asset Store as version 1.1 and will hopefully be up soon. I'm going to explore the more complex option of actually adding physical collisions to the fragments, though, and I'll post again when I have some news on that. Thanks for the suggestion Cascho01!
     
  13. gateian

    gateian

    Joined:
    Dec 23, 2009
    Posts:
    38
    Very cool script. Might have to invest in this. I have been thinking about doing an exploding text effect and this might be the perfect thing. Have you got any test data for mobile in terms of how many polys there can be before there is a performance hit?
     
  14. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Right now it explodes every polygon, so yes you'd need to swap in a lower LOD model if you want fewer fragments. I haven't played with the Unity LOD system yet, but perhaps the script could help with that by having a LOD bias option to select a lower LOD version of your model automatically.
     
  15. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    On the asset store page one of the screenshots shows an iPad 1 exploding a 184-vertex mesh and that was at a solid 60 fps. If you're targeting 30 fps or faster hardware then you can go higher of course. I just did a quick test and I'm getting a solid 30 fps on iPad 1 with a 482 vertex mesh. I have an iPhone 3GS, 4S, and iPad 1, 2, and 3, so if you let me know what your hardware/frame rate target is I'd be happy to get you numbers for that.
     
  16. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Yes, that would be useful. I assume you cache which parts of the triangle wil lbe splitted, so you can preprocess that in editor, not at runtime.

    The other concern about splitting is the texturing on edges which are not split properly

    Also, lastly, I would see you have to switch shade to doubleside, cos like the robot, the interior face is not drawn. Then how do u handle transparencies.
     
  17. keithsoulasa

    keithsoulasa

    Joined:
    Feb 15, 2012
    Posts:
    2,023
    Wow, I had to double check the price, I could of swore I missed a zero .

    Next thing I buy forsure ....
     
  18. napster

    napster

    Joined:
    Jun 15, 2012
    Posts:
    313
    Looks great !
     
  19. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Yes it is cached, so if you are exploding lots of GameObjects with the same mesh you only pay for the pre-processing once. It's actually done at runtime though, on Start(), rather than in the editor. The rationale for that is that the pre-processing is actually pretty quick and I think it's better to waste a millisecond or whatever it is on level load rather than wasting some storage. I haven't tried out tessellation yet, but I suspect that would still be fast enough that it would make sense to do it at runtime.

    I'm not sure I understand what you mean here. Could you go into a bit more detail?

    Actually the script adds extra geometry to the explosion mesh for the the back sides of each triangle so that it can use the original shaders. If the original shader doesn't handle transparency, though, it does swap it out for a transparent version (so if you're using "Bumped Specular" for example, it looks up "Transparent/Bumped Specular") when the triangles start to fade.
     
  20. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Yes, this is what I mean. When you add extra geometry, how does the UV handled properly. My experience for precut mesh, the artist still needs to touch up the UV in the cut portion.
     
  21. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Oh I think I see. The back side vertices just use the same UVs as the front side, so we're thinking of the surface of the object as a shell that looks the same from both sides. Obviously that's not realistic for all objects, but the explosion normally happens so fast that it's unlikely that you'll notice.
     
  22. dilbertian

    dilbertian

    Joined:
    Aug 13, 2010
    Posts:
    74
    How does this work with more complex models which have multiple materials? Example would be like a fighter ship which has a hull material and then a cockpit material.

    Is there a way to have a cascade option (1-n steps) where a model first breaks into larger chunks which then eventually break into the approximate sized chunks that you are doing here?

    Also, regarding the triangle shapes, I think you should have an option to randomize each piece between 1 and <n> triangles/vertices. This way you would see some small, medium and larger chunks flying off and if you randomize it, it should look slightly different each time you run the application.

    -Tim
     
  23. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,038
    I just wanted to note that it was one of the first things I noticed. I think you made the right choices, but it *is* noticeable.
     
  24. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Yep, multiple materials should work fine.

    Hmm, that sounds doable. Might be a bit complex, but I'll look into it. Thanks for the suggestion.
     
  25. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Fair enough. :) What kind of mesh was it where you noticed, just out of interest?
     
  26. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,703
    I'd say this is interesting, but breaking stuff into triangles isn't visually appealing.. why triangles? just because it's easy? The next step you need to consider is exploding the mesh into more meaningful shaped pieces, so that the visual design of it fits into various games better.
     
  27. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Hello all. I've released a new version of Mesh Explosion which adds an option to create explosions where the pieces are full physics objects that interact with the environment, as discussed last week. The web player demo has been updated with a physics explosion test scene (and one for the simulated gravity option I posted the video for earlier), and here's a video of it running:



    The script creates a new GameObject for each triangle in the original mesh, with a rigid body and a box collider. The geometry is rotated so that each box collider is a thin box enclosing the triangle. As you can probably guess, having a bunch of rigid bodies is much more computationally expensive than the standard visual-only explosions, but it works well enough with very low-poly models so I expect there will be some uses for it. It's smart about sharing materials between the pieces so they can be dynamically batched.

    (I'm also experimenting a bit with a lower package price, so erm, get it while it's hot!)
     
  28. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,769
    Yea it looks really cool, some random shapes would be cool too as an option of the triangles.
     
  29. Mementos

    Mementos

    Joined:
    Sep 25, 2012
    Posts:
    79
    That would be cool! Is it still planned/ you think about it?
     
  30. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    I'm focussing on my game project at the moment, so I'm not planning to make any big changes to Mesh Explosion in the near future. Sorry :-(
     
  31. Mementos

    Mementos

    Joined:
    Sep 25, 2012
    Posts:
    79
    Thy for the quick reply, i bought it anyway =)
     
  32. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Ah, thank you very much. :)
     
  33. olgimpy

    olgimpy

    Joined:
    Jun 4, 2013
    Posts:
    3
    Hey man, awesome product. I purchased this today and was having some fun, but the Fade script doesn't work with Additive shaders since they use _TintColor instead of _Color. Is there an easy fix for this? I'm an artist by trade and know damn near nothing about code. Any help is appreciated.

    Thanks!
     
    Last edited: Jun 4, 2013
  34. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Sure, that's a pretty simple fix. I've attached a new version of Fade.cs to this post. Just replace your existing one in 'Mesh Explosion/Internal' with it and it should work with shaders that use _Color or _TintColor. Let me know if you have any more trouble. Thanks!
     

    Attached Files:

  35. olgimpy

    olgimpy

    Joined:
    Jun 4, 2013
    Posts:
    3
    Works like a charm! Thank you.
     
  36. Mikael-Madrid

    Mikael-Madrid

    Joined:
    Nov 2, 2012
    Posts:
    26
    Bought this when it was on sale the other day, love it,its so much fun to just make thinge explode! :p I'll rate it ★★★★★ when I get some time.
     
  37. hyperrodik

    hyperrodik

    Joined:
    Jul 16, 2014
    Posts:
    27
    many thanks for that, Bought it few months ago, and now I've got the chance to use it, but in a bit odd way. what I'd like to ask is can I animate explosion backwards from mesh to object with no click on it just in given time? say I wanna do it for architecture where we've got object coming in from say small mesh to whole object? thank you
     
  38. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    It might be possible to run the explosions backwards like that, but it would require some code modifications I'm afraid. You can see what it would look like by starting an explosion in the editor, then pausing and changing the Unity time scale (under Edit/Project Settings/Time) to negative.

    The crucial part of the script that you'd need to change is in MeshExplosion.Update(), and you'd need to modify the 'explosionTime' variable (and change the 'dt' variable too to reflect the change in explosionTime from the last frame). Essentially you'd want to make the explosion go backwards, and then stop when it gets to zero. You'd also need to handle swapping out the explosion for the original object at the appropriate point.

    Sorry to disappoint
     
  39. hyperrodik

    hyperrodik

    Joined:
    Jul 16, 2014
    Posts:
    27
    oh thanks for so quick reply, got to find another solution for my idea, but still have some ideas to your app, especially it works perfectly for me now
     
    JJC1138 likes this.
  40. hyperrodik

    hyperrodik

    Joined:
    Jul 16, 2014
    Posts:
    27
    sorry I'm not a coder, so is it difficult to change the code or add some kind of variable in the code which would do the time of explosion during animation?
     
  41. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    It would be a fairly complex change, I'm afraid, because the code wasn't written with that in mind.
     
    hyperrodik likes this.
  42. emplementation

    emplementation

    Joined:
    Mar 9, 2015
    Posts:
    7
    Will it work with text mesh pro? Exploding text?
     
  43. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    That's a good question. It depends on how Text Mesh Pro works internally so I'm not 100% sure. If you email me at tools at neverdontplay.com I'll be happy to send you an evaluation copy of Mesh Explosion so you can try it out if you like. :)
     
unityunity