Irregular Polygon Extrusion
Extruded Non Regular Polygon
ExtrudePolygon adds a depth option to CreatePolygon. The extrusion is carried out down the vertical y axis from the polygon shape in the horizontal xz plane. Like CreatePolygon it requires an Earcut script. Since it can be concave it requires a procedure to fill the polygon with triangles and an Earcut method is used. Whilst an Earcut script is pre-loaded in the Playground you will have to add a reference to such a script in your own projects. One is available at cdn or via a npm package.
On creation the local origin of the extruded polygon is coincident with the world origin. It is not possible to give a position relative to the extruded polygon as this depends on the data sets used.
ExtrudePolygon calls PolygonMeshBuilder. There is no instance option. You must set at least the shape and depth options.
MeshBuilder
Usage :
const extrudedPolygon = BABYLON.MeshBuilder.ExtrudePolygon("polygon", options, scene); //scene is optional and defaults to the current scene
option | value | default value |
---|---|---|
option shape | value (Vector3[]) array of Vector3, the shape you want to turn REQUIRED | default value |
option depth | value (number) the depth of the extrusion REQUIRED | default value |
option faceColors | value (Color4[]) array of 3 Color4, one per box face | default value Color4(1, 1, 1, 1) for each side |
option faceUV | value (Vector4[]) array of 3 Vector4, one per box face | default value UVs(0, 0, 1, 1) for each side |
option wrap | value (boolean) maps texture to sides with faceUV[1] when false texture mapped to each individual side, when true wrapped over all sides | default value false |
option holes | value (Vector3[][]) array of holes, each hole being an array of successive Vector3 | default value [] |
option updatable | value (boolean) true if the mesh is updatable | default value false |
option sideOrientation | value (number) side orientation | default value DEFAULTSIDE |
All vectors for shape and holes are Vector3 and should be in the xz plane, ie of the form BABYLON.Vector3(x, 0, z) and in counter clockwise order;
Examples
Extruded Polygon: Extruding Irregular Polygons Extruded Polygons using faceUV, one with wrap, one without: Extruding Irregular Polygons Advanced
Mesh
let polygon = BABYLON.Mesh.CreatePolygon("polygon", shape, depth, scene);let polygon = BABYLON.Mesh.CreatePolygon("polygon", shape, depth, scene, holes, updatable, sideOrientation); //optional parameters after scene