circuit-json-to-gltf 0.0.157 → 0.0.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/dist/index.d.ts +52 -3
- package/dist/index.js +14619 -14252
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -61,8 +61,78 @@ fs.writeFileSync("circuit.gltf", JSON.stringify(gltf))
|
|
|
61
61
|
convertCircuitJsonToGltf(circuitJson: CircuitJson, options?: ConversionOptions): Promise<ArrayBuffer | object>
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
### CAD geometry for physics and solid checks
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { loadCadComponentMesh } from "circuit-json-to-gltf"
|
|
68
|
+
|
|
69
|
+
const mesh = await loadCadComponentMesh(cadComponent, {
|
|
70
|
+
pcbComponent, // Optional PCB context for mounting-layer defaults.
|
|
71
|
+
})
|
|
72
|
+
// mesh.positions: [x, y, z, ...] in Circuit JSON world coordinates, +Z up, mm.
|
|
73
|
+
// mesh.indices: outward counter-clockwise triangle indices.
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The loader shares the renderer's model, origin, scale and mounting rules. It
|
|
77
|
+
loads the actual geometry without creating a board or textures. Supply the
|
|
78
|
+
resolved assembled CAD pose for folded designs. Missing, failed and empty
|
|
79
|
+
models throw; open surfaces remain open for the caller's solid validation.
|
|
80
|
+
Model-loading options `projectBaseUrl`, `authHeaders` and `coordinateTransform`
|
|
81
|
+
are also supported. Indexed vertices retain their coordinates without snapping.
|
|
82
|
+
|
|
83
|
+
### Assembly explosion stages
|
|
84
|
+
|
|
85
|
+
The real RP2040/NEMA17 example below lifts the cover and bolts together, then
|
|
86
|
+
separates the bolts, motor and spacers. These snapshots render the serialized
|
|
87
|
+
Circuit JSON program directly, including a halfway bolt-removal pose. The TSX
|
|
88
|
+
beside each view is the source that authored that stage.
|
|
89
|
+
|
|
90
|
+

|
|
91
|
+
|
|
92
|
+
`cad_explosion_stage` and `cad_explosion_move` records describe a playback program.
|
|
93
|
+
Exports remain assembled by default. Select a pose with the `explosion` option:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import {
|
|
97
|
+
convertCircuitJsonToGltf,
|
|
98
|
+
getAssemblyExplosionFrames,
|
|
99
|
+
} from "circuit-json-to-gltf"
|
|
100
|
+
|
|
101
|
+
const halfway = await convertCircuitJsonToGltf(circuitJson, {
|
|
102
|
+
format: "glb",
|
|
103
|
+
explosion: { throughStageRef: "DEVICE.lift-cover", stageProgress: 0.5 },
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// Assembled, then every completed stage in declared order. Keep one camera
|
|
107
|
+
// across these GLBs and label each image with frame.name for a storyboard.
|
|
108
|
+
for (const frame of getAssemblyExplosionFrames(circuitJson)) {
|
|
109
|
+
const glb = await convertCircuitJsonToGltf(circuitJson, {
|
|
110
|
+
format: "glb",
|
|
111
|
+
explosion: frame.explosion,
|
|
112
|
+
})
|
|
113
|
+
// Save/render glb and label it with frame.name.
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`explosion: {}` finishes all stages. Progress divides the selected stage into its
|
|
118
|
+
ordered moves, retaining all earlier displacement. A stage target expands its
|
|
119
|
+
explicit CAD/reference-surface membership; overlapping targets move once per
|
|
120
|
+
instruction. All references, orders and memberships are validated even when
|
|
121
|
+
selecting an early pose. The assembled input is never mutated.
|
|
122
|
+
|
|
123
|
+
Frames also include evaluated `circuitJson` and guide `lines` in circuit-world
|
|
124
|
+
XYZ (mm, right-handed +X right, +Y top, +Z above). Evaluated poses omit explosion
|
|
125
|
+
instructions to prevent applying them twice after saving. The usual exporter
|
|
126
|
+
converts these positions to glTF +Y-up coordinates. Node and browser entry points
|
|
127
|
+
support the same program, including assemblies without a PCB.
|
|
128
|
+
|
|
129
|
+
Each export is a static pose, not a glTF animation track. Playback supports CAD
|
|
130
|
+
and reference-surface translations; PCB/cable movement, rotation instructions
|
|
131
|
+
and swept collision checking are not supported.
|
|
132
|
+
|
|
64
133
|
### Options
|
|
65
134
|
|
|
135
|
+
- `explosion`: Optional `{ throughStageRef?, stageProgress? }` selecting a serialized assembly pose; omitted means assembled.
|
|
66
136
|
- `format`: "gltf" (JSON) or "glb" (binary) - default: "gltf"
|
|
67
137
|
- `boardTextureResolution`: Resolution for board texture rendering - default: 1024
|
|
68
138
|
- `showPcbNotes`: Include `pcb_note*` elements in board texture rendering (default: `false`)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PcbStiffener, CircuitJson, PcbBoard } from 'circuit-json';
|
|
1
|
+
import { PcbStiffener, CircuitJson, PcbBoard, PcbComponent, CadComponent } from 'circuit-json';
|
|
2
2
|
import { MaterialOptions } from 'jscad-planner';
|
|
3
3
|
import { mat4 } from 'gl-matrix';
|
|
4
4
|
|
|
@@ -32,7 +32,30 @@ type CircuitJsonWithPcbFlex = (CircuitJson[number] | PcbBendRecord | PcbStiffene
|
|
|
32
32
|
interface AuthHeaders extends Record<string, string> {
|
|
33
33
|
Authorization: string;
|
|
34
34
|
}
|
|
35
|
+
/** A pose within the serialized explosion program. Earlier stages stay applied. */
|
|
36
|
+
interface AssemblyExplosionOptions {
|
|
37
|
+
/** Inclusive qualified stage name. Omit to finish all stages. */
|
|
38
|
+
throughStageRef?: string;
|
|
39
|
+
/** Fraction of the selected stage's sequential moves, from 0 to 1. */
|
|
40
|
+
stageProgress?: number;
|
|
41
|
+
}
|
|
42
|
+
/** Circuit-world points in mm: right-handed +X right, +Y top, +Z above. */
|
|
43
|
+
interface AssemblyExplosionLine {
|
|
44
|
+
stageRef: string;
|
|
45
|
+
targetRef: string;
|
|
46
|
+
points: Point3[];
|
|
47
|
+
}
|
|
48
|
+
interface AssemblyExplosionFrame {
|
|
49
|
+
name: string;
|
|
50
|
+
/** Options for rendering the original assembled document at this pose. */
|
|
51
|
+
explosion?: AssemblyExplosionOptions;
|
|
52
|
+
/** Evaluated pose without instructions, safe to save and reopen. */
|
|
53
|
+
circuitJson: CircuitJsonWithPcbFlex;
|
|
54
|
+
lines: AssemblyExplosionLine[];
|
|
55
|
+
}
|
|
35
56
|
interface ConversionOptions {
|
|
57
|
+
/** Render a serialized explosion pose. Omit to keep the assembly assembled. */
|
|
58
|
+
explosion?: AssemblyExplosionOptions;
|
|
36
59
|
/** Override the render fold state. Undefined follows CAD is_on_folded_board in Circuit JSON. */
|
|
37
60
|
foldPcbs?: boolean;
|
|
38
61
|
format?: "gltf" | "glb";
|
|
@@ -159,7 +182,7 @@ interface Box3D {
|
|
|
159
182
|
};
|
|
160
183
|
mesh?: STLMesh | OBJMesh;
|
|
161
184
|
meshUrl?: string;
|
|
162
|
-
meshType?: "stl" | "obj" | "glb" | "step";
|
|
185
|
+
meshType?: "stl" | "obj" | "gltf" | "glb" | "step";
|
|
163
186
|
label?: string;
|
|
164
187
|
labelColor?: Color;
|
|
165
188
|
isTranslucent?: boolean;
|
|
@@ -198,6 +221,8 @@ interface GLTFExportOptions {
|
|
|
198
221
|
includeCustomExtensions?: boolean;
|
|
199
222
|
}
|
|
200
223
|
interface CircuitTo3DOptions {
|
|
224
|
+
/** Evaluate CAD explosion instructions before conversion to scene coordinates. */
|
|
225
|
+
explosion?: AssemblyExplosionOptions;
|
|
201
226
|
/** Override folding for supported PCB bend regions. Undefined follows CAD is_on_folded_board. */
|
|
202
227
|
foldPcbs?: boolean;
|
|
203
228
|
pcbColor?: Color;
|
|
@@ -235,6 +260,12 @@ interface BoardRenderOptions {
|
|
|
235
260
|
showPcbNotes?: boolean;
|
|
236
261
|
}
|
|
237
262
|
|
|
263
|
+
/** Named assembled and end-of-stage poses for storyboard snapshots or playback.
|
|
264
|
+
* Positions and guide points remain in circuit-world XYZ, mm, right-handed +Z up.
|
|
265
|
+
* Rendering uses the normal exporter frame conversion. Input is never mutated.
|
|
266
|
+
*/
|
|
267
|
+
declare function getAssemblyExplosionFrames(assembled: CircuitJsonWithPcbFlex): AssemblyExplosionFrame[];
|
|
268
|
+
|
|
238
269
|
interface PoppyglErrorOverlayOptions {
|
|
239
270
|
/** Final image dimensions in pixels, before PoppyGL supersampling. */
|
|
240
271
|
width: number;
|
|
@@ -296,6 +327,24 @@ declare function clearGLBCache(): void;
|
|
|
296
327
|
|
|
297
328
|
declare const loadJscadPlan: (plan: unknown) => STLMesh;
|
|
298
329
|
|
|
330
|
+
/** Indexed triangles in right-handed Circuit JSON world coordinates, +Z up,
|
|
331
|
+
* millimetres. Positions are points with the CAD placement baked in; indices
|
|
332
|
+
* wind counter-clockwise when viewed from outside. Coincident vertices share
|
|
333
|
+
* an index without rounding or moving their coordinates. */
|
|
334
|
+
interface CadComponentMesh {
|
|
335
|
+
positions: number[];
|
|
336
|
+
indices: number[];
|
|
337
|
+
}
|
|
338
|
+
type CadComponentMeshOptions = Pick<CircuitTo3DOptions, "coordinateTransform" | "projectBaseUrl" | "authHeaders"> & {
|
|
339
|
+
pcbComponent?: PcbComponent;
|
|
340
|
+
};
|
|
341
|
+
/** Load the actual CAD model at its supplied position and rotation, using the
|
|
342
|
+
* renderer's model/origin/scale/layer rules. Folded CAD must already carry its
|
|
343
|
+
* resolved assembled pose. No board, textures or renderer objects are created.
|
|
344
|
+
* Missing, failed or empty models throw instead of returning a bounding box.
|
|
345
|
+
* Solid validity remains the caller's check; open models are not repaired. */
|
|
346
|
+
declare function loadCadComponentMesh(cadComponent: CadComponent, options?: CadComponentMeshOptions): Promise<CadComponentMesh>;
|
|
347
|
+
|
|
299
348
|
declare function loadOBJ({ url, transform, projectBaseUrl, authHeaders, }: {
|
|
300
349
|
url: string;
|
|
301
350
|
transform?: CoordinateTransformConfig;
|
|
@@ -417,4 +466,4 @@ interface BRepShape {
|
|
|
417
466
|
is_negative?: boolean;
|
|
418
467
|
}
|
|
419
468
|
|
|
420
|
-
export { type BRepShape, type BoardRenderOptions, type BoundingBox, type Box3D, CAMERA_PRESET_DIRECTIONS, COORDINATE_TRANSFORMS, type Camera3D, type CameraFitOptions, type CameraPreset, type CircuitJsonWithPcbFlex, type CircuitTo3DOptions, type Color, type ConversionOptions, type CoordinateTransformConfig, type GLTFExportOptions, type LayerRef, type Light3D, type OBJMaterial, type OBJMesh, type OcctImportJsFactory, type PcbBendRecord, type PcbStiffenerRecord, type Point, type Point3, type PoppyglErrorOverlay, type PoppyglErrorOverlayOptions, type STLMesh, type Scene3D, type Size3, type Triangle, applyCoordinateTransform, clearGLBCache, clearOBJCache, clearSTLCache, convertCircuitJsonTo3D, convertCircuitJsonToGltf, convertSceneToGLTF, getBestCameraPosition, getPoppyglErrorOverlayOptions, loadGLB, loadJscadPlan, loadOBJ, loadSTL, renderBoardLayer, renderBoardTextures, setOcctImportJs, transformTriangles };
|
|
469
|
+
export { type AssemblyExplosionFrame, type AssemblyExplosionLine, type AssemblyExplosionOptions, type BRepShape, type BoardRenderOptions, type BoundingBox, type Box3D, CAMERA_PRESET_DIRECTIONS, COORDINATE_TRANSFORMS, type CadComponentMesh, type CadComponentMeshOptions, type Camera3D, type CameraFitOptions, type CameraPreset, type CircuitJsonWithPcbFlex, type CircuitTo3DOptions, type Color, type ConversionOptions, type CoordinateTransformConfig, type GLTFExportOptions, type LayerRef, type Light3D, type OBJMaterial, type OBJMesh, type OcctImportJsFactory, type PcbBendRecord, type PcbStiffenerRecord, type Point, type Point3, type PoppyglErrorOverlay, type PoppyglErrorOverlayOptions, type STLMesh, type Scene3D, type Size3, type Triangle, applyCoordinateTransform, clearGLBCache, clearOBJCache, clearSTLCache, convertCircuitJsonTo3D, convertCircuitJsonToGltf, convertSceneToGLTF, getAssemblyExplosionFrames, getBestCameraPosition, getPoppyglErrorOverlayOptions, loadCadComponentMesh, loadGLB, loadJscadPlan, loadOBJ, loadSTL, renderBoardLayer, renderBoardTextures, setOcctImportJs, transformTriangles };
|