@constructorfleet/sketchforge-engine

中文文档
1.30.0发布于 2026/10/28AGPL-3.0-onlyTypeScriptES Module构建来源已验证近 30 天下载 5205

Portable geometry and project engine for SketchForge.

原始使用文档
文档目录7 节
  1. Node compatibility
  2. Installation
  3. Quick start
  4. Public API
  5. Editing a sketch-backed feature
  6. Limitations
  7. License

SketchForge engine

@constructorfleet/sketchforge-engine is the TypeScript package for SketchForge's project model and geometry operations. It is intended for Node.js applications that need to read or change SketchForge projects, construct parameterized shapes, or import and export geometry without running the web editor.

Node compatibility

The package manifest declares Node.js 20 or newer, but that range is broader than the runtime supported by its full geometry stack: the locked brepjs dependency requires Node.js 24 or newer. Use Node.js 24+ for the complete engine, including exact CAD and kernel-backed operations. On Node.js 20–23, npm may warn about the dependency engine requirement, and full engine behavior is unsupported. The package's engine range should be aligned with this dependency in a future package release.

Installation

npm install @constructorfleet/sketchforge-engine

The package is ECMAScript modules (ESM). TypeScript declarations ship with the package; no separate @types package is needed.

Quick start

Build a shape from parameters without starting the editor or opening a project:

import { shapeFromRequest } from "@constructorfleet/sketchforge-engine";

const shape = shapeFromRequest({ kind: "box", width: 20, depth: 10, height: 5 });
if (!shape) throw new Error("The requested shape could not be built");
console.log(shape.kind, shape.width, shape.depth, shape.height);

The shape request is plain data and can be stored or passed to createEngine. shapeFromRequest returns null for kinds that cannot be created from parameters alone (for example, a mesh with no geometry).

To run project operations, bind an engine to the directory store used by SketchForge:

import { createEngine, directoryProjectStore } from "@constructorfleet/sketchforge-engine";

const projectsDirectory = process.env.SKETCHFORGE_PROJECTS_DIR;
if (!projectsDirectory) throw new Error("Set SKETCHFORGE_PROJECTS_DIR to the project directory");
const engine = createEngine(directoryProjectStore(projectsDirectory));
const result = await engine.project("project-id");
if (!result.ok) throw new Error(`Could not read project: ${result.failure.reason}`);
console.log(`Revision ${result.value.revision}; ${result.value.shapes.length} shapes`);

Set SKETCHFORGE_PROJECTS_DIR to the directory already used by SketchForge, and replace project-id with an existing project ID. The directory must contain projects in the supported on-disk format. Keep access to that directory restricted to trusted local code: this package is a geometry/project library, not an HTTP service or an access-control boundary.

Public API

The package root is the supported import surface. Its main engine facade is Engine, created with createEngine(store). Every operation returns an EngineResult<T>; check ok before reading value or failure.

AreaEngine methodsWhat they do
Read and edit a projectproject, addShapes, changeShape, removeShapeRead placed shapes and project metadata; add parameterized shapes or change/remove an existing shape.
Arrange and repeatalign, distribute, pattern, mirrorBakedPlace selected shapes on a shared axis, spread them, create linear/circular copies, or mirror supported solids.
Import and combineimportMesh, cut, group, ungroup, separate, explodeImport model files, subtract/group solids, split groups/bodies, or explode a retained STEP assembly.
Inspect and measureedges, faces, measurements, properties, measureBetween, interferenceQuery exact geometry topology, shape properties, distances/angles, and gaps/overlaps.
Modify exact geometrytreat, draftPrism, shell, changeShapeApply edge treatments, draft an extruded prism, retain bounded sketch face drafts, or hollow a shape.

These operations address an existing project ID in a ProjectStore; this package does not create projects, project records, or initialize a project directory. addShapes is the first write operation for a project that already exists. All writes persist to the configured store.

The main entry point also exports these API areas:

  • Projects and operations: directoryProjectStore, createEngine, Engine, EngineResult, EngineFailure, project and operation request/result types.
  • Shape requests: shapeFromRequest, shapeWithRequestedChanges, REQUESTABLE_SHAPE_KINDS, plus types describing parameterized shapes.
  • Project files and exchange: .skf import/export and inspection; mesh import; STEP and scene export; SVG/DXF section output; STEP assembly explosion.
  • Geometry and CAD: primitive builders, exact solids, sectioning, topology analysis, shape bounds, CAD measurements, shelling, edge treatments, wall thickness, and projection layouts.
  • Placement and repetition: align/distribute helpers, pattern placement helpers, shape bounds, mirror, canonicalization, and workplane hole-mode helpers.

See the generated TypeScript API reference for every symbol and declaration. The reference links back to this usage guide. Related documentation: REST API, project format, and TypeScript client.

Editing a sketch-backed feature

Sketch extrusions, revolves, and sweeps expose a stable sketchSourceId on the generated shape. Pass that ID to engine.changeShape(projectId, sketchSourceId, { sketchProfile }) to rebuild the feature. For a persisted sketch revolve, the same source ID also accepts operation-setting updates such as { sides: 64 }. A draft prism retains its draftPrismAngle; source edits accept { draftPrismAngle: 12 } and reapply the draft when the extrusion profile changes. Retained sketch extrusions, sweeps, and eligible revolves can store one face draft with { faceDraft: { sourceFaceId, angle, pullDirection } }; use the ID from engine.faces, and use null to clear it. Profile edits resolve the selected planar face by its stored normal and require exactly one match; they never carry the old face index forward. .skf round trips preserve the face draft and source frame. A single-loop sketch extrusion can combine one face draft followed by one all-edge fillet. A single-section, no-hole sketch sweep can combine one face draft followed by one all-edge fillet or one symmetric 45° all-edge chamfer. Sweep treatments replay the source, draft, then treatment on profile edits, including after archive import; tests cover the round trip, replay, unsupported angles, and atomic refusal. Sweep face drafts do not support multiple sections, section holes, selected-edge treatments, or additional treatments. A plain single-region full-turn sketch revolve can combine one face draft followed by either one symmetric 45° all-edge chamfer or one all-edge fillet; profile and setting edits replay the source, draft, then treatment, including after archive import. Other face-draft treatment combinations, prism drafts, and shelling remain unsupported. When the output is nested inside a baked boolean group, the engine updates the sketch output and recomputes its boolean ancestors from their retained operands before writing the project. Each rebuilt ancestor is placed through its group's frame the way ungrouping places the group's children, so a group that was moved, turned, mirrored or resized after creation keeps that placement, mirror and scale across the edit. The edit is atomic: invalid profiles, missing or ambiguous face matches, or a failed dependent rebuild leave the stored project unchanged.

This recomputation currently covers sketch-backed extrusions, revolves, and sweeps nested under boolean groups, plus a retained prism-draft angle applied to a sketch extrusion. Other downstream operations remain baked or unsupported for source-driven recompute, and a general-purpose feature graph is not yet available. .skf export preserves the updated sketch profile, draft angle, and recomputed boolean result.

Limitations

  • The package does not provide the SketchForge web UI, HTTP routes, authentication, or a remote project client. Use the TypeScript client for the REST API.
  • There is no package-level meshForShape dispatcher yet; use the primitive builders or exact-solid helpers for the specific shape kinds they support.
  • The engine reads and writes SketchForge projects through a ProjectStore; directoryProjectStore is a local filesystem implementation. It expects valid project files and a directory managed with SketchForge's project conventions.
  • Parameter-only shape creation does not create drawn sketches or arbitrary mesh geometry. Import mesh data through engine.importMesh or use the editor for drawing workflows.
  • CAD, STEP, and exact-solid operations rely on native/WASM geometry dependencies and can be more resource-intensive than pure parameter and placement helpers. Kernel-specific modules are loaded when those operations run.
  • Use the package root as the supported public API. The export map also permits subpath imports for compiled modules, but undocumented internal modules are not a compatibility promise.

License

This package is licensed under AGPL-3.0-only.

版本与发布记录

@constructorfleet/sketchforge-engine 共发布 27 个版本,首次发布于 2026/10/21;过去 12 个月发布了 27 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.30.0latest2026/10/2813 天前
1.29.12026/10/2714 天前
1.29.02026/10/2615 天前
1.28.02026/10/2615 天前
1.27.02026/10/2516 天前
1.26.02026/10/2417 天前

关于 @constructorfleet/sketchforge-engine 的常见问题

@constructorfleet/sketchforge-engine 是什么?

Portable geometry and project engine for SketchForge.

如何安装 @constructorfleet/sketchforge-engine?

在项目目录运行 npm install @constructorfleet/sketchforge-engine,或使用 pnpm add / yarn add / bun add。

@constructorfleet/sketchforge-engine 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@constructorfleet/sketchforge-engine 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@constructorfleet/sketchforge-engine 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@constructorfleet/sketchforge-engine 可以商用吗?

@constructorfleet/sketchforge-engine 使用 AGPL-3.0-only 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@constructorfleet/sketchforge-engine 的下载量有多少?

根据 npm 官方下载统计,@constructorfleet/sketchforge-engine 在 2026/10/11 – 2026/11/09 这 30 天内被下载 5,205 次,日均约 174 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@constructorfleet/sketchforge-engine 还在维护吗?

最新版本 1.30.0 发布于 2026/10/28(13 天前);至今共发布 27 个版本,其中过去 12 个月发布了 27 个;首次发布于 2026/10/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。