@webspatial/core-sdk 1.3.0 → 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 +41 -1
- package/dist/iife/index.d.ts +73 -31
- package/dist/iife/index.global.js +14 -14
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +73 -31
- package/dist/index.js +182 -64
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/JSBCommand.ts +33 -0
- package/src/Spatial.ts +22 -1
- package/src/SpatialScene.ts +20 -0
- package/src/SpatializedDynamic3DElement.ts +19 -0
- package/src/SpatializedElement.ts +0 -29
- package/src/SpatializedStatic3DElement.test.ts +125 -0
- package/src/SpatializedStatic3DElement.ts +2 -0
- 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/puppeteer/PuppeteerPlatform.ts +52 -52
- package/src/reality/Attachment.ts +2 -0
- package/src/reality/entity/SpatialEntity.ts +45 -24
- package/src/types/global.d.ts +7 -5
- package/src/types/types.ts +16 -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);
|
|
@@ -439,6 +427,7 @@ interface AttachmentEntityOptions {
|
|
|
439
427
|
width: number;
|
|
440
428
|
height: number;
|
|
441
429
|
};
|
|
430
|
+
ownerViewId: string;
|
|
442
431
|
}
|
|
443
432
|
interface AttachmentEntityUpdateOptions {
|
|
444
433
|
position?: [number, number, number];
|
|
@@ -461,6 +450,9 @@ declare class SpatialEntity extends SpatialObject {
|
|
|
461
450
|
events: Record<string, (data: any) => void>;
|
|
462
451
|
children: SpatialEntity[];
|
|
463
452
|
parent: SpatialEntityOrReality | null;
|
|
453
|
+
private _enableInput;
|
|
454
|
+
get enableInput(): boolean;
|
|
455
|
+
set enableInput(value: boolean);
|
|
464
456
|
constructor(id: string, userData?: SpatialEntityUserData | undefined);
|
|
465
457
|
addComponent(component: SpatialComponent): Promise<CommandResult>;
|
|
466
458
|
setPosition(position: Vec3): Promise<CommandResult>;
|
|
@@ -577,6 +569,7 @@ declare class SpatialScene extends SpatialObject {
|
|
|
577
569
|
* @returns The singleton SpatialScene instance
|
|
578
570
|
*/
|
|
579
571
|
static getInstance(): SpatialScene;
|
|
572
|
+
convertCoordinate(position: Vec3, fromId: string, toId: string): Promise<Vec3>;
|
|
580
573
|
/**
|
|
581
574
|
* Updates the properties of the spatial scene.
|
|
582
575
|
* This can include background settings, lighting, and other scene-wide properties.
|
|
@@ -819,6 +812,7 @@ declare class SpatialSession {
|
|
|
819
812
|
* This is the main entry point for the WebSpatial SDK, providing access to spatial capabilities.
|
|
820
813
|
*/
|
|
821
814
|
declare class Spatial {
|
|
815
|
+
private wsAppShellVersionFromUA;
|
|
822
816
|
/**
|
|
823
817
|
* Requests a spatial session object from the browser.
|
|
824
818
|
* This is the primary method to initialize spatial functionality.
|
|
@@ -832,6 +826,7 @@ declare class Spatial {
|
|
|
832
826
|
* @returns True if running in a spatial web environment, false otherwise
|
|
833
827
|
*/
|
|
834
828
|
runInSpatialWeb(): boolean;
|
|
829
|
+
getShellVersionFromUA(): string | null;
|
|
835
830
|
/** @deprecated
|
|
836
831
|
* Checks if WebSpatial is supported in the current environment.
|
|
837
832
|
* Verifies compatibility between native and client versions.
|
|
@@ -852,6 +847,53 @@ declare class Spatial {
|
|
|
852
847
|
getClientVersion(): string;
|
|
853
848
|
}
|
|
854
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
|
+
|
|
855
897
|
declare global {
|
|
856
898
|
declare const __WEBSPATIAL_CORE_SDK_VERSION__: string
|
|
857
899
|
|
|
@@ -882,19 +924,19 @@ declare global {
|
|
|
882
924
|
'natvie-version'?: string
|
|
883
925
|
'react-sdk-version'?: string
|
|
884
926
|
'core-sdk-version'?: string
|
|
927
|
+
physicalMetrics?: PhysicalMetricsValueShape
|
|
885
928
|
}
|
|
886
929
|
|
|
887
|
-
|
|
888
|
-
|
|
930
|
+
xrInnerDepth: number
|
|
931
|
+
xrOuterDepth: number
|
|
889
932
|
}
|
|
890
933
|
|
|
891
934
|
interface HTMLElement {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
getBoundingClientCube: () => CubeInfo | undefined
|
|
935
|
+
xrOffsetBack: number
|
|
936
|
+
xrClientDepth: number
|
|
895
937
|
}
|
|
896
938
|
}
|
|
897
939
|
|
|
898
940
|
declare const isSSREnv: () => boolean;
|
|
899
941
|
|
|
900
|
-
export { Attachment, type AttachmentEntityOptions, type AttachmentEntityUpdateOptions, 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 };
|