提交 9f273f7b 编写于 作者: M Michael Guerrero

Merge remote-tracking branch 'doob_three/dev' into dev-update-marine-character

此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="../../" />
<script src="list.js"></script>
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
<h1>[name]</h1>
<div class="desc">Class for loading an [page:String AudioBuffer].</div>
<h2>Constructor</h2>
<h3>[name]( [page:String context], [page:LoadingManager manager] )</h3>
<div>
[page:String context] — The [page:String AudioContext] for the loader to use. Default is [page:String window.AudioContext].<br />
[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
</div>
<div>
Creates a new [name].
</div>
<h2>Methods</h2>
<h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
<div>
[page:String url] — required<br />
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded text response.<br />
[page:Function onProgress] — Will be called while load progresses. The argument will be the XmlHttpRequest instance, that contain .[page:Integer total] and .[page:Integer loaded] bytes.<br />
[page:Function onError] — Will be called when load errors.<br />
</div>
<div>
Begin loading from url and pass the loaded [page:String AudioBuffer] to onLoad.
</div>
<h2>Example</h2>
<code>
// instantiate a listener
var audioListener = new THREE.AudioListener();
// add the listener to the camera
camera.add( audioListener );
// instantiate audio object
var oceanAmbientSound = new THREE.Audio( audioListener );
// add the audio object to the scene
scene.add( oceanAmbientSound );
// instantiate a loader
var loader = new THREE.AudioLoader();
// load a resource
loader.load(
// resource URL
'audio/ambient_ocean.ogg',
// Function when resource is loaded
function ( audioBuffer ) {
// set the audio object buffer to the loaded object
oceanAmbientSound.setBuffer( audioBuffer );
// play the audio
oceanAmbientSound.play();
},
// Function called when download progresses
function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
// Function called when download errors
function ( xhr ) {
console.log( 'An error happened' );
}
);
</code>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</body>
</html>
......@@ -45,6 +45,7 @@ var list = {
"Loaders": [
[ "AudioLoader", "api/loaders/AudioLoader" ],
[ "BabylonLoader", "api/loaders/BabylonLoader" ],
[ "BufferGeometryLoader", "api/loaders/BufferGeometryLoader" ],
[ "Cache", "api/loaders/Cache" ],
......
......@@ -8,7 +8,6 @@ var files = {
"webgl_camera_logarithmicdepthbuffer",
"webgl_decals",
"webgl_effects_anaglyph",
"webgl_effects_cardboard",
"webgl_effects_parallaxbarrier",
"webgl_effects_peppersghost",
"webgl_effects_stereo",
......@@ -239,6 +238,7 @@ var files = {
"webvr_cubes",
"webvr_panorama",
"webvr_rollercoaster",
"webvr_shadow",
"webvr_video"
],
"css3d": [
......
......@@ -333,9 +333,9 @@
function selectFile( file ) {
if ( selected !== null ) links[ selected ].className = 'link';
if ( selected !== null ) links[ selected ].classList.remove( 'selected' );
links[ file ].className = 'link selected';
links[ file ].classList.add( 'selected' );
window.location.hash = file;
viewer.focus();
......
......@@ -91,7 +91,7 @@ THREE.VRControls = function ( object, onError ) {
};
this.resetSensor = function () {
this.resetPose = function () {
if ( vrInput ) {
......@@ -115,10 +115,17 @@ THREE.VRControls = function ( object, onError ) {
};
this.resetSensor = function () {
console.warn( 'THREE.VRControls: .resetSensor() is now .resetPose().' );
this.resetPose();
};
this.zeroSensor = function () {
console.warn( 'THREE.VRControls: .zeroSensor() is now .resetSensor().' );
this.resetSensor();
console.warn( 'THREE.VRControls: .zeroSensor() is now .resetPose().' );
this.resetPose();
};
......
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.CardboardEffect = function ( renderer ) {
var _camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
var _scene = new THREE.Scene();
var _stereo = new THREE.StereoCamera();
_stereo.aspect = 0.5;
var _params = { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
var _renderTarget = new THREE.WebGLRenderTarget( 512, 512, _params );
_renderTarget.scissorTest = true;
// Distortion Mesh ported from:
// https://github.com/borismus/webvr-boilerplate/blob/master/src/distortion/barrel-distortion-fragment.js
var distortion = new THREE.Vector2( 0.441, 0.156 );
var geometry = new THREE.PlaneBufferGeometry( 1, 1, 10, 20 ).removeAttribute( 'normal' ).toNonIndexed();
var positions = geometry.attributes.position.array;
var uvs = geometry.attributes.uv.array;
// duplicate
var positions2 = new Float32Array( positions.length * 2 );
positions2.set( positions );
positions2.set( positions, positions.length );
var uvs2 = new Float32Array( uvs.length * 2 );
uvs2.set( uvs );
uvs2.set( uvs, uvs.length );
var vector = new THREE.Vector2();
var length = positions.length / 3;
for ( var i = 0, l = positions2.length / 3; i < l; i ++ ) {
vector.x = positions2[ i * 3 + 0 ];
vector.y = positions2[ i * 3 + 1 ];
var dot = vector.dot( vector );
var scalar = 1.5 + ( distortion.x + distortion.y * dot ) * dot;
var offset = i < length ? 0 : 1;
positions2[ i * 3 + 0 ] = ( vector.x / scalar ) * 1.5 - 0.5 + offset;
positions2[ i * 3 + 1 ] = ( vector.y / scalar ) * 3.0;
uvs2[ i * 2 ] = ( uvs2[ i * 2 ] + offset ) * 0.5;
}
geometry.attributes.position.array = positions2;
geometry.attributes.uv.array = uvs2;
//
// var material = new THREE.MeshBasicMaterial( { wireframe: true } );
var material = new THREE.MeshBasicMaterial( { map: _renderTarget } );
var mesh = new THREE.Mesh( geometry, material );
_scene.add( mesh );
//
this.setSize = function ( width, height ) {
renderer.setSize( width, height );
var pixelRatio = renderer.getPixelRatio();
_renderTarget.setSize( width * pixelRatio, height * pixelRatio );
};
this.render = function ( scene, camera ) {
scene.updateMatrixWorld();
if ( camera.parent === null ) camera.updateMatrixWorld();
_stereo.update( camera );
var width = _renderTarget.width / 2;
var height = _renderTarget.height;
_renderTarget.scissor.set( 0, 0, width, height );
_renderTarget.viewport.set( 0, 0, width, height );
renderer.render( scene, _stereo.cameraL, _renderTarget );
_renderTarget.scissor.set( width, 0, width, height );
_renderTarget.viewport.set( width, 0, width, height );
renderer.render( scene, _stereo.cameraR, _renderTarget );
renderer.render( _scene, _camera );
};
};
......@@ -390,36 +390,36 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
x_start = 0;
x_step = 1;
x_end = width;
y_start = 0;
y_step = 1;
y_end = height;
y_start = height - 1;
y_step = -1;
y_end = -1;
break;
case TGA_ORIGIN_BL:
x_start = 0;
x_step = 1;
x_end = width;
y_start = height - 1;
y_step = - 1;
y_end = - 1;
y_start = 0;
y_step = 1;
y_end = height;
break;
case TGA_ORIGIN_UR:
x_start = width - 1;
x_step = - 1;
x_end = - 1;
y_start = 0;
y_step = 1;
y_end = height;
y_start = height - 1;
y_step = -1;
y_end = -1;
break;
case TGA_ORIGIN_BR:
x_start = width - 1;
x_step = - 1;
x_end = - 1;
y_start = height - 1;
y_step = - 1;
y_end = - 1;
y_start = 0;
y_step = 1;
y_end = height;
break;
}
......
......@@ -78,7 +78,6 @@
var listener = new THREE.AudioListener();
camera.add( listener );
scene = new THREE.Scene();
scene.fog = new THREE.FogExp2( 0x000000, 0.0025 );
......@@ -94,14 +93,18 @@
// sound spheres
var audioLoader = new THREE.AudioLoader();
var mesh1 = new THREE.Mesh( sphere, material_sphere1 );
mesh1.position.set( -250, 30, 0 );
scene.add( mesh1 );
var sound1 = new THREE.PositionalAudio( listener );
sound1.load( 'sounds/358232_j_s_song.ogg' );
sound1.setRefDistance( 20 );
sound1.autoplay = true;
audioLoader.load( 'sounds/358232_j_s_song.ogg', function( buffer ) {
sound1.setBuffer( buffer );
sound1.setRefDistance( 20 );
sound1.play();
});
mesh1.add( sound1 );
//
......@@ -111,9 +114,11 @@
scene.add( mesh2 );
var sound2 = new THREE.PositionalAudio( listener );
sound2.load( 'sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg' );
sound2.setRefDistance( 20 );
sound2.autoplay = true;
audioLoader.load( 'sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg', function( buffer ) {
sound2.setBuffer( buffer );
sound2.setRefDistance( 20 );
sound2.play();
});
mesh2.add( sound2 );
//
......@@ -142,10 +147,12 @@
// global ambient audio
var sound4 = new THREE.Audio( listener );
sound4.load( 'sounds/Project_Utopia.ogg' );
sound4.autoplay = true;
sound4.setLoop(true);
sound4.setVolume(0.5);
audioLoader.load( 'sounds/Project_Utopia.ogg', function( buffer ) {
sound4.setBuffer( buffer );
sound4.setLoop(true);
sound4.setVolume(0.5);
sound4.play();
});
// ground
......
......@@ -121,18 +121,17 @@
light.castShadow = true;
light.shadowMapWidth = 1024;
light.shadowMapHeight = 1024;
light.shadow.mapSize.width = 1024;
light.shadow.mapSize.heigth = 1024;
var d = 390;
light.shadowCameraLeft = -d;
light.shadowCameraRight = d;
light.shadowCameraTop = d * 1.5;
light.shadowCameraBottom = -d;
light.shadow.camera.left = -d;
light.shadow.camera.right = d;
light.shadow.camera.top = d * 1.5;
light.shadow.camera.bottom = -d;
light.shadowCameraFar = 3500;
//light.shadowCameraVisible = true;
light.shadow.camera.far = 3500;
// RENDERER
......@@ -160,8 +159,6 @@
var loader = new THREE.JSONLoader();
loader.load( "models/skinned/knight.js", function ( geometry, materials ) {
console.log( 'materials', materials );
createScene( geometry, materials, 0, FLOOR, -300, 60 )
// GUI
......
......@@ -124,14 +124,14 @@
geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
var colors = new Float32Array( triangles * 3 * 4 );
var colors = new Uint8Array( triangles * 3 * 4 );
for ( var i = 0, l = triangles * 3 * 4; i < l; i += 4 ) {
colors[ i ] = Math.random();
colors[ i + 1 ] = Math.random();
colors[ i + 2 ] = Math.random();
colors[ i + 3 ] = Math.random();
colors[ i ] = Math.random() * 255;
colors[ i + 1 ] = Math.random() * 255;
colors[ i + 2 ] = Math.random() * 255;
colors[ i + 3 ] = Math.random() * 255;
}
......
......@@ -70,12 +70,12 @@
var light = new THREE.SpotLight( 0xffffff, 1.5 );
light.position.set( 0, 1500, 200 );
light.castShadow = true;
light.shadowCameraNear = 200;
light.shadowCameraFar = 2000;
light.shadowCameraFov = 70;
light.shadowBias = -0.000222;
light.shadowMapWidth = 1024;
light.shadowMapHeight = 1024;
light.shadow.camera.near = 200;
light.shadow.camera.far = 2000;
light.shadow.camera.fov = 70;
light.shadow.bias = -0.000222;
light.shadow.mapSize.width = 1024;
light.shadow.mapSize.height = 1024;
scene.add( light );
spotlight = light;
......
......@@ -60,14 +60,14 @@
light.position.set( 0, 500, 2000 );
light.castShadow = true;
light.shadowCameraNear = 200;
light.shadowCameraFar = camera.far;
light.shadowCameraFov = 50;
light.shadow.camera.near = 200;
light.shadow.camera.far = camera.far;
light.shadow.camera.fov = 50;
light.shadowBias = -0.00022;
light.shadow.bias = -0.00022;
light.shadowMapWidth = 2048;
light.shadowMapHeight = 2048;
light.shadow.mapSize.width = 2048;
light.shadow.mapSize.height = 2048;
scene.add( light );
......
......@@ -160,7 +160,7 @@
}
geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
geometry.addDrawCall( 0, indices.length );
geometry.addGroup( 0, indices.length );
var material = new THREE.PointsMaterial( { size: pointSize, vertexColors: THREE.VertexColors } );
var pointcloud = new THREE.Points( geometry, material );
......
......@@ -105,14 +105,17 @@
light.position.set( 200, 450, 500 );
light.castShadow = true;
light.shadowMapWidth = 1024;
light.shadowMapHeight = 512;
light.shadowCameraNear = 100;
light.shadowCameraFar = 1200;
light.shadowCameraTop = 350;
light.shadowCameraBottom = -350;
light.shadowCameraRight = 1000;
light.shadowCameraLeft = -1000;
light.shadow.mapSize.width = 1024;
light.shadow.mapSize.height = 512;
light.shadow.camera.near = 100;
light.shadow.camera.far = 1200;
light.shadow.camera.left = -1000;
light.shadow.camera.right = 1000;
light.shadow.camera.top = 350;
light.shadow.camera.bottom = -350;
scene.add( light );
// scene.add( new THREE.CameraHelper( light.shadow.camera ) );
......
......@@ -150,21 +150,20 @@
scene.add( directionalLight );
directionalLight.castShadow = true;
// directionalLight.shadowCameraVisible = true;
var d = 1;
directionalLight.shadowCameraLeft = -d;
directionalLight.shadowCameraRight = d;
directionalLight.shadowCameraTop = d;
directionalLight.shadowCameraBottom = -d;
directionalLight.shadow.camera.left = -d;
directionalLight.shadow.camera.right = d;
directionalLight.shadow.camera.top = d;
directionalLight.shadow.camera.bottom = -d;
directionalLight.shadowCameraNear = 1;
directionalLight.shadowCameraFar = 4;
directionalLight.shadow.camera.near = 1;
directionalLight.shadow.camera.far = 4;
directionalLight.shadowMapWidth = 1024;
directionalLight.shadowMapHeight = 1024;
directionalLight.shadow.mapSize.width = 1024;
directionalLight.shadow.mapSize.height = 1024;
directionalLight.shadowBias = -0.005;
directionalLight.shadow.bias = -0.005;
}
......
......@@ -204,21 +204,20 @@
scene.add( directionalLight );
directionalLight.castShadow = true;
// directionalLight.shadowCameraVisible = true;
var d = 1;
directionalLight.shadowCameraLeft = -d;
directionalLight.shadowCameraRight = d;
directionalLight.shadowCameraTop = d;
directionalLight.shadowCameraBottom = -d;
directionalLight.shadow.camera.left = -d;
directionalLight.shadow.camera.right = d;
directionalLight.shadow.camera.top = d;
directionalLight.shadow.camera.bottom = -d;
directionalLight.shadowCameraNear = 1;
directionalLight.shadowCameraFar = 4;
directionalLight.shadow.camera.near = 1;
directionalLight.shadow.camera.far = 4;
directionalLight.shadowMapWidth = 1024;
directionalLight.shadowMapHeight = 1024;
directionalLight.shadow.mapSize.width = 1024;
directionalLight.shadow.mapSize.height = 1024;
directionalLight.shadowBias = -0.005;
directionalLight.shadow.bias = -0.005;
}
......
......@@ -96,20 +96,19 @@
scene.add( directionalLight );
directionalLight.castShadow = true;
// directionalLight.shadowCameraVisible = true;
directionalLight.shadowMapWidth = 2048;
directionalLight.shadowMaHeight = 2048;
directionalLight.shadow.mapSize.width = 2048;
directionalLight.shadow.mapSize.height = 2048;
var d = 150;
directionalLight.shadowCameraLeft = -d * 1.2;
directionalLight.shadowCameraRight = d * 1.2;
directionalLight.shadowCameraTop = d;
directionalLight.shadowCameraBottom = -d;
directionalLight.shadow.camera.left = -d * 1.2;
directionalLight.shadow.camera.right = d * 1.2;
directionalLight.shadow.camera.top = d;
directionalLight.shadow.camera.bottom = -d;
directionalLight.shadowCameraNear = 200;
directionalLight.shadowCameraFar = 500;
directionalLight.shadow.camera.near = 200;
directionalLight.shadow.camera.far = 500;
// RENDERER
......
......@@ -101,17 +101,16 @@
scene.add( spotLight );
spotLight.castShadow = true;
// spotLight.shadowCameraVisible = true;
spotLight.shadowMapWidth = 2048;
spotLight.shadowMapHeight = 2048;
spotLight.shadow.mapSize.width = 2048;
spotLight.shadow.mapSize.height = 2048;
spotLight.shadowCameraNear = 200;
spotLight.shadowCameraFar = 1500;
spotLight.shadow.camera.near = 200;
spotLight.shadow.camera.far = 1500;
spotLight.shadowCameraFov = 40;
spotLight.shadow.camera.fov = 40;
spotLight.shadowBias = -0.005;
spotLight.shadow.bias = -0.005;
//
......
......@@ -111,20 +111,19 @@
directionalLight.position.set( 500, 0, 500 );
directionalLight.castShadow = true;
//directionalLight.shadowCameraVisible = true;
directionalLight.shadowMapWidth = 2048;
directionalLight.shadowMapHeight = 2048;
directionalLight.shadow.mapSize.width = 2048;
directionalLight.shadow.mapSize.height = 2048;
directionalLight.shadowCameraNear = 200;
directionalLight.shadowCameraFar = 1500;
directionalLight.shadow.camera.near = 200;
directionalLight.shadow.camera.far = 1500;
directionalLight.shadowCameraLeft = -500;
directionalLight.shadowCameraRight = 500;
directionalLight.shadowCameraTop = 500;
directionalLight.shadowCameraBottom = -500;
directionalLight.shadow.camera.left = -500;
directionalLight.shadow.camera.right = 500;
directionalLight.shadow.camera.top = 500;
directionalLight.shadow.camera.bottom = -500;
directionalLight.shadowBias = -0.005;
directionalLight.shadow.bias = -0.005;
scene.add( directionalLight );
......
......@@ -169,21 +169,16 @@
spotLight.target.position.set( 0, 0, 0 );
spotLight.castShadow = true;
spotLight.shadowCameraNear = 100;
spotLight.shadowCameraFar = camera.far;
spotLight.shadowCameraFov = 50;
spotLight.shadow.camera.near = 100;
spotLight.shadow.camera.far = camera.far;
spotLight.shadow.camera.fov = 50;
spotLight.shadowBias = -0.00125;
spotLight.shadowMapWidth = SHADOW_MAP_WIDTH;
spotLight.shadowMapHeight = SHADOW_MAP_HEIGHT;
spotLight.shadow.bias = -0.00125;
spotLight.shadow.mapSize.width = SHADOW_MAP_WIDTH;
spotLight.shadow.mapSize.height = SHADOW_MAP_HEIGHT;
scene.add( spotLight );
directionalLight2 = new THREE.PointLight( 0xff9900, 0.25 );
directionalLight2.position.set( 0.5, -1, 0.5 );
//directionalLight2.position.normalize();
//scene.add( directionalLight2 );
// RENDERER
renderer = new THREE.WebGLRenderer( { antialias: false } );
......
......@@ -77,7 +77,6 @@
// add box 1 - grey8 texture
var texture1 = loader.load( 'textures/crate_grey8.tga' );
texture1.flipY = true;
var material1 = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture1 } );
......@@ -89,7 +88,6 @@
// add box 2 - tga texture
var texture2 = loader.load( 'textures/crate_color8.tga' );
texture2.flipY = true;
var material2 = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture2 } );
......
......@@ -111,16 +111,13 @@
light.castShadow = true;
light.shadowCameraNear = 1200;
light.shadowCameraFar = 2500;
light.shadowCameraFov = 50;
light.shadow.camera.near = 1200;
light.shadow.camera.far = 2500;
light.shadow.camera.fov = 50;
light.shadow.bias = 0.0001;
//light.shadowCameraVisible = true;
light.shadowBias = 0.0001;
light.shadowMapWidth = SHADOW_MAP_WIDTH;
light.shadowMapHeight = SHADOW_MAP_HEIGHT;
light.shadow.mapSize.width = SHADOW_MAP_WIDTH;
light.shadow.mapSize.height = SHADOW_MAP_HEIGHT;
scene.add( light );
......
......@@ -106,16 +106,14 @@
light.castShadow = true;
light.shadowCameraNear = 700;
light.shadowCameraFar = camera.far;
light.shadowCameraFov = 50;
light.shadow.camera.near = 700;
light.shadow.camera.far = camera.far;
light.shadow.camera.fov = 50;
//light.shadowCameraVisible = true;
light.shadow.bias = 0.0001;
light.shadowBias = 0.0001;
light.shadowMapWidth = SHADOW_MAP_WIDTH;
light.shadowMapHeight = SHADOW_MAP_HEIGHT;
light.shadow.mapSize.width = SHADOW_MAP_WIDTH;
light.shadow.mapSize.height = SHADOW_MAP_HEIGHT;
scene.add( light );
......
......@@ -76,10 +76,10 @@
spotLight.penumbra = 0.3;
spotLight.position.set( 10, 10, 5 );
spotLight.castShadow = true;
spotLight.shadowCameraNear = 8;
spotLight.shadowCameraFar = 30;
spotLight.shadowMapWidth = 1024;
spotLight.shadowMapHeight = 1024;
spotLight.shadow.camera.near = 8;
spotLight.shadow.camera.far = 30;
spotLight.shadow.mapSize.width = 1024;
spotLight.shadow.mapSize.height = 1024;
scene.add( spotLight );
scene.add( new THREE.CameraHelper( spotLight.shadow.camera ) );
......@@ -88,14 +88,14 @@
dirLight.name = 'Dir. Light';
dirLight.position.set( 0, 10, 0 );
dirLight.castShadow = true;
dirLight.shadowCameraNear = 1;
dirLight.shadowCameraFar = 10;
dirLight.shadowCameraRight = 15;
dirLight.shadowCameraLeft = - 15;
dirLight.shadowCameraTop = 15;
dirLight.shadowCameraBottom = - 15;
dirLight.shadowMapWidth = 1024;
dirLight.shadowMapHeight = 1024;
dirLight.shadow.camera.near = 1;
dirLight.shadow.camera.far = 10;
dirLight.shadow.camera.right = 15;
dirLight.shadow.camera.left = - 15;
dirLight.shadow.camera.top = 15;
dirLight.shadow.camera.bottom = - 15;
dirLight.shadow.mapSize.width = 1024;
dirLight.shadow.mapSize.height = 1024;
scene.add( dirLight );
scene.add( new THREE.CameraHelper( dirLight.shadow.camera ) );
......
......@@ -14,11 +14,22 @@
<body>
<script src="../build/three.min.js"></script>
<script src="js/effects/CardboardEffect.js"></script>
<script src="js/WebVR.js"></script>
<script src="js/controls/VRControls.js"></script>
<script src="js/effects/VREffect.js"></script>
<script>
if ( WEBVR.isLatestAvailable() === false ) {
document.body.appendChild( WEBVR.getMessage() );
}
//
var camera, scene, renderer;
var effect;
var effect, controls;
init();
animate();
......@@ -27,10 +38,13 @@
scene = new THREE.Scene();
var dummy = new THREE.Camera();
dummy.position.set( 2, 1, 2 );
dummy.lookAt( scene.position );
scene.add( dummy );
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10 );
camera.position.set( 3, 2, 3 );
camera.focalLength = camera.position.distanceTo( scene.position );
camera.lookAt( scene.position );
dummy.add( camera );
var geometry = new THREE.TorusKnotGeometry( 0.4, 0.15, 150, 20 );;
var material = new THREE.MeshStandardMaterial( { roughness: 0.01, metalness: 0.2 } );
......@@ -62,39 +76,23 @@
//
renderer = new THREE.WebGLRenderer( { antialias: false } );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setClearColor( 0x101010 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true;
document.body.appendChild( renderer.domElement );
renderer.domElement.addEventListener( 'click', function () {
if ( this.requestFullscreen ) {
this.requestFullscreen();
} else if ( this.msRequestFullscreen ) {
this.msRequestFullscreen();
} else if ( this.mozRequestFullScreen ) {
this.mozRequestFullScreen();
} else if ( this.webkitRequestFullscreen ) {
this.webkitRequestFullscreen();
//
}
controls = new THREE.VRControls( camera );
effect = new THREE.VREffect( renderer );
} );
if ( WEBVR.isAvailable() === true ) {
//
document.body.appendChild( WEBVR.getButton( effect ) );
effect = new THREE.CardboardEffect( renderer );
effect.setSize( window.innerWidth, window.innerHeight );
}
//
......@@ -121,14 +119,12 @@
function render() {
var time = performance.now() * 0.0002;
camera.position.x = Math.cos( time ) * 4;
camera.position.z = Math.sin( time ) * 4;
camera.lookAt( new THREE.Vector3() );
var mesh = scene.children[ 0 ];
var mesh = scene.children[ 1 ];
mesh.rotation.x = time * 2;
mesh.rotation.y = time * 5;
controls.update();
effect.render( scene, camera );
}
......
/**
* @author mrdoob / http://mrdoob.com/
* @author Reece Aaron Lecrivain / http://reecenotes.com/
*/
THREE.Audio = function ( listener ) {
......@@ -38,10 +39,16 @@ THREE.Audio.prototype.getOutput = function () {
THREE.Audio.prototype.load = function ( file ) {
var buffer = new THREE.AudioBuffer( this.context );
buffer.load( file );
console.warn( 'THREE.Audio: .load has been deprecated. Please use THREE.AudioLoader.' );
this.setBuffer( buffer );
var scope = this;
var audioLoader = new THREE.AudioLoader();
audioLoader.load( file, function ( buffer ) {
scope.setBuffer( buffer );
} );
return this;
......@@ -62,13 +69,9 @@ THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
var scope = this;
audioBuffer.onReady( function( buffer ) {
scope.source.buffer = buffer;
scope.sourceType = 'buffer';
if ( scope.autoplay ) scope.play();
} );
scope.source.buffer = audioBuffer;
scope.sourceType = 'buffer';
if ( scope.autoplay ) scope.play();
return this;
......@@ -213,7 +216,7 @@ THREE.Audio.prototype.getPlaybackRate = function () {
};
THREE.Audio.prototype.onEnded = function() {
THREE.Audio.prototype.onEnded = function () {
this.isPlaying = false;
......
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.AudioBuffer = function ( context ) {
this.context = context;
this.ready = false;
this.readyCallbacks = [];
};
THREE.AudioBuffer.prototype.load = function ( file ) {
var scope = this;
var request = new XMLHttpRequest();
request.open( 'GET', file, true );
request.responseType = 'arraybuffer';
request.onload = function ( e ) {
scope.context.decodeAudioData( this.response, function ( buffer ) {
scope.buffer = buffer;
scope.ready = true;
for ( var i = 0; i < scope.readyCallbacks.length; i ++ ) {
scope.readyCallbacks[ i ]( scope.buffer );
}
scope.readyCallbacks = [];
} );
};
request.send();
return this;
};
THREE.AudioBuffer.prototype.onReady = function ( callback ) {
if ( this.ready ) {
callback( this.buffer );
} else {
this.readyCallbacks.push( callback );
}
};
/**
* @author mrdoob / http://mrdoob.com/
*/
Object.defineProperty( THREE, 'AudioContext', {
get: ( function () {
var context;
return function () {
if ( context === undefined ) {
context = new ( window.AudioContext || window.webkitAudioContext )();
}
return context;
};
} )()
} );
......@@ -8,7 +8,7 @@ THREE.AudioListener = function () {
this.type = 'AudioListener';
this.context = new ( window.AudioContext || window.webkitAudioContext )();
this.context = THREE.AudioContext;
this.gain = this.context.createGain();
this.gain.connect( this.context.destination );
......
/**
* @author Reece Aaron Lecrivain / http://reecenotes.com/
*/
THREE.AudioLoader = function ( manager ) {
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
};
THREE.AudioLoader.prototype = {
constructor: THREE.AudioLoader,
load: function ( url, onLoad, onProgress, onError ) {
var loader = new THREE.XHRLoader( this.manager );
loader.setResponseType( 'arraybuffer' );
loader.load( url, function ( buffer ) {
var context = THREE.AudioContext;
context.decodeAudioData( buffer, function ( audioBuffer ) {
onLoad( audioBuffer );
} );
}, onProgress, onError );
}
};
......@@ -1015,8 +1015,19 @@ THREE.WebGLRenderer = function ( parameters ) {
}
var type = _gl.FLOAT;
var normalized = false;
var array = geometryAttribute.array;
if ( array instanceof Uint8Array ) {
type = _gl.UNSIGNED_BYTE;
normalized = true;
}
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
_gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
_gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * array.BYTES_PER_ELEMENT );
}
......
......@@ -54,7 +54,7 @@
"src/animation/tracks/VectorKeyframeTrack.js",
"src/audio/Audio.js",
"src/audio/AudioAnalyser.js",
"src/audio/AudioBuffer.js",
"src/audio/AudioContext.js",
"src/audio/PositionalAudio.js",
"src/audio/AudioListener.js",
"src/cameras/Camera.js",
......@@ -69,6 +69,7 @@
"src/lights/HemisphereLight.js",
"src/lights/PointLight.js",
"src/lights/SpotLight.js",
"src/loaders/AudioLoader.js",
"src/loaders/Cache.js",
"src/loaders/Loader.js",
"src/loaders/XHRLoader.js",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册