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

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

......@@ -16273,6 +16273,7 @@ THREE.VectorKeyframeTrack.prototype =
/**
* @author mrdoob / http://mrdoob.com/
* @author Reece Aaron Lecrivain / http://reecenotes.com/
*/
THREE.Audio = function ( listener ) {
......@@ -16311,10 +16312,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;
......@@ -16335,13 +16342,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;
......@@ -16486,7 +16489,7 @@ THREE.Audio.prototype.getPlaybackRate = function () {
};
THREE.Audio.prototype.onEnded = function() {
THREE.Audio.prototype.onEnded = function () {
this.isPlaying = false;
......@@ -16561,64 +16564,33 @@ THREE.AudioAnalyser.prototype = {
};
// File:src/audio/AudioBuffer.js
// File:src/audio/AudioContext.js
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.AudioBuffer = function ( context ) {
Object.defineProperty( THREE, 'AudioContext', {
this.context = context;
this.ready = false;
this.readyCallbacks = [];
};
get: ( function () {
THREE.AudioBuffer.prototype.load = function ( file ) {
var context;
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;
return function () {
for ( var i = 0; i < scope.readyCallbacks.length; i ++ ) {
if ( context === undefined ) {
scope.readyCallbacks[ i ]( scope.buffer );
context = new ( window.AudioContext || window.webkitAudioContext )();
}
scope.readyCallbacks = [];
} );
};
request.send();
return context;
return this;
};
THREE.AudioBuffer.prototype.onReady = function ( callback ) {
if ( this.ready ) {
callback( this.buffer );
} else {
this.readyCallbacks.push( callback );
};
}
} )()
};
} );
// File:src/audio/PositionalAudio.js
......@@ -16720,7 +16692,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 );
......@@ -17608,6 +17580,42 @@ THREE.SpotLight.prototype.copy = function ( source ) {
};
// File:src/loaders/AudioLoader.js
/**
* @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 );
}
};
// File:src/loaders/Cache.js
/**
......@@ -24179,14 +24187,14 @@ THREE.ShaderLib = {
uniforms: THREE.UniformsUtils.merge( [
THREE.UniformsLib[ "common" ],
THREE.UniformsLib[ "aomap" ],
THREE.UniformsLib[ "fog" ]
THREE.UniformsLib[ 'common' ],
THREE.UniformsLib[ 'aomap' ],
THREE.UniformsLib[ 'fog' ]
] ),
vertexShader: THREE.ShaderChunk['meshbasic_vert'],
fragmentShader: THREE.ShaderChunk['meshbasic_frag']
vertexShader: THREE.ShaderChunk[ 'meshbasic_vert' ],
fragmentShader: THREE.ShaderChunk[ 'meshbasic_frag' ]
},
......@@ -24194,12 +24202,12 @@ THREE.ShaderLib = {
uniforms: THREE.UniformsUtils.merge( [
THREE.UniformsLib[ "common" ],
THREE.UniformsLib[ "aomap" ],
THREE.UniformsLib[ "lightmap" ],
THREE.UniformsLib[ "emissivemap" ],
THREE.UniformsLib[ "fog" ],
THREE.UniformsLib[ "lights" ],
THREE.UniformsLib[ 'common' ],
THREE.UniformsLib[ 'aomap' ],
THREE.UniformsLib[ 'lightmap' ],
THREE.UniformsLib[ 'emissivemap' ],
THREE.UniformsLib[ 'fog' ],
THREE.UniformsLib[ 'lights' ],
{
"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
......@@ -24207,8 +24215,8 @@ THREE.ShaderLib = {
] ),
vertexShader: THREE.ShaderChunk['meshlambert_vert'],
fragmentShader: THREE.ShaderChunk['meshlambert_frag']
vertexShader: THREE.ShaderChunk[ 'meshlambert_vert' ],
fragmentShader: THREE.ShaderChunk[ 'meshlambert_frag' ]
},
......@@ -24216,15 +24224,15 @@ THREE.ShaderLib = {
uniforms: THREE.UniformsUtils.merge( [
THREE.UniformsLib[ "common" ],
THREE.UniformsLib[ "aomap" ],
THREE.UniformsLib[ "lightmap" ],
THREE.UniformsLib[ "emissivemap" ],
THREE.UniformsLib[ "bumpmap" ],
THREE.UniformsLib[ "normalmap" ],
THREE.UniformsLib[ "displacementmap" ],
THREE.UniformsLib[ "fog" ],
THREE.UniformsLib[ "lights" ],
THREE.UniformsLib[ 'common' ],
THREE.UniformsLib[ 'aomap' ],
THREE.UniformsLib[ 'lightmap' ],
THREE.UniformsLib[ 'emissivemap' ],
THREE.UniformsLib[ 'bumpmap' ],
THREE.UniformsLib[ 'normalmap' ],
THREE.UniformsLib[ 'displacementmap' ],
THREE.UniformsLib[ 'fog' ],
THREE.UniformsLib[ 'lights' ],
{
"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
......@@ -24234,8 +24242,8 @@ THREE.ShaderLib = {
] ),
vertexShader: THREE.ShaderChunk['meshphong_vert'],
fragmentShader: THREE.ShaderChunk['meshphong_frag']
vertexShader: THREE.ShaderChunk[ 'meshphong_vert' ],
fragmentShader: THREE.ShaderChunk[ 'meshphong_frag' ]
},
......@@ -24243,17 +24251,17 @@ THREE.ShaderLib = {
uniforms: THREE.UniformsUtils.merge( [
THREE.UniformsLib[ "common" ],
THREE.UniformsLib[ "aomap" ],
THREE.UniformsLib[ "lightmap" ],
THREE.UniformsLib[ "emissivemap" ],
THREE.UniformsLib[ "bumpmap" ],
THREE.UniformsLib[ "normalmap" ],
THREE.UniformsLib[ "displacementmap" ],
THREE.UniformsLib[ "roughnessmap" ],
THREE.UniformsLib[ "metalnessmap" ],
THREE.UniformsLib[ "fog" ],
THREE.UniformsLib[ "lights" ],
THREE.UniformsLib[ 'common' ],
THREE.UniformsLib[ 'aomap' ],
THREE.UniformsLib[ 'lightmap' ],
THREE.UniformsLib[ 'emissivemap' ],
THREE.UniformsLib[ 'bumpmap' ],
THREE.UniformsLib[ 'normalmap' ],
THREE.UniformsLib[ 'displacementmap' ],
THREE.UniformsLib[ 'roughnessmap' ],
THREE.UniformsLib[ 'metalnessmap' ],
THREE.UniformsLib[ 'fog' ],
THREE.UniformsLib[ 'lights' ],
{
"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
......@@ -24264,8 +24272,8 @@ THREE.ShaderLib = {
] ),
vertexShader: THREE.ShaderChunk['meshstandard_vert'],
fragmentShader: THREE.ShaderChunk['meshstandard_frag']
vertexShader: THREE.ShaderChunk[ 'meshstandard_vert' ],
fragmentShader: THREE.ShaderChunk[ 'meshstandard_frag' ]
},
......@@ -24273,13 +24281,13 @@ THREE.ShaderLib = {
uniforms: THREE.UniformsUtils.merge( [
THREE.UniformsLib[ "points" ],
THREE.UniformsLib[ "fog" ]
THREE.UniformsLib[ 'points' ],
THREE.UniformsLib[ 'fog' ]
] ),
vertexShader: THREE.ShaderChunk['points_vert'],
fragmentShader: THREE.ShaderChunk['points_frag']
vertexShader: THREE.ShaderChunk[ 'points_vert' ],
fragmentShader: THREE.ShaderChunk[ 'points_frag' ]
},
......@@ -24287,8 +24295,8 @@ THREE.ShaderLib = {
uniforms: THREE.UniformsUtils.merge( [
THREE.UniformsLib[ "common" ],
THREE.UniformsLib[ "fog" ],
THREE.UniformsLib[ 'common' ],
THREE.UniformsLib[ 'fog' ],
{
"scale" : { type: "1f", value: 1 },
......@@ -24298,8 +24306,8 @@ THREE.ShaderLib = {
] ),
vertexShader: THREE.ShaderChunk['linedashed_vert'],
fragmentShader: THREE.ShaderChunk['linedashed_frag']
vertexShader: THREE.ShaderChunk[ 'linedashed_vert' ],
fragmentShader: THREE.ShaderChunk[ 'linedashed_frag' ]
},
......@@ -24313,8 +24321,8 @@ THREE.ShaderLib = {
},
vertexShader: THREE.ShaderChunk['depth_vert'],
fragmentShader: THREE.ShaderChunk['depth_frag']
vertexShader: THREE.ShaderChunk[ 'depth_vert' ],
fragmentShader: THREE.ShaderChunk[ 'depth_frag' ]
},
......@@ -24326,8 +24334,8 @@ THREE.ShaderLib = {
},
vertexShader: THREE.ShaderChunk['normal_vert'],
fragmentShader: THREE.ShaderChunk['normal_frag']
vertexShader: THREE.ShaderChunk[ 'normal_vert' ],
fragmentShader: THREE.ShaderChunk[ 'normal_frag' ]
},
......@@ -24342,8 +24350,8 @@ THREE.ShaderLib = {
"tFlip": { type: "1f", value: - 1 }
},
vertexShader: THREE.ShaderChunk['cube_vert'],
fragmentShader: THREE.ShaderChunk['cube_frag']
vertexShader: THREE.ShaderChunk[ 'cube_vert' ],
fragmentShader: THREE.ShaderChunk[ 'cube_frag' ]
},
......@@ -24358,8 +24366,8 @@ THREE.ShaderLib = {
"tFlip": { type: "1f", value: - 1 }
},
vertexShader: THREE.ShaderChunk['equirect_vert'],
fragmentShader: THREE.ShaderChunk['equirect_frag']
vertexShader: THREE.ShaderChunk[ 'equirect_vert' ],
fragmentShader: THREE.ShaderChunk[ 'equirect_frag' ]
},
......@@ -24379,8 +24387,8 @@ THREE.ShaderLib = {
uniforms: {},
vertexShader: THREE.ShaderChunk['depthRGBA_vert'],
fragmentShader: THREE.ShaderChunk['depthRGBA_frag']
vertexShader: THREE.ShaderChunk[ 'depthRGBA_vert' ],
fragmentShader: THREE.ShaderChunk[ 'depthRGBA_frag' ]
},
......@@ -24389,12 +24397,12 @@ THREE.ShaderLib = {
uniforms: {
"lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
"lightPos": { type: "v3", value: new THREE.Vector3() }
},
vertexShader: THREE.ShaderChunk['distanceRGBA_vert'],
fragmentShader: THREE.ShaderChunk['distanceRGBA_frag']
vertexShader: THREE.ShaderChunk[ 'distanceRGBA_vert' ],
fragmentShader: THREE.ShaderChunk[ 'distanceRGBA_frag' ]
}
......@@ -25419,8 +25427,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 );
}
......@@ -26692,14 +26711,34 @@ THREE.WebGLRenderer = function ( parameters ) {
} else if ( type === 'i' ) {
console.warn( 'THREE.WebGLRenderer: Uniform "i" is now "1i".' );
// console.warn( 'THREE.WebGLRenderer: Uniform "i" is now "1i".' );
_gl.uniform1i( location, value );
} else if ( type === 'f' ) {
console.warn( 'THREE.WebGLRenderer: Uniform "f" is now "1f".' );
// console.warn( 'THREE.WebGLRenderer: Uniform "f" is now "1f".' );
_gl.uniform1f( location, value );
} else if ( type === 'iv1' ) {
// console.warn( 'THREE.WebGLRenderer: Uniform "iv1" is now "1iv".' );
_gl.uniform1iv( location, value );
} else if ( type === 'iv' ) {
// console.warn( 'THREE.WebGLRenderer: Uniform "iv" is now "3iv".' );
_gl.uniform3iv( location, value );
} else if ( type === 'fv1' ) {
// console.warn( 'THREE.WebGLRenderer: Uniform "fv1" is now "1fv".' );
_gl.uniform1fv( location, value );
} else if ( type === 'fv' ) {
// console.warn( 'THREE.WebGLRenderer: Uniform "fv" is now "3fv".' );
_gl.uniform3fv( location, value );
} else if ( type === 'v2' ) {
// single THREE.Vector2
......@@ -26756,26 +26795,6 @@ THREE.WebGLRenderer = function ( parameters ) {
}
} else if ( type === 'iv1' ) {
console.warn( 'THREE.WebGLRenderer: Uniform "iv1" is now "1iv".' );
_gl.uniform1iv( location, value );
} else if ( type === 'iv' ) {
console.warn( 'THREE.WebGLRenderer: Uniform "iv" is now "3iv".' );
_gl.uniform3iv( location, value );
} else if ( type === 'fv1' ) {
console.warn( 'THREE.WebGLRenderer: Uniform "fv1" is now "1fv".' );
_gl.uniform1fv( location, value );
} else if ( type === 'fv' ) {
console.warn( 'THREE.WebGLRenderer: Uniform "fv" is now "3fv".' );
_gl.uniform3fv( location, value );
} else if ( type === 'v2v' ) {
// array of THREE.Vector2
......@@ -31056,8 +31075,7 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
var state = renderer.state;
var vertexBuffer, elementBuffer;
var program, attributes, uniforms;
var hasVertexTexture;
var shader, program, attributes, uniforms;
var tempTexture, occlusionTexture;
......@@ -31105,193 +31123,99 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
var shader;
if ( hasVertexTexture ) {
shader = {
vertexShader: [
"uniform lowp int renderType;",
"uniform vec3 screenPosition;",
"uniform vec2 scale;",
"uniform float rotation;",
"uniform sampler2D occlusionMap;",
"attribute vec2 position;",
"attribute vec2 uv;",
"varying vec2 vUV;",
"varying float vVisibility;",
"void main() {",
shader = {
"vUV = uv;",
vertexShader: [
"vec2 pos = position;",
"uniform lowp int renderType;",
"if ( renderType == 2 ) {",
"uniform vec3 screenPosition;",
"uniform vec2 scale;",
"uniform float rotation;",
"vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
"uniform sampler2D occlusionMap;",
"vVisibility = visibility.r / 9.0;",
"vVisibility *= 1.0 - visibility.g / 9.0;",
"vVisibility *= visibility.b / 9.0;",
"vVisibility *= 1.0 - visibility.a / 9.0;",
"attribute vec2 position;",
"attribute vec2 uv;",
"pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
"pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
"varying vec2 vUV;",
"varying float vVisibility;",
"}",
"void main() {",
"gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
"vUV = uv;",
"}"
"vec2 pos = position;",
].join( "\n" ),
"if ( renderType == 2 ) {",
fragmentShader: [
"vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
"uniform lowp int renderType;",
"vVisibility = visibility.r / 9.0;",
"vVisibility *= 1.0 - visibility.g / 9.0;",
"vVisibility *= visibility.b / 9.0;",
"vVisibility *= 1.0 - visibility.a / 9.0;",
"uniform sampler2D map;",
"uniform float opacity;",
"uniform vec3 color;",
"pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
"pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
"varying vec2 vUV;",
"varying float vVisibility;",
"}",
"void main() {",
"gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
// pink square
"}"
"if ( renderType == 0 ) {",
].join( "\n" ),
"gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
fragmentShader: [
// restore
"uniform lowp int renderType;",
"} else if ( renderType == 1 ) {",
"uniform sampler2D map;",
"uniform float opacity;",
"uniform vec3 color;",
"gl_FragColor = texture2D( map, vUV );",
"varying vec2 vUV;",
"varying float vVisibility;",
// flare
"void main() {",
"} else {",
// pink square
"vec4 texture = texture2D( map, vUV );",
"texture.a *= opacity * vVisibility;",
"gl_FragColor = texture;",
"gl_FragColor.rgb *= color;",
"if ( renderType == 0 ) {",
"}",
"gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
"}"
// restore
].join( "\n" )
"} else if ( renderType == 1 ) {",
};
} else {
shader = {
vertexShader: [
"uniform lowp int renderType;",
"uniform vec3 screenPosition;",
"uniform vec2 scale;",
"uniform float rotation;",
"attribute vec2 position;",
"attribute vec2 uv;",
"varying vec2 vUV;",
"void main() {",
"vUV = uv;",
"vec2 pos = position;",
"if ( renderType == 2 ) {",
"pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
"pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
"}",
"gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
"}"
].join( "\n" ),
"gl_FragColor = texture2D( map, vUV );",
fragmentShader: [
// flare
"precision mediump float;",
"} else {",
"uniform lowp int renderType;",
"vec4 texture = texture2D( map, vUV );",
"texture.a *= opacity * vVisibility;",
"gl_FragColor = texture;",
"gl_FragColor.rgb *= color;",
"uniform sampler2D map;",
"uniform sampler2D occlusionMap;",
"uniform float opacity;",
"uniform vec3 color;",
"}",
"varying vec2 vUV;",
"}"
"void main() {",
].join( "\n" )
// pink square
"if ( renderType == 0 ) {",
"gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
// restore
"} else if ( renderType == 1 ) {",
"gl_FragColor = texture2D( map, vUV );",
// flare
"} else {",
"float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
"visibility = ( 1.0 - visibility / 4.0 );",
"vec4 texture = texture2D( map, vUV );",
"texture.a *= opacity * visibility;",
"gl_FragColor = texture;",
"gl_FragColor.rgb *= color;",
"}",
"}"
].join( "\n" )
};
}
};
program = createProgram( shader );
......@@ -31335,7 +31259,10 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
var screenPosition = new THREE.Vector3( 1, 1, 0 ),
screenPositionPixels = new THREE.Vector2( 1, 1 );
var areaToCopy = new THREE.Vector2();
var validArea = new THREE.Box2();
validArea.min.set( 0, 0 );
validArea.max.set( viewport.z - 16, viewport.w - 16 );
if ( program === undefined ) {
......@@ -31383,18 +31310,14 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
screenPosition.copy( tempPosition );
screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
// horizontal and vertical coordinate of the lower left corner of the pixels to copy
areaToCopy.x = viewport.x + screenPositionPixels.x - 8; // horizontal coordinate of the lower left corner of the pixels to copy
areaToCopy.y = viewport.y + screenPositionPixels.y - 8; // vertical coordinate of the lower left corner of the pixels to copy
screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
// screen cull
if ( areaToCopy.x > 0 &&
areaToCopy.x < ( viewport.z - 16 ) &&
areaToCopy.y > 0 &&
areaToCopy.y < ( viewport.w - 16 ) ) {
if ( validArea.containsPoint( screenPositionPixels ) === true ) {
// save current RGB to temp texture
......@@ -31402,7 +31325,7 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
state.bindTexture( gl.TEXTURE_2D, null );
state.activeTexture( gl.TEXTURE1 );
state.bindTexture( gl.TEXTURE_2D, tempTexture );
gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, areaToCopy.x, areaToCopy.y, 16, 16, 0 );
gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
// render pink quad
......@@ -31421,7 +31344,7 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
state.activeTexture( gl.TEXTURE0 );
state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, areaToCopy.x, areaToCopy.y, 16, 16, 0 );
gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
// restore graphics
......
因为 它太大了无法显示 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.
先完成此消息的编辑!
想要评论请 注册