mujoco-react 11.0.0 → 12.1.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 +25 -18
- package/dist/chunk-U2Y2BODT.js +137 -0
- package/dist/chunk-U2Y2BODT.js.map +1 -0
- package/dist/{chunk-UCQ5MJP4.js → chunk-XD3AY7XZ.js} +47 -9
- package/dist/chunk-XD3AY7XZ.js.map +1 -0
- package/dist/index.d.ts +10 -15
- package/dist/index.js +1437 -1090
- package/dist/index.js.map +1 -1
- package/dist/onnx.d.ts +1 -1
- package/dist/physics.worker.d.ts +2 -0
- package/dist/physics.worker.js +78 -0
- package/dist/physics.worker.js.map +1 -0
- package/dist/spark.d.ts +1 -1
- package/dist/spark.js +1 -1
- package/dist/{types-BP8iiYei.d.ts → types-CSi3fIVs.d.ts} +81 -1
- package/dist/vite.d.ts +5 -2
- package/dist/vite.js +6 -2
- package/dist/vite.js.map +1 -1
- package/package.json +6 -3
- package/src/components/CameraView.tsx +9 -7
- package/src/core/MujocoCanvas.tsx +2 -0
- package/src/core/MujocoPhysics.tsx +1 -0
- package/src/core/MujocoSimProvider.tsx +103 -81
- package/src/core/sceneIdentity.ts +15 -0
- package/src/core/stepBudget.ts +18 -0
- package/src/hooks/useCameraStream.ts +14 -17
- package/src/hooks/usePolicy.ts +16 -7
- package/src/index.ts +3 -0
- package/src/physics.worker.ts +13 -0
- package/src/rendering/cameraFrameCapture.ts +33 -7
- package/src/runtime/client.ts +186 -0
- package/src/runtime/engine.ts +93 -0
- package/src/runtime/protocol.ts +59 -0
- package/src/runtime/types.ts +51 -0
- package/src/types.ts +19 -0
- package/src/vite.ts +7 -2
- package/dist/chunk-UCQ5MJP4.js.map +0 -1
package/dist/onnx.d.ts
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SimulationEngine } from './chunk-U2Y2BODT.js';
|
|
2
|
+
import loadMujoco from '@mujoco/mujoco';
|
|
3
|
+
import wasmUrl from '@mujoco/mujoco/mujoco.wasm?url';
|
|
4
|
+
|
|
5
|
+
// src/runtime/protocol.ts
|
|
6
|
+
function createRuntimeHandler(load, send) {
|
|
7
|
+
let engine;
|
|
8
|
+
let generation = 0;
|
|
9
|
+
let busy = false;
|
|
10
|
+
let displayPending = false;
|
|
11
|
+
return async (request) => {
|
|
12
|
+
if (request.kind === "ack") {
|
|
13
|
+
displayPending = false;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (request.kind === "cancel") {
|
|
17
|
+
generation++;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (busy) {
|
|
21
|
+
send({ id: request.id, done: true, error: "Runtime is busy; await the current operation" });
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
busy = true;
|
|
25
|
+
const current = generation;
|
|
26
|
+
let steps = 0, physicsMs = 0;
|
|
27
|
+
try {
|
|
28
|
+
if (request.kind === "initialize") {
|
|
29
|
+
if (engine) throw new Error("Runtime is already initialized");
|
|
30
|
+
engine = new SimulationEngine(await load(), request.initial);
|
|
31
|
+
} else if (!engine) throw new Error("Runtime is not initialized");
|
|
32
|
+
else if (request.kind === "reset") engine.reset();
|
|
33
|
+
else if (request.kind === "restore") engine.restore(request.state);
|
|
34
|
+
else if (request.kind === "advance") {
|
|
35
|
+
if (!Number.isSafeInteger(request.steps) || request.steps <= 0) throw new Error("Steps must be a positive safe integer");
|
|
36
|
+
engine.setControls(request.controls);
|
|
37
|
+
let lastDisplay = performance.now();
|
|
38
|
+
while (steps < request.steps && generation === current) {
|
|
39
|
+
const sliceStart = performance.now();
|
|
40
|
+
do {
|
|
41
|
+
const start = performance.now();
|
|
42
|
+
engine.step();
|
|
43
|
+
physicsMs += performance.now() - start;
|
|
44
|
+
steps++;
|
|
45
|
+
} while (steps < request.steps && performance.now() - sliceStart < 8);
|
|
46
|
+
if (!displayPending && performance.now() - lastDisplay >= 32) {
|
|
47
|
+
displayPending = true;
|
|
48
|
+
send({ id: request.id, done: false, display: engine.snapshot(false) });
|
|
49
|
+
lastDisplay = performance.now();
|
|
50
|
+
}
|
|
51
|
+
if (steps < request.steps) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
send({ id: request.id, done: true, display: engine.snapshot(), cancelled: generation !== current, steps, physicsMs });
|
|
55
|
+
} catch (error) {
|
|
56
|
+
send({ id: request.id, done: true, error: error instanceof Error ? error.message : String(error) });
|
|
57
|
+
} finally {
|
|
58
|
+
busy = false;
|
|
59
|
+
displayPending = false;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/physics.worker.ts
|
|
65
|
+
var scope = self;
|
|
66
|
+
var handle = createRuntimeHandler(
|
|
67
|
+
() => loadMujoco({ locateFile: (file) => file.endsWith(".wasm") ? wasmUrl : file }),
|
|
68
|
+
(response) => {
|
|
69
|
+
const transfer = response.display ? Object.values(response.display.fields).map((value) => value.buffer) : [];
|
|
70
|
+
if (response.display?.integration) transfer.push(response.display.integration.values.buffer);
|
|
71
|
+
scope.postMessage(response, transfer);
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
scope.onmessage = (event) => {
|
|
75
|
+
void handle(event.data);
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=physics.worker.js.map
|
|
78
|
+
//# sourceMappingURL=physics.worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/protocol.ts","../src/physics.worker.ts"],"names":[],"mappings":";;;;;AAaO,SAAS,oBAAA,CAAqB,MAAiC,IAAA,EAAoC;AACxG,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI,UAAA,GAAa,CAAA;AACjB,EAAA,IAAI,IAAA,GAAO,KAAA;AACX,EAAA,IAAI,cAAA,GAAiB,KAAA;AACrB,EAAA,OAAO,OAAO,OAAA,KAAqB;AACjC,IAAA,IAAI,OAAA,CAAQ,SAAS,KAAA,EAAO;A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A,CAAO,KAAK,GAAG,CAAA;AAAA,IACpG,CAAA,SAAE;AAAU,MAAA,IAAA,GAAO,KAAA;AAAO,MAAA,cAAA,GAAiB,KAAA;AAAA,IAAO;AAAA,EACpD,CAAA;AACF;;;ACvDA,IAAM,KAAA,GAAQ,IAAA;AACd,IAAM,MAAA,GAAS,oBAAA;AAAA,EACb,MAAM,UAAA,CAAW,EAAE,UAAA,EAAY,CAAC,IAAA,KAAiB,IAAA,CAAK,QAAA,CAAS,OAAO,CAAA,GAAI,OAAA,GAAU,IAAA,EAAM,CAAA;AAAA,EAC1F,CAAA,QAAA,KAAY;AACV,IAAA,MAAM,QAAA,GAA2B,QAAA,CAAS,OAAA,GAAU,MAAA,CAAO,OAAO,QAAA,CAAS,OAAA,CAAQ,MAAM,CAAA,CAAE,GAAA,CAAI,CAAA,KAAA,KAAS,KAAA,CAAM,MAAqB,IAAI,EAAC;AACxI,IAAA,IAAI,QAAA,CAAS,SAAS,WAAA,EAAa,QAAA,CAAS,KAAK,QAAA,CAAS,OAAA,CAAQ,WAAA,CAAY,MAAA,CAAO,MAAqB,CAAA;AAC1G,IAAA,KAAA,CAAM,WAAA,CAAY,UAAU,QAAQ,CAAA;AAAA,EACtC;AACF,CAAA;AACA,KAAA,CAAM,YAAY,CAAA,KAAA,KAAS;AAAE,EAAA,KAAK,MAAA,CAAO,MAAM,IAAI,CAAA;AAAG,CAAA","file":"physics.worker.js","sourcesContent":["import type { MainModule } from '@mujoco/mujoco';\nimport { SimulationEngine, type DisplayState, type EngineInitialization, type EngineState } from './engine';\nexport type Request = { id: number } & (\n { kind: 'initialize'; initial: EngineInitialization } |\n { kind: 'advance'; steps: number; controls?: Float64Array } |\n { kind: 'restore'; state: EngineState } |\n { kind: 'reset' | 'snapshot' | 'cancel' | 'ack' }\n);\nexport interface Response {\n id: number; done: boolean; display?: DisplayState; error?: string;\n cancelled?: boolean; steps?: number; physicsMs?: number;\n}\n/** Same protocol is exercised with a real engine in worker-thread tests. */\nexport function createRuntimeHandler(load: () => Promise<MainModule>, send: (response: Response) => void) {\n let engine: SimulationEngine | undefined;\n let generation = 0;\n let busy = false;\n let displayPending = false;\n return async (request: Request) => {\n if (request.kind === 'ack') { displayPending = false; return; }\n if (request.kind === 'cancel') { generation++; return; }\n if (busy) { send({ id: request.id, done: true, error: 'Runtime is busy; await the current operation' }); return; }\n busy = true;\n const current = generation;\n let steps = 0, physicsMs = 0;\n try {\n if (request.kind === 'initialize') {\n if (engine) throw new Error('Runtime is already initialized');\n engine = new SimulationEngine(await load(), request.initial);\n } else if (!engine) throw new Error('Runtime is not initialized');\n else if (request.kind === 'reset') engine.reset();\n else if (request.kind === 'restore') engine.restore(request.state);\n else if (request.kind === 'advance') {\n if (!Number.isSafeInteger(request.steps) || request.steps <= 0) throw new Error('Steps must be a positive safe integer');\n engine.setControls(request.controls);\n let lastDisplay = performance.now();\n while (steps < request.steps && generation === current) {\n const sliceStart = performance.now();\n do {\n const start = performance.now();\n engine.step();\n physicsMs += performance.now() - start;\n steps++;\n } while (steps < request.steps && performance.now() - sliceStart < 8);\n if (!displayPending && performance.now() - lastDisplay >= 32) {\n displayPending = true;\n send({ id: request.id, done: false, display: engine.snapshot(false) });\n lastDisplay = performance.now();\n }\n // A task yield is required: a microtask alone starves cancel messages.\n if (steps < request.steps) await new Promise(resolve => setTimeout(resolve, 0));\n }\n }\n send({ id: request.id, done: true, display: engine!.snapshot(), cancelled: generation !== current, steps, physicsMs });\n } catch (error) {\n send({ id: request.id, done: true, error: error instanceof Error ? error.message : String(error) });\n } finally { busy = false; displayPending = false; }\n };\n}\n","import loadMujoco from '@mujoco/mujoco';\nimport wasmUrl from '@mujoco/mujoco/mujoco.wasm?url';\nimport { createRuntimeHandler, type Request, type Response } from './runtime/protocol';\nconst scope = self as unknown as { onmessage: (event: MessageEvent<Request>) => void; postMessage: (response: Response, transfer: Transferable[]) => void };\nconst handle = createRuntimeHandler(\n () => loadMujoco({ locateFile: (file: string) => file.endsWith('.wasm') ? wasmUrl : file }),\n response => {\n const transfer: Transferable[] = response.display ? Object.values(response.display.fields).map(value => value.buffer as ArrayBuffer) : [];\n if (response.display?.integration) transfer.push(response.display.integration.values.buffer as ArrayBuffer);\n scope.postMessage(response, transfer);\n },\n);\nscope.onmessage = event => { void handle(event.data); };\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 {
|
|
3
|
+
import { S as SplatEnvironmentProps, a as PairedSplatEnvironmentConfig, b as SceneConfig, c as SplatEnvironmentReadiness, V as VisualScenarioConfig } from './types-CSi3fIVs.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-XD3AY7XZ.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,66 @@ 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
|
+
interface RuntimeMetrics {
|
|
6
|
+
steps: number;
|
|
7
|
+
physicsMs: number;
|
|
8
|
+
elapsedMs: number;
|
|
9
|
+
realTimeFactor: number;
|
|
10
|
+
captureMs: number;
|
|
11
|
+
busy: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface RuntimeState {
|
|
14
|
+
time: number;
|
|
15
|
+
qpos: Float64Array;
|
|
16
|
+
qvel: Float64Array;
|
|
17
|
+
ctrl: Float64Array;
|
|
18
|
+
sensors: Float64Array;
|
|
19
|
+
contacts: ContactInfo[];
|
|
20
|
+
}
|
|
21
|
+
interface RuntimeSnapshot {
|
|
22
|
+
readonly modelId: string;
|
|
23
|
+
readonly signature: number;
|
|
24
|
+
readonly values: Float64Array;
|
|
25
|
+
}
|
|
26
|
+
interface AdvanceOptions {
|
|
27
|
+
steps: number;
|
|
28
|
+
controls?: ArrayLike<number>;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}
|
|
31
|
+
/** One operation at a time. Await advance/observe rather than queueing work. */
|
|
32
|
+
interface SimulationRuntime {
|
|
33
|
+
readonly state: RuntimeState;
|
|
34
|
+
readonly metrics: Readonly<RuntimeMetrics>;
|
|
35
|
+
advance(options: AdvanceOptions): Promise<RuntimeState>;
|
|
36
|
+
observe(cameras?: PolicyCameraFrameCaptureOptions): Promise<RuntimeState & {
|
|
37
|
+
cameras?: PolicyCameraFrameCaptureResult;
|
|
38
|
+
}>;
|
|
39
|
+
saveState(): Promise<RuntimeSnapshot>;
|
|
40
|
+
restoreState(snapshot: RuntimeSnapshot): Promise<RuntimeState>;
|
|
41
|
+
cancel(): Promise<void>;
|
|
42
|
+
reset(): Promise<RuntimeState>;
|
|
43
|
+
dispose(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
interface WorkerPort {
|
|
46
|
+
postMessage(message: unknown): void;
|
|
47
|
+
terminate(): void;
|
|
48
|
+
onmessage: ((event: MessageEvent) => void) | null;
|
|
49
|
+
onerror: ((event: ErrorEvent) => void) | null;
|
|
50
|
+
onmessageerror: ((event: MessageEvent) => void) | null;
|
|
51
|
+
}
|
|
52
|
+
interface RuntimeOptions {
|
|
53
|
+
/** Override worker construction for custom bundlers or runtime tests. */
|
|
54
|
+
createWorker?: () => WorkerPort;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface PhysicsPerformance {
|
|
58
|
+
steps: number;
|
|
59
|
+
physicsMs: number;
|
|
60
|
+
realTimeFactor: number;
|
|
61
|
+
backlogSteps: number;
|
|
62
|
+
budgetExceeded: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
5
65
|
/**
|
|
6
66
|
* @license
|
|
7
67
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -366,10 +426,14 @@ interface MujocoModel {
|
|
|
366
426
|
flex_shellnum: Int32Array;
|
|
367
427
|
flex_shell: Int32Array;
|
|
368
428
|
flex_rgba: Float32Array;
|
|
429
|
+
/** Number of stateful plastic deformation coordinates. */
|
|
430
|
+
nplastic: number;
|
|
431
|
+
jnt_plasticadr: Int32Array;
|
|
369
432
|
opt: {
|
|
370
433
|
timestep: number;
|
|
371
434
|
gravity: Float64Array;
|
|
372
435
|
integrator: number;
|
|
436
|
+
enableflags: number;
|
|
373
437
|
[key: string]: unknown;
|
|
374
438
|
};
|
|
375
439
|
delete: () => void;
|
|
@@ -382,6 +446,8 @@ interface MujocoData {
|
|
|
382
446
|
time: number;
|
|
383
447
|
qpos: Float64Array;
|
|
384
448
|
qvel: Float64Array;
|
|
449
|
+
/** Plastic rest offsets, included in full integration snapshots. */
|
|
450
|
+
plastic: Float64Array;
|
|
385
451
|
ctrl: Float64Array;
|
|
386
452
|
act: Float64Array;
|
|
387
453
|
xpos: Float64Array;
|
|
@@ -416,6 +482,11 @@ interface MujocoBuffer {
|
|
|
416
482
|
delete(): void;
|
|
417
483
|
}
|
|
418
484
|
interface MujocoModule {
|
|
485
|
+
mjtEnableBit: {
|
|
486
|
+
mjENBL_SPECULATIVE: {
|
|
487
|
+
value: number;
|
|
488
|
+
};
|
|
489
|
+
};
|
|
419
490
|
DoubleBuffer: new (size: number) => MujocoBuffer;
|
|
420
491
|
mj_jacSite(model: MujocoModel, data: MujocoData, jacp: MujocoBuffer | null, jacr: MujocoBuffer | null, site: number): void;
|
|
421
492
|
mj_integratePos(model: MujocoModel, qpos: MujocoBuffer, velocity: number[], dt: number): void;
|
|
@@ -588,6 +659,8 @@ interface PhysicsConfig {
|
|
|
588
659
|
timestep?: number;
|
|
589
660
|
/** Override the MJCF integrator. Omit to preserve model settings. */
|
|
590
661
|
integrator?: MujocoIntegrator;
|
|
662
|
+
/** Main-thread physics time budget per frame. Default 8 ms; at most 100 steps. */
|
|
663
|
+
physicsBudgetMs?: number;
|
|
591
664
|
substeps?: number;
|
|
592
665
|
paused?: boolean;
|
|
593
666
|
speed?: number;
|
|
@@ -856,6 +929,8 @@ interface PolicyConfig {
|
|
|
856
929
|
* - replace is useful for receding-horizon policies where a fresh chunk should supersede stale queued actions.
|
|
857
930
|
*/
|
|
858
931
|
queueStrategy?: 'append' | 'replace';
|
|
932
|
+
/** Maximum buffered actions; overflow fails explicitly. Default: 256. */
|
|
933
|
+
maxQueuedActions?: number;
|
|
859
934
|
/**
|
|
860
935
|
* Clear queued actions and ignore in-flight async results when `stop()` is called.
|
|
861
936
|
* Defaults to false so callers can choose pause/resume behavior explicitly.
|
|
@@ -1272,6 +1347,9 @@ interface BodyProps {
|
|
|
1272
1347
|
children?: ReactNode;
|
|
1273
1348
|
}
|
|
1274
1349
|
interface MujocoSimAPI {
|
|
1350
|
+
/** Dedicated worker owner for exact stepping and policy observations. */
|
|
1351
|
+
createRuntime(options?: RuntimeOptions): Promise<SimulationRuntime>;
|
|
1352
|
+
getPerformance(): PhysicsPerformance;
|
|
1275
1353
|
readonly status: 'loading' | 'ready' | 'error';
|
|
1276
1354
|
readonly config: SceneConfig;
|
|
1277
1355
|
reset(): void;
|
|
@@ -1627,6 +1705,8 @@ type MujocoCanvasProps = Omit<CanvasProps, 'onError'> & {
|
|
|
1627
1705
|
timestep?: number;
|
|
1628
1706
|
/** Override the MJCF integrator. Omit to preserve model settings. */
|
|
1629
1707
|
integrator?: MujocoIntegrator;
|
|
1708
|
+
/** Main-thread physics time budget per frame. Default 8 ms; at most 100 steps. */
|
|
1709
|
+
physicsBudgetMs?: number;
|
|
1630
1710
|
substeps?: number;
|
|
1631
1711
|
paused?: boolean;
|
|
1632
1712
|
speed?: number;
|
|
@@ -1702,4 +1782,4 @@ interface ArrayJointStateResult {
|
|
|
1702
1782
|
velocity: React__default.RefObject<Float64Array>;
|
|
1703
1783
|
}
|
|
1704
1784
|
|
|
1705
|
-
export { type
|
|
1785
|
+
export { type SensorHandle as $, type ActuatedJointInfo as A, type BodyProps as B, type ControlGroupInfo as C, type DragInteractionProps as D, type SplatSceneConfigState as E, type VisualScenarioExecutionContextInput as F, type VisualScenarioExecutionContext as G, type ScenarioLightingPreset as H, type IkConfig as I, type SplatEnvironmentMetadataInput as J, type SplatEnvironmentMetadata as K, type SplatSceneInput as L, type MujocoContextValue as M, type CameraFrameCaptureOptions as N, type ObservationConfig as O, type PolicyActionChunk as P, type DebugProps as Q, type ReadyCallbackInput as R, type SplatEnvironmentProps as S, type GeomInfo as T, type ContactListenerProps as U, type VisualScenarioConfig as V, type TrajectoryPlayerProps as W, type ActuatorInfo as X, type Sites as Y, type SitePositionResult as Z, type Sensors as _, type PairedSplatEnvironmentConfig as a, type ControlJointInfo as a$, type SensorInfo as a0, type Joints as a1, type ScalarJointStateResult as a2, type ArrayJointStateResult as a3, type JointStateOptions as a4, type JointStateResult as a5, type Bodies as a6, type BodyStateResult as a7, type Geoms as a8, type Actuators as a9, type PolicyCameraFrameCaptureResult as aA, type FrameCaptureStatus as aB, type PolicyCameraFrameCaptureAPI as aC, type CameraFrameCaptureTensorOptions as aD, type CameraFrameTensorResult as aE, type CameraFrameSequenceRecorderAPI as aF, type ImagePointCoordinateSpace as aG, type ImagePointProjectionOptions as aH, type ImagePointProjectionResult as aI, type PolicyVector as aJ, type ActuatorControlValue as aK, type AdvanceOptions as aL, type BodyInfo as aM, CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY as aN, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY as aO, CAPTURE_EXCLUDE_KEY as aP, type CameraFrameCaptureBlobResult as aQ, type CameraFrameCaptureQuaternion as aR, type CameraFrameCaptureResult as aS, type CameraFrameCaptureSession as aT, type CameraFrameCaptureVector3 as aU, type CameraFramePixelsResult as aV, type CameraFrameSequenceCameraSummary as aW, type CameraFrameSequenceFrame as aX, type CameraFrameSequenceSampleInput as aY, type CameraFrameSequenceStepInput as aZ, type CameraInfo as a_, type CtrlHandle as aa, type ContactInfo as ab, type KeyboardTeleopConfig as ac, type KeyboardIkTargetConfig as ad, type PolicyConfig as ae, type PolicyAPI as af, type RemotePolicyConfig as ag, type RemotePolicyAPI as ah, type ObservationHandle as ai, type ObservationOutput as aj, type TrajectoryInput as ak, type TrajectoryStateChangeInput as al, type PlaybackState as am, type TrajectoryFrame as an, type FrameCaptureOptions as ao, type FrameCaptureResult as ap, type FrameCaptureBlobResult as aq, type FrameCaptureAPI as ar, type CameraFrameCaptureAPI as as, type Cameras as at, type CameraFrameSequenceCamera as au, type CameraFrameCaptureSource as av, type CameraFrameSequenceOptions as aw, type CameraFrameSequenceResult as ax, type PolicyCameraFrameStream as ay, type PolicyCameraFrameCaptureOptions as az, type SceneConfig as b, type SiteInfo as b$, type DebugVirtualCamera as b0, type FrameCaptureTarget as b1, type FrameCaptureTargetRef as b2, type IKSolveFn as b3, type IkGizmoDragInput as b4, type IkSolveInput as b5, type JointInfo as b6, type JointStateKind as b7, type KeyBinding as b8, type KeyboardIkTargetAction as b9, type PolicyImageTensorResult as bA, type PolicyImageTensorSourceOrigin as bB, type PolicyInferenceInput as bC, type PolicyInferenceOutput as bD, type PolicyInferenceResult as bE, type PolicyObservationInput as bF, type RayHit as bG, type Register as bH, type RegisteredModelMap as bI, type RemotePolicyRequestInfo as bJ, type RemotePolicyRequestInput as bK, type RemotePolicyResponseInfo as bL, type RemotePolicyStatus as bM, type ResetCallbackInput as bN, type ResolvedScenarioCameraConfig as bO, type ResolvedScenarioMaterialConfig as bP, type ResourceSelector as bQ, type RuntimeMetrics as bR, type RuntimeOptions as bS, type RuntimeSnapshot as bT, type RuntimeState as bU, type ScenarioCameraConfig as bV, type ScenarioMaterialConfig as bW, type SceneMarker as bX, type SceneObject as bY, type SensorResult as bZ, type SimulationRuntime as b_, type KeyboardIkTargetBinding as ba, type Keyframes as bb, ModelActuators as bc, ModelBodies as bd, ModelCameras as be, ModelGeoms as bf, ModelJoints as bg, ModelKeyframes as bh, type ModelOptions as bi, type ModelResource as bj, ModelResources as bk, ModelSensors as bl, ModelSites as bm, type Models as bn, type MujocoContact as bo, type MujocoContactArray as bp, type MujocoFrameCaptureOptions as bq, type ObservationLayoutItem as br, type PhysicsConfig as bs, type PhysicsPerformance as bt, type PhysicsStepInput as bu, type PolicyActionInput as bv, type PolicyImageTensorLayout as bw, type PolicyImageTensorOptions as bx, type PolicyImageTensorPixelOptions as by, type PolicyImageTensorRange as bz, type SplatEnvironmentReadiness as c, type SplatAssetConfig as c0, type SplatScenarioConfig as c1, type StateSnapshot as c2, type TrajectoryData as c3, type TrajectoryFrameCallbackInput as c4, type VisualScenarioMaterialFilterInput as c5, type WorkerPort as c6, type XmlPatch as c7, captureCameraFrame as c8, captureCameraFrameBlob as c9, captureCameraFrameTensor as ca, createCameraFrameCaptureSession as cb, dataUrlToPolicyImageTensor as cc, getContact as cd, imageDataToPolicyImageTensor as ce, pixelsToPolicyImageTensor as cf, registerModelResources as cg, renderCameraFrameToCanvas as ch, type MujocoCanvasProps as d, type MujocoSimAPI as e, type StepCallbackInput as f, type SelectionCallbackInput as g, type MujocoIntegrator as h, type MujocoModule as i, type MujocoRenderOptions as j, type PhysicsStepCallback as k, type MujocoModel as l, type MujocoData as m, type ControlGroupSelector as n, type ObservationResult as o, type IkContextValue as p, type IkGizmoProps as q, type SceneLightsProps as r, type ScenarioLightingProps as s, type VisualScenarioEffectsProps as t, type SplatRendererKind as u, type SplatFormat as v, type SplatCollisionProxyConfig as w, type SplatCollisionPrimitive as x, SplatEnvironmentReadinessStatus as y, type SplatSceneConfigInput as z };
|
package/dist/vite.d.ts
CHANGED
|
@@ -42,10 +42,13 @@ declare function mujocoReact(options: MujocoReactPluginOptions): {
|
|
|
42
42
|
chunkSizeWarningLimit?: number;
|
|
43
43
|
};
|
|
44
44
|
}): {
|
|
45
|
-
build
|
|
45
|
+
build?: {
|
|
46
46
|
chunkSizeWarningLimit: number;
|
|
47
|
+
} | undefined;
|
|
48
|
+
optimizeDeps: {
|
|
49
|
+
exclude: string[];
|
|
47
50
|
};
|
|
48
|
-
}
|
|
51
|
+
};
|
|
49
52
|
configResolved(config: ViteConfig): void;
|
|
50
53
|
transform(code: string, id: string): string | undefined;
|
|
51
54
|
buildStart(this: {
|
package/dist/vite.js
CHANGED
|
@@ -39,8 +39,12 @@ function mujocoReact(options) {
|
|
|
39
39
|
name: "mujoco-react",
|
|
40
40
|
enforce: "pre",
|
|
41
41
|
config(userConfig) {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
return {
|
|
43
|
+
// Keep the worker URL relative to its real package file in dev. Vite's
|
|
44
|
+
// dependency prebundler otherwise relocates it into .vite/deps.
|
|
45
|
+
optimizeDeps: { exclude: ["mujoco-react"] },
|
|
46
|
+
...userConfig.build?.chunkSizeWarningLimit === void 0 ? { build: { chunkSizeWarningLimit: 4e3 } } : {}
|
|
47
|
+
};
|
|
44
48
|
},
|
|
45
49
|
configResolved(config) {
|
|
46
50
|
root = config.root;
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vite.ts"],"names":[],"mappings":";;;;AAiDA,IAAM,aAAA,GAA+B,CAAC,WAAA,EAAa,SAAA,EAAW,UAAU,QAAA,EAAU,OAAA,EAAS,OAAA,EAAS,WAAA,EAAa,SAAS,CAAA;AAC1H,IAAM,mCAAmB,IAAI,GAAA,CAAI,CAAC,MAAA,EAAQ,OAAA,EAAS,OAAO,CAAC,CAAA;AAE3D,SAAS,gBAAA,GAAqD;AAC5D,EAAA,OAAO;AAAA,IACL,SAAA,sBAAe,GAAA,EAAI;AAAA,IACnB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KAAA,IAAS,OAAO,GAAG,CAAA,SAAU,GAAG,CAAA,CAAE,IAAI,KAAK,CAAA;AAAA,EACxD;AACF;AAEA,SAAS,gBAAA,CAAiB,IAAA,EAAc,YAAA,EAAwB,MAAA,EAA+B,IAAA,EAAuB;AACpH,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,OAAA,CAAQ,IAAI,CAAA;AAClC,EAAA,IAAI,YAAA,CAAa,QAAA,CAAS,QAAQ,CAAA,EAAG,OAAO,IAAA;AAC5C,EAAA,IAAI,CAAC,gBAAA,CAAiB,GAAA,CAAI,IAAA,CAAK,OAAA,CAAQ,QAAQ,CAAA,CAAE,WAAA,EAAa,CAAA,EAAG,OAAO,KAAA;AACxE,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,KAAU,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,OAAA,CAAQ,IAAA,EAAM,KAAA,CAAM,IAAI,CAAC,CAAC,CAAA;AACpF,EAAA,OAAO,UAAU,IAAA,CAAK,CAAC,QAAQ,gBAAA,CAAiB,QAAA,EAAU,GAAG,CAAC,CAAA;AAChE;AAEA,SAAS,gBAAA,CAAiB,UAAkB,IAAA,EAAuB;AACjE,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,OAAA,CAAQ,IAAI,CAAA,EAAG,IAAA,CAAK,OAAA,CAAQ,QAAQ,CAAC,CAAA;AACzE,EAAA,OAAO,QAAA,KAAa,EAAA,IAAO,QAAA,KAAa,EAAA,IAAM,CAAC,QAAA,CAAS,UAAA,CAAW,IAAI,CAAA,IAAK,CAAC,IAAA,CAAK,UAAA,CAAW,QAAQ,CAAA;AACvG","file":"vite.js","sourcesContent":["/**\n * @license\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\n\ntype ViteConfig = { root: string };\ntype ViteServer = {\n watcher: {\n add(paths: string | string[]): void;\n on(event: 'add' | 'change' | 'unlink', listener: (file: string) => void): void;\n };\n};\n\nexport interface MujocoReactPluginOptions {\n /** Entry MJCF/URDF files to scan. Prefer a record for stable per-robot type names. */\n models: ModelInput;\n /** Generated resource module. Defaults to `src/mujoco-register.gen.ts`. */\n generatedRegister?: string;\n /** Module name to augment. Defaults to `mujoco-react`. */\n moduleName?: string;\n /** Disable console output. */\n disableLogging?: boolean;\n}\n\nexport interface MujocoRegisterCodegenOptions {\n models: ModelInput;\n out: string;\n moduleName?: string;\n root?: string;\n}\n\nexport interface MujocoRegisterCodegenResult {\n out: string;\n files: string[];\n counts: Record<RegisterKey, number>;\n}\n\ntype RegisterKey = 'actuators' | 'sensors' | 'bodies' | 'joints' | 'sites' | 'geoms' | 'keyframes' | 'cameras';\nexport type ModelInput = string | readonly string[] | Record<string, string>;\n\ninterface ModelEntry {\n id: string;\n file: string;\n names: Record<RegisterKey, Set<string>>;\n}\n\nconst REGISTER_KEYS: RegisterKey[] = ['actuators', 'sensors', 'bodies', 'joints', 'sites', 'geoms', 'keyframes', 'cameras'];\nconst MODEL_EXTENSIONS = new Set(['.xml', '.mjcf', '.urdf']);\n\nfunction createEmptyNames(): Record<RegisterKey, Set<string>> {\n return {\n actuators: new Set(),\n sensors: new Set(),\n bodies: new Set(),\n joints: new Set(),\n sites: new Set(),\n geoms: new Set(),\n keyframes: new Set(),\n cameras: new Set(),\n };\n}\n\nexport function mujocoReact(options: MujocoReactPluginOptions) {\n const models = normalizeModels(options.models);\n let root = process.cwd();\n let generatedRegister = options.generatedRegister ?? 'src/mujoco-register.gen.ts';\n let watchedFiles: string[] = [];\n\n async function generate() {\n const result = await generateMujocoRegister({\n models: options.models,\n out: generatedRegister,\n moduleName: options.moduleName,\n root,\n });\n watchedFiles = result.files;\n if (!options.disableLogging) {\n const total = Object.values(result.counts).reduce((sum, count) => sum + count, 0);\n console.log(`[mujoco-react] generated ${path.relative(root, result.out)} (${total} names)`);\n }\n return result;\n }\n\n return {\n name: 'mujoco-react',\n enforce: 'pre' as const,\n config(userConfig: { build?: { chunkSizeWarningLimit?: number } }) {\n // three + drei + MuJoCo WASM glue are inherently large; the large-chunk\n // warning is expected, not a failure. Raise the limit so consumers don't\n // see it. Vite merges plugin config on top of user config, so only set a\n // default when the consumer hasn't specified their own limit.\n if (userConfig.build?.chunkSizeWarningLimit !== undefined) return;\n return { build: { chunkSizeWarningLimit: 4000 } };\n },\n configResolved(config: ViteConfig) {\n root = config.root;\n generatedRegister = path.resolve(root, generatedRegister);\n },\n transform(code: string, id: string) {\n if (!shouldInjectRegisterImport(id, root, generatedRegister)) return;\n return `${renderGeneratedImport(id, generatedRegister)}\\n${code}`;\n },\n async buildStart(this: { addWatchFile?: (file: string) => void }) {\n const result = await generate();\n for (const file of result.files) this.addWatchFile?.(file);\n },\n configureServer(server: ViteServer) {\n generate().then((result) => server.watcher.add(result.files)).catch((error: unknown) => {\n console.error('[mujoco-react] register generation failed', error);\n });\n\n server.watcher.on('add', regenerateIfModelFile);\n server.watcher.on('change', regenerateIfModelFile);\n server.watcher.on('unlink', regenerateIfModelFile);\n\n function regenerateIfModelFile(file: string) {\n if (!shouldRegenerate(file, watchedFiles, models, root)) return;\n generate().then((result) => server.watcher.add(result.files)).catch((error: unknown) => {\n console.error('[mujoco-react] register generation failed', error);\n });\n }\n },\n };\n}\n\nexport async function generateMujocoRegister(\n options: MujocoRegisterCodegenOptions\n): Promise<MujocoRegisterCodegenResult> {\n const root = path.resolve(options.root ?? process.cwd());\n const out = path.resolve(root, options.out);\n const moduleName = options.moduleName ?? 'mujoco-react';\n const models = normalizeModels(options.models);\n const names = createEmptyNames();\n const seen = new Set<string>();\n const declarationsOnly = out.endsWith('.d.ts');\n\n for (const model of models) {\n await scanModel(path.resolve(root, model.file), root, seen, model.names);\n mergeNames(names, model.names);\n }\n\n await mkdir(path.dirname(out), { recursive: true });\n await writeFile(out, renderRegister(moduleName, names, models, declarationsOnly), 'utf8');\n\n return {\n out,\n files: [...seen].sort((a, b) => a.localeCompare(b)),\n counts: Object.fromEntries(REGISTER_KEYS.map((key) => [key, names[key].size])) as Record<RegisterKey, number>,\n };\n}\n\nasync function scanModel(\n filePath: string,\n root: string,\n seen: Set<string>,\n names: Record<RegisterKey, Set<string>>\n) {\n const normalized = path.resolve(filePath);\n if (seen.has(normalized)) return;\n seen.add(normalized);\n\n const xml = await readFile(normalized, 'utf8');\n collectSimpleTagNames(xml, 'body', names.bodies);\n collectSimpleTagNames(xml, 'joint', names.joints);\n collectSimpleTagNames(xml, 'site', names.sites);\n collectSimpleTagNames(xml, 'geom', names.geoms);\n collectSimpleTagNames(xml, 'camera', names.cameras);\n collectSimpleTagNames(xml, 'key', names.keyframes);\n collectSectionNames(xml, 'actuator', names.actuators);\n collectSectionNames(xml, 'sensor', names.sensors);\n\n for (const includePath of collectIncludePaths(xml)) {\n const next = path.resolve(path.dirname(normalized), includePath);\n if (isPathInsideRoot(next, root)) await scanModel(next, root, seen, names);\n }\n}\n\nfunction collectSimpleTagNames(xml: string, tag: string, target: Set<string>) {\n const pattern = new RegExp(`<\\\\s*${tag}\\\\b([^>]*)>`, 'gi');\n for (const match of xml.matchAll(pattern)) {\n const name = readAttr(match[1], 'name');\n if (name) target.add(name);\n }\n}\n\nfunction collectSectionNames(xml: string, section: string, target: Set<string>) {\n const sectionPattern = new RegExp(`<\\\\s*${section}\\\\b[^>]*>([\\\\s\\\\S]*?)<\\\\s*/\\\\s*${section}\\\\s*>`, 'gi');\n for (const sectionMatch of xml.matchAll(sectionPattern)) {\n const tagPattern = /<\\s*[a-zA-Z0-9_:-]+\\b([^>]*)>/g;\n for (const tagMatch of sectionMatch[1].matchAll(tagPattern)) {\n const name = readAttr(tagMatch[1], 'name');\n if (name) target.add(name);\n }\n }\n}\n\nfunction collectIncludePaths(xml: string): string[] {\n const result: string[] = [];\n const pattern = /<\\s*include\\b([^>]*)>/gi;\n for (const match of xml.matchAll(pattern)) {\n const file = readAttr(match[1], 'file');\n if (file && !file.includes('://') && !file.startsWith('/')) result.push(file);\n }\n return result;\n}\n\nfunction readAttr(attrs: string, attr: string): string | undefined {\n const pattern = new RegExp(`\\\\b${attr}\\\\s*=\\\\s*(['\"])(.*?)\\\\1`, 'i');\n return attrs.match(pattern)?.[2];\n}\n\nfunction renderRegister(\n moduleName: string,\n names: Record<RegisterKey, Set<string>>,\n models: readonly ModelEntry[],\n declarationsOnly: boolean\n): string {\n const fields = REGISTER_KEYS\n .filter((key) => names[key].size > 0)\n .map((key) => ` ${key}: ${renderUnion(names[key])};`);\n const modelFields = models\n .map((model) => ` ${quoteProperty(model.id)}: {\\n${renderModelFields(model.names)}\\n };`);\n const namespaceAliases = renderNamespaceAliases(models);\n const registerImport = declarationsOnly ? '' : `import { registerModelResources } from '${moduleName}';\\n`;\n const resources = declarationsOnly ? '' : `${renderResourceTypes(models)}\\n\\n${renderResourceConstants(models)}\\n\\nregisterModelResources(generatedModelResources);\\n\\n`;\n\n return `// Auto-generated by mujoco-react. Do not edit.\n// Regenerate by running Vite with the mujocoReact() plugin or \\`mujoco-react codegen\\`.\n\n${registerImport}import type { ModelResource } from '${moduleName}';\n\n${resources}declare module '${moduleName}' {\n interface Register {\n models: {\n${modelFields.join('\\n')}\n };\n${fields.join('\\n')}\n }\n\n${namespaceAliases}\n}\n`;\n}\n\nfunction renderResourceTypes(models: readonly ModelEntry[]): string {\n const modelTypes = models\n .map((model) => ` readonly ${quoteProperty(model.id)}: {\\n${renderResourceTypeFields(model.names)}\\n };`)\n .join('\\n');\n return `type GeneratedModelResources = {\\n${modelTypes}\\n};`;\n}\n\nfunction renderResourceTypeFields(names: Record<RegisterKey, Set<string>>): string {\n return REGISTER_KEYS\n .map((key) => ` readonly ${key}: ${renderResourceObjectType(names[key])};`)\n .join('\\n');\n}\n\nfunction renderResourceObjectType(values: Set<string>): string {\n const entries = sortedValues(values)\n .map((value) => ` readonly ${quoteProperty(value)}: '${escapeTs(value)}';`);\n return entries.length > 0 ? `{\\n${entries.join('\\n')}\\n }` : '{}';\n}\n\nfunction renderResourceConstants(models: readonly ModelEntry[]): string {\n const entries = models\n .map((model) => ` ${quoteProperty(model.id)}: {\\n${renderResourceConstantFields(model.names)}\\n },`)\n .join('\\n');\n return `const generatedModelResources: GeneratedModelResources = {\\n${entries}\\n};`;\n}\n\nfunction renderResourceConstantFields(names: Record<RegisterKey, Set<string>>): string {\n return REGISTER_KEYS\n .map((key) => ` ${key}: ${renderResourceObject(names[key])},`)\n .join('\\n');\n}\n\nfunction renderResourceObject(values: Set<string>): string {\n const entries = sortedValues(values)\n .map((value) => ` ${quoteProperty(value)}: '${escapeTs(value)}',`);\n return entries.length > 0 ? `{\\n${entries.join('\\n')}\\n }` : '{}';\n}\n\nfunction renderModelFields(names: Record<RegisterKey, Set<string>>): string {\n return REGISTER_KEYS\n .map((key) => ` ${key}: ${names[key].size > 0 ? renderUnion(names[key]) : 'never'};`)\n .join('\\n');\n}\n\nfunction renderUnion(values: Set<string>): string {\n return sortedValues(values).map((value) => `'${escapeTs(value)}'`).join(' | ');\n}\n\nfunction renderNamespaceAliases(models: readonly ModelEntry[]): string {\n const namespaces: Record<RegisterKey, string> = {\n actuators: 'ModelActuators',\n sensors: 'ModelSensors',\n bodies: 'ModelBodies',\n joints: 'ModelJoints',\n sites: 'ModelSites',\n geoms: 'ModelGeoms',\n keyframes: 'ModelKeyframes',\n cameras: 'ModelCameras',\n };\n\n const blocks = REGISTER_KEYS\n .map((key) => {\n const modelAliases = models\n .filter((model) => isIdentifier(model.id))\n .map((model) => ` export type ${model.id} = ModelResource<'${escapeTs(model.id)}', '${key}'>;`);\n if (modelAliases.length === 0) return '';\n return ` export namespace ${namespaces[key]} {\\n${modelAliases.join('\\n')}\\n }`;\n })\n .filter(Boolean)\n .join('\\n\\n');\n\n return blocks ? `${blocks}\\n` : '';\n}\n\nfunction escapeTs(value: string): string {\n return value.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\");\n}\n\nfunction sortedValues(values: Set<string>): string[] {\n return [...values].sort((a, b) => a.localeCompare(b));\n}\n\nfunction quoteProperty(value: string): string {\n return isIdentifier(value) ? value : `'${escapeTs(value)}'`;\n}\n\nfunction isIdentifier(value: string): boolean {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);\n}\n\nfunction toPosixPath(value: string): string {\n return value.split(path.sep).join('/');\n}\n\nfunction shouldInjectRegisterImport(id: string, root: string, generatedRegister: string): boolean {\n if (generatedRegister.endsWith('.d.ts')) return false;\n const file = stripQuery(id);\n if (!/\\.[cm]?[jt]sx?$/.test(file)) return false;\n if (file.includes(`${path.sep}node_modules${path.sep}`)) return false;\n const absolute = path.resolve(file);\n if (absolute === generatedRegister) return false;\n return isPathInsideRoot(absolute, root);\n}\n\nfunction renderGeneratedImport(id: string, generatedRegister: string): string {\n const fromDir = path.dirname(stripQuery(id));\n let relative = toPosixPath(path.relative(fromDir, generatedRegister));\n if (!relative.startsWith('.')) relative = `./${relative}`;\n return `import '${relative}';`;\n}\n\nfunction stripQuery(id: string): string {\n return id.split('?')[0];\n}\n\nfunction normalizeModels(input: ModelInput): ModelEntry[] {\n if (typeof input === 'string') return [createModelEntry(deriveModelId(input), input)];\n if (Array.isArray(input)) return input.map((file) => createModelEntry(deriveModelId(file), file));\n return Object.entries(input).map(([id, file]) => createModelEntry(sanitizeModelId(id), file));\n}\n\nfunction createModelEntry(id: string, file: string): ModelEntry {\n return { id, file, names: createEmptyNames() };\n}\n\nfunction deriveModelId(file: string): string {\n const normalized = file.replace(/\\\\/g, '/');\n const parts = normalized.split('/').filter(Boolean);\n const filename = parts.at(-1) ?? 'model';\n const parent = parts.length > 1 ? parts.at(-2) : undefined;\n const base = filename.replace(/\\.(xml|mjcf|urdf)$/i, '');\n return sanitizeModelId(parent && ['scene', 'model', 'robot'].includes(base.toLowerCase()) ? parent : base);\n}\n\nfunction sanitizeModelId(value: string): string {\n const sanitized = value.replace(/[^A-Za-z0-9_$]/g, '_').replace(/^[^A-Za-z_$]+/, '');\n return sanitized || 'model';\n}\n\nfunction mergeNames(target: Record<RegisterKey, Set<string>>, source: Record<RegisterKey, Set<string>>) {\n for (const key of REGISTER_KEYS) {\n for (const value of source[key]) target[key].add(value);\n }\n}\n\nfunction shouldRegenerate(file: string, watchedFiles: string[], models: readonly ModelEntry[], root: string): boolean {\n const absolute = path.resolve(file);\n if (watchedFiles.includes(absolute)) return true;\n if (!MODEL_EXTENSIONS.has(path.extname(absolute).toLowerCase())) return false;\n const modelDirs = models.map((model) => path.dirname(path.resolve(root, model.file)));\n return modelDirs.some((dir) => isPathInsideRoot(absolute, dir));\n}\n\nfunction isPathInsideRoot(filePath: string, root: string): boolean {\n const relative = path.relative(path.resolve(root), path.resolve(filePath));\n return relative === '' || (relative !== '' && !relative.startsWith('..') && !path.isAbsolute(relative));\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/vite.ts"],"names":[],"mappings":";;;;AAiDA,IAAM,aAAA,GAA+B,CAAC,WAAA,EAAa,SAAA,EAAW,UAAU,QAAA,EAAU,OAAA,EAAS,OAAA,EAAS,WAAA,EAAa,SAAS,CAAA;AAC1H,IAAM,mCAAmB,IAAI,GAAA,CAAI,CAAC,MAAA,EAAQ,OAAA,EAAS,OAAO,CAAC,CAAA;AAE3D,SAAS,gBAAA,GAAqD;AAC5D,EAAA,OAAO;AAAA,IACL,SAAA,sBAAe,GAAA,EAAI;AAAA,IACnB,OAAA,sBAAa,GAAA,EAAI;AAAA,IACjB,MAAA,sBAAY,GAAA,EAAI;AAAA,IAChB,MAAA,sBAAY,GAAA,EAAI;AAAA,IAChB,KAAA,sBAAW,GAAA,EAAI;AAAA,IACf,KAAA,sBAAW,GAAA,EAAI;AAAA,IACf,SAAA,sBAAe,GAAA,EAAI;AAAA,IACnB,OAAA,sBAAa,GAAA;AAAI,GACnB;AACF;AAEO,SAAS,YAAY,OAAA,EAAmC;AAC7D,EAAA,MAAM,MAAA,GAAS,eAAA,CAAgB,OAAA,CAAQ,MAAM,CAAA;AAC7C,EAAA,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CAAS,QAAQ,CAAA,EAAG,OAAO,IAAA;AAC5C,EAAA,IAAI,CAAC,gBAAA,CAAiB,GAAA,CAAI,IAAA,CAAK,OAAA,CAAQ,QAAQ,CAAA,CAAE,WAAA,EAAa,CAAA,EAAG,OAAO,KAAA;AACxE,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,KAAU,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,OAAA,CAAQ,IAAA,EAAM,KAAA,CAAM,IAAI,CAAC,CAAC,CAAA;AACpF,EAAA,OAAO,UAAU,IAAA,CAAK,CAAC,QAAQ,gBAAA,CAAiB,QAAA,EAAU,GAAG,CAAC,CAAA;AAChE;AAEA,SAAS,gBAAA,CAAiB,UAAkB,IAAA,EAAuB;AACjE,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,OAAA,CAAQ,IAAI,CAAA,EAAG,IAAA,CAAK,OAAA,CAAQ,QAAQ,CAAC,CAAA;AACzE,EAAA,OAAO,QAAA,KAAa,EAAA,IAAO,QAAA,KAAa,EAAA,IAAM,CAAC,QAAA,CAAS,UAAA,CAAW,IAAI,CAAA,IAAK,CAAC,IAAA,CAAK,UAAA,CAAW,QAAQ,CAAA;AACvG","file":"vite.js","sourcesContent":["/**\n * @license\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\n\ntype ViteConfig = { root: string };\ntype ViteServer = {\n watcher: {\n add(paths: string | string[]): void;\n on(event: 'add' | 'change' | 'unlink', listener: (file: string) => void): void;\n };\n};\n\nexport interface MujocoReactPluginOptions {\n /** Entry MJCF/URDF files to scan. Prefer a record for stable per-robot type names. */\n models: ModelInput;\n /** Generated resource module. Defaults to `src/mujoco-register.gen.ts`. */\n generatedRegister?: string;\n /** Module name to augment. Defaults to `mujoco-react`. */\n moduleName?: string;\n /** Disable console output. */\n disableLogging?: boolean;\n}\n\nexport interface MujocoRegisterCodegenOptions {\n models: ModelInput;\n out: string;\n moduleName?: string;\n root?: string;\n}\n\nexport interface MujocoRegisterCodegenResult {\n out: string;\n files: string[];\n counts: Record<RegisterKey, number>;\n}\n\ntype RegisterKey = 'actuators' | 'sensors' | 'bodies' | 'joints' | 'sites' | 'geoms' | 'keyframes' | 'cameras';\nexport type ModelInput = string | readonly string[] | Record<string, string>;\n\ninterface ModelEntry {\n id: string;\n file: string;\n names: Record<RegisterKey, Set<string>>;\n}\n\nconst REGISTER_KEYS: RegisterKey[] = ['actuators', 'sensors', 'bodies', 'joints', 'sites', 'geoms', 'keyframes', 'cameras'];\nconst MODEL_EXTENSIONS = new Set(['.xml', '.mjcf', '.urdf']);\n\nfunction createEmptyNames(): Record<RegisterKey, Set<string>> {\n return {\n actuators: new Set(),\n sensors: new Set(),\n bodies: new Set(),\n joints: new Set(),\n sites: new Set(),\n geoms: new Set(),\n keyframes: new Set(),\n cameras: new Set(),\n };\n}\n\nexport function mujocoReact(options: MujocoReactPluginOptions) {\n const models = normalizeModels(options.models);\n let root = process.cwd();\n let generatedRegister = options.generatedRegister ?? 'src/mujoco-register.gen.ts';\n let watchedFiles: string[] = [];\n\n async function generate() {\n const result = await generateMujocoRegister({\n models: options.models,\n out: generatedRegister,\n moduleName: options.moduleName,\n root,\n });\n watchedFiles = result.files;\n if (!options.disableLogging) {\n const total = Object.values(result.counts).reduce((sum, count) => sum + count, 0);\n console.log(`[mujoco-react] generated ${path.relative(root, result.out)} (${total} names)`);\n }\n return result;\n }\n\n return {\n name: 'mujoco-react',\n enforce: 'pre' as const,\n config(userConfig: { build?: { chunkSizeWarningLimit?: number } }) {\n // three + drei + MuJoCo WASM glue are inherently large; the large-chunk\n // warning is expected, not a failure. Raise the limit so consumers don't\n // see it. Vite merges plugin config on top of user config, so only set a\n // default when the consumer hasn't specified their own limit.\n return {\n // Keep the worker URL relative to its real package file in dev. Vite's\n // dependency prebundler otherwise relocates it into .vite/deps.\n optimizeDeps: { exclude: ['mujoco-react'] },\n ...(userConfig.build?.chunkSizeWarningLimit === undefined\n ? { build: { chunkSizeWarningLimit: 4000 } } : {}),\n };\n },\n configResolved(config: ViteConfig) {\n root = config.root;\n generatedRegister = path.resolve(root, generatedRegister);\n },\n transform(code: string, id: string) {\n if (!shouldInjectRegisterImport(id, root, generatedRegister)) return;\n return `${renderGeneratedImport(id, generatedRegister)}\\n${code}`;\n },\n async buildStart(this: { addWatchFile?: (file: string) => void }) {\n const result = await generate();\n for (const file of result.files) this.addWatchFile?.(file);\n },\n configureServer(server: ViteServer) {\n generate().then((result) => server.watcher.add(result.files)).catch((error: unknown) => {\n console.error('[mujoco-react] register generation failed', error);\n });\n\n server.watcher.on('add', regenerateIfModelFile);\n server.watcher.on('change', regenerateIfModelFile);\n server.watcher.on('unlink', regenerateIfModelFile);\n\n function regenerateIfModelFile(file: string) {\n if (!shouldRegenerate(file, watchedFiles, models, root)) return;\n generate().then((result) => server.watcher.add(result.files)).catch((error: unknown) => {\n console.error('[mujoco-react] register generation failed', error);\n });\n }\n },\n };\n}\n\nexport async function generateMujocoRegister(\n options: MujocoRegisterCodegenOptions\n): Promise<MujocoRegisterCodegenResult> {\n const root = path.resolve(options.root ?? process.cwd());\n const out = path.resolve(root, options.out);\n const moduleName = options.moduleName ?? 'mujoco-react';\n const models = normalizeModels(options.models);\n const names = createEmptyNames();\n const seen = new Set<string>();\n const declarationsOnly = out.endsWith('.d.ts');\n\n for (const model of models) {\n await scanModel(path.resolve(root, model.file), root, seen, model.names);\n mergeNames(names, model.names);\n }\n\n await mkdir(path.dirname(out), { recursive: true });\n await writeFile(out, renderRegister(moduleName, names, models, declarationsOnly), 'utf8');\n\n return {\n out,\n files: [...seen].sort((a, b) => a.localeCompare(b)),\n counts: Object.fromEntries(REGISTER_KEYS.map((key) => [key, names[key].size])) as Record<RegisterKey, number>,\n };\n}\n\nasync function scanModel(\n filePath: string,\n root: string,\n seen: Set<string>,\n names: Record<RegisterKey, Set<string>>\n) {\n const normalized = path.resolve(filePath);\n if (seen.has(normalized)) return;\n seen.add(normalized);\n\n const xml = await readFile(normalized, 'utf8');\n collectSimpleTagNames(xml, 'body', names.bodies);\n collectSimpleTagNames(xml, 'joint', names.joints);\n collectSimpleTagNames(xml, 'site', names.sites);\n collectSimpleTagNames(xml, 'geom', names.geoms);\n collectSimpleTagNames(xml, 'camera', names.cameras);\n collectSimpleTagNames(xml, 'key', names.keyframes);\n collectSectionNames(xml, 'actuator', names.actuators);\n collectSectionNames(xml, 'sensor', names.sensors);\n\n for (const includePath of collectIncludePaths(xml)) {\n const next = path.resolve(path.dirname(normalized), includePath);\n if (isPathInsideRoot(next, root)) await scanModel(next, root, seen, names);\n }\n}\n\nfunction collectSimpleTagNames(xml: string, tag: string, target: Set<string>) {\n const pattern = new RegExp(`<\\\\s*${tag}\\\\b([^>]*)>`, 'gi');\n for (const match of xml.matchAll(pattern)) {\n const name = readAttr(match[1], 'name');\n if (name) target.add(name);\n }\n}\n\nfunction collectSectionNames(xml: string, section: string, target: Set<string>) {\n const sectionPattern = new RegExp(`<\\\\s*${section}\\\\b[^>]*>([\\\\s\\\\S]*?)<\\\\s*/\\\\s*${section}\\\\s*>`, 'gi');\n for (const sectionMatch of xml.matchAll(sectionPattern)) {\n const tagPattern = /<\\s*[a-zA-Z0-9_:-]+\\b([^>]*)>/g;\n for (const tagMatch of sectionMatch[1].matchAll(tagPattern)) {\n const name = readAttr(tagMatch[1], 'name');\n if (name) target.add(name);\n }\n }\n}\n\nfunction collectIncludePaths(xml: string): string[] {\n const result: string[] = [];\n const pattern = /<\\s*include\\b([^>]*)>/gi;\n for (const match of xml.matchAll(pattern)) {\n const file = readAttr(match[1], 'file');\n if (file && !file.includes('://') && !file.startsWith('/')) result.push(file);\n }\n return result;\n}\n\nfunction readAttr(attrs: string, attr: string): string | undefined {\n const pattern = new RegExp(`\\\\b${attr}\\\\s*=\\\\s*(['\"])(.*?)\\\\1`, 'i');\n return attrs.match(pattern)?.[2];\n}\n\nfunction renderRegister(\n moduleName: string,\n names: Record<RegisterKey, Set<string>>,\n models: readonly ModelEntry[],\n declarationsOnly: boolean\n): string {\n const fields = REGISTER_KEYS\n .filter((key) => names[key].size > 0)\n .map((key) => ` ${key}: ${renderUnion(names[key])};`);\n const modelFields = models\n .map((model) => ` ${quoteProperty(model.id)}: {\\n${renderModelFields(model.names)}\\n };`);\n const namespaceAliases = renderNamespaceAliases(models);\n const registerImport = declarationsOnly ? '' : `import { registerModelResources } from '${moduleName}';\\n`;\n const resources = declarationsOnly ? '' : `${renderResourceTypes(models)}\\n\\n${renderResourceConstants(models)}\\n\\nregisterModelResources(generatedModelResources);\\n\\n`;\n\n return `// Auto-generated by mujoco-react. Do not edit.\n// Regenerate by running Vite with the mujocoReact() plugin or \\`mujoco-react codegen\\`.\n\n${registerImport}import type { ModelResource } from '${moduleName}';\n\n${resources}declare module '${moduleName}' {\n interface Register {\n models: {\n${modelFields.join('\\n')}\n };\n${fields.join('\\n')}\n }\n\n${namespaceAliases}\n}\n`;\n}\n\nfunction renderResourceTypes(models: readonly ModelEntry[]): string {\n const modelTypes = models\n .map((model) => ` readonly ${quoteProperty(model.id)}: {\\n${renderResourceTypeFields(model.names)}\\n };`)\n .join('\\n');\n return `type GeneratedModelResources = {\\n${modelTypes}\\n};`;\n}\n\nfunction renderResourceTypeFields(names: Record<RegisterKey, Set<string>>): string {\n return REGISTER_KEYS\n .map((key) => ` readonly ${key}: ${renderResourceObjectType(names[key])};`)\n .join('\\n');\n}\n\nfunction renderResourceObjectType(values: Set<string>): string {\n const entries = sortedValues(values)\n .map((value) => ` readonly ${quoteProperty(value)}: '${escapeTs(value)}';`);\n return entries.length > 0 ? `{\\n${entries.join('\\n')}\\n }` : '{}';\n}\n\nfunction renderResourceConstants(models: readonly ModelEntry[]): string {\n const entries = models\n .map((model) => ` ${quoteProperty(model.id)}: {\\n${renderResourceConstantFields(model.names)}\\n },`)\n .join('\\n');\n return `const generatedModelResources: GeneratedModelResources = {\\n${entries}\\n};`;\n}\n\nfunction renderResourceConstantFields(names: Record<RegisterKey, Set<string>>): string {\n return REGISTER_KEYS\n .map((key) => ` ${key}: ${renderResourceObject(names[key])},`)\n .join('\\n');\n}\n\nfunction renderResourceObject(values: Set<string>): string {\n const entries = sortedValues(values)\n .map((value) => ` ${quoteProperty(value)}: '${escapeTs(value)}',`);\n return entries.length > 0 ? `{\\n${entries.join('\\n')}\\n }` : '{}';\n}\n\nfunction renderModelFields(names: Record<RegisterKey, Set<string>>): string {\n return REGISTER_KEYS\n .map((key) => ` ${key}: ${names[key].size > 0 ? renderUnion(names[key]) : 'never'};`)\n .join('\\n');\n}\n\nfunction renderUnion(values: Set<string>): string {\n return sortedValues(values).map((value) => `'${escapeTs(value)}'`).join(' | ');\n}\n\nfunction renderNamespaceAliases(models: readonly ModelEntry[]): string {\n const namespaces: Record<RegisterKey, string> = {\n actuators: 'ModelActuators',\n sensors: 'ModelSensors',\n bodies: 'ModelBodies',\n joints: 'ModelJoints',\n sites: 'ModelSites',\n geoms: 'ModelGeoms',\n keyframes: 'ModelKeyframes',\n cameras: 'ModelCameras',\n };\n\n const blocks = REGISTER_KEYS\n .map((key) => {\n const modelAliases = models\n .filter((model) => isIdentifier(model.id))\n .map((model) => ` export type ${model.id} = ModelResource<'${escapeTs(model.id)}', '${key}'>;`);\n if (modelAliases.length === 0) return '';\n return ` export namespace ${namespaces[key]} {\\n${modelAliases.join('\\n')}\\n }`;\n })\n .filter(Boolean)\n .join('\\n\\n');\n\n return blocks ? `${blocks}\\n` : '';\n}\n\nfunction escapeTs(value: string): string {\n return value.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\");\n}\n\nfunction sortedValues(values: Set<string>): string[] {\n return [...values].sort((a, b) => a.localeCompare(b));\n}\n\nfunction quoteProperty(value: string): string {\n return isIdentifier(value) ? value : `'${escapeTs(value)}'`;\n}\n\nfunction isIdentifier(value: string): boolean {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);\n}\n\nfunction toPosixPath(value: string): string {\n return value.split(path.sep).join('/');\n}\n\nfunction shouldInjectRegisterImport(id: string, root: string, generatedRegister: string): boolean {\n if (generatedRegister.endsWith('.d.ts')) return false;\n const file = stripQuery(id);\n if (!/\\.[cm]?[jt]sx?$/.test(file)) return false;\n if (file.includes(`${path.sep}node_modules${path.sep}`)) return false;\n const absolute = path.resolve(file);\n if (absolute === generatedRegister) return false;\n return isPathInsideRoot(absolute, root);\n}\n\nfunction renderGeneratedImport(id: string, generatedRegister: string): string {\n const fromDir = path.dirname(stripQuery(id));\n let relative = toPosixPath(path.relative(fromDir, generatedRegister));\n if (!relative.startsWith('.')) relative = `./${relative}`;\n return `import '${relative}';`;\n}\n\nfunction stripQuery(id: string): string {\n return id.split('?')[0];\n}\n\nfunction normalizeModels(input: ModelInput): ModelEntry[] {\n if (typeof input === 'string') return [createModelEntry(deriveModelId(input), input)];\n if (Array.isArray(input)) return input.map((file) => createModelEntry(deriveModelId(file), file));\n return Object.entries(input).map(([id, file]) => createModelEntry(sanitizeModelId(id), file));\n}\n\nfunction createModelEntry(id: string, file: string): ModelEntry {\n return { id, file, names: createEmptyNames() };\n}\n\nfunction deriveModelId(file: string): string {\n const normalized = file.replace(/\\\\/g, '/');\n const parts = normalized.split('/').filter(Boolean);\n const filename = parts.at(-1) ?? 'model';\n const parent = parts.length > 1 ? parts.at(-2) : undefined;\n const base = filename.replace(/\\.(xml|mjcf|urdf)$/i, '');\n return sanitizeModelId(parent && ['scene', 'model', 'robot'].includes(base.toLowerCase()) ? parent : base);\n}\n\nfunction sanitizeModelId(value: string): string {\n const sanitized = value.replace(/[^A-Za-z0-9_$]/g, '_').replace(/^[^A-Za-z_$]+/, '');\n return sanitized || 'model';\n}\n\nfunction mergeNames(target: Record<RegisterKey, Set<string>>, source: Record<RegisterKey, Set<string>>) {\n for (const key of REGISTER_KEYS) {\n for (const value of source[key]) target[key].add(value);\n }\n}\n\nfunction shouldRegenerate(file: string, watchedFiles: string[], models: readonly ModelEntry[], root: string): boolean {\n const absolute = path.resolve(file);\n if (watchedFiles.includes(absolute)) return true;\n if (!MODEL_EXTENSIONS.has(path.extname(absolute).toLowerCase())) return false;\n const modelDirs = models.map((model) => path.dirname(path.resolve(root, model.file)));\n return modelDirs.some((dir) => isPathInsideRoot(absolute, dir));\n}\n\nfunction isPathInsideRoot(filePath: string, root: string): boolean {\n const relative = path.relative(path.resolve(root), path.resolve(filePath));\n return relative === '' || (relative !== '' && !relative.startsWith('..') && !path.isAbsolute(relative));\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mujoco-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.1.0",
|
|
4
4
|
"description": "Composable React Three Fiber building blocks for MuJoCo WASM simulations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
"types": "./dist/onnx.d.ts",
|
|
32
32
|
"default": "./dist/onnx.js"
|
|
33
33
|
}
|
|
34
|
+
},
|
|
35
|
+
"./physics.worker": {
|
|
36
|
+
"import": "./dist/physics.worker.js"
|
|
34
37
|
}
|
|
35
38
|
},
|
|
36
39
|
"bin": {
|
|
@@ -63,7 +66,7 @@
|
|
|
63
66
|
"build": "tsup",
|
|
64
67
|
"dev": "tsup --watch",
|
|
65
68
|
"typecheck": "tsc --noEmit",
|
|
66
|
-
"test:runtime": "tsup --config tests/tsup.config.ts && node --test .test-dist/runtime.js"
|
|
69
|
+
"test:runtime": "tsup --config tests/tsup.config.ts && node --test .test-dist/runtime.js .test-dist/simulation-runtime.js"
|
|
67
70
|
},
|
|
68
71
|
"peerDependencies": {
|
|
69
72
|
"@react-three/drei": ">=9",
|
|
@@ -82,7 +85,7 @@
|
|
|
82
85
|
}
|
|
83
86
|
},
|
|
84
87
|
"dependencies": {
|
|
85
|
-
"@mujoco/mujoco": "
|
|
88
|
+
"@mujoco/mujoco": "4.0.1"
|
|
86
89
|
},
|
|
87
90
|
"devDependencies": {
|
|
88
91
|
"@react-three/drei": "^10.7.7",
|
|
@@ -86,8 +86,11 @@ function CameraViewportRenderer({
|
|
|
86
86
|
const mujoco = useMujoco();
|
|
87
87
|
|
|
88
88
|
useFrame(() => {
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
// WebGLRenderer applies its pixel ratio in setViewport/setScissor. Pass
|
|
90
|
+
// logical pixels here; drawing-buffer dimensions would apply DPR twice.
|
|
91
|
+
const dpr = gl.getPixelRatio();
|
|
92
|
+
const drawWidth = gl.domElement.width / dpr;
|
|
93
|
+
const drawHeight = gl.domElement.height / dpr;
|
|
91
94
|
|
|
92
95
|
// We own the render now: draw the main scene full-frame first.
|
|
93
96
|
gl.setScissorTest(false);
|
|
@@ -97,7 +100,6 @@ function CameraViewportRenderer({
|
|
|
97
100
|
const api = mujoco.api;
|
|
98
101
|
if (!api || viewportsRef.current.size === 0) return;
|
|
99
102
|
|
|
100
|
-
const dpr = gl.getPixelRatio();
|
|
101
103
|
const canvasRect = gl.domElement.getBoundingClientRect();
|
|
102
104
|
|
|
103
105
|
for (const descriptor of viewportsRef.current.values()) {
|
|
@@ -112,12 +114,12 @@ function CameraViewportRenderer({
|
|
|
112
114
|
rect.left > canvasRect.right;
|
|
113
115
|
if (isOffscreen) continue;
|
|
114
116
|
|
|
115
|
-
const width =
|
|
116
|
-
const height =
|
|
117
|
+
const width = rect.width;
|
|
118
|
+
const height = rect.height;
|
|
117
119
|
if (width <= 0 || height <= 0) continue;
|
|
118
120
|
|
|
119
|
-
const left =
|
|
120
|
-
const bottom =
|
|
121
|
+
const left = rect.left - canvasRect.left;
|
|
122
|
+
const bottom = canvasRect.bottom - rect.bottom;
|
|
121
123
|
|
|
122
124
|
let resolved: CameraFrameCaptureOptions;
|
|
123
125
|
try {
|
|
@@ -29,6 +29,7 @@ export const MujocoCanvas = forwardRef<MujocoSimAPI, MujocoCanvasProps>(
|
|
|
29
29
|
timestep,
|
|
30
30
|
integrator,
|
|
31
31
|
substeps,
|
|
32
|
+
physicsBudgetMs,
|
|
32
33
|
paused,
|
|
33
34
|
speed,
|
|
34
35
|
interpolate,
|
|
@@ -74,6 +75,7 @@ export const MujocoCanvas = forwardRef<MujocoSimAPI, MujocoCanvasProps>(
|
|
|
74
75
|
timestep={timestep}
|
|
75
76
|
integrator={integrator}
|
|
76
77
|
substeps={substeps}
|
|
78
|
+
physicsBudgetMs={physicsBudgetMs}
|
|
77
79
|
paused={paused}
|
|
78
80
|
speed={speed}
|
|
79
81
|
interpolate={interpolate}
|