mujoco-react 9.0.0 → 9.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/dist/spark.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as _sparkjsdev_spark from '@sparkjsdev/spark';
3
- import { n as SplatEnvironmentProps } from './types-izZlUweI.js';
3
+ import { n as SplatEnvironmentProps } from './types-C5gTvR7b.js';
4
4
  import 'react';
5
5
  import '@react-three/fiber';
6
6
  import 'three';
@@ -837,7 +837,10 @@ interface MujocoSimAPI {
837
837
  addBody(body: SceneObject): Promise<void>;
838
838
  removeBody(name: Bodies): Promise<void>;
839
839
  recompile(patches?: XmlPatch[]): Promise<void>;
840
+ getCanvas(): HTMLCanvasElement | null;
840
841
  getCanvasSnapshot(width?: number, height?: number, mimeType?: string): string;
842
+ captureFrame(options?: MujocoFrameCaptureOptions): Promise<FrameCaptureResult>;
843
+ captureFrameBlob(options?: MujocoFrameCaptureOptions): Promise<FrameCaptureBlobResult>;
841
844
  project2DTo3D(x: number, y: number, cameraPos: THREE.Vector3, lookAt: THREE.Vector3): {
842
845
  point: THREE.Vector3;
843
846
  bodyId: number;
@@ -849,6 +852,34 @@ interface MujocoSimAPI {
849
852
  readonly mjModelRef: React__default.RefObject<MujocoModel | null>;
850
853
  readonly mjDataRef: React__default.RefObject<MujocoData | null>;
851
854
  }
855
+ type FrameCaptureStatus = 'idle' | 'capturing' | 'captured' | 'error';
856
+ type FrameCaptureTarget = HTMLCanvasElement | HTMLElement | null | undefined;
857
+ type FrameCaptureTargetRef = React__default.RefObject<HTMLCanvasElement | HTMLElement | null>;
858
+ interface FrameCaptureOptions {
859
+ target?: FrameCaptureTarget | FrameCaptureTargetRef;
860
+ type?: string;
861
+ quality?: number;
862
+ waitForAnimationFrame?: boolean;
863
+ }
864
+ type MujocoFrameCaptureOptions = Omit<FrameCaptureOptions, 'target'>;
865
+ interface FrameCaptureResult {
866
+ canvas: HTMLCanvasElement;
867
+ dataUrl: string;
868
+ type: string;
869
+ }
870
+ interface FrameCaptureBlobResult {
871
+ canvas: HTMLCanvasElement;
872
+ blob: Blob;
873
+ type: string;
874
+ }
875
+ interface FrameCaptureAPI {
876
+ status: FrameCaptureStatus;
877
+ error: Error | null;
878
+ isCapturing: boolean;
879
+ capture: (options?: FrameCaptureOptions) => Promise<FrameCaptureResult>;
880
+ captureBlob: (options?: FrameCaptureOptions) => Promise<FrameCaptureBlobResult>;
881
+ reset: () => void;
882
+ }
852
883
  type MujocoCanvasProps = Omit<CanvasProps, 'onError'> & {
853
884
  config: SceneConfig;
854
885
  /** R3F content rendered while the MuJoCo WASM module is still loading. */
@@ -907,4 +938,4 @@ interface JointStateResult {
907
938
  velocity: React__default.RefObject<number | Float64Array>;
908
939
  }
909
940
 
910
- export { type PolicyConfig as $, type ActuatedJointInfo as A, type BodyProps as B, type ControlGroupInfo as C, type DragInteractionProps as D, type ActuatorInfo as E, type Sites as F, type GeomInfo as G, type SitePositionResult as H, type IkConfig as I, type Sensors as J, type SensorHandle as K, type SensorInfo as L, type MujocoContextValue as M, type Joints as N, type ObservationConfig as O, type PhysicsStepCallback as P, type JointStateResult as Q, type ReadyCallbackInput as R, type SceneConfig as S, type TrajectoryPlayerProps as T, type Bodies as U, type VisualScenarioEffectsProps as V, type BodyStateResult as W, type Actuators as X, type CtrlHandle as Y, type ContactInfo as Z, type KeyboardTeleopConfig as _, type MujocoCanvasProps as a, type PolicyVector as a0, type ObservationHandle as a1, type TrajectoryInput as a2, type TrajectoryStateChangeInput as a3, type PlaybackState as a4, type TrajectoryFrame as a5, type BodyInfo as a6, type ControlJointInfo as a7, type Geoms as a8, type IKSolveFn as a9, RobotResources as aA, RobotSensors as aB, RobotSites as aC, type Robots as aD, type ScenarioCameraConfig as aE, type ScenarioMaterialConfig as aF, type SceneMarker as aG, type SceneObject as aH, type SensorResult as aI, type SiteInfo as aJ, type SplatAssetConfig as aK, type SplatScenarioConfig as aL, type StateSnapshot as aM, type TrajectoryData as aN, type TrajectoryFrameCallbackInput as aO, type VisualScenarioMaterialFilterInput as aP, type XmlPatch as aQ, getContact as aR, registerRobotResources as aS, type IkGizmoDragInput as aa, type IkSolveInput as ab, type JointInfo as ac, type KeyBinding as ad, type Keyframes as ae, type ModelOptions as af, type MujocoContact as ag, type MujocoContactArray as ah, type ObservationLayoutItem as ai, type ObservationOutput as aj, type PhysicsConfig as ak, type PhysicsStepInput as al, type PolicyActionInput as am, type PolicyInferenceInput as an, type PolicyObservationInput as ao, type RayHit as ap, type Register as aq, type RegisteredRobotMap as ar, type ResetCallbackInput as as, type ResourceSelector as at, RobotActuators as au, RobotBodies as av, RobotGeoms as aw, RobotJoints as ax, RobotKeyframes as ay, type RobotResource as az, type MujocoSimAPI as b, type StepCallbackInput as c, type SelectionCallbackInput as d, type MujocoModule as e, type MujocoModel as f, type MujocoData as g, type ControlGroupSelector as h, type ObservationResult as i, type IkContextValue as j, type IkGizmoProps as k, type SceneLightsProps as l, type ScenarioLightingProps as m, type SplatEnvironmentProps as n, type VisualScenarioConfig as o, type SplatRendererKind as p, type PairedSplatEnvironmentConfig as q, type SplatFormat as r, type SplatCollisionProxyConfig as s, type SplatCollisionPrimitive as t, type ScenarioLightingPreset as u, type SplatEnvironmentMetadataInput as v, type SplatEnvironmentMetadata as w, type SplatSceneInput as x, type DebugProps as y, type ContactListenerProps as z };
941
+ export { type PolicyConfig as $, type ActuatedJointInfo as A, type BodyProps as B, type ControlGroupInfo as C, type DragInteractionProps as D, type ActuatorInfo as E, type Sites as F, type GeomInfo as G, type SitePositionResult as H, type IkConfig as I, type Sensors as J, type SensorHandle as K, type SensorInfo as L, type MujocoContextValue as M, type Joints as N, type ObservationConfig as O, type PhysicsStepCallback as P, type JointStateResult as Q, type ReadyCallbackInput as R, type SceneConfig as S, type TrajectoryPlayerProps as T, type Bodies as U, type VisualScenarioEffectsProps as V, type BodyStateResult as W, type Actuators as X, type CtrlHandle as Y, type ContactInfo as Z, type KeyboardTeleopConfig as _, type MujocoCanvasProps as a, type PolicyVector as a0, type ObservationHandle as a1, type TrajectoryInput as a2, type TrajectoryStateChangeInput as a3, type PlaybackState as a4, type TrajectoryFrame as a5, type FrameCaptureOptions as a6, type FrameCaptureResult as a7, type FrameCaptureBlobResult as a8, type FrameCaptureAPI as a9, type ResetCallbackInput as aA, type ResourceSelector as aB, RobotActuators as aC, RobotBodies as aD, RobotGeoms as aE, RobotJoints as aF, RobotKeyframes as aG, type RobotResource as aH, RobotResources as aI, RobotSensors as aJ, RobotSites as aK, type Robots as aL, type ScenarioCameraConfig as aM, type ScenarioMaterialConfig as aN, type SceneMarker as aO, type SceneObject as aP, type SensorResult as aQ, type SiteInfo as aR, type SplatAssetConfig as aS, type SplatScenarioConfig as aT, type StateSnapshot as aU, type TrajectoryData as aV, type TrajectoryFrameCallbackInput as aW, type VisualScenarioMaterialFilterInput as aX, type XmlPatch as aY, getContact as aZ, registerRobotResources as a_, type BodyInfo as aa, type ControlJointInfo as ab, type FrameCaptureStatus as ac, type FrameCaptureTarget as ad, type FrameCaptureTargetRef as ae, type Geoms as af, type IKSolveFn as ag, type IkGizmoDragInput as ah, type IkSolveInput as ai, type JointInfo as aj, type KeyBinding as ak, type Keyframes as al, type ModelOptions as am, type MujocoContact as an, type MujocoContactArray as ao, type MujocoFrameCaptureOptions as ap, type ObservationLayoutItem as aq, type ObservationOutput as ar, type PhysicsConfig as as, type PhysicsStepInput as at, type PolicyActionInput as au, type PolicyInferenceInput as av, type PolicyObservationInput as aw, type RayHit as ax, type Register as ay, type RegisteredRobotMap as az, type MujocoSimAPI as b, type StepCallbackInput as c, type SelectionCallbackInput as d, type MujocoModule as e, type MujocoModel as f, type MujocoData as g, type ControlGroupSelector as h, type ObservationResult as i, type IkContextValue as j, type IkGizmoProps as k, type SceneLightsProps as l, type ScenarioLightingProps as m, type SplatEnvironmentProps as n, type VisualScenarioConfig as o, type SplatRendererKind as p, type PairedSplatEnvironmentConfig as q, type SplatFormat as r, type SplatCollisionProxyConfig as s, type SplatCollisionPrimitive as t, type ScenarioLightingPreset as u, type SplatEnvironmentMetadataInput as v, type SplatEnvironmentMetadata as w, type SplatSceneInput as x, type DebugProps as y, type ContactListenerProps as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mujoco-react",
3
- "version": "9.0.0",
3
+ "version": "9.1.0",
4
4
  "description": "Composable React Three Fiber building blocks for MuJoCo WASM simulations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -41,6 +41,10 @@ import {
41
41
  StepCallbackInput,
42
42
  XmlPatch,
43
43
  } from '../types';
44
+ import {
45
+ captureFrame as captureCanvasFrame,
46
+ captureFrameBlob as captureCanvasFrameBlob,
47
+ } from '../hooks/useFrameCapture';
44
48
  import {
45
49
  loadScene,
46
50
  createSceneConfigFromFiles,
@@ -1019,6 +1023,24 @@ export function MujocoSimProvider({
1019
1023
  [gl]
1020
1024
  );
1021
1025
 
1026
+ const getCanvas = useCallback((): HTMLCanvasElement | null => {
1027
+ return gl.domElement ?? null;
1028
+ }, [gl]);
1029
+
1030
+ const captureFrameApi = useCallback(
1031
+ (options = {}) => {
1032
+ return captureCanvasFrame({ ...options, target: gl.domElement });
1033
+ },
1034
+ [gl]
1035
+ );
1036
+
1037
+ const captureFrameBlobApi = useCallback(
1038
+ (options = {}) => {
1039
+ return captureCanvasFrameBlob({ ...options, target: gl.domElement });
1040
+ },
1041
+ [gl]
1042
+ );
1043
+
1022
1044
  const project2DTo3D = useCallback(
1023
1045
  (x: number, y: number, cameraPos: THREE.Vector3, lookAt: THREE.Vector3): { point: THREE.Vector3; bodyId: number; geomId: number } | null => {
1024
1046
  const virtCam = (camera as THREE.PerspectiveCamera).clone();
@@ -1128,7 +1150,10 @@ export function MujocoSimProvider({
1128
1150
  addBody: addBodyApi,
1129
1151
  removeBody: removeBodyApi,
1130
1152
  recompile: recompileApi,
1153
+ getCanvas,
1131
1154
  getCanvasSnapshot,
1155
+ captureFrame: captureFrameApi,
1156
+ captureFrameBlob: captureFrameBlobApi,
1132
1157
  project2DTo3D,
1133
1158
  setBodyMass,
1134
1159
  setGeomFriction,
@@ -1146,7 +1171,8 @@ export function MujocoSimProvider({
1146
1171
  getActuatorsApi, getSensors, getModelOption, setGravity, setTimestepApi,
1147
1172
  raycast, getKeyframeNames, getKeyframeCount, loadSceneApi,
1148
1173
  loadFromFilesApi, addBodyApi, removeBodyApi, recompileApi,
1149
- getCanvasSnapshot, project2DTo3D,
1174
+ getCanvas, getCanvasSnapshot, captureFrameApi, captureFrameBlobApi,
1175
+ project2DTo3D,
1150
1176
  setBodyMass, setGeomFriction, setGeomSize,
1151
1177
  ]
1152
1178
  );
@@ -6,48 +6,14 @@
6
6
  */
7
7
 
8
8
  import { useCallback, useState } from 'react';
9
- import type React from 'react';
10
-
11
- export type FrameCaptureStatus = 'idle' | 'capturing' | 'captured' | 'error';
12
-
13
- export type FrameCaptureTarget =
14
- | HTMLCanvasElement
15
- | HTMLElement
16
- | null
17
- | undefined;
18
-
19
- export type FrameCaptureTargetRef =
20
- React.RefObject<HTMLCanvasElement | HTMLElement | null>;
21
-
22
- export interface FrameCaptureOptions {
23
- target?: FrameCaptureTarget | FrameCaptureTargetRef;
24
- type?: string;
25
- quality?: number;
26
- waitForAnimationFrame?: boolean;
27
- }
28
-
29
- export interface FrameCaptureResult {
30
- canvas: HTMLCanvasElement;
31
- dataUrl: string;
32
- type: string;
33
- }
34
-
35
- export interface FrameCaptureBlobResult {
36
- canvas: HTMLCanvasElement;
37
- blob: Blob;
38
- type: string;
39
- }
40
-
41
- export interface FrameCaptureAPI {
42
- status: FrameCaptureStatus;
43
- error: Error | null;
44
- isCapturing: boolean;
45
- capture: (options?: FrameCaptureOptions) => Promise<FrameCaptureResult>;
46
- captureBlob: (
47
- options?: FrameCaptureOptions
48
- ) => Promise<FrameCaptureBlobResult>;
49
- reset: () => void;
50
- }
9
+ import type {
10
+ FrameCaptureAPI,
11
+ FrameCaptureBlobResult,
12
+ FrameCaptureOptions,
13
+ FrameCaptureResult,
14
+ FrameCaptureStatus,
15
+ FrameCaptureTargetRef,
16
+ } from '../types';
51
17
 
52
18
  function isTargetRef(
53
19
  target: FrameCaptureOptions['target']
package/src/index.ts CHANGED
@@ -82,15 +82,6 @@ export {
82
82
  captureFrameBlob,
83
83
  useFrameCapture,
84
84
  } from './hooks/useFrameCapture';
85
- export type {
86
- FrameCaptureAPI,
87
- FrameCaptureBlobResult,
88
- FrameCaptureOptions,
89
- FrameCaptureResult,
90
- FrameCaptureStatus,
91
- FrameCaptureTarget,
92
- FrameCaptureTargetRef,
93
- } from './hooks/useFrameCapture';
94
85
  export { useCtrlNoise } from './hooks/useCtrlNoise';
95
86
  export { useBodyMeshes } from './hooks/useBodyMeshes';
96
87
  export { useSelectionHighlight } from './hooks/useSelectionHighlight';
@@ -189,9 +180,17 @@ export type {
189
180
  ContactListenerProps,
190
181
  // API
191
182
  MujocoSimAPI,
183
+ MujocoFrameCaptureOptions,
192
184
  MujocoCanvasProps,
193
185
  MujocoContextValue,
194
186
  // Hook return types
187
+ FrameCaptureAPI,
188
+ FrameCaptureBlobResult,
189
+ FrameCaptureOptions,
190
+ FrameCaptureResult,
191
+ FrameCaptureStatus,
192
+ FrameCaptureTarget,
193
+ FrameCaptureTargetRef,
195
194
  SitePositionResult,
196
195
  SensorResult,
197
196
  CtrlHandle,
package/src/types.ts CHANGED
@@ -1100,7 +1100,10 @@ export interface MujocoSimAPI {
1100
1100
  recompile(patches?: XmlPatch[]): Promise<void>;
1101
1101
 
1102
1102
  // Canvas
1103
+ getCanvas(): HTMLCanvasElement | null;
1103
1104
  getCanvasSnapshot(width?: number, height?: number, mimeType?: string): string;
1105
+ captureFrame(options?: MujocoFrameCaptureOptions): Promise<FrameCaptureResult>;
1106
+ captureFrameBlob(options?: MujocoFrameCaptureOptions): Promise<FrameCaptureBlobResult>;
1104
1107
  project2DTo3D(
1105
1108
  x: number,
1106
1109
  y: number,
@@ -1118,6 +1121,49 @@ export interface MujocoSimAPI {
1118
1121
  readonly mjDataRef: React.RefObject<MujocoData | null>;
1119
1122
  }
1120
1123
 
1124
+ export type FrameCaptureStatus = 'idle' | 'capturing' | 'captured' | 'error';
1125
+
1126
+ export type FrameCaptureTarget =
1127
+ | HTMLCanvasElement
1128
+ | HTMLElement
1129
+ | null
1130
+ | undefined;
1131
+
1132
+ export type FrameCaptureTargetRef =
1133
+ React.RefObject<HTMLCanvasElement | HTMLElement | null>;
1134
+
1135
+ export interface FrameCaptureOptions {
1136
+ target?: FrameCaptureTarget | FrameCaptureTargetRef;
1137
+ type?: string;
1138
+ quality?: number;
1139
+ waitForAnimationFrame?: boolean;
1140
+ }
1141
+
1142
+ export type MujocoFrameCaptureOptions = Omit<FrameCaptureOptions, 'target'>;
1143
+
1144
+ export interface FrameCaptureResult {
1145
+ canvas: HTMLCanvasElement;
1146
+ dataUrl: string;
1147
+ type: string;
1148
+ }
1149
+
1150
+ export interface FrameCaptureBlobResult {
1151
+ canvas: HTMLCanvasElement;
1152
+ blob: Blob;
1153
+ type: string;
1154
+ }
1155
+
1156
+ export interface FrameCaptureAPI {
1157
+ status: FrameCaptureStatus;
1158
+ error: Error | null;
1159
+ isCapturing: boolean;
1160
+ capture: (options?: FrameCaptureOptions) => Promise<FrameCaptureResult>;
1161
+ captureBlob: (
1162
+ options?: FrameCaptureOptions
1163
+ ) => Promise<FrameCaptureBlobResult>;
1164
+ reset: () => void;
1165
+ }
1166
+
1121
1167
  // ---- Canvas Props ----
1122
1168
 
1123
1169
  export type MujocoCanvasProps = Omit<CanvasProps, 'onError'> & {