|
@@ -37,7 +37,7 @@
|
|
|
import { PMREMGenerator } from './jsm/pmrem/PMREMGenerator.js';
|
|
|
import { PMREMCubeUVPacker } from './jsm/pmrem/PMREMCubeUVPacker.js';
|
|
|
|
|
|
- var container, stats, loader;
|
|
|
+ var container, stats;
|
|
|
|
|
|
var camera, scene, renderer;
|
|
|
|
|
@@ -66,31 +66,36 @@
|
|
|
var mats = [];
|
|
|
var normalMaps = {};
|
|
|
|
|
|
- var windowHalfX = window.innerWidth / 2;
|
|
|
- var windowHalfY = window.innerHeight / 2;
|
|
|
-
|
|
|
const sphereSize = 80;
|
|
|
const sphereSpacing = 1.25 * sphereSize * 2;
|
|
|
|
|
|
const variationsX = [
|
|
|
- (mat, scale, map) => { mat.clearCoatNormalScale.copy(mat.normalScale); },
|
|
|
- (mat, scale, map) => {
|
|
|
- mat.clearCoatNormalScale = new THREE.Vector2(scale, scale);
|
|
|
- if (mat.clearCoatNormalMap !== map) {
|
|
|
+ ( mat, scale, map ) => { },
|
|
|
+ ( mat, scale, map ) => {
|
|
|
+
|
|
|
+ mat.clearCoatNormalScale = new THREE.Vector2( scale, scale );
|
|
|
+ if ( mat.clearCoatNormalMap !== map ) {
|
|
|
+
|
|
|
mat.clearCoatNormalMap = map;
|
|
|
mat.needsUpdate = true;
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
},
|
|
|
];
|
|
|
|
|
|
const variationsY = [
|
|
|
- (mat, scale, map) => { },
|
|
|
- (mat, scale, map) => {
|
|
|
- mat.normalScale = new THREE.Vector2(scale, scale);
|
|
|
- if (mat.normalMap !== map) {
|
|
|
+ ( mat, scale, map ) => { },
|
|
|
+ ( mat, scale, map ) => {
|
|
|
+
|
|
|
+ mat.normalScale = new THREE.Vector2( scale, scale );
|
|
|
+ if ( mat.normalMap !== map ) {
|
|
|
+
|
|
|
mat.normalMap = map;
|
|
|
mat.needsUpdate = true;
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
},
|
|
|
];
|
|
|
|
|
@@ -98,21 +103,25 @@
|
|
|
const maxJ = variationsY.length;
|
|
|
|
|
|
new THREE.FontLoader()
|
|
|
- .load('fonts/gentilis_regular.typeface.json', function (font) {
|
|
|
- init(font);
|
|
|
- animate();
|
|
|
- });
|
|
|
+ .load( 'fonts/gentilis_regular.typeface.json',
|
|
|
+ function ( font ) {
|
|
|
+
|
|
|
+ init( font );
|
|
|
+ animate();
|
|
|
+
|
|
|
+ }
|
|
|
+ );
|
|
|
|
|
|
|
|
|
- function init(font) {
|
|
|
+ function init( font ) {
|
|
|
|
|
|
- container = document.createElement('div');
|
|
|
- document.body.appendChild(container);
|
|
|
+ container = document.createElement( 'div' );
|
|
|
+ document.body.appendChild( container );
|
|
|
|
|
|
- camera = new THREE.PerspectiveCamera(27, window.innerWidth / window.innerHeight, 1, 10000);
|
|
|
+ camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 10000 );
|
|
|
camera.position.z = 1500;
|
|
|
|
|
|
- var genCubeUrls = function (prefix, postfix) {
|
|
|
+ var genCubeUrls = function ( prefix, postfix ) {
|
|
|
|
|
|
return [
|
|
|
prefix + 'px' + postfix, prefix + 'nx' + postfix,
|
|
@@ -124,119 +133,138 @@
|
|
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
|
|
- var hdrUrls = genCubeUrls('./textures/cube/pisaHDR/', '.hdr');
|
|
|
+ var hdrUrls = genCubeUrls( './textures/cube/pisaHDR/', '.hdr' );
|
|
|
|
|
|
new HDRCubeTextureLoader()
|
|
|
- .setType(THREE.UnsignedByteType)
|
|
|
- .load(hdrUrls, function (hdrCubeMap) {
|
|
|
+ .setType( THREE.UnsignedByteType )
|
|
|
+ .load( hdrUrls,
|
|
|
+ function ( hdrCubeMap ) {
|
|
|
|
|
|
- var pmremGenerator = new PMREMGenerator(hdrCubeMap);
|
|
|
- pmremGenerator.update(renderer);
|
|
|
+ var pmremGenerator = new PMREMGenerator( hdrCubeMap );
|
|
|
+ pmremGenerator.update( renderer );
|
|
|
|
|
|
- var pmremCubeUVPacker = new PMREMCubeUVPacker(pmremGenerator.cubeLods);
|
|
|
- pmremCubeUVPacker.update(renderer);
|
|
|
+ var pmremCubeUVPacker = new PMREMCubeUVPacker( pmremGenerator.cubeLods );
|
|
|
+ pmremCubeUVPacker.update( renderer );
|
|
|
|
|
|
- var hdrCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;
|
|
|
+ var hdrCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;
|
|
|
|
|
|
- var geometry = new THREE.SphereBufferGeometry(80, 64, 32);
|
|
|
+ var geometry = new THREE.SphereBufferGeometry( 80, 64, 32 );
|
|
|
|
|
|
- var textureLoader = new THREE.TextureLoader();
|
|
|
+ var textureLoader = new THREE.TextureLoader();
|
|
|
|
|
|
- normalMaps.tentacle = textureLoader
|
|
|
- .load("textures/nvidia_tentacle/tentacle_tangent_space.png");
|
|
|
+ normalMaps.tentacle = textureLoader
|
|
|
+ .load( "textures/nvidia_tentacle/tentacle_tangent_space.png" );
|
|
|
|
|
|
- normalMaps.face = textureLoader
|
|
|
- .load("models/gltf/LeePerrySmith/Infinite-Level_02_Tangent_SmoothUV.jpg");
|
|
|
+ normalMaps.face = textureLoader
|
|
|
+ .load( "models/gltf/LeePerrySmith/Infinite-Level_02_Tangent_SmoothUV.jpg" );
|
|
|
|
|
|
- // objectNormalMap = textureLoader
|
|
|
- // .load("textures/nvidia_tentacle/tentacle_object_space.png");
|
|
|
|
|
|
- var matParams = {
|
|
|
- envMap: hdrCubeRenderTarget.texture,
|
|
|
- };
|
|
|
+ var matParams = {
|
|
|
+ envMap: hdrCubeRenderTarget.texture,
|
|
|
+ };
|
|
|
|
|
|
|
|
|
- for (var ii = 0; ii < maxI; ii++) {
|
|
|
- if (!mats[ii]) {
|
|
|
- mats[ii] = [];
|
|
|
- }
|
|
|
- for (var jj = 0; jj < maxJ; jj++) {
|
|
|
+ for ( var ii = 0; ii < maxI; ii ++ ) {
|
|
|
+
|
|
|
+ if ( ! mats[ ii ] ) {
|
|
|
+
|
|
|
+ mats[ ii ] = [];
|
|
|
|
|
|
- var mat = mats[ii][jj] = new THREE.MeshPhysicalMaterial(matParams);
|
|
|
+ }
|
|
|
+
|
|
|
+ for ( var jj = 0; jj < maxJ; jj ++ ) {
|
|
|
+
|
|
|
+ var mat = mats[ ii ][ jj ] = new THREE.MeshPhysicalMaterial( matParams );
|
|
|
+
|
|
|
+ variationsX[ ii ]( mat, 1, normalMaps.tentacle );
|
|
|
+ variationsY[ jj ]( mat, 1, normalMaps.face );
|
|
|
+ var mesh = new THREE.Mesh( geometry, mat );
|
|
|
+ meshes.push( mesh );
|
|
|
+ mesh.position.x = ( ii - ( maxI - 1 ) / 2 ) * sphereSpacing;
|
|
|
+ mesh.position.y = ( jj - ( maxJ - 1 ) / 2 ) * sphereSpacing;
|
|
|
+ scene.add( mesh );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- variationsX[ii](mat, 1, normalMaps.tentacle);
|
|
|
- variationsY[jj](mat, 1, normalMaps.face);
|
|
|
- var mesh = new THREE.Mesh(geometry, mat);
|
|
|
- meshes.push(mesh);
|
|
|
- mesh.position.x = (ii - (maxI - 1) / 2) * sphereSpacing;
|
|
|
- mesh.position.y = (jj - (maxJ - 1) / 2) * sphereSpacing;
|
|
|
- scene.add(mesh);
|
|
|
}
|
|
|
+
|
|
|
+ hdrCubeMap.magFilter = THREE.LinearFilter;
|
|
|
+ hdrCubeMap.needsUpdate = true;
|
|
|
+ scene.background = hdrCubeMap;
|
|
|
+
|
|
|
+ pmremGenerator.dispose();
|
|
|
+ pmremCubeUVPacker.dispose();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- hdrCubeMap.magFilter = THREE.LinearFilter;
|
|
|
- hdrCubeMap.needsUpdate = true;
|
|
|
- scene.background = hdrCubeMap;
|
|
|
+ );
|
|
|
|
|
|
- pmremGenerator.dispose();
|
|
|
- pmremCubeUVPacker.dispose();
|
|
|
- });
|
|
|
+ function addLabel( name, location, fontSize ) {
|
|
|
|
|
|
- function addLabel(name, location, fontSize) {
|
|
|
fontSize = fontSize | 20;
|
|
|
- var textGeo = new THREE.TextBufferGeometry(name, {
|
|
|
+ var textGeo = new THREE.TextBufferGeometry( name,
|
|
|
+ {
|
|
|
|
|
|
- font: font,
|
|
|
- size: fontSize,
|
|
|
- height: 1,
|
|
|
- curveSegments: 1
|
|
|
+ font: font,
|
|
|
+ size: fontSize,
|
|
|
+ height: 1,
|
|
|
+ curveSegments: 1
|
|
|
|
|
|
- });
|
|
|
+ }
|
|
|
+ );
|
|
|
|
|
|
- var textMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
|
|
|
- var textMesh = new THREE.Mesh(textGeo, textMaterial);
|
|
|
+ var textMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff } );
|
|
|
+ var textMesh = new THREE.Mesh( textGeo, textMaterial );
|
|
|
|
|
|
+ // Center the bounding box on the specified position w/ translation of -half diagonal
|
|
|
textGeo.computeBoundingBox();
|
|
|
var bb = textGeo.boundingBox.clone();
|
|
|
- var displace = bb.max.sub(bb.min).divide(new THREE.Vector3(2, 2, 2));
|
|
|
+ var displace = bb.max.sub( bb.min ).divide( new THREE.Vector3( 2, 2, 2 ) );
|
|
|
|
|
|
- textMesh.position.copy(location.sub(displace));
|
|
|
- scene.add(textMesh);
|
|
|
+ textMesh.position.copy( location.sub( displace ) );
|
|
|
+ scene.add( textMesh );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
- addLabel("Normal Map", new THREE.Vector3(-350, 0, 0), 30);
|
|
|
- addLabel("None", new THREE.Vector3(-250, -100, 0));
|
|
|
- addLabel("Map", new THREE.Vector3(-300, 100, 0));
|
|
|
+ addLabel( "Normal Map", new THREE.Vector3( -350, 0, 0 ), 30 );
|
|
|
+ addLabel( "None", new THREE.Vector3( -250, -100, 0 ) );
|
|
|
+ addLabel( "Map", new THREE.Vector3( -300, 100, 0 ) );
|
|
|
|
|
|
- addLabel("Clearcoat Normal Map", new THREE.Vector3(0, 260, 0), 30);
|
|
|
- addLabel("None", new THREE.Vector3(-100, 200, 0));
|
|
|
- addLabel("Map", new THREE.Vector3(100, 200, 0));
|
|
|
+ addLabel( "Clearcoat Normal Map", new THREE.Vector3( 0, 260, 0 ), 30 );
|
|
|
+ addLabel( "None", new THREE.Vector3( -100, 200, 0 ) );
|
|
|
+ addLabel( "Map", new THREE.Vector3( 100, 200, 0 ) );
|
|
|
|
|
|
// LIGHTS
|
|
|
|
|
|
- particleLight = new THREE.Mesh(new THREE.SphereBufferGeometry(4, 8, 8), new THREE.MeshBasicMaterial({ color: 0xffffff }));
|
|
|
- scene.add(particleLight);
|
|
|
+ particleLight = new THREE.Mesh( new THREE.SphereBufferGeometry( 4, 8, 8 ), new THREE.MeshBasicMaterial( { color: 0xffffff } ) );
|
|
|
+ scene.add( particleLight );
|
|
|
|
|
|
{
|
|
|
- var ambientLight = new THREE.AmbientLight(0x444444);
|
|
|
- scene.add(ambientLight);
|
|
|
+
|
|
|
+ var ambientLight = new THREE.AmbientLight( 0x444444 );
|
|
|
+ scene.add( ambientLight );
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
{
|
|
|
- var pointLight = new THREE.PointLight(0xffffff, 1.25, 1000);
|
|
|
- particleLight.add(pointLight);
|
|
|
+
|
|
|
+ var pointLight = new THREE.PointLight( 0xffffff, 1.25, 1000 );
|
|
|
+ particleLight.add( pointLight );
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
{
|
|
|
- var directionalLight = new THREE.DirectionalLight(0xffffff);
|
|
|
- directionalLight.position.set(1, - 0.5, - 1);
|
|
|
- scene.add(directionalLight);
|
|
|
- }
|
|
|
|
|
|
+ var directionalLight = new THREE.DirectionalLight( 0xffffff );
|
|
|
+ directionalLight.position.set( 1, - 0.5, - 1 );
|
|
|
+ scene.add( directionalLight );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
renderer = new THREE.WebGLRenderer();
|
|
|
- renderer.setSize(window.innerWidth, window.innerHeight);
|
|
|
- container.appendChild(renderer.domElement);
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+ container.appendChild( renderer.domElement );
|
|
|
|
|
|
//
|
|
|
|
|
@@ -246,62 +274,69 @@
|
|
|
//
|
|
|
|
|
|
stats = new Stats();
|
|
|
- container.appendChild(stats.dom);
|
|
|
+ container.appendChild( stats.dom );
|
|
|
|
|
|
// EVENTS
|
|
|
|
|
|
- var controls = new OrbitControls(camera, renderer.domElement);
|
|
|
+ var controls = new OrbitControls( camera, renderer.domElement );
|
|
|
|
|
|
- window.addEventListener('resize', onWindowResize, false);
|
|
|
+ window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
|
|
var gui = new GUI();
|
|
|
|
|
|
{
|
|
|
+
|
|
|
var materialGui = gui.addFolder( 'Physical Material' );
|
|
|
- materialGui.add(guiParams, 'metalness', 0, 1, 0.01);
|
|
|
- materialGui.add(guiParams, 'roughness', 0, 1, 0.01);
|
|
|
- materialGui.add(guiParams, 'reflectivity', 0, 1, 0.01);
|
|
|
+ materialGui.add( guiParams, 'metalness', 0, 1, 0.01 );
|
|
|
+ materialGui.add( guiParams, 'roughness', 0, 1, 0.01 );
|
|
|
+ materialGui.add( guiParams, 'reflectivity', 0, 1, 0.01 );
|
|
|
materialGui.open();
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
{
|
|
|
+
|
|
|
var clearCoatGui = gui.addFolder( 'ClearCoat' );
|
|
|
- clearCoatGui.add(guiParams, 'clearCoat', 0, 1, 0.01);
|
|
|
- clearCoatGui.add(guiParams, 'clearCoatRoughness', 0, 1, 0.01);
|
|
|
+ clearCoatGui.add( guiParams, 'clearCoat', 0, 1, 0.01 );
|
|
|
+ clearCoatGui.add( guiParams, 'clearCoatRoughness', 0, 1, 0.01 );
|
|
|
clearCoatGui.open();
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
{
|
|
|
+
|
|
|
var normalGui = gui.addFolder( 'Normal Maps' );
|
|
|
- normalGui.add(guiMatParams, 'normalMap', guiNormalMapNames);
|
|
|
- normalGui.add(guiMatParams, 'normalScale', 0, 1, 0.01);
|
|
|
- normalGui.add(guiMatParams, 'clearCoatNormalMap', guiNormalMapNames);
|
|
|
- normalGui.add(guiMatParams, 'clearCoatNormalScale', 0, 1, 0.01);
|
|
|
+ normalGui.add( guiMatParams, 'normalMap', guiNormalMapNames );
|
|
|
+ normalGui.add( guiMatParams, 'normalScale', 0, 1, 0.01 );
|
|
|
+ normalGui.add( guiMatParams, 'clearCoatNormalMap', guiNormalMapNames );
|
|
|
+ normalGui.add( guiMatParams, 'clearCoatNormalScale', 0, 1, 0.01 );
|
|
|
normalGui.open();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
|
|
gui.open();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//
|
|
|
|
|
|
function onWindowResize() {
|
|
|
+
|
|
|
var width = window.innerWidth;
|
|
|
var height = window.innerHeight;
|
|
|
|
|
|
camera.aspect = width / height;
|
|
|
camera.updateProjectionMatrix();
|
|
|
|
|
|
- renderer.setSize(width, height);
|
|
|
+ renderer.setSize( width, height );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//
|
|
|
|
|
|
function animate() {
|
|
|
|
|
|
- requestAnimationFrame(animate);
|
|
|
+ requestAnimationFrame( animate );
|
|
|
|
|
|
render();
|
|
|
|
|
@@ -311,43 +346,52 @@
|
|
|
|
|
|
function render() {
|
|
|
|
|
|
- var matColor = new THREE.Color().setHSL(0.0, 0.5, 0.25);
|
|
|
+ var matColor = new THREE.Color().setHSL( 0.0, 0.5, 0.25 );
|
|
|
+
|
|
|
+ for ( var ii = 0; ii < maxI; ii ++ ) {
|
|
|
+
|
|
|
+ if ( mats[ ii ] ) { // avoid exceptions on first render before materials are set. TODO: lauch animation only after setup
|
|
|
|
|
|
- for (var ii = 0; ii < maxI; ii++) {
|
|
|
- if (mats[ii]) {
|
|
|
- for (var jj = 0; jj < maxJ; jj++) {
|
|
|
- var mat = mats[ii][jj];
|
|
|
+ for ( var jj = 0; jj < maxJ; jj ++ ) {
|
|
|
+
|
|
|
+ var mat = mats[ ii ][ jj ];
|
|
|
mat.color = matColor;
|
|
|
- for (var matParam in guiParams) {
|
|
|
- mat[matParam] = guiParams[matParam];
|
|
|
+ for ( var matParam in guiParams ) {
|
|
|
+
|
|
|
+ mat[ matParam ] = guiParams[ matParam ];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- var normalMap = normalMaps[guiMatParams.normalMap];
|
|
|
- var clearCoatNormalMap = normalMaps[guiMatParams.clearCoatNormalMap];
|
|
|
+ var normalMap = normalMaps[ guiMatParams.normalMap ];
|
|
|
+ var clearCoatNormalMap = normalMaps[ guiMatParams.clearCoatNormalMap ];
|
|
|
+
|
|
|
+ variationsX[ ii ]( mat, guiMatParams.clearCoatNormalScale, clearCoatNormalMap );
|
|
|
+ variationsY[ jj ]( mat, guiMatParams.normalScale, normalMap );
|
|
|
|
|
|
- variationsX[ii](mat, guiMatParams.clearCoatNormalScale, clearCoatNormalMap);
|
|
|
- variationsY[jj](mat, guiMatParams.normalScale, normalMap);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
var timer = Date.now() * 0.00025;
|
|
|
- particleLight.position.x = Math.sin(timer * 7) * 300;
|
|
|
- particleLight.position.y = Math.cos(timer * 5) * 400;
|
|
|
- particleLight.position.z = Math.cos(timer * 3) * 300;
|
|
|
+ particleLight.position.x = Math.sin( timer * 7 ) * 300;
|
|
|
+ particleLight.position.y = Math.cos( timer * 5 ) * 400;
|
|
|
+ particleLight.position.z = Math.cos( timer * 3 ) * 300;
|
|
|
|
|
|
|
|
|
- for (var mesh of meshes) {
|
|
|
+ for ( var mesh of meshes ) {
|
|
|
+
|
|
|
mesh.rotation.y += 0.01;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
- renderer.render(scene, camera);
|
|
|
+ renderer.render( scene, camera );
|
|
|
|
|
|
}
|
|
|
|
|
|
- </script>
|
|
|
|
|
|
+ </script>
|
|
|
</body>
|
|
|
-
|
|
|
</html>
|