xrblocks 0.4.0 → 0.5.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.
@@ -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
  };
@@ -5,24 +5,6 @@ export declare const aspectRatios: {
5
5
  depth: number;
6
6
  RGB: number;
7
7
  };
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.
11
- */
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
- };
26
8
  /**
27
9
  * Maps a UV coordinate from a RGB space to a destination depth space,
28
10
  * applying Brown-Conrady distortion and affine transformations based on
@@ -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
  /**
@@ -21,6 +21,7 @@ import { XREffects } from './components/XREffects';
21
21
  import { XRTransition } from './components/XRTransition';
22
22
  import { Options } from './Options';
23
23
  import { User } from './User';
24
+ import { PermissionsManager } from './components/PermissionsManager';
24
25
  /**
25
26
  * Core is the central engine of the XR Blocks framework, acting as a
26
27
  * singleton manager for all XR subsystems. Its primary goal is to abstract
@@ -84,6 +85,7 @@ export declare class Core {
84
85
  scriptsManager: ScriptsManager;
85
86
  renderSceneOverride?: (renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera) => void;
86
87
  webXRSessionManager?: WebXRSessionManager;
88
+ permissionsManager: PermissionsManager;
87
89
  /**
88
90
  * Core is a singleton manager that manages all XR "blocks".
89
91
  * It initializes core components and abstractions like the scene, camera,
@@ -108,6 +108,14 @@ export declare class Options {
108
108
  showEnterSimulatorButton: boolean;
109
109
  alwaysAutostartSimulator: boolean;
110
110
  };
111
+ /**
112
+ * Which permissions to request before entering the XR session.
113
+ */
114
+ permissions: {
115
+ geolocation: boolean;
116
+ camera: boolean;
117
+ microphone: boolean;
118
+ };
111
119
  /**
112
120
  * Constructs the Options object by merging default values with provided
113
121
  * custom options.
@@ -161,11 +169,6 @@ export declare class Options {
161
169
  * @returns The instance for chaining.
162
170
  */
163
171
  enableHandRays(): this;
164
- /**
165
- * Enables the Gemini Live feature.
166
- * @returns The instance for chaining.
167
- */
168
- enableGeminiLive(): this;
169
172
  /**
170
173
  * Enables a standard set of AI features, including Gemini Live.
171
174
  * @returns The instance for chaining.
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Interface representing the result of a permission request.
3
+ */
4
+ export interface PermissionResult {
5
+ granted: boolean;
6
+ status: PermissionState | 'unknown' | 'error';
7
+ error?: string;
8
+ }
9
+ /**
10
+ * A utility class to manage and request browser permissions for
11
+ * Location, Camera, and Microphone.
12
+ */
13
+ export declare class PermissionsManager {
14
+ /**
15
+ * Requests permission to access the user's geolocation.
16
+ * Note: This actually attempts to fetch the position to trigger the prompt.
17
+ */
18
+ requestLocationPermission(): Promise<PermissionResult>;
19
+ /**
20
+ * Requests permission to access the microphone.
21
+ * Opens a stream to trigger the prompt, then immediately closes it.
22
+ */
23
+ requestMicrophonePermission(): Promise<PermissionResult>;
24
+ /**
25
+ * Requests permission to access the camera.
26
+ * Opens a stream to trigger the prompt, then immediately closes it.
27
+ */
28
+ requestCameraPermission(): Promise<PermissionResult>;
29
+ /**
30
+ * Requests permission for both camera and microphone simultaneously.
31
+ */
32
+ requestAVPermission(): Promise<PermissionResult>;
33
+ /**
34
+ * Internal helper to handle getUserMedia requests.
35
+ * Crucially, this stops the tracks immediately after permission is granted
36
+ * so the hardware doesn't remain active.
37
+ */
38
+ private requestMediaPermission;
39
+ /**
40
+ * Requests multiple permissions sequentially.
41
+ * Returns a single result: granted is true only if ALL requested permissions are granted.
42
+ */
43
+ checkAndRequestPermissions({ geolocation, camera, microphone, }: {
44
+ geolocation?: boolean;
45
+ camera?: boolean;
46
+ microphone?: boolean;
47
+ }): Promise<PermissionResult>;
48
+ /**
49
+ * Checks the current status of a permission without triggering a prompt.
50
+ * Useful for UI state (e.g., disabling buttons if already denied).
51
+ * * @param permissionName - 'geolocation', 'camera', or 'microphone'
52
+ */
53
+ checkPermissionStatus(permissionName: 'geolocation' | 'camera' | 'microphone'): Promise<PermissionState | 'unknown'>;
54
+ }
@@ -1,15 +1,22 @@
1
+ import { PermissionsManager } from './PermissionsManager';
1
2
  import { WebXRSessionManager } from './WebXRSessionManager';
2
3
  export declare class XRButton {
3
4
  private sessionManager;
5
+ private permissionsManager;
4
6
  private startText;
5
7
  private endText;
6
8
  private invalidText;
7
9
  private startSimulatorText;
8
10
  startSimulator: () => void;
11
+ private permissions;
9
12
  domElement: HTMLDivElement;
10
13
  simulatorButtonElement: HTMLButtonElement;
11
14
  xrButtonElement: HTMLButtonElement;
12
- constructor(sessionManager: WebXRSessionManager, startText?: string, endText?: string, invalidText?: string, startSimulatorText?: string, showEnterSimulatorButton?: boolean, startSimulator?: () => void);
15
+ constructor(sessionManager: WebXRSessionManager, permissionsManager: PermissionsManager, startText?: string, endText?: string, invalidText?: string, startSimulatorText?: string, showEnterSimulatorButton?: boolean, startSimulator?: () => void, permissions?: {
16
+ geolocation: boolean;
17
+ camera: boolean;
18
+ microphone: boolean;
19
+ });
13
20
  private createSimulatorButton;
14
21
  private createXRButtonElement;
15
22
  private onSessionReady;
@@ -28,6 +28,8 @@ export declare class DepthOptions {
28
28
  enabled: boolean;
29
29
  };
30
30
  useFloat32: boolean;
31
+ depthTypeRequest: XRDepthType[];
32
+ matchDepthView: boolean;
31
33
  constructor(options?: DeepReadonly<DeepPartial<DepthOptions>>);
32
34
  }
33
35
  export declare const xrDepthMeshOptions: {
@@ -58,6 +60,8 @@ export declare const xrDepthMeshOptions: {
58
60
  readonly enabled: boolean;
59
61
  };
60
62
  readonly useFloat32: boolean;
63
+ readonly depthTypeRequest: readonly XRDepthType[];
64
+ readonly matchDepthView: boolean;
61
65
  };
62
66
  export declare const xrDepthMeshVisualizationOptions: {
63
67
  readonly debugging: boolean;
@@ -87,6 +91,8 @@ export declare const xrDepthMeshVisualizationOptions: {
87
91
  readonly enabled: boolean;
88
92
  };
89
93
  readonly useFloat32: boolean;
94
+ readonly depthTypeRequest: readonly XRDepthType[];
95
+ readonly matchDepthView: boolean;
90
96
  };
91
97
  export declare const xrDepthMeshPhysicsOptions: {
92
98
  readonly debugging: boolean;
@@ -116,4 +122,6 @@ export declare const xrDepthMeshPhysicsOptions: {
116
122
  readonly enabled: boolean;
117
123
  };
118
124
  readonly useFloat32: boolean;
125
+ readonly depthTypeRequest: readonly XRDepthType[];
126
+ readonly matchDepthView: boolean;
119
127
  };
@@ -42,6 +42,8 @@ export declare class Simulator extends Script {
42
42
  effects?: XREffects;
43
43
  virtualSceneRenderTarget?: THREE.WebGLRenderTarget;
44
44
  virtualSceneFullScreenQuad?: FullScreenQuad;
45
+ backgroundVideoQuad?: FullScreenQuad;
46
+ videoElement?: HTMLVideoElement;
45
47
  camera?: SimulatorCamera;
46
48
  options: SimulatorOptions;
47
49
  renderer: THREE.WebGLRenderer;
@@ -23,6 +23,7 @@ export declare class SimulatorOptions {
23
23
  z: number;
24
24
  };
25
25
  scenePath: string;
26
+ videoPath?: string;
26
27
  initialScenePosition: {
27
28
  x: number;
28
29
  y: number;
@@ -43,7 +44,10 @@ export declare class SimulatorOptions {
43
44
  enabled: boolean;
44
45
  element: string;
45
46
  };
46
- geminilive: boolean;
47
+ geminiLivePanel: {
48
+ enabled: boolean;
49
+ element: string;
50
+ };
47
51
  stereo: {
48
52
  enabled: boolean;
49
53
  };
@@ -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).