Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slicing Unity's sphere results in meshes with uncovered holes #36

Open
davl3232 opened this issue May 19, 2020 · 6 comments
Open

Slicing Unity's sphere results in meshes with uncovered holes #36

davl3232 opened this issue May 19, 2020 · 6 comments
Assignees
Labels

Comments

@davl3232
Copy link

davl3232 commented May 19, 2020

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!

@DavidArayan DavidArayan self-assigned this May 19, 2020
@DavidArayan
Copy link
Owner

Thank you for the bug report and extensive information! I will investigate to see whats going on.

@pruebasssaa
Copy link

I also have this problem, it doesn't happen with threading branch. Check the List<Vector3> intPoints and with the same model, the master branch has a count of 0. It mainly happens with complex geometry.

It may also be processing well, but you have forgotten to place a material. That is, not even this slot is available in the MeshRenderer, only 1, (the visible material).

@PurpleSlayerFish
Copy link

PurpleSlayerFish commented Feb 21, 2022

Hey, guys.
I also have the same problem and i found the reason, why this happens.
@DavidArayan, Maybe it will help you fix them.
This happens, when cutting plane exactly crosses one or more vertexes of a mesh.
For example, i have a fruit cutting game, and i replaced my mesh with unity standard primitive cube. I turned my cube mesh to 45 degrees and set cutting plane position exactly in the middle of a cube just like on screenshot.
And i sliced this.

UP: i use last framework version with my Unity 2020.3.1f1
UP2: We love your framework so much, David.
image
image
image
image

@random-dev0
Copy link

anyone fixed this?

@XaHDpE
Copy link

XaHDpE commented May 14, 2024

Anybody?)

@evgenykralko
Copy link

evgenykralko commented Mar 14, 2025

This happens when one of the vertices is exactly on the plane. I faced the same issue and fixed it by changing the logic a little bit. When first vertice is on the plane, check second and third vertice as well to make the right decision
Image
EzySlice/Slicer.cs

else {
	SideOfPlane side0 = pl.SideOf(verts[i0]);
	bool up = side0 == SideOfPlane.ON 
		? pl.SideOf(verts[i1]) == SideOfPlane.UP || pl.SideOf(verts[i2]) == SideOfPlane.UP 
		: side0 == SideOfPlane.UP;

	if (up) {
		mesh.upperHull.Add(newTri);
	}
	else {
		mesh.lowerHull.Add(newTri);
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants