BabylonJS mesh

BabylonJS is an open-source, robust JavaScript framework for creating and rendering 3D graphics and immersive experiences directly in web browsers.

Note: Learn more about BabylonJS.

Mesh

A mesh is essentially a collection of vertices, edges, and faces that define the shape of an object in a 3D scene.

Meshes are essential building blocks for creating complex 3D scenes and visualizations.

Syntax

The syntax for adding a mesh is as follows:

BABYLON.MeshBuilder.CreateMeshName(meshType, options, scene);
Mesh syntax
  • meshType: Specifies the type of mesh we want to create, such as "Box", "Sphere", "Cylinder", etc.

  • options: An object containing specific parameters for the chosen mesh type. These parameters can vary depending on the mesh type. For example, for a "Box" mesh, you might specify the size parameter to define its dimensions.

  • scene: The BabylonJS scene to which the mesh will be added.

Types

BabylonJS offers three types of meshes:

  • Set shape mesh

  • Parametric mesh

  • Polyhedra shape mesh

Set shape mesh

Such meshes are basic 3D geometric shapes that can be created using predefined methods provided by the BABYLON.MeshBuilder class. These shapes are often used as building blocks to create more complex 3D models.

Examples of shape meshes include boxes, spheres, cylinders, toruses, etc.

Parametric mesh

A parametric mesh is defined by mathematical formulas that describe the mesh's geometry. This approach allows for high control over the mesh's shape and appearance.

Parametric meshes can be used to create complex and intricate designs that might be challenging to achieve with predefined shape meshes alone.

  • Lines 24–29: The customParametricFunction() function generates the vectors based upon a given sample trigonometric function.

  • Lines 32–40: Sets the initial values of the variables that going to be used ahead in the code.

  • Lines 42–49: Loop to calculate a list of position vectors generated by the customParametricFunction() function.

  • Lines 51–57: Loop to calculate a list of indices vectors of each corresponding position vector calculated by the above loop.

  • Lines 59–61: Stcking all the vectors to create a mesh on the scene.

Polyhedra shape mesh

A polyhedra shape mesh is a 3D shape that consists of flat polygonal faces, straight edges, and sharp corners. Common examples of polyhedra include cubes, pyramids, dodecahedra, icosphere, etc.

Conclusion

Apart from the meshes described above, we can create a custom mesh defining all the parameters ourselves.

Note: Read more about the BabylonJS particle systems and  camera positions in scene graph.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved