filestash/public/assets/pages/viewerpage/application_3d/scene_light.js
Mickael d30c3120b6
feature (plugins): expand and migrate plugin - #803
* chore (dockerfile): cleanup dockerfile

* feature (plugin): extend plugin interface

* chore (docker): setup new Dockerfile

* chore (dockerfile): update dockerfile
2025-01-13 15:41:04 +11:00

38 lines
1.2 KiB
JavaScript

import { settings_get } from "../../../lib/settings.js";
import * as THREE from "../../../../lib/vendor/three/three.module.js";
const LIGHT_COLOR = 0xf5f5f5;
export default function({ scene, box }) {
addLight(
scene,
new THREE.AmbientLight(LIGHT_COLOR),
settings_get("viewerpage_3d_light", 2),
);
// to make things "look nice", a good setup is to get lights positioned
// in a 3D cube with a couple "twist" in term of position & intensity
const l = addLight.bind(this, scene, new THREE.DirectionalLight(LIGHT_COLOR));
l(0.25, [plus(box.max.x*3), 0, 20]); // right
l(0.25, [minus(box.min.x*3), 0, -20]); // left
l(0.35, [0, plus(box.max.y*4), 20]); // top
l(0.35, [0, minus(box.min.y*4), -20]); // bottom
l(0.5, [0, 0, plus(7*box.max.z)]); // front
l(0.2, [0, 0, minus(15*box.min.z)]); // back
}
function addLight(scene, light, intensity, pos = []) {
light = light.clone();
light.intensity = intensity;
light.position.set(...pos);
if (light.type !== "AmbientLight") light.castShadow = true;
scene.add(light);
}
const plus = notZero.bind(null, 1);
const minus = notZero.bind(null, -1);
function notZero(sgn, n) {
if (n === 0) return sgn;
return n;
}