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);
|
|
|
|
};
|
|
|
|
|
2020-04-25 10:24:42 +02:00
|
|
|
const ViewerScene = ({ backgroundColor, showFog }) => {
|
2018-06-06 08:06:03 +02:00
|
|
|
// New scene
|
2020-04-25 10:24:42 +02:00
|
|
|
const bg = new Color(backgroundColor);
|
2019-03-07 04:37:25 +01:00
|
|
|
const scene = new Scene();
|
2020-04-25 10:24:42 +02:00
|
|
|
// 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
|
2020-04-25 10:24:42 +02:00
|
|
|
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;
|