mujoco-react 8.11.0 → 9.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 CHANGED
@@ -154,7 +154,7 @@ import { ScenarioLighting, VisualScenarioEffects } from "mujoco-react";
154
154
  <MujocoCanvas config={sceneConfig}>
155
155
  <VisualScenarioEffects
156
156
  scenario={scenario}
157
- materialFilter={(object) => object.name.startsWith("prop_")}
157
+ materialFilter={({ object }) => object.name.startsWith("prop_")}
158
158
  />
159
159
  <ScenarioLighting preset={scenario.lighting} />
160
160
  </MujocoCanvas>;
@@ -216,7 +216,7 @@ function Scene() {
216
216
  import { useBeforePhysicsStep } from "mujoco-react";
217
217
 
218
218
  function MyController() {
219
- useBeforePhysicsStep((_model, data) => {
219
+ useBeforePhysicsStep(({ data }) => {
220
220
  data.ctrl[0] = Math.sin(data.time);
221
221
  });
222
222
 
@@ -284,7 +284,7 @@ import type { ControlGroupInfo } from "mujoco-react";
284
284
  function HoldTcpPose() {
285
285
  const armRef = useRef<ControlGroupInfo | null>(null);
286
286
 
287
- useBeforePhysicsStep((model, data) => {
287
+ useBeforePhysicsStep(({ model, data }) => {
288
288
  armRef.current ??= resolveControlGroup(model, { siteName: RobotSites.franka.tcp });
289
289
  if (!armRef.current) return;
290
290
 
@@ -305,7 +305,7 @@ Build policy-ready observation vectors from common MuJoCo state without hard-cod
305
305
  import { buildObservation, useBeforePhysicsStep } from "mujoco-react";
306
306
 
307
307
  function PolicyDriver() {
308
- useBeforePhysicsStep((model, data) => {
308
+ useBeforePhysicsStep(({ model, data }) => {
309
309
  const obs = buildObservation(model, data, {
310
310
  qpos: true,
311
311
  qvel: true,
@@ -361,7 +361,7 @@ function useWebSocketControls(url: string) {
361
361
  }, [url]);
362
362
 
363
363
  // Apply incoming actuator controls each physics step.
364
- useBeforePhysicsStep((model, data) => {
364
+ useBeforePhysicsStep(({ model, data }) => {
365
365
  const ctrl = latestCtrlRef.current;
366
366
  if (!ctrl) return;
367
367
  for (let i = 0; i < Math.min(ctrl.length, model.nu); i++) {
@@ -370,7 +370,7 @@ function useWebSocketControls(url: string) {
370
370
  });
371
371
 
372
372
  // Send simulation feedback back after physics.
373
- useAfterPhysicsStep((model, data) => {
373
+ useAfterPhysicsStep(({ data }) => {
374
374
  const ws = wsRef.current;
375
375
  if (!ws || ws.readyState !== WebSocket.OPEN) return;
376
376
 
@@ -433,8 +433,8 @@ The built-in `useIkController()` uses Damped Least-Squares. Pass `ikSolveFn` to
433
433
  import { RobotSites } from "mujoco-react";
434
434
  import type { IKSolveFn } from "mujoco-react";
435
435
 
436
- const myIK: IKSolveFn = (pos, quat, currentQ) => {
437
- return myAnalyticalSolver(pos, currentQ); // return joint angles or null
436
+ const myIK: IKSolveFn = ({ position, currentQ }) => {
437
+ return myAnalyticalSolver(position, currentQ); // return joint angles or null
438
438
  };
439
439
 
440
440
  const ik = useIkController({ siteName: RobotSites.franka.tcp, ikSolveFn: myIK });
@@ -526,7 +526,7 @@ interface SceneConfig {
526
526
  sceneObjects?: SceneObject[]; // Objects injected into scene XML at load time
527
527
  homeJoints?: number[]; // Initial joint positions
528
528
  xmlPatches?: XmlPatch[]; // Patches applied to XML files during loading
529
- onReset?: (model, data) => void; // Called during reset after mj_resetData
529
+ onReset?: ({ model, data }) => void; // Called during reset after mj_resetData
530
530
  }
531
531
  ```
532
532
 
@@ -636,10 +636,10 @@ Thin wrapper around R3F `<Canvas>`. Accepts all R3F Canvas props plus:
636
636
  | Prop | Type | Description |
637
637
  |------|------|-------------|
638
638
  | `config` | `SceneConfig` | **Required.** Scene/robot configuration |
639
- | `onReady` | `(api: MujocoSimAPI) => void` | Fires when model is loaded |
639
+ | `onReady` | `({ api }) => void` | Fires when model is loaded |
640
640
  | `onError` | `(error: Error) => void` | Fires on scene load failure |
641
- | `onStep` | `(time: number) => void` | Called each physics step |
642
- | `onSelection` | `(bodyId: number, name: string) => void` | Called on double-click |
641
+ | `onStep` | `({ time, model, data }) => void` | Called each physics step |
642
+ | `onSelection` | `({ bodyId, name }) => void` | Called on double-click |
643
643
  | `gravity` | `[number, number, number]` | Override model gravity |
644
644
  | `timestep` | `number` | Override model.opt.timestep |
645
645
  | `substeps` | `number` | mj_step calls per frame |
@@ -664,10 +664,10 @@ Physics provider for use inside your own R3F `<Canvas>`. Same physics props as `
664
664
  | Prop | Type | Description |
665
665
  |------|------|-------------|
666
666
  | `config` | `SceneConfig` | **Required.** Scene/robot configuration |
667
- | `onReady` | `(api: MujocoSimAPI) => void` | Fires when model is loaded |
667
+ | `onReady` | `({ api }) => void` | Fires when model is loaded |
668
668
  | `onError` | `(error: Error) => void` | Fires on scene load failure |
669
- | `onStep` | `(time: number) => void` | Called each physics step |
670
- | `onSelection` | `(bodyId: number, name: string) => void` | Called on double-click |
669
+ | `onStep` | `({ time, model, data }) => void` | Called each physics step |
670
+ | `onSelection` | `({ bodyId, name }) => void` | Called on double-click |
671
671
  | `gravity` | `[number, number, number]` | Override model gravity |
672
672
  | `timestep` | `number` | Override model.opt.timestep |
673
673
  | `substeps` | `number` | mj_step calls per frame |
@@ -715,7 +715,7 @@ drei PivotControls gizmo that tracks a MuJoCo site and drives IK on drag. Requir
715
715
  | `controller` | `IkContextValue` | **required** | Controller from `useIkController()` |
716
716
  | `siteName` | `string?` | controller's site | MuJoCo site to track |
717
717
  | `scale` | `number?` | `0.18` | Gizmo handle scale |
718
- | `onDrag` | `(pos, quat) => void` | -- | Custom drag handler (disables auto-IK) |
718
+ | `onDrag` | `({ position, quaternion }) => void` | -- | Custom drag handler (disables auto-IK) |
719
719
 
720
720
  ### `<DragInteraction />`
721
721
 
@@ -826,7 +826,7 @@ if (mujoco) {
826
826
  Run logic **before** `mj_step` each frame. Write to `data.ctrl`, apply forces, drive automation.
827
827
 
828
828
  ```tsx
829
- useBeforePhysicsStep((model, data) => {
829
+ useBeforePhysicsStep(({ data }) => {
830
830
  data.ctrl[0] = Math.sin(data.time);
831
831
  });
832
832
  ```
@@ -983,6 +983,20 @@ const video = useVideoRecorder({ fps: 30, mimeType: "video/webm" });
983
983
  // video.start(), video.stop() -> returns Blob
984
984
  ```
985
985
 
986
+ ### Frame Capture
987
+
988
+ Capture dataset/debug stills from the rendered MuJoCo canvas:
989
+
990
+ ```tsx
991
+ const apiRef = useRef<MujocoSimAPI>(null);
992
+
993
+ const frame = await apiRef.current?.captureFrame({ type: "image/png" });
994
+ const blob = await apiRef.current?.captureFrameBlob({ type: "image/png" });
995
+ ```
996
+
997
+ Use `useFrameCapture()` or the standalone `captureFrame()` helpers when you own
998
+ the canvas or want to capture a custom container.
999
+
986
1000
  ### `useCtrlNoise(config)`
987
1001
 
988
1002
  Apply Gaussian noise to controls for robustness testing:
@@ -1104,7 +1118,10 @@ The full API object available via `ref` or `useMujoco()` (when `isReady`):
1104
1118
  |--------|-------------|
1105
1119
  | `raycast(origin, direction, maxDist?)` | Physics raycast via `mj_ray` |
1106
1120
  | `project2DTo3D(x, y, camPos, lookAt)` | Screen-to-world raycast (returns bodyId + geomId) |
1121
+ | `getCanvas()` | Return the underlying R3F canvas element |
1107
1122
  | `getCanvasSnapshot(w?, h?, mime?)` | Base64 screenshot |
1123
+ | `captureFrame(options?)` | Capture the canvas as a data URL |
1124
+ | `captureFrameBlob(options?)` | Capture the canvas as a Blob |
1108
1125
 
1109
1126
  ### Scene Management
1110
1127
 
@@ -341,7 +341,7 @@ function applyScenarioMaterials(scene, scenario, snapshots, materialFilter) {
341
341
  for (const material of normalizeMaterials(object.material)) {
342
342
  const mutable = getMutableScenarioMaterial(material);
343
343
  if (!mutable) continue;
344
- if (materialFilter && !materialFilter(object, material)) continue;
344
+ if (materialFilter && !materialFilter({ object, material })) continue;
345
345
  if (!snapshots.has(material)) {
346
346
  snapshots.set(material, {
347
347
  color: mutable.color.clone(),
@@ -396,5 +396,5 @@ function clamp01(value) {
396
396
  */
397
397
 
398
398
  export { ScenarioLighting, SplatEnvironment, VisualScenarioEffects, createPairedSplatEnvironment, createSparkSplatViewerUrl, createSplatEnvironmentUserData, getScenarioBackground, getScenarioCameraPosition, useSplatEnvironment, useVisualScenarioEffects, withSplatEnvironment };
399
- //# sourceMappingURL=chunk-SEWQULWO.js.map
400
- //# sourceMappingURL=chunk-SEWQULWO.js.map
399
+ //# sourceMappingURL=chunk-33CV6HSV.js.map
400
+ //# sourceMappingURL=chunk-33CV6HSV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/VisualScenario.tsx"],"names":[],"mappings":";;;;;;AA2BA,IAAM,kBAAA,GAAqB,SAAA;AAEpB,SAAS,gBAAA,CAAiB;AAAA,EAC/B,MAAA,GAAS,QAAA;AAAA,EACT,UAAA,GAAa,IAAA;AAAA,EACb,SAAA,GAAY;AACd,CAAA,EAA0B;AACxB,EAAA,IAAI,WAAW,WAAA,EAAa;AAC1B,IAAA,uBACE,IAAA,CAAA,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,sBAAA,GAAA,CAAC,cAAA,EAAA,EAAa,SAAA,EAAW,IAAA,GAAO,SAAA,EAAW,CAAA;AAAA,sBAC3C,GAAA;AAAA,QAAC,kBAAA;AAAA,QAAA;AAAA,UACC,QAAA,EAAU,CAAC,GAAA,EAAK,EAAA,EAAI,CAAC,CAAA;AAAA,UACrB,WAAW,GAAA,GAAM,SAAA;AAAA,UACjB;AAAA;AAAA,OACF;AAAA,sBACA,GAAA,CAAC,kBAAA,EAAA,EAAiB,QAAA,EAAU,CAAC,EAAA,EAAI,KAAK,GAAG,CAAA,EAAG,SAAA,EAAW,IAAA,GAAO,SAAA,EAAW;AAAA,KAAA,EAC3E,CAAA;AAAA,EAEJ;AAEA,EAAA,IAAI,WAAW,WAAA,EAAa;AAC1B,IAAA,uBACE,IAAA,CAAA,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,sBAAA,GAAA,CAAC,cAAA,EAAA,EAAa,SAAA,EAAW,IAAA,GAAO,SAAA,EAAW,CAAA;AAAA,sBAC3C,GAAA;AAAA,QAAC,kBAAA;AAAA,QA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AA,IAAI,IAAA,GAAO,UAAA;AACX,EAAA,KAAA,IAAS,QAAQ,CAAA,EAAG,KAAA,GAAQ,KAAA,CAAM,MAAA,EAAQ,SAAS,CAAA,EAAG;AACpD,IAAA,IAAA,IAAQ,KAAA,CAAM,WAAW,KAAK,CAAA;AAC9B,IAAA,IAAA,GAAO,IAAA,CAAK,IAAA,CAAK,IAAA,EAAM,QAAQ,CAAA;AAAA,EACjC;AACA,EAAA,OAAA,CAAQ,SAAS,CAAA,IAAK,UAAA;AACxB;AAEA,SAAS,QAAQ,KAAA,EAAe;AAC9B,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAC,CAAA;AACvC","file":"chunk-33CV6HSV.js","sourcesContent":["/**\n * @license\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { useThree } from '@react-three/fiber';\nimport type { ThreeElements } from '@react-three/fiber';\nimport type { ReactNode } from 'react';\nimport { useEffect, useMemo } from 'react';\nimport * as THREE from 'three';\nimport type {\n PairedSplatEnvironmentConfig,\n ScenarioMaterialConfig,\n SceneConfig,\n SplatCollisionProxyConfig,\n SplatEnvironmentMetadata,\n SplatEnvironmentMetadataInput,\n SplatFormat,\n SplatRendererKind,\n SplatSceneInput,\n ScenarioLightingPreset,\n ScenarioLightingProps,\n SplatEnvironmentProps,\n VisualScenarioConfig,\n VisualScenarioEffectsProps,\n} from '../types';\n\nconst DEFAULT_BACKGROUND = '#181a1f';\n\nexport function ScenarioLighting({\n preset = 'studio',\n castShadow = true,\n intensity = 1,\n}: ScenarioLightingProps) {\n if (preset === 'warehouse') {\n return (\n <>\n <ambientLight intensity={0.18 * intensity} />\n <directionalLight\n position={[3.5, -2, 5]}\n intensity={2.2 * intensity}\n castShadow={castShadow}\n />\n <directionalLight position={[-2, 1.5, 2.5]} intensity={0.25 * intensity} />\n </>\n );\n }\n\n if (preset === 'low-light') {\n return (\n <>\n <ambientLight intensity={0.08 * intensity} />\n <directionalLight\n position={[2, -2, 3]}\n intensity={0.75 * intensity}\n castShadow={castShadow}\n />\n <pointLight position={[-0.5, -0.8, 1.3]} intensity={0.6 * intensity} />\n </>\n );\n }\n\n if (preset === 'splat') {\n return (\n <>\n <ambientLight intensity={0.42 * intensity} />\n <directionalLight\n position={[1.8, -2.4, 3.5]}\n intensity={1.2 * intensity}\n castShadow={castShadow}\n />\n <pointLight position={[0.4, 0.2, 1.4]} intensity={0.35 * intensity} />\n </>\n );\n }\n\n return (\n <>\n <ambientLight intensity={0.35 * intensity} />\n <directionalLight\n position={[2.5, -3, 4]}\n intensity={1.6 * intensity}\n castShadow={castShadow}\n />\n </>\n );\n}\n\nexport function getScenarioBackground(\n preset: ScenarioLightingPreset | undefined,\n fallback = DEFAULT_BACKGROUND\n) {\n if (preset === 'warehouse') return '#20242b';\n if (preset === 'low-light') return '#0f1115';\n if (preset === 'splat') return '#1b1f24';\n return fallback;\n}\n\nexport function getScenarioCameraPosition(\n basePosition: readonly [number, number, number],\n scenario?: Pick<VisualScenarioConfig, 'camera'>\n): [number, number, number] {\n const [x, y, z] = basePosition;\n const jitter = scenario?.camera?.jitter ?? 0;\n\n return [\n Number((x + jitter * 0.6).toFixed(3)),\n Number((y - jitter * 0.4).toFixed(3)),\n Number((z + jitter * 0.25).toFixed(3)),\n ];\n}\n\nexport function VisualScenarioEffects(props: VisualScenarioEffectsProps) {\n useVisualScenarioEffects(props);\n return null;\n}\n\nexport function useVisualScenarioEffects({\n scenario,\n enabled = true,\n applyBackground = true,\n applyFog = true,\n applyRenderer = true,\n applyMaterials = true,\n background,\n fogNear,\n fogFar,\n materialFilter,\n}: VisualScenarioEffectsProps) {\n const { gl, scene, invalidate } = useThree();\n\n useEffect(() => {\n if (!enabled || !scenario) {\n return undefined;\n }\n\n const previousExposure = gl.toneMappingExposure;\n const previousBackground = scene.background;\n const previousFog = scene.fog;\n const materialSnapshots = new Map<\n THREE.Material,\n {\n color?: THREE.Color;\n roughness?: number;\n metalness?: number;\n }\n >();\n\n if (applyRenderer) {\n gl.toneMappingExposure = scenario.camera?.exposure ?? 1;\n }\n\n if (applyBackground) {\n scene.background = new THREE.Color(\n background ?? getScenarioBackground(scenario.lighting)\n );\n }\n\n if (applyFog) {\n scene.fog = createScenarioFog(scenario, background, fogNear, fogFar);\n }\n\n if (applyMaterials && scenario.materials) {\n applyScenarioMaterials(scene, scenario, materialSnapshots, materialFilter);\n }\n\n invalidate();\n\n return () => {\n gl.toneMappingExposure = previousExposure;\n scene.background = previousBackground;\n scene.fog = previousFog;\n\n for (const [material, snapshot] of materialSnapshots) {\n const mutable = getMutableScenarioMaterial(material);\n if (!mutable) continue;\n if (snapshot.color) mutable.color.copy(snapshot.color);\n if (typeof snapshot.roughness === 'number') {\n mutable.roughness = snapshot.roughness;\n }\n if (typeof snapshot.metalness === 'number') {\n mutable.metalness = snapshot.metalness;\n }\n mutable.needsUpdate = true;\n }\n\n invalidate();\n };\n }, [\n applyBackground,\n applyFog,\n applyMaterials,\n applyRenderer,\n background,\n enabled,\n fogFar,\n fogNear,\n gl,\n invalidate,\n materialFilter,\n scenario,\n scene,\n ]);\n}\n\n/**\n * Renderer-agnostic Gaussian splat environment boundary.\n *\n * This component intentionally does not import a specific 3DGS renderer. Pass a\n * Spark/GaussianSplats3D object as `children` once the app chooses a renderer,\n * and pass MuJoCo/MJCF collision proxy visuals via `collisionProxy`.\n */\nexport function SplatEnvironment({\n environment,\n scenario,\n renderer,\n src,\n format,\n collisionProxy,\n collisionProxyMetadata,\n children,\n showPlaceholder = true,\n ...groupProps\n}: SplatEnvironmentProps) {\n const metadata = useSplatEnvironment({\n environment,\n scenario,\n renderer,\n src,\n format,\n collisionProxy: collisionProxyMetadata,\n });\n const existingUserData =\n typeof groupProps.userData === 'object' && groupProps.userData !== null\n ? groupProps.userData\n : {};\n\n return (\n <group\n {...groupProps}\n userData={{\n ...existingUserData,\n ...metadata.userData,\n }}\n >\n {children}\n {children || !showPlaceholder ? null : <SplatPlaceholder />}\n {collisionProxy}\n </group>\n );\n}\n\nexport function useSplatEnvironment({\n environment,\n scenario,\n renderer,\n src,\n format,\n collisionProxy,\n}: SplatEnvironmentMetadataInput): SplatEnvironmentMetadata {\n const scenarioEnvironment = useMemo(\n () =>\n environment ??\n (scenario\n ? createPairedSplatEnvironment(scenario, { renderer })\n : undefined),\n [environment, renderer, scenario]\n );\n const resolvedSrc = src ?? scenarioEnvironment?.splat.src ?? scenario?.splat?.src;\n const resolvedFormat =\n format ??\n scenarioEnvironment?.splat.format ??\n scenario?.splat?.format ??\n 'spz';\n const resolvedCollisionProxy =\n collisionProxy ??\n scenarioEnvironment?.collisionProxy ??\n scenario?.splat?.collisionProxy ??\n undefined;\n\n return useMemo(\n () => ({\n src: resolvedSrc,\n format: resolvedFormat,\n collisionProxy: resolvedCollisionProxy,\n userData: createSplatEnvironmentUserData({\n environment: scenarioEnvironment,\n src: resolvedSrc,\n format: resolvedFormat,\n collisionProxy: resolvedCollisionProxy,\n }),\n }),\n [scenarioEnvironment, resolvedSrc, resolvedFormat, resolvedCollisionProxy]\n );\n}\n\n/**\n * Convert a generic visual scenario splat block into a paired visual/physics\n * environment config. Returns undefined until both the splat asset and MJCF\n * collision proxy are present.\n */\nexport function createPairedSplatEnvironment(\n scenario: Pick<VisualScenarioConfig, 'id' | 'label' | 'environment' | 'splat'>,\n options: {\n id?: string;\n label?: string;\n description?: string;\n renderer?: SplatRendererKind;\n } = {}\n): PairedSplatEnvironmentConfig | undefined {\n const splat = scenario.splat;\n const collisionProxy = splat?.collisionProxy;\n\n if (!splat?.enabled || !splat.src || !collisionProxy?.xmlPath) {\n return undefined;\n }\n\n return {\n id: options.id ?? scenario.id ?? 'splat-environment',\n label: options.label ?? scenario.label ?? 'Gaussian splat environment',\n description:\n options.description ??\n (scenario.environment\n ? `Visual ${scenario.environment} splat paired with MJCF collision proxy.`\n : undefined),\n splat: {\n src: splat.src,\n format: splat.format ?? 'spz',\n renderer: options.renderer,\n },\n collisionProxy: {\n ...collisionProxy,\n xmlPath: collisionProxy.xmlPath,\n },\n };\n}\n\nfunction isPairedSplatEnvironment(input: SplatSceneInput): input is PairedSplatEnvironmentConfig {\n return !!input && 'collisionProxy' in input && 'splat' in input;\n}\n\nfunction sceneRelativePath(sceneConfig: SceneConfig, path: string): string {\n const src = sceneConfig.src;\n if (!src) return path;\n\n const base = src.endsWith('/') ? src : src + '/';\n if (path.startsWith(base)) return path.slice(base.length);\n return path;\n}\n\nfunction uniquePaths(paths: readonly string[]): string[] {\n const seen = new Set<string>();\n const result: string[] = [];\n for (const path of paths) {\n if (seen.has(path)) continue;\n seen.add(path);\n result.push(path);\n }\n return result;\n}\n\n/**\n * Compose a MuJoCo scene config with a paired splat collision proxy.\n *\n * This keeps the common hybrid setup declarative:\n * robot XML remains `sceneFile`, the `.spz` remains a visual-only layer, and\n * the paired MJCF collision proxy is added to `environmentFiles`.\n */\nexport function withSplatEnvironment(\n sceneConfig: SceneConfig,\n input: SplatSceneInput,\n options: { renderer?: SplatRendererKind } = {}\n): SceneConfig {\n const environment = isPairedSplatEnvironment(input)\n ? input\n : input\n ? createPairedSplatEnvironment(input, options)\n : undefined;\n const xmlPath = environment?.collisionProxy.xmlPath;\n if (!xmlPath) return sceneConfig;\n\n return {\n ...sceneConfig,\n environmentFiles: uniquePaths([\n ...(sceneConfig.environmentFiles ?? []),\n sceneRelativePath(sceneConfig, xmlPath),\n ]),\n };\n}\n\nexport function createSplatEnvironmentUserData({\n environment,\n src,\n format = 'spz',\n collisionProxy,\n}: {\n environment?: PairedSplatEnvironmentConfig;\n src?: string;\n format?: SplatFormat;\n collisionProxy?: SplatCollisionProxyConfig;\n}) {\n return {\n role: 'splat-environment',\n environmentId: environment?.id,\n environmentLabel: environment?.label,\n splatSrc: src,\n splatFormat: format,\n splatRenderer: environment?.splat.renderer,\n collisionProxyStatus: collisionProxy?.status ?? 'missing',\n collisionProxyXmlPath: collisionProxy?.xmlPath,\n collisionProxyPrimitives: collisionProxy?.primitives ?? [],\n };\n}\n\nexport function createSparkSplatViewerUrl({\n viewerUrl,\n splatSrc,\n}: {\n viewerUrl: string;\n splatSrc: string;\n}) {\n const url = new URL(viewerUrl, 'http://mujoco-react.local');\n url.searchParams.set('splat', splatSrc);\n return viewerUrl.startsWith('http') ? url.toString() : `${url.pathname}${url.search}`;\n}\n\nfunction SplatPlaceholder() {\n return (\n <group>\n <mesh position={[0, 0, 1.2]}>\n <boxGeometry args={[2.4, 2.4, 2.4]} />\n <meshBasicMaterial\n color=\"#8b8b8b\"\n transparent\n opacity={0.06}\n wireframe\n side={THREE.DoubleSide}\n />\n </mesh>\n </group>\n );\n}\n\nfunction createScenarioFog(\n scenario: VisualScenarioConfig,\n background: THREE.ColorRepresentation | undefined,\n fogNear: number | undefined,\n fogFar: number | undefined\n) {\n if (scenario.lighting === 'low-light') {\n return new THREE.Fog(\n background ?? getScenarioBackground(scenario.lighting),\n fogNear ?? 2.5,\n fogFar ?? 9\n );\n }\n\n if (scenario.lighting === 'warehouse') {\n return new THREE.Fog(\n background ?? getScenarioBackground(scenario.lighting),\n fogNear ?? 5,\n fogFar ?? 16\n );\n }\n\n return null;\n}\n\nfunction applyScenarioMaterials(\n scene: THREE.Scene,\n scenario: VisualScenarioConfig,\n snapshots: Map<\n THREE.Material,\n {\n color?: THREE.Color;\n roughness?: number;\n metalness?: number;\n }\n >,\n materialFilter: VisualScenarioEffectsProps['materialFilter']\n) {\n const materials = scenario.materials;\n if (!materials) return;\n\n scene.traverse((object) => {\n if (!(object instanceof THREE.Mesh)) {\n return;\n }\n\n for (const material of normalizeMaterials(object.material)) {\n const mutable = getMutableScenarioMaterial(material);\n if (!mutable) continue;\n if (materialFilter && !materialFilter({ object, material })) continue;\n\n if (!snapshots.has(material)) {\n snapshots.set(material, {\n color: mutable.color.clone(),\n roughness: mutable.roughness,\n metalness: mutable.metalness,\n });\n }\n\n applyScenarioMaterial(mutable, object, scenario, materials);\n }\n });\n}\n\nfunction applyScenarioMaterial(\n material: THREE.MeshStandardMaterial | THREE.MeshPhysicalMaterial,\n object: THREE.Object3D,\n scenario: VisualScenarioConfig,\n materials: ScenarioMaterialConfig\n) {\n const seed = scenario.seed ?? 0;\n const objectKey = `${scenario.id ?? 'scenario'}:${object.name}:${material.name}:${seed}`;\n const variation = hashToUnitInterval(objectKey);\n\n if (materials.randomizeObjectColors) {\n material.color.setHSL(variation, 0.38, 0.42);\n }\n\n if (materials.randomizeTableMaterial) {\n material.roughness = clamp01(\n materials.roughness ?? 0.35 + variation * 0.45\n );\n material.metalness = clamp01(\n materials.metalness ?? variation * 0.12\n );\n }\n\n material.needsUpdate = true;\n}\n\nfunction normalizeMaterials(\n material: THREE.Material | THREE.Material[]\n): THREE.Material[] {\n return Array.isArray(material) ? material : [material];\n}\n\nfunction getMutableScenarioMaterial(\n material: THREE.Material\n): THREE.MeshStandardMaterial | THREE.MeshPhysicalMaterial | null {\n if (\n material instanceof THREE.MeshStandardMaterial ||\n material instanceof THREE.MeshPhysicalMaterial\n ) {\n return material;\n }\n\n return null;\n}\n\nfunction hashToUnitInterval(value: string) {\n let hash = 2166136261;\n for (let index = 0; index < value.length; index += 1) {\n hash ^= value.charCodeAt(index);\n hash = Math.imul(hash, 16777619);\n }\n return (hash >>> 0) / 4294967295;\n}\n\nfunction clamp01(value: number) {\n return Math.max(0, Math.min(1, value));\n}\n\nexport type SplatCollisionProxy = ReactNode | ThreeElements['group'];\n"]}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { M as MujocoContextValue, a as MujocoCanvasProps, b as MujocoSimAPI, S as SceneConfig, c as MujocoModule, P as PhysicsStepCallback, d as MujocoModel, e as MujocoData, C as ControlGroupInfo, A as ActuatedJointInfo, f as ControlGroupSelector, O as ObservationConfig, g as ObservationResult, I as IkConfig, h as IkContextValue, B as BodyProps, i as IkGizmoProps, D as DragInteractionProps, j as SceneLightsProps, k as ScenarioLightingProps, l as SplatEnvironmentProps, V as VisualScenarioEffectsProps, m as VisualScenarioConfig, n as SplatRendererKind, o as PairedSplatEnvironmentConfig, p as SplatFormat, q as SplatCollisionProxyConfig, r as SplatCollisionPrimitive, s as ScenarioLightingPreset, t as SplatEnvironmentMetadataInput, u as SplatEnvironmentMetadata, v as SplatSceneInput, w as DebugProps, G as GeomInfo, x as ContactListenerProps, T as TrajectoryPlayerProps, y as ActuatorInfo, z as Sites, E as SitePositionResult, F as Sensors, H as SensorHandle, J as SensorInfo, K as Joints, L as JointStateResult, N as Bodies, Q as BodyStateResult, R as Actuators, U as CtrlHandle, W as ContactInfo, X as KeyboardTeleopConfig, Y as PolicyConfig, Z as PolicyVector, _ as ObservationHandle, $ as TrajectoryInput, a0 as PlaybackState, a1 as TrajectoryFrame } from './types-BmneHLBM.js';
3
- export { a2 as BodyInfo, a3 as ControlJointInfo, a4 as Geoms, a5 as IKSolveFn, a6 as JointInfo, a7 as KeyBinding, a8 as Keyframes, a9 as ModelOptions, aa as MujocoContact, ab as MujocoContactArray, ac as ObservationLayoutItem, ad as ObservationOutput, ae as PhysicsConfig, af as PolicyActionInput, ag as PolicyInferenceInput, ah as PolicyObservationInput, ai as RayHit, aj as Register, ak as RegisteredRobotMap, al as ResourceSelector, am as RobotActuators, an as RobotBodies, ao as RobotGeoms, ap as RobotJoints, aq as RobotKeyframes, ar as RobotResource, as as RobotResources, at as RobotSensors, au as RobotSites, av as Robots, aw as ScenarioCameraConfig, ax as ScenarioMaterialConfig, ay as SceneMarker, az as SceneObject, aA as SensorResult, aB as SiteInfo, aC as SplatAssetConfig, aD as SplatScenarioConfig, aE as StateSnapshot, aF as TrajectoryData, aG as XmlPatch, aH as getContact, aI as registerRobotResources } from './types-BmneHLBM.js';
2
+ import { M as MujocoContextValue, a as MujocoCanvasProps, b as MujocoSimAPI, S as SceneConfig, R as ReadyCallbackInput, c as StepCallbackInput, d as SelectionCallbackInput, e as MujocoModule, P as PhysicsStepCallback, f as MujocoModel, g as MujocoData, C as ControlGroupInfo, A as ActuatedJointInfo, h as ControlGroupSelector, O as ObservationConfig, i as ObservationResult, I as IkConfig, j as IkContextValue, B as BodyProps, k as IkGizmoProps, D as DragInteractionProps, l as SceneLightsProps, m as ScenarioLightingProps, n as SplatEnvironmentProps, V as VisualScenarioEffectsProps, o as VisualScenarioConfig, p as SplatRendererKind, q as PairedSplatEnvironmentConfig, r as SplatFormat, s as SplatCollisionProxyConfig, t as SplatCollisionPrimitive, u as ScenarioLightingPreset, v as SplatEnvironmentMetadataInput, w as SplatEnvironmentMetadata, x as SplatSceneInput, y as DebugProps, G as GeomInfo, z as ContactListenerProps, T as TrajectoryPlayerProps, E as ActuatorInfo, F as Sites, H as SitePositionResult, J as Sensors, K as SensorHandle, L as SensorInfo, N as Joints, Q as JointStateResult, U as Bodies, W as BodyStateResult, X as Actuators, Y as CtrlHandle, Z as ContactInfo, _ as KeyboardTeleopConfig, $ as PolicyConfig, a0 as PolicyVector, a1 as ObservationHandle, a2 as TrajectoryInput, a3 as TrajectoryStateChangeInput, a4 as PlaybackState, a5 as TrajectoryFrame, a6 as FrameCaptureOptions, a7 as FrameCaptureResult, a8 as FrameCaptureBlobResult, a9 as FrameCaptureAPI } from './types-C5gTvR7b.js';
3
+ export { aa as BodyInfo, ab as ControlJointInfo, ac as FrameCaptureStatus, ad as FrameCaptureTarget, ae as FrameCaptureTargetRef, af as Geoms, ag as IKSolveFn, ah as IkGizmoDragInput, ai as IkSolveInput, aj as JointInfo, ak as KeyBinding, al as Keyframes, am as ModelOptions, an as MujocoContact, ao as MujocoContactArray, ap as MujocoFrameCaptureOptions, aq as ObservationLayoutItem, ar as ObservationOutput, as as PhysicsConfig, at as PhysicsStepInput, au as PolicyActionInput, av as PolicyInferenceInput, aw as PolicyObservationInput, ax as RayHit, ay as Register, az as RegisteredRobotMap, aA as ResetCallbackInput, aB as ResourceSelector, aC as RobotActuators, aD as RobotBodies, aE as RobotGeoms, aF as RobotJoints, aG as RobotKeyframes, aH as RobotResource, aI as RobotResources, aJ as RobotSensors, aK as RobotSites, aL as Robots, aM as ScenarioCameraConfig, aN as ScenarioMaterialConfig, aO as SceneMarker, aP as SceneObject, aQ as SensorResult, aR as SiteInfo, aS as SplatAssetConfig, aT as SplatScenarioConfig, aU as StateSnapshot, aV as TrajectoryData, aW as TrajectoryFrameCallbackInput, aX as VisualScenarioMaterialFilterInput, aY as XmlPatch, aZ as getContact, a_ as registerRobotResources } from './types-C5gTvR7b.js';
4
4
  import * as React$1 from 'react';
5
- import React__default from 'react';
6
5
  import { ThreeElements } from '@react-three/fiber';
7
6
  import * as THREE from 'three';
8
7
 
@@ -56,13 +55,13 @@ interface MujocoPhysicsProps {
56
55
  /** Scene/robot configuration. */
57
56
  config: SceneConfig;
58
57
  /** Fires when model is loaded and API is ready. */
59
- onReady?: (api: MujocoSimAPI) => void;
58
+ onReady?: (input: ReadyCallbackInput) => void;
60
59
  /** Fires on scene load failure. */
61
60
  onError?: (error: Error) => void;
62
61
  /** Called each physics step. */
63
- onStep?: (time: number) => void;
62
+ onStep?: (input: StepCallbackInput) => void;
64
63
  /** Called on body double-click selection. */
65
- onSelection?: (bodyId: number, name: string) => void;
64
+ onSelection?: (input: SelectionCallbackInput) => void;
66
65
  /** Override model gravity. */
67
66
  gravity?: [number, number, number];
68
67
  /** Override model.opt.timestep. */
@@ -133,10 +132,10 @@ interface MujocoSimProviderProps {
133
132
  mujoco: MujocoModule;
134
133
  config: SceneConfig;
135
134
  apiRef?: React.ForwardedRef<MujocoSimAPI>;
136
- onReady?: (api: MujocoSimAPI) => void;
135
+ onReady?: (input: ReadyCallbackInput) => void;
137
136
  onError?: (error: Error) => void;
138
- onStep?: (time: number) => void;
139
- onSelection?: (bodyId: number, name: string) => void;
137
+ onStep?: (input: StepCallbackInput) => void;
138
+ onSelection?: (input: SelectionCallbackInput) => void;
140
139
  gravity?: [number, number, number];
141
140
  timestep?: number;
142
141
  substeps?: number;
@@ -243,7 +242,7 @@ type ControllerComponent<TConfig> = React.FC<{
243
242
  * const MyController = createController<{ speed: number }>(
244
243
  * { name: 'my-controller', defaultConfig: { speed: 1.0 } },
245
244
  * function MyControllerImpl({ config }) {
246
- * useBeforePhysicsStep((_model, data) => {
245
+ * useBeforePhysicsStep(({ data }) => {
247
246
  * data.ctrl[0] = config.speed;
248
247
  * });
249
248
  * return null;
@@ -270,7 +269,7 @@ declare function createController<TConfig>(options: ControllerOptions<TConfig>,
270
269
  * { name: 'useMyController', defaultConfig: { gain: 1.0 } },
271
270
  * function useMyControllerImpl(config) {
272
271
  * // config is MyConfig | null — hooks must be called unconditionally
273
- * useBeforePhysicsStep((_model, data) => {
272
+ * useBeforePhysicsStep(({ data }) => {
274
273
  * if (!config) return;
275
274
  * data.ctrl[0] = config.gain * Math.sin(data.time);
276
275
  * });
@@ -312,7 +311,7 @@ declare function Body({ name, type, size, position, rgba, mass, freejoint, frict
312
311
  * - `controller` — IkContextValue from `useIkController()`.
313
312
  * - `siteName` — MuJoCo site to track. Defaults to the controller's configured site.
314
313
  * - `scale` — Gizmo handle scale. Default: 0.18.
315
- * - `onDrag` — Custom drag callback `(pos, quat) => void`.
314
+ * - `onDrag` — Custom drag callback `({ position, quaternion }) => void`.
316
315
  * When omitted, dragging enables IK and writes to the IK target.
317
316
  * When provided, the consumer handles what happens during drag.
318
317
  */
@@ -655,7 +654,7 @@ interface TrajectoryPlayerOptions {
655
654
  loop?: boolean;
656
655
  mode?: 'kinematic' | 'physics';
657
656
  onComplete?: () => void;
658
- onStateChange?: (state: PlaybackState) => void;
657
+ onStateChange?: (input: TrajectoryStateChangeInput) => void;
659
658
  }
660
659
  /**
661
660
  * Play back a trajectory, overriding simulation state.
@@ -758,33 +757,6 @@ declare function useVideoRecorder(options?: VideoRecorderOptions): {
758
757
  * useFrameCapture — still-frame capture for canvas-backed MuJoCo/R3F scenes.
759
758
  */
760
759
 
761
- type FrameCaptureStatus = 'idle' | 'capturing' | 'captured' | 'error';
762
- type FrameCaptureTarget = HTMLCanvasElement | HTMLElement | null | undefined;
763
- type FrameCaptureTargetRef = React__default.RefObject<HTMLCanvasElement | HTMLElement | null>;
764
- interface FrameCaptureOptions {
765
- target?: FrameCaptureTarget | FrameCaptureTargetRef;
766
- type?: string;
767
- quality?: number;
768
- waitForAnimationFrame?: boolean;
769
- }
770
- interface FrameCaptureResult {
771
- canvas: HTMLCanvasElement;
772
- dataUrl: string;
773
- type: string;
774
- }
775
- interface FrameCaptureBlobResult {
776
- canvas: HTMLCanvasElement;
777
- blob: Blob;
778
- type: string;
779
- }
780
- interface FrameCaptureAPI {
781
- status: FrameCaptureStatus;
782
- error: Error | null;
783
- isCapturing: boolean;
784
- capture: (options?: FrameCaptureOptions) => Promise<FrameCaptureResult>;
785
- captureBlob: (options?: FrameCaptureOptions) => Promise<FrameCaptureBlobResult>;
786
- reset: () => void;
787
- }
788
760
  /**
789
761
  * Capture the current canvas frame as a data URL.
790
762
  *
@@ -896,4 +868,4 @@ interface CameraAnimationAPI {
896
868
  */
897
869
  declare function useCameraAnimation(): CameraAnimationAPI;
898
870
 
899
- export { ActuatedJointInfo, ActuatorInfo, Actuators, Bodies, Body, BodyProps, BodyStateResult, type CameraAnimationAPI, ContactInfo, ContactListener, ContactListenerProps, ContactMarkers, ControlGroupInfo, ControlGroupSelector, type ControllerComponent, type ControllerOptions, CtrlHandle, Debug, DebugProps, DragInteraction, DragInteractionProps, FlexRenderer, type FrameCaptureAPI, type FrameCaptureBlobResult, type FrameCaptureOptions, type FrameCaptureResult, type FrameCaptureStatus, type FrameCaptureTarget, type FrameCaptureTargetRef, GeomInfo, IkConfig, IkContextValue, IkGizmo, IkGizmoProps, InstancedGeomRenderer, JointStateResult, Joints, KeyboardTeleopConfig, MujocoCanvas, MujocoCanvasProps, MujocoContextValue, MujocoData, type MujocoLoader, type MujocoLoaderOptions, MujocoModel, MujocoModule, MujocoPhysics, type MujocoPhysicsProps, MujocoProvider, type MujocoProviderProps, MujocoSimAPI, MujocoSimProvider, type MujocoWasmVariant, ObservationConfig, ObservationHandle, ObservationResult, PairedSplatEnvironmentConfig, PhysicsStepCallback, PlaybackState, PolicyConfig, PolicyVector, ScenarioLighting, ScenarioLightingPreset, ScenarioLightingProps, SceneConfig, SceneLights, SceneLightsProps, SensorHandle, SensorInfo, Sensors, SitePositionResult, Sites, SplatCollisionPrimitive, SplatCollisionProxyConfig, SplatEnvironment, SplatEnvironmentMetadata, SplatEnvironmentMetadataInput, SplatEnvironmentProps, SplatFormat, SplatRendererKind, SplatSceneInput, TendonRenderer, TrajectoryFrame, TrajectoryInput, TrajectoryPlayer, TrajectoryPlayerProps, VisualScenarioConfig, VisualScenarioEffects, VisualScenarioEffectsProps, buildObservation, captureFrame, captureFrameBlob, createContiguousControlGroup, createController, createControllerHook, createPairedSplatEnvironment, createSparkSplatViewerUrl, createSplatEnvironmentUserData, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, getActuatedJoints, getControlMap, getName, getScenarioBackground, getScenarioCameraPosition, loadScene, resolveControlGroup, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyMeshes, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useFrameCapture, useGamepad, useGravityCompensation, useIkController, useJointState, useKeyboardTeleop, useMujoco, useMujocoWasm, useObservation, usePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePosition, useSplatEnvironment, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder, useVisualScenarioEffects, withSplatEnvironment };
871
+ export { ActuatedJointInfo, ActuatorInfo, Actuators, Bodies, Body, BodyProps, BodyStateResult, type CameraAnimationAPI, ContactInfo, ContactListener, ContactListenerProps, ContactMarkers, ControlGroupInfo, ControlGroupSelector, type ControllerComponent, type ControllerOptions, CtrlHandle, Debug, DebugProps, DragInteraction, DragInteractionProps, FlexRenderer, FrameCaptureAPI, FrameCaptureBlobResult, FrameCaptureOptions, FrameCaptureResult, GeomInfo, IkConfig, IkContextValue, IkGizmo, IkGizmoProps, InstancedGeomRenderer, JointStateResult, Joints, KeyboardTeleopConfig, MujocoCanvas, MujocoCanvasProps, MujocoContextValue, MujocoData, type MujocoLoader, type MujocoLoaderOptions, MujocoModel, MujocoModule, MujocoPhysics, type MujocoPhysicsProps, MujocoProvider, type MujocoProviderProps, MujocoSimAPI, MujocoSimProvider, type MujocoWasmVariant, ObservationConfig, ObservationHandle, ObservationResult, PairedSplatEnvironmentConfig, PhysicsStepCallback, PlaybackState, PolicyConfig, PolicyVector, ReadyCallbackInput, ScenarioLighting, ScenarioLightingPreset, ScenarioLightingProps, SceneConfig, SceneLights, SceneLightsProps, SelectionCallbackInput, SensorHandle, SensorInfo, Sensors, SitePositionResult, Sites, SplatCollisionPrimitive, SplatCollisionProxyConfig, SplatEnvironment, SplatEnvironmentMetadata, SplatEnvironmentMetadataInput, SplatEnvironmentProps, SplatFormat, SplatRendererKind, SplatSceneInput, StepCallbackInput, TendonRenderer, TrajectoryFrame, TrajectoryInput, TrajectoryPlayer, TrajectoryPlayerProps, TrajectoryStateChangeInput, VisualScenarioConfig, VisualScenarioEffects, VisualScenarioEffectsProps, buildObservation, captureFrame, captureFrameBlob, createContiguousControlGroup, createController, createControllerHook, createPairedSplatEnvironment, createSparkSplatViewerUrl, createSplatEnvironmentUserData, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, getActuatedJoints, getControlMap, getName, getScenarioBackground, getScenarioCameraPosition, loadScene, resolveControlGroup, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyMeshes, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useFrameCapture, useGamepad, useGravityCompensation, useIkController, useJointState, useKeyboardTeleop, useMujoco, useMujocoWasm, useObservation, usePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePosition, useSplatEnvironment, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder, useVisualScenarioEffects, withSplatEnvironment };