davidarayan / ezy-slice Goto Github PK
View Code? Open in Web Editor NEWAn open source mesh slicer framework for Unity3D Game Engine. Written in C#.
License: MIT License
An open source mesh slicer framework for Unity3D Game Engine. Written in C#.
License: MIT License
First of all, I appreciate your quick help.
As you recommended, I am going to use my own algorithm to fill concave intersections, although I have problems obtaining the intersection points after the cut.
How can I do this? I can't find a way to do it
Thank you!
Hello, It says here that the script's name doesn't match the file or there are no scripts in the file, what is the problem?
I tested the demo project and it works for the cube in the demo project. However it doesn't work with my object.
I have a 3d model of a piece of toast, and I am trying to slice the toast. The lower_hull and upper_hull that are created from the slice are not what they should be. I have attached a screenshot here:
I have uploaded the 3d model here:
Thank you for your help!
Here's a few pictures of what I'm talking about.
This was created by opening the SliceDebugScene in the examples repo, and then slicing the cube 3 times. The third slice created two pieces that are each missing a triangular chunk from their cross sections. I believe this is because no part of the outer mesh touches that corner of the cross section.
I tried fixing it by using Mesh.CombineMeshes on the upper and lower hulls after each cut, which fixes the original issue, but then the cross-section texture ends up overlapping with the outer mesh texture after two cuts.
By the way, thanks for putting up this repo. The code is very clean and well-commented, definitely a pleasure to read.
This is coming from the slicer somewhat randomly. I know the triggers are working right because the haptics and the score keeping works. But sometimes, it just randomly doesn't slice. Most of the time, on the same blocks, it slices perfectly fine. It does seem like when there's a bunch of stuff right up in your face is when it fails the most often.
NullReferenceException: Object reference not set to an instance of an object
Slicer.Update () (at Assets/Scripts/Slicer.cs:26)
This happens at the point where it attempts to create the upper and lower objects.
Investigate a proper method to add cross-section triangulation for concave slices. Currently looking at EarClip Triangulation algorithm.
Since the silhouette (and direction) of triangles is known at runtime, it should simplify the triangulation process for concave objects. If a proper order of vertices can be built during the cutting process, the triangulation should be able to handle both concave object cuts and objects with holes. The Vertex winding order can be determined by the facing direction of the original triangle.
The EarClip Triangulation runs in O(n^2) complexity compared to O(nlog(n)) of the Monotone Chain. This means cutting concave objects will have a bit of a performance impact. There is also a scenario where a concave object slice can yield 3 or more "separate" objects. Weather that should be handled properly or not is up for debate, at the very least it does not seem to be a trivial problem to handle.
Will begin investigation once the threading framework is complete.
Hello! I really love your EzySlice framework. Just wanna ask is it possible if I want to change
FROM
"Cutting objects with plane."
TO
"Cutting objects with uneven plane, for example, a wavy plane. Probably an object that have a mesh filter of a wavy plane. I'm trying to achieve a bite mark effect on food models."
Hope you understand my question. Thanks in advance!
When slicing through a GameObject the pivot points of the hull objects are the same as the pivot point of the old GameObject.
And the center points of the hull objects are somtimes (or always, I haven't checked) not in the center of the mesh too.
This is sadly causing quite some probems in my project^^
Is it possible for you to fix this or is this a Unity related problem?
Plane.cs(61,35): error CS0103: The name 'Normal' does not exist in the current context
`public Plane(Vector3 a, Vector3 b, Vector3 c)
{
m_normal = Vector3.Normalize(Vector3.Cross(b - a, c - a));
m_dist = -Vector3.Dot(Normal, a);
// this is for editor debugging only!
#if UNITY_EDITOR
trans_ref = null;
#endif
}`
Hello David,
I am a big fan of your Ezy-Slice script.
My issue is as the GIF shows on the left is the unity primitve cube(created inside unity) getting cut by the sliceplane. In the middle and on the right are objects i created inside Autodesk Maya and exported to unity. The rock and (generic) cube both are on the layer "sliceable" but are not affected by cut-script.
How is the correct way to export objects to make them work with your script? Or is the script only working with the unity-primitives?
I try to solve it since friday but there must be something i don't understand!
I attached the script, cube and rock mesh.
script_and_objects.zip
Thank you for your support! Hope you know the answer for this to work! Would like to support you aswell!
Greetings
Oliver
Hi there!
Brand-new user to Unity, so please forgive me if the answer to this question is obvious...
I have an animated zombie type character as a monster, and a ninja character with swords as the player character.
I would like to utilize this framework to trigger a slice at the point of collision between the zombie's capsule collider and the capsule collider I have assigned to the player's sword objects.
I have the onTriggerEnter logic working in my zombie character, but when I try to implement the randomSlice example onTriggerEnter, I get a number of warnings involving mesh renderers and filters.
I tried adding these elements manually, but can't seem to work it out how to make it so that the desired effect is achieved - which is my zombie getting hacked up when the ninja hits it.
Is this possible with this extension, and if so, could you provide a bit of information as to how I could go about implementing this behavior...or where to look for an example?
Thanks!
Currently, the plane you define for SliceInstantiate() cuts the mesh according to the object's local coordinate space. For example, when the object's coordinate space is aligned with world space any planes you define cut it as expected, but if the object rotates or moves, an xy plane will always cut the object along the object's local xy plane. I think it would be nice to have a parameter on SliceInstantiate() to signify if the plane should be treated as local or world space, so you can define a a world space xy plane, let's say, and just slice everything according to that properly, regardless of rotation and position.
Adding an optional multi-threaded mode will allow for faster slicing and parallel slicing in real-time. This may take some time since I'll need to do some benchmarking against multiple slices, small/large object slicing etc..
Hello, I have downloaded the example project, but can't find any way to test the cutting effect. I just see a colorful box without any way of actually slicing it. Can you guide me in the right direction? How can I slice that object, which is located in the sample scene?
A recent feature request to generate normals and tangents from the original mesh which is being sliced. From observation it seems the final cut meshes do not render properly, this is due to using Mesh.RegenerateNormals() which is too generic.
EzySlice fails to cut very small triangles due to a false-positive check via Plane.SideOf() function which forces an early-out before intersection takes place.
Hi, I'm using Unity 5.4.5 and on some meshes I get "Array Index Is Out Of Range" on Slicer.cs Line 123
Triangle newTri = new Triangle(ve[i0], ve[i1], ve[i2], uv[i0], uv[i1], uv[i2]);
The meshes are simple shapes exported from blender as .obj (cube, icosphere).
Curiously, the default unity cube mesh works, but not one exported straight from blender. It appears the triangles are in a different configuration that's causing some bug (I think).
On the meshes that do work, when I call SliceInstantiate() the upper and lower hulls have no end caps on the cut face.
This is not actually an issue with code or something, just with the documentation. I don't know how to, or how a game object is sliced. I've written all the codes here, but nothing is being sliced. How exactly does this work, what methods do I need to call inorder to slice something and how do I go about it???
Please help me ππππ
Ill be honest, I have no idea how to use this.
I just want to slice an object when it gets in touch with another when collided.
Example a sword through a branch of a tree.
I've messed around with the example scene but there seems to be a button to slice the things. Im not sure if Im looking at the right thing.
Anything would be helpful! thank you!
i want to do like this image
https://drive.google.com/file/d/1JXkADSdntjlI1dq5noOSoU8IsA8N337Q/view?usp=drive_link
I am getting some odd results after slicing a bent tube shaped mesh.
It looks like some of the normals are messed up? Basically it looks like some polys are missing?
The intersection fill works well, although it does have problems when manipulating the mesh, since the fill does not respect the geometry: (I'm trying to deform the mesh, but the face doesn't fill well)
Do you have any recommendations? Is there an easy way to get the vertices of the intersection so that I can fill it using my own code? Thank you
Hi,
i want to report a bug : if object we want to cut has different localscale on axis ,
for example localscale = new Vector3 ( 0.5 , 1 , 3) ; (0 .5 # 3 # 1) , the sliced face is on wrong direction.
If localscale of them is equal , everything works fine
Thanks
The Slicer relies on sub-meshing to store the polygon data for the cross section. When slicing an already sliced mesh, the framework will continue to add a sub-mesh which increases the array, increases the draw count and eventually leads to errors.
An enhanced mechanism will allow the slicer to reuse sub-meshes (similar to batching) if it detects that the desired Material is the same as from the original object. This will allow Meshes to be continually sliced, guaranteeing only 2 sub-meshes for cases where the Materials don't change.
This will be added as an enhancement over the existing API and will be performed behind the scenes automatically.
DOES YOUR FRAMEWORK WORKS FOR ANDROID BUILDS?
I am using ezyslice in my android game and it runs fine when using unity editor but it doesn't work when I make a build and runs it into null reference exceptions as given below
1.)AndroidPlayer([email protected]:34999) NullReferenceException: Object reference not set to an instance of an object
at EzySlice.Intersector.Intersect (Plane pl, Triangle tri, EzySlice.IntersectionResult& result) [0x00003] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\3rd-Party\EzySlice-fbb271fad6762b7a81c18f4bba19bdd59defbfca\EzySlice\Framework\Intersector.cs:60
at EzySlice.Triangle.Split (Plane pl, EzySlice.IntersectionResult result) [0x0000a] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\3rd-Party\EzySlice-fbb271fad6762b7a81c18f4bba19bdd59defbfca\EzySlice\Framework\Triangle.cs:308
2.)AndroidPlayer([email protected]:34999) NullReferenceException: Object reference not set to an instance of an object
at EzySlice.Intersector.Intersect (Plane pl, Triangle tri, EzySlice.IntersectionResult& result) [0x00003] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\3rd-Party\EzySlice-master\EzySlice\Framework\Intersector.cs:60
at EzySlice.Triangle.Split (Plane pl, EzySlice.IntersectionResult result) [0x0000a] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\3rd-Party\EzySlice-master\EzySlice\Framework\Triangle.cs:308
at EzySlice.Slicer.Slice (UnityEngine.Mesh sharedMesh, Plane pl, TextureRegion region, Int32 crossIndex) [0x0018d] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\3rd-Party\EzySlice-master\EzySlice\Slicer.cs:194
at EzySlice.Slicer.Slice (UnityEngine.GameObject obj, Plane pl, TextureRegion crossRegion, UnityEngine.Material crossMaterial) [0x000e9] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\3rd-Party\EzySlice-master\EzySlice\Slicer.cs:124
at EzySlice.SlicerExtensions.Slice (UnityEngine.GameObject obj, Plane pl, TextureRegion textureRegion, UnityEngine.Material crossSectionMaterial) [0x00005] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\3rd-Party\EzySlice-master\EzySlice\SlicerExtensions.cs:33
at EzySlice.SlicerExtensions.Slice (UnityEngine.GameObject obj, Vector3 position, Vector3 direction, TextureRegion textureRegion, UnityEngine.Material crossSectionMaterial) [0x00027] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\3rd-Party\EzySlice-master\EzySlice\SlicerExtensions.cs:27
at EzySlice.SlicerExtensions.Slice (UnityEngine.GameObject obj, Vector3 position, Vector3 direction, UnityEngine.Material crossSectionMaterial) [0x0001e] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\3rd-Party\EzySlice-master\EzySlice\SlicerExtensions.cs:18
at SlicerRealTimeMod.SliceObject (UnityEngine.GameObject obj, UnityEngine.Material crossSectionMaterial) [0x00019] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\Scripts\ImportedScripts\SlicerRealTimeMod.cs:25
at ShellCreator+c__Iterator0.MoveNext () [0x00035] in C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\Scripts\ShellCreator.cs:41
at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00028] in /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17
UnityEngine.MonoBehaviour:StartCoroutine_Auto_Internal(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/MonoBehaviourBindings.gen.cs:63)
ShellCreator:startShellCreator(GameObject) (at C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\Scripts\ShellCreator.cs:37)
SourceCubeController:OnPointerExit(PointerEventData) (at C:\Users\Mani\Documents\BeatSaberCloneMobile\Assets\Scripts\SourceCubeController.cs:64)
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerExitHandler, BaseEventData) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:29)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:261)
UnityEngine.EventSystems.BaseInputModule:HandlePointerExitAndEnter(PointerEventData, GameObject) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\BaseInputModule.cs:136)
UnityEngine.EventSystems.PointerInputModule:ProcessMove(PointerEventData) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\PointerInputModule.cs:248)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:232)
UnityEngine.EventSystems.StandaloneInputModule:Process() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:211)
UnityEngine.EventSystems.EventSystem:Update() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\EventSystem.cs:294)
(Filename: C Line: 0)
anyone able to help me? designing a beat saber clone and this happens around second or third. this issue is 100% coming from the mesh slice. im using https://github.com/DavidArayan/ezy-slice which should support mobile. works on pc version fine. i have change materials and shaders with same result. thanks btw this is for oculus quest
https://www.facebook.com/mike.donovan.5836711/videos/1127587397610188/
`using EzySlice;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Slice_Eg : MonoBehaviour
{
public GameObject plane1,plane2;
// Start is called before the first frame update
public GameObject objectToSlice; // non-null
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void slice_go_on_Click()
{
GameObject[] first_sliced = Slice(plane2.transform.position, plane2.transform.up);
}
/**
* Example on how to slice a GameObject in world coordinates.
*/
public GameObject[] Slice(Vector3 planeWorldPosition, Vector3 planeWorldDirection)
{
return objectToSlice.SliceInstantiate(planeWorldPosition, planeWorldDirection);
}
}
`
I came into a doubt, Is it really necessary to create a hull when the plane is not cutting the game object,
What I am trying to say for example the cutting plane is entirely above the game object to be cut and is parallel to the game object, In this case, I am thinking the cutting is really not necessary because of there is no intersection between plane and game object but In your algorithm, the lower shell is being created automatically.The same goes for when the plane is entirely below and parallel to the game object.
Is there any case where you require this behaviour?
In both these cases, I think there is no need for cutting.It's just a doubt.
Currently the slicer will duplicate all vertices (including the triangles which fail an intersection). This has been done for performance and code readability reasons. There is an opportunity to optimize this section of the code to ensure that sliced mesh output has minimal duplicated vertices.
As an addition can have a look to see if sliced triangles can also share vertices, however this would require some expensive checks/sorts which could hinder performance. May add it as an optional feature instead of making it part of the core slicer.
If the object is not scaled in a uniform way (e.g scaleX, scaleY, and scaleZ are different) then the slicing is not correct.
How to reproduce:
SliceDebugScene
from https://github.com/DavidArayan/EzySlice-Example-ScenesObjectToSlice
in the editor from (10, 10, 10)
to (10, 50, 10)
for exampleSlicerPlane
field and click Cut Object
Lower_Hull
and Upper_Hull
)I see a slicer script and another sliced hull script, the problem is how to use them in my game I am trying to cut the cubes as shown in this [https://www.youtube.com/watch?v=ZJVXeyXi8Ug] a beat saber game prototype and I am building that game for my mobile(not VR).The major requirements for my game are
1.)I need to slice the cube with my finger and the cubes will be cut in an unequal way i.e., It cuts where I cut them and the original cube is divided into two parts (one upper hull and one lower hull).
2.)When the Objects are sliced I need to attach a light to the edges of the cross-section of both upper and lower hulls of the original cube.
My doubt is how one has to use your scripts to achieve this? What I am really asking is please tell me a detailed step by step process of achieving at least the cutting behaviour (1.)
It would be nice if instead of creating a new material on every cut the entire mesh shared the same material and cut faces could simply be mapped to a select portion of the texture instead. (0.5 , 0.5 would map the cut face UVs to the bottom right quadrant of the texture for example). As it stands repeatedly cutting a mesh creates a big material array because of all the submeshes, and Unity is throwing some errors because of that.
The game crashes when slicing is attempted. Doesnt seem to be a RAM issue because i tested on IPhone XR, it crashes. But it doesnt crash on IPhone 5C. Do you have any idea on the possible issues of the crash?
From the XCode Debug Log, error EXC_BAD_ACCESS happens when i do the slicing.
I've tried unticking Auto Graphics API, removing Metal from the Graphics API but it's still not working currently.
The following happens when attempting to slice the plane using the following parameters. Slice produces artefacts (left of the grey line). https://imgur.com/a/CGMr5Wx
Can this be used in realtime?
If so, could you do an example scene of how to do so?
Thanks!
Scenario: I have a bunch of meshes making up a model and so I want to cut them all on the same plane. Some of the meshes won't be cut, but I just get a null result.
It would be nice if I could determine from the result if the mesh is entirely on the upper or lower side. Then I can group all the new cut upper side meshes together with the uncut upper side meshes and so forth.
Breaking API change idea: For .SliceImmediate that returns two GameObjects, it could return null and the original GameObject. Which GameObject is null or the original depends on the side the mesh is on. Probably should not use the same function signature though since existing code would be broken by this.
For .Slice which returns a SlicedHull, it would be nice to have some properties on the SlicedHull to tell me whether the hull will be sliced and if not which side the mesh lies on would be nice (HullSide.Bisect, HullSide.Upper, HullSide.Lower?). The Create functions returning null or the original gameobject as above would be useful as well. Though again, probably shouldn't use the same function signature. An additional boolean flag on the function call may be the way to do it maybe?
[Package Manager Window] Cannot perform upm operation: Unable to add package [https://github.com/DavidArayan/ezy-slice.git]:
[https://github.com/DavidArayan/ezy-slice.git] does not point to a valid package. No package manifest was found. [NotFound].
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
First I had an error about git not installed on windows, now I have this error, seems it is coming from the git repository ?
Thanks for further help
Slicing a sphere created with Unity's right click>3D Object>Sphere, with identity transform with planeWorldPosition = Vector3.zero
and planeWorldDirection = Vector3.right
results in hemisphere meshes with holes.
When I rotate the sphere 5 degrees along the y axis, it doesn't happen.
This happens in master at commit b93d68c Unity Version 2019.3.5f1 (d691e07d38ef) Personal
This doesn't happen on release 1.0.0
Script used for slicing:
using EzySlice;
using UnityEngine;
public class SliceOnClick : MonoBehaviour
{
public Material innerMaterial;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
Debug.Log("CUTTING");
if (this.Slice(Vector3.zero, Vector3.right) == null)
{
Debug.Log("FAILED");
}
Debug.Log("WORKED");
}
public GameObject[] Slice(Vector3 planeWorldPosition, Vector3 planeWorldDirection)
{
return this.gameObject.SliceInstantiate(planeWorldPosition, planeWorldDirection, CalculateCustomRegion(0, 0, 512, 512), this.innerMaterial);
}
public TextureRegion CalculateCustomRegion(int px, int py, int width, int height)
{
return this.innerMaterial.GetTextureRegion(px, py, width, height);
}
}
PD: Thank you for making this project!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.