@webspatial/core-sdk 1.5.0 → 1.6.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.
- package/CHANGELOG.md +29 -0
- package/dist/iife/index.d.ts +164 -12
- package/dist/iife/index.global.js +11 -11
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +164 -12
- package/dist/index.js +415 -117
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/JSBCommand.ts +7 -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/scene-polyfill.manifest.test.ts +402 -0
- package/src/scene-polyfill.test.ts +168 -18
- package/src/scene-polyfill.ts +290 -46
- package/src/types/global.d.ts +3 -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);
|
|
@@ -544,10 +622,6 @@ declare class Attachment extends SpatialObject {
|
|
|
544
622
|
}
|
|
545
623
|
declare function createAttachmentEntity(options: AttachmentEntityOptions): Promise<Attachment>;
|
|
546
624
|
|
|
547
|
-
declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
|
|
548
|
-
type: SpatialSceneType$1;
|
|
549
|
-
}): void;
|
|
550
|
-
|
|
551
625
|
type SpatialSceneCreationOptionsInternal = SpatialSceneCreationOptions$1 & {
|
|
552
626
|
type: SpatialSceneType$1;
|
|
553
627
|
};
|
|
@@ -559,6 +633,10 @@ declare enum SpatialSceneState {
|
|
|
559
633
|
fail = "fail"
|
|
560
634
|
}
|
|
561
635
|
|
|
636
|
+
declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
|
|
637
|
+
type: SpatialSceneType$1;
|
|
638
|
+
}): void;
|
|
639
|
+
|
|
562
640
|
/**
|
|
563
641
|
* Represents the spatial scene that contains all spatialized elements.
|
|
564
642
|
* This class follows the singleton pattern - only one instance exists per application.
|
|
@@ -641,8 +719,9 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
|
641
719
|
* Registers the element to receive spatial events.
|
|
642
720
|
* @param id Unique identifier for this element
|
|
643
721
|
* @param modelURL URL of the 3D model
|
|
722
|
+
* @param sources Optional fallback model sources
|
|
644
723
|
*/
|
|
645
|
-
constructor(id: string, modelURL
|
|
724
|
+
constructor(id: string, modelURL?: string, sources?: ModelSource[]);
|
|
646
725
|
/**
|
|
647
726
|
* Promise resolver for the ready state.
|
|
648
727
|
* Used to resolve the ready promise when the model is loaded.
|
|
@@ -652,7 +731,16 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
|
652
731
|
* Caches the last model URL to detect changes.
|
|
653
732
|
* Used to reset the ready promise when the model URL changes.
|
|
654
733
|
*/
|
|
655
|
-
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;
|
|
656
744
|
/**
|
|
657
745
|
* Creates a new promise for tracking the ready state of the model.
|
|
658
746
|
* @returns Promise that resolves when the model is loaded (true) or fails to load (false)
|
|
@@ -670,14 +758,74 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
|
670
758
|
* @returns Promise resolving when the update is complete
|
|
671
759
|
*/
|
|
672
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>;
|
|
673
807
|
/**
|
|
674
808
|
* Processes events received from the WebSpatial environment.
|
|
675
809
|
* Handles model loading events in addition to base spatial events.
|
|
676
810
|
* @param data The event data received from the WebSpatial system
|
|
677
811
|
*/
|
|
678
|
-
onReceiveEvent(data:
|
|
679
|
-
|
|
680
|
-
|
|
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;
|
|
681
829
|
/**
|
|
682
830
|
* Callback function for successful model loading.
|
|
683
831
|
*/
|
|
@@ -698,6 +846,7 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
|
698
846
|
set onLoadFailureCallback(callback: undefined | (() => void));
|
|
699
847
|
updateModelTransform(transform: DOMMatrixReadOnly): void;
|
|
700
848
|
}
|
|
849
|
+
type Static3DReceiveEventData = ModelLoadSuccess | ModelLoadFailure | ReceiveEventData | AnimationStateChangeMsg;
|
|
701
850
|
|
|
702
851
|
/**
|
|
703
852
|
* Session used to establish a connection to the spatial renderer of the system.
|
|
@@ -723,7 +872,7 @@ declare class SpatialSession {
|
|
|
723
872
|
* @param modelURL Optional URL to the 3D model to load
|
|
724
873
|
* @returns Promise resolving to a new SpatializedStatic3DElement instance
|
|
725
874
|
*/
|
|
726
|
-
createSpatializedStatic3DElement(modelURL
|
|
875
|
+
createSpatializedStatic3DElement(modelURL?: string, sources?: ModelSource[]): Promise<SpatializedStatic3DElement>;
|
|
727
876
|
/**
|
|
728
877
|
* Initializes the spatial scene with custom configuration.
|
|
729
878
|
* This is a reference to the initScene function from scene-polyfill.
|
|
@@ -922,6 +1071,9 @@ declare global {
|
|
|
922
1071
|
webSpatial?: {
|
|
923
1072
|
genToken?: () => string
|
|
924
1073
|
}
|
|
1074
|
+
__webspatialShell__?: {
|
|
1075
|
+
genToken?: () => string
|
|
1076
|
+
}
|
|
925
1077
|
|
|
926
1078
|
// Will be removed in favor of __WebSpatialData
|
|
927
1079
|
WebSpatailNativeVersion: string
|
|
@@ -946,4 +1098,4 @@ declare global {
|
|
|
946
1098
|
|
|
947
1099
|
declare const isSSREnv: () => boolean;
|
|
948
1100
|
|
|
949
|
-
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 };
|