@layoutit/polycss 0.0.1 → 0.2.0

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
@@ -95,7 +95,7 @@ poly-polygon.hover { filter: brightness(1.5); }
95
95
  | `ambient-intensity` | Ambient light intensity |
96
96
  | `ambient-color` | Ambient light color hex |
97
97
  | `texture-lighting` | `"baked"` or `"dynamic"` |
98
- | `atlas-scale` | Raster scale for generated atlas pages; lower values reduce memory/detail |
98
+ | `atlas-scale` | Atlas bitmap budget and compositor sprite size; lower numeric values reduce memory/detail |
99
99
 
100
100
  For pointer drag, wheel zoom, and autorotate, drop a `<poly-orbit-controls>` child inside the scene (or wire `createPolyOrbitControls(scene, ...)` against the imperative API). For pan-first map-style input use `<poly-map-controls>` / `createPolyMapControls` instead. Mirrors Three.js's split between camera state (`<poly-scene>`) and camera input.
101
101
 
@@ -161,7 +161,7 @@ mesh.dispose();
161
161
  | `directionalLight` | `PolyDirectionalLight` | Directional light config |
162
162
  | `ambientLight` | `PolyAmbientLight` | Ambient light config |
163
163
  | `textureLighting` | `"baked" \| "dynamic"` | Texture lighting mode |
164
- | `atlasScale` | `number \| "auto"` | Raster scale for generated atlas pages |
164
+ | `textureQuality` | `number \| "auto"` | Atlas bitmap budget and compositor sprite size |
165
165
  | `autoCenter` | `boolean` | Rotate around the union bbox center of added meshes |
166
166
 
167
167
  Returns a `PolySceneHandle`:
@@ -177,6 +177,7 @@ interface PolySceneHandle {
177
177
  **`loadMesh(url, options?)`**
178
178
 
179
179
  Fetches and parses a mesh by URL (dispatches by extension: `.obj`, `.glb`, `.gltf`, `.vox`). Returns `Promise<ParseResult>`.
180
+ Mesh optimization defaults to `meshResolution: "lossy"`; pass `"lossless"` for exact planar candidates only.
180
181
 
181
182
  ## Subpath imports
182
183
 
@@ -1,6 +1,13 @@
1
1
  import { Polygon, Vec3, ParseResult, PolyDirectionalLight, PolyAmbientLight, PolyTextureLightingMode, CameraHandle } from '@layoutit/polycss-core';
2
2
 
3
- type AtlasScale = number | "auto";
3
+ type TextureQuality = number | "auto";
4
+ type PolyRenderStrategy = "b" | "i" | "u";
5
+ interface PolyRenderStrategiesOption {
6
+ /** Strategies to skip; polygons that would normally use them fall through
7
+ * the chain (b → i → s, u → i → s, i → s). `<s>` is the universal
8
+ * fallback and cannot be disabled — textured polys have no other path. */
9
+ disable?: readonly PolyRenderStrategy[];
10
+ }
4
11
 
5
12
  /**
6
13
  * createPolyScene — imperative scene API. The vanilla counterpart to
@@ -50,8 +57,17 @@ interface PolySceneOptions {
50
57
  ambientLight?: PolyAmbientLight;
51
58
  /** Textured polygon lighting mode. Defaults to "baked". */
52
59
  textureLighting?: PolyTextureLightingMode;
53
- /** Raster scale for generated atlas pages. `"auto"` reduces large atlases. */
54
- atlasScale?: AtlasScale;
60
+ /** Atlas bitmap budget and CSS sprite size. `"auto"` uses a
61
+ * device-appropriate memory budget (~4 MB mobile / ~16 MB desktop) and
62
+ * desktop/mobile sprite sizing. Numeric values 0.1..1 force an explicit
63
+ * raster scale and the 64px sprite. */
64
+ textureQuality?: TextureQuality;
65
+ /**
66
+ * Skip specific render-strategy tags. Polygons that would normally use a
67
+ * disabled tag fall through the chain (b → i → s, u → i → s, i → s).
68
+ * `<s>` is the universal fallback and cannot be disabled.
69
+ */
70
+ strategies?: PolyRenderStrategiesOption;
55
71
  /**
56
72
  * When `true`, rotation pivots around the union bbox of all added meshes
57
73
  * instead of world (0,0,0). The scene wraps polygons in an inner div
@@ -59,6 +75,24 @@ interface PolySceneOptions {
59
75
  * or `setOptions` is called. Mirrors React's `<PolyScene autoCenter>`.
60
76
  */
61
77
  autoCenter?: boolean;
78
+ /**
79
+ * Shadow appearance for meshes with `castShadow: true`. Only applies in
80
+ * dynamic lighting mode — baked mode does not emit shadow leaves.
81
+ * Defaults: `{ color: "#000000", opacity: 0.25, lift: 0.05 }`.
82
+ */
83
+ shadow?: {
84
+ /** Shadow color as a CSS hex string. Default: `"#000000"`. */
85
+ color?: string;
86
+ /** Shadow opacity 0..1. Default: `0.25`. */
87
+ opacity?: number;
88
+ /**
89
+ * Raises the shadow plane slightly above the model bbox floor along
90
+ * +Z (Z up) so it sits on top of a receiver mesh placed at the bbox
91
+ * bottom, rather than below it where the receiver would occlude the
92
+ * shadow. In world units. Default: `0.05`.
93
+ */
94
+ lift?: number;
95
+ };
62
96
  }
63
97
  interface PolyMeshTransform {
64
98
  /** Stable identifier — exposed on the handle and reflected on the
@@ -85,6 +119,15 @@ interface PolyMeshTransform {
85
119
  * shift the camera target when toggled. Defaults to `false`.
86
120
  */
87
121
  excludeFromAutoCenter?: boolean;
122
+ /**
123
+ * When `true` and the scene is in dynamic lighting mode, the renderer emits
124
+ * a flat shadow leaf sibling for each non-textured polygon. The shadow is
125
+ * projected onto the ground plane (min world-Y of all casting meshes) along
126
+ * the CSS-space light direction (driven by `--clx/--cly/--clz` vars). Zero
127
+ * JS in the render loop — the projection matrix is a CSS var that recomputes
128
+ * via `calc()` when the light vars change. Defaults to `false`.
129
+ */
130
+ castShadow?: boolean;
88
131
  }
89
132
  interface PolyMeshHandle {
90
133
  /** The polygons that were loaded after normalization and automatic merge. */
@@ -109,6 +152,15 @@ interface PolyMeshHandle {
109
152
  stableDom?: boolean;
110
153
  recomputeAutoCenter?: boolean;
111
154
  }): void;
155
+ /**
156
+ * Update a single polygon in place. `target` is either a polygon
157
+ * reference (as returned by `getPolygons()`) or its index. `partial`
158
+ * fields are merged onto the polygon; the mesh is then re-rendered.
159
+ * Skips the merge pass, so this is cheaper than `setPolygons` for
160
+ * targeted edits like color picker updates from an inspector UI.
161
+ * Silently no-ops if `target` isn't found.
162
+ */
163
+ updatePolygon(target: Polygon | number, partial: Partial<Polygon>): void;
112
164
  /** Update transform without re-parsing. */
113
165
  setTransform(t: Partial<PolyMeshTransform>): void;
114
166
  /** Revoke any blob URLs the parse created. Idempotent. */
@@ -156,10 +208,10 @@ interface PolySceneHandle {
156
208
  readonly host: HTMLElement;
157
209
  /**
158
210
  * Snapshot of the current options (camera, lighting, merge, autoCenter,
159
- * textureLighting, atlasScale, perspective). Returned by reference, so
160
- * callers must treat it as read-only — mutations won't propagate. Used
161
- * by helpers that need to read the current camera state without
162
- * duplicating it.
211
+ * textureLighting, textureQuality, and perspective). Returned by reference,
212
+ * so callers must treat it as read-only —
213
+ * mutations won't propagate. Used by helpers that need to read the current
214
+ * camera state without duplicating it.
163
215
  */
164
216
  getOptions(): Readonly<PolySceneOptions>;
165
217
  /** Snapshot of mesh handles currently in the scene (insertion order).
@@ -364,4 +416,4 @@ declare class PolySelectElement extends ELEMENT_BASE {
364
416
  attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
365
417
  }
366
418
 
367
- export { type PolySceneHandle as P, type PolyMeshHandle as a, type PolyCameraOptions as b, PolyMapControlsElement as c, PolyMeshElement as d, type PolyMeshTransform as e, PolyOrbitControlsElement as f, PolyOrthographicCameraElement as g, type PolyOrthographicCameraHandle as h, type PolyOrthographicCameraOptions as i, PolyPerspectiveCameraElement as j, type PolyPerspectiveCameraHandle as k, type PolyPerspectiveCameraOptions as l, PolyPolygonElement as m, PolySceneElement as n, type PolySceneOptions as o, PolySelectElement as p, PolyTransformControlsElement as q, createPolyOrthographicCamera as r, createPolyPerspectiveCamera as s, createPolyScene as t };
419
+ export { type PolySceneHandle as P, type TextureQuality as T, type PolyMeshHandle as a, type PolyCameraOptions as b, PolyMapControlsElement as c, PolyMeshElement as d, type PolyMeshTransform as e, PolyOrbitControlsElement as f, PolyOrthographicCameraElement as g, type PolyOrthographicCameraHandle as h, type PolyOrthographicCameraOptions as i, PolyPerspectiveCameraElement as j, type PolyPerspectiveCameraHandle as k, type PolyPerspectiveCameraOptions as l, PolyPolygonElement as m, type PolyRenderStrategiesOption as n, type PolyRenderStrategy as o, PolySceneElement as p, type PolySceneOptions as q, PolySelectElement as r, PolyTransformControlsElement as s, createPolyOrthographicCamera as t, createPolyPerspectiveCamera as u, createPolyScene as v };
@@ -1,6 +1,13 @@
1
1
  import { Polygon, Vec3, ParseResult, PolyDirectionalLight, PolyAmbientLight, PolyTextureLightingMode, CameraHandle } from '@layoutit/polycss-core';
2
2
 
3
- type AtlasScale = number | "auto";
3
+ type TextureQuality = number | "auto";
4
+ type PolyRenderStrategy = "b" | "i" | "u";
5
+ interface PolyRenderStrategiesOption {
6
+ /** Strategies to skip; polygons that would normally use them fall through
7
+ * the chain (b → i → s, u → i → s, i → s). `<s>` is the universal
8
+ * fallback and cannot be disabled — textured polys have no other path. */
9
+ disable?: readonly PolyRenderStrategy[];
10
+ }
4
11
 
5
12
  /**
6
13
  * createPolyScene — imperative scene API. The vanilla counterpart to
@@ -50,8 +57,17 @@ interface PolySceneOptions {
50
57
  ambientLight?: PolyAmbientLight;
51
58
  /** Textured polygon lighting mode. Defaults to "baked". */
52
59
  textureLighting?: PolyTextureLightingMode;
53
- /** Raster scale for generated atlas pages. `"auto"` reduces large atlases. */
54
- atlasScale?: AtlasScale;
60
+ /** Atlas bitmap budget and CSS sprite size. `"auto"` uses a
61
+ * device-appropriate memory budget (~4 MB mobile / ~16 MB desktop) and
62
+ * desktop/mobile sprite sizing. Numeric values 0.1..1 force an explicit
63
+ * raster scale and the 64px sprite. */
64
+ textureQuality?: TextureQuality;
65
+ /**
66
+ * Skip specific render-strategy tags. Polygons that would normally use a
67
+ * disabled tag fall through the chain (b → i → s, u → i → s, i → s).
68
+ * `<s>` is the universal fallback and cannot be disabled.
69
+ */
70
+ strategies?: PolyRenderStrategiesOption;
55
71
  /**
56
72
  * When `true`, rotation pivots around the union bbox of all added meshes
57
73
  * instead of world (0,0,0). The scene wraps polygons in an inner div
@@ -59,6 +75,24 @@ interface PolySceneOptions {
59
75
  * or `setOptions` is called. Mirrors React's `<PolyScene autoCenter>`.
60
76
  */
61
77
  autoCenter?: boolean;
78
+ /**
79
+ * Shadow appearance for meshes with `castShadow: true`. Only applies in
80
+ * dynamic lighting mode — baked mode does not emit shadow leaves.
81
+ * Defaults: `{ color: "#000000", opacity: 0.25, lift: 0.05 }`.
82
+ */
83
+ shadow?: {
84
+ /** Shadow color as a CSS hex string. Default: `"#000000"`. */
85
+ color?: string;
86
+ /** Shadow opacity 0..1. Default: `0.25`. */
87
+ opacity?: number;
88
+ /**
89
+ * Raises the shadow plane slightly above the model bbox floor along
90
+ * +Z (Z up) so it sits on top of a receiver mesh placed at the bbox
91
+ * bottom, rather than below it where the receiver would occlude the
92
+ * shadow. In world units. Default: `0.05`.
93
+ */
94
+ lift?: number;
95
+ };
62
96
  }
63
97
  interface PolyMeshTransform {
64
98
  /** Stable identifier — exposed on the handle and reflected on the
@@ -85,6 +119,15 @@ interface PolyMeshTransform {
85
119
  * shift the camera target when toggled. Defaults to `false`.
86
120
  */
87
121
  excludeFromAutoCenter?: boolean;
122
+ /**
123
+ * When `true` and the scene is in dynamic lighting mode, the renderer emits
124
+ * a flat shadow leaf sibling for each non-textured polygon. The shadow is
125
+ * projected onto the ground plane (min world-Y of all casting meshes) along
126
+ * the CSS-space light direction (driven by `--clx/--cly/--clz` vars). Zero
127
+ * JS in the render loop — the projection matrix is a CSS var that recomputes
128
+ * via `calc()` when the light vars change. Defaults to `false`.
129
+ */
130
+ castShadow?: boolean;
88
131
  }
89
132
  interface PolyMeshHandle {
90
133
  /** The polygons that were loaded after normalization and automatic merge. */
@@ -109,6 +152,15 @@ interface PolyMeshHandle {
109
152
  stableDom?: boolean;
110
153
  recomputeAutoCenter?: boolean;
111
154
  }): void;
155
+ /**
156
+ * Update a single polygon in place. `target` is either a polygon
157
+ * reference (as returned by `getPolygons()`) or its index. `partial`
158
+ * fields are merged onto the polygon; the mesh is then re-rendered.
159
+ * Skips the merge pass, so this is cheaper than `setPolygons` for
160
+ * targeted edits like color picker updates from an inspector UI.
161
+ * Silently no-ops if `target` isn't found.
162
+ */
163
+ updatePolygon(target: Polygon | number, partial: Partial<Polygon>): void;
112
164
  /** Update transform without re-parsing. */
113
165
  setTransform(t: Partial<PolyMeshTransform>): void;
114
166
  /** Revoke any blob URLs the parse created. Idempotent. */
@@ -156,10 +208,10 @@ interface PolySceneHandle {
156
208
  readonly host: HTMLElement;
157
209
  /**
158
210
  * Snapshot of the current options (camera, lighting, merge, autoCenter,
159
- * textureLighting, atlasScale, perspective). Returned by reference, so
160
- * callers must treat it as read-only — mutations won't propagate. Used
161
- * by helpers that need to read the current camera state without
162
- * duplicating it.
211
+ * textureLighting, textureQuality, and perspective). Returned by reference,
212
+ * so callers must treat it as read-only —
213
+ * mutations won't propagate. Used by helpers that need to read the current
214
+ * camera state without duplicating it.
163
215
  */
164
216
  getOptions(): Readonly<PolySceneOptions>;
165
217
  /** Snapshot of mesh handles currently in the scene (insertion order).
@@ -364,4 +416,4 @@ declare class PolySelectElement extends ELEMENT_BASE {
364
416
  attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
365
417
  }
366
418
 
367
- export { type PolySceneHandle as P, type PolyMeshHandle as a, type PolyCameraOptions as b, PolyMapControlsElement as c, PolyMeshElement as d, type PolyMeshTransform as e, PolyOrbitControlsElement as f, PolyOrthographicCameraElement as g, type PolyOrthographicCameraHandle as h, type PolyOrthographicCameraOptions as i, PolyPerspectiveCameraElement as j, type PolyPerspectiveCameraHandle as k, type PolyPerspectiveCameraOptions as l, PolyPolygonElement as m, PolySceneElement as n, type PolySceneOptions as o, PolySelectElement as p, PolyTransformControlsElement as q, createPolyOrthographicCamera as r, createPolyPerspectiveCamera as s, createPolyScene as t };
419
+ export { type PolySceneHandle as P, type TextureQuality as T, type PolyMeshHandle as a, type PolyCameraOptions as b, PolyMapControlsElement as c, PolyMeshElement as d, type PolyMeshTransform as e, PolyOrbitControlsElement as f, PolyOrthographicCameraElement as g, type PolyOrthographicCameraHandle as h, type PolyOrthographicCameraOptions as i, PolyPerspectiveCameraElement as j, type PolyPerspectiveCameraHandle as k, type PolyPerspectiveCameraOptions as l, PolyPolygonElement as m, type PolyRenderStrategiesOption as n, type PolyRenderStrategy as o, PolySceneElement as p, type PolySceneOptions as q, PolySelectElement as r, PolyTransformControlsElement as s, createPolyOrthographicCamera as t, createPolyPerspectiveCamera as u, createPolyScene as v };