Hi,
I created an Unity Editor Extension which will create multiple levels of destruction from a single mesh.
The target mesh will be split several times based upon some generic settings like slice count and chaos level, extended by some useful Components (Collider, Rigidbody, “Destructable”, eg.) and will be put into a usable handy prefab.
This prefab can be instantiated and is able to be smashed into thousand (well… a little less maybe) pieces. If the creator wishes, the pieces could be smashed in several sub pieces and so on.
For this script I have created some tiny PrefabCache which will precach and instantiate up to 10 (variable) instances of each Prefab and Subprefab (for the sub destructions), the cache will fill them self up over time. This allows the game to spawn multiple destruction prefabs almost without noticeable lags. Also every Destructable will be removed from the scene if it was 10 seconds not visible.
I plan to enhance this script and optimize it, so that the precalculation time of each destruction level will be less noticeable. Also I will allow more options for each destruction level so that a Destructable will spawn a user defined prefab like a particle system or something else. And I will redesign the UI and some internal code structures.
If the script is finished I will put it into the AssetStore for a small fee.
As a side product, the ability to slice meshes inside the game is possible, but currently its not very fast, but as written above, I plan to increase the performance of that.
@megmaltese:
Yes I will provide some options for that:
separate Material
same Material but specific texture coordinate regions for the cut and normal area
@2dfxman1:
Thank your for your feedback, but if I provide a fullscreen video I will need to upload a ~2k*2k Video which will be blurred down by YouTube something worse than ‘sliding’, in my opinion.
@everyone else:
Thanks for the kind feedback, glad to hear that this tool we be of use.
The performance impact currenty comes through the instantiation of the destruction fragments, but the PrefabCache I use will almost eliminate this, so this will only a problem when the cache is empty and completly new instances must be generated on the fly (the cache will regenerate over time).
An other impact is the physic calculation as every fragment can collide with each other fragment, but through setting the collision matrix to not allow this kind of collision for the smaller fragments this can be eliminated too, I will include such option.
The last performance hit is the rendering of each fragment, every fragment is unique so the potential improvement through HW instancing or something similar is not given. A solution for this is not to destruct minor fragments any further, instead using a settable “SmallFragment” Prefab, like a small cube, particle emitter or whatever the user likes the most.
Mark
Edit: Almost forgott to answer your question regarding the mesh. Currently I can only test with the primitive meshs provided by Unity, but it should work well with other meshs, I will create some complex mesh and test it.
But, currently there is a limitation, the hole filling algorithm is a simple delaunay triangulation, so concave meshs or meshs with holes will create strange results on these, for example: Splitting a Tube wil cap the whole tube and not only the outer ring. I will eventually improve this, to at least support concave cut areas.
added the ability to add custom trinagulators (currently there is only delaunay), which should give the user the possibility to select how the cut area geometry should look and feel
added the ability to add custom per destruction level properties, for example: if you do not want my components to be used, feel free to change it without hacking in the core code of Piecemaker, for example: simply add a custom property set for sparkling particles and afterwards nuke the damn vampire from the orbit
refactored most of the code to be more easy maintainable and readable
added the capability to handle meshs with multiple submeshs
added the capability to put the cut area into a new submesh (which should satisfy all of you who want a different material for the ‘inside’)
(- every destruction settings can be serialized to disc and deserialized from disc, so you can keep your settings)
I hope I will be able to post an updated version of the webplayer as soon as everything runs smoothly.
Marrrk, I’ve thought of an idea: could you make this run inside the editor itself? It would be of GREAT use for level designers!
Say I need a destroyed building somewhere, or a destroyed bridge or wall… this would be an immense time saver.
I know it’s probably very difficult and require much more work but if it’s possible I’d give it a chance, you would have a lot of buys more I think.
I imagine you must run the game to have it working, right? So when you exit the game everything is reset.
What would be useful would be to have saved all those generated meshes along with their positions and rotations.
Imagine I have a castle mesh well built. I can place it somewere and use the same mesh somewere else by making that version ruined with your tool.
The steps necessary should be these:
1 - place the mesh in editor (more probably, more than one mesh to simplify) as a dynamic object
2 - run game
3 - destroy them with your tool
4 - when I’m satisfied with the result I click a “save” button
5 - your tool takes the generated meshes, joins them all into a single mesh and saves the newly generated ruined castle somewere in the project folder
6 - back to editor I can mark the mesh as static and use it as static lightmapped object
It’s probably going to be a lot of work more… don’t know if you have wish to do this
Tricky and much larger job than what you have done right now.
But I think it would have a huge impact on real producers, as for artists it would result in a very large time saver.
Think on all the situation this would help, like just dropping rocks on the side of a hill: this thing alone requires a level maker to place all the objects one by one, displace them, rotate, etc.
Now that I think on this, you could just make another tool that does this thing of saving a group of meshes as a single mesh after the physic simulation stops, without even the break tool even if that would be absolutely useful too.
I place the castle on the side of the hill, with ready broken parts, walls, etc. on the top of it in a “ready to fall” position, run the simulation, wait that all objects stop, and then save.
Great, great time saver.