implicit-cad

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Implicit CAD

隐式CAD

Use this skill for implicit CAD models that should run directly in CAD Viewer as browser JS modules. The primary artifact is a
.implicit.js
or
.implicit.mjs
.
This skill is experimental. ALWAYS prefer conventional STEP-first CAD workflows unless the user explicitly asks for an implicit model.
本技能适用于可直接在CAD Viewer中作为浏览器JS模块运行的隐式CAD模型。核心产物为
.implicit.js
.implicit.mjs
文件。
本技能为实验性版本。除非用户明确要求使用隐式模型,否则请优先采用传统的以STEP格式为先的CAD工作流程。

File Format

文件格式

An implicit CAD file is an ES module exporting an
implicit.js/0.1.0
object. The schema source of truth lives in the bundled package at
scripts/packages/implicitjs/src/lib/implicitCad/schema.js
;
scripts/lib/implicit-cad.mjs
re-exports it as
SCHEMA
for helper-authored modules.
js
export default {
  schema: "implicit.js/0.1.0",
  name: "rounded capsule block",
  glsl: `
float sdf(vec3 p) {
  float sphere = implicit_sphere(p, vec3(0.0), 22.0);
  float block = implicit_box_centered(p, vec3(34.0, 18.0, 18.0), vec3(0.0));
  return implicit_union_round(sphere, block, 3.0);
}

vec3 color(vec3 p, vec3 normal) {
  return mix(vec3(0.20, 0.55, 0.95), vec3(0.95, 0.45, 0.20), smoothstep(-15.0, 20.0, p.z));
}
`,
};
Models may also declare params and animations. Parameter definitions use the implicitjs control schema:
number
,
boolean
,
enum
/
select
,
color
,
string
, and
button
. Number, boolean, color, and button params automatically become GLSL uniforms with the same name; do not add a separate
uniforms
object.
bounds
is optional and is estimated from the SDF when omitted; add explicit bounds only when the auto estimate is too broad, too slow, or misses an unusual field.
bounds
and
render
may be JavaScript functions that receive
{ ...params, params, animation, animationState, elapsedSec, progress, t }
.
Built-in GLSL helpers use the
implicit_*
namespace, for example
implicit_sphere
,
implicit_box_centered
, and
implicit_union_round
.
js
export default {
  schema: "implicit.js/0.1.0",
  name: "breathing orb",
  params: {
    radius: {
      type: "number",
      label: "Radius",
      min: 12,
      max: 34,
      default: 22,
      unit: "mm",
    },
  },
  animations: {
    breathe: {
      label: "Breathe",
      duration: 3,
      update({ progress, set }) {
        set("radius", 18 + Math.sin(progress * Math.PI) * 10);
      },
    },
  },
  render: { steps: 224, epsilon: 0.004 },
  glsl: `
float sdf(vec3 p) {
  return length(p) - radius;
}

vec3 color(vec3 p, vec3 normal) {
  return mix(vec3(0.10, 0.58, 0.95), vec3(1.0, 0.34, 0.12), smoothstep(-18.0, 18.0, p.z));
}
`,
};
Do not copy bundled helper files out of this skill. If helper functions are useful, use
scripts/lib/implicit-cad.mjs
during authoring or emit standalone GLSL into the final
.implicit.js
/
.implicit.mjs
module.
隐式CAD文件是一个ES模块,导出一个
implicit.js/0.1.0
对象。Schema的权威定义位于捆绑包的
scripts/packages/implicitjs/src/lib/implicitCad/schema.js
中;
scripts/lib/implicit-cad.mjs
将其重新导出为
SCHEMA
,供辅助模块使用。
js
export default {
  schema: "implicit.js/0.1.0",
  name: "rounded capsule block",
  glsl: `
float sdf(vec3 p) {
  float sphere = implicit_sphere(p, vec3(0.0), 22.0);
  float block = implicit_box_centered(p, vec3(34.0, 18.0, 18.0), vec3(0.0));
  return implicit_union_round(sphere, block, 3.0);
}

vec3 color(vec3 p, vec3 normal) {
  return mix(vec3(0.20, 0.55, 0.95), vec3(0.95, 0.45, 0.20), smoothstep(-15.0, 20.0, p.z));
}
`,
};
模型还可以声明参数和动画。参数定义使用implicitjs控制Schema:
number
boolean
enum
/
select
color
string
button
。数字、布尔值、颜色和按钮参数会自动成为同名的GLSL uniforms;无需添加单独的
uniforms
对象。
bounds
为可选参数,若省略则从SDF估算得出;仅当自动估算范围过宽、过慢或遗漏特殊场时,才添加明确的
bounds
bounds
render
可以是接收
{ ...params, params, animation, animationState, elapsedSec, progress, t }
的JavaScript函数。
内置GLSL辅助函数使用
implicit_*
命名空间,例如
implicit_sphere
implicit_box_centered
implicit_union_round
js
export default {
  schema: "implicit.js/0.1.0",
  name: "breathing orb",
  params: {
    radius: {
      type: "number",
      label: "Radius",
      min: 12,
      max: 34,
      default: 22,
      unit: "mm",
    },
  },
  animations: {
    breathe: {
      label: "Breathe",
      duration: 3,
      update({ progress, set }) {
        set("radius", 18 + Math.sin(progress * Math.PI) * 10);
      },
    },
  },
  render: { steps: 224, epsilon: 0.004 },
  glsl: `
float sdf(vec3 p) {
  return length(p) - radius;
}

vec3 color(vec3 p, vec3 normal) {
  return mix(vec3(0.10, 0.58, 0.95), vec3(1.0, 0.34, 0.12), smoothstep(-18.0, 18.0, p.z));
}
`,
};
请勿复制本技能中的捆绑辅助文件。如果需要使用辅助函数,请在创作时使用
scripts/lib/implicit-cad.mjs
,或在最终的
.implicit.js
/
.implicit.mjs
模块中嵌入独立的GLSL代码。

Authoring Workflow

创作工作流程

  1. Write a natural-language modeling brief with dimensions, coordinate assumptions, procedural color intent, and visual checks.
  2. Create or edit the user-specified
    .implicit.js
    /
    .implicit.mjs
    module.
  3. Use
    scripts/lib/implicit-cad.mjs
    helpers for primitives and field composition when useful:
    • primitives:
      sphere
      ,
      circle
      ,
      boxCentered
      ,
      plane
      ,
      lineSegment
      ,
      torus
      ,
      axis
      ,
      cylinder
      ,
      cylinderCapped
      ,
      capsule
      ,
      cone
      ,
      coneCapped
      ,
      coneCapsule
    • booleans/blends:
      unionSharp
      ,
      intersectSharp
      ,
      unionRound
      ,
      intersectRound
      ,
      unionChamfer
      ,
      intersectChamfer
      ,
      unionExp
      ,
      intersectExp
      ,
      unionLpNorm
      ,
      intersectLpNorm
      ,
      unionRvachev
      ,
      intersectRvachev
      ,
      difference
    • modifiers/lattices:
      shell
      ,
      rotateAxis
      ,
      repeatCentered
      ,
      remapCylindrical
      ,
      cubicGrid
      ,
      squareHoneycomb
      ,
      squareHoneycombReinforced
      ,
      squareDiagonalHoneycomb
      ,
      octetHoneycomb
      ,
      hexagonalHoneycomb
      ,
      triangularHoneycomb
    • TPMS fields:
      tpmsGyroid
      ,
      tpmsSchwarz
      ,
      tpmsDiamond
      ,
      tpmsLidinoid
      ,
      tpmsNeovius
      ,
      tpmsSplitP
      ,
      tpmsIwp
    • shader wrappers:
      distanceFunction
      emits
      float sdf(vec3 p)
      ,
      colorFunction
      emits
      vec3 color(vec3 p, vec3 normal)
  4. Add optional
    params
    and
    animations
    for dimensions, toggles, palettes, mode switches, and animated exploration. Use param names directly in GLSL; the runtime declares matching uniforms.
  5. Add optional procedural color with
    vec3 color(vec3 p, vec3 normal)
    when the model benefits from local material variation. Keep color values in 0..1 RGB.
  6. Rely on automatic SDF bounds first. Add explicit bounds when an animated, periodic, translated, or very thin model needs tighter or more reliable framing/export sampling.
  7. Run the lightweight visual verification flow below after visible geometry, color, params, animation, bounds, render, or export-affecting changes.
  8. Run
    node scripts/export.mjs --input <model.implicit.js> --format glb
    when a mesh artifact is needed for downstream viewers, slicers, or file handoff.
  1. 撰写包含尺寸、坐标假设、程序化颜色意图和视觉检查要求的自然语言建模说明。
  2. 创建或编辑用户指定的
    .implicit.js
    /
    .implicit.mjs
    模块。
  3. 必要时使用
    scripts/lib/implicit-cad.mjs
    中的辅助函数进行图元和场组合:
    • 图元:
      sphere
      circle
      boxCentered
      plane
      lineSegment
      torus
      axis
      cylinder
      cylinderCapped
      capsule
      cone
      coneCapped
      coneCapsule
    • 布尔运算/混合:
      unionSharp
      intersectSharp
      unionRound
      intersectRound
      unionChamfer
      intersectChamfer
      unionExp
      intersectExp
      unionLpNorm
      intersectLpNorm
      unionRvachev
      intersectRvachev
      difference
    • 修改器/晶格:
      shell
      rotateAxis
      repeatCentered
      remapCylindrical
      cubicGrid
      squareHoneycomb
      squareHoneycombReinforced
      squareDiagonalHoneycomb
      octetHoneycomb
      hexagonalHoneycomb
      triangularHoneycomb
    • TPMS场:
      tpmsGyroid
      tpmsSchwarz
      tpmsDiamond
      tpmsLidinoid
      tpmsNeovius
      tpmsSplitP
      tpmsIwp
    • 着色器包装器:
      distanceFunction
      生成
      float sdf(vec3 p)
      colorFunction
      生成
      vec3 color(vec3 p, vec3 normal)
  4. 可选添加
    params
    animations
    ,用于控制尺寸、开关、调色板、模式切换以及动画浏览。在GLSL中直接使用参数名称;运行时会声明对应的uniforms。
  5. 当模型需要局部材质变化时,可选通过
    vec3 color(vec3 p, vec3 normal)
    添加程序化颜色。颜色值请保持在0到1的RGB范围内。
  6. 优先依赖自动SDF范围。当动画、周期性、平移或极薄模型需要更紧凑或更可靠的取景/导出采样时,再添加明确的范围。
  7. 在可见几何体、颜色、参数、动画、范围、渲染或影响导出的更改后,运行以下轻量视觉验证流程。
  8. 当下游查看器、切片器或文件交接需要网格产物时,运行
    node scripts/export.mjs --input <model.implicit.js> --format glb

Visual Verification

视觉验证

Use this skill's snapshot tool as a fast visual check, not as a substitute for deterministic import/export validation. Keep the packet small and purposeful.
For simple static edits, one image is enough:
bash
node scripts/snapshot.mjs --input models/implicit-cad/<model>.implicit.js --output /tmp/implicit-review/<model>.png
For topology, periodicity, thin features, Boolean blends, object identity, color, or suspected framing issues, render a small packet in one CLI call so the browser, module, and runtime model are reused:
bash
node scripts/snapshot.mjs --job - <<'JSON'
{
  "input": "models/implicit-cad/<model>.implicit.js",
  "mode": "view",
  "render": { "sizeProfile": "simple", "frameMargin": 1.55 },
  "graphics": { "modelColors": true, "detail": 1.2, "shadows": true, "ambientOcclusion": true },
  "outputs": [
    { "path": "/tmp/implicit-review/<model>-iso.png", "camera": "iso" },
    { "path": "/tmp/implicit-review/<model>-front.png", "camera": "front" },
    { "path": "/tmp/implicit-review/<model>-top.png", "camera": "top" },
    { "path": "/tmp/implicit-review/<model>-right.png", "camera": "right" }
  ]
}
JSON
Add
implicitParameters
at the job level for one parameter state, or on individual outputs when the point of the review is comparing parameter variants. Use
render.frameMargin
around
1.5
when a model is close to the edge; if a snapshot still appears clipped, first check whether the source
bounds
is cutting the raymarch itself.
For animations, create a short GIF only when motion is part of the request:
bash
node scripts/snapshot.mjs --job - <<'JSON'
{
  "input": "models/implicit-cad/<model>.implicit.js",
  "mode": "animate",
  "outputs": [{ "path": "/tmp/implicit-review/<model>-animation.gif" }],
  "implicitAnimation": { "activeId": "<animation-id>", "durationSeconds": 3, "fps": 12 }
}
JSON
Review the resulting PNG/GIF for centered framing, no top/bottom/side clipping, expected silhouette and topology, visible parameter differences, GLSL-defined colors, no unexpected holes/gaps, and smooth enough edges for the requested graphics settings. If the snapshot reveals a mismatch, fix the implicit source or bounds and rerun only the relevant packet.
使用本技能的快照工具进行快速视觉检查,但不能替代确定性的导入/导出验证。请保持数据包小巧且目标明确。
对于简单的静态编辑,一张图片即可:
bash
node scripts/snapshot.mjs --input models/implicit-cad/<model>.implicit.js --output /tmp/implicit-review/<model>.png
对于拓扑结构、周期性、薄特征、布尔混合、对象识别、颜色或疑似取景问题,通过一次CLI调用生成一个小型数据包,以复用浏览器、模块和运行时模型:
bash
node scripts/snapshot.mjs --job - <<'JSON'
{
  "input": "models/implicit-cad/<model>.implicit.js",
  "mode": "view",
  "render": { "sizeProfile": "simple", "frameMargin": 1.55 },
  "graphics": { "modelColors": true, "detail": 1.2, "shadows": true, "ambientOcclusion": true },
  "outputs": [
    { "path": "/tmp/implicit-review/<model>-iso.png", "camera": "iso" },
    { "path": "/tmp/implicit-review/<model>-front.png", "camera": "front" },
    { "path": "/tmp/implicit-review/<model>-top.png", "camera": "top" },
    { "path": "/tmp/implicit-review/<model>-right.png", "camera": "right" }
  ]
}
JSON
如需设置单一参数状态,可在作业级别添加
implicitParameters
;若审查目的是比较参数变体,则在单个输出中添加。当模型靠近边缘时,将
render.frameMargin
设置为1.5左右;如果快照仍显示被裁剪,请先检查源文件的
bounds
是否截断了光线步进本身。
对于动画,仅当请求包含运动效果时,才创建短GIF:
bash
node scripts/snapshot.mjs --job - <<'JSON'
{
  "input": "models/implicit-cad/<model>.implicit.js",
  "mode": "animate",
  "outputs": [{ "path": "/tmp/implicit-review/<model>-animation.gif" }],
  "implicitAnimation": { "activeId": "<animation-id>", "durationSeconds": 3, "fps": 12 }
}
JSON
检查生成的PNG/GIF是否取景居中、无上下左右裁剪、轮廓和拓扑符合预期、参数差异可见、GLSL定义的颜色正确、无意外孔洞/间隙,且在请求的图形设置下边缘足够平滑。如果快照显示不匹配,请修复隐式源文件或范围,然后仅重新运行相关数据包。

Handoff

交接

After completing implicit CAD work that creates or modifies
.implicit.js
,
.implicit.mjs
,
.glb
,
.stl
, or
.3mf
artifacts, you must ALWAYS hand the explicit file path(s) to
$cad-viewer
when that skill is installed.
$cad-viewer
must start CAD Viewer if it is not already running and return link(s) to the relevant created or updated file(s); include those live viewer link(s) in the final response. If
$cad-viewer
is unavailable or startup fails, report that instead of silently omitting the handoff.
When verification snapshots are generated, also include the saved PNG/GIF snapshot(s) in the final response. If no snapshot applies, or if snapshot generation fails, say why and report the deterministic validation that still ran.
完成创建或修改
.implicit.js
.implicit.mjs
.glb
.stl
.3mf
产物的隐式CAD工作后,若
$cad-viewer
技能已安装,必须始终将明确的文件路径传递给
$cad-viewer
$cad-viewer
必须启动CAD Viewer(如果尚未运行),并返回相关新建或更新文件的链接;请在最终响应中包含这些实时查看器链接。如果
$cad-viewer
不可用或启动失败,请如实报告,不要省略交接步骤。
如果生成了验证快照,请在最终响应中包含保存的PNG/GIF快照。如果不适用快照或快照生成失败,请说明原因并报告已运行的确定性验证。

Snapshot Tool

快照工具

From this skill directory:
bash
node scripts/snapshot.mjs --input <model.implicit.js> --output <snapshot.png>
node scripts/snapshot.mjs --input <model.implicit.js> --output <orbit.gif> --mode orbit
node scripts/snapshot.mjs --job <render-job.json>
node scripts/snapshot.mjs --job - --json
node scripts/snapshot.mjs --help
Use
node scripts/snapshot.mjs --help
for the complete current command interface. The tool appends a UTC timestamp before the output extension. JSON jobs may be a single job, one job with multiple
outputs
, a raw array of jobs, or
{ "jobs": [...] }
; prefer a multi-output job for review packets because it avoids rebuilding the same artifact for each camera.
在本技能目录下运行:
bash
node scripts/snapshot.mjs --input <model.implicit.js> --output <snapshot.png>
node scripts/snapshot.mjs --input <model.implicit.js> --output <orbit.gif> --mode orbit
node scripts/snapshot.mjs --job <render-job.json>
node scripts/snapshot.mjs --job - --json
node scripts/snapshot.mjs --help
使用
node scripts/snapshot.mjs --help
查看完整的当前命令接口。该工具会在输出扩展名前添加UTC时间戳。JSON作业可以是单个作业、包含多个
outputs
的单个作业、原始作业数组或
{ "jobs": [...] }
;对于审查数据包,优先使用多输出作业,因为这样可以避免为每个相机重建相同的产物。

Export Tool

导出工具

From this skill directory:
bash
node scripts/export.mjs --input <model.implicit.js> --format glb
node scripts/export.mjs --input <model.implicit.js> --output <mesh.stl> --resolution <resolution>
node scripts/export.mjs --input <model.implicit.js> --format 3mf --params '<parameter-json>' --json
node scripts/export.mjs --help
Supported export formats are
glb
,
stl
, and
3mf
. The exporter samples the implicit SDF inside the declared bounds and extracts a triangle mesh. If
--output
is omitted, the mesh is written next to the source file using the same stem, such as
<model>.glb
for
<model>.implicit.js
. Use
node scripts/export.mjs --help
for the complete current command interface.
在本技能目录下运行:
bash
node scripts/export.mjs --input <model.implicit.js> --format glb
node scripts/export.mjs --input <model.implicit.js> --output <mesh.stl> --resolution <resolution>
node scripts/export.mjs --input <model.implicit.js> --format 3mf --params '<parameter-json>' --json
node scripts/export.mjs --help
支持的导出格式为
glb
stl
3mf
。导出器会在声明的范围内对隐式SDF进行采样,并提取三角形网格。如果省略
--output
,网格将写入源文件所在目录,使用相同的文件名主体,例如
<model>.implicit.js
对应的
<model>.glb
。使用
node scripts/export.mjs --help
查看完整的当前命令接口。