mujoco-react 8.9.2 → 8.10.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 +44 -0
- package/dist/chunk-KGFRKPLS.js +186 -0
- package/dist/chunk-KGFRKPLS.js.map +1 -0
- package/dist/index.d.ts +37 -735
- package/dist/index.js +41 -19
- package/dist/index.js.map +1 -1
- package/dist/spark.d.ts +32 -0
- package/dist/spark.js +150 -0
- package/dist/spark.js.map +1 -0
- package/dist/types-FFW7ykBu.d.ts +817 -0
- package/dist/vite.d.ts +9 -0
- package/dist/vite.js +4 -0
- package/dist/vite.js.map +1 -1
- package/package.json +15 -2
- package/src/components/VisualScenario.tsx +229 -0
- package/src/hooks/useSceneLights.ts +49 -18
- package/src/index.ts +23 -0
- package/src/spark.tsx +202 -0
- package/src/types.ts +92 -1
- package/src/vite.ts +8 -0
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { ScenarioLighting, SplatEnvironment, createSparkSplatViewerUrl, createSplatEnvironmentUserData, getScenarioBackground, getScenarioCameraPosition, useSplatEnvironment } from './chunk-KGFRKPLS.js';
|
|
1
2
|
import loadMujoco from '@mujoco/mujoco';
|
|
2
3
|
import defaultMujocoWasmUrl from '@mujoco/mujoco/mujoco.wasm?url';
|
|
3
4
|
import { createContext, forwardRef, useEffect, useContext, useState, useRef, useCallback, useMemo, useLayoutEffect } from 'react';
|
|
@@ -6,7 +7,6 @@ import { Canvas, useThree, useFrame } from '@react-three/fiber';
|
|
|
6
7
|
import * as THREE11 from 'three';
|
|
7
8
|
import { PivotControls } from '@react-three/drei';
|
|
8
9
|
|
|
9
|
-
// src/core/MujocoProvider.tsx
|
|
10
10
|
var MujocoContext = createContext({
|
|
11
11
|
mujoco: null,
|
|
12
12
|
status: "loading",
|
|
@@ -3242,24 +3242,35 @@ function useSceneLights(intensity = 1) {
|
|
|
3242
3242
|
targetsRef.current = [];
|
|
3243
3243
|
const nlight = model.nlight ?? 0;
|
|
3244
3244
|
if (nlight === 0) return;
|
|
3245
|
+
const lightActive = getModelArray(model, "light_active");
|
|
3246
|
+
const lightTypeArray = getModelArray(model, "light_type");
|
|
3247
|
+
const lightCastShadow = getModelArray(model, "light_castshadow");
|
|
3248
|
+
const lightIntensity = getModelArray(model, "light_intensity");
|
|
3249
|
+
const lightDiffuse = getModelArray(model, "light_diffuse");
|
|
3250
|
+
const lightPos = getModelArray(model, "light_pos");
|
|
3251
|
+
const lightDir = getModelArray(model, "light_dir");
|
|
3252
|
+
const lightCutoff = getModelArray(model, "light_cutoff");
|
|
3253
|
+
const lightExponent = getModelArray(model, "light_exponent");
|
|
3254
|
+
const lightAttenuation = getModelArray(model, "light_attenuation");
|
|
3255
|
+
if (!lightPos || !lightDir) return;
|
|
3245
3256
|
for (let i = 0; i < nlight; i++) {
|
|
3246
|
-
const active =
|
|
3257
|
+
const active = lightActive ? lightActive[i] : 1;
|
|
3247
3258
|
if (!active) continue;
|
|
3248
|
-
const lightType =
|
|
3259
|
+
const lightType = lightTypeArray ? lightTypeArray[i] : 0;
|
|
3249
3260
|
const isDirectional = lightType === 0;
|
|
3250
|
-
const castShadow =
|
|
3251
|
-
const mjIntensity =
|
|
3261
|
+
const castShadow = lightCastShadow ? lightCastShadow[i] !== 0 : false;
|
|
3262
|
+
const mjIntensity = lightIntensity ? lightIntensity[i] : 1;
|
|
3252
3263
|
const finalIntensity = intensity * mjIntensity;
|
|
3253
|
-
const dr =
|
|
3254
|
-
const dg =
|
|
3255
|
-
const db =
|
|
3264
|
+
const dr = lightDiffuse ? lightDiffuse[3 * i] : 1;
|
|
3265
|
+
const dg = lightDiffuse ? lightDiffuse[3 * i + 1] : 1;
|
|
3266
|
+
const db = lightDiffuse ? lightDiffuse[3 * i + 2] : 1;
|
|
3256
3267
|
const color = new THREE11.Color(dr, dg, db);
|
|
3257
|
-
const px =
|
|
3258
|
-
const py =
|
|
3259
|
-
const pz =
|
|
3260
|
-
const dx =
|
|
3261
|
-
const dy =
|
|
3262
|
-
const dz =
|
|
3268
|
+
const px = lightPos[3 * i];
|
|
3269
|
+
const py = lightPos[3 * i + 1];
|
|
3270
|
+
const pz = lightPos[3 * i + 2];
|
|
3271
|
+
const dx = lightDir[3 * i];
|
|
3272
|
+
const dy = lightDir[3 * i + 1];
|
|
3273
|
+
const dz = lightDir[3 * i + 2];
|
|
3263
3274
|
if (isDirectional) {
|
|
3264
3275
|
const light = new THREE11.DirectionalLight(color, finalIntensity);
|
|
3265
3276
|
light.position.set(px, py, pz);
|
|
@@ -3281,16 +3292,16 @@ function useSceneLights(intensity = 1) {
|
|
|
3281
3292
|
lightsRef.current.push(light);
|
|
3282
3293
|
targetsRef.current.push(light.target);
|
|
3283
3294
|
} else {
|
|
3284
|
-
const cutoff =
|
|
3285
|
-
const exponent =
|
|
3295
|
+
const cutoff = lightCutoff ? lightCutoff[i] : 45;
|
|
3296
|
+
const exponent = lightExponent ? lightExponent[i] : 10;
|
|
3286
3297
|
const angle = cutoff * Math.PI / 180;
|
|
3287
3298
|
const light = new THREE11.SpotLight(color, finalIntensity, 0, angle, exponent / 128);
|
|
3288
3299
|
light.position.set(px, py, pz);
|
|
3289
3300
|
light.target.position.set(px + dx, py + dy, pz + dz);
|
|
3290
3301
|
light.castShadow = castShadow;
|
|
3291
|
-
if (
|
|
3292
|
-
const att1 =
|
|
3293
|
-
const att2 =
|
|
3302
|
+
if (lightAttenuation) {
|
|
3303
|
+
const att1 = lightAttenuation[3 * i + 1];
|
|
3304
|
+
const att2 = lightAttenuation[3 * i + 2];
|
|
3294
3305
|
light.decay = att2 > 0 ? 2 : att1 > 0 ? 1 : 0;
|
|
3295
3306
|
light.distance = att1 > 0 ? 1 / att1 : 0;
|
|
3296
3307
|
}
|
|
@@ -3315,6 +3326,17 @@ function useSceneLights(intensity = 1) {
|
|
|
3315
3326
|
};
|
|
3316
3327
|
}, [status, mjModelRef, scene, intensity]);
|
|
3317
3328
|
}
|
|
3329
|
+
function getModelArray(model, key) {
|
|
3330
|
+
try {
|
|
3331
|
+
const value = model[key];
|
|
3332
|
+
return isArrayLikeNumber(value) ? value : void 0;
|
|
3333
|
+
} catch {
|
|
3334
|
+
return void 0;
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
function isArrayLikeNumber(value) {
|
|
3338
|
+
return typeof value === "object" && value !== null && "length" in value && typeof value.length === "number";
|
|
3339
|
+
}
|
|
3318
3340
|
|
|
3319
3341
|
// src/components/SceneLights.tsx
|
|
3320
3342
|
function SceneLights({ intensity = 1 }) {
|