Creating A Box
Box
The created box has its origin at the center of the box, its width (x), height (y) and depth (z) are as given.
MeshBuilder
Usage :
import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";const box = MeshBuilder.CreateBox("box", options, scene); //scene is optional and defaults to the current scene| options property | value | default value |
|---|---|---|
| size | (number) size of each box side | 1 |
| height | (number) height size, overwrites size option | size |
| width | (number) width size, overwrites size option | size |
| depth | (number) depth size, overwrites size option | size |
| faceColors | (Color4[]) array of 6 Color4, one per box face | Color4(1, 1, 1, 1) for each side |
| faceUV | (Vector4[]) array of 6 Vector4, one per box face | UVs(0, 0, 1, 1) for each side |
| wrap | (boolean) (BJS 4.0 or >) when true, all vertical sides (0, 1, 2, 3) apply image textures upright | false |
| topBaseAt | (number) (BJS 4.0 or >) the base of the top touches the side given by 0, 1, 2, or 3 | 1 |
| bottomBaseAt | (number) (BJS 4.0 or >) the base of the bottom touches the side given by 0, 1, 2, or 3 | 0 |
| updatable | (boolean) true if the mesh is updatable | false |
| sideOrientation | (number) side orientation | DEFAULTSIDE |
| frontUVs | (Vector4) ONLY WHEN sideOrientation:BABYLON.Mesh.DOUBLESIDE set | Vector4(0,0, 1,1) |
| backUVs | (Vector4) ONLY WHEN sideOrientation:BABYLON.Mesh.DOUBLESIDE set | Vector4(0,0, 1,1) |
Examples
Cuboid: Create a Cuboid Face numbers, face 0 is on the positive z axis: Create a Box With Face Numbers
Mesh
Usage
import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";const box = MeshBuilder.CreateBox("box", { size, updatable, sideOrientation }, scene);It is only possible to create a cube with this method; for a cuboid, you need to use scaling.