Bitbybit Docs
    Preparing search index...

    Class BabylonMesh

    Working with meshes already in the BabylonJS scene, the objects draw.drawAnyAsync gives back: moving, rotating and scaling them, showing and hiding, parenting, picking and collision flags, names and ids, cloning and instancing for many copies, and reading their triangles back out. Rotations are given in degrees; positions and distances are in scene units.

    Index

    Constructors

    edit

    • Joins several meshes into one new mesh, which draws faster than many separate ones.

      The sources are removed when disposeSource is true; set allow32BitsIndices when the meshes together have more than 65 thousand vertices, and use the sub-mesh options to keep separate materials.

      Parameters

      Returns Mesh

      The merged mesh

      const merged = bitbybit.babylon.mesh.mergeMeshes({ arrayOfMeshes: [meshA, meshB], disposeSource: true, allow32BitsIndices: true, subdivideWithSubMeshes: false, multiMultiMaterials: false });
      
    • Gives every triangle of a mesh its own vertices and normals, so faces show as flat facets instead of being smoothed across edges; the mesh is changed in place and given back.

      Parameters

      Returns Mesh

      The same mesh, flat shaded

      const faceted = bitbybit.babylon.mesh.convertToFlatShadedMesh({ babylonMesh: mesh });
      
    • Makes a copy of a mesh, with its children, that shares the geometry of the original and is placed at the same spot; the copy casts and receives shadows like the original.

      Parameters

      Returns Mesh

      The copy

      const copy = bitbybit.babylon.mesh.clone({ babylonMesh: mesh });
      bitbybit.babylon.mesh.setPosition({ babylonMesh: copy, position: [10, 0, 0] });
    • Makes one copy of a mesh at every given position, in the same order; the copies share the geometry of the original.

      Parameters

      Returns Mesh[]

      One copy per position

      const copies = bitbybit.babylon.mesh.cloneToPositions({ babylonMesh: mesh, positions: [[0, 0, 0], [10, 0, 0], [20, 0, 0]] });
      

    get

    • Reads the node a mesh is parented to, which is what it moves with; a mesh at the top level has none.

      Parameters

      Returns Node

      The parent node

    • Sets whether a mesh answers to pointer picking, and its children too when includeChildren is true; an unpickable mesh is skipped by clicks and rays that pick.

      Parameters

      Returns void

      bitbybit.babylon.mesh.setPickable({ babylonMesh: mesh, pickable: true, includeChildren: true });
      
    • Reads whether the mesh can be picked with the pointer.

      Parameters

      Returns boolean

      True when the mesh answers to picking

    • Finds every mesh in the scene whose name contains the given text, case-sensitive, in scene order.

      Parameters

      Returns AbstractMesh[]

      The matching meshes

      const wheels = bitbybit.babylon.mesh.getMeshesWhereNameContains({ name: "wheel" });
      
    • Lists the meshes parented under a mesh: all descendants, or only the direct children when directDescendantsOnly is true.

      Parameters

      Returns AbstractMesh[]

      The child meshes

      const parts = bitbybit.babylon.mesh.getChildMeshes({ babylonMesh: model, directDescendantsOnly: false });
      
    • Finds every mesh in the scene with exactly the given id; ids need not be unique, so several may match.

      Parameters

      Returns AbstractMesh[]

      The meshes with that id

      const meshes = bitbybit.babylon.mesh.getMeshesOfId({ id: "wheel" });
      
    • Finds the first mesh in the scene with exactly the given id; use getMeshesOfId when several share it.

      Parameters

      Returns AbstractMesh

      The first mesh with that id

      const mesh = bitbybit.babylon.mesh.getMeshOfId({ id: "wheel" });
      
    • Finds the mesh with the given unique id, the number the scene assigns to every mesh once, as getUniqueId reads it.

      Parameters

      Returns AbstractMesh

      The mesh with that unique id

      const id = bitbybit.babylon.mesh.getUniqueId({ babylonMesh: mesh });
      const same = bitbybit.babylon.mesh.getMeshOfUniqueId({ uniqueId: id });
    • Reads the id of a mesh, the label set by setId or by the loader that created it.

      Parameters

      Returns string

      The id

    • Reads the unique id of a mesh, the number the scene gives every mesh once and never reuses.

      Parameters

      Returns number

      The unique id number

    • Reads the triangles of a mesh as lists of three points in the mesh's own coordinates, the form jscad.shapes.fromPolygonPoints and similar builders take. The mesh must be made of triangles.

      Parameters

      Returns Point3[][]

      The triangles as lists of three points

      const triangles = bitbybit.babylon.mesh.getVerticesAsPolygonPoints({ babylonMesh: mesh });
      
    • Reads the name of a mesh, as set by setName or by whatever created it.

      Parameters

      Returns string

      The name

    • Reads the material of a mesh, the surface description its faces are drawn with.

      Parameters

      Returns Material

      The material

    • Reads the position of a mesh relative to its parent, as a point.

      Parameters

      Returns Point3

      The position as a point

    • Reads the position of a mesh in world coordinates, with every parent's transform applied.

      Parameters

      Returns Point3

      The world position as a point

    • Reads the rotation of a mesh around X, Y and Z, in radians, as its rotation property holds it.

      Parameters

      Returns Point3

      The rotation angles in radians

    • Reads the scale factors of a mesh along X, Y and Z; 1 is unscaled.

      Parameters

      Returns Point3

      The scale factors

    instance

    • Creates a placed instance of a mesh, as createMeshInstanceAndTransform does, without giving it back; for scripts that only need the copy to appear.

      Parameters

      Returns void

      bitbybit.babylon.mesh.createMeshInstanceAndTransformNoReturn({ mesh, position: [10, 0, 0], rotation: [0, 45, 0], scaling: [1, 1, 1] });
      
    • Creates an instance of a mesh, a lightweight copy that shares its geometry and draws cheaply, and places it at the given position, rotation in degrees and scaling.

      A mesh with children gets one instance per child, gathered under a new container; the original is hidden.

      Parameters

      Returns Mesh

      The container holding the instances

      const instance = bitbybit.babylon.mesh.createMeshInstanceAndTransform({ mesh, position: [10, 0, 0], rotation: [0, 45, 0], scaling: [1, 1, 1] });
      
    • Creates an instance of a mesh, a lightweight copy that shares its geometry and draws cheaply when many alike are needed, placed where the original is.

      A mesh with children gets one instance per child, gathered under a new container.

      Parameters

      Returns Mesh

      The instance, or the container holding the child instances

      const instance = bitbybit.babylon.mesh.createMeshInstance({ mesh });
      bitbybit.babylon.mesh.setPosition({ babylonMesh: instance, position: [10, 0, 0] });

    intersects

    • Tells whether two meshes overlap, judged by their bounding boxes: axis-aligned ones by default, or boxes that follow each mesh's rotation when precise is true; includeDescendants tests their children too.

      Parameters

      Returns boolean

      True when the meshes overlap

      const touching = bitbybit.babylon.mesh.intersectsMesh({ babylonMesh: meshA, babylonMesh2: meshB, precise: true, includeDescendants: false });
      
    • Tells whether a point lies inside the bounding box of a mesh.

      Parameters

      Returns boolean

      True when the point is inside the mesh's bounds

      const inside = bitbybit.babylon.mesh.intersectsPoint({ babylonMesh: mesh, point: [0, 1, 0] });
      

    memory

    • Removes a mesh from the scene and frees its GPU resources; the mesh cannot be used afterwards. Nothing happens when no mesh is given.

      Parameters

      Returns void

      bitbybit.babylon.mesh.dispose({ babylonMesh: mesh });
      

    move

    • Moves a mesh along its own forward direction, the local Z axis, by distance scene units; a turned mesh moves the way it faces.

      Parameters

      Returns void

      bitbybit.babylon.mesh.moveForward({ babylonMesh: mesh, distance: 5 });
      
    • Moves a mesh against its own forward direction, the local Z axis, by distance scene units.

      Parameters

      Returns void

    • Moves a mesh along its own up direction, the local Y axis, by distance scene units.

      Parameters

      Returns void

    • Moves a mesh against its own up direction, the local Y axis, by distance scene units.

      Parameters

      Returns void

    • Moves a mesh along its own right direction, the local X axis, by distance scene units.

      Parameters

      Returns void

    • Moves a mesh against its own right direction, the local X axis, by distance scene units.

      Parameters

      Returns void

    • Turns a mesh around its own Y axis by rotate degrees, on top of its current rotation, the way a car turns left or right.

      Parameters

      Returns void

      bitbybit.babylon.mesh.yaw({ babylonMesh: mesh, rotate: 45 });
      
    • Turns a mesh around its own X axis by rotate degrees, on top of its current rotation, the way a nose tips up or down.

      Parameters

      Returns void

    • Turns a mesh around its own Z axis by rotate degrees, on top of its current rotation, the way a wing banks.

      Parameters

      Returns void

    • Turns a mesh by angle degrees around an axis that passes through position, so the mesh orbits that point rather than spinning in place.

      Parameters

      Returns void

      bitbybit.babylon.mesh.rotateAroundAxisWithPosition({ mesh, position: [0, 0, 0], axis: [0, 1, 0], angle: 90 });
      

    set

    • Makes one mesh the child of another, so it moves, turns and scales together with its parent from then on; its position becomes relative to the parent.

      Parameters

      Returns void

      bitbybit.babylon.mesh.setParent({ babylonMesh: wheel, parentMesh: car });
      
    • Turns collision checking on or off for a mesh, and its children when includeChildren is true, so a camera or another collider with collisions enabled cannot pass through it.

      Parameters

      Returns void

      bitbybit.babylon.mesh.setCheckCollisions({ babylonMesh: walls, checkCollisions: true, includeChildren: true });
      
    • Lets a mesh, and its children when includeChildren is true, react to the pointer merely moving over it, which is off by default because it costs a pick on every pointer move.

      Parameters

      Returns void

      bitbybit.babylon.mesh.enablePointerMoveEvents({ babylonMesh: mesh, includeChildren: true });
      
    • Stops a mesh, and its children when includeChildren is true, from reacting to pointer moves, back to the default.

      Parameters

      Returns void

      bitbybit.babylon.mesh.disablePointerMoveEvents({ babylonMesh: mesh, includeChildren: true });
      
    • Sets the id of a mesh, a label that getMeshOfId finds it by and that need not be unique.

      Parameters

      Returns void

    • Sets the name of a mesh, and of its children too when includeChildren is true; names are what getMeshesWhereNameContains searches.

      Parameters

      Returns void

    • Gives a mesh a material, and its children too when includeChildren is true; the material decides the color, shininess and transparency of its surface.

      Parameters

      Returns void

      const material = bitbybit.babylon.material.pbrMetallicRoughness.create({ name: "red", baseColor: "#ff0000", emissiveColor: "#000000", metallic: 0.2, roughness: 0.6, alpha: 1, backFaceCulling: false, zOffset: 0 });
      bitbybit.babylon.mesh.setMaterial({ babylonMesh: mesh, material, includeChildren: true });
    • Places a mesh, or an instance of one, at a point relative to its parent.

      Parameters

      Returns void

      bitbybit.babylon.mesh.setPosition({ babylonMesh: mesh, position: [0, 5, 0] });
      
    • Sets the rotation of a mesh, or an instance of one, as angles in degrees around X, Y and Z, replacing its current rotation.

      Parameters

      Returns void

      bitbybit.babylon.mesh.setRotation({ babylonMesh: mesh, rotation: [0, 90, 0] });
      
    • Sets the scale factors of a mesh, or an instance of one, along X, Y and Z, replacing its current scale; 1 is unscaled.

      Parameters

      Returns void

      bitbybit.babylon.mesh.setScale({ babylonMesh: mesh, scale: [2, 1, 1] });
      
    • Multiplies the current scale of a mesh, or an instance of one, by one factor on all axes, so 2 doubles whatever size it has.

      Parameters

      Returns void

    updates

    • Moves, rotates, scales and recolors a drawn mesh in place, without drawing it again, which is faster when only the placement or the color changes.

      rotation is in radians here. colours is one hex color, or a list with one entry per child mesh, or per point or line of such a drawing; any other list uses its first entry.

      Parameters

      Returns void

      bitbybit.babylon.mesh.updateDrawn({ babylonMesh: mesh, position: [0, 5, 0], rotation: [0, Math.PI / 2, 0], scaling: [1, 1, 1], colours: "#ff0000" });
      

    visibility

    • Sets how visible a mesh is, from 0 for fully transparent to 1 for fully shown, with the values between fading it; includeChildren applies the same value to its child meshes.

      Parameters

      Returns void

      bitbybit.babylon.mesh.setVisibility({ babylonMesh: mesh, visibility: 0.5, includeChildren: true });
      
    • Hides a mesh without removing it from the scene, and its child meshes too when includeChildren is true; show brings it back.

      Parameters

      Returns void

      bitbybit.babylon.mesh.hide({ babylonMesh: mesh, includeChildren: true });
      
    • Shows a mesh that hide or a hidden draw made invisible, and its child meshes too when includeChildren is true.

      Parameters

      Returns void

      bitbybit.babylon.mesh.show({ babylonMesh: mesh, includeChildren: true });