xrblocks 0.5.0 → 0.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/build/ai/AI.d.ts CHANGED
@@ -76,7 +76,7 @@ export declare class AI extends Script {
76
76
  * In XR mode, show a 3D UI to instruct users to get an API key.
77
77
  */
78
78
  triggerKeyPopup(): void;
79
- generate(prompt: string | string[], type?: 'image', systemInstruction?: string, model?: string): Promise<string | void | undefined>;
79
+ generate(prompt: string | string[], type?: 'image', systemInstruction?: string, model?: undefined): Promise<string | void | undefined>;
80
80
  /**
81
81
  * Create a sample keys.json file structure for reference
82
82
  * @returns Sample keys.json structure
@@ -1,15 +1,46 @@
1
1
  import { DeepPartial, DeepReadonly } from '../utils/Types';
2
+ /**
3
+ * Parameters for RGB to depth UV mapping given different aspect ratios.
4
+ * These parameters define the distortion model and affine transformations
5
+ * required to align the RGB camera feed with the depth map.
6
+ */
7
+ export interface RgbToDepthParams {
8
+ scale: number;
9
+ scaleX: number;
10
+ scaleY: number;
11
+ translateU: number;
12
+ translateV: number;
13
+ k1: number;
14
+ k2: number;
15
+ k3: number;
16
+ p1: number;
17
+ p2: number;
18
+ xc: number;
19
+ yc: number;
20
+ }
21
+ /**
22
+ * Default parameters for rgb to depth projection.
23
+ * For RGB and depth, 4:3 and 1:1, respectively.
24
+ */
25
+ export declare const DEFAULT_RGB_TO_DEPTH_PARAMS: RgbToDepthParams;
26
+ /**
27
+ * Configuration options for the device camera.
28
+ */
2
29
  export declare class DeviceCameraOptions {
3
30
  enabled: boolean;
4
31
  /**
5
32
  * Constraints for `getUserMedia`. This will guide the initial camera
6
- * selection. *
33
+ * selection.
7
34
  */
8
35
  videoConstraints?: MediaTrackConstraints;
9
36
  /**
10
37
  * Hint for performance optimization on frequent captures.
11
38
  */
12
39
  willCaptureFrequently: boolean;
40
+ /**
41
+ * Parameters for RGB to depth UV mapping given different aspect ratios.
42
+ */
43
+ rgbToDepthParams: RgbToDepthParams;
13
44
  constructor(options?: DeepReadonly<DeepPartial<DeviceCameraOptions>>);
14
45
  }
15
46
  export declare const xrDeviceCameraEnvironmentOptions: {
@@ -167,6 +198,20 @@ export declare const xrDeviceCameraEnvironmentOptions: {
167
198
  } | undefined;
168
199
  } | undefined;
169
200
  readonly willCaptureFrequently: boolean;
201
+ readonly rgbToDepthParams: {
202
+ readonly scale: number;
203
+ readonly scaleX: number;
204
+ readonly scaleY: number;
205
+ readonly translateU: number;
206
+ readonly translateV: number;
207
+ readonly k1: number;
208
+ readonly k2: number;
209
+ readonly k3: number;
210
+ readonly p1: number;
211
+ readonly p2: number;
212
+ readonly xc: number;
213
+ readonly yc: number;
214
+ };
170
215
  };
171
216
  export declare const xrDeviceCameraUserOptions: {
172
217
  readonly enabled: boolean;
@@ -323,6 +368,20 @@ export declare const xrDeviceCameraUserOptions: {
323
368
  } | undefined;
324
369
  } | undefined;
325
370
  readonly willCaptureFrequently: boolean;
371
+ readonly rgbToDepthParams: {
372
+ readonly scale: number;
373
+ readonly scaleX: number;
374
+ readonly scaleY: number;
375
+ readonly translateU: number;
376
+ readonly translateV: number;
377
+ readonly k1: number;
378
+ readonly k2: number;
379
+ readonly k3: number;
380
+ readonly p1: number;
381
+ readonly p2: number;
382
+ readonly xc: number;
383
+ readonly yc: number;
384
+ };
326
385
  };
327
386
  export declare const xrDeviceCameraEnvironmentContinuousOptions: {
328
387
  readonly enabled: boolean;
@@ -479,6 +538,20 @@ export declare const xrDeviceCameraEnvironmentContinuousOptions: {
479
538
  } | undefined;
480
539
  } | undefined;
481
540
  readonly willCaptureFrequently: boolean;
541
+ readonly rgbToDepthParams: {
542
+ readonly scale: number;
543
+ readonly scaleX: number;
544
+ readonly scaleY: number;
545
+ readonly translateU: number;
546
+ readonly translateV: number;
547
+ readonly k1: number;
548
+ readonly k2: number;
549
+ readonly k3: number;
550
+ readonly p1: number;
551
+ readonly p2: number;
552
+ readonly xc: number;
553
+ readonly yc: number;
554
+ };
482
555
  };
483
556
  export declare const xrDeviceCameraUserContinuousOptions: {
484
557
  readonly enabled: boolean;
@@ -635,4 +708,18 @@ export declare const xrDeviceCameraUserContinuousOptions: {
635
708
  } | undefined;
636
709
  } | undefined;
637
710
  readonly willCaptureFrequently: boolean;
711
+ readonly rgbToDepthParams: {
712
+ readonly scale: number;
713
+ readonly scaleX: number;
714
+ readonly scaleY: number;
715
+ readonly translateU: number;
716
+ readonly translateV: number;
717
+ readonly k1: number;
718
+ readonly k2: number;
719
+ readonly k3: number;
720
+ readonly p1: number;
721
+ readonly p2: number;
722
+ readonly xc: number;
723
+ readonly yc: number;
724
+ };
638
725
  };
@@ -6,29 +6,27 @@ export declare const aspectRatios: {
6
6
  RGB: number;
7
7
  };
8
8
  /**
9
- * Parameters for RGB to depth UV mapping (manually calibrated for aspect
10
- * ratios. For RGB and depth, 4:3 and 1:1, respectively.
9
+ * Maps a UV coordinate from a RGB space to a destination depth space,
10
+ * applying Brown-Conrady distortion and affine transformations based on
11
+ * aspect ratios. If the simulator camera is used, no transformation is applied.
12
+ *
13
+ * @param rgbUv - The RGB UV coordinate, e.g., \{ u: 0.5, v: 0.5 \}.
14
+ * @param xrDeviceCamera - The device camera instance.
15
+ * @returns The transformed UV coordinate in the render camera clip space, or null if
16
+ * inputs are invalid.
11
17
  */
12
- export declare const rgbToDepthParams: {
13
- scale: number;
14
- scaleX: number;
15
- scaleY: number;
16
- translateU: number;
17
- translateV: number;
18
- k1: number;
19
- k2: number;
20
- k3: number;
21
- p1: number;
22
- p2: number;
23
- xc: number;
24
- yc: number;
25
- };
18
+ export declare function transformRgbToRenderCameraClip(rgbUv: {
19
+ u: number;
20
+ v: number;
21
+ }, xrDeviceCamera?: XRDeviceCamera): THREE.Vector2 | null;
26
22
  /**
27
23
  * Maps a UV coordinate from a RGB space to a destination depth space,
28
24
  * applying Brown-Conrady distortion and affine transformations based on
29
25
  * aspect ratios. If the simulator camera is used, no transformation is applied.
30
26
  *
31
27
  * @param rgbUv - The RGB UV coordinate, e.g., \{ u: 0.5, v: 0.5 \}.
28
+ * @param renderCameraWorldFromClip - Render camera world from clip, i.e. inverse of the View Projection matrix.
29
+ * @param depthCameraClipFromWorld - Depth camera clip from world, i.e.
32
30
  * @param xrDeviceCamera - The device camera instance.
33
31
  * @returns The transformed UV coordinate in the depth image space, or null if
34
32
  * inputs are invalid.
@@ -36,7 +34,7 @@ export declare const rgbToDepthParams: {
36
34
  export declare function transformRgbToDepthUv(rgbUv: {
37
35
  u: number;
38
36
  v: number;
39
- }, xrDeviceCamera?: XRDeviceCamera): {
37
+ }, renderCameraWorldFromClip: THREE.Matrix4, depthCameraClipFromWorld: THREE.Matrix4, xrDeviceCamera?: XRDeviceCamera): {
40
38
  u: number;
41
39
  v: number;
42
40
  } | null;
@@ -48,9 +46,9 @@ export declare function transformRgbToDepthUv(rgbUv: {
48
46
  *
49
47
  * @param rgbUv - The RGB UV coordinate, e.g., \{ u: 0.5, v: 0.5 \}.
50
48
  * @param depthArray - Array containing depth data.
51
- * @param viewProjectionMatrix - XRView object with corresponding
49
+ * @param projectionMatrix - XRView object with corresponding
52
50
  * projection matrix.
53
- * @param matrixWorld - Matrix for view-to-world translation.
51
+ * @param matrixWorld - Rendering camera's model matrix.
54
52
  * @param xrDeviceCamera - The device camera instance.
55
53
  * @param xrDepth - The SDK's Depth module.
56
54
  * @returns Vertex at (u, v) in world space.
@@ -58,7 +56,7 @@ export declare function transformRgbToDepthUv(rgbUv: {
58
56
  export declare function transformRgbUvToWorld(rgbUv: {
59
57
  u: number;
60
58
  v: number;
61
- }, depthArray: number[] | Uint16Array | Float32Array, viewProjectionMatrix: THREE.Matrix4, matrixWorld: THREE.Matrix4, xrDeviceCamera?: XRDeviceCamera, xrDepth?: Depth | undefined): THREE.Vector3 | null;
59
+ }, depthArray: number[] | Uint16Array | Float32Array, projectionMatrix: THREE.Matrix4, matrixWorld: THREE.Matrix4, xrDeviceCamera?: XRDeviceCamera, xrDepth?: Depth | undefined): THREE.Vector3;
62
60
  /**
63
61
  * Asynchronously crops a base64 encoded image using a THREE.Box2 bounding box.
64
62
  * This function creates an in-memory image, draws a specified portion of it to
@@ -1,7 +1,7 @@
1
1
  import { SimulatorCamera } from '../simulator/SimulatorCamera';
2
2
  import { SimulatorMediaDeviceInfo } from '../simulator/SimulatorMediaDeviceInfo';
3
3
  import { VideoStream, VideoStreamDetails } from '../video/VideoStream';
4
- import { DeviceCameraOptions } from './CameraOptions';
4
+ import { DeviceCameraOptions, RgbToDepthParams } from './CameraOptions';
5
5
  export type MediaOrSimulatorMediaDeviceInfo = MediaDeviceInfo | SimulatorMediaDeviceInfo;
6
6
  type XRDeviceCameraDetails = VideoStreamDetails & {
7
7
  width?: number;
@@ -15,6 +15,7 @@ type XRDeviceCameraDetails = VideoStreamDetails & {
15
15
  */
16
16
  export declare class XRDeviceCamera extends VideoStream<XRDeviceCameraDetails> {
17
17
  simulatorCamera?: SimulatorCamera;
18
+ rgbToDepthParams: RgbToDepthParams;
18
19
  protected videoConstraints_: MediaTrackConstraints;
19
20
  private isInitializing_;
20
21
  private availableDevices_;
@@ -23,7 +24,7 @@ export declare class XRDeviceCamera extends VideoStream<XRDeviceCameraDetails> {
23
24
  /**
24
25
  * @param options - The configuration options.
25
26
  */
26
- constructor({ videoConstraints, willCaptureFrequently, }?: Partial<DeviceCameraOptions>);
27
+ constructor({ videoConstraints, willCaptureFrequently, rgbToDepthParams, }?: Partial<DeviceCameraOptions>);
27
28
  /**
28
29
  * Retrieves the list of available video input devices.
29
30
  * @returns A promise that resolves with an
@@ -43,7 +44,7 @@ export declare class XRDeviceCamera extends VideoStream<XRDeviceCameraDetails> {
43
44
  /**
44
45
  * Sets the active camera by its device ID. Removes potentially conflicting
45
46
  * constraints such as facingMode.
46
- * @param deviceId - Device id.
47
+ * @param deviceId - Device ID
47
48
  */
48
49
  setDeviceId(deviceId: string): Promise<void>;
49
50
  /**
@@ -10,7 +10,6 @@ export declare class Depth {
10
10
  private renderer;
11
11
  private scene;
12
12
  private projectionMatrixInverse;
13
- private xrRefSpace?;
14
13
  view: XRView[];
15
14
  cpuDepthData: XRCPUDepthInformation[];
16
15
  gpuDepthData: XRWebGLDepthInformation[];
@@ -25,6 +24,9 @@ export declare class Depth {
25
24
  private occlusionPass?;
26
25
  private depthClientsInitialized;
27
26
  private depthClients;
27
+ depthProjectionMatrices: THREE.Matrix4[];
28
+ depthViewMatrices: THREE.Matrix4[];
29
+ depthViewProjectionMatrices: THREE.Matrix4[];
28
30
  /**
29
31
  * Depth is a lightweight manager based on three.js to simply prototyping
30
32
  * with Depth in WebXR.
@@ -54,9 +56,10 @@ export declare class Depth {
54
56
  * @returns Vertex at (u, v)
55
57
  */
56
58
  getVertex(u: number, v: number): THREE.Vector3 | null;
57
- updateCPUDepthData(depthData: XRCPUDepthInformation, view_id?: number): void;
58
- updateGPUDepthData(depthData: XRWebGLDepthInformation, view_id?: number): void;
59
- getTexture(view_id: number): THREE.DataTexture | THREE.ExternalTexture | undefined;
59
+ private updateDepthMatrices;
60
+ updateCPUDepthData(depthData: XRCPUDepthInformation, viewId?: number): void;
61
+ updateGPUDepthData(depthData: XRWebGLDepthInformation, viewId?: number): void;
62
+ getTexture(viewId: number): THREE.DataTexture | THREE.ExternalTexture | undefined;
60
63
  update(frame?: XRFrame): void;
61
64
  updateLocalDepth(frame: XRFrame): void;
62
65
  renderOcclusionPass(): void;
@@ -4,15 +4,25 @@ import { SimulatorDepthMaterial } from './SimulatorDepthMaterial';
4
4
  import { SimulatorScene } from './SimulatorScene';
5
5
  export declare class SimulatorDepth {
6
6
  private simulatorScene;
7
- renderer: THREE.WebGLRenderer;
8
- camera: THREE.Camera;
9
- depth: Depth;
7
+ private renderer;
8
+ private camera;
9
+ private depth;
10
10
  depthWidth: number;
11
11
  depthHeight: number;
12
12
  depthBufferSlice: Float32Array<ArrayBuffer>;
13
13
  depthMaterial: SimulatorDepthMaterial;
14
14
  depthRenderTarget: THREE.WebGLRenderTarget;
15
15
  depthBuffer: Float32Array;
16
+ depthCamera: THREE.Camera;
17
+ /**
18
+ * If true, copies the rendering camera's projection matrix each frame.
19
+ */
20
+ autoUpdateDepthCameraProjection: boolean;
21
+ /**
22
+ * If true, copies the rendering camera's transform each frame.
23
+ */
24
+ autoUpdateDepthCameraTransform: boolean;
25
+ private projectionMatrixArray;
16
26
  constructor(simulatorScene: SimulatorScene);
17
27
  /**
18
28
  * Initialize Simulator Depth.
@@ -20,6 +30,7 @@ export declare class SimulatorDepth {
20
30
  init(renderer: THREE.WebGLRenderer, camera: THREE.Camera, depth: Depth): void;
21
31
  createRenderTarget(): void;
22
32
  update(): void;
23
- renderDepthScene(): void;
24
- updateDepth(): void;
33
+ private updateDepthCamera;
34
+ private renderDepthScene;
35
+ private updateDepth;
25
36
  }
@@ -9,6 +9,8 @@ export type TextButtonOptions = TextViewOptions & {
9
9
  maxWidth?: number;
10
10
  radius?: number;
11
11
  boxSize?: number;
12
+ hoverColor?: string | number;
13
+ selectedFontColor?: string | number;
12
14
  };
13
15
  export declare class TextButton extends TextView {
14
16
  /** Default description of this view in Three.js DevTools. */
@@ -140,7 +140,7 @@ export declare class TextView extends View<TextViewEventMap> {
140
140
  */
141
141
  protected _initializeText(): void;
142
142
  protected syncTextObj(): void;
143
- protected setTextColor(color: number): void;
143
+ protected setTextColor(color: number | string): void;
144
144
  /**
145
145
  * Disposes of resources used by the TextView, such as event listeners.
146
146
  */
@@ -61,7 +61,7 @@ export declare class ObjectDetector extends Script {
61
61
  * Retrieves a list of currently detected objects.
62
62
  *
63
63
  * @param label - The semantic label to filter by (e.g., 'chair'). If null,
64
- * all objects are returned.
64
+ * all objects are returned.
65
65
  * @returns An array of `Object` instances.
66
66
  */
67
67
  get(label?: null): DetectedObject[];
@@ -79,10 +79,15 @@ export declare class ObjectDetector extends Script {
79
79
  * Draws the detected bounding boxes on the input image and triggers a
80
80
  * download for debugging.
81
81
  * @param base64Image - The base64 encoded input image.
82
- * @param detections - The array of detected objects from the
83
- * AI response.
82
+ * @param detections - The array of detected objects from the AI response.
84
83
  */
85
84
  private _visualizeBoundingBoxesOnImage;
85
+ /**
86
+ * Generates a visual representation of the depth map, normalized to 0-1 range,
87
+ * and triggers a download for debugging.
88
+ * @param depthArray - The raw depth data array.
89
+ */
90
+ private _visualizeDepthMap;
86
91
  /**
87
92
  * Creates a simple debug visualization for an object based on its position
88
93
  * (center of its 2D detection bounding box).