@webspatial/core-sdk 1.0.3 → 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.
- package/CHANGELOG.md +4 -0
- package/README.md +112 -81
- package/dist/iife/index.d.ts +683 -561
- package/dist/iife/index.global.js +3 -4
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +683 -561
- package/dist/index.js +2175 -1291
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/src/JSBCommand.ts +631 -0
- package/src/Spatial.ts +68 -0
- package/src/SpatialObject.ts +46 -0
- package/src/SpatialScene.ts +75 -0
- package/src/SpatialSession.ts +187 -0
- package/src/SpatialWebEvent.ts +23 -0
- package/src/SpatialWebEventCreator.ts +12 -0
- package/src/Spatialized2DElement.ts +51 -0
- package/src/SpatializedDynamic3DElement.ts +30 -0
- package/src/SpatializedElement.ts +331 -0
- package/src/SpatializedElementCreator.ts +45 -0
- package/src/SpatializedStatic3DElement.ts +111 -0
- package/src/WebMsgCommand.ts +88 -0
- package/src/index.ts +23 -1
- package/src/platform-adapter/CommandResultUtils.ts +22 -0
- package/src/platform-adapter/android/AndroidPlatform.ts +133 -0
- package/src/platform-adapter/index.ts +21 -0
- package/src/platform-adapter/interface.ts +36 -0
- package/src/platform-adapter/ssr/SSRPlatform.ts +43 -0
- package/src/platform-adapter/vision-os/VisionOSPlatform.ts +77 -0
- package/src/reality/component/ModelComponent.ts +11 -0
- package/src/reality/component/SpatialComponent.ts +17 -0
- package/src/reality/component/index.ts +2 -0
- package/src/reality/entity/SpatialEntity.ts +255 -0
- package/src/reality/entity/SpatialModelEntity.ts +15 -0
- package/src/reality/entity/index.ts +2 -0
- package/src/reality/geometry/SpatialBoxGeometry.ts +12 -0
- package/src/reality/geometry/SpatialConeGeometry.ts +15 -0
- package/src/reality/geometry/SpatialCylinderGeometry.ts +15 -0
- package/src/reality/geometry/SpatialGeometry.ts +12 -0
- package/src/reality/geometry/SpatialPlaneGeometry.ts +15 -0
- package/src/reality/geometry/SpatialSphereGeometry.ts +15 -0
- package/src/reality/geometry/index.ts +6 -0
- package/src/reality/index.ts +5 -0
- package/src/reality/material/SpatialMaterial.ts +14 -0
- package/src/reality/material/SpatialUnlitMaterial.ts +16 -0
- package/src/reality/material/index.ts +2 -0
- package/src/reality/realityCreator.ts +94 -0
- package/src/reality/resource/SpatialModelAsset.ts +11 -0
- package/src/reality/resource/index.ts +1 -0
- package/src/scene-polyfill.test.ts +376 -0
- package/src/scene-polyfill.ts +359 -0
- package/src/spatial-window-polyfill.ts +182 -0
- package/src/ssr-polyfill.ts +3 -0
- package/src/types/global.d.ts +33 -1
- package/src/types/internal.ts +13 -0
- package/src/types/types.ts +380 -0
- package/src/utils.ts +61 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +8 -0
- package/src/core/Spatial.ts +0 -50
- package/src/core/SpatialEntity.ts +0 -147
- package/src/core/SpatialHelper.ts +0 -230
- package/src/core/SpatialObject.ts +0 -26
- package/src/core/SpatialSession.ts +0 -457
- package/src/core/SpatialTransform.ts +0 -26
- package/src/core/SpatialWindowContainer.ts +0 -59
- package/src/core/component/EventSpatialComponent.ts +0 -32
- package/src/core/component/SpatialComponent.ts +0 -26
- package/src/core/component/SpatialInputComponent.ts +0 -24
- package/src/core/component/SpatialModel3DComponent.ts +0 -223
- package/src/core/component/SpatialModelComponent.ts +0 -39
- package/src/core/component/SpatialViewComponent.ts +0 -32
- package/src/core/component/SpatialWindowComponent.ts +0 -177
- package/src/core/component/index.ts +0 -14
- package/src/core/index.ts +0 -10
- package/src/core/private/WebSpatial.ts +0 -383
- package/src/core/private/remote-command/RemoteCommand.ts +0 -15
- package/src/core/private/remote-command/index.ts +0 -1
- package/src/core/resource/SpatialMeshResource.ts +0 -6
- package/src/core/resource/SpatialPhysicallyBasedMaterialResource.ts +0 -42
- package/src/core/resource/index.ts +0 -2
- package/src/core/types.ts +0 -32
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import type { SpatialEntity } from '..'
|
|
2
|
+
import { SpatialGeometry } from '../reality/geometry/SpatialGeometry'
|
|
3
|
+
import { SpatialMaterial } from '../reality/material/SpatialMaterial'
|
|
4
|
+
import type { SpatializedDynamic3DElement } from '../SpatializedDynamic3DElement'
|
|
5
|
+
|
|
6
|
+
export interface Vec3 {
|
|
7
|
+
x: number
|
|
8
|
+
y: number
|
|
9
|
+
z: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type Point3D = Vec3
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Material type for SpatialDiv or HTML document.
|
|
16
|
+
*
|
|
17
|
+
* This type defines the background material options for both SpatialDiv elements and HTML documents.
|
|
18
|
+
*
|
|
19
|
+
* - `'none'`: This is the default value.
|
|
20
|
+
* - For HTML documents, the web page window will have the default native background.
|
|
21
|
+
* - For SpatialDiv, the window will have a transparent background.
|
|
22
|
+
* - `'translucent'`: Represents a glass-like material in AVP (Apple Vision Pro).
|
|
23
|
+
* - `'thick'`: Represents a thick material in AVP.
|
|
24
|
+
* - `'regular'`: Represents a regular material in AVP.
|
|
25
|
+
* - `'thin'`: Represents a thin material in AVP.
|
|
26
|
+
* - `'transparent'`: Represents a fully transparent background.
|
|
27
|
+
*/
|
|
28
|
+
export type BackgroundMaterialType =
|
|
29
|
+
| 'none'
|
|
30
|
+
| 'translucent'
|
|
31
|
+
| 'thick'
|
|
32
|
+
| 'regular'
|
|
33
|
+
| 'thin'
|
|
34
|
+
| 'transparent'
|
|
35
|
+
|
|
36
|
+
export type CornerRadius = {
|
|
37
|
+
topLeading: number
|
|
38
|
+
bottomLeading: number
|
|
39
|
+
topTrailing: number
|
|
40
|
+
bottomTrailing: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SpatialSceneProperties {
|
|
44
|
+
cornerRadius: CornerRadius
|
|
45
|
+
material: BackgroundMaterialType
|
|
46
|
+
opacity: number
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export enum SpatializedElementType {
|
|
50
|
+
Spatialized2DElement,
|
|
51
|
+
SpatializedStatic3DElement,
|
|
52
|
+
SpatializedDynamic3DElement,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface SpatializedElementProperties {
|
|
56
|
+
name: string
|
|
57
|
+
clientX: number
|
|
58
|
+
clientY: number
|
|
59
|
+
width: number
|
|
60
|
+
height: number
|
|
61
|
+
depth: number
|
|
62
|
+
opacity: number
|
|
63
|
+
visible: boolean
|
|
64
|
+
scrollWithParent: boolean
|
|
65
|
+
zIndex: number
|
|
66
|
+
backOffset: number
|
|
67
|
+
rotationAnchor: Point3D
|
|
68
|
+
enableTapGesture: boolean
|
|
69
|
+
enableDragStartGesture: boolean
|
|
70
|
+
enableDragGesture: boolean
|
|
71
|
+
enableDragEndGesture: boolean
|
|
72
|
+
enableRotateStartGesture: boolean
|
|
73
|
+
enableRotateGesture: boolean
|
|
74
|
+
enableRotateEndGesture: boolean
|
|
75
|
+
enableMagnifyStartGesture: boolean
|
|
76
|
+
enableMagnifyGesture: boolean
|
|
77
|
+
enableMagnifyEndGesture: boolean
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface Spatialized2DElementProperties
|
|
81
|
+
extends SpatializedElementProperties {
|
|
82
|
+
scrollPageEnabled: boolean
|
|
83
|
+
cornerRadius: CornerRadius
|
|
84
|
+
material: BackgroundMaterialType
|
|
85
|
+
scrollEdgeInsetsMarginRight: number
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SpatializedStatic3DElementProperties
|
|
89
|
+
extends SpatializedElementProperties {
|
|
90
|
+
modelURL: string
|
|
91
|
+
modelTransform?: number[]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface SpatialSceneCreationOptions {
|
|
95
|
+
defaultSize?: {
|
|
96
|
+
width: number | string // Initial width of the window
|
|
97
|
+
height: number | string // Initial height of the window
|
|
98
|
+
depth?: number | string // Initial depth of the window, only for volume
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
resizability?: {
|
|
102
|
+
minWidth?: number | string // Minimum width of the window
|
|
103
|
+
minHeight?: number | string // Minimum height of the window
|
|
104
|
+
maxWidth?: number | string // Maximum width of the window
|
|
105
|
+
maxHeight?: number | string // Maximum height of the window
|
|
106
|
+
}
|
|
107
|
+
worldScaling?: WorldScalingType
|
|
108
|
+
worldAlignment?: WorldAlignmentType
|
|
109
|
+
|
|
110
|
+
baseplateVisibility?: BaseplateVisibilityType
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const BaseplateVisibilityValues = [
|
|
114
|
+
'automatic',
|
|
115
|
+
'visible',
|
|
116
|
+
'hidden',
|
|
117
|
+
] as const
|
|
118
|
+
export type BaseplateVisibilityType = (typeof BaseplateVisibilityValues)[number]
|
|
119
|
+
|
|
120
|
+
export function isValidBaseplateVisibilityType(type: string): Boolean {
|
|
121
|
+
return BaseplateVisibilityValues.includes(type as BaseplateVisibilityType)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export const WorldScalingValues = ['automatic', 'dynamic'] as const
|
|
125
|
+
export type WorldScalingType = (typeof WorldScalingValues)[number]
|
|
126
|
+
|
|
127
|
+
export function isValidWorldScalingType(type: string): Boolean {
|
|
128
|
+
return WorldScalingValues.includes(type as WorldScalingType)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export const WorldAlignmentValues = [
|
|
132
|
+
'adaptive',
|
|
133
|
+
'automatic',
|
|
134
|
+
'gravityAligned',
|
|
135
|
+
] as const
|
|
136
|
+
export type WorldAlignmentType = (typeof WorldAlignmentValues)[number]
|
|
137
|
+
|
|
138
|
+
export function isValidWorldAlignmentType(type: string): Boolean {
|
|
139
|
+
return WorldAlignmentValues.includes(type as WorldAlignmentType)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const SpatialSceneValues = ['window', 'volume'] as const
|
|
143
|
+
export type SpatialSceneType = (typeof SpatialSceneValues)[number]
|
|
144
|
+
|
|
145
|
+
export function isValidSpatialSceneType(type: string): Boolean {
|
|
146
|
+
return SpatialSceneValues.includes(type as SpatialSceneType)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* check px,m and number, number must be >= 0
|
|
151
|
+
*
|
|
152
|
+
* */
|
|
153
|
+
export function isValidSceneUnit(val: string | number): boolean {
|
|
154
|
+
// only support number or string with unit px or m
|
|
155
|
+
// rpx cm mm not allowed
|
|
156
|
+
if (typeof val === 'number') {
|
|
157
|
+
return val >= 0
|
|
158
|
+
}
|
|
159
|
+
if (typeof val === 'string') {
|
|
160
|
+
if (val.endsWith('px')) {
|
|
161
|
+
// check if number
|
|
162
|
+
if (isNaN(Number(val.slice(0, -2)))) {
|
|
163
|
+
return false
|
|
164
|
+
}
|
|
165
|
+
return Number(val.slice(0, -2)) >= 0
|
|
166
|
+
}
|
|
167
|
+
if (val.endsWith('m')) {
|
|
168
|
+
// check if number
|
|
169
|
+
if (isNaN(Number(val.slice(0, -1)))) {
|
|
170
|
+
return false
|
|
171
|
+
}
|
|
172
|
+
return Number(val.slice(0, -1)) >= 0
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return false
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface SpatialEntityProperties {
|
|
179
|
+
position: Vec3
|
|
180
|
+
rotation: Vec3
|
|
181
|
+
scale: Vec3
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export type SpatialEntityEventType = 'spatialtap' //| 'drag' | 'rotate' | 'scale'
|
|
185
|
+
|
|
186
|
+
export type SpatialGeometryType =
|
|
187
|
+
| 'BoxGeometry'
|
|
188
|
+
| 'PlaneGeometry'
|
|
189
|
+
| 'SphereGeometry'
|
|
190
|
+
| 'CylinderGeometry'
|
|
191
|
+
| 'ConeGeometry'
|
|
192
|
+
|
|
193
|
+
export interface SpatialBoxGeometryOptions {
|
|
194
|
+
width?: number
|
|
195
|
+
height?: number
|
|
196
|
+
depth?: number
|
|
197
|
+
cornerRadius?: number
|
|
198
|
+
splitFaces?: boolean
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface SpatialPlaneGeometryOptions {
|
|
202
|
+
width?: number
|
|
203
|
+
height?: number
|
|
204
|
+
cornerRadius?: number
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface SpatialSphereGeometryOptions {
|
|
208
|
+
radius?: number
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface SpatialConeGeometryOptions {
|
|
212
|
+
radius?: number
|
|
213
|
+
height?: number
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface SpatialCylinderGeometryOptions {
|
|
217
|
+
radius?: number
|
|
218
|
+
height?: number
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export type SpatialGeometryOptions =
|
|
222
|
+
| SpatialBoxGeometryOptions
|
|
223
|
+
| SpatialPlaneGeometryOptions
|
|
224
|
+
| SpatialSphereGeometryOptions
|
|
225
|
+
| SpatialCylinderGeometryOptions
|
|
226
|
+
| SpatialConeGeometryOptions
|
|
227
|
+
|
|
228
|
+
export type SpatialMaterialType = 'unlit'
|
|
229
|
+
|
|
230
|
+
export interface SpatialUnlitMaterialOptions {
|
|
231
|
+
color?: string
|
|
232
|
+
textureId?: string
|
|
233
|
+
transparent?: boolean
|
|
234
|
+
opacity?: number
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface ModelComponentOptions {
|
|
238
|
+
mesh: SpatialGeometry
|
|
239
|
+
materials: SpatialMaterial[]
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface SpatialEntityUserData {
|
|
243
|
+
id?: string
|
|
244
|
+
name?: string
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface SpatialModelEntityCreationOptions {
|
|
248
|
+
modelAssetId: string
|
|
249
|
+
name?: string
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface ModelAssetOptions {
|
|
253
|
+
url: string
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export enum SpatialSceneState {
|
|
257
|
+
idle = 'idle',
|
|
258
|
+
pending = 'pending',
|
|
259
|
+
willVisible = 'willVisible',
|
|
260
|
+
visible = 'visible',
|
|
261
|
+
fail = 'fail',
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Translate event, matching similar behavior to https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/drag_event
|
|
266
|
+
*/
|
|
267
|
+
export type SpatialModelDragEvent = {
|
|
268
|
+
eventType: 'dragstart' | 'dragend' | 'drag'
|
|
269
|
+
translation3D: Vec3
|
|
270
|
+
startLocation3D: Vec3
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface Size {
|
|
274
|
+
width: number
|
|
275
|
+
height: number
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface Size3D extends Size {
|
|
279
|
+
depth: number
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export class CubeInfo {
|
|
283
|
+
constructor(
|
|
284
|
+
public size: Size3D,
|
|
285
|
+
public origin: Vec3,
|
|
286
|
+
) {
|
|
287
|
+
this.size = size
|
|
288
|
+
this.origin = origin
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
get x() {
|
|
292
|
+
return this.origin.x
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
get y() {
|
|
296
|
+
return this.origin.y
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
get z() {
|
|
300
|
+
return this.origin.z
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
get width() {
|
|
304
|
+
return this.size.width
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
get height() {
|
|
308
|
+
return this.size.height
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
get depth() {
|
|
312
|
+
return this.size.depth
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
get left() {
|
|
316
|
+
return this.x
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
get top() {
|
|
320
|
+
return this.y
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
get right() {
|
|
324
|
+
return this.x + this.width
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
get bottom() {
|
|
328
|
+
return this.y + this.height
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
get back() {
|
|
332
|
+
return this.z
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
get front() {
|
|
336
|
+
return this.z + this.depth
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface SpatialTapEventDetail {
|
|
341
|
+
location3D: Point3D
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export type SpatialTapEvent = CustomEvent<SpatialTapEventDetail>
|
|
345
|
+
|
|
346
|
+
export interface SpatialDragEventDetail {
|
|
347
|
+
location3D: Point3D
|
|
348
|
+
startLocation3D: Point3D
|
|
349
|
+
translation3D: Vec3
|
|
350
|
+
predictedEndTranslation3D: Vec3
|
|
351
|
+
predictedEndLocation3D: Point3D
|
|
352
|
+
velocity: Size
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export type SpatialDragEvent = CustomEvent<SpatialDragEventDetail>
|
|
356
|
+
|
|
357
|
+
export type SpatialDragEndEvent = SpatialDragEvent
|
|
358
|
+
|
|
359
|
+
export interface SpatialRotateEventDetail {
|
|
360
|
+
rotation: { vector: [number, number, number, number] }
|
|
361
|
+
startAnchor3D: Vec3
|
|
362
|
+
startLocation3D: Point3D
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export type SpatialRotateEvent = CustomEvent<SpatialRotateEventDetail>
|
|
366
|
+
|
|
367
|
+
export type SpatialRotateEndEvent = SpatialRotateEvent
|
|
368
|
+
|
|
369
|
+
export interface SpatialMagnifyEventDetail {
|
|
370
|
+
magnification: number
|
|
371
|
+
velocity: number
|
|
372
|
+
startAnchor3D: Vec3
|
|
373
|
+
startLocation3D: Point3D
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export type SpatialMagnifyEvent = CustomEvent<SpatialMagnifyEventDetail>
|
|
377
|
+
|
|
378
|
+
export type SpatialMagnifyEndEvent = SpatialMagnifyEvent
|
|
379
|
+
|
|
380
|
+
export type SpatialEntityOrReality = SpatialEntity | SpatializedDynamic3DElement
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Vec3 } from './types/types'
|
|
2
|
+
|
|
3
|
+
function parseBorderRadius(borderProperty: string, width: number) {
|
|
4
|
+
if (borderProperty === '') {
|
|
5
|
+
return 0
|
|
6
|
+
}
|
|
7
|
+
if (borderProperty.endsWith('%')) {
|
|
8
|
+
return (width * parseFloat(borderProperty)) / 100
|
|
9
|
+
}
|
|
10
|
+
return parseFloat(borderProperty)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function parseCornerRadius(computedStyle: CSSStyleDeclaration) {
|
|
14
|
+
const width = parseFloat(computedStyle.getPropertyValue('width'))
|
|
15
|
+
|
|
16
|
+
const topLeftPropertyValue = computedStyle.getPropertyValue(
|
|
17
|
+
'border-top-left-radius',
|
|
18
|
+
)
|
|
19
|
+
const topRightPropertyValue = computedStyle.getPropertyValue(
|
|
20
|
+
'border-top-right-radius',
|
|
21
|
+
)
|
|
22
|
+
const bottomLeftPropertyValue = computedStyle.getPropertyValue(
|
|
23
|
+
'border-bottom-left-radius',
|
|
24
|
+
)
|
|
25
|
+
const bottomRightPropertyValue = computedStyle.getPropertyValue(
|
|
26
|
+
'border-bottom-right-radius',
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
const cornerRadius = {
|
|
30
|
+
topLeading: parseBorderRadius(topLeftPropertyValue, width),
|
|
31
|
+
bottomLeading: parseBorderRadius(bottomLeftPropertyValue, width),
|
|
32
|
+
topTrailing: parseBorderRadius(topRightPropertyValue, width),
|
|
33
|
+
bottomTrailing: parseBorderRadius(bottomRightPropertyValue, width),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return cornerRadius
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* compose SRT matrix
|
|
42
|
+
* @export
|
|
43
|
+
* @param {Vec3} position meter
|
|
44
|
+
* @param {Vec3} rotation degree
|
|
45
|
+
* @param {Vec3} scale
|
|
46
|
+
* @return {*} {DOMMatrix}
|
|
47
|
+
*/
|
|
48
|
+
export function composeSRT(position: Vec3, rotation: Vec3, scale: Vec3) {
|
|
49
|
+
const { x: px, y: py, z: pz } = position
|
|
50
|
+
const { x: rx, y: ry, z: rz } = rotation
|
|
51
|
+
const { x: sx, y: sy, z: sz } = scale
|
|
52
|
+
|
|
53
|
+
let m = new DOMMatrix()
|
|
54
|
+
// https://drafts.fxtf.org/geometry/#immutable-transformation-methods
|
|
55
|
+
// as these methods are post-multiplication, the order of transformations is reversed
|
|
56
|
+
// we want SRT = T * R * S
|
|
57
|
+
m = m.translate(px, py, pz)
|
|
58
|
+
m = m.rotate(rx, ry, rz)
|
|
59
|
+
m = m.scale(sx, sy, sz)
|
|
60
|
+
return m
|
|
61
|
+
}
|
package/tsconfig.json
CHANGED
package/vitest.config.ts
ADDED
package/src/core/Spatial.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { SpatialSession } from './SpatialSession'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base object designed to be placed on navigator.spatial to mirror navigator.xr for webxr
|
|
5
|
-
*/
|
|
6
|
-
export class Spatial {
|
|
7
|
-
/**
|
|
8
|
-
* Requests a session object from the browser
|
|
9
|
-
* @returns The session or null if not availible in the current browser
|
|
10
|
-
* [TODO] discuss implications of this not being async
|
|
11
|
-
*/
|
|
12
|
-
requestSession() {
|
|
13
|
-
if (
|
|
14
|
-
this.isSupported() &&
|
|
15
|
-
this.getNativeVersion() === this.getClientVersion()
|
|
16
|
-
) {
|
|
17
|
-
return new SpatialSession()
|
|
18
|
-
} else {
|
|
19
|
-
return null
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @returns true if web spatial is supported by this webpage
|
|
25
|
-
*/
|
|
26
|
-
isSupported() {
|
|
27
|
-
return this.getNativeVersion() === this.getClientVersion()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Gets the native version, format is "x.x.x"
|
|
32
|
-
* @returns native version string
|
|
33
|
-
*/
|
|
34
|
-
getNativeVersion() {
|
|
35
|
-
if (window.__WebSpatialData && window.__WebSpatialData.getNativeVersion) {
|
|
36
|
-
return window.__WebSpatialData.getNativeVersion()
|
|
37
|
-
}
|
|
38
|
-
return window.WebSpatailNativeVersion === 'PACKAGE_VERSION'
|
|
39
|
-
? this.getClientVersion()
|
|
40
|
-
: window.WebSpatailNativeVersion
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Gets the client version, format is "x.x.x"
|
|
45
|
-
* @returns client version string
|
|
46
|
-
*/
|
|
47
|
-
getClientVersion() {
|
|
48
|
-
return __WEBSPATIAL_CORE_SDK_VERSION__
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { SpatialObject } from './SpatialObject'
|
|
2
|
-
import { SpatialTransform } from './SpatialTransform'
|
|
3
|
-
import { SpatialWindowContainer } from './SpatialWindowContainer'
|
|
4
|
-
import { WebSpatial } from './private/WebSpatial'
|
|
5
|
-
import { SpatialComponent } from './component'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Entity used to describe an object that can be added to the scene
|
|
9
|
-
*/
|
|
10
|
-
export class SpatialEntity extends SpatialObject {
|
|
11
|
-
/**
|
|
12
|
-
* Transform corresponding to the entity
|
|
13
|
-
* note: updateTransform must be called for transform to be synced to rendering
|
|
14
|
-
*/
|
|
15
|
-
transform = new SpatialTransform()
|
|
16
|
-
|
|
17
|
-
/** @hidden */
|
|
18
|
-
private _destroyed = false
|
|
19
|
-
/** @hidden */
|
|
20
|
-
private get _entity() {
|
|
21
|
-
return this._resource
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Syncs the transform with the renderer, must be called to observe updates
|
|
26
|
-
*/
|
|
27
|
-
async updateTransform() {
|
|
28
|
-
await WebSpatial.updateResource(this._entity, this.transform)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Syncs the zIndex with the renderer
|
|
33
|
-
*/
|
|
34
|
-
async updateZIndex(zIndex: number) {
|
|
35
|
-
await WebSpatial.updateResource(this._entity, { zIndex })
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private components: Map<Function, SpatialComponent> = new Map()
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Attaches a component to the entity to be displayed
|
|
42
|
-
* [TODO] review pass by value vs ref and ownership model for this
|
|
43
|
-
*/
|
|
44
|
-
async setComponent(component: SpatialComponent) {
|
|
45
|
-
await WebSpatial.setComponent(this._entity, component._resource)
|
|
46
|
-
this.components.set(component.constructor, component)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Removes a component from the entity
|
|
51
|
-
*/
|
|
52
|
-
async removeComponent<T extends SpatialComponent>(
|
|
53
|
-
type: new (...args: any[]) => T,
|
|
54
|
-
) {
|
|
55
|
-
var c = this.getComponent(type)
|
|
56
|
-
if (c != undefined) {
|
|
57
|
-
await WebSpatial.removeComponent(this._entity, c._resource)
|
|
58
|
-
this.components.delete(c.constructor)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Gets a component from the entity
|
|
64
|
-
*/
|
|
65
|
-
getComponent<T extends SpatialComponent>(
|
|
66
|
-
type: new (...args: any[]) => T,
|
|
67
|
-
): T | undefined {
|
|
68
|
-
return this.components.get(type) as T | undefined
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @hidden
|
|
73
|
-
* Sets the window container that this entity should be rendered by (this does not effect resource ownership)
|
|
74
|
-
* @param wg the window container that should render this entity
|
|
75
|
-
*/
|
|
76
|
-
async _setParentWindowContainer(wg: SpatialWindowContainer) {
|
|
77
|
-
await WebSpatial.updateResource(this._entity, {
|
|
78
|
-
setParentWindowContainerID: wg._wg.id,
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Sets a parent entity, if that entity or its parents are attached to a window container, this entity will be displayed
|
|
84
|
-
* @param e parent entity or null to remove current parent
|
|
85
|
-
*/
|
|
86
|
-
async setParent(e: SpatialEntity | null) {
|
|
87
|
-
await WebSpatial.updateResource(this._entity, {
|
|
88
|
-
setParent: e ? e._entity.id : '',
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Sets the coordinate space of this entity (Default: App)
|
|
94
|
-
* "App" = game engine style coordinates in meters
|
|
95
|
-
* "Dom" = Windowing coordinates in dom units (eg. 0,0,0 is top left of window)
|
|
96
|
-
* "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
|
|
97
|
-
* [TODO] review this api
|
|
98
|
-
* @param space coordinate space mode
|
|
99
|
-
*/
|
|
100
|
-
async setCoordinateSpace(space: 'App' | 'Dom' | 'Root') {
|
|
101
|
-
await WebSpatial.updateResource(this._entity, { setCoordinateSpace: space })
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Query the 3d boudning box of the entity
|
|
106
|
-
* @returns The bounding box of the entity
|
|
107
|
-
*/
|
|
108
|
-
async getBoundingBox() {
|
|
109
|
-
var res: any = await WebSpatial.updateResource(this._entity, {
|
|
110
|
-
getBoundingBox: true,
|
|
111
|
-
})
|
|
112
|
-
return res.data as {
|
|
113
|
-
center: { x: number; y: number; z: number }
|
|
114
|
-
extents: { x: number; y: number; z: number }
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Sets if the entity should be visible (default: True)
|
|
120
|
-
* @param visible
|
|
121
|
-
*/
|
|
122
|
-
async setVisible(visible: boolean) {
|
|
123
|
-
await WebSpatial.updateResource(this._entity, { visible })
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Removes a reference to the entity by the renderer and this object should no longer be used. [TODO] Attached components will not be destroyed
|
|
128
|
-
*/
|
|
129
|
-
async destroy() {
|
|
130
|
-
this._destroyed = true
|
|
131
|
-
await WebSpatial.destroyResource(this._entity)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Check if destroy has been called
|
|
136
|
-
*/
|
|
137
|
-
isDestroyed() {
|
|
138
|
-
return this._destroyed
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Set Entity name. Currently for debugging only.
|
|
142
|
-
/** @hidden */
|
|
143
|
-
async _setName(name: string) {
|
|
144
|
-
this.name = name
|
|
145
|
-
return WebSpatial.updateResource(this._entity, { name })
|
|
146
|
-
}
|
|
147
|
-
}
|