mujoco-react 0.1.0 → 0.3.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 +209 -45
- package/dist/index.d.ts +180 -97
- package/dist/index.js +1148 -772
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ContactMarkers.tsx +12 -19
- package/src/components/Debug.tsx +168 -33
- package/src/components/DragInteraction.tsx +1 -1
- 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 +8 -6
- package/src/components/SelectionHighlight.tsx +2 -49
- package/src/components/TendonRenderer.tsx +90 -26
- package/src/components/TrajectoryPlayer.tsx +14 -10
- package/src/core/IkContext.tsx +40 -0
- package/src/core/MujocoCanvas.tsx +6 -3
- package/src/core/MujocoProvider.tsx +12 -4
- package/src/core/MujocoSimProvider.tsx +69 -334
- package/src/core/SceneLoader.ts +44 -11
- 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 +16 -1
- package/src/types.ts +59 -22
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,12 +288,30 @@ 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;
|
|
294
|
+
/** @deprecated Use IkController config.siteName instead. */
|
|
295
|
+
tcpSiteName?: string;
|
|
296
|
+
/** @deprecated Use your own gripper control logic instead. */
|
|
297
|
+
gripperActuatorName?: string;
|
|
298
|
+
/** @deprecated Use IkController config.numJoints instead. */
|
|
299
|
+
numArmJoints?: number;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ---- IK Controller Config ----
|
|
303
|
+
|
|
304
|
+
export interface IkConfig {
|
|
305
|
+
/** MuJoCo site name for IK target. */
|
|
306
|
+
siteName: string;
|
|
307
|
+
/** Number of joints to solve for. */
|
|
308
|
+
numJoints: number;
|
|
309
|
+
/** Custom IK solver. When omitted, uses built-in Damped Least-Squares solver. */
|
|
310
|
+
ikSolveFn?: IKSolveFn;
|
|
311
|
+
/** DLS damping. Default: 0.01. */
|
|
312
|
+
damping?: number;
|
|
313
|
+
/** Max solver iterations. Default: 50. */
|
|
314
|
+
maxIterations?: number;
|
|
261
315
|
}
|
|
262
316
|
|
|
263
317
|
export interface SceneMarker {
|
|
@@ -533,18 +587,7 @@ export interface MujocoSimAPI {
|
|
|
533
587
|
// Model loading (spec 9.1)
|
|
534
588
|
loadScene(newConfig: SceneConfig): Promise<void>;
|
|
535
589
|
|
|
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
|
|
590
|
+
// Canvas
|
|
548
591
|
getCanvasSnapshot(width?: number, height?: number, mimeType?: string): string;
|
|
549
592
|
project2DTo3D(
|
|
550
593
|
x: number,
|
|
@@ -557,12 +600,6 @@ export interface MujocoSimAPI {
|
|
|
557
600
|
setBodyMass(name: string, mass: number): void;
|
|
558
601
|
setGeomFriction(name: string, friction: [number, number, number]): void;
|
|
559
602
|
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
603
|
|
|
567
604
|
// Internal refs for advanced use
|
|
568
605
|
readonly mjModelRef: React.RefObject<MujocoModel | null>;
|