@glyphcss/react 0.0.4 → 0.0.6

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.cjs CHANGED
@@ -303,12 +303,14 @@ var import_jsx_runtime2 = require("react/jsx-runtime");
303
303
  function GlyphMeshInner({
304
304
  id,
305
305
  polygons: polygonsProp,
306
+ src,
306
307
  geometry,
307
308
  size = 1,
308
309
  color,
309
310
  position,
310
311
  scale,
311
312
  rotation,
313
+ autoCenter = false,
312
314
  castShadow = false,
313
315
  receiveShadow = false,
314
316
  className,
@@ -318,11 +320,26 @@ function GlyphMeshInner({
318
320
  const { sceneRef } = useGlyphSceneContext();
319
321
  const meshRef = (0, import_react4.useRef)(null);
320
322
  const wrapperRef = (0, import_react4.useRef)(null);
323
+ const [loadedPolygons, setLoadedPolygons] = (0, import_react4.useState)(null);
324
+ (0, import_react4.useEffect)(() => {
325
+ if (!src) {
326
+ setLoadedPolygons(null);
327
+ return;
328
+ }
329
+ let cancelled = false;
330
+ (0, import_core.loadMesh)(src).then((result) => {
331
+ if (!cancelled) setLoadedPolygons(result.polygons);
332
+ }).catch(() => {
333
+ if (!cancelled) setLoadedPolygons([]);
334
+ });
335
+ return () => {
336
+ cancelled = true;
337
+ };
338
+ }, [src]);
321
339
  const polygons = (0, import_react4.useMemo)(() => {
322
- if (polygonsProp !== void 0) return polygonsProp;
323
- if (geometry !== void 0) return (0, import_core.resolveGeometry)(geometry, { size, color });
324
- return [];
325
- }, [polygonsProp, geometry, size, color]);
340
+ const base = polygonsProp !== void 0 ? polygonsProp : src !== void 0 ? loadedPolygons ?? [] : geometry !== void 0 ? (0, import_core.resolveGeometry)(geometry, { size, color }) : [];
341
+ return autoCenter ? (0, import_core.recenterPolygons)(base) : base;
342
+ }, [polygonsProp, src, loadedPolygons, geometry, size, color, autoCenter]);
326
343
  const transform = (0, import_react4.useMemo)(() => ({
327
344
  id,
328
345
  position,
@@ -541,6 +558,7 @@ function GlyphPerspectiveCameraInner({
541
558
  rotX,
542
559
  rotY,
543
560
  distance,
561
+ perspective,
544
562
  zoom,
545
563
  stretch,
546
564
  center,
@@ -555,6 +573,7 @@ function GlyphPerspectiveCameraInner({
555
573
  if (rotX !== void 0) opts.rotX = rotX;
556
574
  if (rotY !== void 0) opts.rotY = rotY;
557
575
  if (distance !== void 0) opts.distance = distance;
576
+ if (perspective !== void 0) opts.perspective = perspective;
558
577
  if (zoom !== void 0) opts.zoom = zoom;
559
578
  if (stretch !== void 0) opts.stretch = stretch;
560
579
  if (center !== void 0) opts.center = center;
@@ -576,6 +595,10 @@ function GlyphPerspectiveCameraInner({
576
595
  camera.distance = distance;
577
596
  dirty = true;
578
597
  }
598
+ if (perspective !== void 0 && camera.perspective !== perspective) {
599
+ camera.perspective = perspective;
600
+ dirty = true;
601
+ }
579
602
  if (zoom !== void 0 && camera.zoom !== zoom) {
580
603
  camera.zoom = zoom;
581
604
  dirty = true;
package/dist/index.d.cts CHANGED
@@ -43,6 +43,8 @@ declare const GlyphScene: react.MemoExoticComponent<typeof GlyphSceneInner>;
43
43
  interface GlyphMeshProps {
44
44
  id?: string;
45
45
  polygons?: Polygon[];
46
+ /** URL of an OBJ / GLB / glTF / VOX / STL mesh, fetched + parsed via `loadMesh`. */
47
+ src?: string;
46
48
  /**
47
49
  * Built-in geometry name. Resolved via `resolveGeometry` when neither
48
50
  * `polygons` nor `src` is provided.
@@ -57,6 +59,11 @@ interface GlyphMeshProps {
57
59
  position?: Vec3;
58
60
  scale?: number | Vec3;
59
61
  rotation?: Vec3;
62
+ /**
63
+ * Recenter the mesh's bounding-box center to the origin so it pivots around
64
+ * its own center (center only, no scaling — matches voxcss). Default false.
65
+ */
66
+ autoCenter?: boolean;
60
67
  /**
61
68
  * This mesh casts shadows onto `receiveShadow` surfaces.
62
69
  * Default false — opt-in, matching PolyMesh behaviour.
@@ -79,7 +86,7 @@ interface GlyphMeshProps {
79
86
  onClick?: (event: GlyphMouseEvent) => void;
80
87
  onWheel?: (event: GlyphWheelEvent) => void;
81
88
  }
82
- declare function GlyphMeshInner({ id, polygons: polygonsProp, geometry, size, color, position, scale, rotation, castShadow, receiveShadow, className, style, children, }: GlyphMeshProps): react_jsx_runtime.JSX.Element;
89
+ declare function GlyphMeshInner({ id, polygons: polygonsProp, src, geometry, size, color, position, scale, rotation, autoCenter, castShadow, receiveShadow, className, style, children, }: GlyphMeshProps): react_jsx_runtime.JSX.Element;
83
90
  declare const GlyphMesh: react.MemoExoticComponent<typeof GlyphMeshInner>;
84
91
 
85
92
  interface GlyphGroundProps {
@@ -166,6 +173,9 @@ interface GlyphPerspectiveCameraProps {
166
173
  rotY?: number;
167
174
  /** Perspective distance (world units). Default 6. */
168
175
  distance?: number;
176
+ /** CSS-perspective distance in virtual pixels (matches voxcss). Larger =
177
+ * flatter. Default 32000. Set 0 to disable (legacy orbit projection). */
178
+ perspective?: number;
169
179
  /** Camera zoom — absolute px per world unit (zoom=1 → BASE_TILE=50). Default 0.65. */
170
180
  zoom?: number;
171
181
  /** Extra horizontal stretch on top of cellAspect. Default 1.0. */
@@ -176,7 +186,7 @@ interface GlyphPerspectiveCameraProps {
176
186
  style?: CSSProperties;
177
187
  children?: ReactNode;
178
188
  }
179
- declare function GlyphPerspectiveCameraInner({ rotX, rotY, distance, zoom, stretch, center, className, style, children, }: GlyphPerspectiveCameraProps): react_jsx_runtime.JSX.Element;
189
+ declare function GlyphPerspectiveCameraInner({ rotX, rotY, distance, perspective, zoom, stretch, center, className, style, children, }: GlyphPerspectiveCameraProps): react_jsx_runtime.JSX.Element;
180
190
  declare const GlyphPerspectiveCamera: react.MemoExoticComponent<typeof GlyphPerspectiveCameraInner>;
181
191
 
182
192
  interface GlyphCameraContextValue {
package/dist/index.d.ts CHANGED
@@ -43,6 +43,8 @@ declare const GlyphScene: react.MemoExoticComponent<typeof GlyphSceneInner>;
43
43
  interface GlyphMeshProps {
44
44
  id?: string;
45
45
  polygons?: Polygon[];
46
+ /** URL of an OBJ / GLB / glTF / VOX / STL mesh, fetched + parsed via `loadMesh`. */
47
+ src?: string;
46
48
  /**
47
49
  * Built-in geometry name. Resolved via `resolveGeometry` when neither
48
50
  * `polygons` nor `src` is provided.
@@ -57,6 +59,11 @@ interface GlyphMeshProps {
57
59
  position?: Vec3;
58
60
  scale?: number | Vec3;
59
61
  rotation?: Vec3;
62
+ /**
63
+ * Recenter the mesh's bounding-box center to the origin so it pivots around
64
+ * its own center (center only, no scaling — matches voxcss). Default false.
65
+ */
66
+ autoCenter?: boolean;
60
67
  /**
61
68
  * This mesh casts shadows onto `receiveShadow` surfaces.
62
69
  * Default false — opt-in, matching PolyMesh behaviour.
@@ -79,7 +86,7 @@ interface GlyphMeshProps {
79
86
  onClick?: (event: GlyphMouseEvent) => void;
80
87
  onWheel?: (event: GlyphWheelEvent) => void;
81
88
  }
82
- declare function GlyphMeshInner({ id, polygons: polygonsProp, geometry, size, color, position, scale, rotation, castShadow, receiveShadow, className, style, children, }: GlyphMeshProps): react_jsx_runtime.JSX.Element;
89
+ declare function GlyphMeshInner({ id, polygons: polygonsProp, src, geometry, size, color, position, scale, rotation, autoCenter, castShadow, receiveShadow, className, style, children, }: GlyphMeshProps): react_jsx_runtime.JSX.Element;
83
90
  declare const GlyphMesh: react.MemoExoticComponent<typeof GlyphMeshInner>;
84
91
 
85
92
  interface GlyphGroundProps {
@@ -166,6 +173,9 @@ interface GlyphPerspectiveCameraProps {
166
173
  rotY?: number;
167
174
  /** Perspective distance (world units). Default 6. */
168
175
  distance?: number;
176
+ /** CSS-perspective distance in virtual pixels (matches voxcss). Larger =
177
+ * flatter. Default 32000. Set 0 to disable (legacy orbit projection). */
178
+ perspective?: number;
169
179
  /** Camera zoom — absolute px per world unit (zoom=1 → BASE_TILE=50). Default 0.65. */
170
180
  zoom?: number;
171
181
  /** Extra horizontal stretch on top of cellAspect. Default 1.0. */
@@ -176,7 +186,7 @@ interface GlyphPerspectiveCameraProps {
176
186
  style?: CSSProperties;
177
187
  children?: ReactNode;
178
188
  }
179
- declare function GlyphPerspectiveCameraInner({ rotX, rotY, distance, zoom, stretch, center, className, style, children, }: GlyphPerspectiveCameraProps): react_jsx_runtime.JSX.Element;
189
+ declare function GlyphPerspectiveCameraInner({ rotX, rotY, distance, perspective, zoom, stretch, center, className, style, children, }: GlyphPerspectiveCameraProps): react_jsx_runtime.JSX.Element;
180
190
  declare const GlyphPerspectiveCamera: react.MemoExoticComponent<typeof GlyphPerspectiveCameraInner>;
181
191
 
182
192
  interface GlyphCameraContextValue {
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ import {
23
23
  parseGltf,
24
24
  bakeSolidTextureSamples,
25
25
  bakeSolidTextureSampledPolygons,
26
- loadMesh,
26
+ loadMesh as loadMesh2,
27
27
  createIsometricCamera,
28
28
  parseVox,
29
29
  polygonFaces,
@@ -213,8 +213,8 @@ function GlyphSceneInner({
213
213
  var GlyphScene = memo(GlyphSceneInner);
214
214
 
215
215
  // src/glyphcss/scene/GlyphMesh.tsx
216
- import { memo as memo2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
217
- import { resolveGeometry } from "@glyphcss/core";
216
+ import { memo as memo2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState } from "react";
217
+ import { resolveGeometry, recenterPolygons, loadMesh } from "@glyphcss/core";
218
218
 
219
219
  // src/glyphcss/scene/events.ts
220
220
  var MESH_REGISTRY = /* @__PURE__ */ new WeakMap();
@@ -259,12 +259,14 @@ import { jsx as jsx2 } from "react/jsx-runtime";
259
259
  function GlyphMeshInner({
260
260
  id,
261
261
  polygons: polygonsProp,
262
+ src,
262
263
  geometry,
263
264
  size = 1,
264
265
  color,
265
266
  position,
266
267
  scale,
267
268
  rotation,
269
+ autoCenter = false,
268
270
  castShadow = false,
269
271
  receiveShadow = false,
270
272
  className,
@@ -274,11 +276,26 @@ function GlyphMeshInner({
274
276
  const { sceneRef } = useGlyphSceneContext();
275
277
  const meshRef = useRef2(null);
276
278
  const wrapperRef = useRef2(null);
279
+ const [loadedPolygons, setLoadedPolygons] = useState(null);
280
+ useEffect2(() => {
281
+ if (!src) {
282
+ setLoadedPolygons(null);
283
+ return;
284
+ }
285
+ let cancelled = false;
286
+ loadMesh(src).then((result) => {
287
+ if (!cancelled) setLoadedPolygons(result.polygons);
288
+ }).catch(() => {
289
+ if (!cancelled) setLoadedPolygons([]);
290
+ });
291
+ return () => {
292
+ cancelled = true;
293
+ };
294
+ }, [src]);
277
295
  const polygons = useMemo2(() => {
278
- if (polygonsProp !== void 0) return polygonsProp;
279
- if (geometry !== void 0) return resolveGeometry(geometry, { size, color });
280
- return [];
281
- }, [polygonsProp, geometry, size, color]);
296
+ const base = polygonsProp !== void 0 ? polygonsProp : src !== void 0 ? loadedPolygons ?? [] : geometry !== void 0 ? resolveGeometry(geometry, { size, color }) : [];
297
+ return autoCenter ? recenterPolygons(base) : base;
298
+ }, [polygonsProp, src, loadedPolygons, geometry, size, color, autoCenter]);
282
299
  const transform = useMemo2(() => ({
283
300
  id,
284
301
  position,
@@ -365,7 +382,7 @@ function GlyphGroundInner({
365
382
  var GlyphGround = memo3(GlyphGroundInner);
366
383
 
367
384
  // src/glyphcss/scene/GlyphHotspot.tsx
368
- import { memo as memo4, useEffect as useEffect3, useMemo as useMemo4, useRef as useRef3, useState } from "react";
385
+ import { memo as memo4, useEffect as useEffect3, useMemo as useMemo4, useRef as useRef3, useState as useState2 } from "react";
369
386
  import { createPortal } from "react-dom";
370
387
  function GlyphHotspotInner({
371
388
  id,
@@ -379,7 +396,7 @@ function GlyphHotspotInner({
379
396
  const hotspotRef = useRef3(null);
380
397
  const onClickRef = useRef3(onClick);
381
398
  onClickRef.current = onClick;
382
- const [overlayEl, setOverlayEl] = useState(null);
399
+ const [overlayEl, setOverlayEl] = useState2(null);
383
400
  const atKey = useMemo4(() => at.join(","), [at]);
384
401
  const sizeKey = size ? size.join(",") : "";
385
402
  useEffect3(() => {
@@ -414,11 +431,11 @@ function GlyphHotspotInner({
414
431
  var GlyphHotspot = memo4(GlyphHotspotInner);
415
432
 
416
433
  // src/glyphcss/scene/useGlyphMesh.ts
417
- import { useEffect as useEffect4, useRef as useRef4, useState as useState2 } from "react";
434
+ import { useEffect as useEffect4, useRef as useRef4, useState as useState3 } from "react";
418
435
  function useGlyphMesh(polygons, options) {
419
436
  const { sceneRef } = useGlyphSceneContext();
420
437
  const meshRef = useRef4(null);
421
- const [loading] = useState2(false);
438
+ const [loading] = useState3(false);
422
439
  useEffect4(() => {
423
440
  const scene = sceneRef.current;
424
441
  if (!scene) return;
@@ -497,6 +514,7 @@ function GlyphPerspectiveCameraInner({
497
514
  rotX,
498
515
  rotY,
499
516
  distance,
517
+ perspective,
500
518
  zoom,
501
519
  stretch,
502
520
  center,
@@ -511,6 +529,7 @@ function GlyphPerspectiveCameraInner({
511
529
  if (rotX !== void 0) opts.rotX = rotX;
512
530
  if (rotY !== void 0) opts.rotY = rotY;
513
531
  if (distance !== void 0) opts.distance = distance;
532
+ if (perspective !== void 0) opts.perspective = perspective;
514
533
  if (zoom !== void 0) opts.zoom = zoom;
515
534
  if (stretch !== void 0) opts.stretch = stretch;
516
535
  if (center !== void 0) opts.center = center;
@@ -532,6 +551,10 @@ function GlyphPerspectiveCameraInner({
532
551
  camera.distance = distance;
533
552
  dirty = true;
534
553
  }
554
+ if (perspective !== void 0 && camera.perspective !== perspective) {
555
+ camera.perspective = perspective;
556
+ dirty = true;
557
+ }
535
558
  if (zoom !== void 0 && camera.zoom !== zoom) {
536
559
  camera.zoom = zoom;
537
560
  dirty = true;
@@ -897,7 +920,7 @@ export {
897
920
  inverseRotateVec3,
898
921
  isAxisAlignedSurfaceNormal,
899
922
  isVoxelCameraCullableNormalGroups,
900
- loadMesh,
923
+ loadMesh2 as loadMesh,
901
924
  mergePolygons,
902
925
  normalFacesCamera,
903
926
  normalizeInvertMultiplier,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glyphcss/react",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "React components for the glyphcss ASCII polygon mesh rendering engine",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -40,8 +40,8 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@glyphcss/core": "^0.0.4",
44
- "glyphcss": "^0.0.4"
43
+ "glyphcss": "^0.0.6",
44
+ "@glyphcss/core": "^0.0.6"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^18.0.0 || ^19.0.0",