|
@@ -32,29 +32,33 @@
|
|
|
|
|
|
|
|
let renderer, scene, camera;
|
|
let renderer, scene, camera;
|
|
|
|
|
|
|
|
- let spotLight, lightHelper;
|
|
|
|
|
|
|
+ let spotLight;
|
|
|
|
|
|
|
|
init();
|
|
init();
|
|
|
|
|
|
|
|
function init() {
|
|
function init() {
|
|
|
|
|
|
|
|
|
|
+ // Renderer
|
|
|
|
|
+
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
renderer = new THREE.WebGLRenderer( { antialias: 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 );
|
|
|
document.body.appendChild( renderer.domElement );
|
|
document.body.appendChild( renderer.domElement );
|
|
|
|
|
|
|
|
|
|
+ renderer.toneMapping = THREE.NeutralToneMapping;
|
|
|
|
|
+ renderer.toneMappingExposure = 1;
|
|
|
|
|
+
|
|
|
renderer.shadowMap.enabled = true;
|
|
renderer.shadowMap.enabled = true;
|
|
|
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
|
|
|
|
|
|
- renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
|
|
|
- renderer.toneMappingExposure = 1;
|
|
|
|
|
-
|
|
|
|
|
scene = new THREE.Scene();
|
|
scene = new THREE.Scene();
|
|
|
|
|
|
|
|
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.1, 100 );
|
|
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.1, 100 );
|
|
|
camera.position.set( 7, 4, 1 );
|
|
camera.position.set( 7, 4, 1 );
|
|
|
|
|
|
|
|
|
|
+ // Controls
|
|
|
|
|
+
|
|
|
const controls = new OrbitControls( camera, renderer.domElement );
|
|
const controls = new OrbitControls( camera, renderer.domElement );
|
|
|
controls.minDistance = 2;
|
|
controls.minDistance = 2;
|
|
|
controls.maxDistance = 10;
|
|
controls.maxDistance = 10;
|
|
@@ -62,8 +66,7 @@
|
|
|
controls.target.set( 0, 1, 0 );
|
|
controls.target.set( 0, 1, 0 );
|
|
|
controls.update();
|
|
controls.update();
|
|
|
|
|
|
|
|
- const ambient = new THREE.HemisphereLight( 0xffffff, 0x8d8d8d, 0.15 );
|
|
|
|
|
- scene.add( ambient );
|
|
|
|
|
|
|
+ // Textures
|
|
|
|
|
|
|
|
const loader = new THREE.TextureLoader().setPath( 'textures/' );
|
|
const loader = new THREE.TextureLoader().setPath( 'textures/' );
|
|
|
const filenames = [ 'disturb.jpg', 'colors.png', 'uv_grid_opengl.jpg' ];
|
|
const filenames = [ 'disturb.jpg', 'colors.png', 'uv_grid_opengl.jpg' ];
|
|
@@ -84,28 +87,41 @@
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Lights
|
|
|
|
|
+
|
|
|
|
|
+ const ambient = new THREE.HemisphereLight( 0xffffff, 0x8d8d8d, 0.25 );
|
|
|
|
|
+ scene.add( ambient );
|
|
|
|
|
+
|
|
|
spotLight = new THREE.SpotLight( 0xffffff, 100 );
|
|
spotLight = new THREE.SpotLight( 0xffffff, 100 );
|
|
|
|
|
+ spotLight.name = 'spotLight';
|
|
|
|
|
+ spotLight.map = textures[ 'disturb.jpg' ];
|
|
|
spotLight.position.set( 2.5, 5, 2.5 );
|
|
spotLight.position.set( 2.5, 5, 2.5 );
|
|
|
spotLight.angle = Math.PI / 6;
|
|
spotLight.angle = Math.PI / 6;
|
|
|
spotLight.penumbra = 1;
|
|
spotLight.penumbra = 1;
|
|
|
spotLight.decay = 2;
|
|
spotLight.decay = 2;
|
|
|
spotLight.distance = 0;
|
|
spotLight.distance = 0;
|
|
|
- spotLight.map = textures[ 'disturb.jpg' ];
|
|
|
|
|
|
|
|
|
|
spotLight.castShadow = true;
|
|
spotLight.castShadow = true;
|
|
|
spotLight.shadow.mapSize.width = 1024;
|
|
spotLight.shadow.mapSize.width = 1024;
|
|
|
spotLight.shadow.mapSize.height = 1024;
|
|
spotLight.shadow.mapSize.height = 1024;
|
|
|
- spotLight.shadow.camera.near = 1;
|
|
|
|
|
|
|
+ spotLight.shadow.camera.near = 2;
|
|
|
spotLight.shadow.camera.far = 10;
|
|
spotLight.shadow.camera.far = 10;
|
|
|
spotLight.shadow.focus = 1;
|
|
spotLight.shadow.focus = 1;
|
|
|
|
|
+ spotLight.shadow.bias = - .003;
|
|
|
|
|
+ spotLight.shadow.intensity = 1;
|
|
|
scene.add( spotLight );
|
|
scene.add( spotLight );
|
|
|
|
|
|
|
|
- lightHelper = new THREE.SpotLightHelper( spotLight );
|
|
|
|
|
- scene.add( lightHelper );
|
|
|
|
|
|
|
+ spotLight.lightHelper = new THREE.SpotLightHelper( spotLight );
|
|
|
|
|
+ spotLight.lightHelper.visible = false;
|
|
|
|
|
+ scene.add( spotLight.lightHelper );
|
|
|
|
|
+
|
|
|
|
|
+ spotLight.shadowCameraHelper = new THREE.CameraHelper( spotLight.shadow.camera ); // colored lines
|
|
|
|
|
+ spotLight.shadowCameraHelper.visible = false;
|
|
|
|
|
+ scene.add( spotLight.shadowCameraHelper );
|
|
|
|
|
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
- const geometry = new THREE.PlaneGeometry( 200, 200 );
|
|
|
|
|
|
|
+ const geometry = new THREE.PlaneGeometry( 10, 10 );
|
|
|
const material = new THREE.MeshLambertMaterial( { color: 0xbcbcbc } );
|
|
const material = new THREE.MeshLambertMaterial( { color: 0xbcbcbc } );
|
|
|
|
|
|
|
|
const mesh = new THREE.Mesh( geometry, material );
|
|
const mesh = new THREE.Mesh( geometry, material );
|
|
@@ -114,7 +130,7 @@
|
|
|
mesh.receiveShadow = true;
|
|
mesh.receiveShadow = true;
|
|
|
scene.add( mesh );
|
|
scene.add( mesh );
|
|
|
|
|
|
|
|
- //
|
|
|
|
|
|
|
+ // Model
|
|
|
|
|
|
|
|
new PLYLoader().load( 'models/ply/binary/Lucy100k.ply', function ( geometry ) {
|
|
new PLYLoader().load( 'models/ply/binary/Lucy100k.ply', function ( geometry ) {
|
|
|
|
|
|
|
@@ -132,6 +148,8 @@
|
|
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ //
|
|
|
|
|
+
|
|
|
window.addEventListener( 'resize', onWindowResize );
|
|
window.addEventListener( 'resize', onWindowResize );
|
|
|
|
|
|
|
|
// GUI
|
|
// GUI
|
|
@@ -147,7 +165,8 @@
|
|
|
penumbra: spotLight.penumbra,
|
|
penumbra: spotLight.penumbra,
|
|
|
decay: spotLight.decay,
|
|
decay: spotLight.decay,
|
|
|
focus: spotLight.shadow.focus,
|
|
focus: spotLight.shadow.focus,
|
|
|
- shadows: true
|
|
|
|
|
|
|
+ shadowIntensity: spotLight.shadow.intensity,
|
|
|
|
|
+ helpers: false
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
gui.add( params, 'map', textures ).onChange( function ( val ) {
|
|
gui.add( params, 'map', textures ).onChange( function ( val ) {
|
|
@@ -199,20 +218,16 @@
|
|
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ gui.add( params, 'shadowIntensity', 0, 1 ).onChange( function ( val ) {
|
|
|
|
|
|
|
|
- gui.add( params, 'shadows' ).onChange( function ( val ) {
|
|
|
|
|
-
|
|
|
|
|
- renderer.shadowMap.enabled = val;
|
|
|
|
|
-
|
|
|
|
|
- scene.traverse( function ( child ) {
|
|
|
|
|
|
|
+ spotLight.shadow.intensity = val;
|
|
|
|
|
|
|
|
- if ( child.material ) {
|
|
|
|
|
-
|
|
|
|
|
- child.material.needsUpdate = true;
|
|
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ gui.add( params, 'helpers' ).onChange( function ( val ) {
|
|
|
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ spotLight.lightHelper.visible = val;
|
|
|
|
|
+ spotLight.shadowCameraHelper.visible = val;
|
|
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -236,7 +251,7 @@
|
|
|
spotLight.position.x = Math.cos( time ) * 2.5;
|
|
spotLight.position.x = Math.cos( time ) * 2.5;
|
|
|
spotLight.position.z = Math.sin( time ) * 2.5;
|
|
spotLight.position.z = Math.sin( time ) * 2.5;
|
|
|
|
|
|
|
|
- lightHelper.update();
|
|
|
|
|
|
|
+ spotLight.lightHelper.update();
|
|
|
|
|
|
|
|
renderer.render( scene, camera );
|
|
renderer.render( scene, camera );
|
|
|
|
|
|