@toolpath/viewer 1.1.0 → 1.1.1

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/dist/index.d.ts CHANGED
@@ -114,7 +114,7 @@ interface GridProps {
114
114
  * fixed cells is either invisible on a 900 mm plate or a solid wash under a
115
115
  * 12 mm insert.
116
116
  */
117
- declare const Grid: ({ step, extent, color, opacity }: GridProps) => react.JSX.Element;
117
+ declare const Grid: ({ step, extent, color, opacity }: GridProps) => react.JSX.Element | null;
118
118
  interface AxesProps {
119
119
  size?: number;
120
120
  }
@@ -336,6 +336,18 @@ interface GridSpec {
336
336
  * The plane is the *bottom* of the part, not `z = 0`: parts usually sit on
337
337
  * `z = 0` and then the two agree, but one modelled about its centre would
338
338
  * otherwise be sliced in half by its own grid.
339
+ *
340
+ * **Give this a measured box.** The plane is `box.min.z`, which is `+Infinity`
341
+ * for an empty one. Nothing else in the spec shows it — `getSize` and
342
+ * `getCenter` both short-circuit to zero for an empty `Box3` — so the step and
343
+ * the extent come back looking ordinary and {@link gridGeometry} then builds
344
+ * every vertex on a plane at infinity, which three.js reports as "Computed
345
+ * radius is NaN" once per mount.
346
+ *
347
+ * `useContentBox` hands back an empty box until the scene has been
348
+ * measured, so a caller pairing the two wants `if (box.isEmpty()) return null`
349
+ * ahead of this. That is what the package's own `Grid` does, and it is why it
350
+ * draws nothing on the opening frame rather than a grid nobody asked for.
339
351
  */
340
352
  declare function gridSpec(box: Box3): GridSpec;
341
353
  /**
package/dist/index.js CHANGED
@@ -155,6 +155,18 @@ function gridGeometry(spec) {
155
155
  geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
156
156
  return geometry;
157
157
  }
158
+ function gridFor(box, options = {}) {
159
+ if (box.isEmpty()) return null;
160
+ const spec = gridSpec(box);
161
+ const cell = options.step ?? spec.step;
162
+ return gridGeometry({
163
+ ...spec,
164
+ step: cell,
165
+ // Snapped outwards to a whole number of cells, so the part sits inside the
166
+ // grid rather than ending part-way through a square.
167
+ extent: options.extent ?? Math.ceil(spec.extent / cell) * cell
168
+ });
169
+ }
158
170
 
159
171
  // src/primitives.tsx
160
172
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -162,18 +174,9 @@ var FURNITURE = { [EXCLUDE_FROM_FRAME]: true };
162
174
  var Grid = ({ step, extent, color, opacity = 0.35 }) => {
163
175
  const theme = resolveTheme();
164
176
  const box = useContentBox();
165
- const geometry = useMemo(() => {
166
- const spec = gridSpec(box);
167
- const cell = step ?? spec.step;
168
- return gridGeometry({
169
- ...spec,
170
- step: cell,
171
- // Snapped outwards to a whole number of cells, so the part sits inside
172
- // the grid rather than ending part-way through a square.
173
- extent: extent ?? Math.ceil(spec.extent / cell) * cell
174
- });
175
- }, [box, extent, step]);
176
- useEffect(() => () => geometry.dispose(), [geometry]);
177
+ const geometry = useMemo(() => gridFor(box, { step, extent }), [box, extent, step]);
178
+ useEffect(() => () => geometry?.dispose(), [geometry]);
179
+ if (!geometry) return null;
177
180
  return /* @__PURE__ */ jsx("lineSegments", { geometry, renderOrder: -1, raycast: () => null, userData: FURNITURE, children: /* @__PURE__ */ jsx("lineBasicMaterial", { color: color ?? theme.cubeEdge, transparent: true, opacity }) });
178
181
  };
179
182
  var Axes = ({ size = 25 }) => /* @__PURE__ */ jsx("axesHelper", { args: [size], userData: FURNITURE, raycast: () => null });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolpath/viewer",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "React Three Fiber viewer for Toolpath Engine part reports",
5
5
  "license": "MIT",
6
6
  "engines": {