@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/dist/index.d.ts
CHANGED
|
@@ -455,6 +455,7 @@ declare class SpatialEntity extends SpatialObject {
|
|
|
455
455
|
set enableInput(value: boolean);
|
|
456
456
|
constructor(id: string, userData?: SpatialEntityUserData | undefined);
|
|
457
457
|
addComponent(component: SpatialComponent): Promise<CommandResult>;
|
|
458
|
+
removeComponent(component: SpatialComponent): Promise<CommandResult>;
|
|
458
459
|
setPosition(position: Vec3): Promise<CommandResult>;
|
|
459
460
|
setRotation(rotation: Vec3): Promise<CommandResult>;
|
|
460
461
|
setScale(scale: Vec3): Promise<CommandResult>;
|
|
@@ -477,6 +478,7 @@ declare class SpatialModelEntity extends SpatialEntity {
|
|
|
477
478
|
options?: SpatialModelEntityCreationOptions | undefined;
|
|
478
479
|
userData?: SpatialEntityUserData | undefined;
|
|
479
480
|
constructor(id: string, options?: SpatialModelEntityCreationOptions | undefined, userData?: SpatialEntityUserData | undefined);
|
|
481
|
+
setMaterials(materials: SpatialMaterial[]): Promise<CommandResult>;
|
|
480
482
|
}
|
|
481
483
|
|
|
482
484
|
declare class ModelComponent extends SpatialComponent {
|
|
@@ -916,6 +918,11 @@ declare global {
|
|
|
916
918
|
webkit: any
|
|
917
919
|
webspatialBridge: any
|
|
918
920
|
|
|
921
|
+
// Project Pico OS browser injects this global object to provide internal capabilities.
|
|
922
|
+
webSpatial?: {
|
|
923
|
+
genToken?: () => string
|
|
924
|
+
}
|
|
925
|
+
|
|
919
926
|
// Will be removed in favor of __WebSpatialData
|
|
920
927
|
WebSpatailNativeVersion: string
|
|
921
928
|
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['core-sdk-version'] = "1.
|
|
5
|
+
window.__webspatialsdk__['core-sdk-version'] = "1.5.0"
|
|
6
6
|
})()
|
|
7
7
|
|
|
8
8
|
var __defProp = Object.defineProperty;
|
|
@@ -477,24 +477,24 @@ var init_SpatialWebEvent = __esm({
|
|
|
477
477
|
}
|
|
478
478
|
});
|
|
479
479
|
|
|
480
|
-
// src/platform-adapter/
|
|
481
|
-
var
|
|
482
|
-
__export(
|
|
483
|
-
|
|
480
|
+
// src/platform-adapter/pico-os/PicoOSPlatform.ts
|
|
481
|
+
var PicoOSPlatform_exports = {};
|
|
482
|
+
__export(PicoOSPlatform_exports, {
|
|
483
|
+
PicoOSPlatform: () => PicoOSPlatform
|
|
484
484
|
});
|
|
485
485
|
function nextRequestId() {
|
|
486
486
|
requestId = (requestId + 1) % MAX_ID;
|
|
487
487
|
return `rId_${requestId}`;
|
|
488
488
|
}
|
|
489
|
-
var requestId, MAX_ID,
|
|
490
|
-
var
|
|
491
|
-
"src/platform-adapter/
|
|
489
|
+
var requestId, MAX_ID, PicoOSPlatform;
|
|
490
|
+
var init_PicoOSPlatform = __esm({
|
|
491
|
+
"src/platform-adapter/pico-os/PicoOSPlatform.ts"() {
|
|
492
492
|
"use strict";
|
|
493
493
|
init_CommandResultUtils();
|
|
494
494
|
init_SpatialWebEvent();
|
|
495
495
|
requestId = 0;
|
|
496
496
|
MAX_ID = 1e5;
|
|
497
|
-
|
|
497
|
+
PicoOSPlatform = class {
|
|
498
498
|
async callJSB(cmd, msg) {
|
|
499
499
|
return new Promise((resolve, reject) => {
|
|
500
500
|
try {
|
|
@@ -520,7 +520,7 @@ var init_XRPlatform = __esm({
|
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
522
|
} catch (error) {
|
|
523
|
-
console.error(`
|
|
523
|
+
console.error(`SwanPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`);
|
|
524
524
|
const { code, message } = error;
|
|
525
525
|
resolve(CommandResultFailure(code, message));
|
|
526
526
|
}
|
|
@@ -534,7 +534,6 @@ var init_XRPlatform = __esm({
|
|
|
534
534
|
SpatialWebEvent.addEventReceiver(
|
|
535
535
|
createdId,
|
|
536
536
|
(result) => {
|
|
537
|
-
console.log("createdId", createdId, result.spatialId);
|
|
538
537
|
resolve(
|
|
539
538
|
CommandResultSuccess({
|
|
540
539
|
windowProxy,
|
|
@@ -546,13 +545,11 @@ var init_XRPlatform = __esm({
|
|
|
546
545
|
);
|
|
547
546
|
windowProxy = this.openWindow(
|
|
548
547
|
command,
|
|
549
|
-
|
|
548
|
+
"rid=" + createdId,
|
|
550
549
|
target,
|
|
551
550
|
features
|
|
552
551
|
).windowProxy;
|
|
553
|
-
windowProxy?.open(`about:blank?rid=${createdId}`, "_self");
|
|
554
552
|
} catch (error) {
|
|
555
|
-
console.error(`open window error: ${error}`);
|
|
556
553
|
const { code, message } = error;
|
|
557
554
|
SpatialWebEvent.removeEventReceiver(createdId);
|
|
558
555
|
resolve(CommandResultFailure(code, message));
|
|
@@ -767,8 +764,8 @@ function createPlatform() {
|
|
|
767
764
|
const PuppeteerPlatform2 = (init_PuppeteerPlatform(), __toCommonJS(PuppeteerPlatform_exports)).PuppeteerPlatform;
|
|
768
765
|
return new PuppeteerPlatform2();
|
|
769
766
|
} else if (userAgent.includes("PicoWebApp") && isVersionGreater(webSpatialVersion, [0, 0, 1])) {
|
|
770
|
-
const
|
|
771
|
-
return new
|
|
767
|
+
const PicoOSPlatform2 = (init_PicoOSPlatform(), __toCommonJS(PicoOSPlatform_exports)).PicoOSPlatform;
|
|
768
|
+
return new PicoOSPlatform2();
|
|
772
769
|
} else if (userAgent.includes("Android") || userAgent.includes("Linux")) {
|
|
773
770
|
const AndroidPlatform2 = (init_AndroidPlatform(), __toCommonJS(AndroidPlatform_exports)).AndroidPlatform;
|
|
774
771
|
return new AndroidPlatform2();
|
|
@@ -834,7 +831,7 @@ var init_utils = __esm({
|
|
|
834
831
|
});
|
|
835
832
|
|
|
836
833
|
// src/JSBCommand.ts
|
|
837
|
-
var platform, JSBCommand, UpdateEntityPropertiesCommand, UpdateEntityEventCommand, UpdateSpatialSceneProperties, UpdateSceneConfig, FocusScene, GetSpatialSceneState, SpatializedElementCommand, UpdateSpatialized2DElementProperties, UpdateSpatializedDynamic3DElementProperties, UpdateUnlitMaterialProperties, UpdateSpatializedElementTransform, UpdateSpatializedStatic3DElementProperties, AddSpatializedElementToSpatialized2DElement, AddSpatializedElementToSpatialScene, CreateSpatializedStatic3DElementCommand, CreateSpatializedDynamic3DElementCommand, CreateSpatialEntityCommand, CreateModelComponentCommand, CreateSpatialModelEntityCommand, CreateModelAssetCommand, CreateSpatialGeometryCommand, CreateSpatialUnlitMaterialCommand, AddComponentToEntityCommand, SetParentForEntityCommand, ConvertFromEntityToEntityCommand, ConvertFromEntityToSceneCommand, ConvertFromSceneToEntityCommand, ConvertCoordinateCommand, InspectCommand, DestroyCommand, CheckWebViewCanCreateCommand, WebSpatialProtocolCommand, createSpatialized2DElementCommand, createSpatialSceneCommand, CreateAttachmentEntityCommand, InitializeAttachmentCommand, UpdateAttachmentEntityCommand;
|
|
834
|
+
var platform, JSBCommand, UpdateEntityPropertiesCommand, UpdateEntityEventCommand, UpdateSpatialSceneProperties, UpdateSceneConfig, FocusScene, GetSpatialSceneState, SpatializedElementCommand, UpdateSpatialized2DElementProperties, UpdateSpatializedDynamic3DElementProperties, UpdateUnlitMaterialProperties, UpdateSpatializedElementTransform, UpdateSpatializedStatic3DElementProperties, AddSpatializedElementToSpatialized2DElement, AddSpatializedElementToSpatialScene, CreateSpatializedStatic3DElementCommand, CreateSpatializedDynamic3DElementCommand, CreateSpatialEntityCommand, CreateModelComponentCommand, CreateSpatialModelEntityCommand, CreateModelAssetCommand, CreateSpatialGeometryCommand, CreateSpatialUnlitMaterialCommand, AddComponentToEntityCommand, RemoveComponentFromEntityCommand, SetMaterialsOnEntityCommand, SetParentForEntityCommand, ConvertFromEntityToEntityCommand, ConvertFromEntityToSceneCommand, ConvertFromSceneToEntityCommand, ConvertCoordinateCommand, InspectCommand, DestroyCommand, CheckWebViewCanCreateCommand, WebSpatialProtocolCommand, createSpatialized2DElementCommand, createSpatialSceneCommand, CreateAttachmentEntityCommand, InitializeAttachmentCommand, UpdateAttachmentEntityCommand;
|
|
838
835
|
var init_JSBCommand = __esm({
|
|
839
836
|
"src/JSBCommand.ts"() {
|
|
840
837
|
"use strict";
|
|
@@ -1111,6 +1108,34 @@ var init_JSBCommand = __esm({
|
|
|
1111
1108
|
}
|
|
1112
1109
|
commandType = "AddComponentToEntity";
|
|
1113
1110
|
};
|
|
1111
|
+
RemoveComponentFromEntityCommand = class extends JSBCommand {
|
|
1112
|
+
constructor(entity, comp) {
|
|
1113
|
+
super();
|
|
1114
|
+
this.entity = entity;
|
|
1115
|
+
this.comp = comp;
|
|
1116
|
+
}
|
|
1117
|
+
getParams() {
|
|
1118
|
+
return {
|
|
1119
|
+
entityId: this.entity.id,
|
|
1120
|
+
componentId: this.comp.id
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
commandType = "RemoveComponentFromEntity";
|
|
1124
|
+
};
|
|
1125
|
+
SetMaterialsOnEntityCommand = class extends JSBCommand {
|
|
1126
|
+
constructor(entityId, materials) {
|
|
1127
|
+
super();
|
|
1128
|
+
this.entityId = entityId;
|
|
1129
|
+
this.materials = materials;
|
|
1130
|
+
}
|
|
1131
|
+
getParams() {
|
|
1132
|
+
return {
|
|
1133
|
+
entityId: this.entityId,
|
|
1134
|
+
materialIds: this.materials.map((m) => m.id)
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
commandType = "SetMaterialsOnEntity";
|
|
1138
|
+
};
|
|
1114
1139
|
SetParentForEntityCommand = class extends JSBCommand {
|
|
1115
1140
|
// childId, parentId
|
|
1116
1141
|
constructor(childId, parentId) {
|
|
@@ -1583,6 +1608,18 @@ var SceneManager = class _SceneManager {
|
|
|
1583
1608
|
}
|
|
1584
1609
|
open = (url, target, features) => {
|
|
1585
1610
|
if (url?.startsWith(INTERNAL_SCHEMA_PREFIX)) {
|
|
1611
|
+
if (url.includes("createSpatialized2DElement")) {
|
|
1612
|
+
const token = window.webSpatial?.genToken?.();
|
|
1613
|
+
if (token) {
|
|
1614
|
+
const host = window.location.host;
|
|
1615
|
+
const protocol = window.location.protocol;
|
|
1616
|
+
const finalURL = `${protocol}//${host}/${token}/?command=createSpatialized2DElement`;
|
|
1617
|
+
const rid = new URL(url).searchParams.get("rid");
|
|
1618
|
+
const final = new URL(finalURL);
|
|
1619
|
+
if (rid) final.searchParams.set("rid", rid);
|
|
1620
|
+
return this.originalOpen(final.toString(), target, features);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1586
1623
|
return this.originalOpen(url, target, features);
|
|
1587
1624
|
}
|
|
1588
1625
|
url = this.ensureAbsoluteUrl(url);
|
|
@@ -2270,6 +2307,9 @@ var SpatialEntity = class extends SpatialObject {
|
|
|
2270
2307
|
async addComponent(component) {
|
|
2271
2308
|
return new AddComponentToEntityCommand(this, component).execute();
|
|
2272
2309
|
}
|
|
2310
|
+
async removeComponent(component) {
|
|
2311
|
+
return new RemoveComponentFromEntityCommand(this, component).execute();
|
|
2312
|
+
}
|
|
2273
2313
|
async setPosition(position) {
|
|
2274
2314
|
return this.updateTransform({ position });
|
|
2275
2315
|
}
|
|
@@ -2422,6 +2462,7 @@ var SpatialEntity = class extends SpatialObject {
|
|
|
2422
2462
|
};
|
|
2423
2463
|
|
|
2424
2464
|
// src/reality/entity/SpatialModelEntity.ts
|
|
2465
|
+
init_JSBCommand();
|
|
2425
2466
|
var SpatialModelEntity = class extends SpatialEntity {
|
|
2426
2467
|
constructor(id, options, userData) {
|
|
2427
2468
|
super(id, userData);
|
|
@@ -2429,6 +2470,9 @@ var SpatialModelEntity = class extends SpatialEntity {
|
|
|
2429
2470
|
this.options = options;
|
|
2430
2471
|
this.userData = userData;
|
|
2431
2472
|
}
|
|
2473
|
+
async setMaterials(materials) {
|
|
2474
|
+
return new SetMaterialsOnEntityCommand(this.id, materials).execute();
|
|
2475
|
+
}
|
|
2432
2476
|
};
|
|
2433
2477
|
|
|
2434
2478
|
// src/reality/component/SpatialComponent.ts
|
|
@@ -2811,7 +2855,7 @@ var Spatial = class {
|
|
|
2811
2855
|
* @returns Client SDK version string in format "x.x.x"
|
|
2812
2856
|
*/
|
|
2813
2857
|
getClientVersion() {
|
|
2814
|
-
return "1.
|
|
2858
|
+
return "1.5.0";
|
|
2815
2859
|
}
|
|
2816
2860
|
};
|
|
2817
2861
|
|