mujoco-react 2.0.0 → 4.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 +36 -53
- package/dist/index.d.ts +5 -5
- package/dist/index.js +32 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- 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/IkController.tsx +2 -2
- package/src/components/IkGizmo.tsx +2 -2
- package/src/components/SceneRenderer.tsx +2 -2
- package/src/components/TendonRenderer.tsx +2 -2
- package/src/core/MujocoCanvas.tsx +2 -2
- package/src/core/MujocoPhysics.tsx +2 -2
- package/src/core/MujocoProvider.tsx +1 -1
- package/src/core/MujocoSimProvider.tsx +4 -4
- package/src/core/SceneLoader.ts +1 -1
- package/src/core/createController.tsx +1 -1
- 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/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 +2 -2
- package/src/types.ts +1 -1
package/README.md
CHANGED
|
@@ -23,22 +23,19 @@ import {
|
|
|
23
23
|
IkController,
|
|
24
24
|
IkGizmo,
|
|
25
25
|
} from 'mujoco-react';
|
|
26
|
-
import type { SceneConfig
|
|
26
|
+
import type { SceneConfig } from 'mujoco-react';
|
|
27
27
|
import { OrbitControls } from '@react-three/drei';
|
|
28
28
|
|
|
29
29
|
const config: SceneConfig = {
|
|
30
|
-
|
|
30
|
+
modelId: 'franka_emika_panda',
|
|
31
31
|
sceneFile: 'scene.xml',
|
|
32
32
|
homeJoints: [1.707, -1.754, 0.003, -2.702, 0.003, 0.951, 2.490],
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
function App() {
|
|
36
|
-
const apiRef = useRef<MujocoSimAPI>(null);
|
|
37
|
-
|
|
38
36
|
return (
|
|
39
37
|
<MujocoProvider>
|
|
40
38
|
<MujocoCanvas
|
|
41
|
-
ref={apiRef}
|
|
42
39
|
config={config}
|
|
43
40
|
camera={{ position: [2, -1.5, 2.5], up: [0, 0, 1], fov: 45 }}
|
|
44
41
|
shadows
|
|
@@ -56,25 +53,26 @@ function App() {
|
|
|
56
53
|
}
|
|
57
54
|
```
|
|
58
55
|
|
|
59
|
-
##
|
|
56
|
+
## `useMujoco()`
|
|
60
57
|
|
|
61
|
-
`useMujoco()` gives you the
|
|
58
|
+
Inside `<MujocoCanvas>` or `<MujocoPhysics>`, `useMujoco()` gives you the simulation API, refs to the live model/data, and status:
|
|
62
59
|
|
|
63
60
|
```tsx
|
|
64
61
|
import { useMujoco } from 'mujoco-react';
|
|
65
62
|
|
|
66
|
-
|
|
63
|
+
function StatusOverlay() {
|
|
64
|
+
const { status, api, mjModelRef, mjDataRef } = useMujoco();
|
|
67
65
|
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
if (status !== 'ready') return <span>Loading...</span>;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<button onClick={() => api?.reset()}>
|
|
70
|
+
Reset ({mjModelRef.current?.nq} joints)
|
|
71
|
+
</button>
|
|
72
|
+
);
|
|
73
73
|
}
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
Most users won't need this — `<MujocoCanvas>` and hooks like `useBeforePhysicsStep` handle the model/data lifecycle for you. But the raw module is always available when you need it.
|
|
77
|
-
|
|
78
76
|
## Writing a Controller
|
|
79
77
|
|
|
80
78
|
A controller is a React component that calls `useBeforePhysicsStep` to write `data.ctrl` each frame:
|
|
@@ -183,22 +181,22 @@ const ikCtx = useIk({ optional: true });
|
|
|
183
181
|
Models are loaded from any HTTP source via `SceneConfig.baseUrl`. Defaults to [MuJoCo Menagerie](https://github.com/google-deepmind/mujoco_menagerie) on GitHub.
|
|
184
182
|
|
|
185
183
|
```tsx
|
|
186
|
-
// Menagerie
|
|
184
|
+
// Menagerie models: just set modelId
|
|
187
185
|
const franka: SceneConfig = {
|
|
188
|
-
|
|
186
|
+
modelId: 'franka_emika_panda',
|
|
189
187
|
sceneFile: 'scene.xml',
|
|
190
188
|
};
|
|
191
189
|
|
|
192
190
|
// Any GitHub repo
|
|
193
191
|
const so101: SceneConfig = {
|
|
194
|
-
|
|
192
|
+
modelId: 'so101',
|
|
195
193
|
sceneFile: 'SO101.xml',
|
|
196
194
|
baseUrl: 'https://raw.githubusercontent.com/your-org/your-repo/main/models/',
|
|
197
195
|
};
|
|
198
196
|
|
|
199
197
|
// Self-hosted
|
|
200
198
|
const custom: SceneConfig = {
|
|
201
|
-
|
|
199
|
+
modelId: 'my_robot',
|
|
202
200
|
sceneFile: 'robot.xml',
|
|
203
201
|
baseUrl: 'http://localhost:3000/models/my_robot/',
|
|
204
202
|
};
|
|
@@ -210,7 +208,7 @@ The loader fetches the scene XML, parses it for dependencies (meshes, textures,
|
|
|
210
208
|
|
|
211
209
|
```ts
|
|
212
210
|
interface SceneConfig {
|
|
213
|
-
|
|
211
|
+
modelId: string; // e.g. 'franka_emika_panda'
|
|
214
212
|
sceneFile: string; // Entry XML file, e.g. 'scene.xml'
|
|
215
213
|
baseUrl?: string; // Base URL for fetching model files
|
|
216
214
|
sceneObjects?: SceneObject[]; // Objects injected into scene XML at load time
|
|
@@ -224,7 +222,7 @@ interface SceneConfig {
|
|
|
224
222
|
|
|
225
223
|
```tsx
|
|
226
224
|
const config: SceneConfig = {
|
|
227
|
-
|
|
225
|
+
modelId: 'franka_emika_panda',
|
|
228
226
|
sceneFile: 'scene.xml',
|
|
229
227
|
sceneObjects: [
|
|
230
228
|
{ name: 'ball', type: 'sphere', size: [0.03, 0.03, 0.03],
|
|
@@ -390,24 +388,27 @@ Plays back recorded qpos trajectories with scrubbing.
|
|
|
390
388
|
|
|
391
389
|
### `useMujoco()`
|
|
392
390
|
|
|
393
|
-
Access the
|
|
391
|
+
Access the simulation API and internal refs (must be inside `<MujocoCanvas>` or `<MujocoPhysics>`):
|
|
394
392
|
|
|
395
393
|
```tsx
|
|
396
|
-
const {
|
|
394
|
+
const { api, status, mjModelRef, mjDataRef } = useMujoco();
|
|
397
395
|
```
|
|
398
396
|
|
|
399
|
-
|
|
400
|
-
|-------|------|-------------|
|
|
401
|
-
| `mujoco` | `MujocoModule \| null` | The raw WASM module, or `null` while loading |
|
|
402
|
-
| `status` | `'pending' \| 'error'` | Lifecycle state (absent once loaded) |
|
|
403
|
-
| `error` | `string \| null` | Error message if loading failed |
|
|
404
|
-
|
|
405
|
-
### `useMujocoSim()`
|
|
397
|
+
### `useMujocoWasm()`
|
|
406
398
|
|
|
407
|
-
Access the
|
|
399
|
+
Access the raw WASM module lifecycle from any child of `<MujocoProvider>`. Most users won't need this — `useMujoco()` and hooks like `useBeforePhysicsStep` handle the model/data lifecycle for you.
|
|
408
400
|
|
|
409
401
|
```tsx
|
|
410
|
-
|
|
402
|
+
import { useMujocoWasm } from 'mujoco-react';
|
|
403
|
+
|
|
404
|
+
const { mujoco, status } = useMujocoWasm();
|
|
405
|
+
|
|
406
|
+
if (mujoco) {
|
|
407
|
+
const model = mujoco.MjModel.loadFromXML('/path/to/scene.xml');
|
|
408
|
+
const data = new mujoco.MjData(model);
|
|
409
|
+
mujoco.mj_step(model, data);
|
|
410
|
+
console.log(data.qpos); // joint positions after one step
|
|
411
|
+
}
|
|
411
412
|
```
|
|
412
413
|
|
|
413
414
|
### `useBeforePhysicsStep(callback)`
|
|
@@ -583,7 +584,7 @@ useSceneLights(1.5);
|
|
|
583
584
|
|
|
584
585
|
## MujocoSimAPI
|
|
585
586
|
|
|
586
|
-
The full API object available via `ref` or `
|
|
587
|
+
The full API object available via `ref` or `useMujoco().api`:
|
|
587
588
|
|
|
588
589
|
### Simulation Control
|
|
589
590
|
|
|
@@ -663,27 +664,9 @@ The full API object available via `ref` or `useMujocoSim().api`:
|
|
|
663
664
|
|
|
664
665
|
See [Building Controllers](https://dadd.mintlify.app/guides/building-controllers) for full patterns including config-driven controllers, IK gizmo coexistence, multi-arm support, and the `createController` factory.
|
|
665
666
|
|
|
666
|
-
###
|
|
667
|
-
|
|
668
|
-
Objects need specific MuJoCo contact parameters to be picked up by grippers:
|
|
669
|
-
|
|
670
|
-
```tsx
|
|
671
|
-
sceneObjects: [{
|
|
672
|
-
name: 'cube',
|
|
673
|
-
type: 'box',
|
|
674
|
-
size: [0.025, 0.025, 0.025],
|
|
675
|
-
position: [0.4, 0, 0.025],
|
|
676
|
-
rgba: [0.9, 0.2, 0.15, 1],
|
|
677
|
-
mass: 0.05,
|
|
678
|
-
freejoint: true,
|
|
679
|
-
friction: '1.5 0.3 0.1', // high sliding friction
|
|
680
|
-
solref: '0.01 1', // stiff contact solver
|
|
681
|
-
solimp: '0.95 0.99 0.001 0.5 2', // tight impedance
|
|
682
|
-
condim: 4, // elliptic friction cone
|
|
683
|
-
}]
|
|
684
|
-
```
|
|
667
|
+
### Contact Parameters
|
|
685
668
|
|
|
686
|
-
|
|
669
|
+
Objects that need stable contact (grasping, stacking, etc.) require tuned MuJoCo solver parameters — `friction`, `solref`, `solimp`, and `condim`. See [Contact Parameters](https://dadd.mintlify.app/guides/graspable-objects) for details.
|
|
687
670
|
|
|
688
671
|
### Click-to-Select
|
|
689
672
|
|
package/dist/index.d.ts
CHANGED
|
@@ -233,7 +233,7 @@ interface XmlPatch {
|
|
|
233
233
|
replace?: [string, string];
|
|
234
234
|
}
|
|
235
235
|
interface SceneConfig {
|
|
236
|
-
|
|
236
|
+
modelId: string;
|
|
237
237
|
sceneFile: string;
|
|
238
238
|
baseUrl?: string;
|
|
239
239
|
sceneObjects?: SceneObject[];
|
|
@@ -491,7 +491,7 @@ interface JointStateResult {
|
|
|
491
491
|
/**
|
|
492
492
|
* Hook to access the MuJoCo WASM module.
|
|
493
493
|
*/
|
|
494
|
-
declare function
|
|
494
|
+
declare function useMujocoWasm(): MujocoContextValue;
|
|
495
495
|
interface MujocoProviderProps {
|
|
496
496
|
wasmUrl?: string;
|
|
497
497
|
/** Timeout in ms for WASM module load. Default: 30000. */
|
|
@@ -573,7 +573,7 @@ interface MujocoSimContextValue {
|
|
|
573
573
|
resetCallbacks: React.RefObject<Set<() => void>>;
|
|
574
574
|
status: 'loading' | 'ready' | 'error';
|
|
575
575
|
}
|
|
576
|
-
declare function
|
|
576
|
+
declare function useMujoco(): MujocoSimContextValue;
|
|
577
577
|
declare function useBeforePhysicsStep(callback: PhysicsStepCallback): void;
|
|
578
578
|
declare function useAfterPhysicsStep(callback: PhysicsStepCallback): void;
|
|
579
579
|
interface MujocoSimProviderProps {
|
|
@@ -666,7 +666,7 @@ type ControllerComponent<TConfig> = React.FC<{
|
|
|
666
666
|
* Factory that produces a typed controller component.
|
|
667
667
|
*
|
|
668
668
|
* Controllers are React components that plug into the MuJoCo simulation tree.
|
|
669
|
-
* Inside `Impl`, use any hooks (`
|
|
669
|
+
* Inside `Impl`, use any hooks (`useMujoco`, `useBeforePhysicsStep`, etc.)
|
|
670
670
|
* to interact with the physics engine.
|
|
671
671
|
*
|
|
672
672
|
* @example
|
|
@@ -1154,4 +1154,4 @@ interface CameraAnimationAPI {
|
|
|
1154
1154
|
*/
|
|
1155
1155
|
declare function useCameraAnimation(): CameraAnimationAPI;
|
|
1156
1156
|
|
|
1157
|
-
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, IkController, 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, SelectionHighlight, type SelectionHighlightProps, 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, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useGamepad, useGravityCompensation, useIk, useJointState, useKeyboardTeleop, useMujoco,
|
|
1157
|
+
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, IkController, 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, SelectionHighlight, type SelectionHighlightProps, 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, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useGamepad, useGravityCompensation, useIk, useJointState, useKeyboardTeleop, useMujoco, useMujocoWasm, usePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePosition, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder };
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var MujocoContext = createContext({
|
|
|
11
11
|
status: "loading",
|
|
12
12
|
error: null
|
|
13
13
|
});
|
|
14
|
-
function
|
|
14
|
+
function useMujocoWasm() {
|
|
15
15
|
return useContext(MujocoContext);
|
|
16
16
|
}
|
|
17
17
|
function MujocoProvider({ wasmUrl, timeout = 3e4, children, onError }) {
|
|
@@ -400,7 +400,7 @@ async function loadScene(mujoco, config, onProgress) {
|
|
|
400
400
|
mujoco.FS.mkdir("/working");
|
|
401
401
|
} catch {
|
|
402
402
|
}
|
|
403
|
-
const baseUrl = config.baseUrl || `https://raw.githubusercontent.com/google-deepmind/mujoco_menagerie/main/${config.
|
|
403
|
+
const baseUrl = config.baseUrl || `https://raw.githubusercontent.com/google-deepmind/mujoco_menagerie/main/${config.modelId}/`;
|
|
404
404
|
const downloaded = /* @__PURE__ */ new Set();
|
|
405
405
|
const queue = [config.sceneFile];
|
|
406
406
|
const parser = new DOMParser();
|
|
@@ -508,7 +508,7 @@ function scanDependencies(xmlString, currentFile, parser, downloaded, queue) {
|
|
|
508
508
|
});
|
|
509
509
|
}
|
|
510
510
|
function SceneRenderer(props) {
|
|
511
|
-
const { mjModelRef, mjDataRef, mujocoRef, onSelectionRef, status } =
|
|
511
|
+
const { mjModelRef, mjDataRef, mujocoRef, onSelectionRef, status } = useMujoco();
|
|
512
512
|
const groupRef = useRef(null);
|
|
513
513
|
const bodyRefs = useRef([]);
|
|
514
514
|
const prevModelRef = useRef(null);
|
|
@@ -647,14 +647,14 @@ var _rayGeomId = new Int32Array(1);
|
|
|
647
647
|
var _projRaycaster = new THREE11.Raycaster();
|
|
648
648
|
var _projNdc = new THREE11.Vector2();
|
|
649
649
|
var MujocoSimContext = createContext(null);
|
|
650
|
-
function
|
|
650
|
+
function useMujoco() {
|
|
651
651
|
const ctx = useContext(MujocoSimContext);
|
|
652
652
|
if (!ctx)
|
|
653
|
-
throw new Error("
|
|
653
|
+
throw new Error("useMujoco must be used inside <MujocoSimProvider>");
|
|
654
654
|
return ctx;
|
|
655
655
|
}
|
|
656
656
|
function useBeforePhysicsStep(callback) {
|
|
657
|
-
const { beforeStepCallbacks } =
|
|
657
|
+
const { beforeStepCallbacks } = useMujoco();
|
|
658
658
|
const callbackRef = useRef(callback);
|
|
659
659
|
callbackRef.current = callback;
|
|
660
660
|
useEffect(() => {
|
|
@@ -666,7 +666,7 @@ function useBeforePhysicsStep(callback) {
|
|
|
666
666
|
}, [beforeStepCallbacks]);
|
|
667
667
|
}
|
|
668
668
|
function useAfterPhysicsStep(callback) {
|
|
669
|
-
const { afterStepCallbacks } =
|
|
669
|
+
const { afterStepCallbacks } = useMujoco();
|
|
670
670
|
const callbackRef = useRef(callback);
|
|
671
671
|
callbackRef.current = callback;
|
|
672
672
|
useEffect(() => {
|
|
@@ -1436,7 +1436,7 @@ var MujocoCanvas = forwardRef(
|
|
|
1436
1436
|
children,
|
|
1437
1437
|
...canvasProps
|
|
1438
1438
|
}, ref) {
|
|
1439
|
-
const { mujoco, status: wasmStatus, error: wasmError } =
|
|
1439
|
+
const { mujoco, status: wasmStatus, error: wasmError } = useMujocoWasm();
|
|
1440
1440
|
useEffect(() => {
|
|
1441
1441
|
if (wasmStatus === "error" && onError) {
|
|
1442
1442
|
onError(new Error(wasmError ?? "WASM load failed"));
|
|
@@ -1467,7 +1467,7 @@ var MujocoCanvas = forwardRef(
|
|
|
1467
1467
|
);
|
|
1468
1468
|
var MujocoPhysics = forwardRef(
|
|
1469
1469
|
function MujocoPhysics2({ onError, children, ...props }, ref) {
|
|
1470
|
-
const { mujoco, status: wasmStatus, error: wasmError } =
|
|
1470
|
+
const { mujoco, status: wasmStatus, error: wasmError } = useMujocoWasm();
|
|
1471
1471
|
useEffect(() => {
|
|
1472
1472
|
if (wasmStatus === "error" && onError) {
|
|
1473
1473
|
onError(new Error(wasmError ?? "WASM load failed"));
|
|
@@ -1783,7 +1783,7 @@ function IkControllerImpl({
|
|
|
1783
1783
|
config,
|
|
1784
1784
|
children
|
|
1785
1785
|
}) {
|
|
1786
|
-
const { mjModelRef, mjDataRef, mujocoRef, configRef, resetCallbacks, status } =
|
|
1786
|
+
const { mjModelRef, mjDataRef, mujocoRef, configRef, resetCallbacks, status } = useMujoco();
|
|
1787
1787
|
const ikEnabledRef = useRef(false);
|
|
1788
1788
|
const ikCalculatingRef = useRef(false);
|
|
1789
1789
|
const ikTargetRef = useRef(new THREE11.Group());
|
|
@@ -1977,7 +1977,7 @@ var _pos = new THREE11.Vector3();
|
|
|
1977
1977
|
var _quat = new THREE11.Quaternion();
|
|
1978
1978
|
var _scale = new THREE11.Vector3(1, 1, 1);
|
|
1979
1979
|
function IkGizmo({ siteName, scale = 0.18, onDrag }) {
|
|
1980
|
-
const { mjModelRef, mjDataRef, status } =
|
|
1980
|
+
const { mjModelRef, mjDataRef, status } = useMujoco();
|
|
1981
1981
|
const { ikTargetRef, siteIdRef, ikEnabledRef, setIkEnabled } = useIk();
|
|
1982
1982
|
const wrapperRef = useRef(null);
|
|
1983
1983
|
const pivotRef = useRef(null);
|
|
@@ -2075,7 +2075,7 @@ function ContactMarkers({
|
|
|
2075
2075
|
visible = true,
|
|
2076
2076
|
...groupProps
|
|
2077
2077
|
} = {}) {
|
|
2078
|
-
const { mjDataRef, status } =
|
|
2078
|
+
const { mjDataRef, status } = useMujoco();
|
|
2079
2079
|
const meshRef = useRef(null);
|
|
2080
2080
|
useFrame(() => {
|
|
2081
2081
|
const mesh = meshRef.current;
|
|
@@ -2119,7 +2119,7 @@ function DragInteraction({
|
|
|
2119
2119
|
showArrow = true,
|
|
2120
2120
|
...groupProps
|
|
2121
2121
|
}) {
|
|
2122
|
-
const { mjDataRef, mujocoRef, mjModelRef, status } =
|
|
2122
|
+
const { mjDataRef, mujocoRef, mjModelRef, status } = useMujoco();
|
|
2123
2123
|
const { gl, camera, scene, controls } = useThree();
|
|
2124
2124
|
const draggingRef = useRef(false);
|
|
2125
2125
|
const bodyIdRef = useRef(-1);
|
|
@@ -2277,7 +2277,7 @@ function DragInteraction({
|
|
|
2277
2277
|
return /* @__PURE__ */ jsx("group", { ...groupProps, ref: groupRef });
|
|
2278
2278
|
}
|
|
2279
2279
|
function useSceneLights(intensity = 1) {
|
|
2280
|
-
const { mjModelRef, status } =
|
|
2280
|
+
const { mjModelRef, status } = useMujoco();
|
|
2281
2281
|
const { scene } = useThree();
|
|
2282
2282
|
const lightsRef = useRef([]);
|
|
2283
2283
|
const targetsRef = useRef([]);
|
|
@@ -2398,7 +2398,7 @@ function Debug({
|
|
|
2398
2398
|
showTendons = false,
|
|
2399
2399
|
...groupProps
|
|
2400
2400
|
}) {
|
|
2401
|
-
const { mjModelRef, mjDataRef, status } =
|
|
2401
|
+
const { mjModelRef, mjDataRef, status } = useMujoco();
|
|
2402
2402
|
const { scene } = useThree();
|
|
2403
2403
|
const groupRef = useRef(null);
|
|
2404
2404
|
const debugGeometry = useMemo(() => {
|
|
@@ -2668,7 +2668,7 @@ var DEFAULT_TENDON_COLOR = new THREE11.Color(0.3, 0.3, 0.8);
|
|
|
2668
2668
|
var DEFAULT_TENDON_WIDTH = 2e-3;
|
|
2669
2669
|
new THREE11.Vector3();
|
|
2670
2670
|
function TendonRenderer(props) {
|
|
2671
|
-
const { mjModelRef, mjDataRef, status } =
|
|
2671
|
+
const { mjModelRef, mjDataRef, status } = useMujoco();
|
|
2672
2672
|
const groupRef = useRef(null);
|
|
2673
2673
|
const meshesRef = useRef([]);
|
|
2674
2674
|
const curvesRef = useRef([]);
|
|
@@ -2772,7 +2772,7 @@ function TendonRenderer(props) {
|
|
|
2772
2772
|
return /* @__PURE__ */ jsx("group", { ...props, ref: groupRef });
|
|
2773
2773
|
}
|
|
2774
2774
|
function FlexRenderer(props) {
|
|
2775
|
-
const { mjModelRef, mjDataRef, status } =
|
|
2775
|
+
const { mjModelRef, mjDataRef, status } = useMujoco();
|
|
2776
2776
|
const groupRef = useRef(null);
|
|
2777
2777
|
const meshesRef = useRef([]);
|
|
2778
2778
|
useEffect(() => {
|
|
@@ -2852,7 +2852,7 @@ function getGeomNameCached(model, geomId) {
|
|
|
2852
2852
|
return name;
|
|
2853
2853
|
}
|
|
2854
2854
|
function useContacts(bodyName, callback) {
|
|
2855
|
-
const { mjModelRef, status } =
|
|
2855
|
+
const { mjModelRef, status } = useMujoco();
|
|
2856
2856
|
const contactsRef = useRef([]);
|
|
2857
2857
|
const bodyIdRef = useRef(-1);
|
|
2858
2858
|
const bodyResolvedRef = useRef(false);
|
|
@@ -2951,7 +2951,7 @@ function ContactListener({
|
|
|
2951
2951
|
return null;
|
|
2952
2952
|
}
|
|
2953
2953
|
function useTrajectoryPlayer(trajectory, options = {}) {
|
|
2954
|
-
const { mjModelRef, mjDataRef, mujocoRef, pausedRef } =
|
|
2954
|
+
const { mjModelRef, mjDataRef, mujocoRef, pausedRef } = useMujoco();
|
|
2955
2955
|
const fps = options.fps ?? 30;
|
|
2956
2956
|
const loop = options.loop ?? false;
|
|
2957
2957
|
const playingRef = useRef(false);
|
|
@@ -3106,7 +3106,7 @@ function SelectionHighlight({
|
|
|
3106
3106
|
return null;
|
|
3107
3107
|
}
|
|
3108
3108
|
function useActuators() {
|
|
3109
|
-
const { mjModelRef, status } =
|
|
3109
|
+
const { mjModelRef, status } = useMujoco();
|
|
3110
3110
|
return useMemo(() => {
|
|
3111
3111
|
if (status !== "ready") return [];
|
|
3112
3112
|
const model = mjModelRef.current;
|
|
@@ -3125,7 +3125,7 @@ function useActuators() {
|
|
|
3125
3125
|
}
|
|
3126
3126
|
var _mat42 = new THREE11.Matrix4();
|
|
3127
3127
|
function useSitePosition(siteName) {
|
|
3128
|
-
const { mjModelRef, mjDataRef, status } =
|
|
3128
|
+
const { mjModelRef, mjDataRef, status } = useMujoco();
|
|
3129
3129
|
const siteIdRef = useRef(-1);
|
|
3130
3130
|
const positionRef = useRef(new THREE11.Vector3());
|
|
3131
3131
|
const quaternionRef = useRef(new THREE11.Quaternion());
|
|
@@ -3182,7 +3182,7 @@ function useGravityCompensation(enabled = true) {
|
|
|
3182
3182
|
});
|
|
3183
3183
|
}
|
|
3184
3184
|
function useSensor(name) {
|
|
3185
|
-
const { mjModelRef, mjDataRef, status } =
|
|
3185
|
+
const { mjModelRef, mjDataRef, status } = useMujoco();
|
|
3186
3186
|
const sensorIdRef = useRef(-1);
|
|
3187
3187
|
const sensorAdrRef = useRef(0);
|
|
3188
3188
|
const sensorDimRef = useRef(0);
|
|
@@ -3212,7 +3212,7 @@ function useSensor(name) {
|
|
|
3212
3212
|
return { value: valueRef, size: sensorDimRef.current };
|
|
3213
3213
|
}
|
|
3214
3214
|
function useSensors() {
|
|
3215
|
-
const { mjModelRef, status } =
|
|
3215
|
+
const { mjModelRef, status } = useMujoco();
|
|
3216
3216
|
return useMemo(() => {
|
|
3217
3217
|
const model = mjModelRef.current;
|
|
3218
3218
|
if (!model || status !== "ready") return [];
|
|
@@ -3249,7 +3249,7 @@ function useSensors() {
|
|
|
3249
3249
|
}, [mjModelRef, status]);
|
|
3250
3250
|
}
|
|
3251
3251
|
function useJointState(name) {
|
|
3252
|
-
const { mjModelRef, mjDataRef, status } =
|
|
3252
|
+
const { mjModelRef, mjDataRef, status } = useMujoco();
|
|
3253
3253
|
const jointIdRef = useRef(-1);
|
|
3254
3254
|
const qposAdrRef = useRef(0);
|
|
3255
3255
|
const dofAdrRef = useRef(0);
|
|
@@ -3309,7 +3309,7 @@ function useJointState(name) {
|
|
|
3309
3309
|
return { position: positionRef, velocity: velocityRef };
|
|
3310
3310
|
}
|
|
3311
3311
|
function useBodyState(name) {
|
|
3312
|
-
const { mjModelRef, status } =
|
|
3312
|
+
const { mjModelRef, status } = useMujoco();
|
|
3313
3313
|
const bodyIdRef = useRef(-1);
|
|
3314
3314
|
const position = useRef(new THREE11.Vector3());
|
|
3315
3315
|
const quaternion = useRef(new THREE11.Quaternion());
|
|
@@ -3341,7 +3341,7 @@ function useBodyState(name) {
|
|
|
3341
3341
|
return { position, quaternion, linearVelocity, angularVelocity };
|
|
3342
3342
|
}
|
|
3343
3343
|
function useCtrl(name) {
|
|
3344
|
-
const { mjModelRef, mjDataRef, status } =
|
|
3344
|
+
const { mjModelRef, mjDataRef, status } = useMujoco();
|
|
3345
3345
|
const actuatorIdRef = useRef(-1);
|
|
3346
3346
|
const valueRef = useRef(0);
|
|
3347
3347
|
useEffect(() => {
|
|
@@ -3358,7 +3358,7 @@ function useCtrl(name) {
|
|
|
3358
3358
|
return [valueRef, setValue];
|
|
3359
3359
|
}
|
|
3360
3360
|
function useKeyboardTeleop(config) {
|
|
3361
|
-
const { mjModelRef, mjDataRef, status } =
|
|
3361
|
+
const { mjModelRef, mjDataRef, status } = useMujoco();
|
|
3362
3362
|
const pressedRef = useRef(/* @__PURE__ */ new Set());
|
|
3363
3363
|
const toggleStateRef = useRef(/* @__PURE__ */ new Map());
|
|
3364
3364
|
const enabledRef = useRef(config.enabled ?? true);
|
|
@@ -3421,7 +3421,7 @@ function useKeyboardTeleop(config) {
|
|
|
3421
3421
|
});
|
|
3422
3422
|
}
|
|
3423
3423
|
function usePolicy(config) {
|
|
3424
|
-
const { mjModelRef } =
|
|
3424
|
+
const { mjModelRef } = useMujoco();
|
|
3425
3425
|
const lastActionTimeRef = useRef(0);
|
|
3426
3426
|
const lastActionRef = useRef(null);
|
|
3427
3427
|
const isRunningRef = useRef(true);
|
|
@@ -3455,7 +3455,7 @@ function usePolicy(config) {
|
|
|
3455
3455
|
};
|
|
3456
3456
|
}
|
|
3457
3457
|
function useTrajectoryRecorder(options = {}) {
|
|
3458
|
-
const { mjModelRef } =
|
|
3458
|
+
const { mjModelRef } = useMujoco();
|
|
3459
3459
|
const recordingRef = useRef(false);
|
|
3460
3460
|
const framesRef = useRef([]);
|
|
3461
3461
|
const fields = options.fields ?? ["qpos"];
|
|
@@ -3531,7 +3531,7 @@ function useTrajectoryRecorder(options = {}) {
|
|
|
3531
3531
|
};
|
|
3532
3532
|
}
|
|
3533
3533
|
function useGamepad(config) {
|
|
3534
|
-
const { mjModelRef, status } =
|
|
3534
|
+
const { mjModelRef, status } = useMujoco();
|
|
3535
3535
|
const configRef = useRef(config);
|
|
3536
3536
|
configRef.current = config;
|
|
3537
3537
|
const axisCacheRef = useRef(/* @__PURE__ */ new Map());
|
|
@@ -3627,7 +3627,7 @@ function useVideoRecorder(options = {}) {
|
|
|
3627
3627
|
};
|
|
3628
3628
|
}
|
|
3629
3629
|
function useCtrlNoise(config = {}) {
|
|
3630
|
-
const { mjModelRef } =
|
|
3630
|
+
const { mjModelRef } = useMujoco();
|
|
3631
3631
|
const configRef = useRef(config);
|
|
3632
3632
|
configRef.current = config;
|
|
3633
3633
|
const noiseRef = useRef(null);
|
|
@@ -3907,6 +3907,6 @@ function useCameraAnimation() {
|
|
|
3907
3907
|
* useCameraAnimation — composable camera animation hook.
|
|
3908
3908
|
*/
|
|
3909
3909
|
|
|
3910
|
-
export { ContactListener, ContactMarkers, Debug, DragInteraction, FlexRenderer, IkController, IkGizmo, MujocoCanvas, MujocoPhysics, MujocoProvider, MujocoSimProvider, SceneLights, SelectionHighlight, TendonRenderer, TrajectoryPlayer, createController, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, getContact, getName, loadScene, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useGamepad, useGravityCompensation, useIk, useJointState, useKeyboardTeleop, useMujoco,
|
|
3910
|
+
export { ContactListener, ContactMarkers, Debug, DragInteraction, FlexRenderer, IkController, IkGizmo, MujocoCanvas, MujocoPhysics, MujocoProvider, MujocoSimProvider, SceneLights, SelectionHighlight, TendonRenderer, TrajectoryPlayer, createController, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, getContact, getName, loadScene, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useGamepad, useGravityCompensation, useIk, useJointState, useKeyboardTeleop, useMujoco, useMujocoWasm, usePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePosition, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder };
|
|
3911
3911
|
//# sourceMappingURL=index.js.map
|
|
3912
3912
|
//# sourceMappingURL=index.js.map
|