@webspatial/core-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/core/Spatial.d.ts +27 -0
  2. package/dist/core/Spatial.d.ts.map +1 -0
  3. package/dist/core/Spatial.js +41 -0
  4. package/dist/core/SpatialEntity.d.ts +92 -0
  5. package/dist/core/SpatialEntity.d.ts.map +1 -0
  6. package/dist/core/SpatialEntity.js +121 -0
  7. package/dist/core/SpatialHelper.d.ts +39 -0
  8. package/dist/core/SpatialHelper.d.ts.map +1 -0
  9. package/dist/core/SpatialHelper.js +169 -0
  10. package/dist/core/SpatialObject.d.ts +19 -0
  11. package/dist/core/SpatialObject.d.ts.map +1 -0
  12. package/dist/core/SpatialObject.js +22 -0
  13. package/dist/core/SpatialSession.d.ts +166 -0
  14. package/dist/core/SpatialSession.d.ts.map +1 -0
  15. package/dist/core/SpatialSession.js +310 -0
  16. package/dist/core/SpatialTransform.d.ts +23 -0
  17. package/dist/core/SpatialTransform.d.ts.map +1 -0
  18. package/dist/core/SpatialTransform.js +31 -0
  19. package/dist/core/SpatialWindowContainer.d.ts +31 -0
  20. package/dist/core/SpatialWindowContainer.d.ts.map +1 -0
  21. package/dist/core/SpatialWindowContainer.js +48 -0
  22. package/dist/core/component/EventSpatialComponent.d.ts +22 -0
  23. package/dist/core/component/EventSpatialComponent.d.ts.map +1 -0
  24. package/dist/core/component/EventSpatialComponent.js +23 -0
  25. package/dist/core/component/SpatialComponent.d.ts +11 -0
  26. package/dist/core/component/SpatialComponent.d.ts.map +1 -0
  27. package/dist/core/component/SpatialComponent.js +23 -0
  28. package/dist/core/component/SpatialInputComponent.d.ts +22 -0
  29. package/dist/core/component/SpatialInputComponent.d.ts.map +1 -0
  30. package/dist/core/component/SpatialInputComponent.js +14 -0
  31. package/dist/core/component/SpatialModel3DComponent.d.ts +86 -0
  32. package/dist/core/component/SpatialModel3DComponent.d.ts.map +1 -0
  33. package/dist/core/component/SpatialModel3DComponent.js +176 -0
  34. package/dist/core/component/SpatialModelComponent.d.ts +22 -0
  35. package/dist/core/component/SpatialModelComponent.d.ts.map +1 -0
  36. package/dist/core/component/SpatialModelComponent.js +34 -0
  37. package/dist/core/component/SpatialViewComponent.d.ts +22 -0
  38. package/dist/core/component/SpatialViewComponent.d.ts.map +1 -0
  39. package/dist/core/component/SpatialViewComponent.js +30 -0
  40. package/dist/core/component/SpatialWindowComponent.d.ts +86 -0
  41. package/dist/core/component/SpatialWindowComponent.d.ts.map +1 -0
  42. package/dist/core/component/SpatialWindowComponent.js +114 -0
  43. package/dist/core/component/index.d.ts +7 -0
  44. package/dist/core/component/index.d.ts.map +1 -0
  45. package/dist/core/component/index.js +6 -0
  46. package/dist/core/index.d.ts +11 -0
  47. package/dist/core/index.d.ts.map +1 -0
  48. package/dist/core/index.js +9 -0
  49. package/dist/core/private/WebSpatial.d.ts +46 -0
  50. package/dist/core/private/WebSpatial.d.ts.map +1 -0
  51. package/dist/core/private/WebSpatial.js +282 -0
  52. package/dist/core/private/remote-command/RemoteCommand.d.ts +8 -0
  53. package/dist/core/private/remote-command/RemoteCommand.d.ts.map +1 -0
  54. package/dist/core/private/remote-command/RemoteCommand.js +11 -0
  55. package/dist/core/private/remote-command/index.d.ts +2 -0
  56. package/dist/core/private/remote-command/index.d.ts.map +1 -0
  57. package/dist/core/private/remote-command/index.js +1 -0
  58. package/dist/core/resource/SpatialMeshResource.d.ts +7 -0
  59. package/dist/core/resource/SpatialMeshResource.d.ts.map +1 -0
  60. package/dist/core/resource/SpatialMeshResource.js +6 -0
  61. package/dist/core/resource/SpatialPhysicallyBasedMaterialResource.d.ts +37 -0
  62. package/dist/core/resource/SpatialPhysicallyBasedMaterialResource.d.ts.map +1 -0
  63. package/dist/core/resource/SpatialPhysicallyBasedMaterialResource.js +37 -0
  64. package/dist/core/resource/index.d.ts +3 -0
  65. package/dist/core/resource/index.d.ts.map +1 -0
  66. package/dist/core/resource/index.js +2 -0
  67. package/dist/core/types.d.ts +23 -0
  68. package/dist/core/types.d.ts.map +1 -0
  69. package/dist/core/types.js +1 -0
  70. package/dist/index.d.ts +2 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +1 -0
  73. package/package.json +35 -0
  74. package/src/core/Spatial.ts +48 -0
  75. package/src/core/SpatialEntity.ts +146 -0
  76. package/src/core/SpatialHelper.ts +197 -0
  77. package/src/core/SpatialObject.ts +24 -0
  78. package/src/core/SpatialSession.ts +434 -0
  79. package/src/core/SpatialTransform.ts +26 -0
  80. package/src/core/SpatialWindowContainer.ts +51 -0
  81. package/src/core/component/EventSpatialComponent.ts +32 -0
  82. package/src/core/component/SpatialComponent.ts +26 -0
  83. package/src/core/component/SpatialInputComponent.ts +24 -0
  84. package/src/core/component/SpatialModel3DComponent.ts +213 -0
  85. package/src/core/component/SpatialModelComponent.ts +39 -0
  86. package/src/core/component/SpatialViewComponent.ts +32 -0
  87. package/src/core/component/SpatialWindowComponent.ts +168 -0
  88. package/src/core/component/index.ts +14 -0
  89. package/src/core/index.ts +10 -0
  90. package/src/core/private/WebSpatial.ts +356 -0
  91. package/src/core/private/remote-command/RemoteCommand.ts +15 -0
  92. package/src/core/private/remote-command/index.ts +1 -0
  93. package/src/core/resource/SpatialMeshResource.ts +6 -0
  94. package/src/core/resource/SpatialPhysicallyBasedMaterialResource.ts +42 -0
  95. package/src/core/resource/index.ts +2 -0
  96. package/src/core/types.ts +27 -0
  97. package/src/index.ts +1 -0
  98. package/tsconfig.json +26 -0
@@ -0,0 +1,166 @@
1
+ import { SpatialEntity } from './SpatialEntity';
2
+ import { SpatialWindowContainer } from './SpatialWindowContainer';
3
+ import { LoadingMethodKind, sceneDataShape, WindowStyle } from './types';
4
+ import { SpatialMeshResource, SpatialPhysicallyBasedMaterialResource } from './resource';
5
+ import { SpatialModelComponent, SpatialInputComponent, SpatialWindowComponent, SpatialViewComponent, SpatialModel3DComponent } from './component';
6
+ /**
7
+ * Animation callback with timestamp
8
+ */
9
+ type animCallback = (time: DOMHighResTimeStamp) => Promise<any>;
10
+ /**
11
+ * Session use to establish a connection to the spatial renderer of the system. All resources must be created by the session
12
+ */
13
+ export declare class SpatialSession {
14
+ /** @hidden */
15
+ _engineUpdateListeners: animCallback[];
16
+ /** @hidden */
17
+ _frameLoopStarted: boolean;
18
+ /**
19
+ * Add event listener callback to be called each frame
20
+ * @param callback callback to be called each update
21
+ */
22
+ addOnEngineUpdateEventListener(callback: animCallback): void;
23
+ /**
24
+ * Creates a Entity
25
+ * @returns Entity
26
+ */
27
+ createEntity(): Promise<SpatialEntity>;
28
+ /**
29
+ * Creates a WindowComponent
30
+ * [TODO] should creation of components be moved to entity? and these made private?
31
+ * @returns WindowComponent
32
+ */
33
+ createWindowComponent(options?: {
34
+ windowContainer?: SpatialWindowContainer;
35
+ }): Promise<SpatialWindowComponent>;
36
+ /**
37
+ * Creates a ViewComponent used to display 3D content within the entity
38
+ * @returns SpatialViewComponent
39
+ */
40
+ createViewComponent(options?: {
41
+ windowContainer?: SpatialWindowContainer;
42
+ }): Promise<SpatialViewComponent>;
43
+ /**
44
+ * Creates a ModelComponent used to display geometry + material of a 3D model
45
+ * @returns ModelComponent
46
+ */
47
+ createModelComponent(options?: {
48
+ url: string;
49
+ }): Promise<SpatialModelComponent>;
50
+ /**
51
+ * Creates a Model3DComponent
52
+ * @returns Model3DComponent
53
+ */
54
+ createModel3DComponent(options?: {
55
+ url: string;
56
+ }): Promise<SpatialModel3DComponent>;
57
+ /**
58
+ * Creates a InputComponent
59
+ * [Experimental] Creates a InputComponent used to handle click and drag events of the entity containing a model
60
+ * @returns InputComponent
61
+ */
62
+ createInputComponent(): Promise<SpatialInputComponent>;
63
+ /**
64
+ * Creates a MeshResource containing geometry data
65
+ * @returns MeshResource
66
+ */
67
+ createMeshResource(options?: {
68
+ shape?: string;
69
+ }): Promise<SpatialMeshResource>;
70
+ /**
71
+ * Creates a PhysicallyBasedMaterial containing PBR material data
72
+ * @returns PhysicallyBasedMaterial
73
+ */
74
+ createPhysicallyBasedMaterialResource(options?: {}): Promise<SpatialPhysicallyBasedMaterialResource>;
75
+ /**
76
+ * Creates a WindowContainer
77
+ * @returns SpatialWindowContainer
78
+ * */
79
+ createWindowContainer(options?: {
80
+ style: WindowStyle;
81
+ windowContainer?: SpatialWindowContainer | null;
82
+ windowComponent?: SpatialWindowComponent | null;
83
+ }): Promise<SpatialWindowContainer>;
84
+ /**
85
+ * Creates a Scene to display content within an anchored area managed by the OS
86
+ * @hidden
87
+ * @param {WindowStyle} [style='Plain'] - The style of the Scene container to be created with. Defaults to 'Plain'.
88
+ * @param {Object} [cfg={}] - Configuration object for the Scene.
89
+ * @returns Boolean
90
+ */
91
+ _createScene(style: WindowStyle | undefined, cfg: {
92
+ sceneData: sceneDataShape;
93
+ }): Promise<boolean>;
94
+ /**
95
+ * Retrieves the window for this page
96
+ * @returns the window component corresponding to the js running on this page
97
+ * [TODO] discuss implications of this not being async
98
+ */
99
+ getCurrentWindowComponent(): SpatialWindowComponent;
100
+ /**
101
+ * Retrieves the parent window for this page or null if this is the root page
102
+ * @returns the window component or null
103
+ */
104
+ getParentWindowComponent(): Promise<SpatialWindowComponent | null>;
105
+ /**
106
+ * Logs a message to the native apps console
107
+ * @param msg mesage to log
108
+ */
109
+ log(...msg: any[]): Promise<void>;
110
+ /**
111
+ * @hidden
112
+ * Debugging only, used to ping the native renderer
113
+ */
114
+ _ping(msg: string): Promise<unknown>;
115
+ /**
116
+ * @hidden
117
+ * Debugging to get internal state from native code
118
+ * @returns data as a js object
119
+ */
120
+ _getStats(): Promise<{
121
+ objects: any;
122
+ refObjects: any;
123
+ }>;
124
+ /**
125
+ * @hidden
126
+ */
127
+ _inspect(spatialObjectId?: string): Promise<any>;
128
+ /**
129
+ * @hidden
130
+ */
131
+ _inspectRootWindowContainer(): Promise<any>;
132
+ /** Opens the immersive space */
133
+ openImmersiveSpace(): Promise<void>;
134
+ /** Closes the immersive space */
135
+ dismissImmersiveSpace(): Promise<void>;
136
+ private static _immersiveWindowContainer;
137
+ /**
138
+ * Retreives the window container corresponding to the Immersive space
139
+ * @returns the immersive window container
140
+ */
141
+ getImmersiveWindowContainer(): Promise<SpatialWindowContainer>;
142
+ private static _currentWindowContainer;
143
+ /**
144
+ * Gets the current window container for the window
145
+ * [TODO] discuss what happens if it doesnt yet have a window container
146
+ * @returns the current window container for the window
147
+ */
148
+ getCurrentWindowContainer(): SpatialWindowContainer;
149
+ /**
150
+ * Start a transaction that queues up commands to submit them all at once to reduce ipc overhead
151
+ * @param fn function to be run, within this function, promises will not resolve
152
+ * @returns promise for the entire transaction completion
153
+ */
154
+ transaction(fn: Function): Promise<unknown>;
155
+ /**
156
+ * Creates a window context object that is compatable with SpatialWindowComponent's setFromWindow API
157
+ * @returns window context
158
+ */
159
+ createWindowContext(): Promise<Window | null>;
160
+ /** @hidden */
161
+ _getEntity(id: string): Promise<SpatialEntity>;
162
+ /** @hidden */
163
+ setLoading(method: LoadingMethodKind, style?: string): Promise<unknown>;
164
+ }
165
+ export {};
166
+ //# sourceMappingURL=SpatialSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialSession.d.ts","sourceRoot":"","sources":["../../src/core/SpatialSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAMjE,OAAO,EACL,iBAAiB,EACjB,cAAc,EAEd,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,OAAO,EACL,mBAAmB,EACnB,sCAAsC,EACvC,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,aAAa,CAAA;AAGpB;;GAEG;AACH,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,mBAAmB,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AA4B/D;;GAEG;AACH,qBAAa,cAAc;IACzB,cAAc;IACd,sBAAsB,iBAAwB;IAC9C,cAAc;IACd,iBAAiB,UAAQ;IAEzB;;;OAGG;IACH,8BAA8B,CAAC,QAAQ,EAAE,YAAY;IAerD;;;OAGG;IACG,YAAY;IASlB;;;;OAIG;IACG,qBAAqB,CAAC,OAAO,CAAC,EAAE;QACpC,eAAe,CAAC,EAAE,sBAAsB,CAAA;KACzC;IAWD;;;OAGG;IACG,mBAAmB,CAAC,OAAO,CAAC,EAAE;QAClC,eAAe,CAAC,EAAE,sBAAsB,CAAA;KACzC;IAWD;;;OAGG;IACG,oBAAoB,CAAC,OAAO,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE;IAcpD;;;OAGG;IACG,sBAAsB,CAAC,OAAO,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE;IActD;;;;OAIG;IACG,oBAAoB;IAS1B;;;OAGG;IACG,kBAAkB,CAAC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAUrD;;;OAGG;IACG,qCAAqC,CAAC,OAAO,CAAC,EAAE,EAAE;IASxD;;;SAGK;IACC,qBAAqB,CAAC,OAAO,CAAC,EAAE;QACpC,KAAK,EAAE,WAAW,CAAA;QAClB,eAAe,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAA;QAC/C,eAAe,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAA;KAChD;IAYD;;;;;;OAMG;IACG,YAAY,CAChB,KAAK,EAAE,WAAW,YAAU,EAC5B,GAAG,EAAE;QACH,SAAS,EAAE,cAAc,CAAA;KAC1B;IAKH;;;;OAIG;IACH,yBAAyB;IAIzB;;;OAGG;IACG,wBAAwB;IAgB9B;;;OAGG;IACG,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAIvB;;;OAGG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM;IAIvB;;;;OAIG;IACG,SAAS;iBACsC,GAAG;oBAAc,GAAG;;IAGzE;;OAEG;IACG,QAAQ,CAAC,eAAe,GAAE,MAA2C;IAI3E;;OAEG;IACG,2BAA2B;IAIjC,gCAAgC;IAC1B,kBAAkB;IAIxB,iCAAiC;IAC3B,qBAAqB;IAI3B,OAAO,CAAC,MAAM,CAAC,yBAAyB,CACD;IACvC;;;OAGG;IACG,2BAA2B;IAYjC,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAAwC;IAE9E;;;;OAIG;IACH,yBAAyB;IAWzB;;;;OAIG;IACH,WAAW,CAAC,EAAE,EAAE,QAAQ;IAMxB;;;OAGG;IACG,mBAAmB;IAgCzB,cAAc;IACR,UAAU,CAAC,EAAE,EAAE,MAAM;IAoB3B,cAAc;IACR,UAAU,CAAC,MAAM,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,MAAM;CAG3D"}
@@ -0,0 +1,310 @@
1
+ import { SpatialEntity } from './SpatialEntity';
2
+ import { SpatialWindowContainer } from './SpatialWindowContainer';
3
+ import { WebSpatial, WebSpatialResource, } from './private/WebSpatial';
4
+ import { SpatialMeshResource, SpatialPhysicallyBasedMaterialResource, } from './resource';
5
+ import { SpatialModelComponent, SpatialInputComponent, SpatialWindowComponent, SpatialViewComponent, SpatialModel3DComponent, } from './component';
6
+ import { RemoteCommand } from './private/remote-command';
7
+ /**
8
+ * Parses the resource owners of the created object. If unedfined, will use the current window container and web panel. If null the created resource will not be destroyed unless explicitly destroyed.
9
+ * @param options
10
+ * @returns parsed results
11
+ */
12
+ function _parseParentResources(options) {
13
+ var parentWindowContainer = null;
14
+ if (options?.windowContainer !== null) {
15
+ parentWindowContainer = options?.windowContainer
16
+ ? options?.windowContainer._wg
17
+ : WebSpatial.getCurrentWindowContainer();
18
+ }
19
+ var parentWindow = null;
20
+ if (options?.windowComponent !== null) {
21
+ parentWindow = options?.windowComponent
22
+ ? options?.windowComponent._resource
23
+ : WebSpatial.getCurrentWebPanel();
24
+ }
25
+ return [parentWindowContainer, parentWindow];
26
+ }
27
+ /**
28
+ * Session use to establish a connection to the spatial renderer of the system. All resources must be created by the session
29
+ */
30
+ export class SpatialSession {
31
+ /** @hidden */
32
+ _engineUpdateListeners = Array();
33
+ /** @hidden */
34
+ _frameLoopStarted = false;
35
+ /**
36
+ * Add event listener callback to be called each frame
37
+ * @param callback callback to be called each update
38
+ */
39
+ addOnEngineUpdateEventListener(callback) {
40
+ this._engineUpdateListeners.push(callback);
41
+ if (!this._frameLoopStarted) {
42
+ this._frameLoopStarted = true;
43
+ WebSpatial.onFrame(async (time) => {
44
+ await Promise.all(this._engineUpdateListeners.map(cb => {
45
+ return cb(time);
46
+ }));
47
+ });
48
+ }
49
+ }
50
+ /**
51
+ * Creates a Entity
52
+ * @returns Entity
53
+ */
54
+ async createEntity() {
55
+ let entity = await WebSpatial.createResource('Entity', WebSpatial.getCurrentWindowContainer(), WebSpatial.getCurrentWebPanel());
56
+ return new SpatialEntity(entity);
57
+ }
58
+ /**
59
+ * Creates a WindowComponent
60
+ * [TODO] should creation of components be moved to entity? and these made private?
61
+ * @returns WindowComponent
62
+ */
63
+ async createWindowComponent(options) {
64
+ let entity = await WebSpatial.createResource('SpatialWebView', options?.windowContainer
65
+ ? options?.windowContainer._wg
66
+ : WebSpatial.getCurrentWindowContainer(), WebSpatial.getCurrentWebPanel());
67
+ return new SpatialWindowComponent(entity);
68
+ }
69
+ /**
70
+ * Creates a ViewComponent used to display 3D content within the entity
71
+ * @returns SpatialViewComponent
72
+ */
73
+ async createViewComponent(options) {
74
+ let entity = await WebSpatial.createResource('SpatialView', options?.windowContainer
75
+ ? options?.windowContainer._wg
76
+ : WebSpatial.getCurrentWindowContainer(), WebSpatial.getCurrentWebPanel());
77
+ return new SpatialViewComponent(entity);
78
+ }
79
+ /**
80
+ * Creates a ModelComponent used to display geometry + material of a 3D model
81
+ * @returns ModelComponent
82
+ */
83
+ async createModelComponent(options) {
84
+ var opts = undefined;
85
+ if (options) {
86
+ opts = { modelURL: options.url };
87
+ }
88
+ let entity = await WebSpatial.createResource('ModelComponent', WebSpatial.getCurrentWindowContainer(), WebSpatial.getCurrentWebPanel(), opts);
89
+ return new SpatialModelComponent(entity);
90
+ }
91
+ /**
92
+ * Creates a Model3DComponent
93
+ * @returns Model3DComponent
94
+ */
95
+ async createModel3DComponent(options) {
96
+ var opts = undefined;
97
+ if (options) {
98
+ opts = { modelURL: options.url };
99
+ }
100
+ let entity = await WebSpatial.createResource('Model3DComponent', WebSpatial.getCurrentWindowContainer(), WebSpatial.getCurrentWebPanel(), opts);
101
+ return new SpatialModel3DComponent(entity);
102
+ }
103
+ /**
104
+ * Creates a InputComponent
105
+ * [Experimental] Creates a InputComponent used to handle click and drag events of the entity containing a model
106
+ * @returns InputComponent
107
+ */
108
+ async createInputComponent() {
109
+ let entity = await WebSpatial.createResource('InputComponent', WebSpatial.getCurrentWindowContainer(), WebSpatial.getCurrentWebPanel());
110
+ return new SpatialInputComponent(entity);
111
+ }
112
+ /**
113
+ * Creates a MeshResource containing geometry data
114
+ * @returns MeshResource
115
+ */
116
+ async createMeshResource(options) {
117
+ let entity = await WebSpatial.createResource('MeshResource', WebSpatial.getCurrentWindowContainer(), WebSpatial.getCurrentWebPanel(), options);
118
+ return new SpatialMeshResource(entity);
119
+ }
120
+ /**
121
+ * Creates a PhysicallyBasedMaterial containing PBR material data
122
+ * @returns PhysicallyBasedMaterial
123
+ */
124
+ async createPhysicallyBasedMaterialResource(options) {
125
+ let entity = await WebSpatial.createResource('PhysicallyBasedMaterial', WebSpatial.getCurrentWindowContainer(), WebSpatial.getCurrentWebPanel(), options);
126
+ return new SpatialPhysicallyBasedMaterialResource(entity);
127
+ }
128
+ /**
129
+ * Creates a WindowContainer
130
+ * @returns SpatialWindowContainer
131
+ * */
132
+ async createWindowContainer(options) {
133
+ var style = options?.style ? options?.style : 'Plain';
134
+ var [parentWindowContainer, parentWindow] = _parseParentResources(options);
135
+ return new SpatialWindowContainer(await WebSpatial.createWindowContainer(style, parentWindowContainer, parentWindow));
136
+ }
137
+ /**
138
+ * Creates a Scene to display content within an anchored area managed by the OS
139
+ * @hidden
140
+ * @param {WindowStyle} [style='Plain'] - The style of the Scene container to be created with. Defaults to 'Plain'.
141
+ * @param {Object} [cfg={}] - Configuration object for the Scene.
142
+ * @returns Boolean
143
+ */
144
+ async _createScene(style = 'Plain', cfg) {
145
+ return await WebSpatial.createScene(style, cfg);
146
+ }
147
+ /**
148
+ * Retrieves the window for this page
149
+ * @returns the window component corresponding to the js running on this page
150
+ * [TODO] discuss implications of this not being async
151
+ */
152
+ getCurrentWindowComponent() {
153
+ return new SpatialWindowComponent(WebSpatial.getCurrentWebPanel());
154
+ }
155
+ /**
156
+ * Retrieves the parent window for this page or null if this is the root page
157
+ * @returns the window component or null
158
+ */
159
+ async getParentWindowComponent() {
160
+ let parentResp = await WebSpatial.updateResource(WebSpatial.getCurrentWebPanel(), { getParentID: '' });
161
+ if (parentResp.data.parentID === '') {
162
+ return new Promise((res, rej) => {
163
+ res(null);
164
+ });
165
+ }
166
+ else {
167
+ var res = new WebSpatialResource();
168
+ res.id = parentResp.data.parentID;
169
+ return new SpatialWindowComponent(res);
170
+ }
171
+ }
172
+ /**
173
+ * Logs a message to the native apps console
174
+ * @param msg mesage to log
175
+ */
176
+ async log(...msg) {
177
+ await WebSpatial.sendCommand(new RemoteCommand('log', { logString: msg }));
178
+ }
179
+ /**
180
+ * @hidden
181
+ * Debugging only, used to ping the native renderer
182
+ */
183
+ async _ping(msg) {
184
+ return await WebSpatial.ping(msg);
185
+ }
186
+ /**
187
+ * @hidden
188
+ * Debugging to get internal state from native code
189
+ * @returns data as a js object
190
+ */
191
+ async _getStats() {
192
+ return (await WebSpatial.getStats());
193
+ }
194
+ /**
195
+ * @hidden
196
+ */
197
+ async _inspect(spatialObjectId = WebSpatial.getCurrentWebPanel().id) {
198
+ return WebSpatial.inspect(spatialObjectId);
199
+ }
200
+ /**
201
+ * @hidden
202
+ */
203
+ async _inspectRootWindowContainer() {
204
+ return WebSpatial.inspectRootWindowContainer();
205
+ }
206
+ /** Opens the immersive space */
207
+ async openImmersiveSpace() {
208
+ return await WebSpatial.openImmersiveSpace();
209
+ }
210
+ /** Closes the immersive space */
211
+ async dismissImmersiveSpace() {
212
+ return await WebSpatial.dismissImmersiveSpace();
213
+ }
214
+ static _immersiveWindowContainer = null;
215
+ /**
216
+ * Retreives the window container corresponding to the Immersive space
217
+ * @returns the immersive window container
218
+ */
219
+ async getImmersiveWindowContainer() {
220
+ if (SpatialSession._immersiveWindowContainer) {
221
+ return SpatialSession._immersiveWindowContainer;
222
+ }
223
+ else {
224
+ SpatialSession._immersiveWindowContainer = new SpatialWindowContainer(WebSpatial.getImmersiveWindowContainer());
225
+ return SpatialSession._immersiveWindowContainer;
226
+ }
227
+ }
228
+ // Retreives the window container that is the parent to this spatial web page
229
+ static _currentWindowContainer = null;
230
+ /**
231
+ * Gets the current window container for the window
232
+ * [TODO] discuss what happens if it doesnt yet have a window container
233
+ * @returns the current window container for the window
234
+ */
235
+ getCurrentWindowContainer() {
236
+ if (SpatialSession._currentWindowContainer) {
237
+ return SpatialSession._currentWindowContainer;
238
+ }
239
+ else {
240
+ SpatialSession._currentWindowContainer = new SpatialWindowContainer(WebSpatial.getCurrentWindowContainer());
241
+ return SpatialSession._currentWindowContainer;
242
+ }
243
+ }
244
+ /**
245
+ * Start a transaction that queues up commands to submit them all at once to reduce ipc overhead
246
+ * @param fn function to be run, within this function, promises will not resolve
247
+ * @returns promise for the entire transaction completion
248
+ */
249
+ transaction(fn) {
250
+ WebSpatial.startTransaction();
251
+ fn();
252
+ return WebSpatial.sendTransaction();
253
+ }
254
+ /**
255
+ * Creates a window context object that is compatable with SpatialWindowComponent's setFromWindow API
256
+ * @returns window context
257
+ */
258
+ async createWindowContext() {
259
+ let openedWindow = window.open('webspatial://createWindowContext');
260
+ if (WebSpatial.getBackend() != 'AVP') {
261
+ // Currently there is a bug with webview which requires us to trigger a navigation before native code can interact with created webview
262
+ var counter = 0;
263
+ while (openedWindow.window.testAPI == null) {
264
+ if (counter > 15) {
265
+ openedWindow?.close();
266
+ openedWindow = window.open('about:blank');
267
+ counter = 0;
268
+ this.log('unexpected error when trying to open new window, retrying.');
269
+ }
270
+ var locName = 'about:blank?x' + counter;
271
+ openedWindow.location.href = locName;
272
+ counter++;
273
+ await new Promise(resolve => setTimeout(resolve, 10));
274
+ }
275
+ ;
276
+ openedWindow._webSpatialID = openedWindow.window.testAPI.getWindowID();
277
+ }
278
+ else {
279
+ while (openedWindow.window._webSpatialID == undefined) {
280
+ await new Promise(resolve => setTimeout(resolve, 10));
281
+ }
282
+ }
283
+ openedWindow.document.head.innerHTML =
284
+ '<meta name="viewport" content="width=device-width, initial-scale=1">';
285
+ return openedWindow;
286
+ }
287
+ // Get Entity by id. Currently for debugging only.
288
+ /** @hidden */
289
+ async _getEntity(id) {
290
+ const entityInfo = await WebSpatial.inspect(id);
291
+ const [_, x, y, z] = entityInfo.position.match(/(\d+\.?\d*)/g);
292
+ const [__, sx, sy, sz] = entityInfo.scale.match(/(\d+\.?\d*)/g);
293
+ var res = new WebSpatialResource();
294
+ res.id = id;
295
+ res.windowContainerId = WebSpatial.getCurrentWindowContainer().id;
296
+ const entity = new SpatialEntity(res);
297
+ entity.transform.position.x = parseFloat(x);
298
+ entity.transform.position.y = parseFloat(y);
299
+ entity.transform.position.z = parseFloat(z);
300
+ entity.transform.scale.x = parseFloat(sx);
301
+ entity.transform.scale.y = parseFloat(sy);
302
+ entity.transform.scale.z = parseFloat(sz);
303
+ return entity;
304
+ }
305
+ // set loading view.
306
+ /** @hidden */
307
+ async setLoading(method, style) {
308
+ return WebSpatial.setLoading(method, style);
309
+ }
310
+ }
@@ -0,0 +1,23 @@
1
+ export declare class Vec3 {
2
+ x: number;
3
+ y: number;
4
+ z: number;
5
+ constructor(x?: number, y?: number, z?: number);
6
+ }
7
+ export declare class Vec4 {
8
+ x: number;
9
+ y: number;
10
+ z: number;
11
+ w: number;
12
+ constructor(x?: number, y?: number, z?: number, w?: number);
13
+ }
14
+ /**
15
+ * Transform containing position, orientation and scale
16
+ */
17
+ export declare class SpatialTransform {
18
+ position: Vec3;
19
+ /** Quaternion value for x,y,z,w */
20
+ orientation: Vec4;
21
+ scale: Vec3;
22
+ }
23
+ //# sourceMappingURL=SpatialTransform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialTransform.d.ts","sourceRoot":"","sources":["../../src/core/SpatialTransform.ts"],"names":[],"mappings":"AAAA,qBAAa,IAAI;IAEN,CAAC;IACD,CAAC;IACD,CAAC;gBAFD,CAAC,SAAI,EACL,CAAC,SAAI,EACL,CAAC,SAAI;CAEf;AAED,qBAAa,IAAI;IAEN,CAAC;IACD,CAAC;IACD,CAAC;IACD,CAAC;gBAHD,CAAC,SAAI,EACL,CAAC,SAAI,EACL,CAAC,SAAI,EACL,CAAC,SAAI;CAEf;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,QAAQ,OAAoB;IAC5B,mCAAmC;IACnC,WAAW,OAAuB;IAClC,KAAK,OAAoB;CAC1B"}
@@ -0,0 +1,31 @@
1
+ export class Vec3 {
2
+ x;
3
+ y;
4
+ z;
5
+ constructor(x = 0, y = 0, z = 0) {
6
+ this.x = x;
7
+ this.y = y;
8
+ this.z = z;
9
+ }
10
+ }
11
+ export class Vec4 {
12
+ x;
13
+ y;
14
+ z;
15
+ w;
16
+ constructor(x = 0, y = 0, z = 0, w = 1) {
17
+ this.x = x;
18
+ this.y = y;
19
+ this.z = z;
20
+ this.w = w;
21
+ }
22
+ }
23
+ /**
24
+ * Transform containing position, orientation and scale
25
+ */
26
+ export class SpatialTransform {
27
+ position = new Vec3(0, 0, 0);
28
+ /** Quaternion value for x,y,z,w */
29
+ orientation = new Vec4(0, 0, 0, 1);
30
+ scale = new Vec3(1, 1, 1);
31
+ }
@@ -0,0 +1,31 @@
1
+ import { WindowContainer } from './private/WebSpatial';
2
+ import { SpatialEntity } from './SpatialEntity';
3
+ /**
4
+ * Anchored window managed by the OS
5
+ */
6
+ export declare class SpatialWindowContainer {
7
+ /** @hidden */
8
+ _wg: WindowContainer;
9
+ /** @hidden */
10
+ constructor(
11
+ /** @hidden */
12
+ _wg: WindowContainer);
13
+ /**
14
+ * @hidden
15
+ * Sets sets the open configuration for opening new window containers
16
+ * @param options style options
17
+ */
18
+ _setOpenSettings(options: {
19
+ resolution: {
20
+ width: number;
21
+ height: number;
22
+ };
23
+ }): Promise<void>;
24
+ /**
25
+ * Retrieves the root entity of the windowContainer
26
+ * @returns the root entity of the windowContainer if one exists
27
+ */
28
+ getRootEntity(): Promise<SpatialEntity | null>;
29
+ setRootEntity(entity: SpatialEntity): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=SpatialWindowContainer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialWindowContainer.d.ts","sourceRoot":"","sources":["../../src/core/SpatialWindowContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EAChB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C;;GAEG;AACH,qBAAa,sBAAsB;IAG/B,cAAc;IACP,GAAG,EAAE,eAAe;IAH7B,cAAc;;IAEZ,cAAc;IACP,GAAG,EAAE,eAAe;IAE7B;;;;OAIG;IACG,gBAAgB,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE;IAMjF;;;OAGG;IACG,aAAa;IAgBb,aAAa,CAAC,MAAM,EAAE,aAAa;CAG1C"}
@@ -0,0 +1,48 @@
1
+ import { WebSpatial, WebSpatialResource, } from './private/WebSpatial';
2
+ import { SpatialEntity } from './SpatialEntity';
3
+ /**
4
+ * Anchored window managed by the OS
5
+ */
6
+ export class SpatialWindowContainer {
7
+ _wg;
8
+ /** @hidden */
9
+ constructor(
10
+ /** @hidden */
11
+ _wg) {
12
+ this._wg = _wg;
13
+ }
14
+ /**
15
+ * @hidden
16
+ * Sets sets the open configuration for opening new window containers
17
+ * @param options style options
18
+ */
19
+ async _setOpenSettings(options) {
20
+ await WebSpatial.updateWindowContainer(this._wg, {
21
+ nextOpenSettings: options,
22
+ });
23
+ }
24
+ /**
25
+ * Retrieves the root entity of the windowContainer
26
+ * @returns the root entity of the windowContainer if one exists
27
+ */
28
+ async getRootEntity() {
29
+ let reqResp = await WebSpatial.updateWindowContainer(this._wg, {
30
+ getRootEntityID: '',
31
+ });
32
+ if (reqResp.data.rootEntId === '') {
33
+ return null;
34
+ }
35
+ else {
36
+ var res = new WebSpatialResource();
37
+ res.id = reqResp.data.rootEntId;
38
+ return new SpatialEntity(res);
39
+ }
40
+ }
41
+ /*
42
+ * Sets the root entity that this windowContainer will display (this does not effect resource ownership)
43
+ * @param entity to display
44
+ */
45
+ async setRootEntity(entity) {
46
+ await entity._setParentWindowContainer(this);
47
+ }
48
+ }
@@ -0,0 +1,22 @@
1
+ import { WebSpatialResource } from '../private/WebSpatial';
2
+ import { SpatialComponent } from './SpatialComponent';
3
+ /**
4
+ * @description
5
+ * Represents a spatial component that handles events related to spatial interactions.
6
+ * This class extends `SpatialComponent` and provides additional functionality for managing
7
+ * event-driven spatial behaviors.
8
+ *
9
+ * @hidden
10
+ * This class is intended for internal use and should not be exposed in the public API.
11
+ */
12
+ export declare abstract class EventSpatialComponent extends SpatialComponent {
13
+ constructor(_resource: WebSpatialResource);
14
+ /**
15
+ * @description
16
+ * Abstract method to be implemented by subclasses. Called when a spatial event is received.
17
+ * @param data The data associated with the received event.
18
+ */
19
+ protected abstract onRecvEvent(data: any): void;
20
+ protected onDestroy(): Promise<void>;
21
+ }
22
+ //# sourceMappingURL=EventSpatialComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventSpatialComponent.d.ts","sourceRoot":"","sources":["../../../src/core/component/EventSpatialComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD;;;;;;;;GAQG;AACH,8BAAsB,qBAAsB,SAAQ,gBAAgB;gBAEtD,SAAS,EAAE,kBAAkB;IAOzC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;cAEtB,SAAS;CAGnC"}
@@ -0,0 +1,23 @@
1
+ import { WebSpatial } from '../private/WebSpatial';
2
+ import { SpatialComponent } from './SpatialComponent';
3
+ /**
4
+ * @description
5
+ * Represents a spatial component that handles events related to spatial interactions.
6
+ * This class extends `SpatialComponent` and provides additional functionality for managing
7
+ * event-driven spatial behaviors.
8
+ *
9
+ * @hidden
10
+ * This class is intended for internal use and should not be exposed in the public API.
11
+ */
12
+ export class EventSpatialComponent extends SpatialComponent {
13
+ // Class implementation goes here
14
+ constructor(_resource) {
15
+ super(_resource);
16
+ WebSpatial.registerEventReceiver(_resource.id, (data) => {
17
+ this.onRecvEvent(data);
18
+ });
19
+ }
20
+ async onDestroy() {
21
+ WebSpatial.unregisterEventReceiver(this._resource.id);
22
+ }
23
+ }