PolygonMeshBuilder and Meshbuilder not working

Morning all,

I’m experimenting building meshes programmatically and whilst the playground examples from the documentation seem straight forward I am finding that even with small changes I am not getting the behavior I expect.

For example:

The linked playground is based on a number of examples from the documentation but whilst the BABYLON.MeshBuilder.CreateLines method works and the lines appear as I would expect. Trying to turn this into a face and/or then an extrude using either BABYLON.PolygonMeshBuilder or BABYLON.MeshBuilder.ExtrudePolygon doesn’t seem to do anything. In the playground nothing renders and when running directly in the browser using a local webserver the screen just turns white which suggests I’m not implementing correctly.

I’m sure this is quite straight forward but I’m not sure what to try next as I think I’m using the syntax from the examples correctly?

Best,
Sy

Hi,

I think that’s because your shape is not in the XZ plane. The y coordinate must be equal to 0
I made this playground to explain you with a depth of 100

Here’s the link to the docs that explains

Good luck :wink:

1 Like

Thanks for this - so you can only extrude in the Y direction? That seems pretty limiting? Is there any way to specify a path direction that is not Y with the polygon on any plane?

For example, on mesh might be drawn on XZ and extruded in Y but another might be drawn on XY and extruded in Z?

Thanks for you assistance with this.

best,
Sy

This PG shows difference between CreateLines, PolygonMeshBuilder and Create and Extrude Polygon

Yes there is

However you can only use the cap parameter successfully with a convex polygon

You could use ExtrudePolygon and then rotate the mesh to match the direction you want. You can use

to match the rotation needed.

1 Like

Hello,

Thanks for the feedback. I believe I understand the concept now and it appears that this is more a limitation in how the meshes are constructed as opposed to anything else.

I believe the following PG will demonstrate my understanding better.

In this case a simple square is drawn on each plane, XY, YZ and XZ and then closed. These squares plot as expected.

For each square a subsequent path is defined which is essentially normal to the plane the square is drawn on.

If I extrude each shape along each path my expected behavior would be a final render of 3 cubes which are coincident about the origin (0,0,0) This is not the behavior produced. However, from your explanations I can see why it is rendering the way it is in the PG.

The final geometry I wish to produce involves a lot of shapes being drawn on different planes, extruded normal to those plans and booleaned to each other. Unless there is someway to achieve the behavior I describe I think it will be too complicated drawing everything on XY and then translating/rotating to suit. In this instance I may be better drawing what I need in a CAD package and then using STL exports instead. The downside to this is that my final geometry will be “dead” as opposed to parametric if I could have drawn it live in Babylon.

Thanks.

It is about how you choose the points relative to the origin

However with concave shapes there would be a problem with the end planes or caps

2 Likes

Hello @insidef1 just checking in, was your question answered? :slight_smile: