import * as THREEJS from "three"; import type { Tag } from "@bitbybit-dev/core"; import { DrawCore } from "@bitbybit-dev/core"; import * as Inputs from "../inputs"; import type { Context } from "../context"; import type { DrawHelper } from "../draw-helper"; /** * Everything drawing can hand back: a group for geometry, the tag or tags for tags, a disposable * overlay for one a host application resolves, nothing for an empty entity. * * This is what the dispatch is typed as, because it runs before the kind is known. A caller does * know, and gets the one arm that applies through `Inputs.Draw.Drawn`. */ export type DrawnEntity = Inputs.Draw.DrawnAny; /** * 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 { readonly drawHelper: DrawHelper; readonly context: Context; readonly tag: Tag; private defaultBasicOptions; private defaultPolylineOptions; private defaultFrameOptions; constructor(drawHelper: DrawHelper, context: Context, tag: Tag); /** * 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 * @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>; private cachedSyncHandlers; private syncHandlers; private cachedAsyncHandlers; private asyncHandlers; /** * 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 handleDecomposedMeshShape; private handleDecomposedMeshes; /** * 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; /** * 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): DrawnEntity; /** * 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 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 object and the face index or instance id a raycaster reports. * @param inputs - The drawn recipe, the object 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 [hit] = raycaster.intersectObject(drawn, true); * const globalId = bitbybit.draw.recipeElementOfPick({ drawn, mesh: hit.object, triangle: hit.faceIndex, instance: hit.instanceId }); * ``` */ recipeElementOfPick(inputs: Inputs.Draw.RecipeElementPickDto): string | undefined; /** * 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): THREEJS.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): THREEJS.MeshStandardMaterial; private handleJscadMesh; private handleJscadMeshes; private handleManifoldShape; private handleManifoldShapes; private handleManifoldMesh; private handleManifoldMeshes; private handleRecipeMeshes; private handleOcctShape; private handleOcctShapes; private handleShapeWithAppearance; private handleShapesWithAppearance; private handleDesignBuild; private handleLine; private handlePoint; private handleJscadPath; private handleJscadPaths; private handlePolyline; private handleVerbCurve; private handleVerbSurface; private handleFrames; private handlePolylines; private handleLines; private handlePoints; private handleVerbCurves; private handleVerbSurfaces; private handleTag; private handleTags; private updateAny; private basicOptions; private occtOptions; private manifoldOptions; private handle; private handleAsync; private applyGlobalSettingsAndMetadataAndShadowCasting; }