Giter Site home page Giter Site logo

ezy-slice's Introduction

EzySlice Logo

Twitter: @DavidArayan Join the chat at https://gitter.im/ezyframeworks/ezyslice License Codacy Badge


Open Source Slicer Framework for the Unity3D Game Engine

  • Ability to slice any convex Mesh using a Plane
  • UV/Normal/Tangent Space Interpolation for seamless cuts
  • Flexible and Documented API
  • No external plugin dependencies, fully written in C#
  • Updated for Unity3D 2018
  • MIT Open Source License

Algorithms in use

  • General purpose Monotone Chain for cross section triangulation for Convex slices
  • Barycentric Coordinates for UV/Normal/Tangent space Interpolation
  • Purpose built Triangle to Plane intersection to cover all general cases for slicing
  • Designed with performance in mind

Contributions and Bug Reports

  • Contributions are always welcome and highly appreciated! please use pull request.
  • Bugs, Comments, General Enquiries and Feature Requests please use the Issue Tracker

Example Projects


Usage Examples

Getting started with EzySlice is easy. Below you will find sample usage functions. EzySlice uses extension methods to hide most of the internal complexity.

  • The examples below will slice a GameObject and return SlicedHull object. SlicedHull has functionality for generating the final GameObjects for rendering. An additional API exists to generate the GameObjects automatically without any additional work required.
  • All functions will return null if slicing fails.
SlicedHull Example
public GameObject objectToSlice; // non-null

/**
 * Example on how to slice a GameObject in world coordinates.
 */
public SlicedHull Slice(Vector3 planeWorldPosition, Vector3 planeWorldDirection) {
	return objectToSlice.Slice(planeWorldPosition, planeWorldDirection);
}
Direct Instantiated Example
public GameObject objectToSlice; // non-null

/**
 * Example on how to slice a GameObject in world coordinates.
 */
public GameObject[] Slice(Vector3 planeWorldPosition, Vector3 planeWorldDirection) {
	return objectToSlice.SliceInstantiate(planeWorldPosition, planeWorldDirection);
}
  • A custom TextureRegion can be defined to map the final UV coordinates of the cross-section. TextureRegion is essentially a reference to a specific part of a texture in UV coordinate space. This can be useful if single materials are used repeatedly as atlasses.
SlicedHull Example
public GameObject objectToSlice; // non-null

/**
 * Example on how to slice a GameObject in world coordinates.
 * Uses a custom TextureRegion to offset the UV coordinates of the cross-section
 */
public SlicedHull Slice(Vector3 planeWorldPosition, Vector3 planeWorldDirection, TextureRegion region) {
	return objectToSlice.Slice(planeWorldPosition, planeWorldDirection, region);
}
Direct Instantiated Example
public GameObject objectToSlice; // non-null

/**
 * Example on how to slice a GameObject in world coordinates.
 * Uses a custom TextureRegion to offset the UV coordinates of the cross-section
 */
public GameObject[] Slice(Vector3 planeWorldPosition, Vector3 planeWorldDirection, TextureRegion region) {
	return objectToSlice.SliceInstantiate(planeWorldPosition, planeWorldDirection, region);
}
  • There are cases where supplying the material directly can have performance benefits. In the previous examples, the Slicer will simply create the cross section as a submesh which will allow adding the Material externally when the GameObject is created. By supplying the Material directly, this will allow the Slicer to potentially batch the final results instead of creating repeated submeshes.
SlicedHull Example
public GameObject objectToSlice; // non-null
public Material crossSectionMaterial; // non-null

/**
 * Example on how to slice a GameObject in world coordinates.
 * Uses a custom TextureRegion to offset the UV coordinates of the cross-section
 * Uses a custom Material
 */
public SlicedHull Slice(Vector3 planeWorldPosition, Vector3 planeWorldDirection, TextureRegion region) {
	return objectToSlice.Slice(planeWorldPosition, planeWorldDirection, region, crossSectionMaterial);
}
Direct Instantiated Example
public GameObject objectToSlice; // non-null
public Material crossSectionMaterial; // non-null

/**
 * Example on how to slice a GameObject in world coordinates.
 * Uses a custom TextureRegion to offset the UV coordinates of the cross-section
 * Uses a custom Material
 */
public GameObject[] Slice(Vector3 planeWorldPosition, Vector3 planeWorldDirection, TextureRegion region) {
	return objectToSlice.SliceInstantiate(planeWorldPosition, planeWorldDirection, region, crossSectionMaterial);
}
  • Below is a sample on how to generate a TextureRegion. TextureRegion is stored in UV Coordinate space and is a reference to a specific region of a texture.
Using a Texture
/**
 * Example on how to calculate a custom TextureRegion to reference a different part of a texture
 * 
 * px -> The start X Position in Pixel Coordinates
 * py -> The start Y Position in Pixel Coordinates
 * width -> The width of the texture in Pixel Coordinates
 * height -> The height of the texture in Pixel Coordinates
 */
public TextureRegion CalculateCustomRegion(Texture myTexture, int px, int py, int width, int height) {
	return myTexture.GetTextureRegion(px, py, width, height);
}
Using a Material
/**
 * Example on how to calculate a custom TextureRegion to reference a different part of a texture
 * This example will use the mainTexture component of a Material
 * 
 * px -> The start X Position in Pixel Coordinates
 * py -> The start Y Position in Pixel Coordinates
 * width -> The width of the texture in Pixel Coordinates
 * height -> The height of the texture in Pixel Coordinates
 */
public TextureRegion CalculateCustomRegion(Material myMaterial, int px, int py, int width, int height) {
	return myMaterial.GetTextureRegion(px, py, width, height);
}

ezy-slice's People

Contributors

andrewcarvalho avatar codacy-badger avatar davidarayan avatar jichael avatar ozkitsune avatar slimeq avatar smitdylan2001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ezy-slice's Issues

- Failure to cut very small triangles

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.

How to test an example project?

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?

Possible to change plane to something else?

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!

Doesn't work for more complex objects

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:

Screenshot 2021-02-08 at 12 13 28

I have uploaded the 3d model here:

toast.zip

Thank you for your help!

[Feature] - Reduce the amount of duplicate vertices

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.

  1. Change the Convex Triangulator to output Triangles in such a way that the vertices are shared instead of duplicated.
  2. Change the slicer so that triangles which fail an intersection test (fail to cut) will not have vertices needlessly duplicated.

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.

Randomly doesn't slice (this could well be user error)

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.

Cross sections are created incorrectly if corner of cross section doesn't intersect with outer mesh

Here's a few pictures of what I'm talking about.

crosssectionissueexample
crosssectionissueexample2
crosssectionissueexample3

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.

Realtime usage?

Can this be used in realtime?

If so, could you do an example scene of how to do so?

Thanks!

The Pivot and center points of the hull are wrong

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?

[FEATURE] - Add an optional multi-threading API

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..

  • The multi-threaded API should be easy to use (prefer to have a single function call with a callback if possible). The main application should NOT care about the internal workings.
  • Investigate into slicing large/complex objects simultaneously. Benchmark against single threaded slicing.
  • Investigate into slicing small objects simultaneously. Benchmark against single threaded slicing.
  • Look into using Thread pools to conserve performance for multiple slice jobs.
  • Look into offloading Plane->Triangle slicing as a separate threaded job into a queue (instead of entire slicing jobs), what the performance implications are and if it's worth doing.
  • Look into benchmarking memory usage and come up with a guideline on when to use/not use the threaded api.

Floating point error causing artefacts.

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

  • Mesh Verts: { Vector3.zero, Vector3.right * -5, Vector3.forward*5, new Vector3(-5, 0, 5)}
  • Mesh Triangles: { 0, 1, 2, 1, 3, 2 }
  • Mesh Position: (32.8732147216797f, 0.00100000004749745f, 47.9289321899414f)
  • Slice Position: (32.8732147216797f, 0, 50)
  • Slice Direction: (0.353553384542465f, 0, -0.853553414344788f)

Get the intersection points

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!

Odd results

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?

Holes in mesh after cutting

Hi,
The problem I'm facing currently is: after I cut my object, some of the mesh is missing and there are some "holes" in the object.
Here is the uncut object:
uncutobject
Here is the cut object:
cutobject
Here is another example:
cutobject2

Lost

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 πŸ™πŸ™πŸ™πŸ™

Can you help me how to use this together with unity ?

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.)

Can't download the project through unity git system.

[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

Array Index Is Out Of Range

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.

Apply to Animated Model?

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!

[FEATURE] - Generate proper Normals and Tangents from the original mesh

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.

  • Look into using normals and tangents from the original mesh to ensure the cut mesh renders properly
  • Ensure the generated normals and tangents work properly with the generated cross section

When cutting a complex mesh, the face does not respect the geometry

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)
error2
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

Ezyslice crashes on IOS.

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.

A little help on Slicing an object.

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!

Unexpected hole patching after slice

Here is a custom model that i used in the example SliceDebugScreen, after cutting, the part results as in the image :

MicrosoftTeams-image (1)
MicrosoftTeams-image

it looks like that something went wrong after patching the hole after cutting, any advise how to solve this?

[Feature] World Space Slicing

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.

Ezy Slice - imported objects don't get sliced

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!
slice_error

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

Script Doesn't Link To Editor

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?

After slicing the game object the original prefab holes are closed , the region is filled? i wanted to know if we can retain the original holes in the obj after slicing the game object ?

`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);
}

}
`

Null Reference exception when game is played in android

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)

Only creating necessary Hulls?

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.

[Feature] Single Material

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.

[FEATURE] - Add Concave cross-section triangulation

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.

Slicing Unity's sphere results in meshes with uncovered holes

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.

image

When I rotate the sphere 5 degrees along the y axis, it doesn't happen.

image

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!

[Feature] - Submesh Material batching when slicing

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.

The name 'Normal' does not exist in the current context

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
}`

If a mesh does not intersect the cutting plane it would be nice if I was told if it was on the upper or lower side.

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.