mujoco-react 0.2.0 → 1.0.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 +287 -48
- package/dist/index.d.ts +215 -135
- package/dist/index.js +1176 -795
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/components/ContactMarkers.tsx +19 -22
- package/src/components/Debug.tsx +173 -36
- package/src/components/DragInteraction.tsx +5 -3
- package/src/components/FlexRenderer.tsx +3 -2
- package/src/components/IkController.tsx +262 -0
- package/src/components/IkGizmo.tsx +17 -25
- package/src/components/SceneLights.tsx +2 -112
- package/src/components/SceneRenderer.tsx +13 -8
- package/src/components/SelectionHighlight.tsx +2 -49
- package/src/components/TendonRenderer.tsx +93 -28
- package/src/components/TrajectoryPlayer.tsx +14 -10
- package/src/core/IkContext.tsx +40 -0
- package/src/core/MujocoCanvas.tsx +1 -5
- package/src/core/MujocoPhysics.tsx +79 -0
- package/src/core/MujocoProvider.tsx +12 -4
- package/src/core/MujocoSimProvider.tsx +56 -340
- package/src/core/SceneLoader.ts +45 -18
- package/src/core/createController.tsx +91 -0
- package/src/hooks/useCameraAnimation.ts +102 -0
- package/src/hooks/useContacts.ts +52 -22
- package/src/hooks/useJointState.ts +18 -2
- package/src/hooks/useSceneLights.ts +117 -0
- package/src/hooks/useSelectionHighlight.ts +65 -0
- package/src/index.ts +18 -1
- package/src/types.ts +53 -26
package/src/types.ts
CHANGED
|
@@ -8,6 +8,37 @@ import * as THREE from 'three';
|
|
|
8
8
|
|
|
9
9
|
// ---- MuJoCo WASM Types ----
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* A single MuJoCo contact from the WASM module.
|
|
13
|
+
* Accessed via `data.contact.get(i)`.
|
|
14
|
+
*/
|
|
15
|
+
export interface MujocoContact {
|
|
16
|
+
geom1: number;
|
|
17
|
+
geom2: number;
|
|
18
|
+
pos: Float64Array;
|
|
19
|
+
frame: Float64Array;
|
|
20
|
+
dist: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* WASM contact array — supports indexed access via `.get(i)`.
|
|
25
|
+
*/
|
|
26
|
+
export interface MujocoContactArray {
|
|
27
|
+
get(i: number): MujocoContact | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Read a single contact from the WASM contact array.
|
|
32
|
+
* Returns undefined if the access fails (WASM heap issue, bad index, etc.).
|
|
33
|
+
*/
|
|
34
|
+
export function getContact(data: MujocoData, i: number): MujocoContact | undefined {
|
|
35
|
+
try {
|
|
36
|
+
return data.contact.get(i);
|
|
37
|
+
} catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
11
42
|
/**
|
|
12
43
|
* Minimal interface for MuJoCo Model to avoid 'any'.
|
|
13
44
|
*/
|
|
@@ -51,12 +82,17 @@ export interface MujocoModel {
|
|
|
51
82
|
body_geomadr: Int32Array;
|
|
52
83
|
body_inertia: Float64Array;
|
|
53
84
|
|
|
85
|
+
// Default configuration
|
|
86
|
+
qpos0: Float64Array;
|
|
87
|
+
|
|
54
88
|
// Joint
|
|
55
89
|
jnt_qposadr: Int32Array;
|
|
56
90
|
jnt_dofadr: Int32Array;
|
|
57
91
|
jnt_type: Int32Array;
|
|
58
92
|
jnt_range: Float64Array;
|
|
59
93
|
jnt_bodyid: Int32Array;
|
|
94
|
+
jnt_pos: Float64Array;
|
|
95
|
+
jnt_axis: Float64Array;
|
|
60
96
|
jnt_limited: Uint8Array;
|
|
61
97
|
|
|
62
98
|
// Geom
|
|
@@ -166,7 +202,7 @@ export interface MujocoData {
|
|
|
166
202
|
site_xmat: Float64Array;
|
|
167
203
|
sensordata: Float64Array;
|
|
168
204
|
ncon: number;
|
|
169
|
-
contact:
|
|
205
|
+
contact: MujocoContactArray;
|
|
170
206
|
cvel: Float64Array;
|
|
171
207
|
cfrc_ext: Float64Array;
|
|
172
208
|
ten_length: Float64Array;
|
|
@@ -252,14 +288,26 @@ export interface SceneConfig {
|
|
|
252
288
|
sceneFile: string;
|
|
253
289
|
baseUrl?: string;
|
|
254
290
|
sceneObjects?: SceneObject[];
|
|
255
|
-
tcpSiteName?: string;
|
|
256
|
-
gripperActuatorName?: string;
|
|
257
|
-
numArmJoints?: number;
|
|
258
291
|
homeJoints?: number[];
|
|
259
292
|
xmlPatches?: XmlPatch[];
|
|
260
293
|
onReset?: (model: MujocoModel, data: MujocoData) => void;
|
|
261
294
|
}
|
|
262
295
|
|
|
296
|
+
// ---- IK Controller Config ----
|
|
297
|
+
|
|
298
|
+
export interface IkConfig {
|
|
299
|
+
/** MuJoCo site name for IK target. */
|
|
300
|
+
siteName: string;
|
|
301
|
+
/** Number of joints to solve for. */
|
|
302
|
+
numJoints: number;
|
|
303
|
+
/** Custom IK solver. When omitted, uses built-in Damped Least-Squares solver. */
|
|
304
|
+
ikSolveFn?: IKSolveFn;
|
|
305
|
+
/** DLS damping. Default: 0.01. */
|
|
306
|
+
damping?: number;
|
|
307
|
+
/** Max solver iterations. Default: 50. */
|
|
308
|
+
maxIterations?: number;
|
|
309
|
+
}
|
|
310
|
+
|
|
263
311
|
export interface SceneMarker {
|
|
264
312
|
id: number;
|
|
265
313
|
position: THREE.Vector3;
|
|
@@ -274,7 +322,6 @@ export interface PhysicsConfig {
|
|
|
274
322
|
substeps?: number;
|
|
275
323
|
paused?: boolean;
|
|
276
324
|
speed?: number;
|
|
277
|
-
interpolate?: boolean;
|
|
278
325
|
}
|
|
279
326
|
|
|
280
327
|
// ---- IK ----
|
|
@@ -533,18 +580,7 @@ export interface MujocoSimAPI {
|
|
|
533
580
|
// Model loading (spec 9.1)
|
|
534
581
|
loadScene(newConfig: SceneConfig): Promise<void>;
|
|
535
582
|
|
|
536
|
-
//
|
|
537
|
-
setIkEnabled(enabled: boolean): void;
|
|
538
|
-
moveTarget(pos: THREE.Vector3, duration?: number): void;
|
|
539
|
-
syncTargetToSite(): void;
|
|
540
|
-
solveIK(
|
|
541
|
-
pos: THREE.Vector3,
|
|
542
|
-
quat: THREE.Quaternion,
|
|
543
|
-
currentQ: number[]
|
|
544
|
-
): number[] | null;
|
|
545
|
-
getGizmoStats(): { pos: THREE.Vector3; rot: THREE.Euler } | null;
|
|
546
|
-
|
|
547
|
-
// Canvas / camera
|
|
583
|
+
// Canvas
|
|
548
584
|
getCanvasSnapshot(width?: number, height?: number, mimeType?: string): string;
|
|
549
585
|
project2DTo3D(
|
|
550
586
|
x: number,
|
|
@@ -557,12 +593,6 @@ export interface MujocoSimAPI {
|
|
|
557
593
|
setBodyMass(name: string, mass: number): void;
|
|
558
594
|
setGeomFriction(name: string, friction: [number, number, number]): void;
|
|
559
595
|
setGeomSize(name: string, size: [number, number, number]): void;
|
|
560
|
-
getCameraState(): { position: THREE.Vector3; target: THREE.Vector3 };
|
|
561
|
-
moveCameraTo(
|
|
562
|
-
position: THREE.Vector3,
|
|
563
|
-
target: THREE.Vector3,
|
|
564
|
-
durationMs: number
|
|
565
|
-
): Promise<void>;
|
|
566
596
|
|
|
567
597
|
// Internal refs for advanced use
|
|
568
598
|
readonly mjModelRef: React.RefObject<MujocoModel | null>;
|
|
@@ -583,9 +613,6 @@ export type MujocoCanvasProps = Omit<CanvasProps, 'onError'> & {
|
|
|
583
613
|
substeps?: number;
|
|
584
614
|
paused?: boolean;
|
|
585
615
|
speed?: number;
|
|
586
|
-
interpolate?: boolean;
|
|
587
|
-
gravityCompensation?: boolean;
|
|
588
|
-
mjcfLights?: boolean;
|
|
589
616
|
};
|
|
590
617
|
|
|
591
618
|
// ---- Hook Return Types ----
|