Search Unity

How do I use the ProBuilder API to create an object with a hole?

Discussion in 'World Building' started by Alxander_Watson, Jul 28, 2022.

  1. Alxander_Watson

    Alxander_Watson

    Joined:
    Mar 11, 2017
    Posts:
    16
    Hello

    I'm trying to understand how to use the CreateShapeFromPolygon function to create 3D objects with holes.

    I wrote this:
    Code (CSharp):
    1. List<Vector3> tempControlPoints = new List<Vector3>();
    2. tempControlPoints.Add(new Vector3(-0.5f, -0.5f, 0));
    3. tempControlPoints.Add(new Vector3(0.5f, 0.5f, 0));
    4. tempControlPoints.Add(new Vector3(0.5f, -0.5f, 0));
    5. tempControlPoints.Add(new Vector3(-0.5f, 0.5f, 0));
    6.  
    7. IList<IList<Vector3>> tempHolePoints = new List<IList<Vector3>>();
    8. tempHolePoints.Add(new List<Vector3>());
    9. tempHolePoints[0].Add(new Vector3(-0.25f, -0.25f, 0));
    10. tempHolePoints[0].Add(new Vector3(0.25f, 0.25f, 0));
    11. tempHolePoints[0].Add(new Vector3(0.25f, -0.25f, 0));
    12. tempHolePoints[0].Add(new Vector3(-0.25f, 0.25f, 0));
    13.  
    14. ProBuilderMesh mesh = ProBuilderMesh.Create();
    15.  
    16. Debug.Log(mesh.CreateShapeFromPolygon(tempControlPoints, 1, false, tempHolePoints).status);
    17.  
    18. mesh.ToMesh();
    19. mesh.Refresh();
    I was expecting a cube with a square hole. But the Action result status is always a failure.

    Where am I going wrong?