mujoco-react 8.1.1 → 8.2.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
@@ -8,7 +8,9 @@
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
- **[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)**
11
+ [![npm](https://img.shields.io/npm/v/mujoco-react)](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
 
@@ -111,22 +113,45 @@ Drop it into the tree:
111
113
  </MujocoCanvas>
112
114
  ```
113
115
 
114
- The `createController<TConfig>()` factory adds typed config and default merging for reusable plugins:
116
+ The `createControllerHook` factory produces a typed hook with config stabilization and default merging. Pass `null` to disable:
117
+
118
+ ```tsx
119
+ import { createControllerHook, useBeforePhysicsStep } from "mujoco-react";
120
+
121
+ export const useMyController = createControllerHook<{ gain: number }, { value: number }>(
122
+ { name: "useMyController", defaultConfig: { gain: 1.0 } },
123
+ (config) => {
124
+ useBeforePhysicsStep((_model, data) => {
125
+ if (!config) return;
126
+ data.ctrl[0] = config.gain * Math.sin(data.time);
127
+ });
128
+ if (!config) return null;
129
+ return { value: config.gain };
130
+ },
131
+ );
132
+
133
+ // const result = useMyController({ gain: 2.0 });
134
+ // const disabled = useMyController(null); // returns null
135
+ ```
136
+
137
+ The `createController` factory is the component equivalent — same config stabilization, but returns a component that can render children:
115
138
 
116
139
  ```tsx
117
- import { createController, useBeforePhysicsStep } from "mujoco-react";
140
+ import { createController, useBeforePhysicsStep, Debug } from "mujoco-react";
118
141
 
119
142
  export const MyController = createController<{ gain: number }>(
120
143
  { name: "MyController", defaultConfig: { gain: 1.0 } },
121
- ({ config }) => {
144
+ ({ config, children }) => {
122
145
  useBeforePhysicsStep((_model, data) => {
123
146
  data.ctrl[0] = config.gain * Math.sin(data.time);
124
147
  });
125
- return null;
148
+ return <>{children}</>;
126
149
  },
127
150
  );
128
151
 
129
- // <MyController config={{ gain: 2.0 }} />
152
+ // <MyController config={{ gain: 2.0 }}>
153
+ // <Debug showJoints />
154
+ // </MyController>
130
155
  ```
131
156
 
132
157
  ## Architecture
@@ -727,7 +752,7 @@ The full API object available via `ref` or `useMujoco()` (when `isReady`):
727
752
 
728
753
  ### Building Controllers
729
754
 
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` factory.
755
+ 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
756
 
732
757
  ### Contact Parameters
733
758
 
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mujoco-react",
3
- "version": "8.1.1",
3
+ "version": "8.2.0",
4
4
  "description": "Composable React Three Fiber building blocks for MuJoCo WASM simulations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
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