mujoco-react 8.8.0 → 8.9.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 +91 -36
- package/bin/mujoco-react.mjs +2 -2
- package/dist/index.d.ts +23 -1
- package/dist/index.js +58 -1
- package/dist/index.js.map +1 -1
- package/dist/vite.d.ts +2 -1
- package/dist/vite.js +79 -7
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +12 -7
- package/src/types.ts +80 -0
- package/src/vite.ts +82 -8
package/README.md
CHANGED
|
@@ -39,14 +39,36 @@ export default defineConfig({
|
|
|
39
39
|
});
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
The plugin writes `src/mujoco-register.gen.
|
|
42
|
+
The plugin writes `src/mujoco-register.gen.ts` during dev and build. Commit that generated file. Vite auto-loads it, so app code imports generated values from `mujoco-react`, not from the generated file:
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
|
-
// src/mujoco-register.gen.
|
|
45
|
+
// src/mujoco-register.gen.ts
|
|
46
46
|
// Auto-generated by mujoco-react. Do not edit.
|
|
47
47
|
|
|
48
|
-
import "mujoco-react";
|
|
49
|
-
|
|
48
|
+
import { registerRobotResources } from "mujoco-react";
|
|
49
|
+
|
|
50
|
+
const generatedRobotResources = {
|
|
51
|
+
franka: {
|
|
52
|
+
actuators: { joint1: "joint1", joint2: "joint2", joint3: "joint3", gripper: "gripper" },
|
|
53
|
+
sensors: { force_sensor: "force_sensor", torque_sensor: "torque_sensor" },
|
|
54
|
+
bodies: { link0: "link0", link1: "link1", hand: "hand" },
|
|
55
|
+
joints: { joint1: "joint1", joint2: "joint2", joint3: "joint3" },
|
|
56
|
+
sites: { tcp: "tcp" },
|
|
57
|
+
geoms: { floor: "floor" },
|
|
58
|
+
keyframes: { home: "home" },
|
|
59
|
+
},
|
|
60
|
+
spot: {
|
|
61
|
+
actuators: { fl_hx: "fl_hx", fl_hy: "fl_hy", fl_kn: "fl_kn" },
|
|
62
|
+
sensors: {},
|
|
63
|
+
bodies: { body: "body", fl_hip: "fl_hip", fl_uleg: "fl_uleg" },
|
|
64
|
+
joints: { fl_hx: "fl_hx", fl_hy: "fl_hy", fl_kn: "fl_kn" },
|
|
65
|
+
sites: {},
|
|
66
|
+
geoms: { floor: "floor" },
|
|
67
|
+
keyframes: { home: "home" },
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
registerRobotResources(generatedRobotResources);
|
|
50
72
|
|
|
51
73
|
declare module "mujoco-react" {
|
|
52
74
|
interface Register {
|
|
@@ -74,20 +96,10 @@ declare module "mujoco-react" {
|
|
|
74
96
|
sensors: "force_sensor" | "torque_sensor";
|
|
75
97
|
bodies: "link0" | "link1" | "hand" | "body" | "fl_hip" | "fl_uleg";
|
|
76
98
|
}
|
|
77
|
-
|
|
78
|
-
export namespace RobotActuators {
|
|
79
|
-
export type franka = RobotResource<"franka", "actuators">;
|
|
80
|
-
export type spot = RobotResource<"spot", "actuators">;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export namespace RobotSites {
|
|
84
|
-
export type franka = RobotResource<"franka", "sites">;
|
|
85
|
-
export type spot = RobotResource<"spot", "sites">;
|
|
86
|
-
}
|
|
87
99
|
}
|
|
88
100
|
```
|
|
89
101
|
|
|
90
|
-
Once generated, hooks like `useCtrl`, `useSensor`, `useBodyState`, and API methods like `setCtrl`, `applyForce`, `getSensorData` accept the global union. For robot-scoped
|
|
102
|
+
Once generated, hooks like `useCtrl`, `useSensor`, `useBodyState`, and API methods like `setCtrl`, `applyForce`, `getSensorData` accept the global union. For robot-scoped code, use package exports such as `RobotActuators.franka.gripper`, `RobotSites.franka.tcp`, and `RobotBodies.franka.hand`. Generic type helpers like `RobotActuators<"franka">` are still available for reusable library code. When no `Register` augmentation is present, names fall back to `string`.
|
|
91
103
|
|
|
92
104
|
Non-Vite projects can generate the same file with:
|
|
93
105
|
|
|
@@ -124,10 +136,10 @@ export function App() {
|
|
|
124
136
|
|
|
125
137
|
```tsx
|
|
126
138
|
import { OrbitControls } from "@react-three/drei";
|
|
127
|
-
import { IkGizmo, useIkController } from "mujoco-react";
|
|
139
|
+
import { IkGizmo, RobotSites, useIkController } from "mujoco-react";
|
|
128
140
|
|
|
129
141
|
function PandaTools() {
|
|
130
|
-
const ik = useIkController({ siteName:
|
|
142
|
+
const ik = useIkController({ siteName: RobotSites.franka.tcp });
|
|
131
143
|
|
|
132
144
|
return (
|
|
133
145
|
<>
|
|
@@ -164,18 +176,34 @@ function MyController() {
|
|
|
164
176
|
|
|
165
177
|
Controllers are just React children that read sensors, write `data.ctrl`, apply forces, or call the `MujocoSimAPI` at physics-step time.
|
|
166
178
|
|
|
167
|
-
With generated resource
|
|
179
|
+
With generated resource values, reusable controllers can be scoped to one robot without hand-typing names:
|
|
168
180
|
|
|
169
181
|
```tsx
|
|
170
|
-
import { useCtrl, useIkController } from "mujoco-react";
|
|
171
|
-
import type { RobotActuators, RobotSites } from "mujoco-react";
|
|
172
|
-
|
|
173
|
-
const frankaGripper: RobotActuators.franka = "gripper";
|
|
174
|
-
const frankaTcp: RobotSites.franka = "tcp";
|
|
182
|
+
import { RobotActuators, RobotJoints, RobotSites, useCtrl, useIkController } from "mujoco-react";
|
|
175
183
|
|
|
176
184
|
function FrankaTypedControls() {
|
|
177
|
-
const gripper = useCtrl(
|
|
178
|
-
const ik = useIkController({
|
|
185
|
+
const gripper = useCtrl(RobotActuators.franka.gripper);
|
|
186
|
+
const ik = useIkController({
|
|
187
|
+
siteName: RobotSites.franka.tcp,
|
|
188
|
+
joints: [
|
|
189
|
+
RobotJoints.franka.joint1,
|
|
190
|
+
RobotJoints.franka.joint2,
|
|
191
|
+
RobotJoints.franka.joint3,
|
|
192
|
+
RobotJoints.franka.joint4,
|
|
193
|
+
RobotJoints.franka.joint5,
|
|
194
|
+
RobotJoints.franka.joint6,
|
|
195
|
+
RobotJoints.franka.joint7,
|
|
196
|
+
],
|
|
197
|
+
actuators: [
|
|
198
|
+
RobotActuators.franka.actuator1,
|
|
199
|
+
RobotActuators.franka.actuator2,
|
|
200
|
+
RobotActuators.franka.actuator3,
|
|
201
|
+
RobotActuators.franka.actuator4,
|
|
202
|
+
RobotActuators.franka.actuator5,
|
|
203
|
+
RobotActuators.franka.actuator6,
|
|
204
|
+
RobotActuators.franka.actuator7,
|
|
205
|
+
],
|
|
206
|
+
});
|
|
179
207
|
|
|
180
208
|
return null;
|
|
181
209
|
}
|
|
@@ -200,14 +228,14 @@ Use control groups when a robot's actuator order does not match a simple `qpos[0
|
|
|
200
228
|
|
|
201
229
|
```tsx
|
|
202
230
|
import { useRef } from "react";
|
|
203
|
-
import { resolveControlGroup, useBeforePhysicsStep } from "mujoco-react";
|
|
231
|
+
import { resolveControlGroup, RobotSites, useBeforePhysicsStep } from "mujoco-react";
|
|
204
232
|
import type { ControlGroupInfo } from "mujoco-react";
|
|
205
233
|
|
|
206
234
|
function HoldTcpPose() {
|
|
207
235
|
const armRef = useRef<ControlGroupInfo | null>(null);
|
|
208
236
|
|
|
209
237
|
useBeforePhysicsStep((model, data) => {
|
|
210
|
-
armRef.current ??= resolveControlGroup(model, { siteName:
|
|
238
|
+
armRef.current ??= resolveControlGroup(model, { siteName: RobotSites.franka.tcp });
|
|
211
239
|
if (!armRef.current) return;
|
|
212
240
|
|
|
213
241
|
armRef.current.writeCtrl(data, armRef.current.readQpos(data));
|
|
@@ -352,13 +380,14 @@ A `createControllerHook` factory is also available for the hook equivalent — s
|
|
|
352
380
|
The built-in `useIkController()` uses Damped Least-Squares. Pass `ikSolveFn` to swap in your own solver (analytical, learned, etc.):
|
|
353
381
|
|
|
354
382
|
```tsx
|
|
383
|
+
import { RobotSites } from "mujoco-react";
|
|
355
384
|
import type { IKSolveFn } from "mujoco-react";
|
|
356
385
|
|
|
357
386
|
const myIK: IKSolveFn = (pos, quat, currentQ) => {
|
|
358
387
|
return myAnalyticalSolver(pos, currentQ); // return joint angles or null
|
|
359
388
|
};
|
|
360
389
|
|
|
361
|
-
const ik = useIkController({ siteName:
|
|
390
|
+
const ik = useIkController({ siteName: RobotSites.franka.tcp, ikSolveFn: myIK });
|
|
362
391
|
```
|
|
363
392
|
|
|
364
393
|
### `useIkController(config | null)`
|
|
@@ -366,7 +395,9 @@ const ik = useIkController({ siteName: "tcp", ikSolveFn: myIK });
|
|
|
366
395
|
Hook for interactive end-effector control. Pass `null` to disable IK (safe to call unconditionally):
|
|
367
396
|
|
|
368
397
|
```tsx
|
|
369
|
-
|
|
398
|
+
import { IkGizmo, RobotSites, useIkController } from "mujoco-react";
|
|
399
|
+
|
|
400
|
+
const ik = useIkController({ siteName: RobotSites.franka.tcp });
|
|
370
401
|
return ik ? <IkGizmo controller={ik} /> : null;
|
|
371
402
|
```
|
|
372
403
|
|
|
@@ -387,14 +418,32 @@ Pass the returned value to `<IkGizmo controller={ik} />` or to your own controll
|
|
|
387
418
|
By default the controller infers scalar hinge/slide joints by walking from the site body toward the model root. For robots where the MJCF control layout is not a simple chain, pass explicit names:
|
|
388
419
|
|
|
389
420
|
```tsx
|
|
421
|
+
import { RobotActuators, RobotJoints, RobotSites } from "mujoco-react";
|
|
422
|
+
|
|
390
423
|
const leftArmIk = useIkController({
|
|
391
|
-
siteName:
|
|
392
|
-
joints: [
|
|
424
|
+
siteName: RobotSites.franka.tcp,
|
|
425
|
+
joints: [
|
|
426
|
+
RobotJoints.franka.joint1,
|
|
427
|
+
RobotJoints.franka.joint2,
|
|
428
|
+
RobotJoints.franka.joint3,
|
|
429
|
+
RobotJoints.franka.joint4,
|
|
430
|
+
RobotJoints.franka.joint5,
|
|
431
|
+
RobotJoints.franka.joint6,
|
|
432
|
+
RobotJoints.franka.joint7,
|
|
433
|
+
],
|
|
393
434
|
});
|
|
394
435
|
|
|
395
436
|
const gripperIk = useIkController({
|
|
396
|
-
siteName:
|
|
397
|
-
actuators:
|
|
437
|
+
siteName: RobotSites.franka.tcp,
|
|
438
|
+
actuators: [
|
|
439
|
+
RobotActuators.franka.actuator1,
|
|
440
|
+
RobotActuators.franka.actuator2,
|
|
441
|
+
RobotActuators.franka.actuator3,
|
|
442
|
+
RobotActuators.franka.actuator4,
|
|
443
|
+
RobotActuators.franka.actuator5,
|
|
444
|
+
RobotActuators.franka.actuator6,
|
|
445
|
+
RobotActuators.franka.actuator7,
|
|
446
|
+
],
|
|
398
447
|
});
|
|
399
448
|
```
|
|
400
449
|
|
|
@@ -749,7 +798,9 @@ await moveCameraTo(
|
|
|
749
798
|
Read sensor values by name. Returns a `SensorHandle` with `read()`, `dim`, and `name`:
|
|
750
799
|
|
|
751
800
|
```tsx
|
|
752
|
-
|
|
801
|
+
import { RobotSensors, useSensor } from "mujoco-react";
|
|
802
|
+
|
|
803
|
+
const force = useSensor(RobotSensors.franka.force_sensor);
|
|
753
804
|
// force.read() -> Float64Array, force.dim -> number
|
|
754
805
|
```
|
|
755
806
|
|
|
@@ -774,7 +825,9 @@ const { position, velocity } = useJointState("joint1");
|
|
|
774
825
|
Read/write actuator control by name. Returns a `CtrlHandle` with `read()`, `write()`, `name`, and `range`:
|
|
775
826
|
|
|
776
827
|
```tsx
|
|
777
|
-
|
|
828
|
+
import { RobotActuators, useCtrl } from "mujoco-react";
|
|
829
|
+
|
|
830
|
+
const gripper = useCtrl(RobotActuators.franka.gripper);
|
|
778
831
|
// gripper.read() -> number, gripper.write(0.04), gripper.range -> [min, max]
|
|
779
832
|
```
|
|
780
833
|
|
|
@@ -794,11 +847,13 @@ useContactEvents("block_1", {
|
|
|
794
847
|
Map keyboard keys to actuators:
|
|
795
848
|
|
|
796
849
|
```tsx
|
|
850
|
+
import { RobotActuators, useKeyboardTeleop } from "mujoco-react";
|
|
851
|
+
|
|
797
852
|
useKeyboardTeleop({
|
|
798
853
|
bindings: {
|
|
799
854
|
"w": { actuator: "forward", delta: 0.1 },
|
|
800
855
|
"s": { actuator: "forward", delta: -0.1 },
|
|
801
|
-
"v": { actuator:
|
|
856
|
+
"v": { actuator: RobotActuators.franka.gripper, toggle: [0, 0.04] },
|
|
802
857
|
},
|
|
803
858
|
});
|
|
804
859
|
```
|
package/bin/mujoco-react.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { generateMujocoRegister } from '../dist/vite.js';
|
|
|
5
5
|
|
|
6
6
|
const usage = `
|
|
7
7
|
Usage:
|
|
8
|
-
mujoco-react codegen <scene.xml> [...more.xml] [--out src/mujoco-register.gen.
|
|
8
|
+
mujoco-react codegen <scene.xml> [...more.xml] [--out src/mujoco-register.gen.ts] [--watch]
|
|
9
9
|
mujoco-react codegen franka=models/panda/scene.xml spot=models/spot/scene.xml
|
|
10
10
|
|
|
11
11
|
Vite users usually do not need this command. Prefer:
|
|
@@ -32,7 +32,7 @@ if (command !== 'codegen') {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const commandArgs = args.slice(1);
|
|
35
|
-
const out = valueAfter(commandArgs, '--out') ?? 'src/mujoco-register.gen.
|
|
35
|
+
const out = valueAfter(commandArgs, '--out') ?? 'src/mujoco-register.gen.ts';
|
|
36
36
|
const moduleName = valueAfter(commandArgs, '--module') ?? 'mujoco-react';
|
|
37
37
|
const shouldWatch = commandArgs.includes('--watch');
|
|
38
38
|
const models = commandArgs.filter((arg, index) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -41,13 +41,35 @@ type Robots = [RegisteredRobotMap] extends [never] ? string : Extract<keyof Regi
|
|
|
41
41
|
type RobotResource<TRobot extends string, TKey extends string> = [
|
|
42
42
|
RegisteredRobotMap
|
|
43
43
|
] extends [never] ? string : TRobot extends keyof RegisteredRobotMap ? TKey extends keyof RegisteredRobotMap[TRobot] ? RegisteredRobotMap[TRobot][TKey] : string : never;
|
|
44
|
+
type RegisterResourceKey = 'actuators' | 'sensors' | 'bodies' | 'joints' | 'sites' | 'geoms' | 'keyframes';
|
|
45
|
+
type RobotResourceObject<TRobot extends string, TKey extends RegisterResourceKey> = string extends RobotResource<TRobot, TKey> ? Record<string, string> : {
|
|
46
|
+
readonly [K in RobotResource<TRobot, TKey>]: K;
|
|
47
|
+
};
|
|
48
|
+
type RobotResourceCategory<TKey extends RegisterResourceKey> = string extends Robots ? Record<string, Record<string, string>> : {
|
|
49
|
+
readonly [TRobot in Robots]: RobotResourceObject<TRobot, TKey>;
|
|
50
|
+
};
|
|
51
|
+
type RobotResourceRegistry = string extends Robots ? Record<string, Record<RegisterResourceKey, Record<string, string>>> : {
|
|
52
|
+
readonly [TRobot in Robots]: {
|
|
53
|
+
readonly [TKey in RegisterResourceKey]: RobotResourceObject<TRobot, TKey>;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
type RuntimeRobotResourceRegistration = Readonly<Record<string, Readonly<Record<RegisterResourceKey, Readonly<Record<string, string>>>>>>;
|
|
57
|
+
declare function registerRobotResources(resources: RuntimeRobotResourceRegistration): void;
|
|
58
|
+
declare const RobotResources: RobotResourceRegistry;
|
|
44
59
|
type RobotActuators<TRobot extends string> = RobotResource<TRobot, 'actuators'>;
|
|
60
|
+
declare const RobotActuators: RobotResourceCategory<'actuators'>;
|
|
45
61
|
type RobotSensors<TRobot extends string> = RobotResource<TRobot, 'sensors'>;
|
|
62
|
+
declare const RobotSensors: RobotResourceCategory<'sensors'>;
|
|
46
63
|
type RobotBodies<TRobot extends string> = RobotResource<TRobot, 'bodies'>;
|
|
64
|
+
declare const RobotBodies: RobotResourceCategory<'bodies'>;
|
|
47
65
|
type RobotJoints<TRobot extends string> = RobotResource<TRobot, 'joints'>;
|
|
66
|
+
declare const RobotJoints: RobotResourceCategory<'joints'>;
|
|
48
67
|
type RobotSites<TRobot extends string> = RobotResource<TRobot, 'sites'>;
|
|
68
|
+
declare const RobotSites: RobotResourceCategory<'sites'>;
|
|
49
69
|
type RobotGeoms<TRobot extends string> = RobotResource<TRobot, 'geoms'>;
|
|
70
|
+
declare const RobotGeoms: RobotResourceCategory<'geoms'>;
|
|
50
71
|
type RobotKeyframes<TRobot extends string> = RobotResource<TRobot, 'keyframes'>;
|
|
72
|
+
declare const RobotKeyframes: RobotResourceCategory<'keyframes'>;
|
|
51
73
|
type Actuators = Register extends {
|
|
52
74
|
actuators: infer T extends string;
|
|
53
75
|
} ? T : string;
|
|
@@ -1504,4 +1526,4 @@ interface CameraAnimationAPI {
|
|
|
1504
1526
|
*/
|
|
1505
1527
|
declare function useCameraAnimation(): CameraAnimationAPI;
|
|
1506
1528
|
|
|
1507
|
-
export { type ActuatedJointInfo, type ActuatorInfo, type Actuators, type Bodies, Body, type BodyInfo, type BodyProps, type BodyStateResult, type CameraAnimationAPI, type ContactInfo, ContactListener, type ContactListenerProps, ContactMarkers, type ControlGroupInfo, type ControlGroupSelector, type ControlJointInfo, 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, InstancedGeomRenderer, 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 MujocoLoader, type MujocoLoaderOptions, type MujocoModel, type MujocoModule, MujocoPhysics, type MujocoPhysicsProps, MujocoProvider, type MujocoProviderProps, type MujocoSimAPI, MujocoSimProvider, type MujocoWasmVariant, type ObservationConfig, type ObservationHandle, type ObservationLayoutItem, type ObservationOutput, type ObservationResult, type PhysicsConfig, type PhysicsStepCallback, type PlaybackState, type PolicyConfig, type RayHit, type Register, type RegisteredRobotMap, type ResourceSelector,
|
|
1529
|
+
export { type ActuatedJointInfo, type ActuatorInfo, type Actuators, type Bodies, Body, type BodyInfo, type BodyProps, type BodyStateResult, type CameraAnimationAPI, type ContactInfo, ContactListener, type ContactListenerProps, ContactMarkers, type ControlGroupInfo, type ControlGroupSelector, type ControlJointInfo, 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, InstancedGeomRenderer, 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 MujocoLoader, type MujocoLoaderOptions, type MujocoModel, type MujocoModule, MujocoPhysics, type MujocoPhysicsProps, MujocoProvider, type MujocoProviderProps, type MujocoSimAPI, MujocoSimProvider, type MujocoWasmVariant, type ObservationConfig, type ObservationHandle, type ObservationLayoutItem, type ObservationOutput, type ObservationResult, type PhysicsConfig, type PhysicsStepCallback, type PlaybackState, type PolicyConfig, type RayHit, type Register, type RegisteredRobotMap, type ResourceSelector, RobotActuators, RobotBodies, RobotGeoms, RobotJoints, RobotKeyframes, type RobotResource, RobotResources, RobotSensors, RobotSites, type Robots, 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, buildObservation, createContiguousControlGroup, createController, createControllerHook, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, getActuatedJoints, getContact, getControlMap, getName, loadScene, registerRobotResources, resolveControlGroup, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyMeshes, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useGamepad, useGravityCompensation, useIkController, useJointState, useKeyboardTeleop, useMujoco, useMujocoWasm, useObservation, usePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePosition, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder };
|
package/dist/index.js
CHANGED
|
@@ -106,6 +106,63 @@ function MujocoProvider({
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// src/types.ts
|
|
109
|
+
var runtimeRobotResources = {};
|
|
110
|
+
var REGISTER_RESOURCE_KEYS = ["actuators", "sensors", "bodies", "joints", "sites", "geoms", "keyframes"];
|
|
111
|
+
function createEmptyRuntimeResources() {
|
|
112
|
+
return {
|
|
113
|
+
actuators: {},
|
|
114
|
+
sensors: {},
|
|
115
|
+
bodies: {},
|
|
116
|
+
joints: {},
|
|
117
|
+
sites: {},
|
|
118
|
+
geoms: {},
|
|
119
|
+
keyframes: {}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function registerRobotResources(resources) {
|
|
123
|
+
for (const [robot, robotResources] of Object.entries(resources)) {
|
|
124
|
+
const existing = runtimeRobotResources[robot] ?? createEmptyRuntimeResources();
|
|
125
|
+
for (const key of REGISTER_RESOURCE_KEYS) {
|
|
126
|
+
existing[key] = { ...existing[key], ...robotResources[key] ?? {} };
|
|
127
|
+
}
|
|
128
|
+
runtimeRobotResources[robot] = existing;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function createResourceCategory(key) {
|
|
132
|
+
return new Proxy({}, {
|
|
133
|
+
get(_target, robot) {
|
|
134
|
+
if (typeof robot !== "string") return void 0;
|
|
135
|
+
return runtimeRobotResources[robot]?.[key] ?? {};
|
|
136
|
+
},
|
|
137
|
+
ownKeys() {
|
|
138
|
+
return Reflect.ownKeys(runtimeRobotResources);
|
|
139
|
+
},
|
|
140
|
+
getOwnPropertyDescriptor(_target, robot) {
|
|
141
|
+
if (typeof robot !== "string" || !(robot in runtimeRobotResources)) return void 0;
|
|
142
|
+
return { enumerable: true, configurable: true };
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
var RobotResources = new Proxy(runtimeRobotResources, {
|
|
147
|
+
get(target, robot) {
|
|
148
|
+
if (typeof robot !== "string") return void 0;
|
|
149
|
+
return target[robot] ?? createEmptyRuntimeResources();
|
|
150
|
+
},
|
|
151
|
+
ownKeys(target) {
|
|
152
|
+
return Reflect.ownKeys(target);
|
|
153
|
+
},
|
|
154
|
+
getOwnPropertyDescriptor(target, robot) {
|
|
155
|
+
if (typeof robot !== "string" || !(robot in target)) return void 0;
|
|
156
|
+
return { enumerable: true, configurable: true };
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
var RobotActuators = createResourceCategory("actuators");
|
|
160
|
+
var RobotSensors = createResourceCategory("sensors");
|
|
161
|
+
var RobotBodies = createResourceCategory("bodies");
|
|
162
|
+
var RobotJoints = createResourceCategory("joints");
|
|
163
|
+
var RobotSites = createResourceCategory("sites");
|
|
164
|
+
var RobotGeoms = createResourceCategory("geoms");
|
|
165
|
+
var RobotKeyframes = createResourceCategory("keyframes");
|
|
109
166
|
function getContact(contacts, i) {
|
|
110
167
|
try {
|
|
111
168
|
return contacts.get(i);
|
|
@@ -5045,6 +5102,6 @@ function useCameraAnimation() {
|
|
|
5045
5102
|
* useCameraAnimation — composable camera animation hook.
|
|
5046
5103
|
*/
|
|
5047
5104
|
|
|
5048
|
-
export { Body, ContactListener, ContactMarkers, Debug, DragInteraction, FlexRenderer, IkGizmo, InstancedGeomRenderer, MujocoCanvas, MujocoPhysics, MujocoProvider, MujocoSimProvider, SceneLights, TendonRenderer, TrajectoryPlayer, buildObservation, createContiguousControlGroup, createController, createControllerHook, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, getActuatedJoints, getContact, getControlMap, getName, loadScene, resolveControlGroup, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyMeshes, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useGamepad, useGravityCompensation, useIkController, useJointState, useKeyboardTeleop, useMujoco, useMujocoWasm, useObservation, usePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePosition, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder };
|
|
5105
|
+
export { Body, ContactListener, ContactMarkers, Debug, DragInteraction, FlexRenderer, IkGizmo, InstancedGeomRenderer, MujocoCanvas, MujocoPhysics, MujocoProvider, MujocoSimProvider, RobotActuators, RobotBodies, RobotGeoms, RobotJoints, RobotKeyframes, RobotResources, RobotSensors, RobotSites, SceneLights, TendonRenderer, TrajectoryPlayer, buildObservation, createContiguousControlGroup, createController, createControllerHook, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, getActuatedJoints, getContact, getControlMap, getName, loadScene, registerRobotResources, resolveControlGroup, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyMeshes, useBodyState, useCameraAnimation, useContactEvents, useContacts, useCtrl, useCtrlNoise, useGamepad, useGravityCompensation, useIkController, useJointState, useKeyboardTeleop, useMujoco, useMujocoWasm, useObservation, usePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePosition, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder };
|
|
5049
5106
|
//# sourceMappingURL=index.js.map
|
|
5050
5107
|
//# sourceMappingURL=index.js.map
|