mujoco-react 10.4.0 → 10.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/README.md +73 -136
- package/dist/{chunk-FBXXXPLQ.js → chunk-EN55TTGH.js} +157 -16
- package/dist/chunk-EN55TTGH.js.map +1 -0
- package/dist/index.d.ts +179 -48
- package/dist/index.js +487 -20
- package/dist/index.js.map +1 -1
- package/dist/onnx.d.ts +65 -0
- package/dist/onnx.js +58 -0
- package/dist/onnx.js.map +1 -0
- package/dist/spark.d.ts +1 -1
- package/dist/spark.js +1 -1
- package/dist/{types-CdFZCYmy.d.ts → types-Dvtm4I0o.d.ts} +155 -4
- package/package.json +14 -3
- package/src/components/CameraView.tsx +245 -0
- package/src/core/GenericIK.ts +22 -3
- package/src/core/MujocoSimProvider.tsx +37 -1
- package/src/core/SceneLoader.ts +3 -2
- package/src/hooks/useCameraStream.ts +115 -0
- package/src/hooks/useControlGroup.ts +0 -0
- package/src/hooks/useIkController.ts +36 -5
- package/src/hooks/usePolicyCameraTensors.ts +215 -0
- package/src/index.ts +44 -0
- package/src/onnx.ts +126 -0
- package/src/policyImageTensors.ts +150 -0
- package/src/rendering/cameraFrameCapture.ts +112 -15
- package/src/types.ts +50 -3
- package/dist/chunk-FBXXXPLQ.js.map +0 -1
package/dist/onnx.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as ort from 'onnxruntime-web';
|
|
2
|
+
import { bq as PolicyActionChunk } from './types-Dvtm4I0o.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
import '@react-three/fiber';
|
|
5
|
+
import 'three';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @license
|
|
9
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
*
|
|
11
|
+
* Optional ONNX Runtime Web helpers for browser policy demos.
|
|
12
|
+
*
|
|
13
|
+
* This entry point is exported as `mujoco-react/onnx` so the main package does
|
|
14
|
+
* not import or bundle `onnxruntime-web`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
type OnnxPolicyDtype = 'float32' | 'float64' | 'int32' | 'int64' | 'bool' | string;
|
|
18
|
+
interface OnnxPolicyTensorSpec {
|
|
19
|
+
name: string;
|
|
20
|
+
shape: number[];
|
|
21
|
+
dtype: OnnxPolicyDtype;
|
|
22
|
+
}
|
|
23
|
+
interface OnnxPolicyImageSpec {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
channels?: number;
|
|
27
|
+
layout?: 'CHW' | 'HWC' | string;
|
|
28
|
+
range?: readonly [number, number];
|
|
29
|
+
}
|
|
30
|
+
interface OnnxPolicyManifest {
|
|
31
|
+
model: string;
|
|
32
|
+
variants?: Record<string, string>;
|
|
33
|
+
fps?: number;
|
|
34
|
+
joints?: string[];
|
|
35
|
+
cameras?: string[];
|
|
36
|
+
image?: OnnxPolicyImageSpec;
|
|
37
|
+
chunk_size?: number;
|
|
38
|
+
n_action_steps?: number;
|
|
39
|
+
inputs: OnnxPolicyTensorSpec[];
|
|
40
|
+
output: OnnxPolicyTensorSpec & {
|
|
41
|
+
units?: string;
|
|
42
|
+
};
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
interface LoadOnnxPolicyManifestResult<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest> {
|
|
46
|
+
manifest: TManifest;
|
|
47
|
+
manifestUrl: URL;
|
|
48
|
+
modelUrl: URL;
|
|
49
|
+
}
|
|
50
|
+
interface CreateOnnxPolicySessionOptions<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest> {
|
|
51
|
+
manifestUrl: string | URL;
|
|
52
|
+
variant?: string;
|
|
53
|
+
runtime: typeof ort;
|
|
54
|
+
sessionOptions?: ort.InferenceSession.SessionOptions;
|
|
55
|
+
fetcher?: typeof fetch;
|
|
56
|
+
readManifest?: (response: Response) => Promise<TManifest>;
|
|
57
|
+
}
|
|
58
|
+
interface OnnxPolicySession<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest> extends LoadOnnxPolicyManifestResult<TManifest> {
|
|
59
|
+
session: ort.InferenceSession;
|
|
60
|
+
}
|
|
61
|
+
declare function loadOnnxPolicyManifest<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest>(manifestUrlInput: string | URL, options?: Pick<CreateOnnxPolicySessionOptions<TManifest>, 'variant' | 'fetcher' | 'readManifest'>): Promise<LoadOnnxPolicyManifestResult<TManifest>>;
|
|
62
|
+
declare function createOnnxPolicySession<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest>(options: CreateOnnxPolicySessionOptions<TManifest>): Promise<OnnxPolicySession<TManifest>>;
|
|
63
|
+
declare function onnxTensorToPolicyActionChunk(tensor: ort.Tensor, actionSize?: number, maxActions?: number): PolicyActionChunk;
|
|
64
|
+
|
|
65
|
+
export { type CreateOnnxPolicySessionOptions, type LoadOnnxPolicyManifestResult, type OnnxPolicyDtype, type OnnxPolicyImageSpec, type OnnxPolicyManifest, type OnnxPolicySession, type OnnxPolicyTensorSpec, createOnnxPolicySession, loadOnnxPolicyManifest, onnxTensorToPolicyActionChunk };
|
package/dist/onnx.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/onnx.ts
|
|
2
|
+
function asUrl(value, base = globalThis.location?.href) {
|
|
3
|
+
return value instanceof URL ? value : new URL(value, base);
|
|
4
|
+
}
|
|
5
|
+
function resolveModelPath(manifest, variant) {
|
|
6
|
+
if (variant && manifest.variants?.[variant]) return manifest.variants[variant];
|
|
7
|
+
return manifest.model;
|
|
8
|
+
}
|
|
9
|
+
async function loadOnnxPolicyManifest(manifestUrlInput, options = {}) {
|
|
10
|
+
const fetcher = options.fetcher ?? fetch;
|
|
11
|
+
const manifestUrl = asUrl(manifestUrlInput);
|
|
12
|
+
const response = await fetcher(manifestUrl);
|
|
13
|
+
if (!response.ok) {
|
|
14
|
+
throw new Error(`Unable to load ONNX policy manifest from ${manifestUrl.href} (${response.status}).`);
|
|
15
|
+
}
|
|
16
|
+
const manifest = options.readManifest ? await options.readManifest(response) : await response.json();
|
|
17
|
+
const modelPath = resolveModelPath(manifest, options.variant);
|
|
18
|
+
const modelUrl = asUrl(modelPath, manifestUrl.href);
|
|
19
|
+
return { manifest, manifestUrl, modelUrl };
|
|
20
|
+
}
|
|
21
|
+
async function createOnnxPolicySession(options) {
|
|
22
|
+
const fetcher = options.fetcher ?? fetch;
|
|
23
|
+
const resolved = await loadOnnxPolicyManifest(options.manifestUrl, options);
|
|
24
|
+
const response = await fetcher(resolved.modelUrl);
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw new Error(`Unable to load ONNX policy model from ${resolved.modelUrl.href} (${response.status}).`);
|
|
27
|
+
}
|
|
28
|
+
const modelBytes = await response.arrayBuffer();
|
|
29
|
+
const session = await options.runtime.InferenceSession.create(modelBytes, options.sessionOptions);
|
|
30
|
+
return {
|
|
31
|
+
...resolved,
|
|
32
|
+
session
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function onnxTensorToPolicyActionChunk(tensor, actionSize = tensor.dims.at(-1) ?? 1, maxActions) {
|
|
36
|
+
const rawData = Array.from(tensor.data, (value) => Number(value));
|
|
37
|
+
const actionCount = Math.floor(rawData.length / actionSize);
|
|
38
|
+
const cappedActionCount = maxActions === void 0 ? actionCount : Math.max(0, Math.min(actionCount, Math.floor(maxActions)));
|
|
39
|
+
const actions = [];
|
|
40
|
+
for (let actionIndex = 0; actionIndex < cappedActionCount; actionIndex += 1) {
|
|
41
|
+
const start = actionIndex * actionSize;
|
|
42
|
+
actions.push(rawData.slice(start, start + actionSize));
|
|
43
|
+
}
|
|
44
|
+
return actions;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @license
|
|
48
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
49
|
+
*
|
|
50
|
+
* Optional ONNX Runtime Web helpers for browser policy demos.
|
|
51
|
+
*
|
|
52
|
+
* This entry point is exported as `mujoco-react/onnx` so the main package does
|
|
53
|
+
* not import or bundle `onnxruntime-web`.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
export { createOnnxPolicySession, loadOnnxPolicyManifest, onnxTensorToPolicyActionChunk };
|
|
57
|
+
//# sourceMappingURL=onnx.js.map
|
|
58
|
+
//# sourceMappingURL=onnx.js.map
|
package/dist/onnx.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/onnx.ts"],"names":[],"mappings":"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","file":"onnx.js","sourcesContent":["/**\n * @license\n * SPDX-License-Identifier: Apache-2.0\n *\n * Optional ONNX Runtime Web helpers for browser policy demos.\n *\n * This entry point is exported as `mujoco-react/onnx` so the main package does\n * not import or bundle `onnxruntime-web`.\n */\n\nimport type * as ort from 'onnxruntime-web';\nimport type { PolicyActionChunk } from './types';\n\nexport type OnnxPolicyDtype = 'float32' | 'float64' | 'int32' | 'int64' | 'bool' | string;\n\nexport interface OnnxPolicyTensorSpec {\n name: string;\n shape: number[];\n dtype: OnnxPolicyDtype;\n}\n\nexport interface OnnxPolicyImageSpec {\n width: number;\n height: number;\n channels?: number;\n layout?: 'CHW' | 'HWC' | string;\n range?: readonly [number, number];\n}\n\nexport interface OnnxPolicyManifest {\n model: string;\n variants?: Record<string, string>;\n fps?: number;\n joints?: string[];\n cameras?: string[];\n image?: OnnxPolicyImageSpec;\n chunk_size?: number;\n n_action_steps?: number;\n inputs: OnnxPolicyTensorSpec[];\n output: OnnxPolicyTensorSpec & {\n units?: string;\n };\n [key: string]: unknown;\n}\n\nexport interface LoadOnnxPolicyManifestResult<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest> {\n manifest: TManifest;\n manifestUrl: URL;\n modelUrl: URL;\n}\n\nexport interface CreateOnnxPolicySessionOptions<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest> {\n manifestUrl: string | URL;\n variant?: string;\n runtime: typeof ort;\n sessionOptions?: ort.InferenceSession.SessionOptions;\n fetcher?: typeof fetch;\n readManifest?: (response: Response) => Promise<TManifest>;\n}\n\nexport interface OnnxPolicySession<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest>\n extends LoadOnnxPolicyManifestResult<TManifest> {\n session: ort.InferenceSession;\n}\n\nfunction asUrl(value: string | URL, base = globalThis.location?.href) {\n return value instanceof URL ? value : new URL(value, base);\n}\n\nfunction resolveModelPath(manifest: OnnxPolicyManifest, variant: string | undefined) {\n if (variant && manifest.variants?.[variant]) return manifest.variants[variant];\n return manifest.model;\n}\n\nexport async function loadOnnxPolicyManifest<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest>(\n manifestUrlInput: string | URL,\n options: Pick<CreateOnnxPolicySessionOptions<TManifest>, 'variant' | 'fetcher' | 'readManifest'> = {}\n): Promise<LoadOnnxPolicyManifestResult<TManifest>> {\n const fetcher = options.fetcher ?? fetch;\n const manifestUrl = asUrl(manifestUrlInput);\n const response = await fetcher(manifestUrl);\n if (!response.ok) {\n throw new Error(`Unable to load ONNX policy manifest from ${manifestUrl.href} (${response.status}).`);\n }\n const manifest = options.readManifest\n ? await options.readManifest(response)\n : await response.json() as TManifest;\n const modelPath = resolveModelPath(manifest, options.variant);\n const modelUrl = asUrl(modelPath, manifestUrl.href);\n return { manifest, manifestUrl, modelUrl };\n}\n\nexport async function createOnnxPolicySession<TManifest extends OnnxPolicyManifest = OnnxPolicyManifest>(\n options: CreateOnnxPolicySessionOptions<TManifest>\n): Promise<OnnxPolicySession<TManifest>> {\n const fetcher = options.fetcher ?? fetch;\n const resolved = await loadOnnxPolicyManifest(options.manifestUrl, options);\n const response = await fetcher(resolved.modelUrl);\n if (!response.ok) {\n throw new Error(`Unable to load ONNX policy model from ${resolved.modelUrl.href} (${response.status}).`);\n }\n const modelBytes = await response.arrayBuffer();\n const session = await options.runtime.InferenceSession.create(modelBytes, options.sessionOptions);\n return {\n ...resolved,\n session,\n };\n}\n\nexport function onnxTensorToPolicyActionChunk(\n tensor: ort.Tensor,\n actionSize = tensor.dims.at(-1) ?? 1,\n maxActions?: number\n): PolicyActionChunk {\n const rawData = Array.from(tensor.data as ArrayLike<number>, (value) => Number(value));\n const actionCount = Math.floor(rawData.length / actionSize);\n const cappedActionCount = maxActions === undefined\n ? actionCount\n : Math.max(0, Math.min(actionCount, Math.floor(maxActions)));\n const actions: number[][] = [];\n for (let actionIndex = 0; actionIndex < cappedActionCount; actionIndex += 1) {\n const start = actionIndex * actionSize;\n actions.push(rawData.slice(start, start + actionSize));\n }\n return actions;\n}\n"]}
|
package/dist/spark.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as _sparkjsdev_spark from '@sparkjsdev/spark';
|
|
3
|
-
import { o as SplatEnvironmentProps, r as PairedSplatEnvironmentConfig, S as SceneConfig, u as SplatEnvironmentReadiness, p as VisualScenarioConfig } from './types-
|
|
3
|
+
import { o as SplatEnvironmentProps, r as PairedSplatEnvironmentConfig, S as SceneConfig, u as SplatEnvironmentReadiness, p as VisualScenarioConfig } from './types-Dvtm4I0o.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import '@react-three/fiber';
|
|
6
6
|
import 'three';
|
package/dist/spark.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useSplatSceneConfig, useSplatEnvironment, SplatEnvironment, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY } from './chunk-
|
|
1
|
+
import { useSplatSceneConfig, useSplatEnvironment, SplatEnvironment, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY } from './chunk-EN55TTGH.js';
|
|
2
2
|
import { useThree } from '@react-three/fiber';
|
|
3
3
|
import { useMemo, useState, useEffect, useCallback, useRef } from 'react';
|
|
4
4
|
import * as THREE from 'three';
|
|
@@ -2,6 +2,123 @@ import React__default, { ReactNode } from 'react';
|
|
|
2
2
|
import { CanvasProps, ThreeElements } from '@react-three/fiber';
|
|
3
3
|
import * as THREE from 'three';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
8
|
+
*
|
|
9
|
+
* Helpers for turning browser camera captures into policy image tensors.
|
|
10
|
+
*/
|
|
11
|
+
type PolicyImageTensorLayout = 'CHW' | 'HWC';
|
|
12
|
+
type PolicyImageTensorRange = readonly [number, number];
|
|
13
|
+
/**
|
|
14
|
+
* Row order of a raw pixel buffer. WebGL `readRenderTargetPixels` returns rows
|
|
15
|
+
* bottom-to-top (`'bottom-left'`); `ImageData` is top-to-bottom (`'top-left'`).
|
|
16
|
+
*/
|
|
17
|
+
type PolicyImageTensorSourceOrigin = 'top-left' | 'bottom-left';
|
|
18
|
+
interface PolicyImageTensorOptions {
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
channels?: 3 | 4;
|
|
22
|
+
layout?: PolicyImageTensorLayout;
|
|
23
|
+
range?: PolicyImageTensorRange;
|
|
24
|
+
}
|
|
25
|
+
interface PolicyImageTensorPixelOptions extends PolicyImageTensorOptions {
|
|
26
|
+
/** Row order of the source buffer. Defaults to `'top-left'`. */
|
|
27
|
+
sourceOrigin?: PolicyImageTensorSourceOrigin;
|
|
28
|
+
/** Mirror horizontally while reading. */
|
|
29
|
+
flipX?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface PolicyImageTensorResult {
|
|
32
|
+
data: Float32Array;
|
|
33
|
+
shape: [number, number, number];
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
channels: 3 | 4;
|
|
37
|
+
layout: PolicyImageTensorLayout;
|
|
38
|
+
range: PolicyImageTensorRange;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Convert a raw RGBA pixel buffer (4 bytes per pixel) directly into a policy
|
|
42
|
+
* image tensor. This is the fast path that skips canvas encoding entirely —
|
|
43
|
+
* feed it the `Uint8Array` returned by `readRenderTargetPixels` (which is
|
|
44
|
+
* bottom-left origin, so pass `sourceOrigin: 'bottom-left'`).
|
|
45
|
+
*/
|
|
46
|
+
declare function pixelsToPolicyImageTensor(pixels: Uint8Array | Uint8ClampedArray, options: PolicyImageTensorPixelOptions): PolicyImageTensorResult;
|
|
47
|
+
declare function imageDataToPolicyImageTensor(imageData: ImageData, options: PolicyImageTensorOptions): PolicyImageTensorResult;
|
|
48
|
+
declare function dataUrlToPolicyImageTensor(dataUrl: string, options: PolicyImageTensorOptions): Promise<PolicyImageTensorResult>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @license
|
|
52
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
53
|
+
*
|
|
54
|
+
* Offscreen camera-frame capture for R3F/MuJoCo scenes.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/** Options for capturing a camera frame straight into a policy image tensor. */
|
|
58
|
+
type CameraFrameCaptureTensorOptions = CameraFrameCaptureOptions & Pick<PolicyImageTensorOptions, 'channels' | 'layout' | 'range'>;
|
|
59
|
+
interface CameraFramePixelsResult {
|
|
60
|
+
/** Raw RGBA pixels, bottom-left origin (reused buffer — consume before the next capture). */
|
|
61
|
+
pixels: Uint8Array;
|
|
62
|
+
camera: THREE.Camera;
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
source: CameraFrameCaptureSource;
|
|
66
|
+
}
|
|
67
|
+
interface CameraFrameTensorResult extends PolicyImageTensorResult {
|
|
68
|
+
camera: THREE.Camera;
|
|
69
|
+
source: CameraFrameCaptureSource;
|
|
70
|
+
}
|
|
71
|
+
interface CameraFrameCaptureSession {
|
|
72
|
+
readonly width: number;
|
|
73
|
+
readonly height: number;
|
|
74
|
+
capture(options?: CameraFrameCaptureOptions): {
|
|
75
|
+
canvas: HTMLCanvasElement;
|
|
76
|
+
camera: THREE.Camera;
|
|
77
|
+
width: number;
|
|
78
|
+
height: number;
|
|
79
|
+
source: CameraFrameCaptureSource;
|
|
80
|
+
};
|
|
81
|
+
captureAsync(options?: CameraFrameCaptureOptions): Promise<{
|
|
82
|
+
canvas: HTMLCanvasElement;
|
|
83
|
+
camera: THREE.Camera;
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
source: CameraFrameCaptureSource;
|
|
87
|
+
}>;
|
|
88
|
+
captureDataUrl(options?: CameraFrameCaptureOptions): CameraFrameCaptureResult;
|
|
89
|
+
captureDataUrlAsync(options?: CameraFrameCaptureOptions): Promise<CameraFrameCaptureResult>;
|
|
90
|
+
captureBlob(options?: CameraFrameCaptureOptions): Promise<CameraFrameCaptureBlobResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Render and read raw RGBA pixels without any canvas/PNG round-trip. The
|
|
93
|
+
* returned buffer is reused between calls — copy or convert it before the
|
|
94
|
+
* next capture.
|
|
95
|
+
*/
|
|
96
|
+
capturePixels(options?: CameraFrameCaptureOptions): CameraFramePixelsResult;
|
|
97
|
+
/** Render straight into a normalized policy image tensor (no canvas/PNG encode). */
|
|
98
|
+
captureTensor(options?: CameraFrameCaptureTensorOptions): CameraFrameTensorResult;
|
|
99
|
+
dispose(): void;
|
|
100
|
+
}
|
|
101
|
+
declare const CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY = "mujocoReactCameraFrameCaptureRender";
|
|
102
|
+
declare const CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY = "mujocoReactCameraFrameCapturePreRender";
|
|
103
|
+
declare const CAPTURE_EXCLUDE_KEY = "mujoco.capture.exclude";
|
|
104
|
+
declare function createCameraFrameCaptureSession(renderer: THREE.WebGLRenderer, scene: THREE.Scene, fallbackCamera: THREE.Camera, options?: CameraFrameCaptureOptions): CameraFrameCaptureSession;
|
|
105
|
+
declare function renderCameraFrameToCanvas(renderer: THREE.WebGLRenderer, scene: THREE.Scene, fallbackCamera: THREE.Camera, options?: CameraFrameCaptureOptions): {
|
|
106
|
+
canvas: HTMLCanvasElement;
|
|
107
|
+
camera: THREE.Camera;
|
|
108
|
+
width: number;
|
|
109
|
+
height: number;
|
|
110
|
+
source: CameraFrameCaptureSource;
|
|
111
|
+
};
|
|
112
|
+
declare function captureCameraFrame(renderer: THREE.WebGLRenderer, scene: THREE.Scene, fallbackCamera: THREE.Camera, options?: CameraFrameCaptureOptions): Promise<CameraFrameCaptureResult>;
|
|
113
|
+
declare function captureCameraFrameBlob(renderer: THREE.WebGLRenderer, scene: THREE.Scene, fallbackCamera: THREE.Camera, options?: CameraFrameCaptureOptions): Promise<CameraFrameCaptureBlobResult>;
|
|
114
|
+
/**
|
|
115
|
+
* One-shot camera frame capture straight into a policy image tensor, skipping
|
|
116
|
+
* the canvas/PNG round-trip. For repeated captures (live inference, recording),
|
|
117
|
+
* create a session once with {@link createCameraFrameCaptureSession} and call
|
|
118
|
+
* `session.captureTensor()` so the render target and buffers are reused.
|
|
119
|
+
*/
|
|
120
|
+
declare function captureCameraFrameTensor(renderer: THREE.WebGLRenderer, scene: THREE.Scene, fallbackCamera: THREE.Camera, options?: CameraFrameCaptureTensorOptions): CameraFrameTensorResult;
|
|
121
|
+
|
|
5
122
|
/**
|
|
6
123
|
* @license
|
|
7
124
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -336,6 +453,10 @@ interface SceneObject {
|
|
|
336
453
|
solref?: string;
|
|
337
454
|
solimp?: string;
|
|
338
455
|
condim?: number;
|
|
456
|
+
/** MuJoCo geom contact type bitmask. Defaults to 1 for generated objects. */
|
|
457
|
+
contype?: number;
|
|
458
|
+
/** MuJoCo geom contact affinity bitmask. Defaults to 1 for generated objects. */
|
|
459
|
+
conaffinity?: number;
|
|
339
460
|
/** MuJoCo geom group. Group 3 is conventionally used for collision-only helper geoms. */
|
|
340
461
|
group?: number;
|
|
341
462
|
}
|
|
@@ -392,6 +513,12 @@ interface IkConfig {
|
|
|
392
513
|
* starting at index 0. Prefer inferred IK or `joints`/`actuators`.
|
|
393
514
|
*/
|
|
394
515
|
numJoints?: number;
|
|
516
|
+
/**
|
|
517
|
+
* Optional solve-space joint limits in the same order as the resolved joints.
|
|
518
|
+
* Use this when MJCF limits are intentionally broad or when a setup/calibration
|
|
519
|
+
* tool should stay within a narrower envelope.
|
|
520
|
+
*/
|
|
521
|
+
jointLimits?: ReadonlyArray<readonly [number, number] | null | undefined>;
|
|
395
522
|
/** Custom IK solver. When omitted, uses built-in Damped Least-Squares solver. */
|
|
396
523
|
ikSolveFn?: IKSolveFn;
|
|
397
524
|
/** DLS damping. Default: 0.01. */
|
|
@@ -413,7 +540,7 @@ interface IkContextValue {
|
|
|
413
540
|
ikTargetRef: React__default.RefObject<THREE.Group>;
|
|
414
541
|
siteIdRef: React__default.RefObject<number>;
|
|
415
542
|
setIkEnabled: (enabled: boolean) => void;
|
|
416
|
-
moveTarget: (pos:
|
|
543
|
+
moveTarget: (pos: IkTargetPosition, duration?: number) => void;
|
|
417
544
|
syncTargetToSite: () => void;
|
|
418
545
|
solveIK: (input: IkSolveInput) => number[] | null;
|
|
419
546
|
getGizmoStats: () => {
|
|
@@ -434,9 +561,20 @@ interface PhysicsConfig {
|
|
|
434
561
|
speed?: number;
|
|
435
562
|
}
|
|
436
563
|
type IKSolveFn = (input: IkSolveInput) => number[] | null;
|
|
564
|
+
type IkTargetPosition = THREE.Vector3 | readonly [number, number, number] | {
|
|
565
|
+
readonly x: number;
|
|
566
|
+
readonly y: number;
|
|
567
|
+
readonly z: number;
|
|
568
|
+
};
|
|
569
|
+
type IkTargetQuaternion = THREE.Quaternion | readonly [number, number, number, number] | {
|
|
570
|
+
readonly x: number;
|
|
571
|
+
readonly y: number;
|
|
572
|
+
readonly z: number;
|
|
573
|
+
readonly w: number;
|
|
574
|
+
};
|
|
437
575
|
interface IkSolveInput {
|
|
438
|
-
position:
|
|
439
|
-
quaternion:
|
|
576
|
+
position: IkTargetPosition;
|
|
577
|
+
quaternion: IkTargetQuaternion;
|
|
440
578
|
currentQ: number[];
|
|
441
579
|
context?: IKSolveContext;
|
|
442
580
|
}
|
|
@@ -1141,6 +1279,19 @@ interface MujocoSimAPI {
|
|
|
1141
1279
|
captureFrameBlob(options?: MujocoFrameCaptureOptions): Promise<FrameCaptureBlobResult>;
|
|
1142
1280
|
captureCameraFrame(options?: CameraFrameCaptureOptions): Promise<CameraFrameCaptureResult>;
|
|
1143
1281
|
captureCameraFrameBlob(options?: CameraFrameCaptureOptions): Promise<CameraFrameCaptureBlobResult>;
|
|
1282
|
+
/** Capture a camera frame straight into a policy image tensor (no canvas/PNG encode). */
|
|
1283
|
+
captureCameraFrameTensor(options?: CameraFrameCaptureTensorOptions): CameraFrameTensorResult;
|
|
1284
|
+
/**
|
|
1285
|
+
* Create a reusable offscreen capture session bound to this scene. Reuse it
|
|
1286
|
+
* for live inference/recording so the render target and buffers persist
|
|
1287
|
+
* across frames; call `session.captureTensor()` / `capturePixels()` each step.
|
|
1288
|
+
*/
|
|
1289
|
+
createCameraFrameCaptureSession(options?: CameraFrameCaptureOptions): CameraFrameCaptureSession;
|
|
1290
|
+
/**
|
|
1291
|
+
* Resolve a named MuJoCo camera/site/body into concrete capture options with
|
|
1292
|
+
* the current world pose. Useful for re-aiming a persistent session each step.
|
|
1293
|
+
*/
|
|
1294
|
+
resolveCameraCaptureOptions(options?: CameraFrameCaptureOptions): CameraFrameCaptureOptions;
|
|
1144
1295
|
recordCameraSequence(options: CameraFrameSequenceOptions): Promise<CameraFrameSequenceResult>;
|
|
1145
1296
|
project2DTo3D(x: number, y: number, cameraPos: THREE.Vector3, lookAt: THREE.Vector3): {
|
|
1146
1297
|
point: THREE.Vector3;
|
|
@@ -1498,4 +1649,4 @@ interface ArrayJointStateResult {
|
|
|
1498
1649
|
velocity: React__default.RefObject<Float64Array>;
|
|
1499
1650
|
}
|
|
1500
1651
|
|
|
1501
|
-
export { type
|
|
1652
|
+
export { type Joints as $, type ActuatedJointInfo as A, type BodyProps as B, type ControlGroupInfo as C, type DragInteractionProps as D, type VisualScenarioExecutionContext as E, type ScenarioLightingPreset as F, type SplatEnvironmentMetadataInput as G, type SplatEnvironmentMetadata as H, type IkConfig as I, type SplatSceneInput as J, type CameraFrameCaptureOptions as K, type DebugProps as L, type MujocoContextValue as M, type GeomInfo as N, type ObservationConfig as O, type PhysicsStepCallback as P, type ContactListenerProps as Q, type ReadyCallbackInput as R, type SceneConfig as S, type TrajectoryPlayerProps as T, type ActuatorInfo as U, type VisualScenarioEffectsProps as V, type Sites as W, type SitePositionResult as X, type Sensors as Y, type SensorHandle as Z, type SensorInfo as _, type MujocoCanvasProps as a, type IKSolveFn as a$, type ScalarJointStateResult as a0, type ArrayJointStateResult as a1, type JointStateOptions as a2, type JointStateResult as a3, type Bodies as a4, type BodyStateResult as a5, type Geoms as a6, type Actuators as a7, type CtrlHandle as a8, type ContactInfo as a9, type PolicyCameraFrameCaptureAPI as aA, type CameraFrameCaptureTensorOptions as aB, type CameraFrameTensorResult as aC, type CameraFrameSequenceRecorderAPI as aD, type ImagePointCoordinateSpace as aE, type ImagePointProjectionOptions as aF, type ImagePointProjectionResult as aG, type PolicyVector as aH, type BodyInfo as aI, CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY as aJ, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY as aK, CAPTURE_EXCLUDE_KEY as aL, type CameraFrameCaptureBlobResult as aM, type CameraFrameCaptureQuaternion as aN, type CameraFrameCaptureResult as aO, type CameraFrameCaptureSession as aP, type CameraFrameCaptureVector3 as aQ, type CameraFramePixelsResult as aR, type CameraFrameSequenceCameraSummary as aS, type CameraFrameSequenceFrame as aT, type CameraFrameSequenceSampleInput as aU, type CameraFrameSequenceStepInput as aV, type CameraInfo as aW, type ControlJointInfo as aX, type DebugVirtualCamera as aY, type FrameCaptureTarget as aZ, type FrameCaptureTargetRef as a_, type KeyboardTeleopConfig as aa, type KeyboardIkTargetConfig as ab, type PolicyConfig as ac, type PolicyAPI as ad, type RemotePolicyConfig as ae, type RemotePolicyAPI as af, type ObservationHandle as ag, type ObservationOutput as ah, type TrajectoryInput as ai, type TrajectoryStateChangeInput as aj, type PlaybackState as ak, type TrajectoryFrame as al, type FrameCaptureOptions as am, type FrameCaptureResult as an, type FrameCaptureBlobResult as ao, type FrameCaptureAPI as ap, type CameraFrameCaptureAPI as aq, type Cameras as ar, type CameraFrameSequenceCamera as as, type CameraFrameCaptureSource as at, type CameraFrameSequenceOptions as au, type CameraFrameSequenceResult as av, type PolicyCameraFrameStream as aw, type PolicyCameraFrameCaptureOptions as ax, type PolicyCameraFrameCaptureResult as ay, type FrameCaptureStatus as az, type MujocoSimAPI as b, captureCameraFrameBlob as b$, type IkGizmoDragInput as b0, type IkSolveInput as b1, type JointInfo as b2, type JointStateKind as b3, type KeyBinding as b4, type KeyboardIkTargetAction as b5, type KeyboardIkTargetBinding as b6, type Keyframes as b7, ModelActuators as b8, ModelBodies as b9, type PolicyInferenceResult as bA, type PolicyObservationInput as bB, type RayHit as bC, type Register as bD, type RegisteredModelMap as bE, type RemotePolicyRequestInfo as bF, type RemotePolicyRequestInput as bG, type RemotePolicyResponseInfo as bH, type RemotePolicyStatus as bI, type ResetCallbackInput as bJ, type ResolvedScenarioCameraConfig as bK, type ResolvedScenarioMaterialConfig as bL, type ResourceSelector as bM, type ScenarioCameraConfig as bN, type ScenarioMaterialConfig as bO, type SceneMarker as bP, type SceneObject as bQ, type SensorResult as bR, type SiteInfo as bS, type SplatAssetConfig as bT, type SplatScenarioConfig as bU, type StateSnapshot as bV, type TrajectoryData as bW, type TrajectoryFrameCallbackInput as bX, type VisualScenarioMaterialFilterInput as bY, type XmlPatch as bZ, captureCameraFrame as b_, ModelCameras as ba, ModelGeoms as bb, ModelJoints as bc, ModelKeyframes as bd, type ModelOptions as be, type ModelResource as bf, ModelResources as bg, ModelSensors as bh, ModelSites as bi, type Models as bj, type MujocoContact as bk, type MujocoContactArray as bl, type MujocoFrameCaptureOptions as bm, type ObservationLayoutItem as bn, type PhysicsConfig as bo, type PhysicsStepInput as bp, type PolicyActionChunk as bq, type PolicyActionInput as br, type PolicyImageTensorLayout as bs, type PolicyImageTensorOptions as bt, type PolicyImageTensorPixelOptions as bu, type PolicyImageTensorRange as bv, type PolicyImageTensorResult as bw, type PolicyImageTensorSourceOrigin as bx, type PolicyInferenceInput as by, type PolicyInferenceOutput as bz, type StepCallbackInput as c, captureCameraFrameTensor as c0, createCameraFrameCaptureSession as c1, dataUrlToPolicyImageTensor as c2, getContact as c3, imageDataToPolicyImageTensor as c4, pixelsToPolicyImageTensor as c5, registerModelResources as c6, renderCameraFrameToCanvas as c7, type SelectionCallbackInput as d, type MujocoModule as e, type MujocoRenderOptions as f, type MujocoModel as g, type MujocoData as h, type ControlGroupSelector as i, type ObservationResult as j, type IkContextValue as k, type IkGizmoProps as l, type SceneLightsProps as m, type ScenarioLightingProps as n, type SplatEnvironmentProps as o, type VisualScenarioConfig as p, type SplatRendererKind as q, type PairedSplatEnvironmentConfig as r, type SplatFormat as s, type SplatCollisionProxyConfig as t, type SplatEnvironmentReadiness as u, type SplatCollisionPrimitive as v, SplatEnvironmentReadinessStatus as w, type SplatSceneConfigInput as x, type SplatSceneConfigState as y, type VisualScenarioExecutionContextInput as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mujoco-react",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.6.0",
|
|
4
4
|
"description": "Composable React Three Fiber building blocks for MuJoCo WASM simulations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,13 @@
|
|
|
25
25
|
"default": "./dist/spark.js"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
-
"./package.json": "./package.json"
|
|
28
|
+
"./package.json": "./package.json",
|
|
29
|
+
"./onnx": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/onnx.d.ts",
|
|
32
|
+
"default": "./dist/onnx.js"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
29
35
|
},
|
|
30
36
|
"bin": {
|
|
31
37
|
"mujoco-react": "./bin/mujoco-react.mjs",
|
|
@@ -63,11 +69,15 @@
|
|
|
63
69
|
"@react-three/fiber": ">=8",
|
|
64
70
|
"@sparkjsdev/spark": ">=2.1.0",
|
|
65
71
|
"react": ">=18",
|
|
66
|
-
"three": ">=0.180.0"
|
|
72
|
+
"three": ">=0.180.0",
|
|
73
|
+
"onnxruntime-web": ">=1.20.0"
|
|
67
74
|
},
|
|
68
75
|
"peerDependenciesMeta": {
|
|
69
76
|
"@sparkjsdev/spark": {
|
|
70
77
|
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"onnxruntime-web": {
|
|
80
|
+
"optional": true
|
|
71
81
|
}
|
|
72
82
|
},
|
|
73
83
|
"dependencies": {
|
|
@@ -82,6 +92,7 @@
|
|
|
82
92
|
"@types/node": "^25.9.1",
|
|
83
93
|
"@types/react": "^19.0.0",
|
|
84
94
|
"@types/three": "^0.181.0",
|
|
95
|
+
"onnxruntime-web": "^1.27.0",
|
|
85
96
|
"react": "^19.2.0",
|
|
86
97
|
"semantic-release": "^25.0.3",
|
|
87
98
|
"three": "^0.181.0",
|