circuit-json-to-gltf 0.0.157 → 0.0.158

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 CHANGED
@@ -61,6 +61,25 @@ 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
+
64
83
  ### Options
65
84
 
66
85
  - `format`: "gltf" (JSON) or "glb" (binary) - default: "gltf"
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
 
@@ -159,7 +159,7 @@ interface Box3D {
159
159
  };
160
160
  mesh?: STLMesh | OBJMesh;
161
161
  meshUrl?: string;
162
- meshType?: "stl" | "obj" | "glb" | "step";
162
+ meshType?: "stl" | "obj" | "gltf" | "glb" | "step";
163
163
  label?: string;
164
164
  labelColor?: Color;
165
165
  isTranslucent?: boolean;
@@ -296,6 +296,24 @@ declare function clearGLBCache(): void;
296
296
 
297
297
  declare const loadJscadPlan: (plan: unknown) => STLMesh;
298
298
 
299
+ /** Indexed triangles in right-handed Circuit JSON world coordinates, +Z up,
300
+ * millimetres. Positions are points with the CAD placement baked in; indices
301
+ * wind counter-clockwise when viewed from outside. Coincident vertices share
302
+ * an index without rounding or moving their coordinates. */
303
+ interface CadComponentMesh {
304
+ positions: number[];
305
+ indices: number[];
306
+ }
307
+ type CadComponentMeshOptions = Pick<CircuitTo3DOptions, "coordinateTransform" | "projectBaseUrl" | "authHeaders"> & {
308
+ pcbComponent?: PcbComponent;
309
+ };
310
+ /** Load the actual CAD model at its supplied position and rotation, using the
311
+ * renderer's model/origin/scale/layer rules. Folded CAD must already carry its
312
+ * resolved assembled pose. No board, textures or renderer objects are created.
313
+ * Missing, failed or empty models throw instead of returning a bounding box.
314
+ * Solid validity remains the caller's check; open models are not repaired. */
315
+ declare function loadCadComponentMesh(cadComponent: CadComponent, options?: CadComponentMeshOptions): Promise<CadComponentMesh>;
316
+
299
317
  declare function loadOBJ({ url, transform, projectBaseUrl, authHeaders, }: {
300
318
  url: string;
301
319
  transform?: CoordinateTransformConfig;
@@ -417,4 +435,4 @@ interface BRepShape {
417
435
  is_negative?: boolean;
418
436
  }
419
437
 
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 };
438
+ export { 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, getBestCameraPosition, getPoppyglErrorOverlayOptions, loadCadComponentMesh, loadGLB, loadJscadPlan, loadOBJ, loadSTL, renderBoardLayer, renderBoardTextures, setOcctImportJs, transformTriangles };