Search Unity

Question Creating/Rebuilding ProBuilder Poly Shapes using a Vector3 array.

Discussion in 'World Building' started by theBuilder10000, Aug 13, 2022.

  1. theBuilder10000


    Jul 30, 2016
    I'm creating a game that utilizes real world geographic data from open street maps, including subdivision boundaries. I've exported boundary points into a Vector3[] format, and ProBuilder Poly Shapes seems like the best way to create the shapes I need. I want to know if there's a way to create the poly shapes at runtime or rebuild an existing poly shape so it uses the Vector3 array. I've gotten the Vector3 array into the existing Poly Shape component, but the change is not reflected in the Mesh Filter component. I'm just not sure if it's possible to redo the shape creation process at runtime, nor if there is a function that instantiates the Poly Shape.

    Code (CSharp):
    2.     public string name;
    3.     public Vector2 center;
    4.     public Vector2[] boundaryPoints;
    5.     public Vector3[] boundaryPoints3D;
    6.     public ProBuilderMesh countyMesh;
    7.     public PolyShape countyPoly;
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         for (int i = 0; i < boundaryPoints.Length - 1; i++)
    13.         {
    14.             boundaryPoints3D[i].x = boundaryPoints[i].x;
    15.             boundaryPoints3D[i].z = boundaryPoints[i].y;
    16.         }
    18.         List<Vector3> boundaryPointsList = new List<Vector3>();
    19.         boundaryPointsList.AddRange(boundaryPoints3D);
    20.         countyPoly.m_Points = boundaryPointsList;
    21.         countyPoly.SetControlPoints(boundaryPointsList);
    22.         countyMesh.CreateShapeFromPolygon(boundaryPointsList,1,false);
    23.         countyMesh.ToMesh();
    24.         countyMesh.Refresh();
    25.         */
    26.     }
    The Poly Shape I created using the normal edit mode.

    The Inspector for the Poly Shape before running my script.

    The Poly Shape inspector after running my script.

    The intended shape of the polygon indicated by a Polygon Collider 2D, with a total of 44 points.

    Fixing this issue would really help me streamline this whole process, so any help or suggestions is greatly appreciated.