mujoco-react 8.1.1 → 8.2.1
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 +22 -22
- package/dist/index.d.ts +28 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
package/README.md
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
# mujoco-react
|
|
6
6
|
|
|
7
|
-
> **Beta** — This library is under active development. The API may change between minor versions until
|
|
7
|
+
> **Beta** — This library is under active development. The API may change between minor versions until 10.0.
|
|
8
8
|
|
|
9
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.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
[](https://www.npmjs.com/package/mujoco-react)
|
|
12
|
+
|
|
13
|
+
**[Demo](https://mujoco-react-example.pages.dev)** | **[Docs](https://dadd.mintlify.app)** | **[npm](https://www.npmjs.com/package/mujoco-react)** | **[Example Source](https://github.com/noah-wardlow/mujoco-react-example)** | **[llms.txt](https://dadd.mintlify.app/llms.txt)**
|
|
12
14
|
|
|
13
15
|
## Install
|
|
14
16
|
|
|
@@ -85,50 +87,48 @@ function MyComponent() {
|
|
|
85
87
|
|
|
86
88
|
## Writing a Controller
|
|
87
89
|
|
|
88
|
-
A controller is a
|
|
90
|
+
A controller is a hook that reads sensors and writes actuators each physics step:
|
|
89
91
|
|
|
90
92
|
```tsx
|
|
91
93
|
import { useCtrl, useSensor, useBeforePhysicsStep } from "mujoco-react";
|
|
92
94
|
|
|
93
|
-
function
|
|
95
|
+
function useMyController(gain: number) {
|
|
94
96
|
const shoulder = useCtrl("shoulder");
|
|
95
97
|
const elbow = useCtrl("elbow");
|
|
96
98
|
const force = useSensor("force_sensor");
|
|
97
99
|
|
|
98
100
|
useBeforePhysicsStep(() => {
|
|
99
|
-
shoulder.write(Math.sin(Date.now() / 1000));
|
|
101
|
+
shoulder.write(gain * Math.sin(Date.now() / 1000));
|
|
100
102
|
elbow.write(force.read()[0] * -0.5);
|
|
101
103
|
});
|
|
102
|
-
return null;
|
|
103
104
|
}
|
|
104
105
|
```
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
For reusable controllers with typed config, default merging, and children, use the `createController` factory:
|
|
107
108
|
|
|
108
109
|
```tsx
|
|
109
|
-
|
|
110
|
-
<MyController />
|
|
111
|
-
</MujocoCanvas>
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
The `createController<TConfig>()` factory adds typed config and default merging for reusable plugins:
|
|
115
|
-
|
|
116
|
-
```tsx
|
|
117
|
-
import { createController, useBeforePhysicsStep } from "mujoco-react";
|
|
110
|
+
import { createController, useCtrl, useBeforePhysicsStep } from "mujoco-react";
|
|
118
111
|
|
|
119
112
|
export const MyController = createController<{ gain: number }>(
|
|
120
113
|
{ name: "MyController", defaultConfig: { gain: 1.0 } },
|
|
121
|
-
({ config }) => {
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
({ config, children }) => {
|
|
115
|
+
const shoulder = useCtrl("shoulder");
|
|
116
|
+
|
|
117
|
+
useBeforePhysicsStep(() => {
|
|
118
|
+
shoulder.write(config.gain * Math.sin(Date.now() / 1000));
|
|
124
119
|
});
|
|
125
|
-
|
|
120
|
+
|
|
121
|
+
return <>{children}</>;
|
|
126
122
|
},
|
|
127
123
|
);
|
|
128
124
|
|
|
129
|
-
// <MyController config={{ gain: 2.0 }}
|
|
125
|
+
// <MyController config={{ gain: 2.0 }}>
|
|
126
|
+
// <Debug showJoints />
|
|
127
|
+
// </MyController>
|
|
130
128
|
```
|
|
131
129
|
|
|
130
|
+
A `createControllerHook` factory is also available for the hook equivalent — see the [Building Controllers](https://dadd.mintlify.app/guides/building-controllers) guide.
|
|
131
|
+
|
|
132
132
|
## Architecture
|
|
133
133
|
|
|
134
134
|
`<MujocoCanvas>` wraps R3F `<Canvas>` and forwards all Canvas props (`camera`, `shadows`, `gl`, etc.). For full control over the Canvas, use `<MujocoPhysics>` inside your own:
|
|
@@ -727,7 +727,7 @@ The full API object available via `ref` or `useMujoco()` (when `isReady`):
|
|
|
727
727
|
|
|
728
728
|
### Building Controllers
|
|
729
729
|
|
|
730
|
-
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`
|
|
730
|
+
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 `createControllerHook`/`createController` factories.
|
|
731
731
|
|
|
732
732
|
### Contact Parameters
|
|
733
733
|
|
package/dist/index.d.ts
CHANGED
|
@@ -790,6 +790,33 @@ declare function createController<TConfig>(options: ControllerOptions<TConfig>,
|
|
|
790
790
|
config: TConfig;
|
|
791
791
|
children?: React.ReactNode;
|
|
792
792
|
}>): ControllerComponent<TConfig>;
|
|
793
|
+
/**
|
|
794
|
+
* Factory that produces a typed controller hook.
|
|
795
|
+
*
|
|
796
|
+
* Same config stabilization and default merging as `createController`,
|
|
797
|
+
* but returns a hook instead of a component. Pass `null` to disable.
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```tsx
|
|
801
|
+
* const useMyController = createControllerHook<MyConfig, MyValue>(
|
|
802
|
+
* { name: 'useMyController', defaultConfig: { gain: 1.0 } },
|
|
803
|
+
* function useMyControllerImpl(config) {
|
|
804
|
+
* // config is MyConfig | null — hooks must be called unconditionally
|
|
805
|
+
* useBeforePhysicsStep((_model, data) => {
|
|
806
|
+
* if (!config) return;
|
|
807
|
+
* data.ctrl[0] = config.gain * Math.sin(data.time);
|
|
808
|
+
* });
|
|
809
|
+
* if (!config) return null;
|
|
810
|
+
* return { /* value *\/ };
|
|
811
|
+
* },
|
|
812
|
+
* );
|
|
813
|
+
*
|
|
814
|
+
* // Usage:
|
|
815
|
+
* const value = useMyController({ gain: 2.0 });
|
|
816
|
+
* const disabled = useMyController(null); // returns null
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
declare function createControllerHook<TConfig, TValue>(options: ControllerOptions<TConfig>, useImpl: (config: TConfig | null) => TValue | null): (config: TConfig | null) => TValue | null;
|
|
793
820
|
|
|
794
821
|
/**
|
|
795
822
|
* @license
|
|
@@ -1274,4 +1301,4 @@ interface CameraAnimationAPI {
|
|
|
1274
1301
|
*/
|
|
1275
1302
|
declare function useCameraAnimation(): CameraAnimationAPI;
|
|
1276
1303
|
|
|
1277
|
-
export { type ActuatorInfo, type Actuators, type Bodies, Body, type BodyInfo, type BodyProps, type BodyStateResult, type CameraAnimationAPI, type ContactInfo, ContactListener, type ContactListenerProps, ContactMarkers, type ControllerComponent, type ControllerOptions, type CtrlHandle, Debug, type DebugProps, DragInteraction, type DragInteractionProps, FlexRenderer, type GeomInfo, type Geoms, type IKSolveFn, type IkConfig, type IkContextValue, IkGizmo, type IkGizmoProps, type JointInfo, type JointStateResult, type Joints, type KeyBinding, type KeyboardTeleopConfig, type Keyframes, 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 PlaybackState, type PolicyConfig, type RayHit, type Register, type SceneConfig, SceneLights, type SceneLightsProps, type SceneMarker, type SceneObject, type SensorHandle, type SensorInfo, type SensorResult, type Sensors, type SiteInfo, type SitePositionResult, type Sites, type StateSnapshot, TendonRenderer, type TrajectoryData, type TrajectoryFrame, type TrajectoryInput, 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 };
|
|
1304
|
+
export { type ActuatorInfo, type Actuators, type Bodies, Body, type BodyInfo, type BodyProps, type BodyStateResult, type CameraAnimationAPI, type ContactInfo, ContactListener, type ContactListenerProps, ContactMarkers, type ControllerComponent, type ControllerOptions, type CtrlHandle, Debug, type DebugProps, DragInteraction, type DragInteractionProps, FlexRenderer, type GeomInfo, type Geoms, type IKSolveFn, type IkConfig, type IkContextValue, IkGizmo, type IkGizmoProps, type JointInfo, type JointStateResult, type Joints, type KeyBinding, type KeyboardTeleopConfig, type Keyframes, 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 PlaybackState, type PolicyConfig, type RayHit, type Register, type SceneConfig, SceneLights, type SceneLightsProps, type SceneMarker, type SceneObject, type SensorHandle, type SensorInfo, type SensorResult, type Sensors, type SiteInfo, type SitePositionResult, type Sites, type StateSnapshot, TendonRenderer, type TrajectoryData, type TrajectoryFrame, type TrajectoryInput, TrajectoryPlayer, type TrajectoryPlayerProps, type XmlPatch, createController, createControllerHook, 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 };
|
package/dist/index.js
CHANGED
|
@@ -4176,6 +4176,6 @@ function useCameraAnimation() {
|
|
|
4176
4176
|
* useCameraAnimation — composable camera animation hook.
|
|
4177
4177
|
*/
|
|
4178
4178
|
|
|
4179
|
-
export { Body, ContactListener, ContactMarkers, Debug, DragInteraction, FlexRenderer, IkGizmo, MujocoCanvas, MujocoPhysics, MujocoProvider, MujocoSimProvider, SceneLights, TendonRenderer, TrajectoryPlayer, 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 };
|
|
4179
|
+
export { Body, ContactListener, ContactMarkers, Debug, DragInteraction, FlexRenderer, IkGizmo, MujocoCanvas, MujocoPhysics, MujocoProvider, MujocoSimProvider, SceneLights, TendonRenderer, TrajectoryPlayer, createController, createControllerHook, 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 };
|
|
4180
4180
|
//# sourceMappingURL=index.js.map
|
|
4181
4181
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ export {
|
|
|
23
23
|
} from './core/SceneLoader';
|
|
24
24
|
|
|
25
25
|
// Controller factory
|
|
26
|
-
export { createController } from './core/createController';
|
|
26
|
+
export { createController, createControllerHook } from './core/createController';
|
|
27
27
|
export type { ControllerOptions, ControllerComponent } from './core/createController';
|
|
28
28
|
|
|
29
29
|
// IK controller hook
|