mujoco-react 7.0.1 → 8.1.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 +96 -60
- package/dist/index.d.ts +112 -33
- package/dist/index.js +160 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/TrajectoryPlayer.tsx +16 -2
- package/src/hooks/useBodyState.ts +2 -2
- package/src/hooks/useContacts.ts +3 -3
- package/src/hooks/useCtrl.ts +31 -18
- package/src/hooks/useJointState.ts +2 -2
- package/src/hooks/useSensor.ts +14 -5
- package/src/hooks/useSitePosition.ts +2 -2
- package/src/hooks/useTrajectoryPlayer.ts +152 -29
- package/src/index.ts +13 -0
- package/src/types.ts +71 -14
package/src/types.ts
CHANGED
|
@@ -8,6 +8,34 @@ import type { ReactNode } from 'react';
|
|
|
8
8
|
import type { CanvasProps } from '@react-three/fiber';
|
|
9
9
|
import * as THREE from 'three';
|
|
10
10
|
|
|
11
|
+
// ---- Register (type-safe named resources) ----
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Module augmentation interface for type-safe resource names.
|
|
15
|
+
*
|
|
16
|
+
* Declare your model's resource names via module augmentation:
|
|
17
|
+
* ```ts
|
|
18
|
+
* declare module 'mujoco-react' {
|
|
19
|
+
* interface Register {
|
|
20
|
+
* actuators: 'joint1' | 'joint2' | 'gripper';
|
|
21
|
+
* sensors: 'force_sensor' | 'torque_sensor';
|
|
22
|
+
* bodies: 'link0' | 'link1' | 'hand';
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* When no augmentation is declared, all names fall back to `string`.
|
|
28
|
+
*/
|
|
29
|
+
export interface Register {}
|
|
30
|
+
|
|
31
|
+
export type Actuators = Register extends { actuators: infer T extends string } ? T : string;
|
|
32
|
+
export type Sensors = Register extends { sensors: infer T extends string } ? T : string;
|
|
33
|
+
export type Bodies = Register extends { bodies: infer T extends string } ? T : string;
|
|
34
|
+
export type Joints = Register extends { joints: infer T extends string } ? T : string;
|
|
35
|
+
export type Sites = Register extends { sites: infer T extends string } ? T : string;
|
|
36
|
+
export type Geoms = Register extends { geoms: infer T extends string } ? T : string;
|
|
37
|
+
export type Keyframes = Register extends { keyframes: infer T extends string } ? T : string;
|
|
38
|
+
|
|
11
39
|
// ---- MuJoCo WASM Types ----
|
|
12
40
|
|
|
13
41
|
/**
|
|
@@ -300,7 +328,7 @@ export interface SceneConfig {
|
|
|
300
328
|
|
|
301
329
|
export interface IkConfig {
|
|
302
330
|
/** MuJoCo site name for IK target. */
|
|
303
|
-
siteName:
|
|
331
|
+
siteName: Sites;
|
|
304
332
|
/** Number of joints to solve for. */
|
|
305
333
|
numJoints: number;
|
|
306
334
|
/** Custom IK solver. When omitted, uses built-in Damped Least-Squares solver. */
|
|
@@ -459,10 +487,12 @@ export interface TrajectoryData {
|
|
|
459
487
|
fps: number;
|
|
460
488
|
}
|
|
461
489
|
|
|
490
|
+
export type PlaybackState = 'idle' | 'playing' | 'paused' | 'completed';
|
|
491
|
+
|
|
462
492
|
// ---- Keyboard Teleop (spec 12.1) ----
|
|
463
493
|
|
|
464
494
|
export interface KeyBinding {
|
|
465
|
-
actuator:
|
|
495
|
+
actuator: Actuators;
|
|
466
496
|
delta?: number;
|
|
467
497
|
toggle?: [number, number];
|
|
468
498
|
set?: number;
|
|
@@ -512,12 +542,18 @@ export interface SceneLightsProps {
|
|
|
512
542
|
intensity?: number;
|
|
513
543
|
}
|
|
514
544
|
|
|
545
|
+
export type TrajectoryInput = TrajectoryFrame[] | number[][];
|
|
546
|
+
|
|
515
547
|
export interface TrajectoryPlayerProps {
|
|
516
|
-
trajectory:
|
|
548
|
+
trajectory: TrajectoryInput;
|
|
517
549
|
fps?: number;
|
|
550
|
+
speed?: number;
|
|
518
551
|
loop?: boolean;
|
|
519
552
|
playing?: boolean;
|
|
553
|
+
mode?: 'kinematic' | 'physics';
|
|
520
554
|
onFrame?: (frameIdx: number) => void;
|
|
555
|
+
onComplete?: () => void;
|
|
556
|
+
onStateChange?: (state: PlaybackState) => void;
|
|
521
557
|
}
|
|
522
558
|
|
|
523
559
|
export interface SelectionHighlightProps {
|
|
@@ -527,13 +563,13 @@ export interface SelectionHighlightProps {
|
|
|
527
563
|
}
|
|
528
564
|
|
|
529
565
|
export interface ContactListenerProps {
|
|
530
|
-
body:
|
|
566
|
+
body: Bodies;
|
|
531
567
|
onContactEnter?: (info: ContactInfo) => void;
|
|
532
568
|
onContactExit?: (info: ContactInfo) => void;
|
|
533
569
|
}
|
|
534
570
|
|
|
535
571
|
export interface BodyProps {
|
|
536
|
-
name:
|
|
572
|
+
name: Bodies;
|
|
537
573
|
type: 'box' | 'sphere' | 'cylinder';
|
|
538
574
|
size: [number, number, number];
|
|
539
575
|
position?: [number, number, number];
|
|
@@ -562,7 +598,7 @@ export interface MujocoSimAPI {
|
|
|
562
598
|
step(n?: number): void;
|
|
563
599
|
getTime(): number;
|
|
564
600
|
getTimestep(): number;
|
|
565
|
-
applyKeyframe(nameOrIndex:
|
|
601
|
+
applyKeyframe(nameOrIndex: Keyframes | number): void;
|
|
566
602
|
|
|
567
603
|
// State management (spec 4.1, 4.2, 4.3)
|
|
568
604
|
saveState(): StateSnapshot;
|
|
@@ -573,17 +609,17 @@ export interface MujocoSimAPI {
|
|
|
573
609
|
getQvel(): Float64Array;
|
|
574
610
|
|
|
575
611
|
// Actuator / control (spec 3.1)
|
|
576
|
-
setCtrl(nameOrValues:
|
|
612
|
+
setCtrl(nameOrValues: Actuators | Record<Actuators, number>, value?: number): void;
|
|
577
613
|
getCtrl(): Float64Array;
|
|
578
614
|
|
|
579
615
|
// Force application (spec 8.1)
|
|
580
|
-
applyForce(bodyName:
|
|
581
|
-
applyTorque(bodyName:
|
|
582
|
-
setExternalForce(bodyName:
|
|
616
|
+
applyForce(bodyName: Bodies, force: THREE.Vector3, point?: THREE.Vector3): void;
|
|
617
|
+
applyTorque(bodyName: Bodies, torque: THREE.Vector3): void;
|
|
618
|
+
setExternalForce(bodyName: Bodies, force: THREE.Vector3, torque: THREE.Vector3): void;
|
|
583
619
|
applyGeneralizedForce(values: Float64Array | number[]): void;
|
|
584
620
|
|
|
585
621
|
// Sensors (spec 2.1)
|
|
586
|
-
getSensorData(name:
|
|
622
|
+
getSensorData(name: Sensors): Float64Array | null;
|
|
587
623
|
|
|
588
624
|
// Contacts (spec 2.4)
|
|
589
625
|
getContacts(): ContactInfo[];
|
|
@@ -621,9 +657,9 @@ export interface MujocoSimAPI {
|
|
|
621
657
|
): { point: THREE.Vector3; bodyId: number; geomId: number } | null;
|
|
622
658
|
|
|
623
659
|
// Domain randomization (spec 10.3)
|
|
624
|
-
setBodyMass(name:
|
|
625
|
-
setGeomFriction(name:
|
|
626
|
-
setGeomSize(name:
|
|
660
|
+
setBodyMass(name: Bodies, mass: number): void;
|
|
661
|
+
setGeomFriction(name: Geoms, friction: [number, number, number]): void;
|
|
662
|
+
setGeomSize(name: Geoms, size: [number, number, number]): void;
|
|
627
663
|
|
|
628
664
|
// Internal refs for advanced use
|
|
629
665
|
readonly mjModelRef: React.RefObject<MujocoModel | null>;
|
|
@@ -659,11 +695,32 @@ export interface MujocoContextValue {
|
|
|
659
695
|
error: string | null;
|
|
660
696
|
}
|
|
661
697
|
|
|
698
|
+
/** @deprecated Use `SensorHandle` instead. */
|
|
662
699
|
export interface SensorResult {
|
|
663
700
|
value: React.RefObject<Float64Array>;
|
|
664
701
|
size: number;
|
|
665
702
|
}
|
|
666
703
|
|
|
704
|
+
export interface CtrlHandle {
|
|
705
|
+
/** Read the current ctrl value. */
|
|
706
|
+
read(): number;
|
|
707
|
+
/** Write a ctrl value (goes directly to data.ctrl). */
|
|
708
|
+
write(value: number): void;
|
|
709
|
+
/** Actuator name. */
|
|
710
|
+
name: Actuators;
|
|
711
|
+
/** Actuator control range [min, max]. */
|
|
712
|
+
range: [number, number];
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
export interface SensorHandle {
|
|
716
|
+
/** Read the current sensor data. */
|
|
717
|
+
read(): Float64Array;
|
|
718
|
+
/** Sensor dimensionality. */
|
|
719
|
+
dim: number;
|
|
720
|
+
/** Sensor name. */
|
|
721
|
+
name: Sensors;
|
|
722
|
+
}
|
|
723
|
+
|
|
667
724
|
export interface BodyStateResult {
|
|
668
725
|
position: React.RefObject<THREE.Vector3>;
|
|
669
726
|
quaternion: React.RefObject<THREE.Quaternion>;
|