Skip to main content

128 docs tagged with "Code"

Programming examples and patterns for common 3D tasks.

View all tags

A Family House in IFC

A whole two-storey family house written as an IFC model in a TypeScript project - layered walls, floors, windows and doors, a flat roof, cladding, a solar array, a carport and the garden - drawn in its materials' colours under a sky whose sun follows a time-of-day slider.

Advanced - 3D Text and Patterns

The advanced algorithms of bitbybit.dev - solid 3D text in real fonts, text laid on faces, pyramid patterns over surfaces, dimensions and camera navigation - which ones need a plan, with an example in Rete, Blockly and TypeScript and a table of every function.

Angular Dimension

Learn how to create and display angular dimensions for measuring angles in your 3D models with clear, professional annotations.

Asking a Shape About Itself

What every OCCT shape can tell you and have done to it - its type and orientation, whether it is closed or empty, whether two handles are the same shape, merging the seams a boolean leaves with unifySameDomain and removing the edges a split leaves inside a face - with an example in Rete, Blockly and TypeScript and a table of every function.

BabylonJS in Scripts

The bitbybit.babylon functions that shape the scene a script draws into - background, lights and shadows, camera, materials, GUI, meshes, picking, gizmos, XR and files - how they relate to drawing, and a map of all of them, with an example in Rete, Blockly and TypeScript.

Build and Export Assemblies

Create structured CAD assemblies with parts, instances, and hierarchies. Export STEP files compatible with FreeCAD, Fusion 360, and SolidWorks.

Changing the Scene Every Frame

How a Bitbybit script runs code on every frame the 3D view draws, for spinning parts and other animation - bitbybit.time in TypeScript, the render component in Rete and the render loop block in Blockly - and how to keep the work per frame small.

Checking a Shape

Why an operation can return a shape that is not what you meant without failing, and how to check a result - its volume, its validity, its size - and repair what came from a file.

Choosing a Kernel

When to model with OpenCascade, when with Manifold and when with JSCAD, what each is good and bad at, how a shape moves from one kernel to another, and which way each one builds up.

Christmas Tree

Create a 3D printable Christmas tree ornament using wire offset and extrusion - perfect for festive decorations.

Code in Bitbybit - the API at a Glance

How the Bitbybit API is organised and how one function reads in Rete, Blockly and TypeScript, the concepts every script stands on, and a map of every namespace with what it is for, how many functions it has and where it is explained.

Color Usage Examples

Learn how to use colors and apply them to 3D geometry in Bitbybit with examples in Rete, Blockly, and TypeScript.

Colors in Bitbybit

How bitbybit.color writes colors as hex text or as r, g, b objects, converts between the two with an explicit channel range, reads single channels and inverts a color for readable text.

Compound Shapes

Learn how to create compound shapes for better performance and grouped transformations in OCCT

Compounded Drawing

Learn how to use compounds for efficient rendering of complex geometric patterns and assemblies

Conventions

The handful of conventions that hold everywhere in Bitbybit - colour ranges, which way is up, and the defaults that surprise people.

Convert STEP to GLTF

Convert STEP files to web-optimized GLTF/GLB format directly in the browser with privacy-preserving local processing.

Creating Advanded Loft

Learn how to create a surface by lofting between several wire shapes and use various advanced options that help you make more intricate shapes.

CSV in Bitbybit

Reading and writing CSV tables in a Bitbybit script - rows, columns as numbers, headers, filtering rows and writing lists back as CSV - with an example in Rete, Blockly and TypeScript and a table of every function.

Dates in Bitbybit

How bitbybit.dates creates JavaScript dates, reads and sets their parts in local time or UTC without changing the input, formats them as text and converts to and from Unix timestamps.

Dimensions and Camera Navigation

Measurement annotations drawn in the 3D scene - linear, angular, radial, diametral and ordinate dimensions with their style - and camera moves, points of interest and framing with bitbybit.advanced, with an example in Rete, Blockly and TypeScript and a table of every function.

Drawing Options and Materials

Every drawing option in Bitbybit, generated from the API - precision, colors, edges, vertices, index labels, two-sided faces, surface analysis, materials and textures - which entity each set of options is for and which renderers have it, with an example in Rete, Blockly and TypeScript.

DXF

DXF file format is very popular in 2D CAD applications. Learn how to work with DXF files using OCCT.

Edge Primitives

Master the fundamentals of edge creation in OCCT - from simple lines and circles to complex arcs and ellipses. Learn multiple methods to create precise geometric boundaries for your 3D models.

Export Shapes with Color

Export OCCT shapes to STEP files with preserved colors using the assembly document structure for CAD software compatibility.

Face From Points

Create an OCCT face from an ordered list of points, and see how point order, planarity and closure decide whether you get a valid face or a failed operation.

Face From Wire

Create an OCCT face from a single closed wire, the most common way to turn an outline into a surface you can extrude, offset or boolean against.

Face Hexagons Grid

Create hexagonal face patterns in OCCT that react to a control point, growing hexagons near it and shrinking distant ones for organic wave-like surface effects.

Features: Holes, Bosses, Pockets and More

The OCCT features that change a solid where you point - plain, counterbored and countersunk holes on frames, bosses and pockets from a profile, ribs and grooves, push-pull and removing faces - plus drafts and single corners, with an example in Rete, Blockly and TypeScript.

Files and Assets in Scripts

How a Bitbybit script loads files and sends them out - project assets in the cloud or in this browser, files fetched from a URL, downloads, and the conversions between File, Blob and byte arrays - with a table of every function.

Frames in Bitbybit

Frames place things in Bitbybit - a point with three axes that shapes land on, points convert through, and grids, rings and honeycombs lay out by the dozen - with an example in Rete, Blockly and TypeScript and a table of every function.

Frost Flower

Create a 3D printable frost flower ornament using interpolated curves and 12-fold rotational symmetry.

Frozen Snowflake

Create a complex frozen snowflake ornament using zigzag patterns, advanced lofting, and selective face extrusion.

Gem Star

Create a simple 3D printable gem star decoration using polygon wire loft.

Getting a Model Out

How to take what a script makes out of Bitbybit - the editors' Export model menu for GLB, STL and pictures, and from code STEP and IGES for CAD programs, STL and OBJ for printing, GLB for the web, BREP, SVG and DXF drawings.

Hexagon Hive

Create intricate three-dimensional honeycomb structures by generating individual hexagon cells with controlled random heights, perfect for biomimetic architecture, structural optimization, and artistic installations.

Hexagon Hive Flat

Create flat honeycomb panels by sewing hexagonal faces together into unified structures, ideal for architectural panels, laser cutting templates, and manufacturing-optimized designs.

Hexagon Holes On Face

Create stunning honeycomb patterns and hexagonal perforations using BitByBit's subdivideToHexagonHoles function for architectural panels, biomimetic designs, and structural applications.

Hexagons Grid

Generate a grid of hexagonal OCCT wires from rows, columns and radius, the starting point for panelling, perforation patterns and honeycomb structures.

IFC Building Models

Writing, reading and changing IFC building models in a Bitbybit script - storeys, walls, doors, windows, slabs and roofs, ids of your own, materials and properties - and building them as exact shapes to draw or export to STEP, with an example in Rete, Blockly and TypeScript and a table of every function.

Inside a Shape - Its Graph and Its Geometry

Looking inside an OpenCascade shape - the graph of solids, shells, faces, edges and vertices and how they connect, read with occt.brepGraph, and the curves and surfaces beneath them, built and read with occt.geom - with a table of every function.

Introduction to Assemblies

Understand what OCCT assemblies are, why STEP files matter for CAD workflows, and preview your first assembly model in the browser.

Introduction to OCCT Fillets

Learn about OCCT fillets, which create roundings on the edges of shapes (solids, shells, or wires) to produce smooth transitions, with examples in Bitbybit.

JSON in Bitbybit

Reading and changing JSON data in a Bitbybit script - parsing text, reading properties, finding values with JSONPath, setting them on a copy and writing text back - with an example in Rete, Blockly and TypeScript and a table of every function.

Linear Dimension

Learn how to create and display linear dimensions for measuring distances in your 3D models with clear, professional annotations.

Lines in Bitbybit

How bitbybit.line builds straight lines between two points, measures and reverses them, places points along them, transforms them, converts to the segment form and finds where two lines cross.

Lists in Bitbybit

How bitbybit.lists reads, builds, edits, regroups and sorts lists of any kind of item, what the clone option does to your input, and how positions are counted from 0.

Lists in Every Editor

Points, shapes and numbers often come as lists. How a function takes a whole list as one value, how each editor repeats a function for every item, and where to read more in each editor.

Loading and Exporting with BabylonJS

The bitbybit.babylon functions that bring models into the scene and take it out - glTF, glb, STL and OBJ from files, URLs or bytes, glTF tooling, Gaussian splatting scans, GLB and STL export and screenshots - with a table of every function.

Logic in Bitbybit

How bitbybit.logic compares values, flips booleans, turns lists of numbers into true/false patterns by thresholds or at random, and lets a value through only when a condition holds.

Materials and the Look of a Model

How a model gets its look - colours and edges in the drawing options, physically based materials for metal, plastic and glass, and what the scene's lights and environment add.

Materials, Textures and Decals

The bitbybit.babylon functions for how surfaces look - physically based materials with base colour, metallic and roughness, transparency and emission, textures from images, and decals that stick an image onto a mesh - with a table of every function.

Math in Bitbybit

How bitbybit.math does arithmetic, rounding, trigonometry in radians, random numbers, safe evaluation of typed expressions, and the blending, easing and wrapping helpers used for animation and parametric variation.

Measuring and Analysing Shapes

The OCCT analysis functions answer questions about shapes with numbers and points - bounding boxes, distances and angles, clashes between parts, the kind and curvature of curves and surfaces - with an example in Rete, Blockly and TypeScript.

Mesh Utilities

How bitbybit.mesh works on plain triangle meshes - the plane of a triangle, signed distances, where triangles and meshes cut each other, enclosed volume and turning a flat polygon with holes into triangles.

Meshes and Nodes

The bitbybit.babylon functions for what is already in the scene - moving, turning, scaling, hiding and cloning drawn meshes, parenting them to transform nodes, BabylonJS's own mesh primitives, and transformation matrices - with a table of every function.

Moving, Turning and Placing Shapes

The OCCT transforms - moving, rotating, scaling and mirroring shapes, aligning one frame onto another, and placing many copies on frames that share one shape's geometry - with an example in Rete, Blockly and TypeScript.

Multiple Wire Offsets

Learn how to create multiple parallel offsets from a single open wire using OCCT operations for various design and manufacturing applications.

OCCT Fillets: Applying to 2D Wires

Learn how to apply fillets to the corners of 2D wires in OCCT to create rounded transitions between connected edges, using Bitbybit's Rete, Blockly, and TypeScript editors.

OCCT Fillets: Applying to 3D Wires

Learn how to apply fillets to the corners of 3D wires (non-planar) in OCCT, including variable radii on specific corners, using Bitbybit's Rete, Blockly, and TypeScript editors.

OCCT Vertices

Vertices, OCCT's own points - making them from plain points, reading them back, bundling a point cloud into one shape to draw, and casting points onto a shape to find where they land - with an example in Rete, Blockly and TypeScript and a table of every function.

Offset Operations

Learn how to create offset shapes using various offset operations in OCCT - from simple wire and face offsets to advanced thick solids.

Parse Assembly Structure

Extract and navigate assembly hierarchy from STEP files - find part labels, retrieve shapes, and apply custom styling to individual components.

Pen Sketcher

Draw exact 2D outlines in OCCT with a pen - lines, tangent arcs, sagitta and bulge arcs, Bezier curves, rounded and beveled corners - on any plane, then extrude them into solids.

Picking Faces and Edges

Three ways to tell a function which faces or edges of a shape to work on - by index, by a rule about where they lie and what they are, and by history - and why a rule survives changes an index does not.

Picking, Gizmos and XR

The bitbybit.babylon functions that let a person interact with the scene - picking what is under the pointer or along a ray, gizmos that move, rotate and scale objects by dragging, and entering virtual or augmented reality - with a table of every function.

Pin with Label

Learn how to create annotated pins with labels for marking important points and displaying information in your 3D models.

Pipes and Sweeps

Sweeping a profile along a path with OCCT - round tubes and polygon bars along any wire, your own profiles with pipe, profiles that grow or shrink on the way, and mouldings that follow a flat outline - with an example in Rete, Blockly and TypeScript.

Point Hex Grid Examples

Learn how to generate a hexagonal grid of points and hexagon outlines using Bitbybit's Point class, with examples in Rete, Blockly, and TypeScript.

Point Spiral Examples

Learn how to use the Point class to create and visualize a spiral pattern of points in Bitbybit with Rete, Blockly, and TypeScript.

Points in Bitbybit

How bitbybit.point builds points and point patterns such as spirals, arcs and hex grids, moves, rotates and scales them, measures distances and bounding boxes, and finds the largest fillet a corner allows.

Polylines in Bitbybit

How bitbybit.polyline builds open and closed polylines, measures their length, area and normal, splits them into segments, finds where they cross, joins loose segments into chains and sizes fillets for their corners.

Rectangle Holes On Face

Bitbybit has many helper functions that could streamline some of the modeling tasks, such as subdividing given rectangle faces into multiple holes or wires.

Rotated Extrude

Learn how to create 3D spiral or helical shapes by extruding a 2D wire profile along an axis while rotating it.

Sections, Slices and Drawings

Cutting OCCT shapes for drawings and fabrication - slicing a solid into layers, cutting it with planes or frames, splitting it with other shapes, the outline where two shapes meet, and hidden-line views for technical drawings - with an example in Rete, Blockly and TypeScript.

Selecting Faces and Edges by Rule

The OCCT select functions choose faces and edges by what they are and where they lie - facing a direction, along an axis, on a plane, by radius or size, in a box, around chosen faces - and return the indexes fillets, chamfers and features take, with an example in Rete, Blockly and TypeScript.

Shapes Live in a Worker

Why every kernel call is asynchronous, why a shape in a script is a small handle, why operations never change their inputs, and how the worker's memory of shapes is kept and freed.

Shells

Shells are the connected sets of faces that sit between a face and a solid in OCCT. Learn how to build them, when a shell needs to be closed, and how they feed solid construction.

Simple Flower

Build a parametric flower from OCCT wires and faces, driving petal count, radius and curvature from a handful of numbers so the whole shape rebuilds as you change them.

Simple Holes

Learn how to use outer and inner wire to create a face that has a hole.

Simple Hollow Grids

Learn how to create parametric hollow grids with multiple holes arranged in regular patterns for applications like ventilation panels, perforated sheets, and decorative screens.

Solids

Solids are closed, watertight volumes in OCCT and the shape kind most downstream operations expect. Learn how to create them from primitives and from shells, and how to check one is valid.

Solids

Learn how to get volume and surface area of a solid

Star Ornament

Create a simple 3D printable star ornament using polygon wire extrusion - perfect for tree toppers and holiday decorations.

STEP & IGES Import

Read STEP and IGES files into OCCT shapes - the compressed variants, passing file data from a browser, and how a file that cannot be read reports itself.

SVG Import

Import SVG drawings into OCCT geometry - which elements are supported, how faces and holes are worked out, and what to do about text and reused symbols.

Tangent Lines and Circles

Build OCCT edges that touch other curves - lines tangent to two circles or to a circle and a point, circles of a given radius tangent to two shapes, circles tangent to three, and lines tangent at an angle - in the plane of a frame, with an example in Rete, Blockly and TypeScript.

Technical Drawings from a Model

Turning an OCCT model into a technical drawing - a hidden-line view from any direction, drawn in the scene, saved as SVG with the hidden edges dashed, or written to DXF with the visible and hidden edges on their own layers - with an example in Rete, Blockly and TypeScript.

Text in 3D Compared

The ways to write text in Bitbybit side by side - OCCT stroke wires, plain stroke points, JSCAD stroke solids and real fonts with the Pro text3d - what each gives you, where it lands, which font it uses and how fonts load - with an example in Rete, Blockly and TypeScript.

Text in Bitbybit

How bitbybit.text splits, joins, searches, trims, pads and changes the case of text, works with regular expressions and placeholders, and draws text as strokes of a simple font on the XZ plane.

Text Tags Pinned to Points

Tags in Bitbybit are text labels pinned to 3D positions that follow the camera - how to describe one, draw one or many, update them in place, and what each editor offers - with a table of every function.

Text Usage Examples

Learn how to create and format text strings and then render them as 3D text geometry in Bitbybit using Rete, Blockly, and TypeScript.

The GUI - Buttons, Sliders and Text over the Scene

The bitbybit.babylon.gui functions build an interface inside the 3D view - a full-screen layer or one on a mesh, containers and stack panels, text, buttons, sliders, checkboxes, colour pickers, inputs and images - with an example in Rete, Blockly and TypeScript and a table of every function.

The JSCAD Kernel

JSCAD, Bitbybit's polygon kernel for quick solids - primitives, flat polygons and paths, extrusions with a twist, hulls, booleans, expansions and stroke-font text - with examples in Rete, Blockly and TypeScript and a table of every function.

The Manifold Kernel

Manifold, Bitbybit's fast mesh kernel - solids that always stay closed, cross sections that extrude, revolve, loft and sweep, booleans in bulk, meshes, recipes, and moving shapes between OpenCascade and Manifold - with examples in Rete, Blockly and TypeScript and a table of every function.

The Scene, Lights and Camera

The bitbybit.babylon functions for the scene as a whole - backgrounds and gradients, skyboxes and environment light, fog, directional and point lights with shadows, the camera and its limits, physics and the engine - with a table of every function.

Thick Solids from Complex Faces

Learn how to create thick solids from complex lofted surfaces using OCCT operations - from curved wire interpolation to volumetric solid creation.

Things - Finished Parametric Models

The catalogue of finished parametric models in bitbybit.things - vases, cups, a medal and a phone stand to 3D print, a laser-cut phone holder, tables, a chair, a house and two birdhouses - how to build, draw and dispose one, and which need a plan, with an example in Rete, Blockly and TypeScript.

Tree Decoration

Model a 3D-printable Christmas tree decoration in OCCT: build the outline from wires, give it thickness, and export a watertight solid ready for a slicer.

Twisted Polygon Ornament

Learn how to create an elegant twisted polygon ornament by transforming and lofting hexagonal wires - perfect for 3D printing decorative pieces.

Understanding OCCT Boolean Operations

Learn about the fundamental OCCT boolean operations (Union, Difference, Intersection) for combining and modifying 3D shapes in Bitbybit, with examples in Rete, Blockly, and TypeScript.

Understanding OCCT Chamfers

Learn about OCCT chamfers, which create straight, beveled cuts on the edges of solids or shells, and see examples of applying chamfers in Bitbybit's Rete, Blockly, and TypeScript editors.

Units, Tolerance and Precision

What unit a Bitbybit number is in, why a kernel's tolerance and a drawing's precision are different things, and how precision makes a curve smooth or faceted on screen without changing the shape.

Vector Span and Ease Examples

Learn how to use vector span and easing functions to create interesting point distributions for drawing in Bitbybit, with examples in Rete, Blockly, and TypeScript.

Vectors in Bitbybit

How bitbybit.vector adds, scales and multiplies vectors, measures lengths, distances and angles in degrees, blends between vectors, builds number sequences and cleans lists of vectors.

Wire Bezier Weights

Create Bezier wires in OCCT with per-control-point weights, so you can pull the curve towards individual points without moving them and model conic sections exactly.

Wire Helix Spirals

Create helix and spiral wires in OCCT from radius, pitch and turn count - the base curve for threads, springs, twisted columns and swept tubes.

Wire Via Points

Learn how to create various wires passing via or being controlled by collections of points

Working with Edges in OCCT

Learn about OCCT edges, how to create linear and curved edges, analyze their properties, use them to construct wires, and deconstruct other shapes into edges in Bitbybit.

Working with Faces in OCCT

Learn about OCCT faces, how to create them from wires, their role in constructing solids, and how faces can have multiple wires (e.g., for holes).

Working with Wires in OCCT

Learn about OCCT wires, how to create them from edges or points (polylines, splines, Bezier curves), their role in constructing faces, and how faces can have multiple wires (e.g., for holes).