@webspatial/core-sdk 1.0.4 → 1.0.5

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 (82) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +112 -81
  3. package/dist/iife/index.d.ts +683 -561
  4. package/dist/iife/index.global.js +3 -4
  5. package/dist/iife/index.global.js.map +1 -1
  6. package/dist/index.d.ts +683 -561
  7. package/dist/index.js +2175 -1291
  8. package/dist/index.js.map +1 -1
  9. package/package.json +7 -4
  10. package/src/JSBCommand.ts +631 -0
  11. package/src/Spatial.ts +68 -0
  12. package/src/SpatialObject.ts +46 -0
  13. package/src/SpatialScene.ts +75 -0
  14. package/src/SpatialSession.ts +187 -0
  15. package/src/SpatialWebEvent.ts +23 -0
  16. package/src/SpatialWebEventCreator.ts +12 -0
  17. package/src/Spatialized2DElement.ts +51 -0
  18. package/src/SpatializedDynamic3DElement.ts +30 -0
  19. package/src/SpatializedElement.ts +331 -0
  20. package/src/SpatializedElementCreator.ts +45 -0
  21. package/src/SpatializedStatic3DElement.ts +111 -0
  22. package/src/WebMsgCommand.ts +88 -0
  23. package/src/index.ts +23 -1
  24. package/src/platform-adapter/CommandResultUtils.ts +22 -0
  25. package/src/platform-adapter/android/AndroidPlatform.ts +133 -0
  26. package/src/platform-adapter/index.ts +21 -0
  27. package/src/platform-adapter/interface.ts +36 -0
  28. package/src/platform-adapter/ssr/SSRPlatform.ts +43 -0
  29. package/src/platform-adapter/vision-os/VisionOSPlatform.ts +77 -0
  30. package/src/reality/component/ModelComponent.ts +11 -0
  31. package/src/reality/component/SpatialComponent.ts +17 -0
  32. package/src/reality/component/index.ts +2 -0
  33. package/src/reality/entity/SpatialEntity.ts +255 -0
  34. package/src/reality/entity/SpatialModelEntity.ts +15 -0
  35. package/src/reality/entity/index.ts +2 -0
  36. package/src/reality/geometry/SpatialBoxGeometry.ts +12 -0
  37. package/src/reality/geometry/SpatialConeGeometry.ts +15 -0
  38. package/src/reality/geometry/SpatialCylinderGeometry.ts +15 -0
  39. package/src/reality/geometry/SpatialGeometry.ts +12 -0
  40. package/src/reality/geometry/SpatialPlaneGeometry.ts +15 -0
  41. package/src/reality/geometry/SpatialSphereGeometry.ts +15 -0
  42. package/src/reality/geometry/index.ts +6 -0
  43. package/src/reality/index.ts +5 -0
  44. package/src/reality/material/SpatialMaterial.ts +14 -0
  45. package/src/reality/material/SpatialUnlitMaterial.ts +16 -0
  46. package/src/reality/material/index.ts +2 -0
  47. package/src/reality/realityCreator.ts +94 -0
  48. package/src/reality/resource/SpatialModelAsset.ts +11 -0
  49. package/src/reality/resource/index.ts +1 -0
  50. package/src/scene-polyfill.test.ts +376 -0
  51. package/src/scene-polyfill.ts +359 -0
  52. package/src/spatial-window-polyfill.ts +182 -0
  53. package/src/ssr-polyfill.ts +3 -0
  54. package/src/types/global.d.ts +33 -1
  55. package/src/types/internal.ts +13 -0
  56. package/src/types/types.ts +380 -0
  57. package/src/utils.ts +61 -0
  58. package/tsconfig.json +1 -1
  59. package/vitest.config.ts +8 -0
  60. package/src/core/Spatial.ts +0 -50
  61. package/src/core/SpatialEntity.ts +0 -147
  62. package/src/core/SpatialHelper.ts +0 -230
  63. package/src/core/SpatialObject.ts +0 -26
  64. package/src/core/SpatialSession.ts +0 -457
  65. package/src/core/SpatialTransform.ts +0 -26
  66. package/src/core/SpatialWindowContainer.ts +0 -59
  67. package/src/core/component/EventSpatialComponent.ts +0 -32
  68. package/src/core/component/SpatialComponent.ts +0 -26
  69. package/src/core/component/SpatialInputComponent.ts +0 -24
  70. package/src/core/component/SpatialModel3DComponent.ts +0 -223
  71. package/src/core/component/SpatialModelComponent.ts +0 -39
  72. package/src/core/component/SpatialViewComponent.ts +0 -32
  73. package/src/core/component/SpatialWindowComponent.ts +0 -177
  74. package/src/core/component/index.ts +0 -14
  75. package/src/core/index.ts +0 -10
  76. package/src/core/private/WebSpatial.ts +0 -383
  77. package/src/core/private/remote-command/RemoteCommand.ts +0 -15
  78. package/src/core/private/remote-command/index.ts +0 -1
  79. package/src/core/resource/SpatialMeshResource.ts +0 -6
  80. package/src/core/resource/SpatialPhysicallyBasedMaterialResource.ts +0 -42
  81. package/src/core/resource/index.ts +0 -2
  82. package/src/core/types.ts +0 -32
package/dist/index.d.ts CHANGED
@@ -1,225 +1,216 @@
1
- type WindowStyle = 'Plain' | 'Volumetric';
2
- interface WindowContainerOptions {
3
- defaultSize?: {
4
- width: number;
5
- height: number;
6
- };
7
- resizability?: {
8
- minWidth?: number;
9
- minHeight?: number;
10
- maxWidth?: number;
11
- maxHeight?: number;
12
- };
13
- }
14
- type LoadingMethodKind = 'show' | 'hide';
15
- interface sceneDataShape {
16
- method?: 'createRoot' | 'showRoot';
17
- sceneConfig?: WindowContainerOptions;
18
- url?: string;
19
- window: Window;
20
- }
21
- interface sceneDataJSBShape {
22
- method?: 'createRoot' | 'showRoot';
23
- sceneConfig?: WindowContainerOptions;
24
- url?: string;
25
- windowID?: string;
26
- windowContainerID?: string;
27
- }
28
-
29
- declare global {
30
- interface Window {
31
- __WebSpatialData: {
32
- androidNativeMessage: Function;
33
- getNativeVersion: Function;
34
- };
35
- __SpatialWebEvent: Function;
36
- webkit: any;
37
- __WebSpatialUnloaded: boolean;
38
- _webSpatialID: string;
39
- _webSpatialGroupID: string;
40
- _webSpatialParentGroupID: string;
41
- WebSpatailNativeVersion: string;
42
- }
43
- }
44
- declare class WindowContainer {
45
- id: string;
46
- }
47
- declare class WebSpatialResource {
48
- id: string;
49
- windowContainerId: string;
50
- data: any;
51
- receiveEvent(): void;
52
- }
53
-
54
1
  /**
55
2
  * @hidden
56
3
  * Parent class of spatial objects, should not be used directly
57
4
  */
58
5
  declare class SpatialObject {
59
6
  /** @hidden */
60
- _resource: WebSpatialResource;
7
+ readonly id: string;
61
8
  /** @hidden */
62
9
  constructor(
63
10
  /** @hidden */
64
- _resource: WebSpatialResource);
65
- /**
66
- * Marks resource to be released (it should no longer be used)
67
- */
68
- destroy(): Promise<void>;
69
- name: string;
70
- protected onDestroy(): Promise<void>;
11
+ id: string);
12
+ name?: string;
13
+ isDestroyed: boolean;
14
+ inspect(): Promise<any>;
15
+ destroy(): Promise<any>;
16
+ protected onDestroy(): void;
71
17
  }
72
18
 
73
- declare class Vec3 {
74
- x: number;
75
- y: number;
76
- z: number;
77
- constructor(x?: number, y?: number, z?: number);
19
+ interface CommandResult {
20
+ success: boolean;
21
+ data: any;
22
+ errorCode: string | undefined;
23
+ errorMessage: string | undefined;
78
24
  }
79
- declare class Vec4 {
80
- x: number;
81
- y: number;
82
- z: number;
83
- w: number;
84
- constructor(x?: number, y?: number, z?: number, w?: number);
25
+ interface WebSpatialProtocolResult extends CommandResult {
26
+ success: boolean;
27
+ data: {
28
+ windowProxy: WindowProxy;
29
+ id: string;
30
+ } | undefined;
31
+ errorCode: string | undefined;
32
+ errorMessage: string | undefined;
85
33
  }
86
- /**
87
- * Transform containing position, orientation and scale
88
- */
89
- declare class SpatialTransform {
90
- position: Vec3;
91
- /** Quaternion value for x,y,z,w */
92
- orientation: Vec4;
93
- scale: Vec3;
34
+
35
+ declare class SpatialGeometry extends SpatialObject {
36
+ id: string;
37
+ options: SpatialGeometryOptions;
38
+ static type: SpatialGeometryType;
39
+ constructor(id: string, options: SpatialGeometryOptions);
94
40
  }
95
41
 
96
- /**
97
- * Anchored window managed by the OS
98
- */
99
- declare class SpatialWindowContainer {
100
- /** @hidden */
101
- _wg: WindowContainer;
102
- /** @hidden */
103
- constructor(
104
- /** @hidden */
105
- _wg: WindowContainer);
106
- /**
107
- * @hidden
108
- * Sets sets the open configuration for opening new window containers
109
- * @param options style options
110
- */
111
- _setOpenSettings(options: {
112
- resolution: {
113
- width: number;
114
- height: number;
115
- };
116
- }): Promise<void>;
117
- /**
118
- * Retrieves the root entity of the windowContainer
119
- * @returns the root entity of the windowContainer if one exists
120
- */
121
- getRootEntity(): Promise<SpatialEntity | null>;
122
- setRootEntity(entity: SpatialEntity): Promise<void>;
123
- close(): Promise<void>;
42
+ declare abstract class SpatialMaterial extends SpatialObject {
43
+ id: string;
44
+ type: SpatialMaterialType;
45
+ constructor(id: string, type: SpatialMaterialType);
46
+ abstract updateProperties(properties: any): void;
47
+ }
48
+
49
+ declare enum SpatialWebMsgType {
50
+ cubeInfo = "cubeInfo",
51
+ transform = "transform",
52
+ modelloaded = "modelloaded",
53
+ modelloadfailed = "modelloadfailed",
54
+ spatialtap = "spatialtap",
55
+ spatialdragstart = "spatialdragstart",
56
+ spatialdrag = "spatialdrag",
57
+ spatialdragend = "spatialdragend",
58
+ spatialrotatestart = "spatialrotatestart",
59
+ spatialrotate = "spatialrotate",
60
+ spatialrotateend = "spatialrotateend",
61
+ spatialmagnifystart = "spatialmagnifystart",
62
+ spatialmagnify = "spatialmagnify",
63
+ spatialmagnifyend = "spatialmagnifyend",
64
+ objectdestroy = "objectdestroy"
65
+ }
66
+ interface ObjectDestroyMsg {
67
+ type: SpatialWebMsgType.objectdestroy;
68
+ }
69
+ interface CubeInfoMsg {
70
+ type: SpatialWebMsgType.cubeInfo;
71
+ origin: Vec3;
72
+ size: Size3D;
73
+ }
74
+ interface CubeInfoMsg {
75
+ type: SpatialWebMsgType.cubeInfo;
76
+ origin: Vec3;
77
+ size: Size3D;
78
+ }
79
+ interface TransformMsg {
80
+ type: SpatialWebMsgType.transform;
81
+ detail: {
82
+ column0: [number, number, number];
83
+ column1: [number, number, number];
84
+ column2: [number, number, number];
85
+ column3: [number, number, number];
86
+ };
87
+ }
88
+ interface SpatialTapMsg {
89
+ type: SpatialWebMsgType.spatialtap;
90
+ detail: SpatialTapEventDetail;
91
+ }
92
+ interface SpatialDragMsg {
93
+ type: SpatialWebMsgType.spatialdrag;
94
+ detail: SpatialDragEventDetail;
95
+ }
96
+ interface SpatialDragEndMsg {
97
+ type: SpatialWebMsgType.spatialdragend;
98
+ detail: SpatialDragEventDetail;
99
+ }
100
+ interface SpatialRotateMsg {
101
+ type: SpatialWebMsgType.spatialrotate;
102
+ detail: SpatialRotateEventDetail;
103
+ }
104
+ interface SpatialRotateEndMsg {
105
+ type: SpatialWebMsgType.spatialrotateend;
106
+ detail: SpatialRotateEventDetail;
124
107
  }
125
108
 
126
109
  /**
127
- * Entity used to describe an object that can be added to the scene
110
+ * Abstract base class for all spatialized elements in the WebSpatial environment.
111
+ * Provides common functionality for elements that can exist in 3D space,
112
+ * including transformation handling and gesture event processing.
128
113
  */
129
- declare class SpatialEntity extends SpatialObject {
114
+ declare abstract class SpatializedElement extends SpatialObject {
115
+ readonly id: string;
130
116
  /**
131
- * Transform corresponding to the entity
132
- * note: updateTransform must be called for transform to be synced to rendering
117
+ * Creates a new spatialized element with the specified ID.
118
+ * Registers the element to receive spatial events.
119
+ * @param id Unique identifier for this element
133
120
  */
134
- transform: SpatialTransform;
135
- /** @hidden */
136
- private _destroyed;
137
- /** @hidden */
138
- private get _entity();
121
+ constructor(id: string);
139
122
  /**
140
- * Syncs the transform with the renderer, must be called to observe updates
123
+ * Updates the properties of this spatialized element.
124
+ * Must be implemented by derived classes to handle specific property updates.
125
+ * @param properties Partial set of properties to update
126
+ * @returns Promise resolving to the result of the update operation
141
127
  */
142
- updateTransform(): Promise<void>;
128
+ abstract updateProperties(properties: Partial<SpatializedElementProperties>): Promise<WebSpatialProtocolResult>;
143
129
  /**
144
- * Syncs the zIndex with the renderer
130
+ * Updates the transformation matrix of this element in 3D space.
131
+ * This affects the position, rotation, and scale of the element.
132
+ * @param matrix The new transformation matrix
133
+ * @returns Promise resolving when the transform is updated
145
134
  */
146
- updateZIndex(zIndex: number): Promise<void>;
147
- private components;
135
+ updateTransform(matrix: DOMMatrix): Promise<CommandResult>;
148
136
  /**
149
- * Attaches a component to the entity to be displayed
150
- * [TODO] review pass by value vs ref and ownership model for this
137
+ * Information about the element's bounding cube.
138
+ * Used for spatial calculations and hit testing.
151
139
  */
152
- setComponent(component: SpatialComponent): Promise<void>;
140
+ private _cubeInfo?;
153
141
  /**
154
- * Removes a component from the entity
142
+ * Gets the current cube information for this element.
143
+ * @returns The current CubeInfo or undefined if not set
155
144
  */
156
- removeComponent<T extends SpatialComponent>(type: new (...args: any[]) => T): Promise<void>;
145
+ get cubeInfo(): CubeInfo$1 | undefined;
157
146
  /**
158
- * Gets a component from the entity
147
+ * The current transformation matrix of this element.
159
148
  */
160
- getComponent<T extends SpatialComponent>(type: new (...args: any[]) => T): T | undefined;
149
+ private _transform?;
161
150
  /**
162
- * @hidden
163
- * Sets the window container that this entity should be rendered by (this does not effect resource ownership)
164
- * @param wg the window container that should render this entity
151
+ * The inverse of the current transformation matrix.
152
+ * Used for converting world coordinates to local coordinates.
165
153
  */
166
- _setParentWindowContainer(wg: SpatialWindowContainer): Promise<void>;
154
+ private _transformInv?;
167
155
  /**
168
- * Sets a parent entity, if that entity or its parents are attached to a window container, this entity will be displayed
169
- * @param e parent entity or null to remove current parent
156
+ * Gets the current transformation matrix.
157
+ * @returns The current transformation matrix or undefined if not set
170
158
  */
171
- setParent(e: SpatialEntity | null): Promise<void>;
159
+ get transform(): DOMMatrix | undefined;
172
160
  /**
173
- * Sets the coordinate space of this entity (Default: App)
174
- * "App" = game engine style coordinates in meters
175
- * "Dom" = Windowing coordinates in dom units (eg. 0,0,0 is top left of window)
176
- * "Root" = Coordinate space is ignored and content is displayed and updated as window container's root object, window containers can only have one root entity
177
- * [TODO] review this api
178
- * @param space coordinate space mode
161
+ * Gets the inverse of the current transformation matrix.
162
+ * @returns The inverse transformation matrix or undefined if not set
179
163
  */
180
- setCoordinateSpace(space: 'App' | 'Dom' | 'Root'): Promise<void>;
164
+ get transformInv(): DOMMatrix | undefined;
181
165
  /**
182
- * Query the 3d boudning box of the entity
183
- * @returns The bounding box of the entity
166
+ * Processes events received from the WebSpatial environment.
167
+ * Handles various spatial events like transforms, gestures, and interactions.
168
+ * @param data The event data received from the WebSpatial system
184
169
  */
185
- getBoundingBox(): Promise<{
186
- center: {
187
- x: number;
188
- y: number;
189
- z: number;
190
- };
191
- extents: {
192
- x: number;
193
- y: number;
194
- z: number;
195
- };
196
- }>;
170
+ protected onReceiveEvent(data: CubeInfoMsg | TransformMsg | SpatialTapMsg | SpatialDragMsg | SpatialDragEndMsg | SpatialRotateMsg | SpatialRotateEndMsg | ObjectDestroyMsg): void;
171
+ private _onSpatialTap?;
172
+ set onSpatialTap(value: (event: SpatialTapEvent) => void | undefined);
173
+ private _isDragging;
174
+ private _onSpatialDragStart?;
175
+ set onSpatialDragStart(value: (event: SpatialDragEvent) => void | undefined);
176
+ private _onSpatialDrag?;
177
+ set onSpatialDrag(value: (event: SpatialDragEvent) => void | undefined);
178
+ private _onSpatialDragEnd?;
179
+ set onSpatialDragEnd(value: ((event: SpatialDragEndEvent) => void) | undefined);
180
+ private _isRotating;
181
+ private _onSpatialRotateStart?;
182
+ set onSpatialRotateStart(value: ((event: SpatialRotateEvent) => void) | undefined);
183
+ private _onSpatialRotate?;
184
+ set onSpatialRotate(value: ((event: SpatialRotateEvent) => void) | undefined);
185
+ private _onSpatialRotateEnd?;
186
+ set onSpatialRotateEnd(value: ((event: SpatialRotateEndEvent) => void) | undefined);
187
+ private _isMagnify;
188
+ private _onSpatialMagnifyStart?;
189
+ set onSpatialMagnifyStart(value: ((event: SpatialMagnifyEvent) => void) | undefined);
190
+ private _onSpatialMagnify?;
191
+ set onSpatialMagnify(value: ((event: SpatialMagnifyEvent) => void) | undefined);
192
+ private _onSpatialMagnifyEnd?;
193
+ set onSpatialMagnifyEnd(value: ((event: SpatialMagnifyEndEvent) => void) | undefined);
197
194
  /**
198
- * Sets if the entity should be visible (default: True)
199
- * @param visible
195
+ * Cleans up resources when this element is destroyed.
196
+ * Removes event receivers to prevent memory leaks.
200
197
  */
201
- setVisible(visible: boolean): Promise<void>;
202
- /**
203
- * Removes a reference to the entity by the renderer and this object should no longer be used. [TODO] Attached components will not be destroyed
204
- */
205
- destroy(): Promise<void>;
206
- /**
207
- * Check if destroy has been called
208
- */
209
- isDestroyed(): boolean;
210
- /** @hidden */
211
- _setName(name: string): Promise<unknown>;
198
+ onDestroy(): void;
212
199
  }
213
200
 
214
- /** @hidden */
215
- declare class SpatialComponent extends SpatialObject {
216
- /**
217
- * Gets the entity this component is attached to
218
- * @returns entity or null
219
- */
220
- getEntity(): Promise<SpatialEntity | null>;
201
+ declare class SpatializedDynamic3DElement extends SpatializedElement {
202
+ children: SpatialEntityOrReality[];
203
+ constructor(id: string);
204
+ addEntity(entity: SpatialEntity): Promise<CommandResult>;
205
+ updateProperties(properties: Partial<SpatializedElementProperties>): Promise<CommandResult>;
221
206
  }
222
207
 
208
+ interface Vec3 {
209
+ x: number;
210
+ y: number;
211
+ z: number;
212
+ }
213
+ type Point3D = Vec3;
223
214
  /**
224
215
  * Material type for SpatialDiv or HTML document.
225
216
  *
@@ -241,500 +232,631 @@ type CornerRadius = {
241
232
  topTrailing: number;
242
233
  bottomTrailing: number;
243
234
  };
244
- type StyleParam = {
245
- material?: {
246
- type: BackgroundMaterialType;
235
+ interface SpatialSceneProperties {
236
+ cornerRadius: CornerRadius;
237
+ material: BackgroundMaterialType;
238
+ opacity: number;
239
+ }
240
+ declare enum SpatializedElementType {
241
+ Spatialized2DElement = 0,
242
+ SpatializedStatic3DElement = 1,
243
+ SpatializedDynamic3DElement = 2
244
+ }
245
+ interface SpatializedElementProperties {
246
+ name: string;
247
+ clientX: number;
248
+ clientY: number;
249
+ width: number;
250
+ height: number;
251
+ depth: number;
252
+ opacity: number;
253
+ visible: boolean;
254
+ scrollWithParent: boolean;
255
+ zIndex: number;
256
+ backOffset: number;
257
+ rotationAnchor: Point3D;
258
+ enableTapGesture: boolean;
259
+ enableDragStartGesture: boolean;
260
+ enableDragGesture: boolean;
261
+ enableDragEndGesture: boolean;
262
+ enableRotateStartGesture: boolean;
263
+ enableRotateGesture: boolean;
264
+ enableRotateEndGesture: boolean;
265
+ enableMagnifyStartGesture: boolean;
266
+ enableMagnifyGesture: boolean;
267
+ enableMagnifyEndGesture: boolean;
268
+ }
269
+ interface Spatialized2DElementProperties extends SpatializedElementProperties {
270
+ scrollPageEnabled: boolean;
271
+ cornerRadius: CornerRadius;
272
+ material: BackgroundMaterialType;
273
+ scrollEdgeInsetsMarginRight: number;
274
+ }
275
+ interface SpatializedStatic3DElementProperties extends SpatializedElementProperties {
276
+ modelURL: string;
277
+ modelTransform?: number[];
278
+ }
279
+ interface SpatialSceneCreationOptions$1 {
280
+ defaultSize?: {
281
+ width: number | string;
282
+ height: number | string;
283
+ depth?: number | string;
247
284
  };
248
- cornerRadius?: number | CornerRadius;
249
- };
250
- /**
251
- * Used to position an web window in 3D space
252
- */
253
- declare class SpatialWindowComponent extends SpatialComponent {
254
- /**
255
- * Loads a url page in the window
256
- * @param url url to load
257
- */
258
- loadURL(url: string): Promise<void>;
259
- setFromWindow(window: any): Promise<void>;
260
- /**
261
- * Sets the resolution of the window, the resulting dimensions when rendered will be equal to 1/1360 units
262
- * eg. if the resolution is set to 1360x1360 it will be a 1x1 plane
263
- * See 1360 in spatialViewUI.swift for how this ratio works
264
- * @param width width in pixels
265
- * @param height height in pixels
266
- */
267
- setResolution(width: number, height: number): Promise<void>;
268
- /**
269
- * [Experimental] Sets the anchor which the entity this is attached to will rotate around
270
- * @param rotationAnchor
271
- */
272
- setRotationAnchor(rotationAnchor: Vec3): Promise<void>;
273
- /**
274
- * [Experimental] Sets the opacity of the window after apply material
275
- * @param opacity
276
- */
277
- setOpacity(opacity: number): Promise<void>;
278
- /**
279
- * Sets the style that should be applied to the window
280
- * @param options style options
281
- */
282
- setStyle(styleParam: StyleParam): Promise<void>;
283
- /**
284
- * Modifies the amount the spatial window can be scrolled
285
- * Should only be used internally
286
- * See https://developer.apple.com/documentation/uikit/1624475-uiedgeinsetsmake?language=objc
287
- * @param insets margin to modify scroll distances by
288
- */
289
- setScrollEdgeInsets(insets: {
290
- top: number;
291
- left: number;
292
- bottom: number;
293
- right: number;
294
- }): Promise<void>;
295
- /**
296
- * Enable/Disable scrolling in the window (defaults to enabled), if disabled, scrolling will be applied to the root page
297
- * @param enabled value to set
298
- */
299
- setScrollEnabled(enabled: boolean): Promise<void>;
300
- /**
301
- * Defaults to false. If set to true, scrolling the parent page will also scroll this window with it like other dom elements
302
- * @param scrollWithParent value to set
303
- */
304
- setScrollWithParent(scrollWithParent: boolean): Promise<void>;
285
+ resizability?: {
286
+ minWidth?: number | string;
287
+ minHeight?: number | string;
288
+ maxWidth?: number | string;
289
+ maxHeight?: number | string;
290
+ };
291
+ worldScaling?: WorldScalingType;
292
+ worldAlignment?: WorldAlignmentType;
293
+ baseplateVisibility?: BaseplateVisibilityType;
305
294
  }
306
-
295
+ declare const BaseplateVisibilityValues: readonly ["automatic", "visible", "hidden"];
296
+ type BaseplateVisibilityType = (typeof BaseplateVisibilityValues)[number];
297
+ declare function isValidBaseplateVisibilityType(type: string): Boolean;
298
+ declare const WorldScalingValues: readonly ["automatic", "dynamic"];
299
+ type WorldScalingType = (typeof WorldScalingValues)[number];
300
+ declare function isValidWorldScalingType(type: string): Boolean;
301
+ declare const WorldAlignmentValues: readonly ["adaptive", "automatic", "gravityAligned"];
302
+ type WorldAlignmentType = (typeof WorldAlignmentValues)[number];
303
+ declare function isValidWorldAlignmentType(type: string): Boolean;
304
+ declare const SpatialSceneValues: readonly ["window", "volume"];
305
+ type SpatialSceneType$1 = (typeof SpatialSceneValues)[number];
306
+ declare function isValidSpatialSceneType(type: string): Boolean;
307
307
  /**
308
- * @description
309
- * Represents a spatial component that handles events related to spatial interactions.
310
- * This class extends `SpatialComponent` and provides additional functionality for managing
311
- * event-driven spatial behaviors.
308
+ * check px,m and number, number must be >= 0
312
309
  *
313
- * @hidden
314
- * This class is intended for internal use and should not be exposed in the public API.
315
- */
316
- declare abstract class EventSpatialComponent extends SpatialComponent {
317
- constructor(_resource: WebSpatialResource);
318
- /**
319
- * @description
320
- * Abstract method to be implemented by subclasses. Called when a spatial event is received.
321
- * @param data The data associated with the received event.
322
- */
323
- protected abstract onRecvEvent(data: any): void;
324
- protected onDestroy(): Promise<void>;
310
+ * */
311
+ declare function isValidSceneUnit(val: string | number): boolean;
312
+ interface SpatialEntityProperties {
313
+ position: Vec3;
314
+ rotation: Vec3;
315
+ scale: Vec3;
316
+ }
317
+ type SpatialEntityEventType = 'spatialtap';
318
+ type SpatialGeometryType = 'BoxGeometry' | 'PlaneGeometry' | 'SphereGeometry' | 'CylinderGeometry' | 'ConeGeometry';
319
+ interface SpatialBoxGeometryOptions {
320
+ width?: number;
321
+ height?: number;
322
+ depth?: number;
323
+ cornerRadius?: number;
324
+ splitFaces?: boolean;
325
+ }
326
+ interface SpatialPlaneGeometryOptions {
327
+ width?: number;
328
+ height?: number;
329
+ cornerRadius?: number;
330
+ }
331
+ interface SpatialSphereGeometryOptions {
332
+ radius?: number;
333
+ }
334
+ interface SpatialConeGeometryOptions {
335
+ radius?: number;
336
+ height?: number;
337
+ }
338
+ interface SpatialCylinderGeometryOptions {
339
+ radius?: number;
340
+ height?: number;
341
+ }
342
+ type SpatialGeometryOptions = SpatialBoxGeometryOptions | SpatialPlaneGeometryOptions | SpatialSphereGeometryOptions | SpatialCylinderGeometryOptions | SpatialConeGeometryOptions;
343
+ type SpatialMaterialType = 'unlit';
344
+ interface SpatialUnlitMaterialOptions {
345
+ color?: string;
346
+ textureId?: string;
347
+ transparent?: boolean;
348
+ opacity?: number;
349
+ }
350
+ interface ModelComponentOptions {
351
+ mesh: SpatialGeometry;
352
+ materials: SpatialMaterial[];
353
+ }
354
+ interface SpatialEntityUserData {
355
+ id?: string;
356
+ name?: string;
357
+ }
358
+ interface SpatialModelEntityCreationOptions {
359
+ modelAssetId: string;
360
+ name?: string;
361
+ }
362
+ interface ModelAssetOptions {
363
+ url: string;
364
+ }
365
+ declare enum SpatialSceneState$1 {
366
+ idle = "idle",
367
+ pending = "pending",
368
+ willVisible = "willVisible",
369
+ visible = "visible",
370
+ fail = "fail"
325
371
  }
326
-
327
372
  /**
328
373
  * Translate event, matching similar behavior to https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/drag_event
329
374
  */
330
- type TranslateEvent = {
375
+ type SpatialModelDragEvent = {
331
376
  eventType: 'dragstart' | 'dragend' | 'drag';
332
- translate?: Vec3;
377
+ translation3D: Vec3;
378
+ startLocation3D: Vec3;
333
379
  };
334
- /**
335
- * Used to handle input events on an entity
336
- */
337
- declare class SpatialInputComponent extends EventSpatialComponent {
338
- protected onRecvEvent(data: any): void;
339
- /**
340
- * Callback fired when a translate event occurs
341
- * @param data translate event data
342
- */
343
- onTranslate(data: TranslateEvent): void;
380
+ interface Size {
381
+ width: number;
382
+ height: number;
383
+ }
384
+ interface Size3D extends Size {
385
+ depth: number;
386
+ }
387
+ declare class CubeInfo$1 {
388
+ size: Size3D;
389
+ origin: Vec3;
390
+ constructor(size: Size3D, origin: Vec3);
391
+ get x(): number;
392
+ get y(): number;
393
+ get z(): number;
394
+ get width(): number;
395
+ get height(): number;
396
+ get depth(): number;
397
+ get left(): number;
398
+ get top(): number;
399
+ get right(): number;
400
+ get bottom(): number;
401
+ get back(): number;
402
+ get front(): number;
344
403
  }
404
+ interface SpatialTapEventDetail {
405
+ location3D: Point3D;
406
+ }
407
+ type SpatialTapEvent = CustomEvent<SpatialTapEventDetail>;
408
+ interface SpatialDragEventDetail {
409
+ location3D: Point3D;
410
+ startLocation3D: Point3D;
411
+ translation3D: Vec3;
412
+ predictedEndTranslation3D: Vec3;
413
+ predictedEndLocation3D: Point3D;
414
+ velocity: Size;
415
+ }
416
+ type SpatialDragEvent = CustomEvent<SpatialDragEventDetail>;
417
+ type SpatialDragEndEvent = SpatialDragEvent;
418
+ interface SpatialRotateEventDetail {
419
+ rotation: {
420
+ vector: [number, number, number, number];
421
+ };
422
+ startAnchor3D: Vec3;
423
+ startLocation3D: Point3D;
424
+ }
425
+ type SpatialRotateEvent = CustomEvent<SpatialRotateEventDetail>;
426
+ type SpatialRotateEndEvent = SpatialRotateEvent;
427
+ interface SpatialMagnifyEventDetail {
428
+ magnification: number;
429
+ velocity: number;
430
+ startAnchor3D: Vec3;
431
+ startLocation3D: Point3D;
432
+ }
433
+ type SpatialMagnifyEvent = CustomEvent<SpatialMagnifyEventDetail>;
434
+ type SpatialMagnifyEndEvent = SpatialMagnifyEvent;
435
+ type SpatialEntityOrReality = SpatialEntity | SpatializedDynamic3DElement;
345
436
 
346
- /**
347
- * Mesh asset containing geometry
348
- */
349
- declare class SpatialMeshResource extends SpatialObject {
437
+ declare class SpatialComponent extends SpatialObject {
438
+ constructor(id: string);
439
+ private onReceiveEvent;
440
+ }
441
+
442
+ declare class SpatialEntity extends SpatialObject {
443
+ userData?: SpatialEntityUserData | undefined;
444
+ position: Vec3;
445
+ rotation: Vec3;
446
+ scale: Vec3;
447
+ events: Record<string, (data: any) => void>;
448
+ children: SpatialEntity[];
449
+ parent: SpatialEntityOrReality | null;
450
+ constructor(id: string, userData?: SpatialEntityUserData | undefined);
451
+ addComponent(component: SpatialComponent): Promise<CommandResult>;
452
+ setPosition(position: Vec3): Promise<CommandResult>;
453
+ setRotation(rotation: Vec3): Promise<CommandResult>;
454
+ setScale(scale: Vec3): Promise<CommandResult>;
455
+ addEntity(ent: SpatialEntity): Promise<CommandResult>;
456
+ removeFromParent(): Promise<CommandResult>;
457
+ updateTransform(properties: Partial<SpatialEntityProperties>): Promise<CommandResult>;
458
+ addEvent(type: SpatialEntityEventType, callback: (data: any) => void): Promise<void>;
459
+ removeEvent(eventName: SpatialEntityEventType): Promise<void>;
460
+ updateEntityEvent(eventName: SpatialEntityEventType, isEnable: boolean): Promise<CommandResult>;
461
+ private onReceiveEvent;
462
+ dispatchEvent(evt: CustomEvent): void;
463
+ protected onDestroy(): void;
464
+ convertFromEntityToEntity(fromEntityId: string, toEntityId: string, position: Vec3): Promise<CommandResult>;
465
+ convertFromEntityToScene(fromEntityId: string, position: Vec3): Promise<CommandResult>;
466
+ convertFromSceneToEntity(entityId: string, position: Vec3): Promise<CommandResult>;
467
+ }
468
+
469
+ declare class SpatialModelEntity extends SpatialEntity {
470
+ id: string;
471
+ options?: SpatialModelEntityCreationOptions | undefined;
472
+ userData?: SpatialEntityUserData | undefined;
473
+ constructor(id: string, options?: SpatialModelEntityCreationOptions | undefined, userData?: SpatialEntityUserData | undefined);
474
+ }
475
+
476
+ declare class ModelComponent extends SpatialComponent {
477
+ options: ModelComponentOptions;
478
+ constructor(id: string, options: ModelComponentOptions);
479
+ }
480
+
481
+ declare class SpatialUnlitMaterial extends SpatialMaterial {
482
+ id: string;
483
+ options: SpatialUnlitMaterialOptions;
484
+ constructor(id: string, options: SpatialUnlitMaterialOptions);
485
+ updateProperties(properties: Partial<SpatialUnlitMaterialOptions>): Promise<CommandResult>;
486
+ }
487
+
488
+ declare class SpatialBoxGeometry extends SpatialGeometry {
489
+ id: string;
490
+ options: SpatialBoxGeometryOptions;
491
+ static type: SpatialGeometryType;
492
+ constructor(id: string, options: SpatialBoxGeometryOptions);
493
+ }
494
+
495
+ declare class SpatialSphereGeometry extends SpatialGeometry {
496
+ id: string;
497
+ options: SpatialSphereGeometryOptions;
498
+ static type: SpatialGeometryType;
499
+ constructor(id: string, options: SpatialSphereGeometryOptions);
500
+ }
501
+
502
+ declare class SpatialCylinderGeometry extends SpatialGeometry {
503
+ id: string;
504
+ options: SpatialCylinderGeometryOptions;
505
+ static type: SpatialGeometryType;
506
+ constructor(id: string, options: SpatialCylinderGeometryOptions);
507
+ }
508
+
509
+ declare class SpatialPlaneGeometry extends SpatialGeometry {
510
+ id: string;
511
+ options: SpatialPlaneGeometryOptions;
512
+ static type: SpatialGeometryType;
513
+ constructor(id: string, options: SpatialPlaneGeometryOptions);
514
+ }
515
+
516
+ declare class SpatialConeGeometry extends SpatialGeometry {
517
+ id: string;
518
+ options: SpatialConeGeometryOptions;
519
+ static type: SpatialGeometryType;
520
+ constructor(id: string, options: SpatialConeGeometryOptions);
521
+ }
522
+
523
+ declare class SpatialModelAsset extends SpatialObject {
524
+ id: string;
525
+ options: ModelAssetOptions;
526
+ constructor(id: string, options: ModelAssetOptions);
527
+ }
528
+
529
+ declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
530
+ type: SpatialSceneType$1;
531
+ }): void;
532
+
533
+ type SpatialSceneCreationOptionsInternal = SpatialSceneCreationOptions$1 & {
534
+ type: SpatialSceneType$1;
535
+ };
536
+ declare enum SpatialSceneState {
537
+ idle = "idle",
538
+ pending = "pending",
539
+ willVisible = "willVisible",
540
+ visible = "visible",
541
+ fail = "fail"
350
542
  }
351
543
 
352
544
  /**
353
- * PBR material which can be set on a SpatialModelComponent
545
+ * Represents the spatial scene that contains all spatialized elements.
546
+ * This class follows the singleton pattern - only one instance exists per application.
547
+ * The scene manages the overall spatial environment properties and contains all spatial elements.
354
548
  */
355
- declare class SpatialPhysicallyBasedMaterialResource extends SpatialObject {
549
+ declare class SpatialScene extends SpatialObject {
356
550
  /**
357
- * Base color of the material containing rgba between 0 and 1
551
+ * Gets the singleton instance of the SpatialScene.
552
+ * Creates a new instance if one doesn't exist yet.
553
+ * @returns The singleton SpatialScene instance
358
554
  */
359
- baseColor: {
360
- r: number;
361
- g: number;
362
- b: number;
363
- a: number;
364
- };
555
+ static getInstance(): SpatialScene;
365
556
  /**
366
- * PBR metalic value between 0 and 1
557
+ * Updates the properties of the spatial scene.
558
+ * This can include background settings, lighting, and other scene-wide properties.
559
+ * @param properties Partial set of properties to update
560
+ * @returns Promise resolving when the update is complete
367
561
  */
368
- metallic: {
369
- value: number;
370
- };
562
+ updateSpatialProperties(properties: Partial<SpatialSceneProperties>): Promise<CommandResult>;
371
563
  /**
372
- * PBR roughness value between 0 and 1
564
+ * Adds a spatialized element to the scene.
565
+ * This makes the element visible and interactive in the spatial environment.
566
+ * @param element The SpatializedElement to add to the scene
567
+ * @returns Promise resolving when the element is added
373
568
  */
374
- roughness: {
375
- value: number;
376
- };
377
- _modelComponentAttachedTo: {
378
- [key: string]: SpatialModelComponent;
379
- };
380
- _addToComponent(c: SpatialModelComponent): void;
381
- /**
382
- * Syncs state of color, metallic, roupghness to the renderer
383
- */
384
- update(): Promise<void>;
385
- }
386
-
387
- /**
388
- * Used to position a model in 3D space, made up of a mesh and materials to be applied to the mesh
389
- */
390
- declare class SpatialModelComponent extends SpatialComponent {
391
- private cachedMaterials;
569
+ addSpatializedElement(element: SpatializedElement): Promise<CommandResult>;
392
570
  /**
393
- * Sets the mesh to be displayed by the component
394
- * @param mesh mesh to set
571
+ * Updates the scene creation configuration.
572
+ * This allows changing scene parameters after initial creation.
573
+ * @param config The new scene creation configuration
574
+ * @returns Promise resolving when the update is complete
395
575
  */
396
- setMesh(mesh: SpatialMeshResource): Promise<void>;
576
+ updateSceneCreationConfig(config: SpatialSceneCreationOptionsInternal): Promise<CommandResult>;
397
577
  /**
398
- * Sets the materials that should be applied to the mesh
399
- * @param materials array of materials to set
578
+ * Gets the current state of the spatial scene.
579
+ * This includes information about active elements and scene configuration.
580
+ * @returns Promise resolving to the current SpatialSceneState
400
581
  */
401
- setMaterials(materials: Array<SpatialPhysicallyBasedMaterialResource>): Promise<void>;
402
- /** @hidden */
403
- _syncMaterials(): Promise<void>;
582
+ getState(): Promise<SpatialSceneState>;
404
583
  }
405
584
 
406
585
  /**
407
- * Represenets a volume that can be added to the webpage
408
- * Child entities will be added within this volume's space
409
- * Defaults to having 1x1x1 meter dimensions
410
- * Resolution defaults to 100x100 pixels
411
- * Only will be displayed on entities in "ROOT" or "DOM" space
412
- * If the resolution of the spatial view is not a square, the volume will be larger based on the ratio with the shortest side being 1 meter.
413
- * (eg. 200x100 = 2m x 1m x 1m volume)
586
+ * Represents a 2D HTML element that has been spatialized in 3D space.
587
+ * This class handles the integration between 2D web content and the 3D spatial environment,
588
+ * allowing HTML elements to be positioned and interacted with in spatial applications.
414
589
  */
415
- declare class SpatialViewComponent extends SpatialComponent {
590
+ declare class Spatialized2DElement extends SpatializedElement {
591
+ readonly windowProxy: WindowProxy;
416
592
  /**
417
- * Sets the resolution of the spatial view in dom pixels
593
+ * Creates a new spatialized 2D element.
594
+ * @param id Unique identifier for this element
595
+ * @param windowProxy Reference to the window object containing the 2D content
418
596
  */
419
- setResolution(width: number, height: number): Promise<void>;
597
+ constructor(id: string, windowProxy: WindowProxy);
420
598
  /**
421
- * Sets if content of the spatialView should be within a portal
422
- * If true, volume will be behind the page, if false, it will be in front of the page
599
+ * Updates the properties of this 2D element.
600
+ * This can include size, position, background, and other visual properties.
601
+ * @param properties Partial set of properties to update
602
+ * @returns Promise resolving when the update is complete
423
603
  */
424
- setIsPortal(isPortal: Boolean): Promise<void>;
604
+ updateProperties(properties: Partial<Spatialized2DElementProperties>): Promise<CommandResult>;
605
+ /**
606
+ * Adds a child spatialized element to this 2D element.
607
+ * This allows for creating hierarchical structures of spatial elements.
608
+ * @param element The child element to add
609
+ * @returns Promise resolving when the element is added
610
+ */
611
+ addSpatializedElement(element: SpatializedElement): Promise<CommandResult>;
425
612
  }
426
613
 
427
614
  /**
428
- * Translate event, matching similar behavior to https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/drag_event
615
+ * Represents a static 3D model element in the spatial environment.
616
+ * This class handles loading and displaying pre-built 3D models from URLs,
617
+ * and provides events for load success and failure.
429
618
  */
430
- type SpatialModelDragEvent = {
431
- eventType: 'dragstart' | 'dragend' | 'drag';
432
- translation3D: Vec3;
433
- startLocation3D: Vec3;
434
- };
435
- /**
436
- * Used to position a model3d in 3D space
437
- */
438
- declare class SpatialModel3DComponent extends EventSpatialComponent {
439
- protected onRecvEvent(data: any): void;
440
- /**
441
- * Sets the resolution of the spatial view in dom pixels
442
- */
443
- setResolution(width: number, height: number): Promise<void>;
444
- setRotationAnchor(rotationAnchor: Vec3): Promise<void>;
445
- /**
446
- * Sets the opacity of the model
447
- * @param opacity
448
- */
449
- setOpacity(opacity: number): Promise<void>;
619
+ declare class SpatializedStatic3DElement extends SpatializedElement {
450
620
  /**
451
- * Sets how the model fill the rect
452
- * @param contentMode
621
+ * Promise resolver for the ready state.
622
+ * Used to resolve the ready promise when the model is loaded.
453
623
  */
454
- setContentMode(contentMode: 'fill' | 'fit'): Promise<void>;
624
+ private _readyResolve?;
455
625
  /**
456
- * Constrains this model dimensions to the specified aspect ratio.
457
- * with a value of 0, the model will use the original aspect ratio.
458
- *
459
- * @param aspectRatio number
626
+ * Caches the last model URL to detect changes.
627
+ * Used to reset the ready promise when the model URL changes.
460
628
  */
461
- setAspectRatio(aspectRatio: number): Promise<void>;
629
+ private modelURL;
462
630
  /**
463
- * Defaults to false. If set to true, scrolling the parent page will also scroll this window with it like other dom elements
464
- * @param scrollWithParent value to set
631
+ * Creates a new promise for tracking the ready state of the model.
632
+ * @returns Promise that resolves when the model is loaded (true) or fails to load (false)
465
633
  */
466
- setScrollWithParent(scrollWithParent: boolean): Promise<void>;
634
+ private createReadyPromise;
467
635
  /**
468
- * Sets whether the model appear in original size or fit the rect
469
- * @param resizable
636
+ * Promise that resolves when the model is loaded.
637
+ * Resolves to true on successful load, false on failure.
470
638
  */
471
- setResizable(resizable: boolean): Promise<void>;
639
+ ready: Promise<boolean>;
472
640
  /**
473
- * Callback fired when model load success
641
+ * Updates the properties of this static 3D element.
642
+ * Handles special case for modelURL changes by resetting the ready promise.
643
+ * @param properties Partial set of properties to update
644
+ * @returns Promise resolving when the update is complete
474
645
  */
475
- onSuccess?: () => void;
646
+ updateProperties(properties: Partial<SpatializedStatic3DElementProperties>): Promise<CommandResult>;
476
647
  /**
477
- * Callback fired when model load failure
478
- * @param errorReason
648
+ * Processes events received from the WebSpatial environment.
649
+ * Handles model loading events in addition to base spatial events.
650
+ * @param data The event data received from the WebSpatial system
479
651
  */
480
- onFailure?: (errorReason: string) => void;
652
+ onReceiveEvent(data: {
653
+ type: SpatialWebMsgType;
654
+ }): void;
481
655
  /**
482
- * Callback fired when model was dragged at the beginning
483
- * @param dragEvent
656
+ * Callback function for successful model loading.
484
657
  */
485
- private _onDragStart?;
486
- set onDragStart(callback: ((dragEvent: SpatialModelDragEvent) => void) | undefined);
658
+ private _onLoadCallback?;
487
659
  /**
488
- * Callback fired when model was dragged
489
- * @param dragEvent
660
+ * Sets the callback function for successful model loading.
661
+ * @param callback Function to call when the model is loaded successfully
490
662
  */
491
- private _onDrag?;
492
- set onDrag(callback: ((dragEvent: SpatialModelDragEvent) => void) | undefined);
663
+ set onLoadCallback(callback: undefined | (() => void));
493
664
  /**
494
- * Callback fired when model was dragged at the ending
495
- * @param dragEvent
665
+ * Callback function for model loading failure.
496
666
  */
497
- private _onDragEnd?;
498
- set onDragEnd(callback: ((dragEvent: SpatialModelDragEvent) => void) | undefined);
499
- private get enableDragEvent();
667
+ private _onLoadFailureCallback?;
500
668
  /**
501
- * Callback fired when model was tapped
669
+ * Sets the callback function for model loading failure.
670
+ * @param callback Function to call when the model fails to load
502
671
  */
503
- private _onTap?;
504
- set onTap(callback: (() => void) | undefined);
505
- /** Callback fired when model was double tapped */
506
- private _onDoubleTap?;
507
- set onDoubleTap(callback: (() => void) | undefined);
508
- /** Callback fired when model was long pressed */
509
- private _onLongPress?;
510
- set onLongPress(callback: (() => void) | undefined);
672
+ set onLoadFailureCallback(callback: undefined | (() => void));
673
+ updateModelTransform(transform: DOMMatrix): void;
511
674
  }
512
675
 
513
- type CreateResourceOptions = {
514
- windowContainer?: SpatialWindowContainer | null;
515
- windowComponent?: SpatialWindowComponent | null;
516
- };
517
676
  /**
518
- * Animation callback with timestamp
519
- */
520
- type animCallback = (time: DOMHighResTimeStamp) => Promise<any>;
521
- /**
522
- * Session use to establish a connection to the spatial renderer of the system. All resources must be created by the session
677
+ * Session used to establish a connection to the spatial renderer of the system.
678
+ * All spatial resources must be created through this session object.
679
+ * This class serves as the main factory for creating spatial elements and geometries.
523
680
  */
524
681
  declare class SpatialSession {
525
- /** @hidden */
526
- _engineUpdateListeners: animCallback[];
527
- /** @hidden */
528
- _frameLoopStarted: boolean;
529
682
  /**
530
- * Add event listener callback to be called each frame
531
- * @param callback callback to be called each update
683
+ * Gets the singleton instance of the spatial scene.
684
+ * The spatial scene is the root container for all spatial elements.
685
+ * @returns The SpatialScene singleton instance
532
686
  */
533
- addOnEngineUpdateEventListener(callback: animCallback): void;
687
+ getSpatialScene(): SpatialScene;
534
688
  /**
535
- * Creates a Entity
536
- * @returns Entity
689
+ * Creates a new 2D element that can be spatialized in the 3D environment.
690
+ * 2D elements represent HTML content that can be positioned in 3D space.
691
+ * @returns Promise resolving to a new Spatialized2DElement instance
537
692
  */
538
- createEntity(options?: CreateResourceOptions): Promise<SpatialEntity>;
693
+ createSpatialized2DElement(): Promise<Spatialized2DElement>;
539
694
  /**
540
- * Creates a WindowComponent
541
- * [TODO] should creation of components be moved to entity? and these made private?
542
- * @returns WindowComponent
695
+ * Creates a new static 3D element with an optional model URL.
696
+ * Static 3D elements represent pre-built 3D models that can be loaded from a URL.
697
+ * @param modelURL Optional URL to the 3D model to load
698
+ * @returns Promise resolving to a new SpatializedStatic3DElement instance
543
699
  */
544
- createWindowComponent(options?: CreateResourceOptions): Promise<SpatialWindowComponent>;
700
+ createSpatializedStatic3DElement(modelURL?: string): Promise<SpatializedStatic3DElement>;
545
701
  /**
546
- * Creates a ViewComponent used to display 3D content within the entity
547
- * @returns SpatialViewComponent
702
+ * Initializes the spatial scene with custom configuration.
703
+ * This is a reference to the initScene function from scene-polyfill.
548
704
  */
549
- createViewComponent(options?: CreateResourceOptions): Promise<SpatialViewComponent>;
705
+ initScene: typeof initScene;
550
706
  /**
551
- * Creates a ModelComponent used to display geometry + material of a 3D model
552
- * @returns ModelComponent
707
+ * Creates a new dynamic 3D element that can be manipulated at runtime.
708
+ * Dynamic 3D elements allow for programmatic creation and modification of 3D content.
709
+ * @returns Promise resolving to a new SpatializedDynamic3DElement instance
553
710
  */
554
- createModelComponent(options?: {
555
- url: string;
556
- } & CreateResourceOptions): Promise<SpatialModelComponent>;
711
+ createSpatializedDynamic3DElement(): Promise<SpatializedDynamic3DElement>;
557
712
  /**
558
- * Creates a Model3DComponent
559
- * @returns Model3DComponent
713
+ * Creates a new spatial entity with an optional name.
714
+ * Entities are the basic building blocks for creating custom 3D content.
715
+ * @param name Optional name for the entity
716
+ * @returns Promise resolving to a new SpatialEntity instance
560
717
  */
561
- createModel3DComponent(options?: {
562
- url: string;
563
- } & CreateResourceOptions): Promise<SpatialModel3DComponent>;
718
+ createEntity(userData?: SpatialEntityUserData): Promise<SpatialEntity>;
564
719
  /**
565
- * Creates a InputComponent
566
- * [Experimental] Creates a InputComponent used to handle click and drag events of the entity containing a model
567
- * @returns InputComponent
720
+ * Creates a box geometry with optional configuration.
721
+ * @param options Configuration options for the box geometry
722
+ * @returns Promise resolving to a new SpatialBoxGeometry instance
568
723
  */
569
- createInputComponent(options?: CreateResourceOptions): Promise<SpatialInputComponent>;
724
+ createBoxGeometry(options?: SpatialBoxGeometryOptions): Promise<SpatialBoxGeometry>;
570
725
  /**
571
- * Creates a MeshResource containing geometry data
572
- * @returns MeshResource
726
+ * Creates a plane geometry with optional configuration.
727
+ * @param options Configuration options for the plane geometry
728
+ * @returns Promise resolving to a new SpatialPlaneGeometry instance
573
729
  */
574
- createMeshResource(options?: {
575
- shape?: string;
576
- } & CreateResourceOptions): Promise<SpatialMeshResource>;
730
+ createPlaneGeometry(options?: SpatialPlaneGeometryOptions): Promise<SpatialPlaneGeometry>;
577
731
  /**
578
- * Creates a PhysicallyBasedMaterial containing PBR material data
579
- * @returns PhysicallyBasedMaterial
732
+ * Creates a sphere geometry with optional configuration.
733
+ * @param options Configuration options for the sphere geometry
734
+ * @returns Promise resolving to a new SpatialSphereGeometry instance
580
735
  */
581
- createPhysicallyBasedMaterialResource(options?: {} & CreateResourceOptions): Promise<SpatialPhysicallyBasedMaterialResource>;
736
+ createSphereGeometry(options?: SpatialSphereGeometryOptions): Promise<SpatialSphereGeometry>;
582
737
  /**
583
- * Creates a WindowContainer
584
- * @returns SpatialWindowContainer
585
- * */
586
- createWindowContainer(options?: {
587
- style: WindowStyle;
588
- } & CreateResourceOptions): Promise<SpatialWindowContainer>;
589
- /**
590
- * Creates a Scene to display content within an anchored area managed by the OS
591
- * @hidden
592
- * @param {WindowStyle} [style='Plain'] - The style of the Scene container to be created with. Defaults to 'Plain'.
593
- * @param {Object} [cfg={}] - Configuration object for the Scene.
594
- * @returns Boolean
595
- */
596
- _createScene(style: WindowStyle | undefined, cfg: {
597
- sceneData: sceneDataShape;
598
- }): Promise<boolean>;
599
- /**
600
- * Retrieves the window for this page
601
- * @returns the window component corresponding to the js running on this page
602
- * [TODO] discuss implications of this not being async
738
+ * Creates a cone geometry with the specified configuration.
739
+ * @param options Configuration options for the cone geometry
740
+ * @returns Promise resolving to a new SpatialConeGeometry instance
603
741
  */
604
- getCurrentWindowComponent(): SpatialWindowComponent;
742
+ createConeGeometry(options: SpatialConeGeometryOptions): Promise<SpatialConeGeometry>;
605
743
  /**
606
- * Retrieves the parent window for this page or null if this is the root page
607
- * @returns the window component or null
744
+ * Creates a cylinder geometry with the specified configuration.
745
+ * @param options Configuration options for the cylinder geometry
746
+ * @returns Promise resolving to a new SpatialCylinderGeometry instance
608
747
  */
609
- getParentWindowComponent(): Promise<SpatialWindowComponent | null>;
748
+ createCylinderGeometry(options: SpatialCylinderGeometryOptions): Promise<SpatialCylinderGeometry>;
610
749
  /**
611
- * Logs a message to the native apps console
612
- * @param msg mesage to log
750
+ * Creates a model component with the specified configuration.
751
+ * Model components are used to add 3D model rendering capabilities to entities.
752
+ * @param options Configuration options for the model component
753
+ * @returns Promise resolving to a new ModelComponent instance
613
754
  */
614
- log(...msg: any[]): Promise<void>;
755
+ createModelComponent(options: ModelComponentOptions): Promise<ModelComponent>;
615
756
  /**
616
- * @hidden
617
- * Debugging only, used to ping the native renderer
757
+ * Creates an unlit material with the specified configuration.
758
+ * Unlit materials don't respond to lighting in the scene.
759
+ * @param options Configuration options for the unlit material
760
+ * @returns Promise resolving to a new SpatialUnlitMaterial instance
618
761
  */
619
- _ping(msg: string): Promise<unknown>;
762
+ createUnlitMaterial(options: SpatialUnlitMaterialOptions): Promise<SpatialUnlitMaterial>;
620
763
  /**
621
- * @hidden
622
- * Debugging to get internal state from native code
623
- * @returns stats from native code. Objects tracks number of native objects that were created but not yet explicitly destroyed. RefObjects tracks bjects that still have references. After an object is destroyed, we should be cleaning up all of the native references. Expect objects.count == refObjects.count , if not, there is likely a leak.
764
+ * Creates a model asset with the specified configuration.
765
+ * Model assets represent 3D model resources that can be used by entities.
766
+ * @param options Configuration options for the model asset
767
+ * @returns Promise resolving to a new SpatialModelAsset instance
624
768
  */
625
- _getStats(): Promise<{
626
- backend: string;
627
- objects: {
628
- count: number;
629
- };
630
- refObjects: {
631
- count: number;
632
- };
633
- }>;
769
+ createModelAsset(options: ModelAssetOptions): Promise<SpatialModelAsset>;
634
770
  /**
635
- * @hidden
771
+ * Creates a spatial model entity with the specified configuration.
772
+ * This is a convenience method for creating an entity with a model component.
773
+ * @param options Configuration options for the spatial model entity
774
+ * @returns Promise resolving to a new SpatialModelEntity instance
636
775
  */
637
- _inspect(spatialObjectId?: string): Promise<any>;
638
- /**
639
- * @hidden
640
- */
641
- _inspectRootWindowContainer(): Promise<any>;
642
- /** Opens the immersive space */
643
- openImmersiveSpace(): Promise<void>;
644
- /** Closes the immersive space */
645
- dismissImmersiveSpace(): Promise<void>;
646
- private static _immersiveWindowContainer;
647
- /**
648
- * Retreives the window container corresponding to the Immersive space
649
- * @returns the immersive window container
650
- */
651
- getImmersiveWindowContainer(): Promise<SpatialWindowContainer>;
652
- private static _currentWindowContainer;
653
- /**
654
- * Gets the current window container for the window
655
- * [TODO] discuss what happens if it doesnt yet have a window container
656
- * @returns the current window container for the window
657
- */
658
- getCurrentWindowContainer(): SpatialWindowContainer;
659
- /**
660
- * Start a transaction that queues up commands to submit them all at once to reduce ipc overhead
661
- * @param fn function to be run, within this function, promises will not resolve
662
- * @returns promise for the entire transaction completion
663
- */
664
- transaction(fn: Function): Promise<unknown>;
665
- /**
666
- * Creates a window context object that is compatable with SpatialWindowComponent's setFromWindow API
667
- * @returns window context
668
- */
669
- createWindowContext(): Promise<Window | null>;
670
- /** @hidden */
671
- _getEntity(id: string): Promise<SpatialEntity>;
672
- /** @hidden */
673
- setLoading(method: LoadingMethodKind, style?: string): Promise<unknown>;
776
+ createSpatialModelEntity(options: SpatialModelEntityCreationOptions, userData?: SpatialEntityUserData): Promise<SpatialModelEntity>;
674
777
  }
675
778
 
676
779
  /**
677
- * Base object designed to be placed on navigator.spatial to mirror navigator.xr for webxr
780
+ * Base object designed to be placed on navigator.spatial to mirror navigator.xr for webxr.
781
+ * This is the main entry point for the WebSpatial SDK, providing access to spatial capabilities.
678
782
  */
679
783
  declare class Spatial {
680
784
  /**
681
- * Requests a session object from the browser
682
- * @returns The session or null if not availible in the current browser
785
+ * Requests a spatial session object from the browser.
786
+ * This is the primary method to initialize spatial functionality.
787
+ * @returns The SpatialSession instance or null if not available in the current browser
683
788
  * [TODO] discuss implications of this not being async
684
789
  */
685
790
  requestSession(): SpatialSession | null;
686
791
  /**
687
- * @returns true if web spatial is supported by this webpage
792
+ * Checks if the current page is running in a spatial web environment.
793
+ * This method detects if the application is running in a WebSpatial-compatible browser.
794
+ * @returns True if running in a spatial web environment, false otherwise
795
+ */
796
+ runInSpatialWeb(): boolean;
797
+ /** @deprecated
798
+ * Checks if WebSpatial is supported in the current environment.
799
+ * Verifies compatibility between native and client versions.
800
+ * @returns True if web spatial is supported by this webpage
688
801
  */
689
802
  isSupported(): boolean;
690
- /**
691
- * Gets the native version, format is "x.x.x"
692
- * @returns native version string
803
+ /** @deprecated
804
+ * Gets the native WebSpatial version from the browser environment.
805
+ * The version format follows semantic versioning (x.x.x).
806
+ * @returns Native version string in format "x.x.x"
693
807
  */
694
808
  getNativeVersion(): any;
695
- /**
696
- * Gets the client version, format is "x.x.x"
697
- * @returns client version string
809
+ /** @deprecated
810
+ * Gets the client SDK version.
811
+ * The version format follows semantic versioning (x.x.x).
812
+ * @returns Client SDK version string in format "x.x.x"
698
813
  */
699
814
  getClientVersion(): string;
700
815
  }
701
816
 
702
- /**
703
- * Helper class used to quickly add spatial content to standard web pages
704
- * [Experimental] expect APIs to potentially change in future versions
705
- */
706
- declare class SpatialHelper {
707
- session: SpatialSession;
708
- private static _instance;
709
- static get instance(): SpatialHelper | null;
710
- constructor(session: SpatialSession);
711
- shape: {
712
- createShapeEntity: (shape?: string) => Promise<SpatialEntity>;
713
- createModelEntity: (url: string) => Promise<SpatialEntity>;
714
- wrapInBoundingBoxEntity: (entityToWrap: SpatialEntity) => Promise<SpatialEntity>;
715
- };
716
- navigation: {
717
- openPanel: (url: string, options?: {
718
- resolution: {
719
- width: number;
720
- height: number;
721
- };
722
- }) => Promise<{
723
- windowContainer: SpatialWindowContainer;
724
- }>;
725
- openVolume: (url: string, options?: {
726
- resolution: {
727
- width: number;
728
- height: number;
729
- };
730
- }) => Promise<void>;
731
- };
732
- dom: {
733
- attachSpatialView: (divOnPage: HTMLElement) => Promise<{
734
- entity: SpatialEntity;
735
- }>;
736
- };
737
- setBackgroundStyle: (style: StyleParam, backgroundColor?: string) => Promise<void>;
817
+ declare global {
818
+ declare const __WEBSPATIAL_CORE_SDK_VERSION__: string
819
+
820
+ interface Window {
821
+ xrCurrentSceneType: SpatialSceneType
822
+ xrCurrentSceneDefaults: (
823
+ defaultConfig: SpatialSceneCreationOptions,
824
+ ) => Promise<SpatialSceneCreationOptions>
825
+
826
+ // Location for webspatial custom functions
827
+ __WebSpatialData: {
828
+ androidNativeMessage: Function
829
+ getNativeVersion: Function
830
+ }
831
+
832
+ // Location for webspatial internal callbacks (eg. completion events)
833
+ __SpatialWebEvent: Function
834
+
835
+ // Used to access webkit specific api
836
+ webkit: any
837
+ webspatialBridge: any
838
+
839
+ // Will be removed in favor of __WebSpatialData
840
+ WebSpatailNativeVersion: string
841
+
842
+ __webspatialsdk__?: {
843
+ XR_ENV?: string
844
+ 'natvie-version'?: string
845
+ 'react-sdk-version'?: string
846
+ 'core-sdk-version'?: string
847
+ }
848
+
849
+ innerDepth: number
850
+ outerDepth: number
851
+ }
852
+
853
+ interface HTMLElement {
854
+ offsetBack: number
855
+ clientDepth: number
856
+ getBoundingClientCube: () => CubeInfo | undefined
857
+ }
738
858
  }
739
859
 
740
- export { type BackgroundMaterialType, type CornerRadius, type LoadingMethodKind, Spatial, SpatialComponent, SpatialEntity, SpatialHelper, SpatialInputComponent, SpatialMeshResource, SpatialModel3DComponent, SpatialModelComponent, type SpatialModelDragEvent, SpatialPhysicallyBasedMaterialResource, SpatialSession, SpatialTransform, SpatialViewComponent, SpatialWindowComponent, SpatialWindowContainer, type StyleParam, Vec3, Vec4, type WindowContainerOptions, type WindowStyle, type sceneDataJSBShape, type sceneDataShape };
860
+ declare const isSSREnv: () => boolean;
861
+
862
+ export { type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo$1 as CubeInfo, type ModelAssetOptions, ModelComponent, type ModelComponentOptions, type Point3D, type Size, type Size3D, Spatial, SpatialBoxGeometry, type SpatialBoxGeometryOptions, SpatialComponent, SpatialConeGeometry, type SpatialConeGeometryOptions, SpatialCylinderGeometry, type SpatialCylinderGeometryOptions, type SpatialDragEndEvent, type SpatialDragEvent, type SpatialDragEventDetail, SpatialEntity, type SpatialEntityEventType, type SpatialEntityOrReality, type SpatialEntityProperties, type SpatialEntityUserData, SpatialGeometry, type SpatialGeometryOptions, type SpatialGeometryType, type SpatialMagnifyEndEvent, type SpatialMagnifyEvent, type SpatialMagnifyEventDetail, SpatialMaterial, type SpatialMaterialType, SpatialModelAsset, type SpatialModelDragEvent, SpatialModelEntity, type SpatialModelEntityCreationOptions, SpatialObject, SpatialPlaneGeometry, type SpatialPlaneGeometryOptions, type SpatialRotateEndEvent, type SpatialRotateEvent, type SpatialRotateEventDetail, SpatialScene, type SpatialSceneCreationOptions$1 as SpatialSceneCreationOptions, type SpatialSceneProperties, SpatialSceneState$1 as SpatialSceneState, type SpatialSceneType$1 as SpatialSceneType, SpatialSceneValues, SpatialSession, SpatialSphereGeometry, type SpatialSphereGeometryOptions, type SpatialTapEvent, type SpatialTapEventDetail, SpatialUnlitMaterial, type SpatialUnlitMaterialOptions, Spatialized2DElement, type Spatialized2DElementProperties, SpatializedDynamic3DElement, SpatializedElement, type SpatializedElementProperties, SpatializedElementType, SpatializedStatic3DElement, type SpatializedStatic3DElementProperties, type Vec3, type WorldAlignmentType, WorldAlignmentValues, type WorldScalingType, WorldScalingValues, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };