提交 762ecf63 编写于 作者: M Mr.doob

Examples: Improved games_fps.

上级 9cfd4260
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
const scene = new THREE.Scene(); const scene = new THREE.Scene();
scene.background = new THREE.Color( 0x88ccff ); scene.background = new THREE.Color( 0x88ccff );
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ); const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.rotation.order = 'YXZ'; camera.rotation.order = 'YXZ';
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
scene.add( ambientlight ); scene.add( ambientlight );
const fillLight1 = new THREE.DirectionalLight( 0xff9999, 0.5 ); const fillLight1 = new THREE.DirectionalLight( 0xff9999, 0.5 );
fillLight1.position.set( -1, 1, 2 ); fillLight1.position.set( - 1, 1, 2 );
scene.add( fillLight1 ); scene.add( fillLight1 );
const fillLight2 = new THREE.DirectionalLight( 0x8888ff, 0.2 ); const fillLight2 = new THREE.DirectionalLight( 0x8888ff, 0.2 );
...@@ -53,11 +53,11 @@ ...@@ -53,11 +53,11 @@
directionalLight.shadow.mapSize.width = 1024; directionalLight.shadow.mapSize.width = 1024;
directionalLight.shadow.mapSize.height = 1024; directionalLight.shadow.mapSize.height = 1024;
directionalLight.shadow.radius = 4; directionalLight.shadow.radius = 4;
directionalLight.shadow.bias = - 0.00006; directionalLight.shadow.bias = - 0.00006;
scene.add( directionalLight ); scene.add( directionalLight );
const renderer = new THREE.WebGLRenderer( { antialias: true } ); const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( 1 ); renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight ); renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true; renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.VSMShadowMap; renderer.shadowMap.type = THREE.VSMShadowMap;
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
for ( let i = 0; i < NUM_SPHERES; i ++ ) { for ( let i = 0; i < NUM_SPHERES; i ++ ) {
let sphere = new THREE.Mesh( sphereGeometry, sphereMaterial ); const sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
sphere.castShadow = true; sphere.castShadow = true;
sphere.receiveShadow = true; sphere.receiveShadow = true;
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
}, false ); }, false );
document.addEventListener( 'mousedown', ( event ) => { document.addEventListener( 'mousedown', () => {
document.body.requestPointerLock(); document.body.requestPointerLock();
...@@ -167,7 +167,7 @@ ...@@ -167,7 +167,7 @@
playerOnFloor = result.normal.y > 0; playerOnFloor = result.normal.y > 0;
if( ! playerOnFloor ) { if ( ! playerOnFloor ) {
playerVelocity.addScaledVector( result.normal, - result.normal.dot( playerVelocity ) ); playerVelocity.addScaledVector( result.normal, - result.normal.dot( playerVelocity ) );
...@@ -201,29 +201,29 @@ ...@@ -201,29 +201,29 @@
} }
function spheresCollisions(){ function spheresCollisions() {
for( let i = 0; i < spheres.length; i ++ ){ for ( let i = 0; i < spheres.length; i ++ ) {
let s1 = spheres[ i ]; const s1 = spheres[ i ];
for( let j = i + 1; j < spheres.length; j ++ ){ for ( let j = i + 1; j < spheres.length; j ++ ) {
let s2 = spheres[ j ]; const s2 = spheres[ j ];
let d2 = s1.collider.center.distanceToSquared( s2.collider.center ); const d2 = s1.collider.center.distanceToSquared( s2.collider.center );
let r = s1.collider.radius + s2.collider.radius; const r = s1.collider.radius + s2.collider.radius;
let r2 = r * r; const r2 = r * r;
if( d2 < r2 ){ if ( d2 < r2 ) {
let normal = s1.collider.clone().center.sub( s2.collider.center ).normalize(); const normal = s1.collider.clone().center.sub( s2.collider.center ).normalize();
let v1 = normal.clone().multiplyScalar( normal.dot( s1.velocity ) ); const v1 = normal.clone().multiplyScalar( normal.dot( s1.velocity ) );
let v2 = normal.clone().multiplyScalar( normal.dot( s2.velocity ) ); const v2 = normal.clone().multiplyScalar( normal.dot( s2.velocity ) );
s1.velocity.add(v2).sub(v1); s1.velocity.add( v2 ).sub( v1 );
s2.velocity.add(v1).sub(v2); s2.velocity.add( v1 ).sub( v2 );
var d = ( r - Math.sqrt(d2) ) / 2; const d = ( r - Math.sqrt( d2 ) ) / 2;
s1.collider.center.addScaledVector( normal, d ); s1.collider.center.addScaledVector( normal, d );
s2.collider.center.addScaledVector( normal, - d ); s2.collider.center.addScaledVector( normal, - d );
...@@ -231,6 +231,7 @@ ...@@ -231,6 +231,7 @@
} }
} }
} }
} }
...@@ -336,18 +337,24 @@ ...@@ -336,18 +337,24 @@
gltf.scene.traverse( child => { gltf.scene.traverse( child => {
if ( child.type === 'Mesh' ) { if ( child.isMesh ) {
child.castShadow = true; child.castShadow = true;
child.receiveShadow = true; child.receiveShadow = true;
if ( child.material.map ) {
child.material.map.anisotropy = 8;
}
} }
} ); } );
animate(); animate();
}); } );
function animate() { function animate() {
...@@ -370,4 +377,4 @@ ...@@ -370,4 +377,4 @@
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册