|
@@ -7,6 +7,7 @@
|
|
|
<link type="text/css" rel="stylesheet" href="main.css">
|
|
<link type="text/css" rel="stylesheet" href="main.css">
|
|
|
</head>
|
|
</head>
|
|
|
<body>
|
|
<body>
|
|
|
|
|
+
|
|
|
<script type="importmap">
|
|
<script type="importmap">
|
|
|
{
|
|
{
|
|
|
"imports": {
|
|
"imports": {
|
|
@@ -22,42 +23,34 @@
|
|
|
|
|
|
|
|
import * as THREE from 'three';
|
|
import * as THREE from 'three';
|
|
|
|
|
|
|
|
|
|
+ import Stats from 'three/addons/libs/stats.module.js';
|
|
|
|
|
+
|
|
|
let camera, scene, renderer;
|
|
let camera, scene, renderer;
|
|
|
let mesh;
|
|
let mesh;
|
|
|
|
|
+ let stats;
|
|
|
|
|
+
|
|
|
const AMOUNT = 6;
|
|
const AMOUNT = 6;
|
|
|
|
|
|
|
|
init();
|
|
init();
|
|
|
|
|
|
|
|
function init() {
|
|
function init() {
|
|
|
|
|
|
|
|
- const ASPECT_RATIO = window.innerWidth / window.innerHeight;
|
|
|
|
|
-
|
|
|
|
|
- const WIDTH = ( window.innerWidth / AMOUNT );
|
|
|
|
|
- const HEIGHT = ( window.innerHeight / AMOUNT );
|
|
|
|
|
|
|
+ const subCameras = [];
|
|
|
|
|
|
|
|
- const cameras = [];
|
|
|
|
|
|
|
+ for ( let i = 0; i < AMOUNT * AMOUNT; i ++ ) {
|
|
|
|
|
|
|
|
- for ( let y = 0; y < AMOUNT; y ++ ) {
|
|
|
|
|
|
|
+ const subCamera = new THREE.PerspectiveCamera( 40, 1, 0.1, 10 );
|
|
|
|
|
+ subCamera.viewport = new THREE.Vector4();
|
|
|
|
|
|
|
|
- for ( let x = 0; x < AMOUNT; x ++ ) {
|
|
|
|
|
-
|
|
|
|
|
- const subcamera = new THREE.PerspectiveCamera( 40, ASPECT_RATIO, 0.1, 10 );
|
|
|
|
|
- subcamera.viewport = new THREE.Vector4( Math.floor( x * WIDTH ), Math.floor( y * HEIGHT ), Math.ceil( WIDTH ), Math.ceil( HEIGHT ) );
|
|
|
|
|
- subcamera.position.x = ( x / AMOUNT ) - 0.5;
|
|
|
|
|
- subcamera.position.y = 0.5 - ( y / AMOUNT );
|
|
|
|
|
- subcamera.position.z = 1.5;
|
|
|
|
|
- subcamera.position.multiplyScalar( 2 );
|
|
|
|
|
- subcamera.lookAt( 0, 0, 0 );
|
|
|
|
|
- subcamera.updateMatrixWorld();
|
|
|
|
|
- cameras.push( subcamera );
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ subCameras.push( subCamera );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- camera = new THREE.ArrayCamera( cameras );
|
|
|
|
|
|
|
+ camera = new THREE.ArrayCamera( subCameras );
|
|
|
camera.position.z = 3;
|
|
camera.position.z = 3;
|
|
|
|
|
|
|
|
|
|
+ updateCameras();
|
|
|
|
|
+
|
|
|
scene = new THREE.Scene();
|
|
scene = new THREE.Scene();
|
|
|
|
|
|
|
|
scene.add( new THREE.AmbientLight( 0x999999 ) );
|
|
scene.add( new THREE.AmbientLight( 0x999999 ) );
|
|
@@ -65,8 +58,8 @@
|
|
|
const light = new THREE.DirectionalLight( 0xffffff, 3 );
|
|
const light = new THREE.DirectionalLight( 0xffffff, 3 );
|
|
|
light.position.set( 0.5, 0.5, 1 );
|
|
light.position.set( 0.5, 0.5, 1 );
|
|
|
light.castShadow = true;
|
|
light.castShadow = true;
|
|
|
- light.shadow.camera.zoom = 4; // tighter shadow map
|
|
|
|
|
light.shadow.bias = - 0.001;
|
|
light.shadow.bias = - 0.001;
|
|
|
|
|
+ light.shadow.camera.zoom = 4; // tighter shadow map
|
|
|
scene.add( light );
|
|
scene.add( light );
|
|
|
|
|
|
|
|
const geometryBackground = new THREE.PlaneGeometry( 100, 100 );
|
|
const geometryBackground = new THREE.PlaneGeometry( 100, 100 );
|
|
@@ -77,7 +70,7 @@
|
|
|
background.position.set( 0, 0, - 1 );
|
|
background.position.set( 0, 0, - 1 );
|
|
|
scene.add( background );
|
|
scene.add( background );
|
|
|
|
|
|
|
|
- const geometryCylinder = new THREE.BoxGeometry();
|
|
|
|
|
|
|
+ const geometryCylinder = new THREE.CylinderGeometry( 0.5, 0.5, 1, 32 );
|
|
|
const materialCylinder = new THREE.MeshPhongMaterial( { color: 0xff0000 } );
|
|
const materialCylinder = new THREE.MeshPhongMaterial( { color: 0xff0000 } );
|
|
|
|
|
|
|
|
mesh = new THREE.Mesh( geometryCylinder, materialCylinder );
|
|
mesh = new THREE.Mesh( geometryCylinder, materialCylinder );
|
|
@@ -85,7 +78,7 @@
|
|
|
mesh.receiveShadow = true;
|
|
mesh.receiveShadow = true;
|
|
|
scene.add( mesh );
|
|
scene.add( mesh );
|
|
|
|
|
|
|
|
- renderer = new THREE.WebGPURenderer( { antialias: true } );
|
|
|
|
|
|
|
+ renderer = new THREE.WebGPURenderer( /*{ forceWebGL: true }*/ );
|
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
renderer.setAnimationLoop( animate );
|
|
renderer.setAnimationLoop( animate );
|
|
@@ -96,13 +89,18 @@
|
|
|
|
|
|
|
|
window.addEventListener( 'resize', onWindowResize );
|
|
window.addEventListener( 'resize', onWindowResize );
|
|
|
|
|
|
|
|
|
|
+ //
|
|
|
|
|
+
|
|
|
|
|
+ stats = new Stats();
|
|
|
|
|
+ document.body.appendChild( stats.dom );
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function onWindowResize() {
|
|
|
|
|
|
|
+ function updateCameras() {
|
|
|
|
|
|
|
|
const ASPECT_RATIO = window.innerWidth / window.innerHeight;
|
|
const ASPECT_RATIO = window.innerWidth / window.innerHeight;
|
|
|
- const WIDTH = ( window.innerWidth / AMOUNT );
|
|
|
|
|
- const HEIGHT = ( window.innerHeight / AMOUNT );
|
|
|
|
|
|
|
+ const WIDTH = window.innerWidth / AMOUNT;
|
|
|
|
|
+ const HEIGHT = window.innerHeight / AMOUNT;
|
|
|
|
|
|
|
|
camera.aspect = ASPECT_RATIO;
|
|
camera.aspect = ASPECT_RATIO;
|
|
|
camera.updateProjectionMatrix();
|
|
camera.updateProjectionMatrix();
|
|
@@ -112,28 +110,42 @@
|
|
|
for ( let x = 0; x < AMOUNT; x ++ ) {
|
|
for ( let x = 0; x < AMOUNT; x ++ ) {
|
|
|
|
|
|
|
|
const subcamera = camera.cameras[ AMOUNT * y + x ];
|
|
const subcamera = camera.cameras[ AMOUNT * y + x ];
|
|
|
|
|
+ subcamera.copy( camera ); // copy fov, aspect ratio, near, far from the root camera
|
|
|
|
|
|
|
|
- subcamera.viewport.set(
|
|
|
|
|
- Math.floor( x * WIDTH ),
|
|
|
|
|
- Math.floor( y * HEIGHT ),
|
|
|
|
|
- Math.ceil( WIDTH ),
|
|
|
|
|
- Math.ceil( HEIGHT ) );
|
|
|
|
|
-
|
|
|
|
|
- subcamera.aspect = ASPECT_RATIO;
|
|
|
|
|
|
|
+ subcamera.viewport.set( Math.floor( x * WIDTH ), Math.floor( y * HEIGHT ), Math.ceil( WIDTH ), Math.ceil( HEIGHT ) );
|
|
|
subcamera.updateProjectionMatrix();
|
|
subcamera.updateProjectionMatrix();
|
|
|
|
|
|
|
|
|
|
+ subcamera.position.x = ( x / AMOUNT ) - 0.5;
|
|
|
|
|
+ subcamera.position.y = 0.5 - ( y / AMOUNT );
|
|
|
|
|
+ subcamera.position.z = 1.5 + ( ( x + y ) * .5 );
|
|
|
|
|
+ subcamera.position.multiplyScalar( 2 );
|
|
|
|
|
+
|
|
|
|
|
+ subcamera.lookAt( 0, 0, 0 );
|
|
|
|
|
+ subcamera.updateMatrixWorld();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function onWindowResize() {
|
|
|
|
|
+
|
|
|
|
|
+ updateCameras();
|
|
|
|
|
+
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function animate() {
|
|
function animate() {
|
|
|
|
|
|
|
|
|
|
+ mesh.rotation.x += 0.005;
|
|
|
|
|
+ mesh.rotation.z += 0.01;
|
|
|
|
|
+
|
|
|
renderer.render( scene, camera );
|
|
renderer.render( scene, camera );
|
|
|
|
|
|
|
|
|
|
+ stats.update();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
</script>
|