@code3d/core
v0.0.1-alpha.17
Published
The TypeScript modeling runtime used by Code3D. Compose solids, profiles, curves, points, and editable sketches; inspect their geometry and reuse the same models in the App or a supported Node.js runtime.
Readme
@code3d/core
The TypeScript modeling runtime used by Code3D. Compose solids, profiles, curves, points, and editable sketches; inspect their geometry and reuse the same models in the App or a supported Node.js runtime.
Installation
npm install @code3d/coreThe App includes Core in its built-in modeling runtime. If a project declares
its own @code3d/core, the App uses that project's installed packages
and declarations instead. See project package installation.
Example
Place a part on a base, offset it, and rotate it around a chosen pivot.
import {on, box, group, offset, pivot} from '@code3d/core';
const base = box(40, 8, 30);
const part = box(14, 20, 12).relate(() => [
on(base.up), // Touch the base.
offset(6, 0, 0),
pivot([0, -10, 0]).rotate(0, 0, 25),
]);
export default group([base, part]);
The part is rotated 25° around Z. In the App, select rotate(0, 0, 25) to show
the rotation gizmo and parameter panel. Drag a ring or edit an angle to update
the code.
Complete example: part placement and rotation.
Usage notes
- Dimensions are in millimetres and angles are in degrees.
- Declare numeric form parameters with
input('Width', 40), or add{min, max, step}as a third argument for bounded controls and sliders. See numeric inputs. - Models have local coordinate frames. Constructors choose the initial origin; derived operations inherit their main input frame. See local coordinates.
- Use
frame()for an independent coordinate reference andgroup(parts, {frame: base, name: 'Assembly'})to choose the assembly's coordinates. The frame adds no geometry. See independent frames. - Modeling operations return new values. Measurements such as
.length,.areaand.volumereturn numbers; select an expression in the App to inspect it. - Node loads the modeling kernel automatically. Model authors do not initialize it or manage evaluation caches. See runtime integration.
Documentation
- Modeling API by task: primitives, operations, placement, materials and measurements.
- Solid primitives: individual references for box, cylinder, sphere, ellipsoid, frustum, regularPrism, tube and coil.
- Points, curves and profiles: point, line, arc, bezier, spline and four filled planar profile constructors.
- Shape construction: extrude, revolve, sweep, loft, wrap and thicken profiles.
- Booleans and solid modifications: union, cut, intersect, fillet, chamfer and shell. Solid boolean methods accept one solid or an array; free functions take arrays.
- Origins and local transforms: choose local zero, rotate and scale geometry.
- Groups and placement: groups, exposed references, relations, transforms and rotation coupling.
- Complete API export index: all public functions, types, members and integration entries.
- Model types and capabilities: model aliases, generics and supported members.
- Independent frames: non-geometric assembly coordinate references.
- Model metadata: symbol-keyed snapshots for package-specific data.
- Model values: immutable values and geometry measurements.
- Geometry measurements: clearance, length, area, volume, bounds and model-origin position.
- Sketch API: entity and constraint tuples, derived layers, finite regions and spatial placement.
- Text and fonts: text faces, local font files and Google Font selections.
- Parameters, time and caching: numeric inputs, playback offsets and reusable computations.
- Materials and appearance: captured colors, native materials, textures and Three.js integration.
- Local coordinates: frames, origins and placement conventions.
- Relations: position parts using bounds, geometry and frames.
- Rotation coupling: transmit cumulative angles through fixed-axis connections.
- Origins and rotation: choose a pivot and adjust a part.
- Shells: hollow solids and choose openings.
- Topology references: select vertices, edges and surfaces; reference elements and directional bounds define placement interfaces.
- Topology workflow: visual selection and stable IDs across modeling operations.
- Editable sketches: draw and constrain planar geometry, with construction curves for reference.
- Text and fonts: build planar or curved lettering.
- Curved surface wrapping: wrap profiles and thicken along surface normals.
- Reusable models: compose model functions.
- Model tools: add editing tools and argument presets.
- Extension API: native builders, package metadata, custom inspectors and annotations.
- Custom primitives: extend modeling with Replicad geometry.
- Tooling API: host evaluation, resources, snapshots, caches, topology and inspection.
- Runtime integration: numeric inputs, time offsets, resources, materials and source inspection.
- Current limitations: supported workflows and known boundaries.
Source and development
- Public API: exported constructors and model interfaces.
- Runtime tests: geometry, value semantics and integration coverage.
- Runtime development: kernel integration and resource ownership.
- Development guide: repository setup and test commands.
