@webspatial/core-sdk 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -1
- package/dist/iife/index.d.ts +7 -0
- package/dist/iife/index.global.js +4 -4
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +62 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/JSBCommand.ts +33 -0
- package/src/platform-adapter/index.ts +2 -2
- package/src/platform-adapter/{xr/XRPlatform.ts → pico-os/PicoOSPlatform.ts} +5 -7
- package/src/reality/entity/SpatialEntity.ts +4 -0
- package/src/reality/entity/SpatialModelEntity.ts +6 -0
- package/src/scene-polyfill.ts +12 -0
- package/src/types/global.d.ts +5 -0
package/package.json
CHANGED
package/src/JSBCommand.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { createPlatform } from './platform-adapter'
|
|
|
2
2
|
import { WebSpatialProtocolResult } from './platform-adapter/interface'
|
|
3
3
|
import { SpatialComponent } from './reality/component/SpatialComponent'
|
|
4
4
|
import { SpatialEntity } from './reality/entity/SpatialEntity'
|
|
5
|
+
import { SpatialMaterial } from './reality/material/SpatialMaterial'
|
|
5
6
|
import { SpatializedDynamic3DElement } from './SpatializedDynamic3DElement'
|
|
6
7
|
import { SpatializedElement } from './SpatializedElement'
|
|
7
8
|
import { SpatialObject } from './SpatialObject'
|
|
@@ -386,6 +387,38 @@ export class AddComponentToEntityCommand extends JSBCommand {
|
|
|
386
387
|
commandType = 'AddComponentToEntity'
|
|
387
388
|
}
|
|
388
389
|
|
|
390
|
+
export class RemoveComponentFromEntityCommand extends JSBCommand {
|
|
391
|
+
constructor(
|
|
392
|
+
public entity: SpatialEntity,
|
|
393
|
+
public comp: SpatialComponent,
|
|
394
|
+
) {
|
|
395
|
+
super()
|
|
396
|
+
}
|
|
397
|
+
protected getParams(): Record<string, any> | undefined {
|
|
398
|
+
return {
|
|
399
|
+
entityId: this.entity.id,
|
|
400
|
+
componentId: this.comp.id,
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
commandType = 'RemoveComponentFromEntity'
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export class SetMaterialsOnEntityCommand extends JSBCommand {
|
|
407
|
+
constructor(
|
|
408
|
+
public entityId: string,
|
|
409
|
+
public materials: SpatialMaterial[],
|
|
410
|
+
) {
|
|
411
|
+
super()
|
|
412
|
+
}
|
|
413
|
+
protected getParams(): Record<string, any> | undefined {
|
|
414
|
+
return {
|
|
415
|
+
entityId: this.entityId,
|
|
416
|
+
materialIds: this.materials.map(m => m.id),
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
commandType = 'SetMaterialsOnEntity'
|
|
420
|
+
}
|
|
421
|
+
|
|
389
422
|
export class AddEntityToDynamic3DCommand extends JSBCommand {
|
|
390
423
|
constructor(
|
|
391
424
|
public d3dEle: SpatializedDynamic3DElement,
|
|
@@ -40,8 +40,8 @@ export function createPlatform(): PlatformAbility {
|
|
|
40
40
|
userAgent.includes('PicoWebApp') &&
|
|
41
41
|
isVersionGreater(webSpatialVersion, [0, 0, 1])
|
|
42
42
|
) {
|
|
43
|
-
const
|
|
44
|
-
return new
|
|
43
|
+
const PicoOSPlatform = require('./pico-os/PicoOSPlatform').PicoOSPlatform
|
|
44
|
+
return new PicoOSPlatform()
|
|
45
45
|
} else if (userAgent.includes('Android') || userAgent.includes('Linux')) {
|
|
46
46
|
const AndroidPlatform = require('./android/AndroidPlatform').AndroidPlatform
|
|
47
47
|
return new AndroidPlatform()
|
|
@@ -23,9 +23,10 @@ function nextRequestId() {
|
|
|
23
23
|
return `rId_${requestId}`
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
// Only supports Pico OS 6
|
|
27
|
+
export class PicoOSPlatform implements PlatformAbility {
|
|
27
28
|
async callJSB(cmd: string, msg: string): Promise<CommandResult> {
|
|
28
|
-
//
|
|
29
|
+
// swan JS Bridge interface only support sync invoking
|
|
29
30
|
// in order to implement promise API, register every request by requestId and remove when resolve/reject.
|
|
30
31
|
return new Promise((resolve, reject) => {
|
|
31
32
|
try {
|
|
@@ -54,7 +55,7 @@ export class XRPlatform implements PlatformAbility {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
} catch (error: unknown) {
|
|
57
|
-
console.error(`
|
|
58
|
+
console.error(`SwanPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`)
|
|
58
59
|
const { code, message } = error as JSBError
|
|
59
60
|
resolve(CommandResultFailure(code, message))
|
|
60
61
|
}
|
|
@@ -75,7 +76,6 @@ export class XRPlatform implements PlatformAbility {
|
|
|
75
76
|
SpatialWebEvent.addEventReceiver(
|
|
76
77
|
createdId,
|
|
77
78
|
(result: { spatialId: string }) => {
|
|
78
|
-
console.log('createdId', createdId, result.spatialId)
|
|
79
79
|
resolve(
|
|
80
80
|
CommandResultSuccess({
|
|
81
81
|
windowProxy: windowProxy,
|
|
@@ -87,13 +87,11 @@ export class XRPlatform implements PlatformAbility {
|
|
|
87
87
|
)
|
|
88
88
|
windowProxy = this.openWindow(
|
|
89
89
|
command,
|
|
90
|
-
|
|
90
|
+
'rid=' + createdId,
|
|
91
91
|
target,
|
|
92
92
|
features,
|
|
93
93
|
).windowProxy
|
|
94
|
-
windowProxy?.open(`about:blank?rid=${createdId}`, '_self')
|
|
95
94
|
} catch (error: unknown) {
|
|
96
|
-
console.error(`open window error: ${error}`)
|
|
97
95
|
const { code, message } = error as JSBError
|
|
98
96
|
SpatialWebEvent.removeEventReceiver(createdId)
|
|
99
97
|
resolve(CommandResultFailure(code, message))
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
AddComponentToEntityCommand,
|
|
15
15
|
AddEntityToEntityCommand,
|
|
16
|
+
RemoveComponentFromEntityCommand,
|
|
16
17
|
RemoveEntityFromParentCommand,
|
|
17
18
|
UpdateEntityEventCommand,
|
|
18
19
|
UpdateEntityPropertiesCommand,
|
|
@@ -79,6 +80,9 @@ export class SpatialEntity extends SpatialObject {
|
|
|
79
80
|
async addComponent(component: SpatialComponent) {
|
|
80
81
|
return new AddComponentToEntityCommand(this, component).execute()
|
|
81
82
|
}
|
|
83
|
+
async removeComponent(component: SpatialComponent) {
|
|
84
|
+
return new RemoveComponentFromEntityCommand(this, component).execute()
|
|
85
|
+
}
|
|
82
86
|
async setPosition(position: Vec3) {
|
|
83
87
|
return this.updateTransform({ position })
|
|
84
88
|
}
|
|
@@ -2,6 +2,8 @@ import {
|
|
|
2
2
|
SpatialEntityUserData,
|
|
3
3
|
SpatialModelEntityCreationOptions,
|
|
4
4
|
} from '../../types/types'
|
|
5
|
+
import { SetMaterialsOnEntityCommand } from '../../JSBCommand'
|
|
6
|
+
import { SpatialMaterial } from '../material/SpatialMaterial'
|
|
5
7
|
import { SpatialEntity } from './SpatialEntity'
|
|
6
8
|
|
|
7
9
|
export class SpatialModelEntity extends SpatialEntity {
|
|
@@ -12,4 +14,8 @@ export class SpatialModelEntity extends SpatialEntity {
|
|
|
12
14
|
) {
|
|
13
15
|
super(id, userData)
|
|
14
16
|
}
|
|
17
|
+
|
|
18
|
+
async setMaterials(materials: SpatialMaterial[]) {
|
|
19
|
+
return new SetMaterialsOnEntityCommand(this.id, materials).execute()
|
|
20
|
+
}
|
|
15
21
|
}
|
package/src/scene-polyfill.ts
CHANGED
|
@@ -76,6 +76,18 @@ class SceneManager {
|
|
|
76
76
|
private open = (url?: string, target?: string, features?: string) => {
|
|
77
77
|
// bypass internal
|
|
78
78
|
if (url?.startsWith(INTERNAL_SCHEMA_PREFIX)) {
|
|
79
|
+
if (url.includes('createSpatialized2DElement')) {
|
|
80
|
+
const token = window.webSpatial?.genToken?.()
|
|
81
|
+
if (token) {
|
|
82
|
+
const host = window.location.host
|
|
83
|
+
const protocol = window.location.protocol
|
|
84
|
+
const finalURL = `${protocol}//${host}/${token}/?command=createSpatialized2DElement`
|
|
85
|
+
const rid = new URL(url).searchParams.get('rid')
|
|
86
|
+
const final = new URL(finalURL)
|
|
87
|
+
if (rid) final.searchParams.set('rid', rid)
|
|
88
|
+
return this.originalOpen(final.toString(), target, features)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
79
91
|
return this.originalOpen(url, target, features)
|
|
80
92
|
}
|
|
81
93
|
|
package/src/types/global.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ declare global {
|
|
|
22
22
|
webkit: any
|
|
23
23
|
webspatialBridge: any
|
|
24
24
|
|
|
25
|
+
// Project Pico OS browser injects this global object to provide internal capabilities.
|
|
26
|
+
webSpatial?: {
|
|
27
|
+
genToken?: () => string
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
// Will be removed in favor of __WebSpatialData
|
|
26
31
|
WebSpatailNativeVersion: string
|
|
27
32
|
|