Bitbybit Docs
    Preparing search index...

    Class Draw

    Drawing anything into the scene: kernel shapes, points, lines, polylines, frames, curves, meshes and tags all go through drawAnyAsync, which picks the right renderer for the entity and returns the drawn object. The options methods build the drawing options with defaults for each kind of entity, createPBRMaterial and createTexture make materials for the face slots, and a drawn object can be redrawn in place by passing it back.

    Hierarchy (View Summary)

    Index

    Constructors

    • Returns Bit.Draw

    draw async

    • Draws any entity into the scene, as drawAnyAsync does, without giving the drawn object back; for the last step of a script that only needs the result to appear.

      Parameters

      • inputs: DrawAny

        The entity to draw and the optional drawing options

      Returns Promise<void>

      const box = await bitbybit.occt.shapes.solid.createBox({ width: 10, length: 10, height: 10, center: [0, 0, 0] });
      await bitbybit.draw.drawAnyAsyncNoReturn({ entity: box });
    • Draws any entity the library produces into the scene and gives back the drawn object: kernel shapes from OCCT, JSCAD and Manifold, points, lines, polylines, frames, curves, meshes, tags and nodes.

      The options are matched to the entity, with defaults when none are given; pass the previous result back in the update slot to redraw in place.

      Type Parameters

      • E extends any

      Parameters

      • inputs: DrawAny<E>

        The entity to draw, the optional drawing options and the previous result when updating

      Returns Promise<Drawn<E, Mesh>>

      What drawing the entity produces: a scene object for geometry, the tag or tags for a tag, an axis triad for a node; undefined for an empty list

      const box = await bitbybit.occt.shapes.solid.createBox({ width: 10, length: 10, height: 10, center: [0, 0, 0] });
      const options = bitbybit.draw.optionsOcctShapeSimple({ precision: 0.01, drawFaces: true, faceColour: "#ff0000", drawEdges: true, edgeColour: "#ffffff", edgeWidth: 2, drawTwoSided: true, backFaceColour: "#0000ff", backFaceOpacity: 1 });
      const drawn = await bitbybit.draw.drawAnyAsync({ entity: box, options });

    draw sync

    • Draws an entity that needs no kernel work, as drawAny does, without giving the drawn object back; points, lines, polylines, frames and tags qualify, kernel shapes do not.

      Parameters

      • inputs: DrawAny

        The entity to draw and the optional drawing options

      Returns void

      bitbybit.draw.drawAnyNoReturn({ entity: [[0, 0, 0], [5, 5, 5], [10, 0, 0]] });
      
    • Draws an entity that needs no kernel work into the scene right away and gives back the drawn object: points, lines, polylines, frames, tags and nodes.

      Kernel shapes from OCCT, JSCAD and Manifold must go through drawAnyAsync, which waits for the kernel to mesh them.

      Type Parameters

      • E extends any

      Parameters

      • inputs: DrawAny<E>

        The entity to draw, the optional drawing options and the previous result when updating

      Returns Drawn<E, Mesh>

      What drawing the entity produces: a scene object for geometry, the tag or tags for a tag, an axis triad for a node; undefined for an empty list

      const options = bitbybit.draw.optionsSimple({ colours: "#00ff00", size: 0.5, opacity: 1, updatable: false, hidden: false, drawTwoSided: true, backFaceColour: "#0000ff", backFaceOpacity: 1, colorMapStrategy: Bit.Inputs.Base.colorMapStrategyEnum.lastColorRemainder, arrowSize: 0, arrowAngle: 15 });
      const drawn = bitbybit.draw.drawAny({ entity: [[0, 0, 0], [5, 5, 5], [10, 0, 0]], options });

    grid

    • Draws a grid on the ground plane, as drawGridMesh does, without giving the mesh back.

      Parameters

      Returns void

      bitbybit.draw.drawGridMeshNoReturn({ width: 400, height: 400, subdivisions: 10, majorUnitFrequency: 10, minorUnitVisibility: 0.45, gridRatio: 0.5, opacity: 0.5, backFaceCulling: false, mainColor: "#ffffff", secondaryColor: "#ffffff" });
      
    • Draws a grid on the ground plane, the XZ plane through the origin, to give a sense of scale and orientation; every tenth line is drawn thicker by default.

      Parameters

      Returns Mesh

      The grid mesh

      const grid = bitbybit.draw.drawGridMesh({ width: 400, height: 400, subdivisions: 10, majorUnitFrequency: 10, minorUnitVisibility: 0.45, gridRatio: 0.5, opacity: 0.5, backFaceCulling: false, mainColor: "#ffffff", secondaryColor: "#ffffff" });
      

    material

    • Creates an image texture from a URL for the texture slots of createPBRMaterial, with tiling, offset, rotation and filtering that mean the same in every renderer.

      Parameters

      • inputs: GenericTextureDto

        The image URL and the tiling, offset, rotation, flip and sampling options

      Returns Texture

      The engine's texture

      const texture = bitbybit.draw.createTexture({ url: "https://example.com/wood.jpg", name: "wood", uScale: 2, vScale: 2, uOffset: 0, vOffset: 0, wAng: 0, invertY: false, invertZ: false, samplingMode: Bit.Inputs.Draw.samplingModeEnum.trilinear });
      
    • Creates a physically based material from settings that mean the same in every renderer: base color, metallic and roughness, opacity, emissive glow, the texture slots and the alpha and side options; put it in the faceMaterial of the drawing options.

      Parameters

      • inputs: GenericPBRMaterialDto

        The name, colors, metallic and roughness values, opacity, textures and rendering options

      Returns PBRMetallicRoughnessMaterial

      The engine's material

      const material = bitbybit.draw.createPBRMaterial({ name: "steel", baseColor: "#c0c0c0", metallic: 1, roughness: 0.4, alpha: 1, emissiveColor: "#000000", emissiveIntensity: 1, zOffset: 0, zOffsetUnits: 0, alphaMode: Bit.Inputs.Draw.alphaModeEnum.opaque, alphaCutoff: 0.5, doubleSided: false, wireframe: false, unlit: false });
      const options = bitbybit.draw.optionsOcctShapeMaterial({ precision: 0.01, faceMaterial: material, drawEdges: true, edgeColour: "#ffffff", edgeWidth: 2 });

    options

    • Builds drawing options for points, lines, polylines, curves, surfaces and JSCAD meshes: colors, size, opacity, two-sided rendering and arrow heads on lines, with defaults for what is left out.

      Parameters

      Returns DrawBasicGeometryOptions

      The drawing options

      const options = bitbybit.draw.optionsSimple({ colours: "#ff0000", size: 2, opacity: 1, updatable: false, hidden: false, drawTwoSided: true, backFaceColour: "#0000ff", backFaceOpacity: 1, colorMapStrategy: Bit.Inputs.Base.colorMapStrategyEnum.lastColorRemainder, arrowSize: 0, arrowAngle: 15 });
      
    • Builds drawing options for frames: how long the axes are and their colors, whether the small grid in the frame's plane is drawn and in which color, the line width and whether the frame can be redrawn in place, with defaults for what is left out.

      Parameters

      Returns DrawFrameOptions

      The drawing options

      const options = bitbybit.draw.optionsFrame({ size: 2, colorX: "#ff0000", colorY: "#00ff00", colorZ: "#0000ff", drawPlane: true, colorPlane: "#808080", lineWidth: 2, updatable: false });
      const drawn = bitbybit.draw.drawAny({ entity: bitbybit.frame.world(), options });
    • Builds the full drawing options for OCCT shapes: meshing precision, face, edge and vertex colors and sizes, index labels, arrows on edges, two-sided rendering, iso curves, a surface analysis coloring the faces and the triangulation cache, with defaults for what is left out.

      Parameters

      Returns DrawOcctShapeOptions

      The drawing options

      const options = bitbybit.draw.optionsOcctShape({ faceOpacity: 1, edgeOpacity: 1, edgeColour: "#ffffff", faceColour: "#ff0000", edgeWidth: 2, drawEdges: true, drawFaces: true, drawVertices: false, vertexColour: "#ff00ff", vertexSize: 0.03, precision: 0.01, drawEdgeIndexes: false, edgeIndexHeight: 0.06, edgeIndexColour: "#ff00ff", drawFaceIndexes: false, faceIndexHeight: 0.06, faceIndexColour: "#0000ff", drawTwoSided: true, backFaceColour: "#0000ff", backFaceOpacity: 1, edgeArrowSize: 0, edgeArrowAngle: 15, keepMeshData: false, allowQualityDecrease: true, forceFaceDeflection: false, drawIsoCurves: true, isoCurvesU: 5, isoCurvesV: 5, isoCurvesColour: "#808080", surfaceAnalysis: Bit.Inputs.OCCT.surfaceAnalysisEnum.gaussian, draftDirection: [0, 1, 0] });
      
    • Builds the most used drawing options for OCCT shapes, precision, face and edge colors and two-sided rendering, with defaults for what is left out.

      Parameters

      Returns DrawOcctShapeSimpleOptions

      The drawing options

      const options = bitbybit.draw.optionsOcctShapeSimple({ precision: 0.01, drawFaces: true, faceColour: "#ff0000", drawEdges: true, edgeColour: "#ffffff", edgeWidth: 2, drawTwoSided: true, backFaceColour: "#0000ff", backFaceOpacity: 1 });
      
    • Builds drawing options for OCCT shapes whose faces use a full engine material, as createPBRMaterial makes one, plus the precision and edge style.

      Parameters

      Returns DrawOcctShapeMaterialOptions

      The drawing options

      const material = bitbybit.draw.createPBRMaterial({ name: "steel", baseColor: "#c0c0c0", metallic: 1, roughness: 0.4, alpha: 1, emissiveColor: "#000000", emissiveIntensity: 1, zOffset: 0, zOffsetUnits: 0, alphaMode: Bit.Inputs.Draw.alphaModeEnum.opaque, alphaCutoff: 0.5, doubleSided: false, wireframe: false, unlit: false });
      const options = bitbybit.draw.optionsOcctShapeMaterial({ precision: 0.01, faceMaterial: material, drawEdges: true, edgeColour: "#ffffff", edgeWidth: 2 });
    • Builds drawing options for Manifold solids and cross-sections: face color or a full engine material, the line style of cross-sections, normals and the two-sided rendering.

      Parameters

      Returns DrawManifoldOrCrossSectionOptions

      The drawing options

      const options = bitbybit.draw.optionsManifoldShapeMaterial({ faceOpacity: 1, faceColour: "#ff0000", faceMaterial: material, crossSectionColour: "#ff00ff", crossSectionWidth: 2, crossSectionOpacity: 1, computeNormals: false, drawTwoSided: true, backFaceColour: "#0000ff", backFaceOpacity: 1 });
      const drawn = await bitbybit.draw.drawAnyAsync({ entity: solid, options });
    • Builds drawing options for transform nodes, which are drawn as a triad of colored axis lines of a given length.

      Parameters

      Returns DrawNodeOptions

      The drawing options

      const options = bitbybit.draw.optionsBabylonNode({ colorX: "#ff0000", colorY: "#00ff00", colorZ: "#0000ff", size: 2 });
      const drawn = await bitbybit.draw.drawAnyAsync({ entity: node, options });