mujoco-react 10.1.0 → 10.2.1
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/{chunk-FEKBKHEN.js → chunk-CYDGWNKQ.js} +33 -17
- package/dist/chunk-CYDGWNKQ.js.map +1 -0
- package/dist/index.d.ts +13 -3
- package/dist/index.js +307 -154
- package/dist/index.js.map +1 -1
- package/dist/spark.d.ts +1 -1
- package/dist/spark.js +1 -1
- package/dist/{types-BHBNJubg.d.ts → types-B-J8fpPP.d.ts} +35 -1
- package/package.json +1 -1
- package/src/core/MujocoSimProvider.tsx +30 -0
- package/src/hooks/usePolicy.ts +4 -1
- package/src/hooks/useRemotePolicy.ts +2 -1
- package/src/index.ts +7 -0
- package/src/rendering/cameraFrameCapture.ts +40 -15
- package/src/rendering/imageProjection.ts +186 -0
- package/src/types.ts +41 -0
- package/dist/chunk-FEKBKHEN.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { withContacts, getContact, captureCameraFrame, captureCameraFrameBlob, createCameraFrameCaptureSession, CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY, CAPTURE_EXCLUDE_KEY } from './chunk-
|
|
2
|
-
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, createCameraFrameCaptureSession, createPairedSplatEnvironment, createSparkSplatViewerUrl, createSplatEnvironmentUserData, createSplatSceneConfig, createVisualScenarioExecutionContext, getContact, getScenarioBackground, getScenarioCameraPosition, getSplatEnvironmentReadiness, registerModelResources, renderCameraFrameToCanvas, useSplatEnvironment, useSplatSceneConfig, useVisualScenarioEffects, useVisualScenarioExecutionContext, withSplatEnvironment } from './chunk-
|
|
1
|
+
import { withContacts, getContact, captureCameraFrame, captureCameraFrameBlob, createCameraFrameCaptureSession, CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY, CAPTURE_EXCLUDE_KEY } from './chunk-CYDGWNKQ.js';
|
|
2
|
+
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, createCameraFrameCaptureSession, createPairedSplatEnvironment, createSparkSplatViewerUrl, createSplatEnvironmentUserData, createSplatSceneConfig, createVisualScenarioExecutionContext, getContact, getScenarioBackground, getScenarioCameraPosition, getSplatEnvironmentReadiness, registerModelResources, renderCameraFrameToCanvas, useSplatEnvironment, useSplatSceneConfig, useVisualScenarioEffects, useVisualScenarioExecutionContext, withSplatEnvironment } from './chunk-CYDGWNKQ.js';
|
|
3
3
|
import loadMujoco from '@mujoco/mujoco';
|
|
4
4
|
import defaultMujocoWasmUrl from '@mujoco/mujoco/mujoco.wasm?url';
|
|
5
5
|
import { createContext, forwardRef, useEffect, useContext, useState, useRef, useCallback, useMemo, useLayoutEffect } from 'react';
|
|
6
6
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
7
7
|
import { Canvas, useThree, useFrame } from '@react-three/fiber';
|
|
8
|
-
import * as
|
|
8
|
+
import * as THREE11 from 'three';
|
|
9
9
|
import { PivotControls } from '@react-three/drei';
|
|
10
10
|
|
|
11
11
|
var MujocoContext = createContext({
|
|
@@ -105,16 +105,16 @@ function MujocoProvider({
|
|
|
105
105
|
}
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
|
-
var CapsuleGeometry = class extends
|
|
108
|
+
var CapsuleGeometry = class extends THREE11.BufferGeometry {
|
|
109
109
|
parameters;
|
|
110
110
|
constructor(radius = 1, length = 1, capSegments = 4, radialSegments = 8) {
|
|
111
111
|
super();
|
|
112
112
|
this.type = "CapsuleGeometry";
|
|
113
113
|
this.parameters = { radius, length, capSegments, radialSegments };
|
|
114
|
-
const path = new
|
|
114
|
+
const path = new THREE11.Path();
|
|
115
115
|
path.absarc(0, -length / 2, radius, Math.PI * 1.5, 0, false);
|
|
116
116
|
path.absarc(0, length / 2, radius, 0, Math.PI * 0.5, false);
|
|
117
|
-
const latheGeometry = new
|
|
117
|
+
const latheGeometry = new THREE11.LatheGeometry(path.getPoints(capSegments), radialSegments);
|
|
118
118
|
const self = this;
|
|
119
119
|
self.setIndex(latheGeometry.getIndex());
|
|
120
120
|
self.setAttribute("position", latheGeometry.getAttribute("position"));
|
|
@@ -930,10 +930,10 @@ var GeomBuilder = class {
|
|
|
930
930
|
rgba[out + 2] = b;
|
|
931
931
|
rgba[out + 3] = a;
|
|
932
932
|
}
|
|
933
|
-
const texture = new
|
|
934
|
-
texture.colorSpace =
|
|
935
|
-
texture.wrapS =
|
|
936
|
-
texture.wrapT =
|
|
933
|
+
const texture = new THREE11.DataTexture(rgba, width, height, THREE11.RGBAFormat);
|
|
934
|
+
texture.colorSpace = THREE11.LinearSRGBColorSpace;
|
|
935
|
+
texture.wrapS = THREE11.RepeatWrapping;
|
|
936
|
+
texture.wrapT = THREE11.RepeatWrapping;
|
|
937
937
|
texture.flipY = true;
|
|
938
938
|
const repeatOffset = matId * 2;
|
|
939
939
|
const repeatS = mjModel.mat_texrepeat?.[repeatOffset] ?? 1;
|
|
@@ -954,7 +954,7 @@ var GeomBuilder = class {
|
|
|
954
954
|
const pos = mjModel.geom_pos.subarray(g * 3, g * 3 + 3);
|
|
955
955
|
const quat = mjModel.geom_quat.subarray(g * 4, g * 4 + 4);
|
|
956
956
|
const matId = mjModel.geom_matid[g];
|
|
957
|
-
const color = new
|
|
957
|
+
const color = new THREE11.Color(16777215);
|
|
958
958
|
const map = this.getMaterialTexture(mjModel, matId);
|
|
959
959
|
let opacity = 1;
|
|
960
960
|
if (matId >= 0) {
|
|
@@ -970,16 +970,16 @@ var GeomBuilder = class {
|
|
|
970
970
|
let geo = null;
|
|
971
971
|
const getVal = (v) => v?.value ?? v;
|
|
972
972
|
if (type === getVal(MG.mjGEOM_PLANE)) {
|
|
973
|
-
geo = new
|
|
973
|
+
geo = new THREE11.PlaneGeometry(size[0] * 2 || 5, size[1] * 2 || 5);
|
|
974
974
|
} else if (type === getVal(MG.mjGEOM_SPHERE)) {
|
|
975
|
-
geo = new
|
|
975
|
+
geo = new THREE11.SphereGeometry(size[0], 24, 24);
|
|
976
976
|
} else if (type === getVal(MG.mjGEOM_CAPSULE)) {
|
|
977
977
|
geo = new CapsuleGeometry(size[0], size[1] * 2, 24, 12);
|
|
978
978
|
geo.rotateX(Math.PI / 2);
|
|
979
979
|
} else if (type === getVal(MG.mjGEOM_BOX)) {
|
|
980
|
-
geo = new
|
|
980
|
+
geo = new THREE11.BoxGeometry(size[0] * 2, size[1] * 2, size[2] * 2);
|
|
981
981
|
} else if (type === getVal(MG.mjGEOM_CYLINDER)) {
|
|
982
|
-
geo = new
|
|
982
|
+
geo = new THREE11.CylinderGeometry(size[0], size[0], size[1] * 2, 24);
|
|
983
983
|
geo.rotateX(Math.PI / 2);
|
|
984
984
|
} else if (type === getVal(MG.mjGEOM_MESH)) {
|
|
985
985
|
const mId = mjModel.geom_dataid[g];
|
|
@@ -987,8 +987,8 @@ var GeomBuilder = class {
|
|
|
987
987
|
const vNum = mjModel.mesh_vertnum[mId];
|
|
988
988
|
const fAdr = mjModel.mesh_faceadr[mId];
|
|
989
989
|
const fNum = mjModel.mesh_facenum[mId];
|
|
990
|
-
geo = new
|
|
991
|
-
geo.setAttribute("position", new
|
|
990
|
+
geo = new THREE11.BufferGeometry();
|
|
991
|
+
geo.setAttribute("position", new THREE11.Float32BufferAttribute(mjModel.mesh_vert.subarray(vAdr * 3, (vAdr + vNum) * 3), 3));
|
|
992
992
|
geo.setIndex(Array.from(mjModel.mesh_face.subarray(fAdr * 3, (fAdr + fNum) * 3)));
|
|
993
993
|
geo.computeVertexNormals();
|
|
994
994
|
}
|
|
@@ -999,7 +999,7 @@ var GeomBuilder = class {
|
|
|
999
999
|
materialMap.repeat.multiplyScalar(2.5);
|
|
1000
1000
|
materialMap.needsUpdate = true;
|
|
1001
1001
|
}
|
|
1002
|
-
const mesh = new
|
|
1002
|
+
const mesh = new THREE11.Mesh(geo, new THREE11.MeshStandardMaterial({
|
|
1003
1003
|
color,
|
|
1004
1004
|
map: materialMap,
|
|
1005
1005
|
transparent: opacity < 1,
|
|
@@ -1050,7 +1050,7 @@ function SceneRenderer(props) {
|
|
|
1050
1050
|
}
|
|
1051
1051
|
const refs = [];
|
|
1052
1052
|
for (let i = 0; i < model.nbody; i++) {
|
|
1053
|
-
const bodyGroup = new
|
|
1053
|
+
const bodyGroup = new THREE11.Group();
|
|
1054
1054
|
bodyGroup.userData.bodyID = i;
|
|
1055
1055
|
const bodyName = getName(model, model.name_bodyadr[i]);
|
|
1056
1056
|
if (!hiddenBodiesRef.current.has(bodyName)) {
|
|
@@ -1079,9 +1079,9 @@ function SceneRenderer(props) {
|
|
|
1079
1079
|
const alpha = interpolation.alpha;
|
|
1080
1080
|
const i3 = i * 3;
|
|
1081
1081
|
ref.position.set(
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1082
|
+
THREE11.MathUtils.lerp(interpolation.previousXpos[i3], interpolation.currentXpos[i3], alpha),
|
|
1083
|
+
THREE11.MathUtils.lerp(interpolation.previousXpos[i3 + 1], interpolation.currentXpos[i3 + 1], alpha),
|
|
1084
|
+
THREE11.MathUtils.lerp(interpolation.previousXpos[i3 + 2], interpolation.currentXpos[i3 + 2], alpha)
|
|
1085
1085
|
);
|
|
1086
1086
|
const i4 = i * 4;
|
|
1087
1087
|
_previousQuat.set(
|
|
@@ -1141,8 +1141,8 @@ function SceneRenderer(props) {
|
|
|
1141
1141
|
}
|
|
1142
1142
|
);
|
|
1143
1143
|
}
|
|
1144
|
-
var _previousQuat = new
|
|
1145
|
-
var _currentQuat = new
|
|
1144
|
+
var _previousQuat = new THREE11.Quaternion();
|
|
1145
|
+
var _currentQuat = new THREE11.Quaternion();
|
|
1146
1146
|
function isTargetRef(target) {
|
|
1147
1147
|
return Boolean(target && typeof target === "object" && "current" in target);
|
|
1148
1148
|
}
|
|
@@ -1648,6 +1648,125 @@ async function recordMountedCameraFrameSequence(api, options) {
|
|
|
1648
1648
|
readiness
|
|
1649
1649
|
};
|
|
1650
1650
|
}
|
|
1651
|
+
var _raycaster = new THREE11.Raycaster();
|
|
1652
|
+
var _ndc = new THREE11.Vector2();
|
|
1653
|
+
function toVector3(value, fallback) {
|
|
1654
|
+
if (!value) return fallback.clone();
|
|
1655
|
+
return value instanceof THREE11.Vector3 ? value.clone() : new THREE11.Vector3(value[0], value[1], value[2]);
|
|
1656
|
+
}
|
|
1657
|
+
function applyCameraPose(camera, options, fallbackCamera) {
|
|
1658
|
+
camera.position.copy(toVector3(options.position, fallbackCamera.position));
|
|
1659
|
+
camera.up.copy(toVector3(options.up, fallbackCamera.up));
|
|
1660
|
+
if (options.quaternion) {
|
|
1661
|
+
if (options.quaternion instanceof THREE11.Quaternion) {
|
|
1662
|
+
camera.quaternion.copy(options.quaternion);
|
|
1663
|
+
} else {
|
|
1664
|
+
camera.quaternion.set(
|
|
1665
|
+
options.quaternion[0],
|
|
1666
|
+
options.quaternion[1],
|
|
1667
|
+
options.quaternion[2],
|
|
1668
|
+
options.quaternion[3]
|
|
1669
|
+
);
|
|
1670
|
+
}
|
|
1671
|
+
} else if (options.lookAt) {
|
|
1672
|
+
camera.lookAt(toVector3(options.lookAt, new THREE11.Vector3()));
|
|
1673
|
+
} else {
|
|
1674
|
+
camera.quaternion.copy(fallbackCamera.quaternion);
|
|
1675
|
+
}
|
|
1676
|
+
camera.updateMatrixWorld();
|
|
1677
|
+
}
|
|
1678
|
+
function createProjectionCamera(fallbackCamera, options, width, height) {
|
|
1679
|
+
const camera = options.camera ? options.camera.clone() : fallbackCamera instanceof THREE11.PerspectiveCamera ? fallbackCamera.clone() : new THREE11.PerspectiveCamera(45, width / height, 0.01, 100);
|
|
1680
|
+
if (camera instanceof THREE11.PerspectiveCamera) {
|
|
1681
|
+
camera.aspect = width / height;
|
|
1682
|
+
camera.fov = options.fov ?? camera.fov;
|
|
1683
|
+
camera.near = options.near ?? camera.near;
|
|
1684
|
+
camera.far = options.far ?? camera.far;
|
|
1685
|
+
camera.updateProjectionMatrix();
|
|
1686
|
+
}
|
|
1687
|
+
applyCameraPose(camera, options, fallbackCamera);
|
|
1688
|
+
return camera;
|
|
1689
|
+
}
|
|
1690
|
+
function getProjectionSource(options) {
|
|
1691
|
+
if (options.source) return options.source;
|
|
1692
|
+
if (options.cameraName) return { kind: "mujoco-camera", cameraName: options.cameraName };
|
|
1693
|
+
if (options.siteName) return { kind: "mujoco-site", siteName: options.siteName };
|
|
1694
|
+
if (options.bodyName) return { kind: "mujoco-body", bodyName: options.bodyName };
|
|
1695
|
+
if (options.camera) return { kind: "custom-camera" };
|
|
1696
|
+
if (options.position || options.lookAt || options.quaternion) return { kind: "explicit-pose" };
|
|
1697
|
+
return { kind: "fallback-camera" };
|
|
1698
|
+
}
|
|
1699
|
+
function imageSize(renderer, options) {
|
|
1700
|
+
return [
|
|
1701
|
+
Math.max(1, Math.floor(options.imageWidth ?? options.width ?? renderer.domElement.width)),
|
|
1702
|
+
Math.max(1, Math.floor(options.imageHeight ?? options.height ?? renderer.domElement.height))
|
|
1703
|
+
];
|
|
1704
|
+
}
|
|
1705
|
+
function imagePointToNdc(x, y, coordinateSpace = "normalized", width = 1, height = 1) {
|
|
1706
|
+
if (coordinateSpace === "ndc") return [x, y];
|
|
1707
|
+
if (coordinateSpace === "normalized-1000") {
|
|
1708
|
+
return [x / 1e3 * 2 - 1, 1 - y / 1e3 * 2];
|
|
1709
|
+
}
|
|
1710
|
+
if (coordinateSpace === "pixel") {
|
|
1711
|
+
return [x / width * 2 - 1, 1 - y / height * 2];
|
|
1712
|
+
}
|
|
1713
|
+
return [x * 2 - 1, 1 - y * 2];
|
|
1714
|
+
}
|
|
1715
|
+
function isProjectionCandidate(object, options) {
|
|
1716
|
+
if (!object.visible) return false;
|
|
1717
|
+
if (object.userData[CAPTURE_EXCLUDE_KEY]) return false;
|
|
1718
|
+
const geomGroup = object.userData.geomGroup;
|
|
1719
|
+
const geomName = object.userData.geomName;
|
|
1720
|
+
if (options.hiddenGeomNames && typeof geomName === "string" && options.hiddenGeomNames.includes(geomName)) {
|
|
1721
|
+
return false;
|
|
1722
|
+
}
|
|
1723
|
+
if (options.hiddenGeomGroups && typeof geomGroup === "number" && options.hiddenGeomGroups.includes(geomGroup)) {
|
|
1724
|
+
return false;
|
|
1725
|
+
}
|
|
1726
|
+
if (options.visibleGeomGroups && typeof geomGroup === "number" && !options.visibleGeomGroups.includes(geomGroup)) {
|
|
1727
|
+
return false;
|
|
1728
|
+
}
|
|
1729
|
+
return true;
|
|
1730
|
+
}
|
|
1731
|
+
function findBodyId(object) {
|
|
1732
|
+
let current = object;
|
|
1733
|
+
while (current && current.userData.bodyID === void 0 && current.parent) {
|
|
1734
|
+
current = current.parent;
|
|
1735
|
+
}
|
|
1736
|
+
return typeof current?.userData.bodyID === "number" ? current.userData.bodyID : -1;
|
|
1737
|
+
}
|
|
1738
|
+
function projectImagePointTo3D(renderer, scene, fallbackCamera, options) {
|
|
1739
|
+
const [width, height] = imageSize(renderer, options);
|
|
1740
|
+
const [ndcX, ndcY] = imagePointToNdc(
|
|
1741
|
+
options.x,
|
|
1742
|
+
options.y,
|
|
1743
|
+
options.coordinateSpace,
|
|
1744
|
+
width,
|
|
1745
|
+
height
|
|
1746
|
+
);
|
|
1747
|
+
const projectionCamera = createProjectionCamera(fallbackCamera, options, width, height);
|
|
1748
|
+
scene.updateMatrixWorld(true);
|
|
1749
|
+
_ndc.set(ndcX, ndcY);
|
|
1750
|
+
_raycaster.setFromCamera(_ndc, projectionCamera);
|
|
1751
|
+
_raycaster.far = options.maxDistance ?? Infinity;
|
|
1752
|
+
const objects = [];
|
|
1753
|
+
scene.traverse((object) => {
|
|
1754
|
+
if (object.isMesh && isProjectionCandidate(object, options)) {
|
|
1755
|
+
objects.push(object);
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
const [hit] = _raycaster.intersectObjects(objects, true);
|
|
1759
|
+
if (!hit) return null;
|
|
1760
|
+
return {
|
|
1761
|
+
point: hit.point.clone(),
|
|
1762
|
+
bodyId: findBodyId(hit.object),
|
|
1763
|
+
geomId: typeof hit.object.userData.geomID === "number" ? hit.object.userData.geomID : -1,
|
|
1764
|
+
distance: hit.distance,
|
|
1765
|
+
ndc: [ndcX, ndcY],
|
|
1766
|
+
imageSize: [width, height],
|
|
1767
|
+
source: getProjectionSource(options)
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1651
1770
|
var JOINT_TYPE_NAMES2 = ["free", "ball", "slide", "hinge"];
|
|
1652
1771
|
var GEOM_TYPE_NAMES = ["plane", "hfield", "sphere", "capsule", "ellipsoid", "cylinder", "box", "mesh"];
|
|
1653
1772
|
var SENSOR_TYPE_NAMES = {
|
|
@@ -1723,8 +1842,8 @@ var _applyPoint = new Float64Array(3);
|
|
|
1723
1842
|
var _rayPnt = new Float64Array(3);
|
|
1724
1843
|
var _rayVec = new Float64Array(3);
|
|
1725
1844
|
var _rayGeomId = new Int32Array(1);
|
|
1726
|
-
var _projRaycaster = new
|
|
1727
|
-
var _projNdc = new
|
|
1845
|
+
var _projRaycaster = new THREE11.Raycaster();
|
|
1846
|
+
var _projNdc = new THREE11.Vector2();
|
|
1728
1847
|
function waitForNextAnimationFrame2() {
|
|
1729
1848
|
return new Promise((resolve) => {
|
|
1730
1849
|
requestAnimationFrame(() => resolve());
|
|
@@ -1749,7 +1868,7 @@ function quaternionFromMujocoQuat(values, offset) {
|
|
|
1749
1868
|
];
|
|
1750
1869
|
}
|
|
1751
1870
|
function quaternionFromXmat(values, offset) {
|
|
1752
|
-
const matrix = new
|
|
1871
|
+
const matrix = new THREE11.Matrix4();
|
|
1753
1872
|
matrix.set(
|
|
1754
1873
|
values[offset],
|
|
1755
1874
|
values[offset + 1],
|
|
@@ -1768,7 +1887,7 @@ function quaternionFromXmat(values, offset) {
|
|
|
1768
1887
|
0,
|
|
1769
1888
|
1
|
|
1770
1889
|
);
|
|
1771
|
-
const quaternion = new
|
|
1890
|
+
const quaternion = new THREE11.Quaternion().setFromRotationMatrix(matrix);
|
|
1772
1891
|
return [quaternion.x, quaternion.y, quaternion.z, quaternion.w];
|
|
1773
1892
|
}
|
|
1774
1893
|
function omitResolvedCameraSelectors(options) {
|
|
@@ -1776,14 +1895,14 @@ function omitResolvedCameraSelectors(options) {
|
|
|
1776
1895
|
return rest;
|
|
1777
1896
|
}
|
|
1778
1897
|
function vector3FromCaptureValue(value) {
|
|
1779
|
-
return value instanceof
|
|
1898
|
+
return value instanceof THREE11.Vector3 ? value.clone() : new THREE11.Vector3(value[0], value[1], value[2]);
|
|
1780
1899
|
}
|
|
1781
1900
|
function quaternionFromCaptureValue(value) {
|
|
1782
|
-
return value instanceof
|
|
1901
|
+
return value instanceof THREE11.Quaternion ? value.clone() : new THREE11.Quaternion(value[0], value[1], value[2], value[3]);
|
|
1783
1902
|
}
|
|
1784
1903
|
function applyMountedCameraPoseOffsets(options, position, quaternion) {
|
|
1785
|
-
const resolvedPosition = new
|
|
1786
|
-
const resolvedQuaternion = new
|
|
1904
|
+
const resolvedPosition = new THREE11.Vector3(position[0], position[1], position[2]);
|
|
1905
|
+
const resolvedQuaternion = new THREE11.Quaternion(
|
|
1787
1906
|
quaternion[0],
|
|
1788
1907
|
quaternion[1],
|
|
1789
1908
|
quaternion[2],
|
|
@@ -2590,7 +2709,7 @@ function MujocoSimProvider({
|
|
|
2590
2709
|
const geomId = _rayGeomId[0];
|
|
2591
2710
|
const bodyId = geomId >= 0 ? model.geom_bodyid[geomId] : -1;
|
|
2592
2711
|
return {
|
|
2593
|
-
point: new
|
|
2712
|
+
point: new THREE11.Vector3(
|
|
2594
2713
|
origin.x + dir.x * dist,
|
|
2595
2714
|
origin.y + dir.y * dist,
|
|
2596
2715
|
origin.z + dir.z * dist
|
|
@@ -2951,6 +3070,30 @@ function MujocoSimProvider({
|
|
|
2951
3070
|
},
|
|
2952
3071
|
[camera, gl]
|
|
2953
3072
|
);
|
|
3073
|
+
const projectImagePointTo3D2 = useCallback(
|
|
3074
|
+
(options) => {
|
|
3075
|
+
const {
|
|
3076
|
+
x,
|
|
3077
|
+
y,
|
|
3078
|
+
coordinateSpace,
|
|
3079
|
+
imageWidth,
|
|
3080
|
+
imageHeight,
|
|
3081
|
+
maxDistance,
|
|
3082
|
+
...captureOptions
|
|
3083
|
+
} = options;
|
|
3084
|
+
const resolvedCaptureOptions = resolveCameraCaptureOptions(captureOptions);
|
|
3085
|
+
return projectImagePointTo3D(gl, scene, camera, {
|
|
3086
|
+
...resolvedCaptureOptions,
|
|
3087
|
+
x,
|
|
3088
|
+
y,
|
|
3089
|
+
coordinateSpace,
|
|
3090
|
+
imageWidth,
|
|
3091
|
+
imageHeight,
|
|
3092
|
+
maxDistance
|
|
3093
|
+
});
|
|
3094
|
+
},
|
|
3095
|
+
[camera, gl, resolveCameraCaptureOptions, scene]
|
|
3096
|
+
);
|
|
2954
3097
|
const setBodyMass = useCallback((name, mass) => {
|
|
2955
3098
|
const model = mjModelRef.current;
|
|
2956
3099
|
if (!model) return;
|
|
@@ -3035,6 +3178,7 @@ function MujocoSimProvider({
|
|
|
3035
3178
|
captureCameraFrameBlob: captureCameraFrameBlobApi,
|
|
3036
3179
|
recordCameraSequence: recordCameraSequenceApi,
|
|
3037
3180
|
project2DTo3D,
|
|
3181
|
+
projectImagePointTo3D: projectImagePointTo3D2,
|
|
3038
3182
|
setBodyMass,
|
|
3039
3183
|
setGeomFriction,
|
|
3040
3184
|
setGeomSize,
|
|
@@ -3094,6 +3238,7 @@ function MujocoSimProvider({
|
|
|
3094
3238
|
captureCameraFrameBlobApi,
|
|
3095
3239
|
recordCameraSequenceApi,
|
|
3096
3240
|
project2DTo3D,
|
|
3241
|
+
projectImagePointTo3D2,
|
|
3097
3242
|
setBodyMass,
|
|
3098
3243
|
setGeomFriction,
|
|
3099
3244
|
setGeomSize
|
|
@@ -3569,7 +3714,7 @@ function solve6x6(A, b, x) {
|
|
|
3569
3714
|
}
|
|
3570
3715
|
|
|
3571
3716
|
// src/hooks/useIkController.ts
|
|
3572
|
-
var _syncMat4 = new
|
|
3717
|
+
var _syncMat4 = new THREE11.Matrix4();
|
|
3573
3718
|
function syncGizmoToSite(data, siteId, target) {
|
|
3574
3719
|
if (siteId === -1) return;
|
|
3575
3720
|
const sitePos = data.site_xpos.subarray(siteId * 3, siteId * 3 + 3);
|
|
@@ -3601,7 +3746,7 @@ var useIkController = createControllerHook(
|
|
|
3601
3746
|
const { mjModelRef, mjDataRef, mujocoRef, resetCallbacks, status } = useMujocoContext();
|
|
3602
3747
|
const ikEnabledRef = useRef(false);
|
|
3603
3748
|
const ikCalculatingRef = useRef(false);
|
|
3604
|
-
const ikTargetRef = useRef(new
|
|
3749
|
+
const ikTargetRef = useRef(new THREE11.Group());
|
|
3605
3750
|
const siteIdRef = useRef(-1);
|
|
3606
3751
|
const controlGroupRef = useRef(null);
|
|
3607
3752
|
const genericIkRef = useRef(new GenericIK(mujocoRef.current));
|
|
@@ -3609,10 +3754,10 @@ var useIkController = createControllerHook(
|
|
|
3609
3754
|
const needsInitialSync = useRef(true);
|
|
3610
3755
|
const gizmoAnimRef = useRef({
|
|
3611
3756
|
active: false,
|
|
3612
|
-
startPos: new
|
|
3613
|
-
endPos: new
|
|
3614
|
-
startRot: new
|
|
3615
|
-
endRot: new
|
|
3757
|
+
startPos: new THREE11.Vector3(),
|
|
3758
|
+
endPos: new THREE11.Vector3(),
|
|
3759
|
+
startRot: new THREE11.Quaternion(),
|
|
3760
|
+
endRot: new THREE11.Quaternion(),
|
|
3616
3761
|
startTime: 0,
|
|
3617
3762
|
duration: 1e3
|
|
3618
3763
|
});
|
|
@@ -3764,8 +3909,8 @@ var useIkController = createControllerHook(
|
|
|
3764
3909
|
const target = ikTargetRef.current;
|
|
3765
3910
|
if (!target) return;
|
|
3766
3911
|
const targetPos = pos.clone();
|
|
3767
|
-
const targetRot = new
|
|
3768
|
-
new
|
|
3912
|
+
const targetRot = new THREE11.Quaternion().setFromEuler(
|
|
3913
|
+
new THREE11.Euler(Math.PI, 0, 0)
|
|
3769
3914
|
);
|
|
3770
3915
|
if (duration > 0) {
|
|
3771
3916
|
const ga = gizmoAnimRef.current;
|
|
@@ -3790,7 +3935,7 @@ var useIkController = createControllerHook(
|
|
|
3790
3935
|
if (!ikCalculatingRef.current || !target) return null;
|
|
3791
3936
|
return {
|
|
3792
3937
|
pos: target.position.clone(),
|
|
3793
|
-
rot: new
|
|
3938
|
+
rot: new THREE11.Euler().setFromQuaternion(target.quaternion)
|
|
3794
3939
|
};
|
|
3795
3940
|
},
|
|
3796
3941
|
[]
|
|
@@ -3886,10 +4031,10 @@ function Body({
|
|
|
3886
4031
|
if (!hasChildren) return null;
|
|
3887
4032
|
return /* @__PURE__ */ jsx("group", { ref: groupRef, children });
|
|
3888
4033
|
}
|
|
3889
|
-
var _mat4 = new
|
|
3890
|
-
var _pos = new
|
|
3891
|
-
var _quat = new
|
|
3892
|
-
var _scale = new
|
|
4034
|
+
var _mat4 = new THREE11.Matrix4();
|
|
4035
|
+
var _pos = new THREE11.Vector3();
|
|
4036
|
+
var _quat = new THREE11.Quaternion();
|
|
4037
|
+
var _scale = new THREE11.Vector3(1, 1, 1);
|
|
3893
4038
|
function IkGizmo({ controller, siteName, scale = 0.18, onDrag }) {
|
|
3894
4039
|
const { mjModelRef, mjDataRef, status } = useMujocoContext();
|
|
3895
4040
|
const { ikTargetRef, siteIdRef, ikEnabledRef, setIkEnabled } = controller;
|
|
@@ -3988,7 +4133,7 @@ function IkGizmo({ controller, siteName, scale = 0.18, onDrag }) {
|
|
|
3988
4133
|
}
|
|
3989
4134
|
);
|
|
3990
4135
|
}
|
|
3991
|
-
var _dummy = new
|
|
4136
|
+
var _dummy = new THREE11.Object3D();
|
|
3992
4137
|
function ContactMarkers({
|
|
3993
4138
|
maxContacts = 100,
|
|
3994
4139
|
radius = 8e-3,
|
|
@@ -4042,11 +4187,11 @@ function ContactMarkers({
|
|
|
4042
4187
|
var _force = new Float64Array(3);
|
|
4043
4188
|
var _torque = new Float64Array(3);
|
|
4044
4189
|
var _point = new Float64Array(3);
|
|
4045
|
-
var _bodyPos = new
|
|
4046
|
-
var _bodyQuat = new
|
|
4047
|
-
var _worldHit = new
|
|
4048
|
-
var
|
|
4049
|
-
var _mouse = new
|
|
4190
|
+
var _bodyPos = new THREE11.Vector3();
|
|
4191
|
+
var _bodyQuat = new THREE11.Quaternion();
|
|
4192
|
+
var _worldHit = new THREE11.Vector3();
|
|
4193
|
+
var _raycaster2 = new THREE11.Raycaster();
|
|
4194
|
+
var _mouse = new THREE11.Vector2();
|
|
4050
4195
|
function DragInteraction({
|
|
4051
4196
|
stiffness = 250,
|
|
4052
4197
|
showArrow = true,
|
|
@@ -4057,16 +4202,16 @@ function DragInteraction({
|
|
|
4057
4202
|
const draggingRef = useRef(false);
|
|
4058
4203
|
const bodyIdRef = useRef(-1);
|
|
4059
4204
|
const grabDistanceRef = useRef(0);
|
|
4060
|
-
const localHitRef = useRef(new
|
|
4061
|
-
const grabWorldRef = useRef(new
|
|
4062
|
-
const mouseWorldRef = useRef(new
|
|
4205
|
+
const localHitRef = useRef(new THREE11.Vector3());
|
|
4206
|
+
const grabWorldRef = useRef(new THREE11.Vector3());
|
|
4207
|
+
const mouseWorldRef = useRef(new THREE11.Vector3());
|
|
4063
4208
|
const arrowRef = useRef(null);
|
|
4064
4209
|
const groupRef = useRef(null);
|
|
4065
4210
|
useEffect(() => {
|
|
4066
4211
|
if (!showArrow || !groupRef.current) return;
|
|
4067
|
-
const arrow = new
|
|
4068
|
-
new
|
|
4069
|
-
new
|
|
4212
|
+
const arrow = new THREE11.ArrowHelper(
|
|
4213
|
+
new THREE11.Vector3(0, 1, 0),
|
|
4214
|
+
new THREE11.Vector3(),
|
|
4070
4215
|
0.1,
|
|
4071
4216
|
16729156
|
|
4072
4217
|
);
|
|
@@ -4094,8 +4239,8 @@ function DragInteraction({
|
|
|
4094
4239
|
(evt.clientX - rect.left) / rect.width * 2 - 1,
|
|
4095
4240
|
-((evt.clientY - rect.top) / rect.height) * 2 + 1
|
|
4096
4241
|
);
|
|
4097
|
-
|
|
4098
|
-
const hits =
|
|
4242
|
+
_raycaster2.setFromCamera(_mouse, camera);
|
|
4243
|
+
const hits = _raycaster2.intersectObjects(scene.children, true);
|
|
4099
4244
|
for (const hit of hits) {
|
|
4100
4245
|
let obj = hit.object;
|
|
4101
4246
|
while (obj && obj.userData.bodyID === void 0 && obj.parent) {
|
|
@@ -4140,8 +4285,8 @@ function DragInteraction({
|
|
|
4140
4285
|
(evt.clientX - rect.left) / rect.width * 2 - 1,
|
|
4141
4286
|
-((evt.clientY - rect.top) / rect.height) * 2 + 1
|
|
4142
4287
|
);
|
|
4143
|
-
|
|
4144
|
-
mouseWorldRef.current.copy(
|
|
4288
|
+
_raycaster2.setFromCamera(_mouse, camera);
|
|
4289
|
+
mouseWorldRef.current.copy(_raycaster2.ray.origin).addScaledVector(_raycaster2.ray.direction, grabDistanceRef.current);
|
|
4145
4290
|
};
|
|
4146
4291
|
const onPointerUp = () => {
|
|
4147
4292
|
if (!draggingRef.current) return;
|
|
@@ -4249,7 +4394,7 @@ function useSceneLights(intensity = 1) {
|
|
|
4249
4394
|
const dr = lightDiffuse ? lightDiffuse[3 * i] : 1;
|
|
4250
4395
|
const dg = lightDiffuse ? lightDiffuse[3 * i + 1] : 1;
|
|
4251
4396
|
const db = lightDiffuse ? lightDiffuse[3 * i + 2] : 1;
|
|
4252
|
-
const color = new
|
|
4397
|
+
const color = new THREE11.Color(dr, dg, db);
|
|
4253
4398
|
const px = lightPos[3 * i];
|
|
4254
4399
|
const py = lightPos[3 * i + 1];
|
|
4255
4400
|
const pz = lightPos[3 * i + 2];
|
|
@@ -4257,7 +4402,7 @@ function useSceneLights(intensity = 1) {
|
|
|
4257
4402
|
const dy = lightDir[3 * i + 1];
|
|
4258
4403
|
const dz = lightDir[3 * i + 2];
|
|
4259
4404
|
if (isDirectional) {
|
|
4260
|
-
const light = new
|
|
4405
|
+
const light = new THREE11.DirectionalLight(color, finalIntensity);
|
|
4261
4406
|
light.position.set(px, py, pz);
|
|
4262
4407
|
light.target.position.set(px + dx, py + dy, pz + dz);
|
|
4263
4408
|
light.castShadow = castShadow;
|
|
@@ -4280,7 +4425,7 @@ function useSceneLights(intensity = 1) {
|
|
|
4280
4425
|
const cutoff = lightCutoff ? lightCutoff[i] : 45;
|
|
4281
4426
|
const exponent = lightExponent ? lightExponent[i] : 10;
|
|
4282
4427
|
const angle = cutoff * Math.PI / 180;
|
|
4283
|
-
const light = new
|
|
4428
|
+
const light = new THREE11.SpotLight(color, finalIntensity, 0, angle, exponent / 128);
|
|
4284
4429
|
light.position.set(px, py, pz);
|
|
4285
4430
|
light.target.position.set(px + dx, py + dy, pz + dz);
|
|
4286
4431
|
light.castShadow = castShadow;
|
|
@@ -4563,12 +4708,12 @@ var JOINT_COLORS = {
|
|
|
4563
4708
|
3: 16776960
|
|
4564
4709
|
// hinge - yellow
|
|
4565
4710
|
};
|
|
4566
|
-
var _v3a = new
|
|
4567
|
-
new
|
|
4568
|
-
var _quat2 = new
|
|
4569
|
-
var _cameraMatrix = new
|
|
4570
|
-
var _contactPos = new
|
|
4571
|
-
var _contactNormal = new
|
|
4711
|
+
var _v3a = new THREE11.Vector3();
|
|
4712
|
+
new THREE11.Vector3();
|
|
4713
|
+
var _quat2 = new THREE11.Quaternion();
|
|
4714
|
+
var _cameraMatrix = new THREE11.Matrix4();
|
|
4715
|
+
var _contactPos = new THREE11.Vector3();
|
|
4716
|
+
var _contactNormal = new THREE11.Vector3();
|
|
4572
4717
|
var MAX_CONTACT_ARROWS = 50;
|
|
4573
4718
|
var CAMERA_DEBUG_LENGTH = 0.12;
|
|
4574
4719
|
var CAMERA_DEBUG_FRUSTUM_DEPTH = 0.08;
|
|
@@ -4601,21 +4746,21 @@ function Debug({
|
|
|
4601
4746
|
let geometry = null;
|
|
4602
4747
|
switch (type) {
|
|
4603
4748
|
case 2:
|
|
4604
|
-
geometry = new
|
|
4749
|
+
geometry = new THREE11.SphereGeometry(s[3 * i], 12, 8);
|
|
4605
4750
|
break;
|
|
4606
4751
|
case 3:
|
|
4607
|
-
geometry = new
|
|
4752
|
+
geometry = new THREE11.CapsuleGeometry(s[3 * i], s[3 * i + 1] * 2, 6, 8);
|
|
4608
4753
|
break;
|
|
4609
4754
|
case 5:
|
|
4610
|
-
geometry = new
|
|
4755
|
+
geometry = new THREE11.CylinderGeometry(s[3 * i], s[3 * i], s[3 * i + 1] * 2, 12);
|
|
4611
4756
|
break;
|
|
4612
4757
|
case 6:
|
|
4613
|
-
geometry = new
|
|
4758
|
+
geometry = new THREE11.BoxGeometry(s[3 * i] * 2, s[3 * i + 1] * 2, s[3 * i + 2] * 2);
|
|
4614
4759
|
break;
|
|
4615
4760
|
}
|
|
4616
4761
|
if (geometry) {
|
|
4617
|
-
const mat = new
|
|
4618
|
-
const mesh = new
|
|
4762
|
+
const mat = new THREE11.MeshBasicMaterial({ color: 65280, wireframe: true, transparent: true, opacity: 0.3 });
|
|
4763
|
+
const mesh = new THREE11.Mesh(geometry, mat);
|
|
4619
4764
|
mesh.userData.geomId = i;
|
|
4620
4765
|
mesh.userData.bodyId = model.geom_bodyid[i];
|
|
4621
4766
|
geoms.push(mesh);
|
|
@@ -4638,9 +4783,9 @@ function Debug({
|
|
|
4638
4783
|
}
|
|
4639
4784
|
if (maxGeomSize > 0) radius = maxGeomSize * 0.15;
|
|
4640
4785
|
}
|
|
4641
|
-
const geometry = new
|
|
4642
|
-
const mat = new
|
|
4643
|
-
const mesh = new
|
|
4786
|
+
const geometry = new THREE11.OctahedronGeometry(radius);
|
|
4787
|
+
const mat = new THREE11.MeshBasicMaterial({ color: 16711935, depthTest: false });
|
|
4788
|
+
const mesh = new THREE11.Mesh(geometry, mat);
|
|
4644
4789
|
mesh.renderOrder = 999;
|
|
4645
4790
|
mesh.frustumCulled = false;
|
|
4646
4791
|
mesh.userData.siteId = i;
|
|
@@ -4652,9 +4797,9 @@ function Debug({
|
|
|
4652
4797
|
ctx.font = "bold 36px monospace";
|
|
4653
4798
|
ctx.textAlign = "center";
|
|
4654
4799
|
ctx.fillText(getName(model, model.name_siteadr[i]), 128, 42);
|
|
4655
|
-
const tex = new
|
|
4656
|
-
const spriteMat = new
|
|
4657
|
-
const sprite = new
|
|
4800
|
+
const tex = new THREE11.CanvasTexture(canvas);
|
|
4801
|
+
const spriteMat = new THREE11.SpriteMaterial({ map: tex, depthTest: false, transparent: true });
|
|
4802
|
+
const sprite = new THREE11.Sprite(spriteMat);
|
|
4658
4803
|
const labelScale = radius * 15;
|
|
4659
4804
|
sprite.scale.set(labelScale, labelScale * 0.25, 1);
|
|
4660
4805
|
sprite.position.y = radius * 2;
|
|
@@ -4677,9 +4822,9 @@ function Debug({
|
|
|
4677
4822
|
}
|
|
4678
4823
|
}
|
|
4679
4824
|
const arrowLen = Math.max(maxGeomSize * 0.8, 0.05);
|
|
4680
|
-
const arrow = new
|
|
4681
|
-
new
|
|
4682
|
-
new
|
|
4825
|
+
const arrow = new THREE11.ArrowHelper(
|
|
4826
|
+
new THREE11.Vector3(0, 0, 1),
|
|
4827
|
+
new THREE11.Vector3(),
|
|
4683
4828
|
arrowLen,
|
|
4684
4829
|
color,
|
|
4685
4830
|
arrowLen * 0.25,
|
|
@@ -4687,7 +4832,7 @@ function Debug({
|
|
|
4687
4832
|
);
|
|
4688
4833
|
arrow.renderOrder = 999;
|
|
4689
4834
|
arrow.frustumCulled = false;
|
|
4690
|
-
arrow.line.material = new
|
|
4835
|
+
arrow.line.material = new THREE11.LineBasicMaterial({ color, depthTest: false });
|
|
4691
4836
|
arrow.cone.material.depthTest = false;
|
|
4692
4837
|
arrow.line.renderOrder = 999;
|
|
4693
4838
|
arrow.line.frustumCulled = false;
|
|
@@ -4702,20 +4847,20 @@ function Debug({
|
|
|
4702
4847
|
}
|
|
4703
4848
|
if (showCameras && model.ncam && model.name_camadr) {
|
|
4704
4849
|
for (let i = 0; i < model.ncam; i++) {
|
|
4705
|
-
const group = new
|
|
4850
|
+
const group = new THREE11.Group();
|
|
4706
4851
|
group.userData.cameraId = i;
|
|
4707
4852
|
group.renderOrder = 999;
|
|
4708
4853
|
group.frustumCulled = false;
|
|
4709
|
-
const marker = new
|
|
4710
|
-
new
|
|
4711
|
-
new
|
|
4854
|
+
const marker = new THREE11.Mesh(
|
|
4855
|
+
new THREE11.BoxGeometry(0.014, 9e-3, 6e-3),
|
|
4856
|
+
new THREE11.MeshBasicMaterial({ color: 3718648, depthTest: false })
|
|
4712
4857
|
);
|
|
4713
4858
|
marker.renderOrder = 999;
|
|
4714
4859
|
marker.frustumCulled = false;
|
|
4715
4860
|
group.add(marker);
|
|
4716
|
-
const forward = new
|
|
4717
|
-
new
|
|
4718
|
-
new
|
|
4861
|
+
const forward = new THREE11.ArrowHelper(
|
|
4862
|
+
new THREE11.Vector3(0, 0, -1),
|
|
4863
|
+
new THREE11.Vector3(),
|
|
4719
4864
|
CAMERA_DEBUG_LENGTH,
|
|
4720
4865
|
3718648,
|
|
4721
4866
|
CAMERA_DEBUG_LENGTH * 0.24,
|
|
@@ -4723,20 +4868,20 @@ function Debug({
|
|
|
4723
4868
|
);
|
|
4724
4869
|
forward.renderOrder = 999;
|
|
4725
4870
|
forward.frustumCulled = false;
|
|
4726
|
-
forward.line.material = new
|
|
4871
|
+
forward.line.material = new THREE11.LineBasicMaterial({
|
|
4727
4872
|
color: 3718648,
|
|
4728
4873
|
depthTest: false
|
|
4729
4874
|
});
|
|
4730
4875
|
forward.cone.material.depthTest = false;
|
|
4731
4876
|
group.add(forward);
|
|
4732
|
-
const frustumGeometry = new
|
|
4877
|
+
const frustumGeometry = new THREE11.BufferGeometry();
|
|
4733
4878
|
frustumGeometry.setAttribute(
|
|
4734
4879
|
"position",
|
|
4735
|
-
new
|
|
4880
|
+
new THREE11.Float32BufferAttribute(new Float32Array(8 * 2 * 3), 3)
|
|
4736
4881
|
);
|
|
4737
|
-
const frustum = new
|
|
4882
|
+
const frustum = new THREE11.LineSegments(
|
|
4738
4883
|
frustumGeometry,
|
|
4739
|
-
new
|
|
4884
|
+
new THREE11.LineBasicMaterial({
|
|
4740
4885
|
color: 3718648,
|
|
4741
4886
|
transparent: true,
|
|
4742
4887
|
opacity: 0.8,
|
|
@@ -4755,9 +4900,9 @@ function Debug({
|
|
|
4755
4900
|
ctx.font = "bold 32px monospace";
|
|
4756
4901
|
ctx.textAlign = "center";
|
|
4757
4902
|
ctx.fillText(getName(model, model.name_camadr[i]), 128, 42);
|
|
4758
|
-
const texture = new
|
|
4759
|
-
const sprite = new
|
|
4760
|
-
new
|
|
4903
|
+
const texture = new THREE11.CanvasTexture(canvas);
|
|
4904
|
+
const sprite = new THREE11.Sprite(
|
|
4905
|
+
new THREE11.SpriteMaterial({
|
|
4761
4906
|
map: texture,
|
|
4762
4907
|
depthTest: false,
|
|
4763
4908
|
transparent: true
|
|
@@ -4773,9 +4918,9 @@ function Debug({
|
|
|
4773
4918
|
}
|
|
4774
4919
|
if (showCOM) {
|
|
4775
4920
|
for (let i = 1; i < model.nbody; i++) {
|
|
4776
|
-
const geometry = new
|
|
4777
|
-
const mat = new
|
|
4778
|
-
const mesh = new
|
|
4921
|
+
const geometry = new THREE11.SphereGeometry(5e-3, 6, 6);
|
|
4922
|
+
const mat = new THREE11.MeshBasicMaterial({ color: 16711680 });
|
|
4923
|
+
const mesh = new THREE11.Mesh(geometry, mat);
|
|
4779
4924
|
mesh.userData.bodyId = i;
|
|
4780
4925
|
comMarkers.push(mesh);
|
|
4781
4926
|
}
|
|
@@ -4884,7 +5029,7 @@ function Debug({
|
|
|
4884
5029
|
);
|
|
4885
5030
|
group.quaternion.setFromRotationMatrix(_cameraMatrix);
|
|
4886
5031
|
const fovy = model.cam_fovy?.[cameraId] ?? 45;
|
|
4887
|
-
const halfHeight = Math.tan(
|
|
5032
|
+
const halfHeight = Math.tan(THREE11.MathUtils.degToRad(fovy) / 2) * CAMERA_DEBUG_FRUSTUM_DEPTH;
|
|
4888
5033
|
const halfWidth = halfHeight * 4 / 3;
|
|
4889
5034
|
const positions = group.userData.frustum.geometry.attributes.position;
|
|
4890
5035
|
const array = positions.array;
|
|
@@ -4929,9 +5074,9 @@ function Debug({
|
|
|
4929
5074
|
contactPoolInitRef.current = true;
|
|
4930
5075
|
const pool = [];
|
|
4931
5076
|
for (let i = 0; i < MAX_CONTACT_ARROWS; i++) {
|
|
4932
|
-
const arrow = new
|
|
4933
|
-
new
|
|
4934
|
-
new
|
|
5077
|
+
const arrow = new THREE11.ArrowHelper(
|
|
5078
|
+
new THREE11.Vector3(0, 1, 0),
|
|
5079
|
+
new THREE11.Vector3(),
|
|
4935
5080
|
0.1,
|
|
4936
5081
|
16729156,
|
|
4937
5082
|
0.03,
|
|
@@ -4996,9 +5141,9 @@ function Debug({
|
|
|
4996
5141
|
}
|
|
4997
5142
|
);
|
|
4998
5143
|
}
|
|
4999
|
-
var DEFAULT_TENDON_COLOR = new
|
|
5144
|
+
var DEFAULT_TENDON_COLOR = new THREE11.Color(0.3, 0.3, 0.8);
|
|
5000
5145
|
var DEFAULT_TENDON_WIDTH = 2e-3;
|
|
5001
|
-
new
|
|
5146
|
+
new THREE11.Vector3();
|
|
5002
5147
|
function TendonRenderer(props) {
|
|
5003
5148
|
const { mjModelRef, mjDataRef, status } = useMujocoContext();
|
|
5004
5149
|
const groupRef = useRef(null);
|
|
@@ -5012,7 +5157,7 @@ function TendonRenderer(props) {
|
|
|
5012
5157
|
if (!model || !data || !group) return;
|
|
5013
5158
|
const ntendon = model.ntendon ?? 0;
|
|
5014
5159
|
if (ntendon === 0) return;
|
|
5015
|
-
const material = new
|
|
5160
|
+
const material = new THREE11.MeshStandardMaterial({
|
|
5016
5161
|
color: DEFAULT_TENDON_COLOR,
|
|
5017
5162
|
roughness: 0.6,
|
|
5018
5163
|
metalness: 0.1
|
|
@@ -5027,11 +5172,11 @@ function TendonRenderer(props) {
|
|
|
5027
5172
|
curves.push(null);
|
|
5028
5173
|
continue;
|
|
5029
5174
|
}
|
|
5030
|
-
const points = Array.from({ length: wrapNum }, () => new
|
|
5031
|
-
const curve = new
|
|
5175
|
+
const points = Array.from({ length: wrapNum }, () => new THREE11.Vector3());
|
|
5176
|
+
const curve = new THREE11.CatmullRomCurve3(points, false);
|
|
5032
5177
|
const segments = Math.max(wrapNum * 2, 4);
|
|
5033
|
-
const geometry = new
|
|
5034
|
-
const mesh = new
|
|
5178
|
+
const geometry = new THREE11.TubeGeometry(curve, segments, DEFAULT_TENDON_WIDTH, 6, false);
|
|
5179
|
+
const mesh = new THREE11.Mesh(geometry, material);
|
|
5035
5180
|
mesh.frustumCulled = false;
|
|
5036
5181
|
group.add(mesh);
|
|
5037
5182
|
meshes.push(mesh);
|
|
@@ -5086,11 +5231,11 @@ function TendonRenderer(props) {
|
|
|
5086
5231
|
if (curve.points.length !== validCount) {
|
|
5087
5232
|
curve.points.length = validCount;
|
|
5088
5233
|
while (curve.points.length < validCount) {
|
|
5089
|
-
curve.points.push(new
|
|
5234
|
+
curve.points.push(new THREE11.Vector3());
|
|
5090
5235
|
}
|
|
5091
5236
|
}
|
|
5092
5237
|
mesh.geometry.dispose();
|
|
5093
|
-
mesh.geometry = new
|
|
5238
|
+
mesh.geometry = new THREE11.TubeGeometry(
|
|
5094
5239
|
curve,
|
|
5095
5240
|
Math.max(validCount * 2, 4),
|
|
5096
5241
|
DEFAULT_TENDON_WIDTH,
|
|
@@ -5117,24 +5262,24 @@ function FlexRenderer(props) {
|
|
|
5117
5262
|
const vertAdr = model.flex_vertadr[f];
|
|
5118
5263
|
const vertNum = model.flex_vertnum[f];
|
|
5119
5264
|
if (vertNum === 0) continue;
|
|
5120
|
-
const geometry = new
|
|
5265
|
+
const geometry = new THREE11.BufferGeometry();
|
|
5121
5266
|
const positions = new Float32Array(vertNum * 3);
|
|
5122
|
-
geometry.setAttribute("position", new
|
|
5267
|
+
geometry.setAttribute("position", new THREE11.BufferAttribute(positions, 3));
|
|
5123
5268
|
geometry.computeVertexNormals();
|
|
5124
|
-
let color = new
|
|
5269
|
+
let color = new THREE11.Color(0.5, 0.5, 0.5);
|
|
5125
5270
|
if (model.flex_rgba) {
|
|
5126
|
-
color = new
|
|
5271
|
+
color = new THREE11.Color(
|
|
5127
5272
|
model.flex_rgba[4 * f],
|
|
5128
5273
|
model.flex_rgba[4 * f + 1],
|
|
5129
5274
|
model.flex_rgba[4 * f + 2]
|
|
5130
5275
|
);
|
|
5131
5276
|
}
|
|
5132
|
-
const material = new
|
|
5277
|
+
const material = new THREE11.MeshStandardMaterial({
|
|
5133
5278
|
color,
|
|
5134
5279
|
roughness: 0.7,
|
|
5135
|
-
side:
|
|
5280
|
+
side: THREE11.DoubleSide
|
|
5136
5281
|
});
|
|
5137
|
-
const mesh = new
|
|
5282
|
+
const mesh = new THREE11.Mesh(geometry, material);
|
|
5138
5283
|
mesh.userData.flexId = f;
|
|
5139
5284
|
mesh.userData.vertAdr = vertAdr;
|
|
5140
5285
|
mesh.userData.vertNum = vertNum;
|
|
@@ -5170,7 +5315,7 @@ function FlexRenderer(props) {
|
|
|
5170
5315
|
return /* @__PURE__ */ jsx("group", { ...props, ref: groupRef });
|
|
5171
5316
|
}
|
|
5172
5317
|
var GEOM_TYPE_NAMES2 = ["plane", "hfield", "sphere", "capsule", "ellipsoid", "cylinder", "box", "mesh"];
|
|
5173
|
-
var _matrix = new
|
|
5318
|
+
var _matrix = new THREE11.Matrix4();
|
|
5174
5319
|
function getGeomInfo(model, geomId) {
|
|
5175
5320
|
const size = model.geom_size.subarray(geomId * 3, geomId * 3 + 3);
|
|
5176
5321
|
const type = model.geom_type[geomId];
|
|
@@ -5192,10 +5337,10 @@ function geomSignature(model, geomId) {
|
|
|
5192
5337
|
return [type, size, mat, data, rgba].join("|");
|
|
5193
5338
|
}
|
|
5194
5339
|
function firstMesh(object) {
|
|
5195
|
-
if (object instanceof
|
|
5340
|
+
if (object instanceof THREE11.Mesh) return object;
|
|
5196
5341
|
let mesh = null;
|
|
5197
5342
|
object.traverse((child) => {
|
|
5198
|
-
if (!mesh && child instanceof
|
|
5343
|
+
if (!mesh && child instanceof THREE11.Mesh) mesh = child;
|
|
5199
5344
|
});
|
|
5200
5345
|
return mesh;
|
|
5201
5346
|
}
|
|
@@ -5624,12 +5769,12 @@ function useActuators() {
|
|
|
5624
5769
|
return actuators;
|
|
5625
5770
|
}, [status, mjModelRef]);
|
|
5626
5771
|
}
|
|
5627
|
-
var _mat42 = new
|
|
5772
|
+
var _mat42 = new THREE11.Matrix4();
|
|
5628
5773
|
function useSitePosition(siteName) {
|
|
5629
5774
|
const { mjModelRef, mjDataRef, status } = useMujocoContext();
|
|
5630
5775
|
const siteIdRef = useRef(-1);
|
|
5631
|
-
const positionRef = useRef(new
|
|
5632
|
-
const quaternionRef = useRef(new
|
|
5776
|
+
const positionRef = useRef(new THREE11.Vector3());
|
|
5777
|
+
const quaternionRef = useRef(new THREE11.Quaternion());
|
|
5633
5778
|
useEffect(() => {
|
|
5634
5779
|
const model = mjModelRef.current;
|
|
5635
5780
|
if (!model || status !== "ready") {
|
|
@@ -5822,10 +5967,10 @@ function useJointState(name, options = {}) {
|
|
|
5822
5967
|
function useBodyState(name) {
|
|
5823
5968
|
const { mjModelRef, status } = useMujocoContext();
|
|
5824
5969
|
const bodyIdRef = useRef(-1);
|
|
5825
|
-
const position = useRef(new
|
|
5826
|
-
const quaternion = useRef(new
|
|
5827
|
-
const linearVelocity = useRef(new
|
|
5828
|
-
const angularVelocity = useRef(new
|
|
5970
|
+
const position = useRef(new THREE11.Vector3());
|
|
5971
|
+
const quaternion = useRef(new THREE11.Quaternion());
|
|
5972
|
+
const linearVelocity = useRef(new THREE11.Vector3());
|
|
5973
|
+
const angularVelocity = useRef(new THREE11.Vector3());
|
|
5829
5974
|
useEffect(() => {
|
|
5830
5975
|
const model = mjModelRef.current;
|
|
5831
5976
|
if (!model || status !== "ready") return;
|
|
@@ -5851,7 +5996,7 @@ function useBodyState(name) {
|
|
|
5851
5996
|
});
|
|
5852
5997
|
return { position, quaternion, linearVelocity, angularVelocity };
|
|
5853
5998
|
}
|
|
5854
|
-
var _matrix2 = new
|
|
5999
|
+
var _matrix2 = new THREE11.Matrix4();
|
|
5855
6000
|
function quaternionFromMatrixArray(target, values, offset) {
|
|
5856
6001
|
_matrix2.set(
|
|
5857
6002
|
values[offset],
|
|
@@ -5885,8 +6030,8 @@ function useNamedPose(kind, name) {
|
|
|
5885
6030
|
const { mjModelRef, status } = useMujocoContext();
|
|
5886
6031
|
const idRef = useRef(-1);
|
|
5887
6032
|
const foundRef = useRef(false);
|
|
5888
|
-
const positionRef = useRef(new
|
|
5889
|
-
const quaternionRef = useRef(new
|
|
6033
|
+
const positionRef = useRef(new THREE11.Vector3());
|
|
6034
|
+
const quaternionRef = useRef(new THREE11.Quaternion());
|
|
5890
6035
|
useEffect(() => {
|
|
5891
6036
|
const model = mjModelRef.current;
|
|
5892
6037
|
if (!model || status !== "ready") {
|
|
@@ -6229,9 +6374,9 @@ function useKeyboardTeleop(config) {
|
|
|
6229
6374
|
}
|
|
6230
6375
|
var DEFAULT_TRANSLATE_SPEED = 0.25;
|
|
6231
6376
|
var DEFAULT_ROTATE_SPEED = 1;
|
|
6232
|
-
var _translation = new
|
|
6233
|
-
var _axis = new
|
|
6234
|
-
var _quat3 = new
|
|
6377
|
+
var _translation = new THREE11.Vector3();
|
|
6378
|
+
var _axis = new THREE11.Vector3();
|
|
6379
|
+
var _quat3 = new THREE11.Quaternion();
|
|
6235
6380
|
function actionSign(action) {
|
|
6236
6381
|
return action.endsWith("+") ? 1 : -1;
|
|
6237
6382
|
}
|
|
@@ -6416,7 +6561,8 @@ function usePolicy(config) {
|
|
|
6416
6561
|
const shouldInfer = !inFlightRef.current && (!queuedAction || actionQueueRef.current.length <= prefetchThreshold);
|
|
6417
6562
|
if (!shouldInfer) return;
|
|
6418
6563
|
const observation = cfg.onObservation({ model, data });
|
|
6419
|
-
const
|
|
6564
|
+
const queuedActions = actionQueueRef.current.length;
|
|
6565
|
+
const result = cfg.infer ? cfg.infer({ observation, model, data, queuedActions }) : observation;
|
|
6420
6566
|
if (isPromiseLike(result)) {
|
|
6421
6567
|
const epoch = epochRef.current;
|
|
6422
6568
|
inFlightRef.current = true;
|
|
@@ -6447,11 +6593,11 @@ function usePolicy(config) {
|
|
|
6447
6593
|
cfg.queueStrategy ?? "append"
|
|
6448
6594
|
);
|
|
6449
6595
|
} else {
|
|
6450
|
-
const [action, ...
|
|
6596
|
+
const [action, ...queuedActions2] = actions;
|
|
6451
6597
|
if (!action) return;
|
|
6452
6598
|
enqueuePolicyActions(
|
|
6453
6599
|
actionQueueRef.current,
|
|
6454
|
-
|
|
6600
|
+
queuedActions2,
|
|
6455
6601
|
observation,
|
|
6456
6602
|
cfg.queueStrategy ?? "append"
|
|
6457
6603
|
);
|
|
@@ -6594,7 +6740,7 @@ function useRemotePolicy(config) {
|
|
|
6594
6740
|
const remoteEpochRef = useRef(0);
|
|
6595
6741
|
const policy = usePolicy({
|
|
6596
6742
|
...config,
|
|
6597
|
-
infer: async ({ observation, model, data }) => {
|
|
6743
|
+
infer: async ({ observation, model, data, queuedActions }) => {
|
|
6598
6744
|
const cfg = configRef.current;
|
|
6599
6745
|
abortController(abortControllerRef.current, createAbortError("Remote policy request was superseded."));
|
|
6600
6746
|
const controller = new AbortController();
|
|
@@ -6606,6 +6752,7 @@ function useRemotePolicy(config) {
|
|
|
6606
6752
|
observation,
|
|
6607
6753
|
model,
|
|
6608
6754
|
data,
|
|
6755
|
+
queuedActions,
|
|
6609
6756
|
reset: requestIndex === 0,
|
|
6610
6757
|
requestIndex,
|
|
6611
6758
|
signal
|
|
@@ -7573,7 +7720,7 @@ function useSelectionHighlight(bodyId, options = {}) {
|
|
|
7573
7720
|
}
|
|
7574
7721
|
}
|
|
7575
7722
|
prevRef.current = [];
|
|
7576
|
-
const highlightColor = new
|
|
7723
|
+
const highlightColor = new THREE11.Color(color);
|
|
7577
7724
|
for (const mesh of meshes) {
|
|
7578
7725
|
const mat = mesh.material;
|
|
7579
7726
|
if (mat.emissive) {
|
|
@@ -7600,15 +7747,15 @@ function useSelectionHighlight(bodyId, options = {}) {
|
|
|
7600
7747
|
}
|
|
7601
7748
|
function useCameraAnimation() {
|
|
7602
7749
|
const { camera } = useThree();
|
|
7603
|
-
const orbitTargetRef = useRef(new
|
|
7750
|
+
const orbitTargetRef = useRef(new THREE11.Vector3(0, 0, 0));
|
|
7604
7751
|
const cameraAnimRef = useRef({
|
|
7605
7752
|
active: false,
|
|
7606
|
-
startPos: new
|
|
7607
|
-
endPos: new
|
|
7608
|
-
startRot: new
|
|
7609
|
-
endRot: new
|
|
7610
|
-
startTarget: new
|
|
7611
|
-
endTarget: new
|
|
7753
|
+
startPos: new THREE11.Vector3(),
|
|
7754
|
+
endPos: new THREE11.Vector3(),
|
|
7755
|
+
startRot: new THREE11.Quaternion(),
|
|
7756
|
+
endRot: new THREE11.Quaternion(),
|
|
7757
|
+
startTarget: new THREE11.Vector3(),
|
|
7758
|
+
endTarget: new THREE11.Vector3(),
|
|
7612
7759
|
startTime: 0,
|
|
7613
7760
|
duration: 0,
|
|
7614
7761
|
resolve: null
|
|
@@ -7686,6 +7833,12 @@ function useCameraAnimation() {
|
|
|
7686
7833
|
*
|
|
7687
7834
|
* Helpers for resolving dataset camera streams to mounted MuJoCo resources.
|
|
7688
7835
|
*/
|
|
7836
|
+
/**
|
|
7837
|
+
* @license
|
|
7838
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7839
|
+
*
|
|
7840
|
+
* Project detector/image coordinates from a camera view into the rendered MuJoCo scene.
|
|
7841
|
+
*/
|
|
7689
7842
|
/**
|
|
7690
7843
|
* @license
|
|
7691
7844
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -7921,6 +8074,6 @@ function useCameraAnimation() {
|
|
|
7921
8074
|
* useCameraAnimation — composable camera animation hook.
|
|
7922
8075
|
*/
|
|
7923
8076
|
|
|
7924
|
-
export { Body, ContactListener, ContactMarkers, Debug, DragInteraction, FlexRenderer, IkGizmo, InstancedGeomRenderer, MountedCameraFrameSequenceManifestStatus, MountedCameraFrameSequenceReadinessStatus, MountedCameraFrameSourceSuggestionMatch, MujocoCanvas, MujocoPhysics, MujocoProvider, MujocoSimProvider, SceneLights, SplatCollisionProxyPreview, TendonRenderer, TrajectoryPlayer, applyPolicyActionToControls, bodyPositionField, buildObservation, canFetchSplatCollisionProxyXml, captureFrame, captureFrameBlob, capturePolicyCameraFrames, capturePolicyCameraFramesFromMountedStreams, clampPolicyActionValue, createContiguousControlGroup, createController, createControllerHook, createMountedCameraFrameSequenceManifest, createMountedCameraFrameSequencePlan, createMountedCameraFrameSequencePlanFromApi, createMountedCameraFrameSequenceReadiness, createMountedCameraFrameSourceSuggestions, createNamedObservationBuilder, createPolicyCameraFrameCapturePlan, createPolicyCameraFrameCapturePlanFromApi, ctrlField, fetchSplatCollisionProxyXml, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, geomPositionField, getActuatedJoints, getCameraFrameCaptureSourceTarget, getControlMap, getMountedCameraFrameCaptureSource, getName, isMountedCameraFrameCaptureSource, loadScene, parseSplatCollisionProxyGeoms, qposField, qvelField, readNamedObservation, recordMountedCameraFrameSequence, resolveControlGroup, resolveMountedCameraFrameSource, sitePositionField, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyMeshes, useBodyPose, useBodyState, useCameraAnimation, useCameraFrameCapture, useCameraSequenceRecorder, useContactEvents, useContactHistory, useContacts, useControlWriter, useCtrl, useCtrlNoise, useFrameCapture, useGamepad, useGeomPose, useGravityCompensation, useIkController, useJointState, useKeyboardIkTarget, useKeyboardTeleop, useMountedCameraSequenceRecorder, useMujoco, useMujocoWasm, useNamedObservation, useObservation, usePolicy, usePolicyCameraFrames, usePolicyCameraFramesFromMountedStreams, useRemotePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePose, useSitePosition, useSplatCollisionProxyGeoms, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder };
|
|
8077
|
+
export { Body, ContactListener, ContactMarkers, Debug, DragInteraction, FlexRenderer, IkGizmo, InstancedGeomRenderer, MountedCameraFrameSequenceManifestStatus, MountedCameraFrameSequenceReadinessStatus, MountedCameraFrameSourceSuggestionMatch, MujocoCanvas, MujocoPhysics, MujocoProvider, MujocoSimProvider, SceneLights, SplatCollisionProxyPreview, TendonRenderer, TrajectoryPlayer, applyPolicyActionToControls, bodyPositionField, buildObservation, canFetchSplatCollisionProxyXml, captureFrame, captureFrameBlob, capturePolicyCameraFrames, capturePolicyCameraFramesFromMountedStreams, clampPolicyActionValue, createContiguousControlGroup, createController, createControllerHook, createMountedCameraFrameSequenceManifest, createMountedCameraFrameSequencePlan, createMountedCameraFrameSequencePlanFromApi, createMountedCameraFrameSequenceReadiness, createMountedCameraFrameSourceSuggestions, createNamedObservationBuilder, createPolicyCameraFrameCapturePlan, createPolicyCameraFrameCapturePlanFromApi, ctrlField, fetchSplatCollisionProxyXml, findActuatorByName, findBodyByName, findGeomByName, findJointByName, findKeyframeByName, findSensorByName, findSiteByName, findTendonByName, geomPositionField, getActuatedJoints, getCameraFrameCaptureSourceTarget, getControlMap, getMountedCameraFrameCaptureSource, getName, imagePointToNdc, isMountedCameraFrameCaptureSource, loadScene, parseSplatCollisionProxyGeoms, projectImagePointTo3D, qposField, qvelField, readNamedObservation, recordMountedCameraFrameSequence, resolveControlGroup, resolveMountedCameraFrameSource, sitePositionField, useActuators, useAfterPhysicsStep, useBeforePhysicsStep, useBodyMeshes, useBodyPose, useBodyState, useCameraAnimation, useCameraFrameCapture, useCameraSequenceRecorder, useContactEvents, useContactHistory, useContacts, useControlWriter, useCtrl, useCtrlNoise, useFrameCapture, useGamepad, useGeomPose, useGravityCompensation, useIkController, useJointState, useKeyboardIkTarget, useKeyboardTeleop, useMountedCameraSequenceRecorder, useMujoco, useMujocoWasm, useNamedObservation, useObservation, usePolicy, usePolicyCameraFrames, usePolicyCameraFramesFromMountedStreams, useRemotePolicy, useSceneLights, useSelectionHighlight, useSensor, useSensors, useSitePose, useSitePosition, useSplatCollisionProxyGeoms, useTrajectoryPlayer, useTrajectoryRecorder, useVideoRecorder };
|
|
7925
8078
|
//# sourceMappingURL=index.js.map
|
|
7926
8079
|
//# sourceMappingURL=index.js.map
|