ice3 0.2.0 → 0.2.2

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.
Files changed (39) hide show
  1. package/README.md +7 -6
  2. package/dist/_types/assets/ICEGLBReader.d.ts +8 -1
  3. package/dist/_types/assets/ICEPreparedGLB.d.ts +26 -0
  4. package/dist/_types/assets/ICEPreviewGeometryPacket.d.ts +60 -0
  5. package/dist/_types/assets/index.d.ts +3 -0
  6. package/dist/_types/core/camera/ICEPerspectiveCamera.d.ts +8 -2
  7. package/dist/_types/core/geometry/ICEGeometry.d.ts +13 -0
  8. package/dist/_types/core/geometry/ICEIndexedGeometry.d.ts +3 -1
  9. package/dist/_types/core/index.d.ts +2 -2
  10. package/dist/_types/core/material/ICEBasicMaterial.d.ts +52 -0
  11. package/dist/_types/renderer/InstanceBatch.d.ts +7 -0
  12. package/dist/_types/renderer/SceneBounds.d.ts +16 -0
  13. package/dist/_types/renderer/ShadowFrustum.d.ts +20 -0
  14. package/dist/_types/renderer/WebGL2DepthMath.d.ts +22 -0
  15. package/dist/_types/renderer/WebGL2GeometryCache.d.ts +16 -2
  16. package/dist/_types/renderer/WebGL2InstanceBatch.d.ts +1 -1
  17. package/dist/_types/renderer/WebGL2Program.d.ts +68 -0
  18. package/dist/_types/renderer/WebGL2RendererBackend.d.ts +44 -0
  19. package/dist/_types/renderer/WebGL2SceneDepth.d.ts +19 -0
  20. package/dist/_types/renderer/WebGL2Shader.d.ts +11 -0
  21. package/dist/_types/renderer/WebGL2ShadowMap.d.ts +42 -0
  22. package/dist/_types/renderer/WebGL2TextureCache.d.ts +31 -0
  23. package/dist/_types/renderer/WebGL2Uv.d.ts +16 -0
  24. package/dist/_types/renderer/WebGPUDrawStorage.d.ts +1 -0
  25. package/dist/_types/renderer/WebGPUGeometryCache.d.ts +16 -2
  26. package/dist/_types/renderer/WebGPURenderPipeline.d.ts +1 -1
  27. package/dist/_types/renderer/WebGPURendererBackend.d.ts +2 -0
  28. package/dist/_types/renderer/index.d.ts +1 -1
  29. package/dist/_types/renderer/types.d.ts +9 -1
  30. package/dist/_types/runtime/ICE3.d.ts +8 -0
  31. package/dist/_types/runtime/asset/ICEAssetSceneBuilder.d.ts +8 -2
  32. package/dist/_types/runtime/asset/ICEPreviewPacketLoader.d.ts +25 -0
  33. package/dist/_types/runtime/asset/ICETilesetLoader.d.ts +0 -1
  34. package/dist/_types/runtime/index.d.ts +2 -1
  35. package/dist/_types/runtime/input/ICEOrbitController.d.ts +2 -0
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.js +2742 -242
  38. package/dist/index.js.map +4 -4
  39. package/package.json +1 -1
@@ -0,0 +1,42 @@
1
+ import { type ICEBounds } from './ShadowFrustum.js';
2
+ /** 光源方向(与主着色器的 diffuse 保持同一方向)。 */
3
+ export { SHADOW_LIGHT_DIRECTION as LIGHT_DIRECTION } from './ShadowFrustum.js';
4
+ export declare class WebGL2ShadowMap {
5
+ private readonly gl;
6
+ /** 最近一次着色器编译/链接失败的原因,供诊断读取。 */
7
+ lastError: string | null;
8
+ private framebuffer;
9
+ private depthTexture;
10
+ private program;
11
+ private matrixLocation;
12
+ private instancingLocation;
13
+ private matrixScratch;
14
+ private texelWorldValue;
15
+ constructor(gl: WebGL2RenderingContext);
16
+ /** 深度纹理,供主着色器采样。 */
17
+ get texture(): WebGLTexture | null;
18
+ get matrix(): Float32Array;
19
+ /** 一个深度纹素在世界空间的边长(米)。法线偏移按它换算,别用魔数。 */
20
+ get texelWorld(): number;
21
+ /**
22
+ * 按场景包围盒拟合视锥。每帧调用没有意义——场景内容不变时矩阵也不会变,
23
+ * 所以由调用方决定何时重算(包围盒变化或首帧)。
24
+ */
25
+ setBounds(bounds: ICEBounds | null): void;
26
+ /** 绑定阴影帧缓冲,返回是否成功。 */
27
+ begin(): boolean;
28
+ /**
29
+ * 非实例化绘制:矩阵换成 `lightViewProjection × world`,顶点位置直接当世界坐标用。
30
+ *
31
+ * 阴影通道原先只会画实例化批次,瓦片(渲染批次)与落单网格因此完全不投影。
32
+ * 补这两条路径靠的就是这个入口——和 `WebGL2SceneDepth` 同一套写法。
33
+ */
34
+ setMatrix(matrix: Float32Array): void;
35
+ setInstancing(enabled: boolean): void;
36
+ /** 解绑,恢复默认帧缓冲。 */
37
+ end(width: number, height: number): void;
38
+ dispose(): void;
39
+ private createResources;
40
+ private createProgram;
41
+ }
42
+ //# sourceMappingURL=WebGL2ShadowMap.d.ts.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Base-colour texture cache.
3
+ *
4
+ * Materials reference textures by URL; the renderer turns each URL into one
5
+ * `WebGLTexture` the first time a frame needs it and keeps it for later frames.
6
+ * Loading is asynchronous, so the first frames after a URL appears draw with the
7
+ * flat material colour and switch to the texture once the upload lands — a
8
+ * self-correcting behaviour that never blocks the frame loop.
9
+ */
10
+ export type ICEImageLoader = (url: string) => Promise<ImageBitmap>;
11
+ export type ICEWebGL2TextureStats = {
12
+ readonly loaded: number;
13
+ readonly pending: number;
14
+ readonly failed: number;
15
+ };
16
+ /** Default loader: fetch the image and decode it off the main thread. */
17
+ export declare const fetchImageLoader: ICEImageLoader;
18
+ export declare class WebGL2TextureCache {
19
+ private readonly gl;
20
+ private readonly load;
21
+ private readonly onUpload?;
22
+ private readonly entries;
23
+ private disposed;
24
+ constructor(gl: WebGL2RenderingContext, load?: ICEImageLoader, onUpload?: (() => void) | undefined);
25
+ /** Texture for `url`, or `null` while it is still loading (or after failure). */
26
+ texture(url: string): WebGLTexture | null;
27
+ stats(): ICEWebGL2TextureStats;
28
+ dispose(): void;
29
+ private upload;
30
+ }
31
+ //# sourceMappingURL=WebGL2TextureCache.d.ts.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Box-projected texture coordinates.
3
+ *
4
+ * Studio generates geometry procedurally, so meshes reach the renderer without a
5
+ * UV attribute. The projection is derived from the surface instead: each fragment
6
+ * is projected along the dominant axis of its normal, which is stable inside a
7
+ * face and needs no extra vertex channel.
8
+ *
9
+ * This mirrors `box_projected_uvs` in Studio's exporter, so a surface textured in
10
+ * the viewport and the same surface exported as glTF land on the same texels.
11
+ * Coordinates are in metres; tiling is a material concern.
12
+ */
13
+ export type ICEUvScale = readonly [number, number];
14
+ export declare const DEFAULT_UV_SCALE: ICEUvScale;
15
+ export declare function boxProjectedUv(position: readonly [number, number, number], normal: readonly [number, number, number], scale?: ICEUvScale): [number, number];
16
+ //# sourceMappingURL=WebGL2Uv.d.ts.map
@@ -3,6 +3,7 @@ export type ICEWebGPUDrawUniform = Readonly<{
3
3
  color: readonly [number, number, number, number];
4
4
  useVertexColor: boolean;
5
5
  useInstancing: boolean;
6
+ useLighting?: boolean;
6
7
  semanticHighlight?: number;
7
8
  useSemantic?: boolean;
8
9
  selectionBase: number;
@@ -1,5 +1,9 @@
1
- import { type ICEGeometry } from '../core/index.js';
1
+ import { type ICEGeometry, type ICEGeometryBufferUpdate } from '../core/index.js';
2
2
  export interface WebGPUGeometryEntry {
3
+ geometry: ICEGeometry;
4
+ readonly geometryId: string;
5
+ readonly attributeDigest: string;
6
+ readonly topologyDigest: string;
3
7
  readonly vertexBuffer: GPUBuffer;
4
8
  readonly triangleIndexBuffer: GPUBuffer;
5
9
  readonly edgeIndexBuffer: GPUBuffer | null;
@@ -21,15 +25,20 @@ export declare class WebGPUGeometryCache {
21
25
  private readonly entries;
22
26
  private active;
23
27
  private readonly pinned;
28
+ private readonly objectKeys;
29
+ private readonly legacyKeys;
30
+ private objectKeySequence;
24
31
  private readonly inactiveGraceFrames;
25
32
  private readonly maxBytes;
26
33
  private uploads;
34
+ private updatedBytes;
27
35
  private evictions;
28
36
  private frameId;
29
37
  private resourceGeneration;
30
38
  constructor(options: WebGPUGeometryCacheOptions);
31
39
  retain(geometry: ICEGeometry): WebGPUGeometryEntry;
32
- pin(geometry: ICEGeometry): WebGPUGeometryEntry;
40
+ private createEntry;
41
+ pin(geometry: ICEGeometry, update?: ICEGeometryBufferUpdate): WebGPUGeometryEntry;
33
42
  unpin(geometry: ICEGeometry): void;
34
43
  beginFrame(): void;
35
44
  endFrame(): void;
@@ -37,9 +46,14 @@ export declare class WebGPUGeometryCache {
37
46
  dispose(): void;
38
47
  get totalBytes(): number;
39
48
  get uploadCount(): number;
49
+ get updateBytes(): number;
40
50
  get evictionCount(): number;
41
51
  get generation(): number;
42
52
  private enforceBudget;
43
53
  private deleteEntry;
54
+ private applyPositionUpdate;
55
+ private canReuse;
56
+ private sameTopology;
57
+ private keyFor;
44
58
  }
45
59
  //# sourceMappingURL=WebGPUGeometryCache.d.ts.map
@@ -1,5 +1,5 @@
1
1
  export declare const WEBGPU_UNIFORM_STRIDE = 256;
2
- export declare const WEBGPU_UNIFORM_BYTES = 128;
2
+ export declare const WEBGPU_UNIFORM_BYTES = 144;
3
3
  export declare class WebGPURenderPipeline {
4
4
  readonly device: GPUDevice;
5
5
  readonly format: GPUTextureFormat;
@@ -80,6 +80,8 @@ export declare class WebGPURendererBackend implements ICERendererBackend {
80
80
  resize(viewport: ICEViewport, dpr: number): void;
81
81
  setBackgroundColor(color: string): void;
82
82
  prepareBatchGeometry(geometry: ICEGeometry): void;
83
+ prepareGeometry(geometry: ICEGeometry, update?: import('../core/index.js').ICEGeometryBufferUpdate): void;
84
+ releaseGeometry(geometry: ICEGeometry): void;
83
85
  releaseBatchGeometry(geometry: ICEGeometry): void;
84
86
  render(frame: ICEFrame): void;
85
87
  enableProfiling(enabled: boolean): void;
@@ -15,7 +15,7 @@ export { WebGPUBundleCache } from './WebGPUBundleCache.js';
15
15
  export { buildSelectionMask, WebGPUSelectionMaskBuffer, type ICESelectionMaskLayout, } from './WebGPUSelectionMask.js';
16
16
  export { collectWebGPUPickIds, WebGPUPicker, } from './WebGPUPicker.js';
17
17
  export { collectRenderables, selectionIdentity, type ICEGeometryRenderable, } from './Renderables.js';
18
- export { collectInstanceBatches, type ICEInstanceBatch, } from './InstanceBatch.js';
18
+ export { collectInstanceBatches, renderablesOutsideInstanceBatches, type ICEInstanceBatch, } from './InstanceBatch.js';
19
19
  export { queueBatchGeneration } from './ICEWebGL2BatchGenerationUploader.js';
20
20
  export type { ICEFrameStageProfile, } from './RendererProfiler.js';
21
21
  export { RendererProfiler, } from './RendererProfiler.js';
@@ -1,4 +1,4 @@
1
- import type { ICEGeometry, ICEEngineError, ICEPerspectiveCamera, ICEScene } from '../core/index.js';
1
+ import type { ICEGeometry, ICEGeometryBufferUpdate, ICEEngineError, ICEPerspectiveCamera, ICEScene } from '../core/index.js';
2
2
  export type ICEViewport = {
3
3
  readonly x: number;
4
4
  readonly y: number;
@@ -49,11 +49,19 @@ export interface ICERendererBackend {
49
49
  readonly onContextLost?: () => void;
50
50
  readonly onContextRestored?: () => void;
51
51
  readonly onError?: (error: ICEEngineError) => void;
52
+ /** A deferred GPU upload (for example a base-colour texture) just landed. */
53
+ readonly onUploadReady?: () => void;
54
+ /** Directional-light shadows. Off by default: it costs a full extra scene pass. */
55
+ readonly shadows?: boolean;
52
56
  }): void;
53
57
  resize(viewport: ICEViewport, dpr: number): void;
54
58
  setBackgroundColor?(color: string): void;
59
+ /** Clip plane `[nx, ny, nz, d]`: fragments with `dot(world, n) + d < 0` are discarded; `null` disables. */
60
+ setClipPlane?(plane: readonly [number, number, number, number] | null): void;
55
61
  prepareBatchGeometry?(geometry: ICEGeometry): void;
56
62
  releaseBatchGeometry?(geometry: ICEGeometry): void;
63
+ prepareGeometry?(geometry: ICEGeometry, update?: ICEGeometryBufferUpdate): void;
64
+ releaseGeometry?(geometry: ICEGeometry): void;
57
65
  pick?(frame: ICEFrame, point: ICEScreenPoint): Promise<string | undefined>;
58
66
  render(frame: ICEFrame): void;
59
67
  finish?(): Promise<void>;
@@ -72,6 +72,7 @@ export declare class ICE3 extends ICEEventDispatcher {
72
72
  private generatedOverlayCanvas;
73
73
  private scene;
74
74
  private camera;
75
+ private clipPlane;
75
76
  private viewport;
76
77
  private dpr;
77
78
  private frameId;
@@ -96,8 +97,15 @@ export declare class ICE3 extends ICEEventDispatcher {
96
97
  setScene(scene: ICEScene): this;
97
98
  setCamera(camera: ICEPerspectiveCamera): this;
98
99
  setBackgroundColor(color: string): this;
100
+ /**
101
+ * Section plane `[nx, ny, nz, d]`: fragments with `dot(world, n) + d < 0`
102
+ * are discarded. `null` (or a zero plane) disables clipping.
103
+ */
104
+ setClipPlane(plane: readonly [number, number, number, number] | null): this;
99
105
  prepareRenderBatchGeometry(geometry: ICEGeometry): this;
100
106
  releaseRenderBatchGeometry(geometry: ICEGeometry): this;
107
+ prepareGeometry(geometry: ICEGeometry, update?: import('../core/index.js').ICEGeometryBufferUpdate): this;
108
+ releaseGeometry(geometry: ICEGeometry): this;
101
109
  addLayer(layer: ICE2DLayer): this;
102
110
  removeLayer(layer: ICE2DLayer): this;
103
111
  start(): this;
@@ -1,9 +1,15 @@
1
- import type { ICEPreparedAssetSnapshot, ICEPreparedStats } from '../../assets/index.js';
2
- import { ICEScene, type ICEGeometryBounds } from '../../core/index.js';
1
+ import type { ICEPreparedAssetSnapshot, ICEPreparedStats, ICEPreviewGeometryPacket } from '../../assets/index.js';
2
+ import { ICEIndexedGeometry, ICEScene, type ICEGeometryBounds, type ICEGeometryBufferUpdate } from '../../core/index.js';
3
3
  export interface ICEBuiltAsset {
4
4
  readonly scene: ICEScene;
5
5
  readonly bounds: ICEGeometryBounds;
6
6
  readonly stats: ICEPreparedStats;
7
7
  }
8
+ export interface ICEBuiltPreviewPacket {
9
+ readonly scene: ICEScene;
10
+ readonly geometries: ReadonlyMap<string, ICEIndexedGeometry>;
11
+ readonly geometryUpdates: ReadonlyMap<string, ICEGeometryBufferUpdate>;
12
+ }
8
13
  export declare function buildAssetScene(snapshot: ICEPreparedAssetSnapshot): ICEBuiltAsset;
14
+ export declare function buildPreviewPacketScene(packet: ICEPreviewGeometryPacket, previousGeometries?: ReadonlyMap<string, ICEIndexedGeometry>): ICEBuiltPreviewPacket;
9
15
  //# sourceMappingURL=ICEAssetSceneBuilder.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { type ICEPreviewGeometryPacket } from '../../assets/index.js';
2
+ import type { ICEGeometryBufferUpdate, ICEIndexedGeometry, ICEScene } from '../../core/index.js';
3
+ export type ICEPreviewPacketFallbackReason = 'packet-unavailable' | 'packet-invalid' | 'packet-revision-mismatch';
4
+ export type ICEPreviewPacketLoadResult = {
5
+ readonly kind: 'packet';
6
+ readonly packet: ICEPreviewGeometryPacket;
7
+ } | {
8
+ readonly kind: 'fallback';
9
+ readonly reason: ICEPreviewPacketFallbackReason;
10
+ };
11
+ export interface ICEPreviewPacketLoaderOptions {
12
+ readonly fetch?: typeof fetch;
13
+ readonly pinGeometry?: (geometry: ICEIndexedGeometry, update?: ICEGeometryBufferUpdate) => void;
14
+ }
15
+ export declare class ICEPreviewPacketLoader {
16
+ private readonly fetcher;
17
+ private readonly pinGeometry;
18
+ private geometries;
19
+ private publishedScene;
20
+ constructor(options?: ICEPreviewPacketLoaderOptions | typeof fetch);
21
+ get scene(): ICEScene | null;
22
+ get currentGeometries(): ReadonlyMap<string, ICEIndexedGeometry>;
23
+ load(url: string, current?: ICEPreviewGeometryPacket): Promise<ICEPreviewPacketLoadResult>;
24
+ }
25
+ //# sourceMappingURL=ICEPreviewPacketLoader.d.ts.map
@@ -154,7 +154,6 @@ export declare class ICETilesetHandle extends ICEEventDispatcher {
154
154
  private enterCameraMotion;
155
155
  private promoteReadyVisibleTargets;
156
156
  private lodReadyVisibleCoverage;
157
- private reconcileSelectionVisibility;
158
157
  private rejectReadyIfVisibleSetFailed;
159
158
  private updateBudgetWarning;
160
159
  private residentBudgetReached;
@@ -25,10 +25,11 @@ export { ICERenderBatch, type ICERenderBatchOptions, } from './asset/ICERenderBa
25
25
  export { ICEAssetLoader, type ICEAssetHandle, type ICEAssetLoaderOptions, type ICEAssetLoadOptions, } from './asset/ICEAssetLoader.js';
26
26
  export { ICETilesetHandle, ICETilesetLoader, type ICETilesetEvent, type ICETilesetLoaderOptions, type ICETilesetOpenOptions, type ICETilesetStats, type ICETilesetTileState, } from './asset/ICETilesetLoader.js';
27
27
  export { ICETilesetScheduler, type ICETilesetSchedulerOptions, type ICETilesetWorkSet, type ICETilesetWorkSetInput, } from './asset/ICETilesetScheduler.js';
28
+ export { ICEPreviewPacketLoader, type ICEPreviewPacketFallbackReason, type ICEPreviewPacketLoadResult, type ICEPreviewPacketLoaderOptions, } from './asset/ICEPreviewPacketLoader.js';
28
29
  export { ICELodSelector, type ICELodSelection, type ICELodSelectionInput, } from './asset/ICELodSelector.js';
29
30
  export type { ICELodStats } from './asset/ICETilesetLoader.js';
30
31
  export { collectSceneItems, raycastSceneNode, type ICERay, type ICESceneItem, type ICESceneQuery, } from './query/ICESceneQuery.js';
31
- export type { ICEPreparedContract, ICEPreparedStats, } from '../assets/index.js';
32
+ export type { ICEPreparedContract, ICEPreparedStats, ICEPreviewGeometryPacket, } from '../assets/index.js';
32
33
  export { ICEAdaptiveRenderBatchController, } from './batching/ICEAdaptiveRenderBatchController.js';
33
34
  export type { ICEAdaptiveBatchExecutionResult, ICEAdaptiveBatchRequest, ICEAdaptiveBatchRequestResult, ICERenderBatchingMode, ICERenderBatchingOptions, } from './batching/ICEAdaptiveRenderBatchController.js';
34
35
  export { ICERenderBatchPlanner } from './batching/ICERenderBatchPlanner.js';
@@ -7,6 +7,8 @@ export declare class ICEOrbitController {
7
7
  private yaw;
8
8
  private pitch;
9
9
  private distance;
10
+ private readonly minDistance;
11
+ private readonly maxDistance;
10
12
  private targetYaw;
11
13
  private targetPitch;
12
14
  private targetDistance;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { ICEBasicMaterial, ICEBoxGeometry, ICEIndexedGeometry, ICEEngineError, ICEAssetLoader, ICETilesetHandle, ICETilesetLoader, ICELabel, ICEMesh, ICENode, ICEOrbitController, ICEPerspectiveCamera, ICEScene, ICEScreenLayer, ICETypeRegistry, ICEWorldLayer, ICE3, deserializeScene, serializeScene, } from './_types/runtime/index.js';
2
- export type { ICEDeserializedScene, ICEDiagnostic, ICEDiagnosticSeverity, ICEEngineDiagnostics, ICE3Options, ICE3RendererPreference, ICE3RendererSelection, ICEInputEvent, ICEInputTarget, ICEKeyboardInputEvent, ICEProjectedPoint, ICEAssetHandle, ICEAssetLoaderOptions, ICEAssetLoadOptions, ICETilesetEvent, ICETilesetLoaderOptions, ICETilesetOpenOptions, ICETilesetStats, ICETilesetTileState, ICEPreparedContract, ICEPreparedStats, ICERenderBatchingOptions, ICESerializedScene, ICEGeometry, ICEGeometryBounds, ICEIndexedGeometryOptions, ICEMatrix4Tuple, ICEPickOutcome, } from './_types/runtime/index.js';
1
+ export { ICEBasicMaterial, ICEBoxGeometry, ICEIndexedGeometry, ICEEngineError, ICEAssetLoader, ICETilesetHandle, ICETilesetLoader, ICELabel, ICEMesh, ICENode, ICEOrbitController, ICEPreviewPacketLoader, ICEPerspectiveCamera, ICEScene, ICEScreenLayer, ICETypeRegistry, ICEWorldLayer, ICE3, collectSceneItems, deserializeScene, serializeScene, } from './_types/runtime/index.js';
2
+ export type { ICEDeserializedScene, ICEDiagnostic, ICEDiagnosticSeverity, ICEEngineDiagnostics, ICE3Options, ICE3RendererPreference, ICE3RendererSelection, ICEInputEvent, ICEInputTarget, ICEKeyboardInputEvent, ICEProjectedPoint, ICEAssetHandle, ICEAssetLoaderOptions, ICEAssetLoadOptions, ICETilesetEvent, ICETilesetLoaderOptions, ICETilesetOpenOptions, ICETilesetStats, ICETilesetTileState, ICEPreparedContract, ICEPreparedStats, ICERenderBatchingOptions, ICESerializedScene, ICEGeometry, ICEGeometryBounds, ICEIndexedGeometryOptions, ICEMatrix4Tuple, ICEPickOutcome, ICEPreviewPacketFallbackReason, ICEPreviewPacketLoadResult, ICEPreviewPacketLoaderOptions, ICEPreviewGeometryPacket, } from './_types/runtime/index.js';
3
3
  //# sourceMappingURL=index.d.ts.map