import * as BABYLON from "@babylonjs/core"; import * as Inputs from "../inputs"; import type { BabylonNode } from "./babylon/node"; import type { Tag } from "@bitbybit-dev/core"; import { DrawCore } from "@bitbybit-dev/core"; import type { Context } from "../context"; import type { DrawHelper } from "../draw-helper"; /** * 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. */ export declare class Draw extends DrawCore { /** * @ignore true */ readonly drawHelper: DrawHelper; /** * @ignore true */ readonly node: BabylonNode; /** * @ignore true */ readonly tag: Tag; /** * @ignore true */ readonly context: Context; private defaultBasicOptions; private defaultPolylineOptions; private defaultNodeOptions; private defaultFrameOptions; constructor( /** * @ignore true */ drawHelper: DrawHelper, /** * @ignore true */ node: BabylonNode, /** * @ignore true */ tag: Tag, /** * @ignore true */ context: Context); /** * 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. * @param inputs - The entity to draw and the optional drawing options * @group draw async * @shortname draw async void * @disposableOutput true * @drawable true * @example * ```typescript * const box = await bitbybit.occt.shapes.solid.createBox({ width: 10, length: 10, height: 10, center: [0, 0, 0] }); * await bitbybit.draw.drawAnyAsyncNoReturn({ entity: box }); * ``` */ drawAnyAsyncNoReturn(inputs: Inputs.Draw.DrawAny): Promise; /** * Draws any entity the library produces into the scene and gives back the drawn object: kernel * shapes, alone or with their appearance, design builds, 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. * @param inputs - The entity to draw, the optional drawing options and the previous result when updating * @returns 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 * @group draw async * @shortname draw async * @drawable true * @disposableOutput true * @example * ```typescript * 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 }); * ``` */ drawAnyAsync(inputs: Inputs.Draw.DrawAny): Promise>; /** * Every branch of the asynchronous dispatch, typed as what it can actually produce. * * A package that adds entity kinds overrides this rather than the public signature: two * unresolved conditional types over the same `E` have no provable relation to each other, so a * narrower override of `drawAnyAsync` cannot typecheck however correct it is. * @ignore true */ protected drawResolvedAsync(inputs: Inputs.Draw.DrawAny): Promise>; private mergedOcctShapeOptions; private withDefaults; private basicOptions; private occtOptions; private manifoldOptions; private nodeOptions; private handleDecomposedMeshShape; private handleDecomposedMeshes; private decomposedMeshesContainerCounter; private updateAny; /** * 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. * @param inputs - The entity to draw and the optional drawing options * @group draw sync * @shortname draw sync void * @example * ```typescript * bitbybit.draw.drawAnyNoReturn({ entity: [[0, 0, 0], [5, 5, 5], [10, 0, 0]] }); * ``` */ drawAnyNoReturn(inputs: Inputs.Draw.DrawAny): void; /** * 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. * @param inputs - The entity to draw, the optional drawing options and the previous result when updating * @returns 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 * @group draw sync * @shortname draw sync * @example * ```typescript * 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 }); * ``` */ drawAny(inputs: Inputs.Draw.DrawAny): Inputs.Draw.Drawn; private cachedSyncHandlers; private syncHandlers; private cachedAsyncHandlers; private asyncHandlers; /** * Whether the entity is a node this renderer can draw an axis triad for. * * The engine-agnostic check this replaces asks whether `id` is a string containing "node", which * any object can satisfy and most real nodes do not: it matched only the ones this library named * itself, so a node from a loaded model, or one a script constructed, typechecked as drawable * and then silently drew nothing. A node is a renderer's own concept, so the honest check lives * beside the renderer that has the type to ask about. * @ignore true */ detectNode(entity: unknown): entity is BABYLON.TransformNode; /** * @ignore true */ detectNodes(entity: unknown): entity is BABYLON.TransformNode[]; /** * Every branch of the synchronous dispatch, typed as what it can actually produce. Overridden * instead of the public signature, for the reason given on its asynchronous twin. * @ignore true */ protected drawResolved(inputs: Inputs.Draw.DrawAny): Inputs.Draw.DrawnAny; /** * Draws a grid on the ground plane, as `drawGridMesh` does, without giving the mesh back. * @param inputs - The size, line spacing, colors and opacity of the grid * @group grid * @shortname draw grid no return * @disposableOutput true * @example * ```typescript * 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" }); * ``` */ drawGridMeshNoReturn(inputs: Inputs.Draw.SceneDrawGridMeshDto): void; /** * 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. * @param inputs - The size, line spacing, colors and opacity of the grid * @returns The grid mesh * @group grid * @shortname draw grid * @disposableOutput true * @example * ```typescript * 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" }); * ``` */ drawGridMesh(inputs: Inputs.Draw.SceneDrawGridMeshDto): BABYLON.Mesh; /** * 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. * @param inputs - The options to start from * @returns The drawing options * @group options * @shortname simple * @example * ```typescript * 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 }); * ``` */ optionsSimple(inputs: Inputs.Draw.DrawBasicGeometryOptions): Inputs.Draw.DrawBasicGeometryOptions; /** * 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. * @param inputs - The options to start from * @returns The drawing options * @group options * @shortname frame * @example * ```typescript * 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 }); * ``` */ optionsFrame(inputs: Inputs.Draw.DrawFrameOptions): Inputs.Draw.DrawFrameOptions; /** * 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. * @param inputs - The options to start from * @returns The drawing options * @group options * @shortname occt shape * @example * ```typescript * 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] }); * ``` */ optionsOcctShape(inputs: Inputs.Draw.DrawOcctShapeOptions): Inputs.Draw.DrawOcctShapeOptions; /** * 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. * @param inputs - The options to start from * @returns The drawing options * @group options * @shortname occt shape simple * @example * ```typescript * const options = bitbybit.draw.optionsOcctShapeSimple({ precision: 0.01, drawFaces: true, faceColour: "#ff0000", drawEdges: true, edgeColour: "#ffffff", edgeWidth: 2, drawTwoSided: true, backFaceColour: "#0000ff", backFaceOpacity: 1 }); * ``` */ optionsOcctShapeSimple(inputs: Inputs.Draw.DrawOcctShapeSimpleOptions): Inputs.Draw.DrawOcctShapeSimpleOptions; /** * Builds drawing options for OCCT shapes whose faces use a full engine material, as * `createPBRMaterial` makes one, plus the precision and edge style. * @param inputs - The options to start from * @returns The drawing options * @group options * @shortname occt shape with material * @example * ```typescript * 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 }); * ``` */ optionsOcctShapeMaterial(inputs: Inputs.Draw.DrawOcctShapeMaterialOptions): Inputs.Draw.DrawOcctShapeMaterialOptions; /** * 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. * @param inputs - The options to start from * @returns The drawing options * @group options * @shortname manifold shape draw options * @example * ```typescript * 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 }); * ``` */ optionsManifoldShapeMaterial(inputs: Inputs.Draw.DrawManifoldOrCrossSectionOptions): Inputs.Draw.DrawManifoldOrCrossSectionOptions; /** * Builds drawing options for the meshes of a recipe, as `manifold.recipes.meshes` gives them: * the tag naming an element, when repeated meshes become instances, the batch size, and the * color and surface of roots without a color. * @param inputs - The options to start from * @returns The drawing options * @group options * @shortname recipe meshes draw options * @example * ```typescript * const options = bitbybit.draw.optionsRecipeMeshes({ elementKey: "globalId", instancing: true, minInstances: 2, maxBatchVertices: 1000000, defaultColour: "#cccccc", defaultOpacity: 1, metallic: 0, roughness: 0.8 }); * const drawn = await bitbybit.draw.drawAnyAsync({ entity: meshes, options }); * ``` */ optionsRecipeMeshes(inputs: Inputs.Draw.DrawRecipeMeshesOptions): Inputs.Draw.DrawRecipeMeshesOptions; /** * Shows or hides elements of a recipe drawn from its meshes, such as one storey's walls, by the * values of their element tag, changing only their own triangles and instances. * @param inputs - The drawn recipe, the elements and whether they are shown * @group recipe elements * @shortname show recipe elements * @drawable false * @example * ```typescript * const drawn = await bitbybit.draw.drawAnyAsync({ entity: meshes }); * bitbybit.draw.setRecipeElementsVisible({ drawn, keys: ["2O2Fr$t4X7Zf8NOew3FLOH"], visible: false }); * ``` */ setRecipeElementsVisible(inputs: Inputs.Draw.RecipeElementsVisibilityDto): void; /** * Shows elements of a recipe drawn from its meshes in one color, such as the ones selected, or * with no color gives each its own back, by the values of their element tag. * @param inputs - The drawn recipe, the elements, and the color and opacity, or none * @group recipe elements * @shortname color recipe elements * @drawable false * @example * ```typescript * const drawn = await bitbybit.draw.drawAnyAsync({ entity: meshes }); * bitbybit.draw.setRecipeElementsColour({ drawn, keys: ["2O2Fr$t4X7Zf8NOew3FLOH"], colour: "#ffaa00" }); * bitbybit.draw.setRecipeElementsColour({ drawn, keys: ["2O2Fr$t4X7Zf8NOew3FLOH"] }); * ``` */ setRecipeElementsColour(inputs: Inputs.Draw.RecipeElementsColourDto): void; /** * Gives the element a pick hit in a recipe drawn from its meshes, as the value of its element * tag, from the mesh and the face or thin instance the scene's pick reports. * @param inputs - The drawn recipe, the mesh hit, and its triangle or instance * @returns The value of the element's tag, or undefined when the pick hit no element of it * @group recipe elements * @shortname recipe element of pick * @drawable false * @example * ```typescript * const drawn = await bitbybit.draw.drawAnyAsync({ entity: meshes }); * const pick = scene.pick(scene.pointerX, scene.pointerY); * const globalId = bitbybit.draw.recipeElementOfPick({ drawn, mesh: pick.pickedMesh, triangle: pick.faceId, instance: pick.thinInstanceIndex }); * ``` */ recipeElementOfPick(inputs: Inputs.Draw.RecipeElementPickDto): string | undefined; /** * Builds drawing options for transform nodes, which are drawn as a triad of colored axis lines * of a given length. * @param inputs - The options to start from * @returns The drawing options * @group options * @shortname babylon node * @example * ```typescript * const options = bitbybit.draw.optionsBabylonNode({ colorX: "#ff0000", colorY: "#00ff00", colorZ: "#0000ff", size: 2 }); * const drawn = await bitbybit.draw.drawAnyAsync({ entity: node, options }); * ``` */ optionsBabylonNode(inputs: Inputs.Draw.DrawNodeOptions): Inputs.Draw.DrawNodeOptions; /** * 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. * @param inputs - The image URL and the tiling, offset, rotation, flip and sampling options * @returns The engine's texture * @group material * @shortname create texture * @disposableOutput true * @example * ```typescript * 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 }); * ``` */ createTexture(inputs: Inputs.Draw.GenericTextureDto): BABYLON.Texture; /** * 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. * @param inputs - The name, colors, metallic and roughness values, opacity, textures and rendering options * @returns The engine's material * @group material * @shortname create pbr material * @disposableOutput true * @example * ```typescript * 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 }); * ``` */ createPBRMaterial(inputs: Inputs.Draw.GenericPBRMaterialDto): BABYLON.PBRMetallicRoughnessMaterial; private getSamplingMode; private handleTags; private handleTag; private handleVerbSurfaces; private handleVerbCurves; private handleNodes; private handlePoints; private handleLines; private handleFrames; private handlePolylines; private handleVerbSurface; private handleVerbCurve; private handleNode; private handleJscadPath; private handleJscadPaths; private handlePolyline; private handlePoint; private handleLine; private handleJscadMeshes; private handleManifoldShape; private handleManifoldShapes; private handleManifoldMesh; private handleManifoldMeshes; private handleRecipeMeshes; private handleOcctShape; private handleOcctShapes; private handleShapeWithAppearance; private handleShapesWithAppearance; private handleDesignBuild; private handleJscadMesh; private applyNodeSettingsAndMetadata; private applyGlobalSettingsAndMetadataAndShadowCasting; }