Skip to content

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

Open

Description

@davl3232

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!

Activity

  1. self-assigned this
    on May 19, 2020
  2. DavidArayan commented on May 19, 2020

    @DavidArayan
    Owner

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

  3. pruebasssaa commented on May 28, 2020

    @pruebasssaa

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

  4. PurpleSlayerFish commented on Feb 21, 2022

    @PurpleSlayerFish

    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

  5. michail-p commented on Jul 6, 2023

    @michail-p

    anyone fixed this?

  6. XaHDpE commented on May 14, 2024

    @XaHDpE

    Anybody?)

  7. evgenykralko commented on Mar 14, 2025

    @evgenykralko

    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

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions