@webspatial/core-sdk 1.2.1 → 1.4.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 +69 -1
- package/dist/iife/index.d.ts +115 -32
- package/dist/iife/index.global.js +68 -3
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +115 -32
- package/dist/index.js +603 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/JSBCommand.ts +65 -0
- package/src/Spatial.ts +22 -1
- package/src/SpatialScene.ts +20 -0
- package/src/SpatialSession.ts +15 -1
- package/src/SpatializedDynamic3DElement.ts +19 -0
- package/src/SpatializedElement.ts +0 -29
- package/src/SpatializedElementCreator.ts +1 -1
- package/src/SpatializedStatic3DElement.test.ts +125 -0
- package/src/SpatializedStatic3DElement.ts +14 -1
- package/src/WebMsgCommand.ts +0 -26
- package/src/index.ts +2 -0
- package/src/jsbcommand.coverage.test.ts +0 -43
- package/src/physicalMetrics.test.ts +110 -0
- package/src/physicalMetrics.ts +101 -0
- package/src/platform-adapter/index.ts +5 -1
- package/src/platform-adapter/puppeteer/PuppeteerPlatform.ts +470 -0
- package/src/reality/Attachment.ts +47 -0
- package/src/reality/entity/SpatialEntity.ts +45 -24
- package/src/reality/index.ts +1 -0
- package/src/types/global.d.ts +7 -5
- package/src/types/types.ts +29 -2
package/dist/index.d.ts
CHANGED
|
@@ -47,8 +47,6 @@ declare abstract class SpatialMaterial extends SpatialObject {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
declare enum SpatialWebMsgType {
|
|
50
|
-
cubeInfo = "cubeInfo",
|
|
51
|
-
transform = "transform",
|
|
52
50
|
modelloaded = "modelloaded",
|
|
53
51
|
modelloadfailed = "modelloadfailed",
|
|
54
52
|
spatialtap = "spatialtap",
|
|
@@ -64,25 +62,6 @@ declare enum SpatialWebMsgType {
|
|
|
64
62
|
interface ObjectDestroyMsg {
|
|
65
63
|
type: SpatialWebMsgType.objectdestroy;
|
|
66
64
|
}
|
|
67
|
-
interface CubeInfoMsg {
|
|
68
|
-
type: SpatialWebMsgType.cubeInfo;
|
|
69
|
-
origin: Vec3;
|
|
70
|
-
size: Size3D;
|
|
71
|
-
}
|
|
72
|
-
interface CubeInfoMsg {
|
|
73
|
-
type: SpatialWebMsgType.cubeInfo;
|
|
74
|
-
origin: Vec3;
|
|
75
|
-
size: Size3D;
|
|
76
|
-
}
|
|
77
|
-
interface TransformMsg {
|
|
78
|
-
type: SpatialWebMsgType.transform;
|
|
79
|
-
detail: {
|
|
80
|
-
column0: [number, number, number];
|
|
81
|
-
column1: [number, number, number];
|
|
82
|
-
column2: [number, number, number];
|
|
83
|
-
column3: [number, number, number];
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
65
|
interface SpatialTapMsg {
|
|
87
66
|
type: SpatialWebMsgType.spatialtap;
|
|
88
67
|
detail: SpatialTapEventDetail;
|
|
@@ -144,7 +123,7 @@ declare abstract class SpatializedElement extends SpatialObject {
|
|
|
144
123
|
* Gets the current cube information for this element.
|
|
145
124
|
* @returns The current CubeInfo or undefined if not set
|
|
146
125
|
*/
|
|
147
|
-
get cubeInfo(): CubeInfo
|
|
126
|
+
get cubeInfo(): CubeInfo | undefined;
|
|
148
127
|
/**
|
|
149
128
|
* The current transformation matrix of this element.
|
|
150
129
|
*/
|
|
@@ -169,7 +148,7 @@ declare abstract class SpatializedElement extends SpatialObject {
|
|
|
169
148
|
* Handles various spatial events like transforms, gestures, and interactions.
|
|
170
149
|
* @param data The event data received from the WebSpatial system
|
|
171
150
|
*/
|
|
172
|
-
protected onReceiveEvent(data:
|
|
151
|
+
protected onReceiveEvent(data: SpatialTapMsg | SpatialDragStartMsg | SpatialDragMsg | SpatialDragEndMsg | SpatialRotateMsg | SpatialRotateEndMsg | ObjectDestroyMsg): void;
|
|
173
152
|
private _onSpatialTap?;
|
|
174
153
|
set onSpatialTap(value: (event: SpatialTapEvent) => void | undefined);
|
|
175
154
|
private _onSpatialDragStart?;
|
|
@@ -195,8 +174,12 @@ declare abstract class SpatializedElement extends SpatialObject {
|
|
|
195
174
|
|
|
196
175
|
declare class SpatializedDynamic3DElement extends SpatializedElement {
|
|
197
176
|
children: SpatialEntityOrReality[];
|
|
177
|
+
events: Record<string, (data: any) => void>;
|
|
198
178
|
constructor(id: string);
|
|
199
179
|
addEntity(entity: SpatialEntity): Promise<CommandResult>;
|
|
180
|
+
addEvent(type: SpatialEntityEventType, callback: (data: any) => void): void;
|
|
181
|
+
removeEvent(eventName: SpatialEntityEventType): void;
|
|
182
|
+
dispatchEvent(evt: CustomEvent): void;
|
|
200
183
|
updateProperties(properties: Partial<SpatializedElementProperties>): Promise<CommandResult>;
|
|
201
184
|
}
|
|
202
185
|
|
|
@@ -264,6 +247,11 @@ interface SpatializedElementProperties {
|
|
|
264
247
|
enableRotateEndGesture: boolean;
|
|
265
248
|
enableMagnifyGesture: boolean;
|
|
266
249
|
enableMagnifyEndGesture: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Optional world-space axis for spatial rotate gesture. Omitted or zero vector
|
|
252
|
+
* means unconstrained rotation (platform default).
|
|
253
|
+
*/
|
|
254
|
+
rotateConstrainedToAxis?: Vec3;
|
|
267
255
|
}
|
|
268
256
|
interface Spatialized2DElementProperties extends SpatializedElementProperties {
|
|
269
257
|
scrollPageEnabled: boolean;
|
|
@@ -291,6 +279,7 @@ interface SpatialSceneCreationOptions$1 {
|
|
|
291
279
|
worldAlignment?: WorldAlignmentType;
|
|
292
280
|
baseplateVisibility?: BaseplateVisibilityType;
|
|
293
281
|
}
|
|
282
|
+
type SpatialEntityEventType = 'spatialtap' | 'spatialdragstart' | 'spatialdrag' | 'spatialdragend' | 'spatialrotate' | 'spatialrotateend' | 'spatialmagnify' | 'spatialmagnifyend';
|
|
294
283
|
declare const BaseplateVisibilityValues: readonly ["automatic", "visible", "hidden"];
|
|
295
284
|
type BaseplateVisibilityType = (typeof BaseplateVisibilityValues)[number];
|
|
296
285
|
declare function isValidBaseplateVisibilityType(type: string): Boolean;
|
|
@@ -313,7 +302,6 @@ interface SpatialEntityProperties {
|
|
|
313
302
|
rotation: Vec3;
|
|
314
303
|
scale: Vec3;
|
|
315
304
|
}
|
|
316
|
-
type SpatialEntityEventType = 'spatialtap';
|
|
317
305
|
type SpatialGeometryType = 'BoxGeometry' | 'PlaneGeometry' | 'SphereGeometry' | 'CylinderGeometry' | 'ConeGeometry';
|
|
318
306
|
interface SpatialBoxGeometryOptions {
|
|
319
307
|
width?: number;
|
|
@@ -383,7 +371,7 @@ interface Size {
|
|
|
383
371
|
interface Size3D extends Size {
|
|
384
372
|
depth: number;
|
|
385
373
|
}
|
|
386
|
-
declare class CubeInfo
|
|
374
|
+
declare class CubeInfo {
|
|
387
375
|
size: Size3D;
|
|
388
376
|
origin: Vec3;
|
|
389
377
|
constructor(size: Size3D, origin: Vec3);
|
|
@@ -402,10 +390,12 @@ declare class CubeInfo$1 {
|
|
|
402
390
|
}
|
|
403
391
|
interface SpatialTapEventDetail {
|
|
404
392
|
location3D: Point3D;
|
|
393
|
+
globalLocation3D?: Point3D;
|
|
405
394
|
}
|
|
406
395
|
type SpatialTapEvent = CustomEvent<SpatialTapEventDetail>;
|
|
407
396
|
interface SpatialDragStartEventDetail {
|
|
408
397
|
startLocation3D: Point3D;
|
|
398
|
+
globalLocation3D?: Point3D;
|
|
409
399
|
}
|
|
410
400
|
interface SpatialDragEventDetail {
|
|
411
401
|
translation3D: Vec3;
|
|
@@ -430,6 +420,22 @@ interface SpatialMagnifyEndEventDetail {
|
|
|
430
420
|
type SpatialMagnifyEvent = CustomEvent<SpatialMagnifyEventDetail>;
|
|
431
421
|
type SpatialMagnifyEndEvent = CustomEvent<SpatialMagnifyEndEventDetail>;
|
|
432
422
|
type SpatialEntityOrReality = SpatialEntity | SpatializedDynamic3DElement;
|
|
423
|
+
interface AttachmentEntityOptions {
|
|
424
|
+
parentEntityId: string;
|
|
425
|
+
position?: [number, number, number];
|
|
426
|
+
size: {
|
|
427
|
+
width: number;
|
|
428
|
+
height: number;
|
|
429
|
+
};
|
|
430
|
+
ownerViewId: string;
|
|
431
|
+
}
|
|
432
|
+
interface AttachmentEntityUpdateOptions {
|
|
433
|
+
position?: [number, number, number];
|
|
434
|
+
size?: {
|
|
435
|
+
width: number;
|
|
436
|
+
height: number;
|
|
437
|
+
};
|
|
438
|
+
}
|
|
433
439
|
|
|
434
440
|
declare class SpatialComponent extends SpatialObject {
|
|
435
441
|
constructor(id: string);
|
|
@@ -444,6 +450,9 @@ declare class SpatialEntity extends SpatialObject {
|
|
|
444
450
|
events: Record<string, (data: any) => void>;
|
|
445
451
|
children: SpatialEntity[];
|
|
446
452
|
parent: SpatialEntityOrReality | null;
|
|
453
|
+
private _enableInput;
|
|
454
|
+
get enableInput(): boolean;
|
|
455
|
+
set enableInput(value: boolean);
|
|
447
456
|
constructor(id: string, userData?: SpatialEntityUserData | undefined);
|
|
448
457
|
addComponent(component: SpatialComponent): Promise<CommandResult>;
|
|
449
458
|
setPosition(position: Vec3): Promise<CommandResult>;
|
|
@@ -523,6 +532,16 @@ declare class SpatialModelAsset extends SpatialObject {
|
|
|
523
532
|
constructor(id: string, options: ModelAssetOptions);
|
|
524
533
|
}
|
|
525
534
|
|
|
535
|
+
declare class Attachment extends SpatialObject {
|
|
536
|
+
private readonly windowProxy;
|
|
537
|
+
private options;
|
|
538
|
+
constructor(id: string, windowProxy: WindowProxy, options: AttachmentEntityOptions);
|
|
539
|
+
getContainer(): HTMLElement;
|
|
540
|
+
getWindowProxy(): WindowProxy;
|
|
541
|
+
update(options: AttachmentEntityUpdateOptions): Promise<CommandResult | undefined>;
|
|
542
|
+
}
|
|
543
|
+
declare function createAttachmentEntity(options: AttachmentEntityOptions): Promise<Attachment>;
|
|
544
|
+
|
|
526
545
|
declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
|
|
527
546
|
type: SpatialSceneType$1;
|
|
528
547
|
}): void;
|
|
@@ -550,6 +569,7 @@ declare class SpatialScene extends SpatialObject {
|
|
|
550
569
|
* @returns The singleton SpatialScene instance
|
|
551
570
|
*/
|
|
552
571
|
static getInstance(): SpatialScene;
|
|
572
|
+
convertCoordinate(position: Vec3, fromId: string, toId: string): Promise<Vec3>;
|
|
553
573
|
/**
|
|
554
574
|
* Updates the properties of the spatial scene.
|
|
555
575
|
* This can include background settings, lighting, and other scene-wide properties.
|
|
@@ -614,6 +634,13 @@ declare class Spatialized2DElement extends SpatializedElement {
|
|
|
614
634
|
* and provides events for load success and failure.
|
|
615
635
|
*/
|
|
616
636
|
declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
637
|
+
/**
|
|
638
|
+
* Creates a new spatialized static 3D element with the specified ID and URL.
|
|
639
|
+
* Registers the element to receive spatial events.
|
|
640
|
+
* @param id Unique identifier for this element
|
|
641
|
+
* @param modelURL URL of the 3D model
|
|
642
|
+
*/
|
|
643
|
+
constructor(id: string, modelURL: string);
|
|
617
644
|
/**
|
|
618
645
|
* Promise resolver for the ready state.
|
|
619
646
|
* Used to resolve the ready promise when the model is loaded.
|
|
@@ -694,7 +721,7 @@ declare class SpatialSession {
|
|
|
694
721
|
* @param modelURL Optional URL to the 3D model to load
|
|
695
722
|
* @returns Promise resolving to a new SpatializedStatic3DElement instance
|
|
696
723
|
*/
|
|
697
|
-
createSpatializedStatic3DElement(modelURL
|
|
724
|
+
createSpatializedStatic3DElement(modelURL: string): Promise<SpatializedStatic3DElement>;
|
|
698
725
|
/**
|
|
699
726
|
* Initializes the spatial scene with custom configuration.
|
|
700
727
|
* This is a reference to the initScene function from scene-polyfill.
|
|
@@ -771,6 +798,13 @@ declare class SpatialSession {
|
|
|
771
798
|
* @returns Promise resolving to a new SpatialModelEntity instance
|
|
772
799
|
*/
|
|
773
800
|
createSpatialModelEntity(options: SpatialModelEntityCreationOptions, userData?: SpatialEntityUserData): Promise<SpatialModelEntity>;
|
|
801
|
+
/**
|
|
802
|
+
* Creates an attachment entity that renders 2D HTML content as a child
|
|
803
|
+
* of a 3D entity in the scene graph.
|
|
804
|
+
* @param options Configuration options including parent entity ID, position, and size
|
|
805
|
+
* @returns Promise resolving to a new Attachment instance
|
|
806
|
+
*/
|
|
807
|
+
createAttachmentEntity(options: AttachmentEntityOptions): Promise<Attachment>;
|
|
774
808
|
}
|
|
775
809
|
|
|
776
810
|
/**
|
|
@@ -778,6 +812,7 @@ declare class SpatialSession {
|
|
|
778
812
|
* This is the main entry point for the WebSpatial SDK, providing access to spatial capabilities.
|
|
779
813
|
*/
|
|
780
814
|
declare class Spatial {
|
|
815
|
+
private wsAppShellVersionFromUA;
|
|
781
816
|
/**
|
|
782
817
|
* Requests a spatial session object from the browser.
|
|
783
818
|
* This is the primary method to initialize spatial functionality.
|
|
@@ -791,6 +826,7 @@ declare class Spatial {
|
|
|
791
826
|
* @returns True if running in a spatial web environment, false otherwise
|
|
792
827
|
*/
|
|
793
828
|
runInSpatialWeb(): boolean;
|
|
829
|
+
getShellVersionFromUA(): string | null;
|
|
794
830
|
/** @deprecated
|
|
795
831
|
* Checks if WebSpatial is supported in the current environment.
|
|
796
832
|
* Verifies compatibility between native and client versions.
|
|
@@ -811,6 +847,53 @@ declare class Spatial {
|
|
|
811
847
|
getClientVersion(): string;
|
|
812
848
|
}
|
|
813
849
|
|
|
850
|
+
type PhysicalMetricsValueShape = {
|
|
851
|
+
meterToPtUnscaled: number;
|
|
852
|
+
meterToPtScaled: number;
|
|
853
|
+
};
|
|
854
|
+
type WorldScalingCompensation = 'unscaled' | 'scaled';
|
|
855
|
+
type ConvertOption = {
|
|
856
|
+
worldScalingCompensation: WorldScalingCompensation;
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* Converts scene points (pt) to physical meters (m).
|
|
860
|
+
*
|
|
861
|
+
* @param point Points value to convert.
|
|
862
|
+
* @param options Optional conversion options to select world scaling compensation.
|
|
863
|
+
* @returns Physical length in meters.
|
|
864
|
+
*/
|
|
865
|
+
declare function pointToPhysical(point: number, options?: ConvertOption): number;
|
|
866
|
+
/**
|
|
867
|
+
* Converts physical meters (m) to scene points (pt).
|
|
868
|
+
*
|
|
869
|
+
* @param physical Physical length in meters to convert.
|
|
870
|
+
* @param options Optional conversion options to select world scaling compensation.
|
|
871
|
+
* @returns Points length in the scene.
|
|
872
|
+
*/
|
|
873
|
+
declare function physicalToPoint(physical: number, options?: ConvertOption): number;
|
|
874
|
+
/**
|
|
875
|
+
* Returns the current physical metrics used for conversions.
|
|
876
|
+
*
|
|
877
|
+
* @returns The current metrics snapshot `{ meterToPtUnscaled, meterToPtScaled }`.
|
|
878
|
+
*/
|
|
879
|
+
declare function getValue(): PhysicalMetricsValueShape;
|
|
880
|
+
/**
|
|
881
|
+
* Subscribes to physical metrics changes.
|
|
882
|
+
*
|
|
883
|
+
* @param cb Callback invoked when metrics update is detected.
|
|
884
|
+
* @returns Unsubscribe function to remove the listener.
|
|
885
|
+
*/
|
|
886
|
+
declare function subscribe(cb: () => void): () => void;
|
|
887
|
+
|
|
888
|
+
type physicalMetrics_PhysicalMetricsValueShape = PhysicalMetricsValueShape;
|
|
889
|
+
declare const physicalMetrics_getValue: typeof getValue;
|
|
890
|
+
declare const physicalMetrics_physicalToPoint: typeof physicalToPoint;
|
|
891
|
+
declare const physicalMetrics_pointToPhysical: typeof pointToPhysical;
|
|
892
|
+
declare const physicalMetrics_subscribe: typeof subscribe;
|
|
893
|
+
declare namespace physicalMetrics {
|
|
894
|
+
export { type physicalMetrics_PhysicalMetricsValueShape as PhysicalMetricsValueShape, physicalMetrics_getValue as getValue, physicalMetrics_physicalToPoint as physicalToPoint, physicalMetrics_pointToPhysical as pointToPhysical, physicalMetrics_subscribe as subscribe };
|
|
895
|
+
}
|
|
896
|
+
|
|
814
897
|
declare global {
|
|
815
898
|
declare const __WEBSPATIAL_CORE_SDK_VERSION__: string
|
|
816
899
|
|
|
@@ -841,19 +924,19 @@ declare global {
|
|
|
841
924
|
'natvie-version'?: string
|
|
842
925
|
'react-sdk-version'?: string
|
|
843
926
|
'core-sdk-version'?: string
|
|
927
|
+
physicalMetrics?: PhysicalMetricsValueShape
|
|
844
928
|
}
|
|
845
929
|
|
|
846
|
-
|
|
847
|
-
|
|
930
|
+
xrInnerDepth: number
|
|
931
|
+
xrOuterDepth: number
|
|
848
932
|
}
|
|
849
933
|
|
|
850
934
|
interface HTMLElement {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
getBoundingClientCube: () => CubeInfo | undefined
|
|
935
|
+
xrOffsetBack: number
|
|
936
|
+
xrClientDepth: number
|
|
854
937
|
}
|
|
855
938
|
}
|
|
856
939
|
|
|
857
940
|
declare const isSSREnv: () => boolean;
|
|
858
941
|
|
|
859
|
-
export { type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo
|
|
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 };
|