xrblocks 0.5.1 → 0.7.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/README.md CHANGED
@@ -74,8 +74,8 @@ code below:
74
74
  <script type="importmap">
75
75
  {
76
76
  "imports": {
77
- "three": "https://cdn.jsdelivr.net/npm/three@0.181.0/build/three.module.js",
78
- "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.181.0/examples/jsm/",
77
+ "three": "https://cdn.jsdelivr.net/npm/three@0.182.0/build/three.module.js",
78
+ "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.182.0/examples/jsm/",
79
79
  "xrblocks": "https://cdn.jsdelivr.net/gh/google/xrblocks@build/xrblocks.js",
80
80
  "xrblocks/addons/": "https://cdn.jsdelivr.net/gh/google/xrblocks@build/addons/"
81
81
  }
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
@@ -12,13 +12,29 @@ export declare const aspectRatios: {
12
12
  *
13
13
  * @param rgbUv - The RGB UV coordinate, e.g., \{ u: 0.5, v: 0.5 \}.
14
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.
17
+ */
18
+ export declare function transformRgbToRenderCameraClip(rgbUv: {
19
+ u: number;
20
+ v: number;
21
+ }, xrDeviceCamera?: XRDeviceCamera): THREE.Vector2 | null;
22
+ /**
23
+ * Maps a UV coordinate from a RGB space to a destination depth space,
24
+ * applying Brown-Conrady distortion and affine transformations based on
25
+ * aspect ratios. If the simulator camera is used, no transformation is applied.
26
+ *
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.
30
+ * @param xrDeviceCamera - The device camera instance.
15
31
  * @returns The transformed UV coordinate in the depth image space, or null if
16
32
  * inputs are invalid.
17
33
  */
18
34
  export declare function transformRgbToDepthUv(rgbUv: {
19
35
  u: number;
20
36
  v: number;
21
- }, xrDeviceCamera?: XRDeviceCamera): {
37
+ }, renderCameraWorldFromClip: THREE.Matrix4, depthCameraClipFromWorld: THREE.Matrix4, xrDeviceCamera?: XRDeviceCamera): {
22
38
  u: number;
23
39
  v: number;
24
40
  } | null;
@@ -30,9 +46,9 @@ export declare function transformRgbToDepthUv(rgbUv: {
30
46
  *
31
47
  * @param rgbUv - The RGB UV coordinate, e.g., \{ u: 0.5, v: 0.5 \}.
32
48
  * @param depthArray - Array containing depth data.
33
- * @param viewProjectionMatrix - XRView object with corresponding
49
+ * @param projectionMatrix - XRView object with corresponding
34
50
  * projection matrix.
35
- * @param matrixWorld - Matrix for view-to-world translation.
51
+ * @param matrixWorld - Rendering camera's model matrix.
36
52
  * @param xrDeviceCamera - The device camera instance.
37
53
  * @param xrDepth - The SDK's Depth module.
38
54
  * @returns Vertex at (u, v) in world space.
@@ -40,7 +56,7 @@ export declare function transformRgbToDepthUv(rgbUv: {
40
56
  export declare function transformRgbUvToWorld(rgbUv: {
41
57
  u: number;
42
58
  v: number;
43
- }, 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;
44
60
  /**
45
61
  * Asynchronously crops a base64 encoded image using a THREE.Box2 bounding box.
46
62
  * This function creates an in-memory image, draws a specified portion of it to
@@ -14,6 +14,9 @@ export declare class ScriptsManager {
14
14
  callKeyUpBound: (event: KeyEvent) => void;
15
15
  /** The set of scripts currently being initialized. */
16
16
  private initializingScripts;
17
+ private seenScripts;
18
+ private syncPromises;
19
+ private checkScriptBound;
17
20
  constructor(initScriptFunction: (script: Script) => Promise<void>);
18
21
  /**
19
22
  * Initializes a script and adds it to the set of scripts which will receive
@@ -29,13 +32,17 @@ export declare class ScriptsManager {
29
32
  * @param script - The script to uninitialize.
30
33
  */
31
34
  uninitScript(script: Script): void;
35
+ /**
36
+ * Helper for scene traversal to avoid closure allocation.
37
+ */
38
+ private checkScript;
32
39
  /**
33
40
  * Finds all scripts in the scene and initializes them or uninitailizes them.
34
41
  * Returns a promise which resolves when all new scripts are finished
35
42
  * initalizing.
36
43
  * @param scene - The main scene which is used to find scripts.
37
44
  */
38
- syncScriptsWithScene(scene: THREE.Scene): Promise<void>;
45
+ syncScriptsWithScene(scene: THREE.Scene): Promise<PromiseSettledResult<void>[]>;
39
46
  callSelectStart(event: SelectEvent): void;
40
47
  callSelectEnd(event: SelectEvent): void;
41
48
  callSelect(event: SelectEvent): void;
@@ -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[];
@@ -20,11 +19,14 @@ export declare class Depth {
20
19
  options: DepthOptions;
21
20
  width: number;
22
21
  height: number;
23
- rawValueToMeters: number;
22
+ get rawValueToMeters(): number;
24
23
  occludableShaders: Set<Shader>;
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;
@@ -2,14 +2,14 @@ import * as THREE from 'three';
2
2
  import { DepthOptions } from './DepthOptions';
3
3
  export declare class DepthTextures {
4
4
  private options;
5
- private uint16Arrays;
5
+ private float32Arrays;
6
6
  private uint8Arrays;
7
7
  private dataTextures;
8
8
  private nativeTextures;
9
9
  depthData: XRCPUDepthInformation[];
10
10
  constructor(options: DepthOptions);
11
11
  private createDataDepthTextures;
12
- updateData(depthData: XRCPUDepthInformation, view_id: number): void;
13
- updateNativeTexture(depthData: XRWebGLDepthInformation, renderer: THREE.WebGLRenderer, view_id: number): void;
14
- get(view_id: number): THREE.DataTexture | THREE.ExternalTexture;
12
+ updateData(depthData: XRCPUDepthInformation, viewId: number): void;
13
+ updateNativeTexture(depthData: XRWebGLDepthInformation, renderer: THREE.WebGLRenderer, viewId: number): void;
14
+ get(viewId: number): THREE.DataTexture | THREE.ExternalTexture;
15
15
  }
@@ -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
  }