Search Unity

Shatter Toolkit

Discussion in 'Assets and Asset Store' started by gustavolsson, Jul 8, 2011.

  1. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Hi!

    I answered this question by email, but just in case someone else is wondering:

    This was a bug in earlier versions of the toolkit. I've confirmed that it is possible to shatter a quad (2 triangles) using the latest version (FillCut disabled). Just update to the latest version and it should work fine :)
     
  2. WillBellJr

    WillBellJr

    Joined:
    Apr 10, 2009
    Posts:
    394
    Wow, I'm interested in this for my Space Game; I wanted to be able to break up my Asteroids upon collision and when they're being mined by a cutting laser etc., but not having looked at any of the videos or demos yet, after reading this I'm thinking now that perhaps this may not have been able to give me the effect I was after anyway?

    I would certainly need chunks over shards for sure?

    I'll take a look at the videos when I get home tonite...


    -Will
     
  3. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    $Capture.JPG

    HI, is it possible to split only right half like on screenshot? specify bounds for cutting plane?
     
  4. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    Hello. Can the shatter system work with structural stress? Such as if the supports on the first floor of a building get mostly destroyed, all of the higher floors will come falling down? Would it be to much to apply the shatter system to each building of a entire city? (using level of detail, optimizations, etc).

    here is a test I done with my own destruction sytem with pre fragmented peices to get a better idea.
    https://www.youtube.com/watch?v=mF3q3yQ7BIg
     
  5. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    No, the shatter toolkit can only split a mesh using infinite planes. It is not possible to limit the operation to a finite area of a plane.

    Your destruction looks great :)

    The shatter toolkit does not calculate the stress a rigidbody is subject to, it simply cuts a game object into multiple pieces using a set of planes, at a location specified by the user (or the ShatterOnCollision script). You could shatter each part of the building in your game at the point the shell hits it, but you'll have to keep track of when the whole building should collapse, the toolkit will not handle this for you.

    The performance depends on how you use it. If you only shatter a relatively simple mesh once or twice, and make sure that you destroy the debris after a couple of seconds/minutes you should be able to use it for every building in a city.

    You could see it as a replacement for the swap-to-destroyed-meshes technique (the original whole mesh is replaced by a set of mesh pieces that give the impression of being destroyed) used in most games. The difference here is that the toolkit will shatter the mesh at the location you specify when the tank shell hits, not in a pre-determined point :)
     
    Last edited: Apr 17, 2013
  6. Bloodyem

    Bloodyem

    Joined:
    Mar 26, 2013
    Posts:
    8
    I don't know any C#, so I'm having a very difficult time figuring out how to send a post split message to my object. Can you explain how to do it in unity script?
     
  7. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Here is a custom UnityScript that will print how many pieces a game object is split into. Just attach the script to a game object with a Shatter Tool component that has the "Post Split msg" checkbox enabled.

    Code (csharp):
    1. #pragma strict
    2.  
    3. function PostSplit(gameObjects : GameObject[]) {
    4.     // This happens just after the game object is split, before the original is destroyed:
    5.     Debug.Log("The game object was split into " + gameObjects.Length + " pieces.");
    6. }
    Hope this helps :)
     
  8. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    @gustavolsson Quick question: Does this script support vertex colors?
     
  9. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Good question. I was quite sure it did until I looked at the code to make sure, and apparently I totally forgot about vertex colors! At the moment vertex positions, normals, tangents and uvs (first channel) are supported if they're available. (If they're not available, no time is wasted on interpolation)

    This is an easy fix and vertex colors will be supported in the next version. I will try to submit a small update soon to add this and provide some minor fixes. I will post here when it's submitted. Thanks :)
     
  10. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    Cool! Could you let the user specify the cross sections color somehow? (like the uv/mat on that watermelon)
     
  11. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Sure :)

    By the way, I played your game (No, Human) quite a while ago and really liked it. Keep it up!
     
    Last edited: Jul 13, 2013
  12. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    Thanks! :) I hope the Shatter Toolkit will be part of my next one!
     
  13. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I just submitted version 1.5 to the asset store, it should be live as soon as Unity accepts it.

    $vertexcolors.png

    This version adds vertex color support. If the mesh to be shattered/split has vertex colors, attach a SolidColorMapper script to the game object with the ShatterTool script. This script lets you choose the color of the cut area. @woodn: Hope this helps :)

    Apart from vertex color support, I've added a new helper script. Here is the changelog:

     
    Last edited: Jul 16, 2013
  14. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    Wow, that was quick! I will check it out as soon as i can. :)
    Question: Does it affect performance in the cutting process a lot? I've just read yesterday that setting vertex colors in unity can be quite slow...
     
  15. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Each vertex property (normal, tangent, uv, color) present in the mesh has roughly the same performance impact. So, shattering a mesh that has normals and uv-coordinates is roughly equivalent to shattering a mesh that has vertex colors and uv-coordinates, for example. That said, there are more checks necessary (if-statements to see if vertex colors should be handled) in the new version than in the previous, but the performance impact of this should be negligible.

    Could you provide a link to where it says it's slow to set vertex colors? I can't come up with any reason that it should be slower than setting other vertex properties. I use the Color32 struct to improve performance as the documentation suggests.

    As a side note, I have big plans for the future of the toolkit. I will not disclose my plans now, in case my ideas are unrealistic, but if I manage to pull it off there will be some great new features in version 2.0 of the toolkit. I might even have to bump the version number up to 3.0 for good measure :)
     
    Last edited: Jul 15, 2013
  16. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
  17. w00dn

    w00dn

    Joined:
    Apr 28, 2010
    Posts:
    275
    What is taking them so looong!! GNARRL! That Approve-Button is just one click away, Unity!
     
  18. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Version 1.5 is now available on the Asset Store!

    Here is the change list again:

     
    Last edited: Jul 29, 2013
  19. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I've decided to experiment a little with the price of the toolkit and have lowered it to 80$

    Here is a link to the Asset Store

    I'm currently working on a big update and I will try this new price point at least until the new update is out. So, if you have ever considered buying the toolkit but have put it off because of the previous price, now is the time to buy it :)
     
  20. Setmaster

    Setmaster

    Joined:
    Sep 2, 2013
    Posts:
    239
    Can this work with raytrace?
    Can you provide a demo with raytrace?
     
    Last edited: Sep 6, 2013
  21. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes, if you attach a mesh collider to the object you can use Collider.Raycast() or Physics.Raycast() to accurately query the pieces of the object after it has been shattered. Is this what you're after?

    The webplayer demo uses world raycasts when determining where objects should be shattered if you use the "Mouse Shatter" mode.
     
  22. Setmaster

    Setmaster

    Joined:
    Sep 2, 2013
    Posts:
    239
    I'm planning on using this into a fps to break some objects.

    The "mouse shatter" doesn't work on "small" pieces in the demo, any reason for this?

    Also this isn't capable of shattering animated objects like a flying bird right?
     
    Last edited: Sep 9, 2013
  23. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    It is possible to specify the maximum times a game object can be shattered when using the toolkit (the ShatterTool.GenerationLimit property). In the webplayer demo, I have set it to 3 or 4 which will make small pieces unshatterable if they are pieces of bigger game objects. There is no limit to the GenerationLimit property so if you want to keep shattering pieces, you can. (The performance will degrade as the number of triangles increase, though) Very small game objects (< 0.01 units in size) are also discarded automatically, but you can change this threshold value at the top of FastHull.cs.

    Nope, skinned/animated meshes are not supported.

    Hope this helps :)
     
  24. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    Hiya! using the script assigned to a basic Cube, I'm trying to shatter things but the resulting geometry isn't modified. The texture/renderer appears to be working great (the shatters visually appear in the correct place), but when I pause the scene and click on a shattered piece, the physics collider is the same as the original shape. How do I fix that?

    Secondly (maybe related), even with none of the shatterscript stuff in the scene, I'm getting an error constantly running in the console:
    m_UniqueThreadAllocator -> GetAllocatedMemorySize() == 0
     
  25. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    What kind of physics collider are you using? A simple cube with a convex mesh collider works well for me. I don't get the error you're referring to, are you sure that the Shatter Toolkit is causing it?

    Sorry for the very late reply and thanks for using the toolkit!
     
  26. anurp

    anurp

    Joined:
    Feb 24, 2013
    Posts:
    8
    Hi Gustav,

    I am facing a problem using the shatter toolkit. We are using your toolkit for a fruit-slashing type of game.

    We are using the mousesplitcontinous helper script for this.

    The problem :

    On the IPhone 4 and the iPad 2, sometimes when the object is split, there is a split second lag seen.

    I tried to reduce the maximum generations to 1 , as we all tried using the Mousesplit helper script. But this did not help in any way.

    Do you know what could be happening here ? Also if you have some suggestions on what could be done to solve the problem, do let me know.

    Also I am not sure whether I have the latest version of the toolkit. I could not find references to the version number anywhere in the imported package folder.

    Also how do I make sure I have the latest version of the toolkit , as in where to download the update from if we have already bought the earlier version ?

    Thanks!
    Anur
     
    Last edited: Jan 3, 2014
  27. JovanD

    JovanD

    Joined:
    Jan 5, 2014
    Posts:
    205
    o/ Hello, great job on the asset.
    I need a little bit of guidance since im noob at programming. How could i make object in world(a blade for example) cut stuff? Like if i wanted to make a guillotine trap or blender simulator or just make main char cut stuff with he's sword. Im guessing i should attach a script to blade that calls the split function when the blade's colider hit's the targeted object's colider, but since im noob im having trouble wrapping my head around on where to start XD
    Thanks in advance and i hope this helps other people with similar problem.
     
  28. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Hi all, sorry for the absence.

    What is the vertiex/triangle count of the models you're splitting? Is the lag always there or does it only happen occasionally? I've noticed slower performance for the first split in a new scene, and I'm not sure what the cause is. Unity might do more the first time a new game object is instantiated, sounds strange but it's the only explanation I can come up with.

    To make sure that you have the latest version, go to the Shatter Toolkit page on the asset store and re-download and re-import the package using the small arrow button.

    Yeah you have it pretty much figured out. When the sword hits some other game object you can send a Split() message to that object. For the sword, you want to create a plane that coincides with the face of the sword and then supply it to the Split() function. Say that the face of the sword points towards the positive Z-axis in it's local space. Then you can use the following code to split the other game object:

    Code (csharp):
    1.  
    2. Vector3 worldNormal = sword.transform.forward;
    3. Vector3 worldPoint = sword.transform.position;
    4.  
    5. Vector3 normal = other.transform.InverseTransformDirection(worldNormal).normalized;
    6. Vector3 point = other.transform.InverseTransformPoint(worldPoint);
    7.  
    8. other.SendMessage("Split", new Plane[] { new Plane(normal, point) });
    9.  
    Hope this helps! I will include an example scene for this with the next update to the toolkit :)
     
  29. sr388

    sr388

    Joined:
    Jul 22, 2014
    Posts:
    2,900
    I already ask this question in the turbo slicer forum, but I want to ask here too:

    I would like to know which asset is better, have a better performance, specially in mobile devices (where I am more interested to work with it), which is the faster, etc of the next assets:
    • piecemaker
    • turbo slicer
    • shatter toolkit
    I ask this because of all them have different price, and I want to know which is the best purchase, so if any of you have experience with this assets, please tell me what do you think about them.

    I think that this asset has more features, like shatter the object by collision, but I see something strange in the webplayer demo when I cut a object horizontally, it looks like a little part of the object disappears between the cutting, this really happens?

    Thanks in advice.
     
  30. luizcarlosfx

    luizcarlosfx

    Joined:
    May 28, 2013
    Posts:
    15
    Does this works with 2D colliders?
     
  31. Megalithic

    Megalithic

    Joined:
    Apr 21, 2014
    Posts:
    61
    Hi,

    While playing the demos I just realized that the shapes get sliced upon mouse button up. Is there any way you can change that to while mouse button down?

    Hoping to heat from you all.
     
  32. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I'm a bit biased so I won't comment on this :)

    This is because the toolkit automatically removes very thin game objects automatically. The threshold value for what is considered "too thin" is set at the top of the FastHull.cs script. I should probably break this out so that the user can change this value without modifying the script. I will do this for the next update.

    The toolkit requires a MeshRenderer component to work with. If you also have 2d colliders on the game object they will be carried over to the piece game objects unchanged. The toolkit does not yet update the Rigidbody2D component to reflect the fact that a split occured (for example while it was rotating), this is something I'm going to look into for the next update.

    Yes, this is possible using a custom script. You can write the mouse handling code and then send a Split() message to the ShatterTool component. The bundled MouseSplit should be a good starting point to look at.

    I will add this to the list of features for the next update as well.

    Hope this helps :)
     
  33. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I just wanted to let you guys know that I've lowered the price of the toolkit to $60 for the time being!

    Let me know if you have any questions :)
     
    Last edited: Apr 26, 2015
  34. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
  35. SpaceRay

    SpaceRay

    Joined:
    Feb 26, 2014
    Posts:
    455
    I think this is interesting and cool, but after reading this thread and trying to understand how it works, I am sorry that I still do not know if this can really shatter and break any 3D objects with it´s own materials or shaders into different parts.

    1 - I am interested in this is as a possible solution to breaking any object without having to make a prefacture of each object I have in the game, and if there is any possible limitation.

    2 - Sorry to say that the demo really does not show what happens when you FIRE something at a 3D object and how it gets broken by the impact and so I want to know if this can be done easily

    3 - Is there an option to know how many parts it will be broken into?
    Does it depend on the size of the 3D object? I mean if bigger size would give more parts.

    4 - Would the force of the rocket and speed modify how the breaking of the 3D object is made?

    5 - Can the direction of the broken parts be customized (where they are going) and how far they can reach?

    6 - I have a whole city with 400 buildings with about 12 different materials and shapes, I can´t take the time to prefacture each one of the buildings as is needed with other assets, so I wonder if I could use a weapon to shoot a missile or rocket to a building and then on impact it would shatter that building into pieces. Some of them are really a simple rectangular cube with a substance material added to the surface.

    7 - And also if when destroyed, you could fire again and fracture and shatter AGAIN the already broken parts into smaller pieces

    Thanks very much for your help

    Best wishes and kind regards
     
    Last edited: May 2, 2015
  36. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I'm sorry that it's a bit unclear. I will improve the description on the website/in the thread asap :)

    An object is shattered in real-time without the need of prefracturing. When shattering a game object, a number of infinite planes (with random normals) that pass through the point of impact are generated and the game object is subsequently split using these planes. In most cases, this results in 2^n new game objects where n is the number of split planes used. Each of the resulting pieces can then be shattered again using the same technique. The "Cuts" property of the ShatterTool component specifies the number of planes to use for each shatter event ("n"), and the "Generation Limit" property specifies the maximum number of shatter events that can happen to the game object/pieces of the game object.

    There is a helper script called "ShatterOnCollision" that does exactly this. The "Walls" example scene shows this in practice. I can update the web player demo to showcase this scene as well.

    The point of impact is the only thing taken into account. The shatter event always uses randomly generated planes that pass through the point of impact. However, as soon as an object is shattered, the velocities of the rigidbodies are updated automatically so that a spinning wheel will have it's pieces flying outwards realistically, for example.

    You can create a custom shattering algorithm by specifying your own set of split planes and calling the "ShatterTool.Split(planes)" function. This function is internally used for the "ShatterTool.Shatter()" function and for cutting with the mouse helper scripts.

    The pieces are just clones of the original game object with new MeshFilter, Collider and ShatterTool components. The "Generation" property of the ShatterTool is increased after each shatter event, in order for custom scripts to detect which "generation" a specific piece belongs to, and to stop the recursion so pieces can't be split indefinitely.

    You can make the ShatterTool send a "PostSplit" message to all connected scripts (just check the corresponding checkbox on the ShatterTool component). This can trigger an explosion force in a custom script, for example, that throws the pieces in your preferred direction.

    Yes, this should work fine. However, you should be aware of the fact that the toolkit uses infinite planes (per game object) only, so if you have large game objects, the resulting shatter effect will look a bit too much like shattering glass. You can improve the effect by having walls etc as separate game objects. I'm also planning a big update to improve this in version 2 of the toolkit, so stay tuned :)

    Also take a look at the "PieceRemover" helper script if you have a large scene. This script automatically deletes pieces above a certain "Generation" if they're out of view, which improves performance.

    Yes, see the answer to Q1 and Q3 above.

    No problem, thanks for the interest in the toolkit! :)
     
    Danirey likes this.
  37. ashwinFEC

    ashwinFEC

    Joined:
    May 19, 2013
    Posts:
    48
    @gustavolsson the static class Tools of the Shatter Toolkit can conflict with UnityEditor.Tools. Maybe you should add namespaces to the toolkit.
     
    hippocoder likes this.
  38. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I got another email about this, I will update the toolkit with namespaces ASAP. Thanks for the feedback :)
     
  39. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hi, I'm also getting the issue with
    Tools.current = Tool.None; etc in many of our assets, in short you've broken everything. Halp!
     
  40. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Sorry about this. I will submit the update tonight.

    As a temporary fix, you could rename the "Tools" class to "ShatterTools" using the refactor in Visual Studio or MonoDevelop (so it updates the references internally). If you don't use an IDE, I'm afraid that there is no work around other than adding namespaces, unfortunately. Hopefully it won't take too long to get the update accepted.
     
  41. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yep did that, works fine now - thanks :)
     
  42. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I've now updated the toolkit so that all code files have namespaces. The new version number is 1.61. It'll be live as soon as Unity verifies it. (@hippocoder)

    Thanks for using the toolkit!
     
    hippocoder likes this.
  43. SpaceRay

    SpaceRay

    Joined:
    Feb 26, 2014
    Posts:
    455
    Thanks very much for the complete and detailed answer, it answers my doubts and I understood it better how it works, and I think it will be useful for me and will consider buying it.

    What happened to the Android demo that you had? I tried to find it but is not available.

    For last, please, I would like to see the if possible the webplayer of the wall demo scene.

    Thanks for your help

    Best wishes

     
  44. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The android demo was very old so I decided to remove it. I will create a new demo app when I have some more free time, hopefully in the near future. I'm also planning a big update to the shatter toolkit which I rather work on first. Maybe I can just upload one of the demo scenes to the Play store, that wouldn't be too much work.

    I will upload a webplayer with the "Walls" example scene tomorrow evening, since I'm away from the computer today.

    Thanks again for the interest in the toolkit everybody! :)
     
  45. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hiya, we're using it for shattering glass. One problem we're having is that there seems to be a 10mb allocation and 350ms cost (I have 4.5ghz i7 with 780 ti overclocked) - it might be due to physx contacts or something? when the player runs though it, there is a definate pause in the game.

    The glass is just a cube for testing at present, and i'm wondering what can be done to fix this?

    edit: just tried shooting a single bullet through the glass:

    upload_2015-5-6_12-10-55.png

    515 calls for a single sphere collider bullet hitting a cube mesh - seems something is off or broken somewhere for performance impacts like this (much worse if player goes through).

    Edit: new bug, rammed a fence in my car which spawned this error (doesn't always happen unfortunately)

    Gu::ConvexMesh::loadConvexHull: convex hull init failed! Try to use the PxConvexFlag::eINFLATE_CONVEX flag. (see PxToolkit::createConvexMeshSafe)
     
    Last edited: May 6, 2015
  46. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    This seems really strange, a typical allocation for me is ~50kb when a shatter occurs in the "Wall" scene.

    What parameter values do you use for the glass object and other objects involved? How many triangles does the glass consist of? Make sure that the "Cooldown time" of the ShatterOnCollision script is not 0 (then it will just keep on shattering pieces recursively) and that you don't call the ShatterTool.Shatter(...) function from any other scripts at the same time.

    If you want to send me a scene that illustrates the problem, you can contact me through my website.
     

    Attached Files:

  47. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
  48. astrand130

    astrand130

    Joined:
    Nov 9, 2014
    Posts:
    21
    Hello, I have been having a problem with Shatter Toolkit causing interference with Particle Playground; Every time Upon Importing Shatter Toolkit into a project with Particle Playground there are Script Errors from Particle Playground related to tools like:
    Assets/Particle Playground/Scripts/Editor/PlaygroundInspectorC.cs(123,35): error CS0117: `Tools' does not contain a definition for `current'

    I was wondering if you could look into the issue of compatibility by importing PP into a project to work out incompatibilities on your end and possibly contact the developer since this seems to be related to something that Shatter Toolkit is doing to PP and not something PP is doing to Shatter Toolkit.

    It would like to use Shatter Toolkit in my Project but with the compatibility issues between Shatter Toolkit and a important widely used add-on I might have to wait until this is sorted out.

    If you would like any more details or information on my problem please contact me

    Thank you.

    (Edit: It seems the problem is caused by the name of the script "Tools" which is a broad term for a public class if you ask me; I will also ask the Dev of Particle Playground about this issue to see if he could rename his as well to avoid any future interference.)
     
    Last edited: May 7, 2015
  49. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I've submitted an update to the toolkit that should fix this problem (Version number 1.61). It should be live as soon as Unity accepts it!
     
  50. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    @astrand130 I think Tools.current is a legit use of the Tools class, ie PP is doing it ok - it's not his class but unity's.