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 way to fill the polygon with triangles, and an Earcut method is used. Although 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 from the 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 :
import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";const extrudedPolygon = MeshBuilder.ExtrudePolygon("polygon", options, scene); //scene is optional and defaults to the current scene| option | value | default value |
|---|---|---|
| shape | (Vector3[]) array of Vector3, the shape you want to turn REQUIRED | |
| depth | (number) the depth of the extrusion REQUIRED | |
| faceColors | (Color4[]) array of 3 Color4, one per box face | Color4(1, 1, 1, 1) for each side |
| faceUV | (Vector4[]) array of 3 Vector4, one per box face | UVs(0, 0, 1, 1) for each side |
| wrap | (boolean) maps texture to sides with faceUV[1] when false texture mapped to each individual side, when true wrapped over all sides | false |
| holes | (Vector3[][]) array of holes, each hole being an array of successive Vector3 | [] |
| updatable | (boolean) true if the mesh is updatable | false |
| sideOrientation | (number) side orientation | DEFAULTSIDE |
All vectors for shape and holes are Vector3 and should be in the xz plane, i.e. 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
import { Mesh } from "@babylonjs/core/Meshes/mesh";let polygon = Mesh.CreatePolygon("polygon", shape, depth, scene);let polygon = Mesh.CreatePolygon("polygon", shape, depth, scene, holes, updatable, sideOrientation); //optional parameters after scene