mujoco-react 8.2.1 → 8.4.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 +129 -7
- package/dist/index.d.ts +93 -8
- package/dist/index.js +484 -87
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/ContactMarkers.tsx +14 -12
- package/src/components/Debug.tsx +18 -16
- package/src/components/FlexRenderer.tsx +1 -1
- package/src/components/TendonRenderer.tsx +1 -1
- package/src/core/GenericIK.ts +13 -10
- package/src/core/MujocoProvider.tsx +93 -8
- package/src/core/MujocoSimProvider.tsx +63 -18
- package/src/core/SceneLoader.ts +354 -2
- package/src/hooks/useContacts.ts +20 -18
- package/src/hooks/useIkController.ts +30 -11
- package/src/index.ts +10 -0
- package/src/rendering/GeomBuilder.ts +1 -1
- package/src/types.ts +94 -7
- package/src/wasm-url.d.ts +4 -0
package/src/types.ts
CHANGED
|
@@ -55,20 +55,33 @@ export interface MujocoContact {
|
|
|
55
55
|
*/
|
|
56
56
|
export interface MujocoContactArray {
|
|
57
57
|
get(i: number): MujocoContact | undefined;
|
|
58
|
+
delete?: () => void;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
|
-
* Read a single contact from
|
|
62
|
+
* Read a single contact from an already-acquired WASM contact array.
|
|
62
63
|
* Returns undefined if the access fails (WASM heap issue, bad index, etc.).
|
|
63
64
|
*/
|
|
64
|
-
export function getContact(
|
|
65
|
+
export function getContact(contacts: MujocoContactArray, i: number): MujocoContact | undefined {
|
|
65
66
|
try {
|
|
66
|
-
return
|
|
67
|
+
return contacts.get(i);
|
|
67
68
|
} catch {
|
|
68
69
|
return undefined;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Access the current contact vector and release the copied WASM handle afterwards.
|
|
75
|
+
*/
|
|
76
|
+
export function withContacts<T>(data: MujocoData, read: (contacts: MujocoContactArray) => T): T {
|
|
77
|
+
const contacts = data.contact;
|
|
78
|
+
try {
|
|
79
|
+
return read(contacts);
|
|
80
|
+
} finally {
|
|
81
|
+
contacts.delete?.();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
72
85
|
/**
|
|
73
86
|
* Minimal interface for MuJoCo Model to avoid 'any'.
|
|
74
87
|
*/
|
|
@@ -249,7 +262,12 @@ export interface MujocoData {
|
|
|
249
262
|
* Minimal interface for the MuJoCo WASM Module.
|
|
250
263
|
*/
|
|
251
264
|
export interface MujocoModule {
|
|
252
|
-
MjModel: {
|
|
265
|
+
MjModel: {
|
|
266
|
+
from_xml_path?: (path: string) => MujocoModel;
|
|
267
|
+
from_xml_string?: (xml: string, vfs?: unknown) => MujocoModel;
|
|
268
|
+
loadFromXML?: (path: string) => MujocoModel;
|
|
269
|
+
[key: string]: unknown;
|
|
270
|
+
};
|
|
253
271
|
MjData: new (model: MujocoModel) => MujocoData;
|
|
254
272
|
MjvOption: new () => { delete: () => void; [key: string]: unknown };
|
|
255
273
|
mj_forward: (m: MujocoModel, d: MujocoData) => void;
|
|
@@ -326,11 +344,27 @@ export interface SceneConfig {
|
|
|
326
344
|
|
|
327
345
|
// ---- IK Controller Config ----
|
|
328
346
|
|
|
347
|
+
export type ResourceSelector<TInfo, TName extends string = string> =
|
|
348
|
+
| TName
|
|
349
|
+
| readonly TName[]
|
|
350
|
+
| RegExp
|
|
351
|
+
| ((info: TInfo) => boolean);
|
|
352
|
+
|
|
329
353
|
export interface IkConfig {
|
|
330
354
|
/** MuJoCo site name for IK target. */
|
|
331
355
|
siteName: Sites;
|
|
332
|
-
/**
|
|
333
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Explicit joints for IK. When omitted, the controller infers scalar hinge/slide
|
|
358
|
+
* joints by walking from the site body to the model root.
|
|
359
|
+
*/
|
|
360
|
+
joints?: ResourceSelector<JointInfo, Joints>;
|
|
361
|
+
/** Explicit actuators for IK control output. */
|
|
362
|
+
actuators?: ResourceSelector<ActuatorInfo, Actuators>;
|
|
363
|
+
/**
|
|
364
|
+
* Number of joints to solve for, assuming legacy contiguous qpos/ctrl layout
|
|
365
|
+
* starting at index 0. Prefer inferred IK or `joints`/`actuators`.
|
|
366
|
+
*/
|
|
367
|
+
numJoints?: number;
|
|
334
368
|
/** Custom IK solver. When omitted, uses built-in Damped Least-Squares solver. */
|
|
335
369
|
ikSolveFn?: IKSolveFn;
|
|
336
370
|
/** DLS damping. Default: 0.01. */
|
|
@@ -372,9 +406,17 @@ export interface PhysicsConfig {
|
|
|
372
406
|
export type IKSolveFn = (
|
|
373
407
|
pos: THREE.Vector3,
|
|
374
408
|
quat: THREE.Quaternion,
|
|
375
|
-
currentQ: number[]
|
|
409
|
+
currentQ: number[],
|
|
410
|
+
context?: IKSolveContext
|
|
376
411
|
) => number[] | null;
|
|
377
412
|
|
|
413
|
+
export interface IKSolveContext {
|
|
414
|
+
model: MujocoModel;
|
|
415
|
+
data: MujocoData;
|
|
416
|
+
siteId: number;
|
|
417
|
+
controlGroup: ControlGroupInfo;
|
|
418
|
+
}
|
|
419
|
+
|
|
378
420
|
// ---- Callbacks ----
|
|
379
421
|
|
|
380
422
|
export type PhysicsStepCallback = (
|
|
@@ -435,6 +477,48 @@ export interface ActuatorInfo {
|
|
|
435
477
|
range: [number, number];
|
|
436
478
|
}
|
|
437
479
|
|
|
480
|
+
export interface ActuatedJointInfo extends JointInfo {
|
|
481
|
+
actuatorId: number;
|
|
482
|
+
actuatorName: string;
|
|
483
|
+
ctrlAdr: number;
|
|
484
|
+
ctrlRange: [number, number];
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export interface ControlJointInfo extends JointInfo {
|
|
488
|
+
actuatorId: number | null;
|
|
489
|
+
actuatorName: string | null;
|
|
490
|
+
ctrlAdr: number | null;
|
|
491
|
+
ctrlRange: [number, number] | null;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export interface ControlGroupSelector {
|
|
495
|
+
/** Infer a kinematic chain from a MuJoCo site. */
|
|
496
|
+
siteName?: Sites;
|
|
497
|
+
/** Infer a kinematic chain from a body. */
|
|
498
|
+
bodyName?: Bodies;
|
|
499
|
+
/** Select joints by name, names, regex, or predicate. */
|
|
500
|
+
joints?: ResourceSelector<JointInfo, Joints>;
|
|
501
|
+
/** Select actuators by name, names, regex, or predicate. */
|
|
502
|
+
actuators?: ResourceSelector<ActuatorInfo, Actuators>;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
export interface ControlGroupInfo {
|
|
506
|
+
/** Joints in solve/control order. */
|
|
507
|
+
joints: ControlJointInfo[];
|
|
508
|
+
/** Actuators in control output order. */
|
|
509
|
+
actuators: ActuatorInfo[];
|
|
510
|
+
/** qpos addresses for scalar hinge/slide joints. */
|
|
511
|
+
qposAdr: number[];
|
|
512
|
+
/** dof addresses for scalar hinge/slide joints. */
|
|
513
|
+
dofAdr: number[];
|
|
514
|
+
/** ctrl addresses matching writable actuators. */
|
|
515
|
+
ctrlAdr: number[];
|
|
516
|
+
readQpos(data: MujocoData): Float64Array;
|
|
517
|
+
readCtrl(data: MujocoData): Float64Array;
|
|
518
|
+
writeQpos(data: MujocoData, values: ArrayLike<number>): void;
|
|
519
|
+
writeCtrl(data: MujocoData, values: ArrayLike<number>): void;
|
|
520
|
+
}
|
|
521
|
+
|
|
438
522
|
export interface SensorInfo {
|
|
439
523
|
id: number;
|
|
440
524
|
name: string;
|
|
@@ -611,6 +695,9 @@ export interface MujocoSimAPI {
|
|
|
611
695
|
// Actuator / control (spec 3.1)
|
|
612
696
|
setCtrl(nameOrValues: Actuators | Record<Actuators, number>, value?: number): void;
|
|
613
697
|
getCtrl(): Float64Array;
|
|
698
|
+
getControlMap(): ControlGroupInfo;
|
|
699
|
+
getActuatedJoints(): ActuatedJointInfo[];
|
|
700
|
+
resolveControlGroup(selector: ControlGroupSelector): ControlGroupInfo | null;
|
|
614
701
|
|
|
615
702
|
// Force application (spec 8.1)
|
|
616
703
|
applyForce(bodyName: Bodies, force: THREE.Vector3, point?: THREE.Vector3): void;
|