mujoco-react 6.0.1 → 7.0.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 +84 -46
- package/dist/index.d.ts +88 -57
- package/dist/index.js +372 -243
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Body.tsx +102 -0
- package/src/components/ContactMarkers.tsx +2 -2
- package/src/components/Debug.tsx +2 -2
- package/src/components/DragInteraction.tsx +2 -2
- package/src/components/FlexRenderer.tsx +2 -2
- package/src/components/IkGizmo.tsx +7 -11
- package/src/components/SceneRenderer.tsx +9 -6
- package/src/components/TendonRenderer.tsx +2 -2
- package/src/core/MujocoSimProvider.tsx +87 -6
- package/src/core/createController.tsx +54 -2
- package/src/hooks/useActuators.ts +2 -2
- package/src/hooks/useBodyState.ts +2 -2
- package/src/hooks/useContacts.ts +2 -2
- package/src/hooks/useCtrl.ts +2 -2
- package/src/hooks/useCtrlNoise.ts +2 -2
- package/src/hooks/useGamepad.ts +2 -2
- package/src/hooks/useIkController.ts +242 -0
- package/src/hooks/useJointState.ts +2 -2
- package/src/hooks/useKeyboardTeleop.ts +2 -2
- package/src/hooks/usePolicy.ts +2 -2
- package/src/hooks/useSceneLights.ts +2 -2
- package/src/hooks/useSensor.ts +3 -3
- package/src/hooks/useSitePosition.ts +2 -2
- package/src/hooks/useTrajectoryPlayer.ts +2 -2
- package/src/hooks/useTrajectoryRecorder.ts +2 -2
- package/src/index.ts +5 -4
- package/src/types.ts +30 -0
- package/src/components/IkController.tsx +0 -262
- package/src/core/IkContext.tsx +0 -40
package/README.md
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
# mujoco-react
|
|
6
6
|
|
|
7
|
+
> **Beta** — This library is under active development. The API may change between minor versions until 1.0.
|
|
8
|
+
|
|
7
9
|
Composable [React Three Fiber](https://docs.pmnd.rs/react-three-fiber) wrapper around [mujoco-js](https://www.npmjs.com/package/mujoco-js). Load any MuJoCo model, step physics, render bodies, and write controllers as React components.
|
|
8
10
|
|
|
9
|
-
**[
|
|
11
|
+
**[Demo](https://mujoco-react-example.pages.dev)** | **[Docs](https://dadd.mintlify.app)** | **[Example Source](https://github.com/noah-wardlow/mujoco-react-example)** | **[llms.txt](https://dadd.mintlify.app/llms.txt)**
|
|
10
12
|
|
|
11
13
|
## Install
|
|
12
14
|
|
|
@@ -20,7 +22,7 @@ npm install mujoco-react three @react-three/fiber @react-three/drei
|
|
|
20
22
|
import {
|
|
21
23
|
MujocoProvider,
|
|
22
24
|
MujocoCanvas,
|
|
23
|
-
|
|
25
|
+
useIkController,
|
|
24
26
|
IkGizmo,
|
|
25
27
|
} from 'mujoco-react';
|
|
26
28
|
import type { SceneConfig } from 'mujoco-react';
|
|
@@ -32,6 +34,18 @@ const config: SceneConfig = {
|
|
|
32
34
|
homeJoints: [1.707, -1.754, 0.003, -2.702, 0.003, 0.951, 2.490],
|
|
33
35
|
};
|
|
34
36
|
|
|
37
|
+
function Scene() {
|
|
38
|
+
const ik = useIkController({ siteName: 'tcp', numJoints: 7 });
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
<OrbitControls enableDamping makeDefault />
|
|
42
|
+
{ik && <IkGizmo controller={ik} />}
|
|
43
|
+
<ambientLight intensity={0.7} />
|
|
44
|
+
<directionalLight position={[1, 2, 5]} intensity={1.2} castShadow />
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
35
49
|
function App() {
|
|
36
50
|
return (
|
|
37
51
|
<MujocoProvider>
|
|
@@ -41,12 +55,7 @@ function App() {
|
|
|
41
55
|
shadows
|
|
42
56
|
style={{ width: '100%', height: '100vh' }}
|
|
43
57
|
>
|
|
44
|
-
<
|
|
45
|
-
<IkController config={{ siteName: 'tcp', numJoints: 7 }}>
|
|
46
|
-
<IkGizmo />
|
|
47
|
-
</IkController>
|
|
48
|
-
<ambientLight intensity={0.7} />
|
|
49
|
-
<directionalLight position={[1, 2, 5]} intensity={1.2} castShadow />
|
|
58
|
+
<Scene />
|
|
50
59
|
</MujocoCanvas>
|
|
51
60
|
</MujocoProvider>
|
|
52
61
|
);
|
|
@@ -60,14 +69,18 @@ Inside `<MujocoCanvas>` or `<MujocoPhysics>`, `useMujoco()` gives you the simula
|
|
|
60
69
|
```tsx
|
|
61
70
|
import { useMujoco } from 'mujoco-react';
|
|
62
71
|
|
|
63
|
-
function
|
|
64
|
-
const {
|
|
72
|
+
function MyComponent() {
|
|
73
|
+
const { api, status } = useMujoco();
|
|
74
|
+
const sim = useMujoco();
|
|
65
75
|
|
|
66
|
-
if (
|
|
76
|
+
if (!api) return null;
|
|
77
|
+
if (sim.isPending) return <span>Loading...</span>;
|
|
78
|
+
if (sim.isError) return <span>Error: {sim.error}</span>;
|
|
67
79
|
|
|
80
|
+
// sim.api is fully typed here
|
|
68
81
|
return (
|
|
69
|
-
<button onClick={() => api
|
|
70
|
-
Reset ({mjModelRef.current?.nq} joints)
|
|
82
|
+
<button onClick={() => sim.api.reset()}>
|
|
83
|
+
Reset ({sim.mjModelRef.current?.nq} joints)
|
|
71
84
|
</button>
|
|
72
85
|
);
|
|
73
86
|
}
|
|
@@ -122,17 +135,17 @@ export const MyController = createController<{ gain: number }>(
|
|
|
122
135
|
```
|
|
123
136
|
<MujocoProvider> <MujocoProvider>
|
|
124
137
|
<MujocoCanvas config={...}> <Canvas shadows gl={...}>
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
</MujocoProvider>
|
|
138
|
+
<Scene /> <MujocoPhysics config={...}>
|
|
139
|
+
<MyController /> <MyController />
|
|
140
|
+
</MujocoCanvas> </MujocoPhysics>
|
|
141
|
+
</MujocoProvider> <EffectComposer>...</EffectComposer>
|
|
142
|
+
</Canvas>
|
|
143
|
+
</MujocoProvider>
|
|
131
144
|
```
|
|
132
145
|
|
|
133
146
|
### Custom IK Solvers
|
|
134
147
|
|
|
135
|
-
The built-in
|
|
148
|
+
The built-in `useIkController()` uses Damped Least-Squares. Pass `ikSolveFn` to swap in your own solver (analytical, learned, etc.):
|
|
136
149
|
|
|
137
150
|
```tsx
|
|
138
151
|
import type { IKSolveFn } from 'mujoco-react';
|
|
@@ -141,19 +154,16 @@ const myIK: IKSolveFn = (pos, quat, currentQ) => {
|
|
|
141
154
|
return myAnalyticalSolver(pos, currentQ); // return joint angles or null
|
|
142
155
|
};
|
|
143
156
|
|
|
144
|
-
|
|
145
|
-
<IkGizmo />
|
|
146
|
-
</IkController>
|
|
157
|
+
const ik = useIkController({ siteName: 'tcp', numJoints: 7, ikSolveFn: myIK });
|
|
147
158
|
```
|
|
148
159
|
|
|
149
|
-
###
|
|
160
|
+
### `useIkController(config | null)`
|
|
150
161
|
|
|
151
|
-
|
|
162
|
+
Hook for interactive end-effector control. Pass `null` to disable IK (safe to call unconditionally):
|
|
152
163
|
|
|
153
164
|
```tsx
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
</IkController>
|
|
165
|
+
const ik = useIkController({ siteName: 'tcp', numJoints: 7 });
|
|
166
|
+
return ik ? <IkGizmo controller={ik} /> : null;
|
|
157
167
|
```
|
|
158
168
|
|
|
159
169
|
| Config | Type | Default | Description |
|
|
@@ -164,17 +174,9 @@ The library includes one controller for interactive end-effector control:
|
|
|
164
174
|
| `damping` | `number` | `0.01` | DLS damping |
|
|
165
175
|
| `maxIterations` | `number` | `50` | Max solver iterations |
|
|
166
176
|
|
|
167
|
-
|
|
177
|
+
Returns `IkContextValue | null` with methods like `setIkEnabled`, `moveTarget`, `syncTargetToSite`, `solveIK`, and `getGizmoStats`.
|
|
168
178
|
|
|
169
|
-
|
|
170
|
-
const { setIkEnabled, moveTarget, solveIK } = useIk();
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Pass `{ optional: true }` for components that may or may not be inside an `<IkController>`:
|
|
174
|
-
|
|
175
|
-
```tsx
|
|
176
|
-
const ikCtx = useIk({ optional: true });
|
|
177
|
-
```
|
|
179
|
+
Pass the returned value to `<IkGizmo controller={ik} />` or to your own controller as a prop.
|
|
178
180
|
|
|
179
181
|
## Loading Models
|
|
180
182
|
|
|
@@ -289,13 +291,46 @@ Physics provider for use inside your own R3F `<Canvas>`. Same physics props as `
|
|
|
289
291
|
| `paused` | `boolean` | Declarative pause |
|
|
290
292
|
| `speed` | `number` | Simulation speed multiplier |
|
|
291
293
|
|
|
294
|
+
### `<Body />`
|
|
295
|
+
|
|
296
|
+
Declaratively add physics bodies to the simulation as JSX. Bodies are injected into the MJCF XML before model compilation.
|
|
297
|
+
|
|
298
|
+
```tsx
|
|
299
|
+
<Body name="cube" type="box" size={[0.05, 0.05, 0.05]}
|
|
300
|
+
position={[0.5, 0, 0.05]} rgba={[1, 0, 0, 1]}
|
|
301
|
+
mass={0.1} freejoint />
|
|
302
|
+
|
|
303
|
+
// With custom Three.js visuals
|
|
304
|
+
<Body name="ball" type="sphere" size={[0.03, 0, 0]}
|
|
305
|
+
position={[0, 0.3, 0.1]} mass={0.5} freejoint>
|
|
306
|
+
<mesh>
|
|
307
|
+
<sphereGeometry args={[0.03]} />
|
|
308
|
+
<meshPhysicalMaterial color="gold" metalness={0.8} />
|
|
309
|
+
</mesh>
|
|
310
|
+
</Body>
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
| Prop | Type | Default | Description |
|
|
314
|
+
|------|------|---------|-------------|
|
|
315
|
+
| `name` | `string` | **required** | Unique body name |
|
|
316
|
+
| `type` | `'box' \| 'sphere' \| 'cylinder'` | **required** | Geom type |
|
|
317
|
+
| `size` | `[number, number, number]` | **required** | Geom size |
|
|
318
|
+
| `position` | `[number, number, number]` | `[0,0,0]` | Initial position |
|
|
319
|
+
| `rgba` | `[number, number, number, number]` | `[0.5,0.5,0.5,1]` | Color (ignored with children) |
|
|
320
|
+
| `mass` | `number?` | -- | Body mass in kg |
|
|
321
|
+
| `freejoint` | `boolean?` | -- | Add freejoint for free movement |
|
|
322
|
+
| `friction` | `string?` | -- | MuJoCo friction params |
|
|
323
|
+
| `condim` | `number?` | -- | Contact dimensionality (4-6 for grasping) |
|
|
324
|
+
| `children` | `ReactNode?` | -- | Custom Three.js visuals |
|
|
325
|
+
|
|
292
326
|
### `<IkGizmo />`
|
|
293
327
|
|
|
294
|
-
drei PivotControls gizmo that tracks a MuJoCo site and drives IK on drag.
|
|
328
|
+
drei PivotControls gizmo that tracks a MuJoCo site and drives IK on drag. Requires a `controller` from `useIkController()`.
|
|
295
329
|
|
|
296
330
|
| Prop | Type | Default | Description |
|
|
297
331
|
|------|------|---------|-------------|
|
|
298
|
-
| `
|
|
332
|
+
| `controller` | `IkContextValue` | **required** | Controller from `useIkController()` |
|
|
333
|
+
| `siteName` | `string?` | controller's site | MuJoCo site to track |
|
|
299
334
|
| `scale` | `number?` | `0.18` | Gizmo handle scale |
|
|
300
335
|
| `onDrag` | `(pos, quat) => void` | -- | Custom drag handler (disables auto-IK) |
|
|
301
336
|
|
|
@@ -373,10 +408,13 @@ Plays back recorded qpos trajectories with scrubbing.
|
|
|
373
408
|
|
|
374
409
|
### `useMujoco()`
|
|
375
410
|
|
|
376
|
-
Access the simulation API
|
|
411
|
+
Access the simulation API (must be inside `<MujocoCanvas>` or `<MujocoPhysics>`). Narrow on `isReady`, `isPending`, or `isError`:
|
|
377
412
|
|
|
378
413
|
```tsx
|
|
379
|
-
const
|
|
414
|
+
const sim = useMujoco();
|
|
415
|
+
if (sim.isReady) {
|
|
416
|
+
sim.api.reset(); // fully typed
|
|
417
|
+
}
|
|
380
418
|
```
|
|
381
419
|
|
|
382
420
|
### `useMujocoWasm()`
|
|
@@ -410,9 +448,9 @@ useBeforePhysicsStep((model, data) => {
|
|
|
410
448
|
|
|
411
449
|
Run logic **after** `mj_step` each frame. Read results, compute rewards, log telemetry.
|
|
412
450
|
|
|
413
|
-
### `
|
|
451
|
+
### `useIkController(config | null)`
|
|
414
452
|
|
|
415
|
-
|
|
453
|
+
Set up IK control for a MuJoCo site. Pass `null` to disable. Returns `IkContextValue | null`.
|
|
416
454
|
|
|
417
455
|
### `useCameraAnimation()`
|
|
418
456
|
|
|
@@ -579,7 +617,7 @@ useSceneLights(1.5);
|
|
|
579
617
|
|
|
580
618
|
## MujocoSimAPI
|
|
581
619
|
|
|
582
|
-
The full API object available via `ref` or `useMujoco()
|
|
620
|
+
The full API object available via `ref` or `useMujoco()` (when `isReady`):
|
|
583
621
|
|
|
584
622
|
### Simulation Control
|
|
585
623
|
|
|
@@ -682,7 +720,7 @@ See [Click-to-Select](https://dadd.mintlify.app/guides/click-to-select) for the
|
|
|
682
720
|
| Priority | Owner | Purpose |
|
|
683
721
|
|----------|-------|---------|
|
|
684
722
|
| -1 | MujocoSimProvider | beforeStep, mj_step, afterStep |
|
|
685
|
-
| 0 (default) | SceneRenderer (internal),
|
|
723
|
+
| 0 (default) | SceneRenderer (internal), useIkController, your code | Body mesh sync, IK, rendering |
|
|
686
724
|
|
|
687
725
|
## Roadmap
|
|
688
726
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React$1 from 'react';
|
|
3
|
+
import React__default, { ReactNode } from 'react';
|
|
2
4
|
import { CanvasProps, ThreeElements } from '@react-three/fiber';
|
|
3
5
|
import * as THREE from 'three';
|
|
4
|
-
import * as react from 'react';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @license
|
|
@@ -254,6 +255,20 @@ interface IkConfig {
|
|
|
254
255
|
/** Max solver iterations. Default: 50. */
|
|
255
256
|
maxIterations?: number;
|
|
256
257
|
}
|
|
258
|
+
interface IkContextValue {
|
|
259
|
+
ikEnabledRef: React__default.RefObject<boolean>;
|
|
260
|
+
ikCalculatingRef: React__default.RefObject<boolean>;
|
|
261
|
+
ikTargetRef: React__default.RefObject<THREE.Group>;
|
|
262
|
+
siteIdRef: React__default.RefObject<number>;
|
|
263
|
+
setIkEnabled: (enabled: boolean) => void;
|
|
264
|
+
moveTarget: (pos: THREE.Vector3, duration?: number) => void;
|
|
265
|
+
syncTargetToSite: () => void;
|
|
266
|
+
solveIK: (pos: THREE.Vector3, quat: THREE.Quaternion, currentQ: number[]) => number[] | null;
|
|
267
|
+
getGizmoStats: () => {
|
|
268
|
+
pos: THREE.Vector3;
|
|
269
|
+
rot: THREE.Euler;
|
|
270
|
+
} | null;
|
|
271
|
+
}
|
|
257
272
|
interface SceneMarker {
|
|
258
273
|
id: number;
|
|
259
274
|
position: THREE.Vector3;
|
|
@@ -374,6 +389,7 @@ interface DebugProps {
|
|
|
374
389
|
showTendons?: boolean;
|
|
375
390
|
}
|
|
376
391
|
interface IkGizmoProps {
|
|
392
|
+
controller: IkContextValue;
|
|
377
393
|
siteName?: string;
|
|
378
394
|
scale?: number;
|
|
379
395
|
onDrag?: (position: THREE.Vector3, quaternion: THREE.Quaternion) => void;
|
|
@@ -398,6 +414,20 @@ interface ContactListenerProps {
|
|
|
398
414
|
onContactEnter?: (info: ContactInfo) => void;
|
|
399
415
|
onContactExit?: (info: ContactInfo) => void;
|
|
400
416
|
}
|
|
417
|
+
interface BodyProps {
|
|
418
|
+
name: string;
|
|
419
|
+
type: 'box' | 'sphere' | 'cylinder';
|
|
420
|
+
size: [number, number, number];
|
|
421
|
+
position?: [number, number, number];
|
|
422
|
+
rgba?: [number, number, number, number];
|
|
423
|
+
mass?: number;
|
|
424
|
+
freejoint?: boolean;
|
|
425
|
+
friction?: string;
|
|
426
|
+
solref?: string;
|
|
427
|
+
solimp?: string;
|
|
428
|
+
condim?: number;
|
|
429
|
+
children?: ReactNode;
|
|
430
|
+
}
|
|
401
431
|
interface MujocoSimAPI {
|
|
402
432
|
readonly status: 'loading' | 'ready' | 'error';
|
|
403
433
|
readonly config: SceneConfig;
|
|
@@ -445,8 +475,8 @@ interface MujocoSimAPI {
|
|
|
445
475
|
setBodyMass(name: string, mass: number): void;
|
|
446
476
|
setGeomFriction(name: string, friction: [number, number, number]): void;
|
|
447
477
|
setGeomSize(name: string, size: [number, number, number]): void;
|
|
448
|
-
readonly mjModelRef:
|
|
449
|
-
readonly mjDataRef:
|
|
478
|
+
readonly mjModelRef: React__default.RefObject<MujocoModel | null>;
|
|
479
|
+
readonly mjDataRef: React__default.RefObject<MujocoData | null>;
|
|
450
480
|
}
|
|
451
481
|
type MujocoCanvasProps = Omit<CanvasProps, 'onError'> & {
|
|
452
482
|
config: SceneConfig;
|
|
@@ -461,8 +491,8 @@ type MujocoCanvasProps = Omit<CanvasProps, 'onError'> & {
|
|
|
461
491
|
speed?: number;
|
|
462
492
|
};
|
|
463
493
|
interface SitePositionResult {
|
|
464
|
-
position:
|
|
465
|
-
quaternion:
|
|
494
|
+
position: React__default.RefObject<THREE.Vector3>;
|
|
495
|
+
quaternion: React__default.RefObject<THREE.Quaternion>;
|
|
466
496
|
}
|
|
467
497
|
interface MujocoContextValue {
|
|
468
498
|
mujoco: MujocoModule | null;
|
|
@@ -470,18 +500,18 @@ interface MujocoContextValue {
|
|
|
470
500
|
error: string | null;
|
|
471
501
|
}
|
|
472
502
|
interface SensorResult {
|
|
473
|
-
value:
|
|
503
|
+
value: React__default.RefObject<Float64Array>;
|
|
474
504
|
size: number;
|
|
475
505
|
}
|
|
476
506
|
interface BodyStateResult {
|
|
477
|
-
position:
|
|
478
|
-
quaternion:
|
|
479
|
-
linearVelocity:
|
|
480
|
-
angularVelocity:
|
|
507
|
+
position: React__default.RefObject<THREE.Vector3>;
|
|
508
|
+
quaternion: React__default.RefObject<THREE.Quaternion>;
|
|
509
|
+
linearVelocity: React__default.RefObject<THREE.Vector3>;
|
|
510
|
+
angularVelocity: React__default.RefObject<THREE.Vector3>;
|
|
481
511
|
}
|
|
482
512
|
interface JointStateResult {
|
|
483
|
-
position:
|
|
484
|
-
velocity:
|
|
513
|
+
position: React__default.RefObject<number | Float64Array>;
|
|
514
|
+
velocity: React__default.RefObject<number | Float64Array>;
|
|
485
515
|
}
|
|
486
516
|
|
|
487
517
|
/**
|
|
@@ -508,7 +538,7 @@ declare function MujocoProvider({ wasmUrl, timeout, children, onError }: MujocoP
|
|
|
508
538
|
*
|
|
509
539
|
* Forward ref exposes MujocoSimAPI (not the canvas element).
|
|
510
540
|
*/
|
|
511
|
-
declare const MujocoCanvas:
|
|
541
|
+
declare const MujocoCanvas: React$1.ForwardRefExoticComponent<Omit<MujocoCanvasProps, "ref"> & React$1.RefAttributes<MujocoSimAPI>>;
|
|
512
542
|
|
|
513
543
|
interface MujocoPhysicsProps {
|
|
514
544
|
/** Scene/robot configuration. */
|
|
@@ -552,24 +582,37 @@ interface MujocoPhysicsProps {
|
|
|
552
582
|
*
|
|
553
583
|
* Forward ref exposes MujocoSimAPI.
|
|
554
584
|
*/
|
|
555
|
-
declare const MujocoPhysics:
|
|
585
|
+
declare const MujocoPhysics: React$1.ForwardRefExoticComponent<MujocoPhysicsProps & React$1.RefAttributes<MujocoSimAPI>>;
|
|
556
586
|
|
|
557
|
-
|
|
587
|
+
type UseMujocoResult = {
|
|
588
|
+
status: 'loading';
|
|
589
|
+
isPending: true;
|
|
590
|
+
isReady: false;
|
|
591
|
+
isError: false;
|
|
592
|
+
error: null;
|
|
593
|
+
api: null;
|
|
594
|
+
mjModelRef: null;
|
|
595
|
+
mjDataRef: null;
|
|
596
|
+
} | {
|
|
597
|
+
status: 'error';
|
|
598
|
+
isPending: false;
|
|
599
|
+
isReady: false;
|
|
600
|
+
isError: true;
|
|
601
|
+
error: string;
|
|
602
|
+
api: null;
|
|
603
|
+
mjModelRef: null;
|
|
604
|
+
mjDataRef: null;
|
|
605
|
+
} | {
|
|
606
|
+
status: 'ready';
|
|
607
|
+
isPending: false;
|
|
608
|
+
isReady: true;
|
|
609
|
+
isError: false;
|
|
610
|
+
error: null;
|
|
558
611
|
api: MujocoSimAPI;
|
|
559
612
|
mjModelRef: React.RefObject<MujocoModel | null>;
|
|
560
613
|
mjDataRef: React.RefObject<MujocoData | null>;
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
pausedRef: React.RefObject<boolean>;
|
|
564
|
-
speedRef: React.RefObject<number>;
|
|
565
|
-
substepsRef: React.RefObject<number>;
|
|
566
|
-
onSelectionRef: React.RefObject<((bodyId: number, name: string) => void) | undefined>;
|
|
567
|
-
beforeStepCallbacks: React.RefObject<Set<PhysicsStepCallback>>;
|
|
568
|
-
afterStepCallbacks: React.RefObject<Set<PhysicsStepCallback>>;
|
|
569
|
-
resetCallbacks: React.RefObject<Set<() => void>>;
|
|
570
|
-
status: 'loading' | 'ready' | 'error';
|
|
571
|
-
}
|
|
572
|
-
declare function useMujoco(): MujocoSimContextValue;
|
|
614
|
+
};
|
|
615
|
+
declare function useMujoco(): UseMujocoResult;
|
|
573
616
|
declare function useBeforePhysicsStep(callback: PhysicsStepCallback): void;
|
|
574
617
|
declare function useAfterPhysicsStep(callback: PhysicsStepCallback): void;
|
|
575
618
|
interface MujocoSimProviderProps {
|
|
@@ -642,8 +685,6 @@ declare function loadScene(mujoco: MujocoModule, config: SceneConfig, onProgress
|
|
|
642
685
|
/**
|
|
643
686
|
* @license
|
|
644
687
|
* SPDX-License-Identifier: Apache-2.0
|
|
645
|
-
*
|
|
646
|
-
* createController — typed factory for BYOC (Bring Your Own Controller) plugins.
|
|
647
688
|
*/
|
|
648
689
|
interface ControllerOptions<TConfig> {
|
|
649
690
|
/** Unique name for this controller (used as displayName). */
|
|
@@ -686,47 +727,37 @@ declare function createController<TConfig>(options: ControllerOptions<TConfig>,
|
|
|
686
727
|
children?: React.ReactNode;
|
|
687
728
|
}>): ControllerComponent<TConfig>;
|
|
688
729
|
|
|
689
|
-
|
|
730
|
+
/**
|
|
731
|
+
* @license
|
|
732
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
733
|
+
*/
|
|
734
|
+
|
|
735
|
+
declare const useIkController: (config: IkConfig | null) => IkContextValue | null;
|
|
690
736
|
|
|
691
|
-
interface IkContextValue {
|
|
692
|
-
ikEnabledRef: React.RefObject<boolean>;
|
|
693
|
-
ikCalculatingRef: React.RefObject<boolean>;
|
|
694
|
-
ikTargetRef: React.RefObject<THREE.Group>;
|
|
695
|
-
siteIdRef: React.RefObject<number>;
|
|
696
|
-
setIkEnabled(enabled: boolean): void;
|
|
697
|
-
moveTarget(pos: THREE.Vector3, duration?: number): void;
|
|
698
|
-
syncTargetToSite(): void;
|
|
699
|
-
solveIK(pos: THREE.Vector3, quat: THREE.Quaternion, currentQ: number[]): number[] | null;
|
|
700
|
-
getGizmoStats(): {
|
|
701
|
-
pos: THREE.Vector3;
|
|
702
|
-
rot: THREE.Euler;
|
|
703
|
-
} | null;
|
|
704
|
-
}
|
|
705
737
|
/**
|
|
706
|
-
*
|
|
738
|
+
* Declarative physics body component. Registers a body definition in the
|
|
739
|
+
* provider-level registry so it gets injected into the MJCF XML at load time.
|
|
707
740
|
*
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*/
|
|
712
|
-
declare function
|
|
713
|
-
declare function useIk(options: {
|
|
714
|
-
optional: true;
|
|
715
|
-
}): IkContextValue | null;
|
|
741
|
+
* Bodies present at initial mount cause zero extra reloads (useLayoutEffect
|
|
742
|
+
* runs before the provider's loadScene useEffect). Bodies added/removed after
|
|
743
|
+
* the initial load trigger a debounced scene reload.
|
|
744
|
+
*/
|
|
745
|
+
declare function Body({ name, type, size, position, rgba, mass, freejoint, friction, solref, solimp, condim, children, }: BodyProps): react_jsx_runtime.JSX.Element | null;
|
|
716
746
|
|
|
717
747
|
/**
|
|
718
748
|
* IkGizmo — drei PivotControls that tracks a MuJoCo site.
|
|
719
749
|
*
|
|
720
|
-
*
|
|
750
|
+
* Requires a `controller` from `useIkController()`.
|
|
721
751
|
*
|
|
722
752
|
* Props:
|
|
723
|
-
* - `
|
|
753
|
+
* - `controller` — IkContextValue from `useIkController()`.
|
|
754
|
+
* - `siteName` — MuJoCo site to track. Defaults to the controller's configured site.
|
|
724
755
|
* - `scale` — Gizmo handle scale. Default: 0.18.
|
|
725
756
|
* - `onDrag` — Custom drag callback `(pos, quat) => void`.
|
|
726
757
|
* When omitted, dragging enables IK and writes to the IK target.
|
|
727
758
|
* When provided, the consumer handles what happens during drag.
|
|
728
759
|
*/
|
|
729
|
-
declare function IkGizmo({ siteName, scale, onDrag }: IkGizmoProps): react_jsx_runtime.JSX.Element | null;
|
|
760
|
+
declare function IkGizmo({ controller, siteName, scale, onDrag }: IkGizmoProps): react_jsx_runtime.JSX.Element | null;
|
|
730
761
|
|
|
731
762
|
interface ContactMarkersProps {
|
|
732
763
|
/** Maximum contacts to render. Default: 100. */
|
|
@@ -1164,4 +1195,4 @@ interface CameraAnimationAPI {
|
|
|
1164
1195
|
*/
|
|
1165
1196
|
declare function useCameraAnimation(): CameraAnimationAPI;
|
|
1166
1197
|
|
|
1167
|
-
export { type ActuatorInfo, type BodyInfo, type BodyStateResult, type CameraAnimationAPI, type ContactInfo, ContactListener, type ContactListenerProps, ContactMarkers, type ControllerComponent, type ControllerOptions, Debug, type DebugProps, DragInteraction, type DragInteractionProps, FlexRenderer, type GeomInfo, type IKSolveFn, type IkConfig, type IkContextValue,
|
|
1198
|
+
export { type ActuatorInfo, Body, type BodyInfo, type BodyProps, type BodyStateResult, type CameraAnimationAPI, type ContactInfo, ContactListener, type ContactListenerProps, ContactMarkers, type ControllerComponent, type ControllerOptions, Debug, type DebugProps, DragInteraction, type DragInteractionProps, FlexRenderer, type GeomInfo, type IKSolveFn, type IkConfig, type IkContextValue, IkGizmo, type IkGizmoProps, type JointInfo, type JointStateResult, type KeyBinding, type KeyboardTeleopConfig, type ModelOptions, MujocoCanvas, type MujocoCanvasProps, type MujocoContact, type MujocoContactArray, type MujocoContextValue, type MujocoData, type MujocoModel, type MujocoModule, MujocoPhysics, type MujocoPhysicsProps, MujocoProvider, type MujocoSimAPI, MujocoSimProvider, type PhysicsConfig, type PhysicsStepCallback, type PolicyConfig, type RayHit, type SceneConfig, SceneLights, type SceneLightsProps, type SceneMarker, type SceneObject, type SensorInfo, type SensorResult, type SiteInfo, type SitePositionResult, type StateSnapshot, TendonRenderer, type TrajectoryData, type TrajectoryFrame, TrajectoryPlayer, type TrajectoryPlayerProps, type XmlPatch, createController, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, getContact, getName, loadScene, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyMeshes, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useGamepad, useGravityCompensation, useIkController, useJointState, useKeyboardTeleop, useMujoco, useMujocoWasm, usePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePosition, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder };
|