Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Dynamic Mesh Cutter - A flexible run time mesh cutting solution [Discussion Thread]

Discussion in 'Assets and Asset Store' started by PBTools, Mar 7, 2022.

  1. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    cover_1950_1300.png

    Please read through the manual first before asking questions.

    Manual
    Demonstration Video 1
    Demonstration Video 2
    Unity Asset Store Link


    Why this thread?
    Because of requests from my users, I created this discussion thread for anyone having questions, comments, advice or other feedback regarding Dynamic Mesh Cutter. I will always answer mails at philipbeaucamp.inquiries@gmail.com as well, but this thread will act as an alternative way of reaching out to me.

    What is Dynamic Mesh Cutter?
    Dynamic Mesh Cutter is a runtime algorithm that allows you to quickly cut meshes in a very performant way. More than that it can separate disjoint meshes and also cut ragdolls, allowing you to cut a human ragdoll and have its newly cut meshes behave like ragdolls as well. The latter requires quite a bit of setup that I'm happy to explain further if people have questions.

    How does it work?
    Whatever mesh (be it static or skinned) will be cut by an infinitely large plane. If this plane intersects any triangles of the mesh, the mesh counts as cut. The result will first be split into two parts, a positive and a negative side and can optionally further be separated into individual meshes if the vertices are disjoint. This however is a option the user can enable or disable. There are many settings to choose from, such as whether to have the algorithm run asynchronously (for better performance) and how the resulted mesh should be treated.

    What is this tool NOT?

    You can not cut a mesh a "certain distance" only or in any other form but via a plane. You can add cool vfx, animations, sounds or other callback related logic yourself (I exposed the right callbacks for this), in fact I encourage you to do this since it will greatly enhance the cutting experience, but keep in mind that this tool is a cutting algorithm only. It is not meant to do all the cool fancy stuff for you, it just cuts meshes.

    What are some current limitations/issues?
    First of all, because of performance reasons, this algorithm does not detect holes inside a mesh. It correctly cuts most shapes, such as human limbs and does exceptionally well for convex shapes, but it might not be the right tool for you if you plane on using vastly complex meshes.
    Secondly I've had one report so far of a memory leak. I couldn't reproduce or confirm this on my end, but if there is anyone else experiencing issues with this I'd greatly appreciate your feedback. I hope to make this tool as easy to use and hassle free as can be. Update: I have not heard any related issues on this so I assume the issue was not related to Dynamic Mesh Cutter.

     
    Last edited: Aug 17, 2022
  2. y0u553ef

    y0u553ef

    Joined:
    May 2, 2017
    Posts:
    26
    Hey , I want to achieve an effect similar to the video the square mesh change to take the shape of the metal obstacle . (change from square to tree based on the collision) . is that possible with your framework ?
     
  3. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Hi @y0u553ef . That's not possible but most likely also not what you want to be doing. From the video it looks like the mesh is simply being replaced by another, tree shaped one. This solution is much more performent and easier to achieve. To clarify, Dynamic Mesh Cutter only cuts via a plane, but again you most likely want to simply replace your mesh if the shape is already predefined and known at editor time anyway. Hope this helps!
     
  4. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    440
    hi. so I'm interested in a couple of things. in the description it says it cuts ragdoll, but in the example scene it still falls like a stiff statue, not a ragdoll. it is not implemented in that scene?

    limbhacker had a problem with nested hierarchies (I usually keep ragdoll object (switched off) under main character object), but tried this dynamic ragdoll script's autocalculate and everything seems fine. so it should be no problem, right?
    - a bit more info on this: so the cutting should be done on the ragdoll object after it is switched on. is it possible somehow?

    also, can something be done with worldwide mesh cutting, so cutting functions like a sword? something like filtering meshes based on distance (?) or collision, and perhaps maximizing joints to cut, if it's a big world, many actors to save performance?

    do I get this right:
    this is the line that starts it all
    Cut(target, transform.position, transform.forward, null, OnCreated);
    so if the right target of a object is fed in and the right plane defined (?), it would do the trick?
     
    Last edited: Mar 31, 2022
  5. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    hi @bobadi .

    In order for the "ragdoll" cutting to work you have to change the DefaultBehaviour setting on the MeshTarget component and set it to "Ragdoll".

    Not sure I fully understand your question, but the ragdoll cut will work as long as the dynamic ragdoll component is set up properly in advance in the editor. The colliders should be detected even when the gameobjects are disabled in the hierarchy.

    The algorithm currently cuts any active MeshTarget components that intersect with the plane (which is infinite). If you need to exclude/include certain objects or only want to cut objects in a certain range, you'll have to implement that logic yourself (e.g. disable the MeshTarget component if the sword is not touching the enemy etc.).

    That's absolutely correct. This is the only line you need to call for the algorithm to start!

    Hope this helps!
     
  6. thePortalDude

    thePortalDude

    Joined:
    Jan 9, 2017
    Posts:
    6
    Hi! I've been using your tool and it's awesome! I've one question for you: is there a way I can modify the cut behaviour so that I always cut the mesh parts that are on the upper side of the cut plane? (both mouse behaviour and plane behaviour cases). My goal is to have always a visible mesh on the ground (it's a moving object) but if I do a horizontal cut side to side the upper mesh is the one remaining. I hope I made my question clear enough :)
     
  7. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Hi @thePortalDude . I'm afraid I don't exactly understand what you mean by "cutting the mesh parts on the upper side".
    Could you try and elaborate? Sorry!
     
  8. thePortalDude

    thePortalDude

    Joined:
    Jan 9, 2017
    Posts:
    6
    @PBTools Let's say I have a cube, if I draw a cut line horizontally in the middle of the cube what I would always want is that the cube is cut by half and the lower mesh is the only part that remains. This should be true for every cut I perform: I would want that every part of the mesh that is above the line is the cut part.

    Currently the behaviour is the one I am showing in the screenshots I posted. As you can see the cut erased the lower half of the mesh, but what I would want is the opposite.

    Sorry if this is still unclear, I'll try again if necessary :p

    Thanks for your time!

    Immagine 2022-04-06 125419.png Immagine 2022-04-06 125420.png
     
  9. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    What I am not fully understanding is what you mean by "remaining" and "erased". The tool does not erase anything, it should just separate the green box into two different, smaller meshes.

    Are you talking about manually deleting/disabling the mesh that ends up being on the upper side of the cut after both meshes have been created? You could achieve this by disabling the objects in the OnCut or OnCreated callbacks in the CutterBehaviour. (See the manual, point 2.3 and check out the Info class of those callbacks if you don't know what I'm talking about).
     
  10. marounkattar

    marounkattar

    Joined:
    Jul 1, 2019
    Posts:
    4
    Hello dear I have a question about your asset when I cut one human leg it will cut both legs can I change something with your code mousebehaviour or planebehaviour and thank you
     
  11. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
  12. beddggv

    beddggv

    Joined:
    May 9, 2022
    Posts:
    2
    Hello.
    Thanks for your reply in the review.
    I am able to call the plane to the VR controller position.
    Sorry for the rudimentary question.
    How can I make this called plane execute the cut automatically?
    Even if I could call a plane with PlaneBehaviour on it.
    I don't know how to execute the cut in game.
     
  13. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    hi @beddggv ,
    Once you have a plane all you need to do is call the "Cut" function on the CutterBehaviour script in your scene.
    You will need at least one CutterBehaviour in your scene. Once you have a reference to it, simply call the public function called "Cut" and pass in the plane and the rest of the parameters. I hope this helps.
     
  14. beddggv

    beddggv

    Joined:
    May 9, 2022
    Posts:
    2

    Hello.
    Thanks for the advice, now I can execute the cuts!
    I have an additional question.
    If the cutter target is set to ragdoll or animation, the settings of the original object will be inherited.
    However, in the case of stones, they cannot be taken over.
    How can I reflect tags and components in the cut object even in the case of stones?
     
    Last edited: May 29, 2022
  15. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    @beddggv That is a great catch! Currently only in the case of "stone" I am making a brand new gameobject. For the other cases I am duplicating the objects which is why things such as tags carry over.
    I think its a good idea to be able to keep tags and perhaps components as well, give me some time to update the package!

    If you need the fixes ASAP I would recommended adding the tags/component in the OnCreated callback manually. I know this is not pretty but hopefully I will find a better solution soon!

    Thanks again for the feedback.
     
  16. tancfire

    tancfire

    Joined:
    Mar 12, 2017
    Posts:
    1
    First, it is a very great asset !

    I have question:
    Is it possible to apply a texture that adapts to the size of the face ?
    For some reason, the texture from the material face i want to apply is zoomed in when i cut from certains angles ....
     
  17. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Since it's impossible to know how the cut face will look in advance it's hard to have textures "adapt" to the new face. I recommend using textures with basic, simple colors for the cut face.
     
  18. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,622
    Hi there!
    I am looking at your asset in the store. I am wondering when I cut a mesh, can I, have the inside (new surface), have a different material?

    I often see the mesh cutting games where the inside (new surface) is a rainbow, while the old, original surface is chocolate cake, for example.

    Thanks!
     
  19. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    @renman3000 Sorry for my late reply but yes, that is possible! You can apply a new material to the new surface that is being created by the cut, or you can also choose to simply have the same material be applied. Check out the documentation for more info.
     
  20. jsinisi001

    jsinisi001

    Joined:
    Sep 23, 2014
    Posts:
    4
    Hi, I'm curious if this supports Puppetmaster at all, and if not if you have any guidance for getting this to work with puppetmaster.
     
  21. UmutGurdal

    UmutGurdal

    Joined:
    Aug 22, 2020
    Posts:
    2
    Is there a way to edit cutting plane size ?

    I want to cut just the hips but it cuts every mesh on the plane. I tried more than one skinned meshes but couldn't manage to make it work.
     

    Attached Files:

  22. irshadgirachirshu

    irshadgirachirshu

    Joined:
    Sep 14, 2020
    Posts:
    7
    Hi, I'm deciding whether I should buy this asset.
    I want similar functionality of cutting mesh of a human body but I also have multiple meshes within, some even intersecting each other. will I be able to cut the mesh and apply custom material on the cut surface?
     

    Attached Files:

  23. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Hi,
    you won't be able to do this, sorry. Dynamic Mesh Cutter creates a clean new face ignoring any holes or meshes insides you mesh. You'd still be able to cut the model, but it wouldn't look very great.

    In my experience you won't find a performant runtime algorithm that does what you're asking for, it is simply to complex to be used in most applications, but I have also never attempted to create one such algorithm so take it with a grain of salt.
     
  24. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    I have never used Puppetmaster so I cannot say this tool works with it.
    If you're really savvy you might be able to get it to work together, but currently it is not supported.
     
  25. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    No, there is no way to only cut part of a mesh. A mesh either gets separated in half or not, there is not in-between.
     
    UmutGurdal likes this.
  26. Invent4

    Invent4

    Joined:
    Aug 20, 2012
    Posts:
    15
    Hello,

    Great work. It's a pretty nice plugin, which really worth every cent. We recommend this for any developer looking for a dynamic mesh cutting solution.

    My question, suggestion, is about Root Motion compatibility. I read the posts above, but to make your plugin compatible with Root Motion, is just a question of forecasting different joints type.

    I mean, you are considering for Ragdolls only joint type CharacterJoint. The RootMotion ragdolls use ConfigurableJoints instead. The rest of the functionality would be exactly the same.

    I'm trying to adapt your codes, but I'm sure you could do it much easier, and turn your plugin compatible with RootMotion ragdolls (which is another good plugin, with incredible ragdoll functions).

    Anyway, great work. Thanks.
     
  27. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Thanks for the kind words and the great feedback.

    Since I haven't used RootMotion plugins before I wasn't aware what joints they used but I will definitely look into this.
    If it is really just about extending the functionality to ConfigurableJoints, then this should indeed be possible.
     
  28. EvilKris

    EvilKris

    Joined:
    Nov 18, 2014
    Posts:
    11
    Great asset. One addition I'd make would be to make it possible to drag in particles that are then randomly placed on the new cut side. That would be great for blood or for adding sparks or dust, for example.
     
    JUNG-ZEN likes this.
  29. znith52

    znith52

    Joined:
    May 6, 2017
    Posts:
    2
    Awesome asset. Is there any way to slice a mesh and just add the new geometry rather than separate along the cut?
     
  30. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    134
    I have a question, i see the lowest supprted version is 2020, would it be possible to get this to work in 2019.4? Is there an area of the code that needs some new function not in older version of Unity?
     
  31. StevoFx

    StevoFx

    Joined:
    Apr 1, 2020
    Posts:
    10
    Hello, my enemy models have the skinned mesh renderer on multiple different objects. For example the head and body are separate objects each with a skinned mesh. Will this asset work with that setup?
     
    radiantboy likes this.
  32. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,528
    Looks great, I tried today to cut one of my npcs, but I get this error:
    I placed mesh cutter on his main skinnedrenderer (inside him) and dynamicrgadoll on the parent object.

    Async cutter failed.System.NullReferenceException: Object reference not set to an instance of an object
    at DynamicMeshCutter.DynamicMesh.AddTriangle (System.Int32[] triangle, System.Int32 sub) [0x000c9] in Z:\gdv3.2021.2.16f1\gd\Assets\DynamicMeshCutter\Scripts\Core\DynamicMesh.cs:80
    at DynamicMeshCutter.MeshCutting.Cut (DynamicMeshCutter.Info& info) [0x00121] in Z:\gdv3.2021.2.16f1\gd\Assets\DynamicMeshCutter\Scripts\Core\MeshCutting.cs:78
    at DynamicMeshCutter.AsycWorker.AsyncCutting (System.Object args) [0x0000c] in Z:\gdv3.2021.2.16f1\gd\Assets\DynamicMeshCutter\Scripts\Core\AsycWorker.cs:94
    0x00007ff6a2ce643d (Unity) StackWalker::GetCurrentCallstack
    0x00007ff6a2ced199 (Unity) StackWalker::ShowCallstack
    0x00007ff6a3c52c23 (Unity) GetStacktrace
    0x00007ff6a42dc20d (Unity) DebugStringToFile
    0x00007ff6a1df6ef2 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    0x000002a39c564723 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    0x000002a39c56429b (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    0x000002a39c563e40 (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
    0x000002a4998fe4a5 (Mono JIT Code) UnityEngine.Debug:LogError (object)
    0x000002a4997e7633 (Mono JIT Code) [AsycWorker.cs:117] DynamicMeshCutter.AsycWorker:AsyncCutting (object)
    0x000002a4997e715b (Mono JIT Code) [AsycWorker.cs:63] DynamicMeshCutter.AsycWorker:Thread ()
    0x000002a4996c32c6 (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart_Context (object)
    0x000002a39c56312e (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
    0x000002a39c562c0b (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
    0x000002a4996c317b (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object)
    0x000002a4996c3083 (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart ()
    0x000002a39c001496 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    0x00007ffed6e8e034 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke
    0x00007ffed6dce724 (mono-2.0-bdwgc) [object.c:3064] do_runtime_invoke
    0x00007ffed6dd210c (mono-2.0-bdwgc) [object.c:4452] mono_runtime_delegate_try_invoke
    0x00007ffed6dfb911 (mono-2.0-bdwgc) [threads.c:1292] start_wrapper_internal
    0x00007ffed6dfbab6 (mono-2.0-bdwgc) [threads.c:1344] start_wrapper
    0x00007fff83947034 (KERNEL32) BaseThreadInitThunk
    0x00007fff851c2651 (ntdll) RtlUserThreadStart
     
  33. cryogee

    cryogee

    Joined:
    Aug 6, 2009
    Posts:
    132
    Hi -

    The mesh after cutting : the resulting two objects don't have correct pivot points or centre position or transform position correct

    We have to resort to Renderer Bounds method to find correct centre transform for these resulting two objects.

    Is that something you can fix in package itself?
     
  34. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Thanks for the feedback!

    I want to keep the tool as lean as possible and I'm sure everyone has slightly different needs for particles or VFX, but that's why I created two callback methods (OnCut and OnCreated) where you can trigger these kind of effects yourself it you'd like! Hope this helps!

     
  35. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    I'm afraid I don't understand, sorry! Could you give me a few more details?
     
  36. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Yes, 2019.4 is supported!
     
  37. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Yes, but be warned that it can get really complicated when working with multiple meshes, especially when animation and skinned meshes are concerned.
    To give you an example, if you cut only the body, two (or more) new meshes for the body will be created, but what happens to the head? Does it continue its animation? Does it fall down? Does it stick to the cut body? If so, to which bodypart does it stick? How do you manage the hierarchy? It's impossible to find a generic solution because everyones hierarchy/parenting looks different.

    I'm sure there is a solution for you, but don't assume you won't have to work or write custom code to find it.

    All DynamicMeshCutter is, is a tool to cut meshes. It cannot solve complex hierarchy logic without knowing the constraints.

    Hope this helps!
     
  38. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Since the _targetMesh in line 80 is being referenced just before, I assume it can only be that _targetMesh.Assignments is null. Unfortunately it is impossible to know why this is the cases without debugging the code. Can you step through your code to find out why this is the case?

    If you don't know how to do that, it'll be difficult to troubleshoot, but perhaps checkout the ragdoll setup in the ExampleScene and try to mimic the setup and hierarchy!
     
  39. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    That is both correct and incorrect, depending on your point of view. Some people need the pivot points to stay where the original pivot was, for others such as yourself it needs to be recalculated and moved somewhere else.

    I understand the issue your having, but as you can hopefully see, there is unfortunately no solution that fits all.

    The good news is that there should be a ton of data inside the OnCut/OnCreated callbacks that should help everyones needs. For example inside the "Info" class you have access to MeshTarget, the center of the new faces (GetWorldFaceCenter()), as well as all the mesh data. If the rendering bounds work for you, then that is also a fine solution!
     
  40. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    212
    Hello, I am interested in buying this asset, does it work with unity 2019.4 lts ??
     
  41. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Yes
     
  42. merpheus

    merpheus

    Joined:
    Mar 5, 2013
    Posts:
    190
    Does it preserve the cut skinned meshes bones? Meaning that, if I cut the legs of a biped, can it remain animated?
     
  43. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    Yes
     
  44. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    440
    hi, the infinite plane limitation is still there? the algorithm can't check vertices / face distance from a position, so it would cut those that are too far?
     
  45. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    It is up to the developer to decide which mesh to cut, not the cutting algorithm. One should try to separate the tasks of game logic and mesh cutting, the latter shouldn't have to care about how far away a mesh/object is, only how to cut it.

    Please try and find your own solution of determining which object to cut.
     
  46. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    440
    I'm not talking about choosing cut target object, that is simply doable.
    I'm talking about part of the object, like one arm of a object.
     
  47. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    If by "part of the object" you mean a part of the mesh the no, that is not possible. Every vertex of a given mesh is considered when performing the algorithm, there is no way of cutting only certain vertices of a mesh.
     
  48. whitegreenstudios88

    whitegreenstudios88

    Joined:
    Dec 12, 2021
    Posts:
    8
    Hi, just bought ur asset, everything working on window platform. Just a few question, does it work on webgl? And I have an naked avatar, it will only wear shirt and pants during runtime, that mean the shirt and pants is stich to the avatar. All share the same bone structures. Is it possible to just cut the shirt and pants(skinned mesh with texture)? Tq
     
  49. PBTools

    PBTools

    Joined:
    Mar 7, 2022
    Posts:
    25
    If the shirt/pants is a completely separate mesh then you can definitely just cut it without cutting the avatars body. If they share the some bone structure however doesn't they are part of the same mesh?

    I am not sure about webgl, I have only ever tested the tool in the Unity editor and on build versions on Windows.
     
unityunity