|
@@ -85,16 +85,18 @@
|
|
|
|
|
|
import { OrbitControls } from './jsm/controls/OrbitControls.js';
|
|
import { OrbitControls } from './jsm/controls/OrbitControls.js';
|
|
|
|
|
|
- var scenes = [], views, t, canvas, renderer;
|
|
|
|
|
|
+ const scenes = [];
|
|
|
|
+
|
|
|
|
+ let views, t, canvas, renderer;
|
|
|
|
|
|
window.onload = init;
|
|
window.onload = init;
|
|
|
|
|
|
function init() {
|
|
function init() {
|
|
|
|
|
|
- var balls = 20;
|
|
|
|
- var size = .25;
|
|
|
|
|
|
+ const balls = 20;
|
|
|
|
+ const size = .25;
|
|
|
|
|
|
- var colors = [
|
|
|
|
|
|
+ const colors = [
|
|
'rgb(0,127,255)', 'rgb(255,0,0)', 'rgb(0,255,0)', 'rgb(0,255,255)',
|
|
'rgb(0,127,255)', 'rgb(255,0,0)', 'rgb(0,255,0)', 'rgb(0,255,255)',
|
|
'rgb(255,0,255)', 'rgb(255,0,127)', 'rgb(255,255,0)', 'rgb(0,255,127)'
|
|
'rgb(255,0,255)', 'rgb(255,0,127)', 'rgb(255,255,0)', 'rgb(0,255,127)'
|
|
];
|
|
];
|
|
@@ -106,24 +108,24 @@
|
|
|
|
|
|
views = document.querySelectorAll( '.view' );
|
|
views = document.querySelectorAll( '.view' );
|
|
|
|
|
|
- for ( var n = 0; n < views.length; n ++ ) {
|
|
|
|
|
|
+ for ( let n = 0; n < views.length; n ++ ) {
|
|
|
|
|
|
- var scene = new THREE.Scene();
|
|
|
|
|
|
+ const scene = new THREE.Scene();
|
|
scene.background = new THREE.Color( 0xffffff );
|
|
scene.background = new THREE.Color( 0xffffff );
|
|
|
|
|
|
- var geometry0 = new THREE.BufferGeometry();
|
|
|
|
- var geometry1 = new THREE.BufferGeometry();
|
|
|
|
|
|
+ const geometry0 = new THREE.BufferGeometry();
|
|
|
|
+ const geometry1 = new THREE.BufferGeometry();
|
|
|
|
|
|
- var vertices = [];
|
|
|
|
|
|
+ const vertices = [];
|
|
|
|
|
|
if ( views[ n ].lattice ) {
|
|
if ( views[ n ].lattice ) {
|
|
|
|
|
|
- var range = balls / 2;
|
|
|
|
- for ( var i = - range; i <= range; i ++ ) {
|
|
|
|
|
|
+ const range = balls / 2;
|
|
|
|
+ for ( let i = - range; i <= range; i ++ ) {
|
|
|
|
|
|
- for ( var j = - range; j <= range; j ++ ) {
|
|
|
|
|
|
+ for ( let j = - range; j <= range; j ++ ) {
|
|
|
|
|
|
- for ( var k = - range; k <= range; k ++ ) {
|
|
|
|
|
|
+ for ( let k = - range; k <= range; k ++ ) {
|
|
|
|
|
|
vertices.push( i, j, k );
|
|
vertices.push( i, j, k );
|
|
|
|
|
|
@@ -135,11 +137,11 @@
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- for ( var m = 0; m < Math.pow( balls, 3 ); m ++ ) {
|
|
|
|
|
|
+ for ( let m = 0; m < Math.pow( balls, 3 ); m ++ ) {
|
|
|
|
|
|
- var i = balls * Math.random() - balls / 2;
|
|
|
|
- var j = balls * Math.random() - balls / 2;
|
|
|
|
- var k = balls * Math.random() - balls / 2;
|
|
|
|
|
|
+ const i = balls * Math.random() - balls / 2;
|
|
|
|
+ const j = balls * Math.random() - balls / 2;
|
|
|
|
+ const k = balls * Math.random() - balls / 2;
|
|
|
|
|
|
vertices.push( i, j, k );
|
|
vertices.push( i, j, k );
|
|
|
|
|
|
@@ -150,29 +152,29 @@
|
|
geometry0.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
|
|
geometry0.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
|
|
geometry1.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices.slice(), 3 ) );
|
|
geometry1.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices.slice(), 3 ) );
|
|
|
|
|
|
- var index = Math.floor( colors.length * Math.random() );
|
|
|
|
|
|
+ const index = Math.floor( colors.length * Math.random() );
|
|
|
|
|
|
- var canvas2 = document.createElement( 'canvas' );
|
|
|
|
|
|
+ const canvas2 = document.createElement( 'canvas' );
|
|
canvas2.width = 128;
|
|
canvas2.width = 128;
|
|
canvas2.height = 128;
|
|
canvas2.height = 128;
|
|
- var context = canvas2.getContext( '2d' );
|
|
|
|
|
|
+ const context = canvas2.getContext( '2d' );
|
|
context.arc( 64, 64, 64, 0, 2 * Math.PI );
|
|
context.arc( 64, 64, 64, 0, 2 * Math.PI );
|
|
context.fillStyle = colors[ index ];
|
|
context.fillStyle = colors[ index ];
|
|
context.fill();
|
|
context.fill();
|
|
- var texture = new THREE.CanvasTexture( canvas2 );
|
|
|
|
|
|
+ const texture = new THREE.CanvasTexture( canvas2 );
|
|
|
|
|
|
- var material = new THREE.PointsMaterial( { size: size, map: texture, transparent: true, alphaTest: 0.1 } );
|
|
|
|
|
|
+ const material = new THREE.PointsMaterial( { size: size, map: texture, transparent: true, alphaTest: 0.1 } );
|
|
|
|
|
|
scene.add( new THREE.Points( geometry0, material ) );
|
|
scene.add( new THREE.Points( geometry0, material ) );
|
|
|
|
|
|
scene.userData.view = views[ n ];
|
|
scene.userData.view = views[ n ];
|
|
scene.userData.geometry1 = geometry1;
|
|
scene.userData.geometry1 = geometry1;
|
|
|
|
|
|
- var camera = new THREE.PerspectiveCamera( 75, 1, 0.1, 100 );
|
|
|
|
|
|
+ const camera = new THREE.PerspectiveCamera( 75, 1, 0.1, 100 );
|
|
camera.position.set( 0, 0, 1.2 * balls );
|
|
camera.position.set( 0, 0, 1.2 * balls );
|
|
scene.userData.camera = camera;
|
|
scene.userData.camera = camera;
|
|
|
|
|
|
- var controls = new OrbitControls( camera, views[ n ] );
|
|
|
|
|
|
+ const controls = new OrbitControls( camera, views[ n ] );
|
|
scene.userData.controls = controls;
|
|
scene.userData.controls = controls;
|
|
|
|
|
|
scenes.push( scene );
|
|
scenes.push( scene );
|
|
@@ -186,8 +188,8 @@
|
|
|
|
|
|
function updateSize() {
|
|
function updateSize() {
|
|
|
|
|
|
- var width = canvas.clientWidth;
|
|
|
|
- var height = canvas.clientHeight;
|
|
|
|
|
|
+ const width = canvas.clientWidth;
|
|
|
|
+ const height = canvas.clientHeight;
|
|
|
|
|
|
if ( canvas.width !== width || canvas.height != height ) {
|
|
if ( canvas.width !== width || canvas.height != height ) {
|
|
|
|
|
|
@@ -217,32 +219,36 @@
|
|
|
|
|
|
scenes.forEach( function ( scene ) {
|
|
scenes.forEach( function ( scene ) {
|
|
|
|
|
|
- var rect = scene.userData.view.getBoundingClientRect();
|
|
|
|
|
|
+ const rect = scene.userData.view.getBoundingClientRect();
|
|
|
|
+
|
|
// check if it's offscreen. If so skip it
|
|
// check if it's offscreen. If so skip it
|
|
|
|
+
|
|
if ( rect.bottom < 0 || rect.top > renderer.domElement.clientHeight ||
|
|
if ( rect.bottom < 0 || rect.top > renderer.domElement.clientHeight ||
|
|
rect.right < 0 || rect.left > renderer.domElement.clientWidth ) {
|
|
rect.right < 0 || rect.left > renderer.domElement.clientWidth ) {
|
|
|
|
|
|
return; // it's off screen
|
|
return; // it's off screen
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
// set the viewport
|
|
// set the viewport
|
|
- var width = rect.right - rect.left;
|
|
|
|
- var height = rect.bottom - rect.top;
|
|
|
|
- var left = rect.left;
|
|
|
|
- var bottom = renderer.domElement.clientHeight - rect.bottom;
|
|
|
|
|
|
+
|
|
|
|
+ const width = rect.right - rect.left;
|
|
|
|
+ const height = rect.bottom - rect.top;
|
|
|
|
+ const left = rect.left;
|
|
|
|
+ const bottom = renderer.domElement.clientHeight - rect.bottom;
|
|
|
|
|
|
renderer.setViewport( left, bottom, width, height );
|
|
renderer.setViewport( left, bottom, width, height );
|
|
renderer.setScissor( left, bottom, width, height );
|
|
renderer.setScissor( left, bottom, width, height );
|
|
|
|
|
|
renderer.render( scene, scene.userData.camera );
|
|
renderer.render( scene, scene.userData.camera );
|
|
|
|
|
|
- var points = scene.children[ 0 ];
|
|
|
|
- var position = points.geometry.attributes.position;
|
|
|
|
|
|
+ const points = scene.children[ 0 ];
|
|
|
|
+ const position = points.geometry.attributes.position;
|
|
|
|
|
|
- var point = new THREE.Vector3();
|
|
|
|
- var offset = new THREE.Vector3();
|
|
|
|
|
|
+ const point = new THREE.Vector3();
|
|
|
|
+ const offset = new THREE.Vector3();
|
|
|
|
|
|
- for ( var i = 0; i < position.count; i ++ ) {
|
|
|
|
|
|
+ for ( let i = 0; i < position.count; i ++ ) {
|
|
|
|
|
|
point.fromBufferAttribute( scene.userData.geometry1.attributes.position, i );
|
|
point.fromBufferAttribute( scene.userData.geometry1.attributes.position, i );
|
|
|
|
|
|
@@ -317,7 +323,7 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
|
- var parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
+ let parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
|
|
|
|
@@ -337,7 +343,7 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
|
- var parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
+ parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
|
|
|
|
@@ -431,7 +437,7 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
|
- var parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
+ parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
|
|
|
|
@@ -441,8 +447,8 @@
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- var rho = Math.sqrt( x * x + y * y );
|
|
|
|
- var phi = Math.atan2( y, x );
|
|
|
|
|
|
+ const rho = Math.sqrt( x * x + y * y );
|
|
|
|
+ const phi = Math.atan2( y, x );
|
|
|
|
|
|
return target.set( 1.5 * Math.cos( phi ) * Math.sin( rho - t ) / Math.sqrt( rho ), 1.5 * Math.sin( phi ) * Math.sin( rho - t ) / Math.sqrt( rho ), 0 );
|
|
return target.set( 1.5 * Math.cos( phi ) * Math.sin( rho - t ) / Math.sqrt( rho ), 1.5 * Math.sin( phi ) * Math.sin( rho - t ) / Math.sqrt( rho ), 0 );
|
|
|
|
|
|
@@ -462,7 +468,7 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
|
- var parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
+ parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
|
|
|
|
@@ -472,8 +478,8 @@
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- var rho = Math.sqrt( x * x + y * y );
|
|
|
|
- var phi = Math.atan2( y, x );
|
|
|
|
|
|
+ const rho = Math.sqrt( x * x + y * y );
|
|
|
|
+ const phi = Math.atan2( y, x );
|
|
|
|
|
|
return target.set( 1.5 * Math.cos( phi ) * Math.sin( rho - t ) / Math.sqrt( rho ), 1.5 * Math.sin( phi ) * Math.sin( rho - t ) / Math.sqrt( rho ), 0 );
|
|
return target.set( 1.5 * Math.cos( phi ) * Math.sin( rho - t ) / Math.sqrt( rho ), 1.5 * Math.sin( phi ) * Math.sin( rho - t ) / Math.sqrt( rho ), 0 );
|
|
|
|
|
|
@@ -567,7 +573,7 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
|
- var parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
+ parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
|
|
|
|
@@ -577,9 +583,9 @@
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- var r = Math.sqrt( x * x + y * y + z * z );
|
|
|
|
- var theta = Math.acos( z / r );
|
|
|
|
- var phi = Math.atan2( y, x );
|
|
|
|
|
|
+ const r = Math.sqrt( x * x + y * y + z * z );
|
|
|
|
+ const theta = Math.acos( z / r );
|
|
|
|
+ const phi = Math.atan2( y, x );
|
|
|
|
|
|
return target.set( 3 * Math.cos( phi ) * Math.sin( theta ) * Math.sin( r - t ) / r, 3 * Math.sin( phi ) * Math.sin( theta ) * Math.sin( r - t ) / r, 3 * Math.cos( theta ) * Math.sin( r - t ) / r );
|
|
return target.set( 3 * Math.cos( phi ) * Math.sin( theta ) * Math.sin( r - t ) / r, 3 * Math.sin( phi ) * Math.sin( theta ) * Math.sin( r - t ) / r, 3 * Math.cos( theta ) * Math.sin( r - t ) / r );
|
|
|
|
|
|
@@ -599,7 +605,7 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
|
- var parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
+ parent = document.scripts[ document.scripts.length - 1 ].parentNode;
|
|
|
|
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
parent.displacement = function ( x, y, z, t, target ) {
|
|
|
|
|
|
@@ -609,9 +615,9 @@
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- var r = Math.sqrt( x * x + y * y + z * z );
|
|
|
|
- var theta = Math.acos( z / r );
|
|
|
|
- var phi = Math.atan2( y, x );
|
|
|
|
|
|
+ const r = Math.sqrt( x * x + y * y + z * z );
|
|
|
|
+ const theta = Math.acos( z / r );
|
|
|
|
+ const phi = Math.atan2( y, x );
|
|
|
|
|
|
return target.set( 3 * Math.cos( phi ) * Math.sin( theta ) * Math.sin( r - t ) / r, 3 * Math.sin( phi ) * Math.sin( theta ) * Math.sin( r - t ) / r, 3 * Math.cos( theta ) * Math.sin( r - t ) / r );
|
|
return target.set( 3 * Math.cos( phi ) * Math.sin( theta ) * Math.sin( r - t ) / r, 3 * Math.sin( phi ) * Math.sin( theta ) * Math.sin( r - t ) / r, 3 * Math.cos( theta ) * Math.sin( r - t ) / r );
|
|
|
|
|