mujoco-react 12.1.0 → 12.1.2
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 +5 -0
- package/dist/{chunk-XD3AY7XZ.js → chunk-CV6LBHC4.js} +42 -67
- package/dist/chunk-CV6LBHC4.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -1
- package/dist/onnx.d.ts +1 -1
- package/dist/spark.d.ts +1 -1
- package/dist/spark.js +25 -16
- package/dist/spark.js.map +1 -1
- package/dist/{types-CSi3fIVs.d.ts → types-BvMb-EIC.d.ts} +5 -0
- package/package.json +2 -2
- package/src/hooks/useCameraStream.ts +1 -1
- package/src/rendering/cameraFrameCapture.ts +47 -68
- package/src/runtime/client.ts +17 -7
- package/src/spark.tsx +24 -15
- package/src/types.ts +5 -0
- package/dist/chunk-XD3AY7XZ.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { displayFields } from './chunk-U2Y2BODT.js';
|
|
2
|
-
import { withContacts, getContact, captureCameraFrame, captureCameraFrameBlob, createCameraFrameCaptureSession, CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY, CAPTURE_EXCLUDE_KEY, createCaptureCamera, prepareCaptureCamera } from './chunk-
|
|
3
|
-
export { CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY, CAPTURE_EXCLUDE_KEY, ModelActuators, ModelBodies, ModelCameras, ModelGeoms, ModelJoints, ModelKeyframes, ModelResources, ModelSensors, ModelSites, ScenarioLighting, SplatEnvironment, SplatEnvironmentReadinessStatus, VisualScenarioEffects, captureCameraFrame, captureCameraFrameBlob, captureCameraFrameTensor, createCameraFrameCaptureSession, createPairedSplatEnvironment, createSparkSplatViewerUrl, createSplatEnvironmentUserData, createSplatSceneConfig, createVisualScenarioExecutionContext, dataUrlToPolicyImageTensor, getContact, getScenarioBackground, getScenarioCameraPosition, getSplatEnvironmentReadiness, imageDataToPolicyImageTensor, pixelsToPolicyImageTensor, registerModelResources, renderCameraFrameToCanvas, useSplatEnvironment, useSplatSceneConfig, useVisualScenarioEffects, useVisualScenarioExecutionContext, withSplatEnvironment } from './chunk-
|
|
2
|
+
import { withContacts, getContact, captureCameraFrame, captureCameraFrameBlob, createCameraFrameCaptureSession, CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY, CAPTURE_EXCLUDE_KEY, createCaptureCamera, prepareCaptureCamera } from './chunk-CV6LBHC4.js';
|
|
3
|
+
export { CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY, CAPTURE_EXCLUDE_KEY, ModelActuators, ModelBodies, ModelCameras, ModelGeoms, ModelJoints, ModelKeyframes, ModelResources, ModelSensors, ModelSites, ScenarioLighting, SplatEnvironment, SplatEnvironmentReadinessStatus, VisualScenarioEffects, captureCameraFrame, captureCameraFrameBlob, captureCameraFrameTensor, createCameraFrameCaptureSession, createPairedSplatEnvironment, createSparkSplatViewerUrl, createSplatEnvironmentUserData, createSplatSceneConfig, createVisualScenarioExecutionContext, dataUrlToPolicyImageTensor, getContact, getScenarioBackground, getScenarioCameraPosition, getSplatEnvironmentReadiness, imageDataToPolicyImageTensor, pixelsToPolicyImageTensor, registerModelResources, renderCameraFrameToCanvas, useSplatEnvironment, useSplatSceneConfig, useVisualScenarioEffects, useVisualScenarioExecutionContext, withSplatEnvironment } from './chunk-CV6LBHC4.js';
|
|
4
4
|
import loadMujoco from '@mujoco/mujoco';
|
|
5
5
|
import defaultMujocoWasmUrl from '@mujoco/mujoco/mujoco.wasm?url';
|
|
6
6
|
import { createContext, forwardRef, useRef, useEffect, useContext, useState, useCallback, useMemo, useLayoutEffect, useId } from 'react';
|
|
@@ -1695,14 +1695,14 @@ var RuntimeClient = class {
|
|
|
1695
1695
|
await this.cancel();
|
|
1696
1696
|
this.close();
|
|
1697
1697
|
}
|
|
1698
|
-
close(error = new Error("Simulation runtime disposed")) {
|
|
1698
|
+
close(error = new Error("Simulation runtime disposed"), restoreViewer = true) {
|
|
1699
1699
|
if (this.closed) return;
|
|
1700
1700
|
this.closed = true;
|
|
1701
1701
|
this.generation++;
|
|
1702
1702
|
this.worker.terminate();
|
|
1703
1703
|
this.pending?.reject(error);
|
|
1704
1704
|
this.pending = null;
|
|
1705
|
-
this.release();
|
|
1705
|
+
this.release(restoreViewer);
|
|
1706
1706
|
}
|
|
1707
1707
|
};
|
|
1708
1708
|
async function attachSimulationRuntime(module, api, waitForDisplay, invalidate, options = {}) {
|
|
@@ -1740,14 +1740,24 @@ async function attachSimulationRuntime(module, api, waitForDisplay, invalidate,
|
|
|
1740
1740
|
data.time = display.time;
|
|
1741
1741
|
invalidate();
|
|
1742
1742
|
};
|
|
1743
|
-
const client = new RuntimeClient(worker, apply, () => {
|
|
1744
|
-
|
|
1745
|
-
|
|
1743
|
+
const client = new RuntimeClient(worker, apply, (restoreViewer) => {
|
|
1744
|
+
try {
|
|
1745
|
+
if (api.mjModelRef.current === model && complete) {
|
|
1746
|
+
apply(complete);
|
|
1747
|
+
if (restoreViewer) {
|
|
1748
|
+
module.mj_forward(model, data);
|
|
1749
|
+
const state2 = complete.integration;
|
|
1750
|
+
module.mj_setState(model, data, Array.from(state2.values), state2.signature);
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
} finally {
|
|
1754
|
+
owners.delete(model);
|
|
1755
|
+
}
|
|
1746
1756
|
}, async (cameras) => {
|
|
1747
1757
|
await waitForDisplay();
|
|
1748
1758
|
return capturePolicyCameraFrames(api, cameras);
|
|
1749
1759
|
});
|
|
1750
|
-
owners.set(model, { close: () => client.close(), contacts: () => client.state.contacts });
|
|
1760
|
+
owners.set(model, { close: () => client.close(void 0, false), contacts: () => client.state.contacts });
|
|
1751
1761
|
try {
|
|
1752
1762
|
await client.initialize({ model: binary, state: initialState });
|
|
1753
1763
|
return client;
|
|
@@ -5722,7 +5732,7 @@ function useCameraStream(canvasRef, options) {
|
|
|
5722
5732
|
}
|
|
5723
5733
|
const session = sessionRef.current;
|
|
5724
5734
|
inFlightRef.current = true;
|
|
5725
|
-
session.captureAsync(api.resolveCameraCaptureOptions(opts)).then((frame) => {
|
|
5735
|
+
session.captureAsync(api.resolveCameraCaptureOptions({ ...opts, renderMode: opts.renderMode ?? "preview" })).then((frame) => {
|
|
5726
5736
|
const canvas = canvasRef.current;
|
|
5727
5737
|
if (!mountedRef.current || !canvas) return;
|
|
5728
5738
|
const ctx = canvas.getContext("2d");
|