Bitbybit Docs
    Preparing search index...

    Class BabylonMeshBuilder

    BabylonJS's own mesh primitives, built straight into the scene as ready-to-render meshes rather than through a CAD kernel: boxes, spheres, discs, tori, polygons, tubes, polyhedra, capsules, cylinders, extrusions, ribbons, lathes and grounds. They are quick to make and cheap to draw but carry no exact geometry, so use the kernels when the shape must be measured, cut or exported. Every builder centers its mesh on the origin, sets sideOrientation and registers it for shadows unless enableShadows is false.

    Index

    Constructors

    create simple

    • Builds a box centered on the origin with width along X, height along Y and depth along Z.

      Parameters

      • inputs: CreateBoxDto

        The three sizes, the side orientation and the shadow flag

      Returns Mesh

      The box mesh

      const box = bitbybit.babylon.meshBuilder.createBox({ width: 10, height: 5, depth: 20, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.frontside, enableShadows: true });
      
    • Builds a cube centered on the origin with every edge size long.

      Parameters

      • inputs: CreateCubeDto

        The edge length, the side orientation and the shadow flag

      Returns Mesh

      The cube mesh

      const cube = bitbybit.babylon.meshBuilder.createCube({ size: 10, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.frontside, enableShadows: true });
      
    • Builds a flat square of side size centered on the origin in the XY plane, facing the Z axis; a single-sided plane is invisible from behind unless sideOrientation is double-sided.

      Parameters

      Returns Mesh

      The plane mesh

      const plane = bitbybit.babylon.meshBuilder.createSquarePlane({ size: 10, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Builds a sphere of the given diameter centered on the origin; segments sets how finely it is divided, more being rounder and heavier.

      Parameters

      • inputs: CreateSphereDto

        The diameter, the segment count, the side orientation and the shadow flag

      Returns Mesh

      The sphere mesh

      const ball = bitbybit.babylon.meshBuilder.createSphere({ diameter: 10, segments: 32, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.frontside, enableShadows: true });
      
    • Builds a sphere from evenly sized triangles, subdivided from an icosahedron, which shades more evenly than createSphere.

      radiusX, radiusY and radiusZ stretch it per axis and fall back to radius when 0; flat gives faceted shading.

      Parameters

      • inputs: CreateIcoSphereDto

        The radii, the flat flag, the subdivisions, the side orientation and the shadow flag

      Returns Mesh

      The ico sphere mesh

      const ball = bitbybit.babylon.meshBuilder.createIcoSphere({ radius: 5, radiusX: 0, radiusY: 0, radiusZ: 0, flat: false, subdivisions: 4, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.frontside, enableShadows: true });
      
    • Builds a flat disc of the given radius centered on the origin in the XY plane; arc below 1 leaves a pie slice, so 0.5 is a half disc.

      Parameters

      • inputs: CreateDiscDto

        The radius, the tessellation, the arc fraction, the side orientation and the shadow flag

      Returns Mesh

      The disc mesh

      const disc = bitbybit.babylon.meshBuilder.createDisc({ radius: 5, tessellation: 32, arc: 1, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Builds a ring lying in the XZ plane around the origin: diameter is the ring's overall diameter and thickness the diameter of its tube.

      Parameters

      • inputs: CreateTorusDto

        The diameter, the tube thickness, the tessellation, the side orientation and the shadow flag

      Returns Mesh

      The torus mesh

      const ring = bitbybit.babylon.meshBuilder.createTorus({ diameter: 10, thickness: 2, tessellation: 32, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.frontside, enableShadows: true });
      
    • Builds a tube wound into a knot around the origin: p and q are how many times it winds around the ring and through its hole, so 2 and 3 give the classic trefoil.

      Parameters

      • inputs: CreateTorusKnotDto

        The radius, the tube radius, the segment counts, the winding numbers, the side orientation and the shadow flag

      Returns Mesh

      The torus knot mesh

      const knot = bitbybit.babylon.meshBuilder.createTorusKnot({ radius: 5, tube: 1, radialSegments: 128, tubularSegments: 32, p: 2, q: 3, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.frontside, enableShadows: true });
      
    • Builds a flat filled polygon from its outline points, with optional holes, lying in the XZ plane; a depth above 0 gives it thickness downward.

      The points are 3D but only X and Z are used, and the outline must not cross itself.

      Parameters

      • inputs: CreatePolygonDto

        The outline, the holes, the depth, the smoothing, the side orientation, the wrap flag and the shadow flag

      Returns Mesh

      The polygon mesh

      const slab = bitbybit.babylon.meshBuilder.createPolygon({ shape: [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]], holes: [], depth: 0, smoothingThreshold: 0.01, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, wrap: false, enableShadows: true });
      
    • Builds a solid by extruding a flat polygon, given by its outline points in the XZ plane with optional holes, downward by depth.

      Parameters

      • inputs: ExtrudePolygonDto

        The outline, the holes, the depth, the side orientation, the wrap flag and the shadow flag

      Returns Mesh

      The extruded mesh

      const block = bitbybit.babylon.meshBuilder.extrudePolygon({ shape: [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]], holes: [[[3, 0, 3], [7, 0, 3], [7, 0, 7], [3, 0, 7]]], depth: 5, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.frontside, wrap: false, enableShadows: true });
      
    • Builds a tube of the given radius along a path of points; cap closes neither, one or both ends, and arc below 1 leaves the tube open along its length.

      Parameters

      • inputs: CreateTubeDto

        The path, the radius, the tessellation, the cap mode, the arc fraction, the side orientation and the shadow flag

      Returns Mesh

      The tube mesh

      const pipe = bitbybit.babylon.meshBuilder.createTube({ path: [[0, 0, 0], [10, 0, 0], [10, 10, 0]], radius: 1, tessellation: 32, cap: 3, arc: 1, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Builds one of the fifteen built-in polyhedra by type, from tetrahedron (0) to elongated pentagonal cupola (14), or your own from custom data.

      sizeX, sizeY and sizeZ stretch it per axis and fall back to size when 0; flat gives faceted shading.

      Parameters

      • inputs: CreatePolyhedronDto

        The size and type, the custom data, the flat flag, the side orientation and the shadow flag

      Returns Mesh

      The polyhedron mesh

      const dodecahedron = bitbybit.babylon.meshBuilder.createPolyhedron({ size: 5, type: 2, sizeX: 0, sizeY: 0, sizeZ: 0, flat: true, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.frontside, enableShadows: true });
      
    • Builds a geodesic sphere, an icosahedron whose faces are subdivided into triangles as m and n say, so the surface is made of near-equal triangles.

      sizeX, sizeY and sizeZ stretch it per axis and fall back to size when 0.

      Parameters

      • inputs: CreateGeodesicDto

        The subdivision numbers, the sizes, the flat flag, the side orientation and the shadow flag

      Returns Mesh

      The geodesic mesh

      const dome = bitbybit.babylon.meshBuilder.createGeodesic({ m: 4, n: 4, size: 5, sizeX: 0, sizeY: 0, sizeZ: 0, flat: false, subdivisions: 4, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.frontside, enableShadows: true });
      
    • Builds a Goldberg polyhedron, a ball made of hexagons and twelve pentagons like a football, with m and n setting how many hexagons there are.

      sizeX, sizeY and sizeZ stretch it per axis and fall back to size when 0.

      Parameters

      • inputs: CreateGoldbergDto

        The subdivision numbers, the sizes, the side orientation and the shadow flag

      Returns Mesh

      The Goldberg mesh

      const ball = bitbybit.babylon.meshBuilder.createGoldberg({ m: 4, n: 4, size: 5, sizeX: 0, sizeY: 0, sizeZ: 0, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Builds a capsule, a cylinder with rounded ends, of the given height and radius along orientation; radiusTop and radiusBottom size the two ends separately.

      Parameters

      • inputs: CreateCapsuleDto

        The orientation, the sizes, the subdivision counts, the side orientation and the shadow flag

      Returns Mesh

      The capsule mesh

      const pill = bitbybit.babylon.meshBuilder.createCapsule({ orientation: [0, 1, 0], subdivisions: 2, tessellation: 16, height: 10, radius: 2, capSubdivisions: 6, radiusTop: 2, radiusBottom: 2, topCapSubdivisions: 6, bottomCapSubdivisions: 6, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Builds a cylinder standing along Y, centered on the origin; different top and bottom diameters make a cone or a taper, and 0 closes an end to a point.

      Parameters

      • inputs: CreateCylinderDto

        The height, the two diameters, the tessellation, the subdivisions, the side orientation and the shadow flag

      Returns Mesh

      The cylinder mesh

      const cone = bitbybit.babylon.meshBuilder.createCylinder({ height: 10, diameterTop: 0, diameterBottom: 6, tessellation: 64, subdivisions: 1, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Sweeps a profile along a path: shape is the profile as points in the XY plane and path the points it travels through, with scale and rotation in radians applied step by step along the way.

      closeShape joins the profile's ends, closePath joins the path's, and cap closes neither, one or both ends.

      Parameters

      • inputs: CreateExtrudedShapeDto

        The profile, the path, the scale, the rotation per step, the closing flags, the cap mode, the side orientation and the shadow flag

      Returns Mesh

      The swept mesh

      const rail = bitbybit.babylon.meshBuilder.createExtrudedSahpe({ shape: [[-1, 0, 0], [1, 0, 0], [1, 1, 0], [-1, 1, 0]], path: [[0, 0, 0], [10, 0, 0], [10, 0, 10]], scale: 1, rotation: 0, closeShape: true, closePath: false, cap: 3, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Builds a surface through several paths of points, joining neighboring paths with triangles, like cloth stretched over a set of lines.

      closePath joins each path's ends, closeArray joins the last path back to the first, and offset shifts how points pair up when only one path is given.

      Parameters

      • inputs: CreateRibbonDto

        The paths, the closing flags, the offset, the updatable flag, the side orientation and the shadow flag

      Returns Mesh

      The ribbon mesh

      const sheet = bitbybit.babylon.meshBuilder.createRibbon({ pathArray: [[[0, 0, 0], [10, 0, 0], [20, 0, 0]], [[0, 5, 5], [10, 5, 5], [20, 5, 5]]], closeArray: false, closePath: false, offset: 0, updatable: false, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Revolves a profile around the Y axis, the way a lathe turns wood: shape is the profile as points in the XY plane with X as the distance from the axis, radius pushes it outward, and arc below 1 leaves the revolution open.

      Parameters

      • inputs: CreateLatheDto

        The profile, the radius, the tessellation, the arc fraction, the closed flag, the side orientation and the shadow flag

      Returns Mesh

      The lathe mesh

      const vase = bitbybit.babylon.meshBuilder.createLathe({ shape: [[2, 0, 0], [3, 3, 0], [2, 6, 0], [2.5, 8, 0]], radius: 0, tessellation: 64, arc: 1, closed: true, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Builds a flat ground plane centered on the origin in the XZ plane, width along X and height along Z, divided into a grid of subdivisionsX by subdivisionsY cells.

      Parameters

      • inputs: CreateGroundDto

        The width, the height, the subdivisions, the side orientation and the shadow flag

      Returns Mesh

      The ground mesh

      const ground = bitbybit.babylon.meshBuilder.createGround({ width: 100, height: 100, subdivisionsX: 1, subdivisionsY: 1, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });
      
    • Builds a flat rectangle centered on the origin in the XY plane, width along X and height along Y, facing the Z axis.

      Parameters

      Returns Mesh

      The plane mesh

      const plane = bitbybit.babylon.meshBuilder.createRectanglePlane({ width: 20, height: 10, sideOrientation: Bit.Inputs.BabylonMesh.sideOrientationEnum.doubleside, enableShadows: true });