mujoco-react 0.1.0 → 0.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 +3 -3
- package/dist/index.d.ts +5 -2
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/MujocoCanvas.tsx +6 -3
- package/src/core/MujocoSimProvider.tsx +14 -3
package/README.md
CHANGED
|
@@ -31,13 +31,13 @@ const config: SceneConfig = {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
function App() {
|
|
34
|
-
const apiRef = useRef<MujocoSimAPI
|
|
34
|
+
const apiRef = useRef<MujocoSimAPI>(null);
|
|
35
35
|
|
|
36
36
|
return (
|
|
37
37
|
<MujocoProvider>
|
|
38
38
|
<MujocoCanvas
|
|
39
|
+
ref={apiRef}
|
|
39
40
|
config={config}
|
|
40
|
-
onReady={(api) => { apiRef.current = api; }}
|
|
41
41
|
camera={{ position: [2, -1.5, 2.5], up: [0, 0, 1], fov: 45 }}
|
|
42
42
|
shadows
|
|
43
43
|
style={{ width: '100%', height: '100vh' }}
|
|
@@ -392,7 +392,7 @@ Ref-based site position/quaternion tracking.
|
|
|
392
392
|
|
|
393
393
|
## MujocoSimAPI
|
|
394
394
|
|
|
395
|
-
The full API object
|
|
395
|
+
The full API object available via `ref` or `useMujocoSim().api`:
|
|
396
396
|
|
|
397
397
|
### Simulation Control
|
|
398
398
|
|
package/dist/index.d.ts
CHANGED
|
@@ -490,8 +490,10 @@ declare function MujocoProvider({ wasmUrl, children, onError }: MujocoProviderPr
|
|
|
490
490
|
* MujocoCanvas — thin R3F Canvas wrapper for MuJoCo scenes.
|
|
491
491
|
* Accepts all R3F Canvas props and forwards them through.
|
|
492
492
|
* Supports declarative physics config props (spec 1.1).
|
|
493
|
+
*
|
|
494
|
+
* Forward ref exposes MujocoSimAPI (not the canvas element).
|
|
493
495
|
*/
|
|
494
|
-
declare const MujocoCanvas: react.ForwardRefExoticComponent<Omit<MujocoCanvasProps, "ref"> & react.RefAttributes<
|
|
496
|
+
declare const MujocoCanvas: react.ForwardRefExoticComponent<Omit<MujocoCanvasProps, "ref"> & react.RefAttributes<MujocoSimAPI>>;
|
|
495
497
|
|
|
496
498
|
/**
|
|
497
499
|
* @license
|
|
@@ -578,6 +580,7 @@ declare function useAfterPhysicsStep(callback: PhysicsStepCallback): void;
|
|
|
578
580
|
interface MujocoSimProviderProps {
|
|
579
581
|
mujoco: MujocoModule;
|
|
580
582
|
config: SceneConfig;
|
|
583
|
+
apiRef?: React.ForwardedRef<MujocoSimAPI>;
|
|
581
584
|
onReady?: (api: MujocoSimAPI) => void;
|
|
582
585
|
onError?: (error: Error) => void;
|
|
583
586
|
onStep?: (time: number) => void;
|
|
@@ -590,7 +593,7 @@ interface MujocoSimProviderProps {
|
|
|
590
593
|
interpolate?: boolean;
|
|
591
594
|
children: React.ReactNode;
|
|
592
595
|
}
|
|
593
|
-
declare function MujocoSimProvider({ mujoco, config, onReady, onError, onStep, onSelection, gravity, timestep, substeps, paused, speed, interpolate, children, }: MujocoSimProviderProps): react_jsx_runtime.JSX.Element;
|
|
596
|
+
declare function MujocoSimProvider({ mujoco, config, apiRef: externalApiRef, onReady, onError, onStep, onSelection, gravity, timestep, substeps, paused, speed, interpolate, children, }: MujocoSimProviderProps): react_jsx_runtime.JSX.Element;
|
|
594
597
|
|
|
595
598
|
/**
|
|
596
599
|
* @license
|
package/dist/index.js
CHANGED
|
@@ -553,6 +553,7 @@ function useAfterPhysicsStep(callback) {
|
|
|
553
553
|
function MujocoSimProvider({
|
|
554
554
|
mujoco,
|
|
555
555
|
config,
|
|
556
|
+
apiRef: externalApiRef,
|
|
556
557
|
onReady,
|
|
557
558
|
onError,
|
|
558
559
|
onStep,
|
|
@@ -731,8 +732,16 @@ function MujocoSimProvider({
|
|
|
731
732
|
};
|
|
732
733
|
}, [mujoco, config]);
|
|
733
734
|
useEffect(() => {
|
|
734
|
-
if (status === "ready"
|
|
735
|
-
|
|
735
|
+
if (status === "ready") {
|
|
736
|
+
const api2 = apiRef.current;
|
|
737
|
+
if (onReady) onReady(api2);
|
|
738
|
+
if (externalApiRef) {
|
|
739
|
+
if (typeof externalApiRef === "function") {
|
|
740
|
+
externalApiRef(api2);
|
|
741
|
+
} else {
|
|
742
|
+
externalApiRef.current = api2;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
736
745
|
}
|
|
737
746
|
}, [status]);
|
|
738
747
|
useFrame((state) => {
|
|
@@ -1542,11 +1551,12 @@ var MujocoCanvas = forwardRef(
|
|
|
1542
1551
|
if (wasmStatus === "error" || wasmStatus === "loading" || !mujoco) {
|
|
1543
1552
|
return null;
|
|
1544
1553
|
}
|
|
1545
|
-
return /* @__PURE__ */ jsx(Canvas, {
|
|
1554
|
+
return /* @__PURE__ */ jsx(Canvas, { ...canvasProps, children: /* @__PURE__ */ jsx(
|
|
1546
1555
|
MujocoSimProvider,
|
|
1547
1556
|
{
|
|
1548
1557
|
mujoco,
|
|
1549
1558
|
config,
|
|
1559
|
+
apiRef: ref,
|
|
1550
1560
|
onReady,
|
|
1551
1561
|
onError,
|
|
1552
1562
|
onStep,
|