@webspatial/core-sdk 1.4.0 → 1.6.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 +34 -1
- package/dist/iife/index.d.ts +171 -12
- package/dist/iife/index.global.js +11 -11
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +171 -12
- package/dist/index.js +460 -114
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/JSBCommand.ts +40 -2
- package/src/Spatial.ts +1 -1
- package/src/SpatialSession.ts +4 -2
- package/src/SpatializedElement.ts +10 -10
- package/src/SpatializedElementCreator.ts +5 -2
- package/src/SpatializedStatic3DElement.test.ts +15 -1
- package/src/SpatializedStatic3DElement.ts +167 -8
- package/src/WebMsgCommand.ts +22 -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.manifest.test.ts +402 -0
- package/src/scene-polyfill.test.ts +108 -18
- package/src/scene-polyfill.ts +284 -26
- package/src/types/global.d.ts +8 -0
- package/src/types/types.ts +71 -0
- package/src/utils.ts +21 -0
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ declare enum SpatialWebMsgType {
|
|
|
57
57
|
spatialrotateend = "spatialrotateend",
|
|
58
58
|
spatialmagnify = "spatialmagnify",
|
|
59
59
|
spatialmagnifyend = "spatialmagnifyend",
|
|
60
|
+
animationstatechange = "animationstatechange",
|
|
60
61
|
objectdestroy = "objectdestroy"
|
|
61
62
|
}
|
|
62
63
|
interface ObjectDestroyMsg {
|
|
@@ -86,6 +87,23 @@ interface SpatialRotateEndMsg {
|
|
|
86
87
|
type: SpatialWebMsgType.spatialrotateend;
|
|
87
88
|
detail: SpatialRotateEventDetail;
|
|
88
89
|
}
|
|
90
|
+
interface ModelLoadSuccess {
|
|
91
|
+
type: SpatialWebMsgType.modelloaded;
|
|
92
|
+
detail?: {
|
|
93
|
+
src: string;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
interface ModelLoadFailure {
|
|
97
|
+
type: SpatialWebMsgType.modelloadfailed;
|
|
98
|
+
}
|
|
99
|
+
interface AnimationStateChangeDetail {
|
|
100
|
+
paused: boolean;
|
|
101
|
+
duration: number;
|
|
102
|
+
}
|
|
103
|
+
interface AnimationStateChangeMsg {
|
|
104
|
+
type: SpatialWebMsgType.animationstatechange;
|
|
105
|
+
detail: AnimationStateChangeDetail;
|
|
106
|
+
}
|
|
89
107
|
|
|
90
108
|
/**
|
|
91
109
|
* Abstract base class for all spatialized elements in the WebSpatial environment.
|
|
@@ -148,7 +166,7 @@ declare abstract class SpatializedElement extends SpatialObject {
|
|
|
148
166
|
* Handles various spatial events like transforms, gestures, and interactions.
|
|
149
167
|
* @param data The event data received from the WebSpatial system
|
|
150
168
|
*/
|
|
151
|
-
protected onReceiveEvent(data:
|
|
169
|
+
protected onReceiveEvent(data: ReceiveEventData): void;
|
|
152
170
|
private _onSpatialTap?;
|
|
153
171
|
set onSpatialTap(value: (event: SpatialTapEvent) => void | undefined);
|
|
154
172
|
private _onSpatialDragStart?;
|
|
@@ -171,6 +189,7 @@ declare abstract class SpatializedElement extends SpatialObject {
|
|
|
171
189
|
*/
|
|
172
190
|
onDestroy(): void;
|
|
173
191
|
}
|
|
192
|
+
type ReceiveEventData = SpatialTapMsg | SpatialDragStartMsg | SpatialDragMsg | SpatialDragEndMsg | SpatialRotateMsg | SpatialRotateEndMsg | ObjectDestroyMsg;
|
|
174
193
|
|
|
175
194
|
declare class SpatializedDynamic3DElement extends SpatializedElement {
|
|
176
195
|
children: SpatialEntityOrReality[];
|
|
@@ -259,9 +278,18 @@ interface Spatialized2DElementProperties extends SpatializedElementProperties {
|
|
|
259
278
|
material: BackgroundMaterialType;
|
|
260
279
|
scrollEdgeInsetsMarginRight: number;
|
|
261
280
|
}
|
|
281
|
+
interface ModelSource {
|
|
282
|
+
src: string;
|
|
283
|
+
type?: string;
|
|
284
|
+
}
|
|
262
285
|
interface SpatializedStatic3DElementProperties extends SpatializedElementProperties {
|
|
263
286
|
modelURL: string;
|
|
287
|
+
sources?: ModelSource[];
|
|
264
288
|
modelTransform?: number[];
|
|
289
|
+
autoplay?: boolean;
|
|
290
|
+
loop?: boolean;
|
|
291
|
+
animationPaused?: boolean;
|
|
292
|
+
playbackRate?: number;
|
|
265
293
|
}
|
|
266
294
|
interface SpatialSceneCreationOptions$1 {
|
|
267
295
|
defaultSize?: {
|
|
@@ -436,6 +464,56 @@ interface AttachmentEntityUpdateOptions {
|
|
|
436
464
|
height: number;
|
|
437
465
|
};
|
|
438
466
|
}
|
|
467
|
+
type SceneUnitPx = `${number}px`;
|
|
468
|
+
type SceneUnitM = `${number}m`;
|
|
469
|
+
type SceneUnit = number | SceneUnitPx | SceneUnitM;
|
|
470
|
+
interface XRSceneSize {
|
|
471
|
+
width: SceneUnit;
|
|
472
|
+
height: SceneUnit;
|
|
473
|
+
depth?: SceneUnit;
|
|
474
|
+
}
|
|
475
|
+
interface XRSceneResizability {
|
|
476
|
+
minWidth?: SceneUnit;
|
|
477
|
+
minHeight?: SceneUnit;
|
|
478
|
+
maxWidth?: SceneUnit;
|
|
479
|
+
maxHeight?: SceneUnit;
|
|
480
|
+
}
|
|
481
|
+
interface XRMainSceneConfig extends XRSpatialSceneDefaults {
|
|
482
|
+
type?: SpatialSceneType$1;
|
|
483
|
+
}
|
|
484
|
+
interface XRSpatialSceneDefaults {
|
|
485
|
+
default_size?: XRSceneSize;
|
|
486
|
+
resizability?: XRSceneResizability;
|
|
487
|
+
worldScaling?: WorldScalingType;
|
|
488
|
+
worldAlignment?: WorldAlignmentType;
|
|
489
|
+
baseplateVisibility?: BaseplateVisibilityType;
|
|
490
|
+
}
|
|
491
|
+
interface XRSpatialSceneOverrides {
|
|
492
|
+
window_scene?: XRSpatialSceneDefaults;
|
|
493
|
+
volume_scene?: XRSpatialSceneDefaults;
|
|
494
|
+
}
|
|
495
|
+
interface XRSpatialSceneConfig extends XRSpatialSceneDefaults {
|
|
496
|
+
overrides?: XRSpatialSceneOverrides;
|
|
497
|
+
}
|
|
498
|
+
interface XRPrdConfig {
|
|
499
|
+
xr_main_scene?: XRMainSceneConfig;
|
|
500
|
+
xr_spatial_scene?: XRSpatialSceneConfig;
|
|
501
|
+
}
|
|
502
|
+
interface PWAManifest extends XRPrdConfig {
|
|
503
|
+
name?: string;
|
|
504
|
+
short_name?: string;
|
|
505
|
+
start_url?: string;
|
|
506
|
+
display?: string;
|
|
507
|
+
icons?: Array<{
|
|
508
|
+
src: string;
|
|
509
|
+
sizes?: string;
|
|
510
|
+
type?: string;
|
|
511
|
+
purpose?: string;
|
|
512
|
+
}>;
|
|
513
|
+
id?: string;
|
|
514
|
+
scope?: string;
|
|
515
|
+
[key: string]: any;
|
|
516
|
+
}
|
|
439
517
|
|
|
440
518
|
declare class SpatialComponent extends SpatialObject {
|
|
441
519
|
constructor(id: string);
|
|
@@ -455,6 +533,7 @@ declare class SpatialEntity extends SpatialObject {
|
|
|
455
533
|
set enableInput(value: boolean);
|
|
456
534
|
constructor(id: string, userData?: SpatialEntityUserData | undefined);
|
|
457
535
|
addComponent(component: SpatialComponent): Promise<CommandResult>;
|
|
536
|
+
removeComponent(component: SpatialComponent): Promise<CommandResult>;
|
|
458
537
|
setPosition(position: Vec3): Promise<CommandResult>;
|
|
459
538
|
setRotation(rotation: Vec3): Promise<CommandResult>;
|
|
460
539
|
setScale(scale: Vec3): Promise<CommandResult>;
|
|
@@ -477,6 +556,7 @@ declare class SpatialModelEntity extends SpatialEntity {
|
|
|
477
556
|
options?: SpatialModelEntityCreationOptions | undefined;
|
|
478
557
|
userData?: SpatialEntityUserData | undefined;
|
|
479
558
|
constructor(id: string, options?: SpatialModelEntityCreationOptions | undefined, userData?: SpatialEntityUserData | undefined);
|
|
559
|
+
setMaterials(materials: SpatialMaterial[]): Promise<CommandResult>;
|
|
480
560
|
}
|
|
481
561
|
|
|
482
562
|
declare class ModelComponent extends SpatialComponent {
|
|
@@ -542,10 +622,6 @@ declare class Attachment extends SpatialObject {
|
|
|
542
622
|
}
|
|
543
623
|
declare function createAttachmentEntity(options: AttachmentEntityOptions): Promise<Attachment>;
|
|
544
624
|
|
|
545
|
-
declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
|
|
546
|
-
type: SpatialSceneType$1;
|
|
547
|
-
}): void;
|
|
548
|
-
|
|
549
625
|
type SpatialSceneCreationOptionsInternal = SpatialSceneCreationOptions$1 & {
|
|
550
626
|
type: SpatialSceneType$1;
|
|
551
627
|
};
|
|
@@ -557,6 +633,10 @@ declare enum SpatialSceneState {
|
|
|
557
633
|
fail = "fail"
|
|
558
634
|
}
|
|
559
635
|
|
|
636
|
+
declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
|
|
637
|
+
type: SpatialSceneType$1;
|
|
638
|
+
}): void;
|
|
639
|
+
|
|
560
640
|
/**
|
|
561
641
|
* Represents the spatial scene that contains all spatialized elements.
|
|
562
642
|
* This class follows the singleton pattern - only one instance exists per application.
|
|
@@ -639,8 +719,9 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
|
639
719
|
* Registers the element to receive spatial events.
|
|
640
720
|
* @param id Unique identifier for this element
|
|
641
721
|
* @param modelURL URL of the 3D model
|
|
722
|
+
* @param sources Optional fallback model sources
|
|
642
723
|
*/
|
|
643
|
-
constructor(id: string, modelURL
|
|
724
|
+
constructor(id: string, modelURL?: string, sources?: ModelSource[]);
|
|
644
725
|
/**
|
|
645
726
|
* Promise resolver for the ready state.
|
|
646
727
|
* Used to resolve the ready promise when the model is loaded.
|
|
@@ -650,7 +731,16 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
|
650
731
|
* Caches the last model URL to detect changes.
|
|
651
732
|
* Used to reset the ready promise when the model URL changes.
|
|
652
733
|
*/
|
|
653
|
-
private modelURL
|
|
734
|
+
private modelURL?;
|
|
735
|
+
/**
|
|
736
|
+
* Caches the last sources array to detect changes.
|
|
737
|
+
*/
|
|
738
|
+
private sources?;
|
|
739
|
+
/**
|
|
740
|
+
* The model URL that was successfully loaded by the native runtime.
|
|
741
|
+
*/
|
|
742
|
+
private _currentSrc;
|
|
743
|
+
get currentSrc(): string;
|
|
654
744
|
/**
|
|
655
745
|
* Creates a new promise for tracking the ready state of the model.
|
|
656
746
|
* @returns Promise that resolves when the model is loaded (true) or fails to load (false)
|
|
@@ -668,14 +758,74 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
|
668
758
|
* @returns Promise resolving when the update is complete
|
|
669
759
|
*/
|
|
670
760
|
updateProperties(properties: Partial<SpatializedStatic3DElementProperties>): Promise<CommandResult>;
|
|
761
|
+
/**
|
|
762
|
+
* Total animation duration in seconds, synced from native.
|
|
763
|
+
*/
|
|
764
|
+
private _duration;
|
|
765
|
+
/**
|
|
766
|
+
* Returns the total animation duration in seconds.
|
|
767
|
+
*/
|
|
768
|
+
get duration(): number;
|
|
769
|
+
/**
|
|
770
|
+
* Playback speed multiplier.
|
|
771
|
+
*/
|
|
772
|
+
private _playbackRate;
|
|
773
|
+
/**
|
|
774
|
+
* Returns the current playback rate.
|
|
775
|
+
*/
|
|
776
|
+
get playbackRate(): number;
|
|
777
|
+
/**
|
|
778
|
+
* Sets the playback rate and sends it to native.
|
|
779
|
+
*/
|
|
780
|
+
set playbackRate(value: number);
|
|
781
|
+
/**
|
|
782
|
+
* Whether the animation is currently paused.
|
|
783
|
+
*/
|
|
784
|
+
private _paused;
|
|
785
|
+
/**
|
|
786
|
+
* Returns whether the animation is currently paused.
|
|
787
|
+
*/
|
|
788
|
+
get paused(): boolean;
|
|
789
|
+
/**
|
|
790
|
+
* Callback for animation state changes.
|
|
791
|
+
*/
|
|
792
|
+
private _onAnimationStateChangeCallback?;
|
|
793
|
+
/**
|
|
794
|
+
* Sets the callback for animation state changes.
|
|
795
|
+
*/
|
|
796
|
+
set onAnimationStateChangeCallback(callback: undefined | ((detail: AnimationStateChangeDetail) => void));
|
|
797
|
+
/**
|
|
798
|
+
* Starts or resumes animation playback.
|
|
799
|
+
* @returns Promise resolving when the command is sent
|
|
800
|
+
*/
|
|
801
|
+
play(): Promise<void>;
|
|
802
|
+
/**
|
|
803
|
+
* Pauses animation playback.
|
|
804
|
+
* @returns Promise resolving when the command is sent
|
|
805
|
+
*/
|
|
806
|
+
pause(): Promise<void>;
|
|
671
807
|
/**
|
|
672
808
|
* Processes events received from the WebSpatial environment.
|
|
673
809
|
* Handles model loading events in addition to base spatial events.
|
|
674
810
|
* @param data The event data received from the WebSpatial system
|
|
675
811
|
*/
|
|
676
|
-
onReceiveEvent(data:
|
|
677
|
-
|
|
678
|
-
|
|
812
|
+
onReceiveEvent(data: Static3DReceiveEventData): void;
|
|
813
|
+
/**
|
|
814
|
+
* Whether the model should automatically play its first animation on load.
|
|
815
|
+
*/
|
|
816
|
+
private _autoplay;
|
|
817
|
+
/**
|
|
818
|
+
* Returns whether autoplay is enabled for this element.
|
|
819
|
+
*/
|
|
820
|
+
get autoplay(): boolean;
|
|
821
|
+
/**
|
|
822
|
+
* Whether the model animation should loop continuously.
|
|
823
|
+
*/
|
|
824
|
+
private _loop;
|
|
825
|
+
/**
|
|
826
|
+
* Returns whether loop is enabled for this element.
|
|
827
|
+
*/
|
|
828
|
+
get loop(): boolean;
|
|
679
829
|
/**
|
|
680
830
|
* Callback function for successful model loading.
|
|
681
831
|
*/
|
|
@@ -696,6 +846,7 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
|
696
846
|
set onLoadFailureCallback(callback: undefined | (() => void));
|
|
697
847
|
updateModelTransform(transform: DOMMatrixReadOnly): void;
|
|
698
848
|
}
|
|
849
|
+
type Static3DReceiveEventData = ModelLoadSuccess | ModelLoadFailure | ReceiveEventData | AnimationStateChangeMsg;
|
|
699
850
|
|
|
700
851
|
/**
|
|
701
852
|
* Session used to establish a connection to the spatial renderer of the system.
|
|
@@ -721,7 +872,7 @@ declare class SpatialSession {
|
|
|
721
872
|
* @param modelURL Optional URL to the 3D model to load
|
|
722
873
|
* @returns Promise resolving to a new SpatializedStatic3DElement instance
|
|
723
874
|
*/
|
|
724
|
-
createSpatializedStatic3DElement(modelURL
|
|
875
|
+
createSpatializedStatic3DElement(modelURL?: string, sources?: ModelSource[]): Promise<SpatializedStatic3DElement>;
|
|
725
876
|
/**
|
|
726
877
|
* Initializes the spatial scene with custom configuration.
|
|
727
878
|
* This is a reference to the initScene function from scene-polyfill.
|
|
@@ -916,6 +1067,14 @@ declare global {
|
|
|
916
1067
|
webkit: any
|
|
917
1068
|
webspatialBridge: any
|
|
918
1069
|
|
|
1070
|
+
// Project Pico OS browser injects this global object to provide internal capabilities.
|
|
1071
|
+
webSpatial?: {
|
|
1072
|
+
genToken?: () => string
|
|
1073
|
+
}
|
|
1074
|
+
__webspatialShell__?: {
|
|
1075
|
+
genToken?: () => string
|
|
1076
|
+
}
|
|
1077
|
+
|
|
919
1078
|
// Will be removed in favor of __WebSpatialData
|
|
920
1079
|
WebSpatailNativeVersion: string
|
|
921
1080
|
|
|
@@ -939,4 +1098,4 @@ declare global {
|
|
|
939
1098
|
|
|
940
1099
|
declare const isSSREnv: () => boolean;
|
|
941
1100
|
|
|
942
|
-
export { Attachment, type AttachmentEntityOptions, type AttachmentEntityUpdateOptions, type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo, type ModelAssetOptions, ModelComponent, type ModelComponentOptions, physicalMetrics as PhysicalMetrics, type Point3D, type Quaternion, type Size, type Size3D, Spatial, SpatialBoxGeometry, type SpatialBoxGeometryOptions, SpatialComponent, SpatialConeGeometry, type SpatialConeGeometryOptions, SpatialCylinderGeometry, type SpatialCylinderGeometryOptions, type SpatialDragEndEvent, type SpatialDragEndEventDetail, type SpatialDragEvent, type SpatialDragEventDetail, type SpatialDragStartEvent, type SpatialDragStartEventDetail, SpatialEntity, type SpatialEntityEventType, type SpatialEntityOrReality, type SpatialEntityProperties, type SpatialEntityUserData, SpatialGeometry, type SpatialGeometryOptions, type SpatialGeometryType, type SpatialMagnifyEndEvent, type SpatialMagnifyEndEventDetail, type SpatialMagnifyEvent, type SpatialMagnifyEventDetail, SpatialMaterial, type SpatialMaterialType, SpatialModelAsset, type SpatialModelDragEvent, SpatialModelEntity, type SpatialModelEntityCreationOptions, SpatialObject, SpatialPlaneGeometry, type SpatialPlaneGeometryOptions, type SpatialRotateEndEvent, type SpatialRotateEndEventDetail, 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, createAttachmentEntity, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };
|
|
1101
|
+
export { Attachment, type AttachmentEntityOptions, type AttachmentEntityUpdateOptions, type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo, type ModelAssetOptions, ModelComponent, type ModelComponentOptions, type ModelSource, type PWAManifest, physicalMetrics as PhysicalMetrics, type Point3D, type Quaternion, type SceneUnit, type SceneUnitM, type SceneUnitPx, type Size, type Size3D, Spatial, SpatialBoxGeometry, type SpatialBoxGeometryOptions, SpatialComponent, SpatialConeGeometry, type SpatialConeGeometryOptions, SpatialCylinderGeometry, type SpatialCylinderGeometryOptions, type SpatialDragEndEvent, type SpatialDragEndEventDetail, type SpatialDragEvent, type SpatialDragEventDetail, type SpatialDragStartEvent, type SpatialDragStartEventDetail, SpatialEntity, type SpatialEntityEventType, type SpatialEntityOrReality, type SpatialEntityProperties, type SpatialEntityUserData, SpatialGeometry, type SpatialGeometryOptions, type SpatialGeometryType, type SpatialMagnifyEndEvent, type SpatialMagnifyEndEventDetail, type SpatialMagnifyEvent, type SpatialMagnifyEventDetail, SpatialMaterial, type SpatialMaterialType, SpatialModelAsset, type SpatialModelDragEvent, SpatialModelEntity, type SpatialModelEntityCreationOptions, SpatialObject, SpatialPlaneGeometry, type SpatialPlaneGeometryOptions, type SpatialRotateEndEvent, type SpatialRotateEndEventDetail, 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, type XRMainSceneConfig, type XRPrdConfig, type XRSceneResizability, type XRSceneSize, type XRSpatialSceneConfig, type XRSpatialSceneDefaults, type XRSpatialSceneOverrides, createAttachmentEntity, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };
|