Search Unity

[RELEASED 1.2.5] Smart Slicer Pro 2D

Discussion in 'Assets and Asset Store' started by Qzia, Feb 7, 2018.

  1. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    Introduction
    Smart Slicer 2D is a powerful tool to modify 2D objects that are using 2D Colliders. This tool also provides low level API to slice (points lists). The final goal of this project is to create an universal tool which would allow you to split, slice or merge 2D objects in any way you might like!



    Screen1.png Screen3.png screen4.png Screen5.png screen1.png

    If you have any suggestions or feature requests - feel free share it!

    [Note] documentation is being updated


    • Flawless Customer Support
    • Sprite Slicer (sprite sheet is supported)
    • Joints Slicer (destroy joints)
    • 2D Terrain Destruction
    • Supports multiple joints attached to the slice-able objects
    • Uses Box, Circle, Capsule, Polygon Colliders
    • Supports Concave Colliders with holes
    • Custom LineRenderer for Sprites & 2D Meshes
    • Multi Touch Support
    • Shape Comparison in percent
    • 10 Tech Demo scenes
    • 4 Game Demos
    • Custom input control (AI programming)
    • Slice Particles
    • Events Handling - Slicer Events returns information about the slice
    • Multiple controllers & Slicer2D components
    • Controller & Slicer2D components
    • Slicer Layers
    • Full C# Code API
    • 2D Geometry Helper API
    • Mobile friendly
    • Easy to setup
    • Programming is not a necessity


    For this stage I'm prioritizing the functionality and reliability of slicer tool.
    There are a few known flaws with "polygon" type slicing cases.


    Trello Roadmap List

    V1.2.5 [2020-07-27]
    [ADDED] Sprite 3D Mode
    [ADDED] Unity 2020 Support
    [FIXED] Linear Slicer: Cutting through points
    [FIXED] Mesh 2D UV coordinate generation
    [CHANGED] Polygon Slicer Stability
    [CHANGED] Optimized GC Calls for visuals
    [CHANGED] Namespaces to avoid conflicts

    V1.2.4 [2020-01-23]
    [FIXED] Add Force sometimes did not work properly
    [FIXED] Tracked Slicer skipped slicing in certain cases
    [FIXED] JointLineRenderer2D Mesh Leak
    [ADDED] Slicer2D "Center Of Slice" setting
    [CHANGED] Tracked Slicer properties now reset after re-enabling controller

    V1.2.3 [2019-11-22]
    [FIXED] Add Force sometimes did not work properly

    V1.2.2 [2019-11-17]
    [ADDED] Merger2D - Slicer2D extension to merge objects
    [ADDED] Merger2D Complex Controller
    [ADDED] Merger2D Polygon Controller
    [ADDED] Merge2D object returns merge result information
    [ADDED] Controller Sorting Layer and Sorting Order Support
    [CHANGED] Slicer2D algoritm clean up

    V1.2.1 [2019-11-11]

    [SUPPORT] Package for Unity 2019
    [CHANGED] Improved Complex Slicer input smoothness
    [CHANGED] Improved Complex CutSlicer input smoothness
    [CHANGED] Improved Complex Tracked Slicer input smoothness
    [FIXED] SpringJoint2D links disappearing after slice


    V1.2.0 [2019-10-28]
    [ADDED] Slicer 2D Settings Window
    [ADDED] LWRP Support
    [ADDED] Shape recognition & comparison
    [ADDED] Slicer2D object field afterSliceRemoveOrigin
    [ADDED] Tag support for game object slices
    [ADDED] Multi-touch for Linear Slicer
    [ADDED] Multi-touch for Complex Slicer
    [ADDED] Multi-touch for Linear Trail Slicer
    [ADDED] Multi-touch for Complex Trail Slicer
    [ADDED] Auto Complete for Complex Slicer
    [ADDED] Auto Complete for Linear Slicer
    [ADDED] Slicer AI - interface to control slicer input
    [CHANGED] Improved Slicer algorithm
    [CHANGED] Improved Tracker and Trail algorithm performance

    [FIXED] SpringJoint2D links disappearing after slice
    [FIXED] New objects did not inherit original game object layer & physics material


    V1.1.9 [2018-12-07]
    [ADDED] Linear Track Slicer Type
    [ADDED] Force parameter for linear and complex trail slicers
    [ADDED] ColliderLineRenderer "Order in Layer" parameter
    [ADDED] Slicer2DController "display collisions" parameter
    [CHANGED] Improved Slicer algorithm


    V1.1.8 [2018-11-22]
    [ADDED] Linear Trail Slicer Type
    [ADDED] 4 demo games
    [CHANGED] Improved Slicer algorithm


    V1.1.7 [2018-11-14]
    [ADDED] Next & Previous Scene Buttons
    [ADDED] Complex Click slicing type
    [ADDED] Edge/Polygon Collider Generation Option
    [CHANGED] Improved Joints Demo
    [CHANGED] Improved ColliderLineRenderer visuals
    [CHANGED] Improved Slicer2DController visuals
    [CHANGED] Improved Joints Renderer visuals

    V1.1.6 [2018-11-07]
    [ADDED] Downloadable mobile demo (APK)
    [ADDED] Demo scenes supports mobile resolutions
    [CHANGED] Demo 1 Scene now includes trail slicer
    [CHANGED] Optimized visual performance
    [CHANGED] Optimized joints code

    V1.1.5 [2018-11-02]
    [ADDED]
    Global Slicer2D & Anchor Events
    [ADDED] Trail slicing type
    [ADDED] Option to recalculate center of sliced object
    [ADDED] Slicer2DSound adds sounds for the sliced objects
    [ADDED] Mouse Scroll resize size of cut
    [CHANGED] Slicer2DAnchors is now built-in Slicer2D Component feature
    [CHANGED] Slicer2D Particle System performance improvements
    [FIXED] Slicer2D did not used sprite FlipX & FlipY parameters
    [FIXED] Sliceable HingeJoint anchor offset was incorrect
    [FIXED] Slicer2DController "Enable Visuals" did not worked properly
    [FIXED] Blinking collide line renderers after slicing with complex tracked slicer
    [FIXED] Slicer2DController Layer Serialization


    E-Mail: simonas@kuzmickas.lt
    Discord: https://discord.gg/AktrfBe
     
    Last edited: Jul 30, 2020
    WootWoot and theANMATOR2b like this.
  2. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Instabuy. So simple and clean slicing solution for such a small price. Hope you'll get more people out here.

    I've got a bug -- sliced box with hole a few times and the big orange (box with hole colour) rectangle at the background.

    How to reproduce -- slice box with holes real fast like at this GIF -- https://gyazo.com/4dd528a39a302c9def19609e9e86c4a3

    upload_2018-2-26_21-29-5.png
     
  3. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    Hey, Thank you!

    I'm working on this issue. I hope to completely fix it in couple of upcoming versions.

    Line Renderer draws correctly, so this means the slicing works just fine.
    However, the problem is in complicated mesh triangulation with holes.
    It generates corrupted mesh in a certain case (I already know exactly which case it is)

    I'm currently thinking of the best way to patch this up. This only happens with complex slicer and polygons with holes:)

    By the way, this tool can be used to make a game like worms and it could use unity physics with it because of collider system. There is a way to improve the performance for large bodiesby implementing collider chunks, so it wouldn't need to re-create whole collider.
    Also, I've updated documentation today, more particularly Slice2D result object section.

    Thanks for a good review!
     
    Last edited: Feb 27, 2018
  4. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Thanks for the reply. I made some research and found out some performance bottlenecks.

    ColliderLineRenderer generates a lot of garbage and lowers FPS significantly as the number of pieces increasing.
    ToWorldSpace function has lots of calls and every call generates one object and it has 2 foreach loops over collections. The vertex and tris count is not so important as 1.6MB of garbage every frame and thousands of GC calls.

    Have a look:

    Without collider lines:
    upload_2018-2-27_19-40-28.png
    With:
    upload_2018-2-27_17-12-16.png

    First of all I think there is no need to create unity object to represent borderline/outline. That should be a shader effect.

    Have a look at the video with optimizations, maybe you can get something useful.

     
  5. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    Oh, that's great that you are looking into this and you gave some great points there.
    I am aware of the topic you provided with the video.

    The ColliderLineRenderer2D actually is entirely graphics function, it renders objects from the script with GL function OnPostRender method. It is just a small "Max2D" library I made for the demo scenes. I chose that way because it was a specific line effect I was aiming for. This method applies on all materials, sprites and was easy to implement, therefore for the demos I thought it would be the best.

    Indeed, probably this could be changed with a well written Shader.

    For instance, ColliderLineRenderer2D creates 3 GL.Quads for each line (start/middle/end)
    So currently if you have a BoxCollider2D - there are 4 lines, 12 quads, 24 triangles.

    I agree that it's quite heavy for such a visual script, however the main priority is the slicer features at the moment.

    I want to add 4 more demos - different types of mini games.

    Working on 1.0.8 at the moment
    • Did a clean up for linear & complex slicers code
    • In terrain demo, the floating pieces now falls on the ground
    • Fixed a bug when slicing (complex slicer) inside the holes
    • Fixed some minor issues with CircleCollider2D vertices count
    • Fixed 6 demo - polygon slicer canceled some slices because of wrong slicing type
    • Slightly improved ColliderLineRenderer2D performance
     
    Last edited: Feb 28, 2018
  6. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    The main performance impact of ColliderLineRenderer2D is that it generates lots of Polygon instances. Especially temporary, like when the ToWorldSpace method is called. So it's not as about the GL side at all, it's just about lots of Polygon objects.

    This is how I see the problem.
     
  7. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    The performance increases 3X after I change smooth line with regular one.
    Try adding "Max2D.SetSmooth (false);" OnPostRender loop (ColliderLineRenderer2D.cs)

    It doesn't seem to impact performance a lot if I change from poly.ToWorldSpace (transform) to just poly.
     
  8. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Yeah, but look at the difference. Regular and the new one.
    upload_2018-2-28_12-58-51.png

    upload_2018-2-28_12-58-24.png
     
  9. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    Yeah, I hate the default line look ^_^

    I just wanted to say that "ToWorldSpace" is not the reason it slows down so much.

    I'm surprised that PostRendering loop is actually quite slow, maybe that's because of the material I'm using for the line.
    I'll investigate that further later on.
     
  10. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    I see that you have a good utils library. Can't find actual function but want to ask you: can I calculate slice's area using your utils library? It will be helpfull.

    Also I found out that Slice events are private and non-static. Why? Of course I've changed it for my needs, but what was the intention?
     
  11. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    Yes, you can calculate polygon area using "Polygon" class.

    Code (CSharp):
    1. Polygon poly = Polygon.CreateFromCollider(gameObject);
    2. Debug.Log(poly.GetArea());
    For slice event, you can iterate through polygons list:
    Code (CSharp):
    1. void Start () {
    2.     Slicer2D slicer = GetComponent<Slicer2D> ();
    3.     slicer.AddEvent (OnSlice);
    4. }
    5.  
    6. bool OnSlice(Slice2D sliceResult)
    7. {
    8.     foreach (Polygon poly in sliceResult.polygons) {
    9.         Debug.Log (poly.GetArea ());
    10.     }
    11.     return(true);
    12. }

    About events, this event system allows you to create specific components which are triggered on slice event.
    • There are two types of events
      • AddEvent - Called before the slice is performed and new objects are created
        • Result includes only "polygons" class objects (can be canceled)
      • AddResultEvent - Called after new objects were created
        • Result includes game objects that were created after the slice (cannot be canceled)

    By using "return(false)" you can cancel that certain slice for example.

    Code (CSharp):
    1. void Start () {
    2.    Slicer2D slicer = GetComponent<Slicer2D> ();
    3.    slicer.AddEvent(OnSliceResult);
    4. }
    5.  
    6. bool OnSliceResult (Slice2D result) {
    7.    // This cancel the slice, it won't be performed
    8.    return(false);
    9. }
    From my personal experience, this seemed to be more universal and easiest way to write specific slice functions.
    It was intended to work as similar as "OnCollisionEnter" method.

    I could also include static event system which would return objects and events, however I don't really see any benefits from it. Could you provide some cases where it would be useful?
     
    Last edited: Mar 1, 2018
  12. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Thanks! You are being extremely helpful!

    Now I understand your intention behind the event handling. It's quite a good idea.

    And I've got a problem:

    Slice Limit is not working for situations when you are creating multiple slices at one time. Like with complex slicer. I'll try to fix it by myself for current project.

    That's my small fix for the problem. +1 is because result contains an original piece.
    upload_2018-3-1_16-44-44.png


    Ohh...I see you've got 2 new reviews on Asset Store. Cool!
     
    Last edited: Mar 1, 2018
  13. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    Regarding the slice limit.

    Slice limit 1 means you can slice the object once.
    Slice limit 2 means you can slice object and then slice it's childs (slices) once.
    "slicingLimit" must be true.
    Everything seems to be working fine without the fix though.

    By the way, your fix check is too late because all the slicing algorithms are already performed at that point. There is the same check in every slicing method ( GetPolygonToSlice() )

    When using Complex Slicer, it calculates "multiple" slices as one. That was intended at first, however I could improve it now when you mentioned it.
    The problem is that whole Complex Slicer algorithm is entirely calculated by "lower" level API which does not return how many slices were performed at the moment.

    To solve that problem, I could improve it by adding slice count in Slice2D object in lower level API.

    Yeah, that's great to hear that people uses it, I hope more people will get interested.
    Well, this asset is mostly oriented for slicing games that I guess are not that common.

    Also thank you, your questions and time spent helps to improve the asset. This will help me to develop documentation:)
     
    Last edited: Mar 2, 2018
  14. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Can I ask you what is the formula here? Can't find actual vector formula close to it.
    upload_2018-3-2_17-55-50.png
     
  15. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    It's just a function. There is no other way to simplify it further.
    Code (CSharp):
    1. float area = 0f;
    2. Vector2 a = list.Last ();
    3. foreach (Vector2 b in list) {
    4.    area += ((b.x - a.x) * (b.y + a.y)) / 2f;
    5.    a = b;
    6. }
    PS: back from vacation
     
    Last edited: Mar 11, 2018
  16. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Cool. I found out that border is rendering in front of the slice trail. Both rendered via OnRenderObject, but how can we basically change the render order/queue? There is no way, as I know, to change it in OnRenderObject. Moving slicer trail into OnPostRender didn't help.
    upload_2018-3-12_20-11-30.png
     
  17. WootWoot

    WootWoot

    Joined:
    Jul 10, 2013
    Posts:
    1
    Hey, first of all, this asset is really awesome. Working like charm at the moment.
    Anyway i encounter a bug on the 6th demo with the bombs.
    If i click on exact same X position, it returns me this error : "Slicer2D: Returns Empty Polygon Slice".

    Do you have any idea how to fix this please ?
     
  18. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @interpol_kun, I'm thinking about that right now, can't find a proper solution except to rewrite the LineRenderer in next version.

    @WootWoot, This is error from my currently not fully finished code when slicing-off polygons.
    I'm aware of this issue very well as I manage to print an error on that specific case.
    I'll be fixing/updating this functionality with new update.
     
    Last edited: Mar 20, 2018
    WootWoot likes this.
  19. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Ok, before you start. I did a research and found out the performance problem with ColliderLineRenderer and LineRenderer.

    So we was looking at the wrong direction. The main problem is that both of them generate TONS of setpass calls and batches. No instancing, nothing at all. For example I have a scene with some HUD and triangle:

    With border (even though setsmooth is set to false):
    upload_2018-3-20_19-33-45.png

    upload_2018-3-20_19-34-7.png

    And without:
    upload_2018-3-20_19-35-34.png

    it's not mobile friendly at all, yet. Because >100 calls isn't recommended at all if it's not a top device. But It would be not friendly at all even for a good PCs when the shapes become more complex, or when, as I mentioned early, there will be a lot of pieces.

    What happens with complex shapes?

    upload_2018-3-20_19-37-13.png
    upload_2018-3-20_19-37-55.png

    160 calls just for collider line renderer.

    Ok. Let's check the Line Renderer.

    Just pressing the button (when the simple first square for line renderer is created) gives us +32 calls instantly.
    And every step of the line gives us at least 4 calls. Like if I draw circle around the butterfly, it will give me up to 250 calls in addition to existing calls.


    The main problem is setpass calls and batches. We should batch everything to draw it in a few drawcalls instead of hundreds.

    So, at least now we all know the real problem with that thing. I hope you will fix that, also I have something for you to improve the tool (I am extensively using it in my project). Reply to me when you'll read that and tell if you need some help with that.
     
    Last edited: Mar 20, 2018
  20. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    To reduce set pass calls try replacing max2d.cs with this code:
    https://pastebin.com/3dB6d23F
    I hope it's capable with last version, because I did quite some changes for upcoming release.

    Probably I'll need to rewrite lineRenderer script anyway as I want it to support different materials, width, color, glow, proper order & queue.
     
  21. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Actually I am using previous version because I changed a lot of your code for my needs.

    So I changed the code and resolve some errors (there is a new Z argument, I passed 0 value in all methods, works fine). Woks cool, 1 set pass call per shape's border. Now I can enable SetSmooth!

    But line renderer is still generates a lot of calls.

    Do not forget to add support for sprite color. I did some changes so the SpriteMesh2D generates mesh considering the SpriteRenderer color property.
    upload_2018-3-20_21-5-42.png

    The line renderer performance is still not quite right. I'll still use the old version of tool for the current project because, as I said, I changed it a lot, but for future releases the performance I hope will be on top.

    Also, don't forget to add Max2D fix for a new release, cheers!
     
  22. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    Oh right, I'll add color pass as well, that's a necessity, didn't noticed this.

    With last Max2D edit I've provided, ColiderLineRenderer component should require 1 SetPass call & 1 batch.
    From GPU perspective it's the best I can do using OnPostRender.

    Oh, I got confused..because by line renderer you were probably referring to Slicer Controler line renderer.
    I will do fix in a moment.

    I could also generate a child line mesh with the materials, so I wouldn't need to use any drawing scripts in real-time.
     
  23. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Ah, yep, my bad. Line renderer is a slice controller visuals, I mean. They are generate a lot of calls, still. But as I see it's using the same Max2D class to render itself. Strange. Maybe we could draw the line on a transparent texture on top of the viewport so we could decrease the cost to 1 call at time?

    Huh, stupid idea, but it may be efficient.
     
  24. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    This should fix it for SlicerController, Max2D.cs:
    https://pastebin.com/jtziT5KL

    This improvement of course is going to be included in next updates:)
     
  25. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Cool! I'll check it tomorrow and tell you if it works or not. Thanks for the fast feedback.
     
    Qzia likes this.
  26. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @interpol_kun This version should optimize the set pass calls & batches the most:
    https://pastebin.com/kcdDn8ih

    Note: With this particular version you might get some additional errors.
    I have renamed Max2D.DrawSquare to Max2D.DrawLineSquare

    Also slicer line width should be adjusted in the controller.
    Max2D.SetLineWidth (lineWidth) to Max2D.SetLineWidth (lineWidth * .5f);

    Edit:
    https://pastebin.com/MPZHHsTD
    this fixes sharp line edges, but uses slightly more calls

    @WootWoot, if you want to remove error message, just press on console warning and it will take you to the code line, just comment that specific line which prints the error (uses "Debug.LogError" function)
     
    Last edited: Mar 22, 2018
  27. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    I'll pick that version.

    The next 2 versions have a very strange behaviour. There is a FLAT square at the start and the end of lines instead of normal hollow square. Yeah, there are less calls, but I want it to look good too. So ~40 drawcalls are acceptable for me by now.

    Strange I didn't get any errors with all 3 samples.
     
  28. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    Last edited: Mar 27, 2018
  29. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    - 1.1.0 Insights -
    [FIXED] Slicer2D now properly clones components state when creating new slice
    [CHANGED] Complex Slicer LineRenderer now is seperated into same distance vertices
    [ADDED] Demo 7 - Joints
    [ADDED] Component "Slicer2DJoint" - must be attached to a component which is affected by Joints
    [ADDED] Component "Slicer2DAnchor" - attach Slicer2D Component to a Collider

    Still working on improvements.
     
  30. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Hey. I am back.

    Nope. Less calls, yes, but the square is not hollow. Maybe I am not good at describing. I'll show you.

    1st. Proper line and squares.

    upload_2018-4-5_0-20-39.png

    2nd. Your last version. As you can see squares are flat. Line has borders too, but it's not the case.

    upload_2018-4-5_0-23-27.png

    I wanted the first version with less calls and asked for that. If it's not possible, so no problem, I'll stick to the current code (https://pastebin.com/NRKPCgjA).

    I don't know. You have a lot of different games which show almost everything.
     
  31. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @interpol_kun
    I've updated asset to 1.1.0 version with all optimizations, doesn't the line work there?

    There could be something that you have missed when changing the code, I'm not sure.
     
  32. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Hey @Qzia, just purchased the package and have a question. I'm pushing a character using AddForce in FixedUpdate on top of one of a 2D primitive that you've created in another scene (the box). I can slice the box, which works as expected, and the character moves as expected. However, when I slice the box while the character is in contact with it, the character comes to a stop. Any ideas why? Thanks!

    upload_2018-4-23_21-7-7.png
     
  33. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @AntLewis Strange behaviour indeed.
    Probably removing and object on which the character is in contact with causes that, however it's really strange.
    Could you provide a sample scene? I would take a look.

    I tried to reproduce the issue, but in my case sliced body did not affect the controlled circle.
     
    Last edited: Apr 24, 2018
  34. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Here's a link - thanks. If you could load the test scene.
     
  35. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    Thanks! It seems that shared material wasn't passed correctly after slicing bodies.
    Try updating slicer2D.cs with this
    https://pastebin.com/KRkqQFhy
     
  36. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Perfect! Thanks so much for the speedy support. Within the API, which is the best method to access the the properties (specifically the rigidbody) of the objects that has been created after a slice?
     
    Last edited: Apr 24, 2018
  37. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @AntLewis
    I've made an event system which can return created polygons/game objects before or after slices.
    You should attach this script to the object you are slicing.

    Code (CSharp):
    1. public class SampleClass : MonoBehaviour {
    2.  
    3.     void Start () {
    4.         Slicer2D slicer = GetComponent<Slicer2D> ();
    5.         slicer.AddResultEvent(OnSliceResult);
    6.     }
    7.  
    8.     void OnSliceResult (List <GameObject> result) {
    9.         // You can use for each to loop through the objects
    10.         foreach (GameObject g in result) {
    11.         // g.GetComponent
    12.         }
    13.     }
    14. }
    15.  
     
  38. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Cheers!
     
  39. cgrimsley707

    cgrimsley707

    Joined:
    Jul 31, 2017
    Posts:
    1
    Hello @Qzia, I'm not a super adept coder but i can usually figure most things out. I have one problem that keeps stumping me. I'm trying to get the slicer to take chunks out of a planet -- similar to the terrain destruction demo. I got it somewhat working, however i can't seem to find the variable that lets me adjust the diameter/radius of the slice being taken out. Would you be able to point me in the right direction?
     
  40. Euthyphro

    Euthyphro

    Joined:
    Jun 29, 2013
    Posts:
    9
    Hey, just started using this asset but ran into a problem that hopefully is a quick fix. The sprite I'm using is a simple single mode sprite, however, the Slicer2D when adding SpriteMesh2D keeps turning it from a single sprite into a sprite sheet of sorts.




    Any idea on why this is happening? The sprite itself is set to the exact same parameters as the example with the food/fruit sprites in the demo.
     
  41. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @Euthyphro Is there a way I could take a look at sample project? It could be that I didn't made it work correctly with sprite sheets. I could do some adjustments for that though!

    @cgrimsley707 It depends on which API function you are using. If you are using this:
    PolygonSliceAll(pos, slicePolygon, polygontoDestroyInside, Slice2DLayer layer)

    You have to input your own polygons to slice, so that would mean you need to create a Polygon() and insert points youself
    Fortunately, Polygon class includes a constructors for circle polygons.

    PS: I'm a little busy lately, I will send up some samples asap if needed.
     
  42. unitynosf

    unitynosf

    Joined:
    Jun 9, 2014
    Posts:
    23
    Hi everybody, I've been playing with the WebGL demo few times this week and am very impressed.
    Great job! Kudos. I am about to buy this next week when starting on personal project that could utilise a bit of this engine, for fun. Someone nicely said, and I agree - instabuy :)

    I do have a specific need tho, it may or may not be doable with API you have (which I am not familiar with yet), so I thought just to post a quick question, in case anyone bothers to jump in with an idea, so I can have a think about it over next few days. I would be writing a solution of my own if there isn't, but am very curious at the moment, hence why I ask.

    So, pseudo like to be quickly explained:
    - instead of OnMouseDown - make a line - OnMouseUp to get starting and end point
    is it possible to get cut to execute whenever both points are outside of target object by using current API or similar?
    So it works more like autodetect, where you wouldn't have to release mouse to get actual cut line.

    If not, I suppose I'd have to see if I can do it somehow with raycast/linecast or similar, which would likely have length same as mouse starting and current point delta/distance.

    Thank you in advance for time and effort.
    Best of luck with this and other projects.
    Regards
     
  43. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @Euthyphro I've fixed your issue in 1.1.1 version which is pending at the moment.

    @unitynosf It's really easy to do, because Slicer2D API does not return result until slice points are inside the polygon.
    If you still have issue, I could help you to solve this.

    @cgrimsley707 I could help out if I would know what you are working with.
    You could contact me with mail (simonas@kuzmickas.lt) if you want your project to keep in private.

    Released New Version: 1.1.1
    [FIXED]
    Slice result returned modified transform scale
    [FIXED] Sprite Sheet Sprites appeared distorted when using Slicer2D component
    [ADDED] Mass recalculation for Slicer2D component
    [ADDED] Linear Cut mode for Slicer2D Controller
     
  44. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    Is it mobile friendly yet? Without all those setpass calls?
     
  45. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @Cypras It was optimized a lot in latest versions. The only part that requires some improvement is custom LineRenderer which takes 2 set pass calls per object. Though I'm working on mobile demo scene which should be even more optimized.

    Edit: Optimized LineRenderer to use only 1 setpass call for next version (1.1.2)
    1.1.2 version is now pending in asset store.
    Also I'm working on a mini game "SLICEROIDS" that will be included in the package.

    Untitled.png

    Untitled.png
     

    Attached Files:

    Last edited: Aug 6, 2018
  46. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Is it possible to know how much percentage of sprite got cut? something like this game
     
  47. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @idurvesh Yeah, there is a method polygon.GetArea() which returns the size of polygon.
    You just have to divide original area by sliced area.

    You can get polygon object from collider with static Polygon class method.
    Polygon.CreateFromCollider(GameObject gameObject)

    (originalArea / slicedArea) * 100 = percents
     
    idurvesh likes this.
  48. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Cool awesome. And any method to check how to not slice if ball is in the sliced area?
     
  49. Qzia

    Qzia

    Joined:
    Jan 25, 2015
    Posts:
    138
    @idurvesh I did a small demo for your case.
    I might include it in the next version package or earlier send you through the mail.

    To get if ball is in sliced area I used MathHelper class functions and SlicerController list of points.
    I have extended MathHelper a little to support circle collisions now.

    PS: I'm also adding "Tracked Slicer" functionality to the next version for slicing moving bodies. Attached video.



     
    Last edited: Aug 9, 2018
    VicenzoPegado and idurvesh like this.
  50. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Awesome, Plz send me ASAP, I need it soon. Sending you mail.