PolygonMeshBuilder vs MeshBuilder.createPolygon

Hello everyone,
I want to add in my app square area calculations. I made a playground of it here: https://playground.babylonjs.com/#QNJLCY#18.

My problem starts when I want to move it to my angular application. How should I use PolygonMeshBuilder to work like MeshBuilder.CreatePolygon?

*edit it occurs my model is rotated 90 degrees in X-axis, but I guess that shouldnt be a problem

this is how it’s working in my app:

how it should work(like in playground):

This is how I make it in my app:

  createPolygon(polygon: Polygon, scene: Scene) {
    const { pointsMeshes } = polygon;

    //this is just array of clicked positions
    const spheresPositionsArr = pointsMeshes.map((e) => {
      return new Vector3(e.position.x, e.position.y, e.position.z);
    });

    const polygonMeshBuilder = new PolygonMeshBuilder(
      "polygonMeshBuilder",
      spheresPositionsArr,
      scene,
      MyEarcut
    );

    const polygonMesh = polygonMeshBuilder.build();

    return polygonMesh;
  }

that can be a problem

1 Like

I managed to fix it.

I saw that polygonMeshBuilder contains an array of elements with x and y properties only:
image

so I changed the spheresPositionsArr which I give as an argument to PolygonMeshBuilder to:

    const spheresPositionsArr = pointsMeshes.map((e) => {
      return new Vector2(e.position.x, e.position.z);
    });
2 Likes