lbry-desktop/ui/component/viewers/threeViewer/internal/scene.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-03-07 04:37:25 +01:00
import { Color } from 'three-full/sources/math/Color';
import { HemisphereLight } from 'three-full/sources/lights/HemisphereLight';
import { DirectionalLight } from 'three-full/sources/lights/DirectionalLight';
import { Scene } from 'three-full/sources/scenes/Scene';
import { Fog } from 'three-full/sources/scenes/Fog';
2018-06-06 08:06:03 +02:00
const addLights = (scene, color, groundColor) => {
// Light color
2019-03-07 04:37:25 +01:00
const lightColor = new Color(color);
2018-06-06 08:06:03 +02:00
// Main light
2019-03-07 04:37:25 +01:00
const light = new HemisphereLight(lightColor, groundColor, 0.4);
2018-06-06 08:06:03 +02:00
// Shadow light
2019-03-07 04:37:25 +01:00
const shadowLight = new DirectionalLight(lightColor, 0.4);
2018-06-06 08:06:03 +02:00
shadowLight.position.set(100, 50, 100);
// Back light
2019-03-07 04:37:25 +01:00
const backLight = new DirectionalLight(lightColor, 0.6);
2018-06-06 08:06:03 +02:00
backLight.position.set(-100, 200, 50);
// Add lights to scene
scene.add(backLight);
scene.add(light);
scene.add(shadowLight);
};
2019-03-07 04:37:25 +01:00
const ViewerScene = ({ backgroundColor, groundColor, showFog }) => {
2018-06-13 00:40:55 +02:00
// Convert color
2019-03-07 04:37:25 +01:00
const bgColor = new Color(backgroundColor);
2018-06-06 08:06:03 +02:00
// New scene
2019-03-07 04:37:25 +01:00
const scene = new Scene();
2018-06-06 08:06:03 +02:00
// Background color
2018-06-13 00:40:55 +02:00
scene.background = bgColor;
2018-06-06 08:06:03 +02:00
// Fog effect
2019-03-07 04:37:25 +01:00
scene.fog = showFog === true ? new Fog(bgColor, 1, 95) : null;
2018-06-06 08:06:03 +02:00
// Add basic lights
addLights(scene, '#FFFFFF', groundColor);
// Return new three scene
return scene;
};
2019-03-07 04:37:25 +01:00
export default ViewerScene;