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

41 lines
1.2 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);
};
const ViewerScene = ({ backgroundColor, showFog }) => {
2018-06-06 08:06:03 +02:00
// New scene
const bg = new Color(backgroundColor);
2019-03-07 04:37:25 +01:00
const scene = new Scene();
// Transparent background
scene.background = bg;
// Add fog
if (showFog) {
scene.fog = new Fog(bg, 1, 54);
}
2018-06-06 08:06:03 +02:00
// Add basic lights
addLights(scene, 0xffffff, bg);
2018-06-06 08:06:03 +02:00
// Return new three scene
return scene;
};
2019-03-07 04:37:25 +01:00
export default ViewerScene;