|
@@ -25,24 +25,24 @@
|
|
import { RenderPass } from './jsm/postprocessing/RenderPass.js';
|
|
import { RenderPass } from './jsm/postprocessing/RenderPass.js';
|
|
import { OutlinePass } from './jsm/postprocessing/OutlinePass.js';
|
|
import { OutlinePass } from './jsm/postprocessing/OutlinePass.js';
|
|
|
|
|
|
- var container, stats;
|
|
|
|
|
|
+ let container, stats;
|
|
|
|
|
|
- var scene, renderer, composer, gui;
|
|
|
|
|
|
+ let scene, renderer, composer, gui;
|
|
|
|
|
|
- var currentSceneIndex = 0;
|
|
|
|
|
|
+ let currentSceneIndex = 0;
|
|
|
|
|
|
- var currentTime = 0;
|
|
|
|
|
|
+ let currentTime = 0;
|
|
|
|
|
|
- var sceneCreators = [
|
|
|
|
|
|
+ const sceneCreators = [
|
|
createConesScene,
|
|
createConesScene,
|
|
createPlasmaBallScene,
|
|
createPlasmaBallScene,
|
|
createStormScene
|
|
createStormScene
|
|
];
|
|
];
|
|
|
|
|
|
- var clock = new THREE.Clock();
|
|
|
|
|
|
+ const clock = new THREE.Clock();
|
|
|
|
|
|
- var raycaster = new THREE.Raycaster();
|
|
|
|
- var mouse = new THREE.Vector2();
|
|
|
|
|
|
+ const raycaster = new THREE.Raycaster();
|
|
|
|
+ const mouse = new THREE.Vector2();
|
|
|
|
|
|
init();
|
|
init();
|
|
animate();
|
|
animate();
|
|
@@ -100,7 +100,7 @@
|
|
|
|
|
|
gui = new GUI( { width: 350 } );
|
|
gui = new GUI( { width: 350 } );
|
|
|
|
|
|
- var sceneFolder = gui.addFolder( "Scene" );
|
|
|
|
|
|
+ const sceneFolder = gui.addFolder( "Scene" );
|
|
|
|
|
|
scene.userData.sceneIndex = currentSceneIndex;
|
|
scene.userData.sceneIndex = currentSceneIndex;
|
|
|
|
|
|
@@ -117,7 +117,7 @@
|
|
|
|
|
|
sceneFolder.open();
|
|
sceneFolder.open();
|
|
|
|
|
|
- var graphicsFolder = gui.addFolder( "Graphics" );
|
|
|
|
|
|
+ const graphicsFolder = gui.addFolder( "Graphics" );
|
|
|
|
|
|
graphicsFolder.add( scene.userData, "outlineEnabled" ).name( "Glow enabled" );
|
|
graphicsFolder.add( scene.userData, "outlineEnabled" ).name( "Glow enabled" );
|
|
|
|
|
|
@@ -144,7 +144,7 @@
|
|
|
|
|
|
graphicsFolder.open();
|
|
graphicsFolder.open();
|
|
|
|
|
|
- var rayFolder = gui.addFolder( "Ray parameters" );
|
|
|
|
|
|
+ const rayFolder = gui.addFolder( "Ray parameters" );
|
|
|
|
|
|
rayFolder.add( scene.userData.rayParams, 'straightness', 0, 1 ).name( 'Straightness' );
|
|
rayFolder.add( scene.userData.rayParams, 'straightness', 0, 1 ).name( 'Straightness' );
|
|
rayFolder.add( scene.userData.rayParams, 'roughness', 0, 1 ).name( 'Roughness' );
|
|
rayFolder.add( scene.userData.rayParams, 'roughness', 0, 1 ).name( 'Roughness' );
|
|
@@ -160,7 +160,7 @@
|
|
|
|
|
|
// Parameters which need to recreate the ray after modification
|
|
// Parameters which need to recreate the ray after modification
|
|
|
|
|
|
- var raySlowFolder = gui.addFolder( "Ray parameters (slow)" );
|
|
|
|
|
|
+ const raySlowFolder = gui.addFolder( "Ray parameters (slow)" );
|
|
|
|
|
|
raySlowFolder.add( scene.userData.rayParams, 'ramification', 0, 15 ).step( 1 ).name( 'Ramification' ).onFinishChange( function () {
|
|
raySlowFolder.add( scene.userData.rayParams, 'ramification', 0, 15 ).step( 1 ).name( 'Ramification' ).onFinishChange( function () {
|
|
|
|
|
|
@@ -215,7 +215,7 @@
|
|
|
|
|
|
function createOutline( scene, objectsArray, visibleColor ) {
|
|
function createOutline( scene, objectsArray, visibleColor ) {
|
|
|
|
|
|
- var outlinePass = new OutlinePass( new THREE.Vector2( window.innerWidth, window.innerHeight ), scene, scene.userData.camera, objectsArray );
|
|
|
|
|
|
+ const outlinePass = new OutlinePass( new THREE.Vector2( window.innerWidth, window.innerHeight ), scene, scene.userData.camera, objectsArray );
|
|
outlinePass.edgeStrength = 2.5;
|
|
outlinePass.edgeStrength = 2.5;
|
|
outlinePass.edgeGlow = 0.7;
|
|
outlinePass.edgeGlow = 0.7;
|
|
outlinePass.edgeThickness = 2.8;
|
|
outlinePass.edgeThickness = 2.8;
|
|
@@ -233,7 +233,7 @@
|
|
|
|
|
|
function createConesScene() {
|
|
function createConesScene() {
|
|
|
|
|
|
- var scene = new THREE.Scene();
|
|
|
|
|
|
+ const scene = new THREE.Scene();
|
|
scene.background = new THREE.Color( 0x050505 );
|
|
scene.background = new THREE.Color( 0x050505 );
|
|
|
|
|
|
scene.userData.canGoBackwardsInTime = true;
|
|
scene.userData.canGoBackwardsInTime = true;
|
|
@@ -245,32 +245,32 @@
|
|
scene.userData.lightningColor = new THREE.Color( 0xB0FFFF );
|
|
scene.userData.lightningColor = new THREE.Color( 0xB0FFFF );
|
|
scene.userData.outlineColor = new THREE.Color( 0x00FFFF );
|
|
scene.userData.outlineColor = new THREE.Color( 0x00FFFF );
|
|
|
|
|
|
- var posLight = new THREE.PointLight( 0x00ffff, 1, 5000, 2 );
|
|
|
|
|
|
+ const posLight = new THREE.PointLight( 0x00ffff, 1, 5000, 2 );
|
|
scene.add( posLight );
|
|
scene.add( posLight );
|
|
|
|
|
|
// Ground
|
|
// Ground
|
|
|
|
|
|
- var ground = new THREE.Mesh( new THREE.PlaneBufferGeometry( 200000, 200000 ), new THREE.MeshPhongMaterial( { color: 0xC0C0C0, shininess: 0 } ) );
|
|
|
|
|
|
+ const ground = new THREE.Mesh( new THREE.PlaneBufferGeometry( 200000, 200000 ), new THREE.MeshPhongMaterial( { color: 0xC0C0C0, shininess: 0 } ) );
|
|
ground.rotation.x = - Math.PI * 0.5;
|
|
ground.rotation.x = - Math.PI * 0.5;
|
|
scene.add( ground );
|
|
scene.add( ground );
|
|
|
|
|
|
// Cones
|
|
// Cones
|
|
|
|
|
|
- var conesDistance = 1000;
|
|
|
|
- var coneHeight = 200;
|
|
|
|
- var coneHeightHalf = coneHeight * 0.5;
|
|
|
|
|
|
+ const conesDistance = 1000;
|
|
|
|
+ const coneHeight = 200;
|
|
|
|
+ const coneHeightHalf = coneHeight * 0.5;
|
|
|
|
|
|
posLight.position.set( 0, ( conesDistance + coneHeight ) * 0.5, 0 );
|
|
posLight.position.set( 0, ( conesDistance + coneHeight ) * 0.5, 0 );
|
|
posLight.color = scene.userData.outlineColor;
|
|
posLight.color = scene.userData.outlineColor;
|
|
|
|
|
|
scene.userData.camera.position.set( 5 * coneHeight, 4 * coneHeight, 18 * coneHeight );
|
|
scene.userData.camera.position.set( 5 * coneHeight, 4 * coneHeight, 18 * coneHeight );
|
|
|
|
|
|
- var coneMesh1 = new THREE.Mesh( new THREE.ConeBufferGeometry( coneHeight, coneHeight, 30, 1, false ), new THREE.MeshPhongMaterial( { color: 0xFFFF00, emissive: 0x1F1F00 } ) );
|
|
|
|
|
|
+ const coneMesh1 = new THREE.Mesh( new THREE.ConeBufferGeometry( coneHeight, coneHeight, 30, 1, false ), new THREE.MeshPhongMaterial( { color: 0xFFFF00, emissive: 0x1F1F00 } ) );
|
|
coneMesh1.rotation.x = Math.PI;
|
|
coneMesh1.rotation.x = Math.PI;
|
|
coneMesh1.position.y = conesDistance + coneHeight;
|
|
coneMesh1.position.y = conesDistance + coneHeight;
|
|
scene.add( coneMesh1 );
|
|
scene.add( coneMesh1 );
|
|
|
|
|
|
- var coneMesh2 = new THREE.Mesh( coneMesh1.geometry.clone(), new THREE.MeshPhongMaterial( { color: 0xFF2020, emissive: 0x1F0202 } ) );
|
|
|
|
|
|
+ const coneMesh2 = new THREE.Mesh( coneMesh1.geometry.clone(), new THREE.MeshPhongMaterial( { color: 0xFF2020, emissive: 0x1F0202 } ) );
|
|
coneMesh2.position.y = coneHeightHalf;
|
|
coneMesh2.position.y = coneHeightHalf;
|
|
scene.add( coneMesh2 );
|
|
scene.add( coneMesh2 );
|
|
|
|
|
|
@@ -303,9 +303,9 @@
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
- var lightningStrike;
|
|
|
|
- var lightningStrikeMesh;
|
|
|
|
- var outlineMeshArray = [];
|
|
|
|
|
|
+ let lightningStrike;
|
|
|
|
+ let lightningStrikeMesh;
|
|
|
|
+ const outlineMeshArray = [];
|
|
|
|
|
|
scene.userData.recreateRay = function () {
|
|
scene.userData.recreateRay = function () {
|
|
|
|
|
|
@@ -335,7 +335,7 @@
|
|
|
|
|
|
// Controls
|
|
// Controls
|
|
|
|
|
|
- var controls = new OrbitControls( scene.userData.camera, renderer.domElement );
|
|
|
|
|
|
+ const controls = new OrbitControls( scene.userData.camera, renderer.domElement );
|
|
controls.target.y = ( conesDistance + coneHeight ) * 0.5;
|
|
controls.target.y = ( conesDistance + coneHeight ) * 0.5;
|
|
controls.enableDamping = true;
|
|
controls.enableDamping = true;
|
|
controls.dampingFactor = 0.05;
|
|
controls.dampingFactor = 0.05;
|
|
@@ -377,27 +377,27 @@
|
|
|
|
|
|
function createPlasmaBallScene() {
|
|
function createPlasmaBallScene() {
|
|
|
|
|
|
- var scene = new THREE.Scene();
|
|
|
|
|
|
+ const scene = new THREE.Scene();
|
|
|
|
|
|
scene.userData.canGoBackwardsInTime = true;
|
|
scene.userData.canGoBackwardsInTime = true;
|
|
|
|
|
|
scene.userData.camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 100, 50000 );
|
|
scene.userData.camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 100, 50000 );
|
|
|
|
|
|
- var ballScene = new THREE.Scene();
|
|
|
|
|
|
+ const ballScene = new THREE.Scene();
|
|
ballScene.background = new THREE.Color( 0x454545 );
|
|
ballScene.background = new THREE.Color( 0x454545 );
|
|
|
|
|
|
// Lights
|
|
// Lights
|
|
|
|
|
|
- var ambientLight = new THREE.AmbientLight( 0x444444 );
|
|
|
|
|
|
+ const ambientLight = new THREE.AmbientLight( 0x444444 );
|
|
ballScene.add( ambientLight );
|
|
ballScene.add( ambientLight );
|
|
scene.add( ambientLight );
|
|
scene.add( ambientLight );
|
|
|
|
|
|
- var light1 = new THREE.DirectionalLight( 0xffffff, 0.5 );
|
|
|
|
|
|
+ const light1 = new THREE.DirectionalLight( 0xffffff, 0.5 );
|
|
light1.position.set( 1, 1, 1 );
|
|
light1.position.set( 1, 1, 1 );
|
|
ballScene.add( light1 );
|
|
ballScene.add( light1 );
|
|
scene.add( light1 );
|
|
scene.add( light1 );
|
|
|
|
|
|
- var light2 = new THREE.DirectionalLight( 0xffffff, 1.5 );
|
|
|
|
|
|
+ const light2 = new THREE.DirectionalLight( 0xffffff, 1.5 );
|
|
light2.position.set( - 0.5, 1, 0.2 );
|
|
light2.position.set( - 0.5, 1, 0.2 );
|
|
ballScene.add( light2 );
|
|
ballScene.add( light2 );
|
|
scene.add( light2 );
|
|
scene.add( light2 );
|
|
@@ -409,16 +409,16 @@
|
|
|
|
|
|
scene.userData.lightningMaterial = new THREE.MeshBasicMaterial( { color: scene.userData.lightningColor, side: THREE.DoubleSide } );
|
|
scene.userData.lightningMaterial = new THREE.MeshBasicMaterial( { color: scene.userData.lightningColor, side: THREE.DoubleSide } );
|
|
|
|
|
|
- var r = "textures/cube/Bridge2/";
|
|
|
|
- var urls = [ r + "posx.jpg", r + "negx.jpg",
|
|
|
|
|
|
+ const r = "textures/cube/Bridge2/";
|
|
|
|
+ const urls = [ r + "posx.jpg", r + "negx.jpg",
|
|
r + "posy.jpg", r + "negy.jpg",
|
|
r + "posy.jpg", r + "negy.jpg",
|
|
r + "posz.jpg", r + "negz.jpg" ];
|
|
r + "posz.jpg", r + "negz.jpg" ];
|
|
|
|
|
|
- var textureCube = new THREE.CubeTextureLoader().load( urls );
|
|
|
|
|
|
+ const textureCube = new THREE.CubeTextureLoader().load( urls );
|
|
textureCube.mapping = THREE.CubeReflectionMapping;
|
|
textureCube.mapping = THREE.CubeReflectionMapping;
|
|
textureCube.encoding = THREE.sRGBEncoding;
|
|
textureCube.encoding = THREE.sRGBEncoding;
|
|
|
|
|
|
- var sphereMaterial = new THREE.MeshPhysicalMaterial( {
|
|
|
|
|
|
+ const sphereMaterial = new THREE.MeshPhysicalMaterial( {
|
|
transparent: true,
|
|
transparent: true,
|
|
transmission: .96,
|
|
transmission: .96,
|
|
depthWrite: false,
|
|
depthWrite: false,
|
|
@@ -428,37 +428,37 @@
|
|
envMap: textureCube
|
|
envMap: textureCube
|
|
} );
|
|
} );
|
|
|
|
|
|
- var sphereHeight = 300;
|
|
|
|
- var sphereRadius = 200;
|
|
|
|
|
|
+ const sphereHeight = 300;
|
|
|
|
+ const sphereRadius = 200;
|
|
|
|
|
|
scene.userData.camera.position.set( 5 * sphereRadius, 2 * sphereHeight, 6 * sphereRadius );
|
|
scene.userData.camera.position.set( 5 * sphereRadius, 2 * sphereHeight, 6 * sphereRadius );
|
|
|
|
|
|
- var sphereMesh = new THREE.Mesh( new THREE.SphereBufferGeometry( sphereRadius, 80, 40 ), sphereMaterial );
|
|
|
|
|
|
+ const sphereMesh = new THREE.Mesh( new THREE.SphereBufferGeometry( sphereRadius, 80, 40 ), sphereMaterial );
|
|
sphereMesh.position.set( 0, sphereHeight, 0 );
|
|
sphereMesh.position.set( 0, sphereHeight, 0 );
|
|
ballScene.add( sphereMesh );
|
|
ballScene.add( sphereMesh );
|
|
|
|
|
|
- var sphere = new THREE.Sphere( sphereMesh.position, sphereRadius );
|
|
|
|
|
|
+ const sphere = new THREE.Sphere( sphereMesh.position, sphereRadius );
|
|
|
|
|
|
- var spherePlasma = new THREE.Mesh( new THREE.SphereBufferGeometry( sphereRadius * 0.05, 24, 12 ), scene.userData.lightningMaterial );
|
|
|
|
|
|
+ const spherePlasma = new THREE.Mesh( new THREE.SphereBufferGeometry( sphereRadius * 0.05, 24, 12 ), scene.userData.lightningMaterial );
|
|
spherePlasma.position.copy( sphereMesh.position );
|
|
spherePlasma.position.copy( sphereMesh.position );
|
|
spherePlasma.scale.y = 0.6;
|
|
spherePlasma.scale.y = 0.6;
|
|
scene.add( spherePlasma );
|
|
scene.add( spherePlasma );
|
|
|
|
|
|
- var post = new THREE.Mesh(
|
|
|
|
|
|
+ const post = new THREE.Mesh(
|
|
new THREE.CylinderBufferGeometry( sphereRadius * 0.06, sphereRadius * 0.06, sphereHeight, 6, 1, true ),
|
|
new THREE.CylinderBufferGeometry( sphereRadius * 0.06, sphereRadius * 0.06, sphereHeight, 6, 1, true ),
|
|
new THREE.MeshLambertMaterial( { color: 0x020202 } )
|
|
new THREE.MeshLambertMaterial( { color: 0x020202 } )
|
|
);
|
|
);
|
|
post.position.y = sphereHeight * 0.5 - sphereRadius * 0.05 * 1.2;
|
|
post.position.y = sphereHeight * 0.5 - sphereRadius * 0.05 * 1.2;
|
|
scene.add( post );
|
|
scene.add( post );
|
|
|
|
|
|
- var box = new THREE.Mesh( new THREE.BoxBufferGeometry( sphereHeight * 0.5, sphereHeight * 0.1, sphereHeight * 0.5 ), post.material );
|
|
|
|
|
|
+ const box = new THREE.Mesh( new THREE.BoxBufferGeometry( sphereHeight * 0.5, sphereHeight * 0.1, sphereHeight * 0.5 ), post.material );
|
|
box.position.y = sphereHeight * 0.05 * 0.5;
|
|
box.position.y = sphereHeight * 0.05 * 0.5;
|
|
scene.add( box );
|
|
scene.add( box );
|
|
|
|
|
|
- var rayDirection = new THREE.Vector3();
|
|
|
|
- var rayLength = 0;
|
|
|
|
- var vec1 = new THREE.Vector3();
|
|
|
|
- var vec2 = new THREE.Vector3();
|
|
|
|
|
|
+ const rayDirection = new THREE.Vector3();
|
|
|
|
+ let rayLength = 0;
|
|
|
|
+ const vec1 = new THREE.Vector3();
|
|
|
|
+ const vec2 = new THREE.Vector3();
|
|
|
|
|
|
scene.userData.rayParams = {
|
|
scene.userData.rayParams = {
|
|
|
|
|
|
@@ -489,11 +489,13 @@
|
|
|
|
|
|
vec1.subVectors( childSubray.pos1, lightningStrike.rayParameters.sourceOffset );
|
|
vec1.subVectors( childSubray.pos1, lightningStrike.rayParameters.sourceOffset );
|
|
vec2.set( 0, 0, 0 );
|
|
vec2.set( 0, 0, 0 );
|
|
|
|
+
|
|
if ( lightningStrike.randomGenerator.random() < 0.7 ) {
|
|
if ( lightningStrike.randomGenerator.random() < 0.7 ) {
|
|
|
|
|
|
vec2.copy( rayDirection ).multiplyScalar( rayLength * 1.0865 );
|
|
vec2.copy( rayDirection ).multiplyScalar( rayLength * 1.0865 );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
vec1.add( vec2 ).setLength( rayLength );
|
|
vec1.add( vec2 ).setLength( rayLength );
|
|
childSubray.pos1.addVectors( vec1, lightningStrike.rayParameters.sourceOffset );
|
|
childSubray.pos1.addVectors( vec1, lightningStrike.rayParameters.sourceOffset );
|
|
|
|
|
|
@@ -501,9 +503,9 @@
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
- var lightningStrike;
|
|
|
|
- var lightningStrikeMesh;
|
|
|
|
- var outlineMeshArray = [];
|
|
|
|
|
|
+ let lightningStrike;
|
|
|
|
+ let lightningStrikeMesh;
|
|
|
|
+ const outlineMeshArray = [];
|
|
|
|
|
|
scene.userData.recreateRay = function () {
|
|
scene.userData.recreateRay = function () {
|
|
|
|
|
|
@@ -532,11 +534,11 @@
|
|
|
|
|
|
composer.addPass( new RenderPass( ballScene, scene.userData.camera ) );
|
|
composer.addPass( new RenderPass( ballScene, scene.userData.camera ) );
|
|
|
|
|
|
- var rayPass = new RenderPass( scene, scene.userData.camera );
|
|
|
|
|
|
+ const rayPass = new RenderPass( scene, scene.userData.camera );
|
|
rayPass.clear = false;
|
|
rayPass.clear = false;
|
|
composer.addPass( rayPass );
|
|
composer.addPass( rayPass );
|
|
|
|
|
|
- var outlinePass = createOutline( scene, outlineMeshArray, scene.userData.outlineColor );
|
|
|
|
|
|
+ const outlinePass = createOutline( scene, outlineMeshArray, scene.userData.outlineColor );
|
|
|
|
|
|
scene.userData.render = function ( time ) {
|
|
scene.userData.render = function ( time ) {
|
|
|
|
|
|
@@ -556,7 +558,7 @@
|
|
|
|
|
|
// Controls
|
|
// Controls
|
|
|
|
|
|
- var controls = new OrbitControls( scene.userData.camera, renderer.domElement );
|
|
|
|
|
|
+ const controls = new OrbitControls( scene.userData.camera, renderer.domElement );
|
|
controls.target.copy( sphereMesh.position );
|
|
controls.target.copy( sphereMesh.position );
|
|
controls.enableDamping = true;
|
|
controls.enableDamping = true;
|
|
controls.dampingFactor = 0.05;
|
|
controls.dampingFactor = 0.05;
|
|
@@ -577,13 +579,13 @@
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var intersection = new THREE.Vector3();
|
|
|
|
|
|
+ const intersection = new THREE.Vector3();
|
|
|
|
|
|
function checkIntersection() {
|
|
function checkIntersection() {
|
|
|
|
|
|
raycaster.setFromCamera( mouse, scene.userData.camera );
|
|
raycaster.setFromCamera( mouse, scene.userData.camera );
|
|
|
|
|
|
- var result = raycaster.ray.intersectSphere( sphere, intersection );
|
|
|
|
|
|
+ const result = raycaster.ray.intersectSphere( sphere, intersection );
|
|
|
|
|
|
if ( result !== null ) {
|
|
if ( result !== null ) {
|
|
|
|
|
|
@@ -601,7 +603,7 @@
|
|
|
|
|
|
function createStormScene() {
|
|
function createStormScene() {
|
|
|
|
|
|
- var scene = new THREE.Scene();
|
|
|
|
|
|
+ const scene = new THREE.Scene();
|
|
scene.background = new THREE.Color( 0x050505 );
|
|
scene.background = new THREE.Color( 0x050505 );
|
|
|
|
|
|
scene.userData.canGoBackwardsInTime = false;
|
|
scene.userData.canGoBackwardsInTime = false;
|
|
@@ -612,21 +614,21 @@
|
|
|
|
|
|
scene.add( new THREE.AmbientLight( 0x444444 ) );
|
|
scene.add( new THREE.AmbientLight( 0x444444 ) );
|
|
|
|
|
|
- var light1 = new THREE.DirectionalLight( 0xffffff, 0.5 );
|
|
|
|
|
|
+ const light1 = new THREE.DirectionalLight( 0xffffff, 0.5 );
|
|
light1.position.set( 1, 1, 1 );
|
|
light1.position.set( 1, 1, 1 );
|
|
scene.add( light1 );
|
|
scene.add( light1 );
|
|
|
|
|
|
- var posLight = new THREE.PointLight( 0x00ffff );
|
|
|
|
|
|
+ const posLight = new THREE.PointLight( 0x00ffff );
|
|
posLight.position.set( 0, 100, 0 );
|
|
posLight.position.set( 0, 100, 0 );
|
|
scene.add( posLight );
|
|
scene.add( posLight );
|
|
|
|
|
|
// Ground
|
|
// Ground
|
|
|
|
|
|
- var GROUND_SIZE = 1000;
|
|
|
|
|
|
+ const GROUND_SIZE = 1000;
|
|
|
|
|
|
scene.userData.camera.position.set( 0, 0.2, 1.6 ).multiplyScalar( GROUND_SIZE * 0.5 );
|
|
scene.userData.camera.position.set( 0, 0.2, 1.6 ).multiplyScalar( GROUND_SIZE * 0.5 );
|
|
|
|
|
|
- var ground = new THREE.Mesh( new THREE.PlaneBufferGeometry( GROUND_SIZE, GROUND_SIZE ), new THREE.MeshLambertMaterial( { color: 0x072302 } ) );
|
|
|
|
|
|
+ const ground = new THREE.Mesh( new THREE.PlaneBufferGeometry( GROUND_SIZE, GROUND_SIZE ), new THREE.MeshLambertMaterial( { color: 0x072302 } ) );
|
|
ground.rotation.x = - Math.PI * 0.5;
|
|
ground.rotation.x = - Math.PI * 0.5;
|
|
scene.add( ground );
|
|
scene.add( ground );
|
|
|
|
|
|
@@ -637,10 +639,10 @@
|
|
|
|
|
|
scene.userData.lightningMaterial = new THREE.MeshBasicMaterial( { color: scene.userData.lightningColor } );
|
|
scene.userData.lightningMaterial = new THREE.MeshBasicMaterial( { color: scene.userData.lightningColor } );
|
|
|
|
|
|
- var rayDirection = new THREE.Vector3( 0, - 1, 0 );
|
|
|
|
- var rayLength = 0;
|
|
|
|
- var vec1 = new THREE.Vector3();
|
|
|
|
- var vec2 = new THREE.Vector3();
|
|
|
|
|
|
+ const rayDirection = new THREE.Vector3( 0, - 1, 0 );
|
|
|
|
+ let rayLength = 0;
|
|
|
|
+ const vec1 = new THREE.Vector3();
|
|
|
|
+ const vec2 = new THREE.Vector3();
|
|
|
|
|
|
scene.userData.rayParams = {
|
|
scene.userData.rayParams = {
|
|
|
|
|
|
@@ -670,10 +672,10 @@
|
|
|
|
|
|
rayLength = lightningStrike.rayParameters.sourceOffset.y;
|
|
rayLength = lightningStrike.rayParameters.sourceOffset.y;
|
|
vec1.subVectors( childSubray.pos1, lightningStrike.rayParameters.sourceOffset );
|
|
vec1.subVectors( childSubray.pos1, lightningStrike.rayParameters.sourceOffset );
|
|
- var proj = rayDirection.dot( vec1 );
|
|
|
|
|
|
+ const proj = rayDirection.dot( vec1 );
|
|
vec2.copy( rayDirection ).multiplyScalar( proj );
|
|
vec2.copy( rayDirection ).multiplyScalar( proj );
|
|
vec1.sub( vec2 );
|
|
vec1.sub( vec2 );
|
|
- var scale = proj / rayLength > 0.5 ? rayLength / proj : 1;
|
|
|
|
|
|
+ const scale = proj / rayLength > 0.5 ? rayLength / proj : 1;
|
|
vec2.multiplyScalar( scale );
|
|
vec2.multiplyScalar( scale );
|
|
vec1.add( vec2 );
|
|
vec1.add( vec2 );
|
|
childSubray.pos1.addVectors( vec1, lightningStrike.rayParameters.sourceOffset );
|
|
childSubray.pos1.addVectors( vec1, lightningStrike.rayParameters.sourceOffset );
|
|
@@ -683,10 +685,10 @@
|
|
};
|
|
};
|
|
|
|
|
|
// Black star mark
|
|
// Black star mark
|
|
- var starVertices = [];
|
|
|
|
- var prevPoint = new THREE.Vector3( 0, 0, 1 );
|
|
|
|
- var currPoint = new THREE.Vector3();
|
|
|
|
- for ( var i = 1; i <= 16; i ++ ) {
|
|
|
|
|
|
+ const starVertices = [];
|
|
|
|
+ const prevPoint = new THREE.Vector3( 0, 0, 1 );
|
|
|
|
+ const currPoint = new THREE.Vector3();
|
|
|
|
+ for ( let i = 1; i <= 16; i ++ ) {
|
|
|
|
|
|
currPoint.set( Math.sin( 2 * Math.PI * i / 16 ), 0, Math.cos( 2 * Math.PI * i / 16 ) );
|
|
currPoint.set( Math.sin( 2 * Math.PI * i / 16 ), 0, Math.cos( 2 * Math.PI * i / 16 ) );
|
|
|
|
|
|
@@ -704,14 +706,14 @@
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var starGeometry = new THREE.BufferGeometry();
|
|
|
|
|
|
+ const starGeometry = new THREE.BufferGeometry();
|
|
starGeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( starVertices, 3 ) );
|
|
starGeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( starVertices, 3 ) );
|
|
- var starMesh = new THREE.Mesh( starGeometry, new THREE.MeshBasicMaterial( { color: 0x020900 } ) );
|
|
|
|
|
|
+ const starMesh = new THREE.Mesh( starGeometry, new THREE.MeshBasicMaterial( { color: 0x020900 } ) );
|
|
starMesh.scale.multiplyScalar( 6 );
|
|
starMesh.scale.multiplyScalar( 6 );
|
|
|
|
|
|
//
|
|
//
|
|
|
|
|
|
- var storm = new LightningStorm( {
|
|
|
|
|
|
+ const storm = new LightningStorm( {
|
|
|
|
|
|
size: GROUND_SIZE,
|
|
size: GROUND_SIZE,
|
|
minHeight: 90,
|
|
minHeight: 90,
|
|
@@ -726,7 +728,7 @@
|
|
onLightningDown: function ( lightning ) {
|
|
onLightningDown: function ( lightning ) {
|
|
|
|
|
|
// Add black star mark at ray strike
|
|
// Add black star mark at ray strike
|
|
- var star1 = starMesh.clone();
|
|
|
|
|
|
+ const star1 = starMesh.clone();
|
|
star1.position.copy( lightning.rayParameters.destOffset );
|
|
star1.position.copy( lightning.rayParameters.destOffset );
|
|
star1.position.y = 0.05;
|
|
star1.position.y = 0.05;
|
|
star1.rotation.y = 2 * Math.PI * Math.random();
|
|
star1.rotation.y = 2 * Math.PI * Math.random();
|
|
@@ -746,7 +748,7 @@
|
|
|
|
|
|
// Controls
|
|
// Controls
|
|
|
|
|
|
- var controls = new OrbitControls( scene.userData.camera, renderer.domElement );
|
|
|
|
|
|
+ const controls = new OrbitControls( scene.userData.camera, renderer.domElement );
|
|
controls.target.y = GROUND_SIZE * 0.05;
|
|
controls.target.y = GROUND_SIZE * 0.05;
|
|
controls.enableDamping = true;
|
|
controls.enableDamping = true;
|
|
controls.dampingFactor = 0.05;
|
|
controls.dampingFactor = 0.05;
|