Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
76aa9087
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
76aa9087
编写于
8月 21, 2019
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated builds.
上级
7bed038d
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
1353 addition
and
1166 deletion
+1353
-1166
build/three.js
build/three.js
+303
-211
build/three.min.js
build/three.min.js
+747
-744
build/three.module.js
build/three.module.js
+303
-211
未找到文件。
build/three.js
浏览文件 @
76aa9087
...
...
@@ -19246,13 +19246,11 @@
function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
var _frustum = new Frustum(),
_projScreenMatrix = new Matrix4(),
_shadowMapSize = new Vector2(),
_
maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize
),
_
viewportSize = new Vector2(
),
_lookTarget = new Vector3(),
_lightPositionWorld = new Vector3(),
_viewport = new Vector4(),
_MorphingFlag = 1,
_SkinningFlag = 2,
...
...
@@ -19266,21 +19264,6 @@
var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
var cubeDirections = [
new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
];
var cubeUps = [
new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
];
var cube2DViewPorts = [
new Vector4(), new Vector4(), new Vector4(),
new Vector4(), new Vector4(), new Vector4()
];
// init
for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
...
...
@@ -19299,8 +19282,6 @@
_depthMaterials[ i ] = depthMaterial;
//
var distanceMaterial = new MeshDistanceMaterial( {
morphTargets: useMorphing,
...
...
@@ -19312,8 +19293,6 @@
}
//
var scope = this;
this.enabled = false;
...
...
@@ -19344,13 +19323,10 @@
// render depth map
var faceCount;
for ( var i = 0, il = lights.length; i < il; i ++ ) {
var light = lights[ i ];
var shadow = light.shadow;
var isPointLight = light && light.isPointLight;
if ( shadow === undefined ) {
...
...
@@ -19359,130 +19335,68 @@
}
var shadowCamera = shadow.camera;
_shadowMapSize.copy( shadow.mapSize );
_shadowMapSize.min( _maxShadowMapSize );
if ( isPointLight ) {
var shadowFrameExtents = shadow.getFrameExtents();
var vpWidth = _shadowMapSize.x;
var vpHeight = _shadowMapSize.y;
_shadowMapSize.multiply( shadowFrameExtents );
// These viewports map a cube-map onto a 2D texture with the
// following orientation:
//
// xzXZ
// y Y
//
// X - Positive x direction
// x - Negative x direction
// Y - Positive y direction
// y - Negative y direction
// Z - Positive z direction
// z - Negative z direction
// positive X
cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
// negative X
cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
// positive Z
cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
// negative Z
cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
// positive Y
cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
// negative Y
cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
_shadowMapSize.x *= 4.0;
_shadowMapSize.y *= 2.0;
_viewportSize.copy( shadow.mapSize );
}
if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
if ( shadow.map === null ) {
console.warn( 'THREE.WebGLShadowMap:', light, 'has shadow exceeding max texture size, reducing' );
var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
if ( _shadowMapSize.x > maxTextureSize ) {
shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
shadow.map.texture.name = light.name + ".shadowMap";
_viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
_shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
shadow.mapSize.x = _viewportSize.x;
shadowCamera.updateProjectionMatrix();
}
}
if ( _shadowMapSize.y > maxTextureSize ) {
if ( shadow.isSpotLightShadow ) {
_viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
_shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
shadow.mapSize.y = _viewportSize.y;
shadow.update( light );
}
}
var shadowMap = shadow.map;
var shadowMatrix = shadow.matrix;
_lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
shadowCamera.position.copy( _lightPositionWorld );
if ( isPointLight ) {
faceCount = 6;
// for point lights we set the shadow matrix to be a translation-only matrix
// equal to inverse of the light's position
shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
} else {
faceCount = 1;
_lookTarget.setFromMatrixPosition( light.target.matrixWorld );
shadowCamera.lookAt( _lookTarget );
shadowCamera.updateMatrixWorld();
// compute shadow matrix
if ( shadow.map === null ) {
shadowMatrix.set(
0.5, 0.0, 0.0, 0.5,
0.0, 0.5, 0.0, 0.5,
0.0, 0.0, 0.5, 0.5,
0.0, 0.0, 0.0, 1.0
);
var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
shadow
Matrix.multiply( shadowCamera.projectionMatrix
);
shadow
Matrix.multiply( shadowCamera.matrixWorldInverse )
;
shadow
.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars
);
shadow
.map.texture.name = light.name + ".shadowMap"
;
}
_renderer.setRenderTarget( shadow
M
ap );
_renderer.setRenderTarget( shadow
.m
ap );
_renderer.clear();
// render shadow map for each cube face (if omni-directional) or
// run a single pass if not
for ( var face = 0; face < faceCount; face ++ ) {
var viewportCount = shadow.getViewportCount();
if ( isPointLight
) {
for ( var vp = 0; vp < viewportCount; vp ++
) {
_lookTarget.copy( shadowCamera.position );
_lookTarget.add( cubeDirections[ face ] );
shadowCamera.up.copy( cubeUps[ face ] );
shadowCamera.lookAt( _lookTarget );
shadowCamera.updateMatrixWorld();
var viewport = shadow.getViewport( vp );
var vpDimensions = cube2DViewPorts[ face ];
_state.viewport( vpDimensions );
}
_viewport.set(
_viewportSize.x * viewport.x,
_viewportSize.y * viewport.y,
_viewportSize.x * viewport.z,
_viewportSize.y * viewport.w
);
// update camera matrices and frustum
_state.viewport( _viewport );
_projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
_frustum.setFromMatrix( _projScreenMatrix );
shadow.updateMatrices( light, camera, vp );
// set object matrices & frustum culling
_frustum = shadow.getFrustum();
renderObject( scene, camera, shadow
Camera, isPointL
ight );
renderObject( scene, camera, shadow
.camera, l
ight );
}
...
...
@@ -19494,7 +19408,7 @@
};
function getDepthMaterial( object, material,
isPointLight, lightPositionWorld
, shadowCameraNear, shadowCameraFar ) {
function getDepthMaterial( object, material,
light
, shadowCameraNear, shadowCameraFar ) {
var geometry = object.geometry;
...
...
@@ -19503,7 +19417,7 @@
var materialVariants = _depthMaterials;
var customMaterial = object.customDepthMaterial;
if ( isPointLight ) {
if (
light.
isPointLight ) {
materialVariants = _distanceMaterials;
customMaterial = object.customDistanceMaterial;
...
...
@@ -19592,9 +19506,9 @@
result.wireframeLinewidth = material.wireframeLinewidth;
result.linewidth = material.linewidth;
if ( isPointLight && result.isMeshDistanceMaterial ) {
if (
light.
isPointLight && result.isMeshDistanceMaterial ) {
result.referencePosition.
copy( lightPosition
World );
result.referencePosition.
setFromMatrixPosition( light.matrix
World );
result.nearDistance = shadowCameraNear;
result.farDistance = shadowCameraFar;
...
...
@@ -19604,7 +19518,7 @@
}
function renderObject( object, camera, shadowCamera,
isPointL
ight ) {
function renderObject( object, camera, shadowCamera,
l
ight ) {
if ( object.visible === false ) return;
...
...
@@ -19630,7 +19544,7 @@
if ( groupMaterial && groupMaterial.visible ) {
var depthMaterial = getDepthMaterial( object, groupMaterial,
isPointLight, _lightPositionWorld
, shadowCamera.near, shadowCamera.far );
var depthMaterial = getDepthMaterial( object, groupMaterial,
light
, shadowCamera.near, shadowCamera.far );
_renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
}
...
...
@@ -19639,7 +19553,7 @@
} else if ( material.visible ) {
var depthMaterial = getDepthMaterial( object, material,
isPointLight, _lightPositionWorld
, shadowCamera.near, shadowCamera.far );
var depthMaterial = getDepthMaterial( object, material,
light
, shadowCamera.near, shadowCamera.far );
_renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
}
...
...
@@ -19652,7 +19566,7 @@
for ( var i = 0, l = children.length; i < l; i ++ ) {
renderObject( children[ i ], camera, shadowCamera,
isPointL
ight );
renderObject( children[ i ], camera, shadowCamera,
l
ight );
}
...
...
@@ -37426,10 +37340,72 @@
this.map = null;
this.matrix = new Matrix4();
this._frustum = new Frustum();
this._frameExtents = new Vector2( 1, 1 );
this._viewportCount = 1;
this._viewports = [
new Vector4( 0, 0, 1, 1 )
];
}
Object.assign( LightShadow.prototype, {
_projScreenMatrix: new Matrix4(),
_lightPositionWorld: new Vector3(),
_lookTarget: new Vector3(),
getViewportCount: function () {
return this._viewportCount;
},
getFrustum: function () {
return this._frustum;
},
updateMatrices: function () {
var shadowCamera = this.camera,
shadowMatrix = this.matrix,
projScreenMatrix = this._projScreenMatrix;
projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
this._frustum.setFromMatrix( projScreenMatrix );
shadowMatrix.set(
0.5, 0.0, 0.0, 0.5,
0.0, 0.5, 0.0, 0.5,
0.0, 0.0, 0.5, 0.5,
0.0, 0.0, 0.0, 1.0
);
shadowMatrix.multiply( shadowCamera.projectionMatrix );
shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
},
getViewport: function ( viewportIndex ) {
return this._viewports[ viewportIndex ];
},
getFrameExtents: function () {
return this._frameExtents;
},
copy: function ( source ) {
this.camera = source.camera.clone();
...
...
@@ -37482,9 +37458,11 @@
isSpotLightShadow: true,
update
: function ( light
) {
update
Matrices: function ( light, viewCamera, viewportIndex
) {
var camera = this.camera;
var camera = this.camera,
lookTarget = this._lookTarget,
lightPositionWorld = this._lightPositionWorld;
var fov = _Math.RAD2DEG * 2 * light.angle;
var aspect = this.mapSize.width / this.mapSize.height;
...
...
@@ -37499,6 +37477,15 @@
}
lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
camera.position.copy( lightPositionWorld );
lookTarget.setFromMatrixPosition( light.target.matrixWorld );
camera.lookAt( lookTarget );
camera.updateMatrixWorld();
LightShadow.prototype.updateMatrices.call( this, light, viewCamera, viewportIndex );
}
} );
...
...
@@ -37569,6 +37556,87 @@
} );
function PointLightShadow() {
LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
this._frameExtents = new Vector2( 4, 2 );
this._viewportCount = 6;
this._viewports = [
// These viewports map a cube-map onto a 2D texture with the
// following orientation:
//
// xzXZ
// y Y
//
// X - Positive x direction
// x - Negative x direction
// Y - Positive y direction
// y - Negative y direction
// Z - Positive z direction
// z - Negative z direction
// positive X
new Vector4( 2, 1, 1, 1 ),
// negative X
new Vector4( 0, 1, 1, 1 ),
// positive Z
new Vector4( 3, 1, 1, 1 ),
// negative Z
new Vector4( 1, 1, 1, 1 ),
// positive Y
new Vector4( 3, 0, 1, 1 ),
// negative Y
new Vector4( 1, 0, 1, 1 )
];
this._cubeDirections = [
new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
];
this._cubeUps = [
new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
];
}
PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
constructor: PointLightShadow,
isPointLightShadow: true,
updateMatrices: function ( light, viewCamera, viewportIndex ) {
var camera = this.camera,
shadowMatrix = this.matrix,
lightPositionWorld = this._lightPositionWorld,
lookTarget = this._lookTarget,
shadowMatrix = this.matrix,
projScreenMatrix = this._projScreenMatrix;
lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
camera.position.copy( lightPositionWorld );
lookTarget.copy( camera.position );
lookTarget.add( this._cubeDirections[ viewportIndex ] );
camera.up.copy( this._cubeUps[ viewportIndex ] );
camera.lookAt( lookTarget );
camera.updateMatrixWorld();
shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
this._frustum.setFromMatrix( projScreenMatrix );
}
} );
/**
* @author mrdoob / http://mrdoob.com/
*/
...
...
@@ -37600,7 +37668,7 @@
this.distance = ( distance !== undefined ) ? distance : 0;
this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
this.shadow = new
LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 )
);
this.shadow = new
PointLightShadow(
);
}
...
...
@@ -37771,7 +37839,7 @@
* @author mrdoob / http://mrdoob.com/
*/
function DirectionalLightShadow(
) {
function DirectionalLightShadow() {
LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
...
...
@@ -37779,7 +37847,26 @@
DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
constructor: DirectionalLightShadow
constructor: DirectionalLightShadow,
isDirectionalLightShadow: true,
updateMatrices: function ( light, viewCamera, viewportIndex ) {
var camera = this.camera,
lightPositionWorld = this._lightPositionWorld,
lookTarget = this._lookTarget;
lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
camera.position.copy( lightPositionWorld );
lookTarget.setFromMatrixPosition( light.target.matrixWorld );
camera.lookAt( lookTarget );
camera.updateMatrixWorld();
LightShadow.prototype.updateMatrices.call( this, light, viewCamera, viewportIndex );
}
} );
...
...
@@ -38426,25 +38513,102 @@
};
/**
* @author
mrdoob / http://mrdoob
.com/
* @author
alteredq / http://alteredqualia
.com/
*/
function
Object
Loader( manager ) {
function Loader( manager ) {
this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
this.crossOrigin = 'anonymous';
this.path = '';
this.resourcePath = '';
}
Object.assign(
Object
Loader.prototype, {
Object.assign( Loader.prototype, {
crossOrigin: 'anonymous',
load: function ( /* url, onLoad, onProgress, onError */ ) {},
parse: function ( /* data */ ) {},
setCrossOrigin: function ( crossOrigin ) {
this.crossOrigin = crossOrigin;
return this;
},
setPath: function ( path ) {
this.path = path;
return this;
},
setResourcePath: function ( resourcePath ) {
this.resourcePath = resourcePath;
return this;
}
} );
//
Loader.Handlers = {
handlers: [],
add: function ( regex, loader ) {
this.handlers.push( regex, loader );
},
get: function ( file ) {
var handlers = this.handlers;
for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
var regex = handlers[ i ];
var loader = handlers[ i + 1 ];
if ( regex.test( file ) ) {
return loader;
}
}
return null;
}
};
/**
* @author mrdoob / http://mrdoob.com/
*/
function ObjectLoader( manager ) {
Loader.call( this, manager );
}
ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
constructor: ObjectLoader,
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
var path = ( this.path ===
undefined
) ? LoaderUtils.extractUrlBase( url ) : this.path;
var path = ( this.path ===
''
) ? LoaderUtils.extractUrlBase( url ) : this.path;
this.resourcePath = this.resourcePath || path;
var loader = new FileLoader( scope.manager );
...
...
@@ -38482,27 +38646,6 @@
},
setPath: function ( value ) {
this.path = value;
return this;
},
setResourcePath: function ( value ) {
this.resourcePath = value;
return this;
},
setCrossOrigin: function ( value ) {
this.crossOrigin = value;
return this;
},
parse: function ( json, onLoad ) {
var shapes = this.parseShape( json.shapes );
...
...
@@ -39991,57 +40134,6 @@
} );
/**
* @author alteredq / http://alteredqualia.com/
*/
function Loader() {}
Loader.Handlers = {
handlers: [],
add: function ( regex, loader ) {
this.handlers.push( regex, loader );
},
get: function ( file ) {
var handlers = this.handlers;
for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
var regex = handlers[ i ];
var loader = handlers[ i + 1 ];
if ( regex.test( file ) ) {
return loader;
}
}
return null;
}
};
Object.assign( Loader.prototype, {
crossOrigin: 'anonymous',
onLoadStart: function () {},
onLoadProgress: function () {},
onLoadComplete: function () {}
} );
/**
* @author mrdoob / http://mrdoob.com/
*/
build/three.min.js
浏览文件 @
76aa9087
此差异已折叠。
点击以展开。
build/three.module.js
浏览文件 @
76aa9087
...
...
@@ -19240,13 +19240,11 @@ MeshDistanceMaterial.prototype.copy = function ( source ) {
function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
var _frustum = new Frustum(),
_projScreenMatrix = new Matrix4(),
_shadowMapSize = new Vector2(),
_
maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize
),
_
viewportSize = new Vector2(
),
_lookTarget = new Vector3(),
_lightPositionWorld = new Vector3(),
_viewport = new Vector4(),
_MorphingFlag = 1,
_SkinningFlag = 2,
...
...
@@ -19260,21 +19258,6 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
var cubeDirections = [
new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
];
var cubeUps = [
new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
];
var cube2DViewPorts = [
new Vector4(), new Vector4(), new Vector4(),
new Vector4(), new Vector4(), new Vector4()
];
// init
for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
...
...
@@ -19293,8 +19276,6 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
_depthMaterials[ i ] = depthMaterial;
//
var distanceMaterial = new MeshDistanceMaterial( {
morphTargets: useMorphing,
...
...
@@ -19306,8 +19287,6 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
}
//
var scope = this;
this.enabled = false;
...
...
@@ -19338,13 +19317,10 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
// render depth map
var faceCount;
for ( var i = 0, il = lights.length; i < il; i ++ ) {
var light = lights[ i ];
var shadow = light.shadow;
var isPointLight = light && light.isPointLight;
if ( shadow === undefined ) {
...
...
@@ -19353,130 +19329,68 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
}
var shadowCamera = shadow.camera;
_shadowMapSize.copy( shadow.mapSize );
_shadowMapSize.min( _maxShadowMapSize );
if ( isPointLight ) {
var shadowFrameExtents = shadow.getFrameExtents();
var vpWidth = _shadowMapSize.x;
var vpHeight = _shadowMapSize.y;
_shadowMapSize.multiply( shadowFrameExtents );
// These viewports map a cube-map onto a 2D texture with the
// following orientation:
//
// xzXZ
// y Y
//
// X - Positive x direction
// x - Negative x direction
// Y - Positive y direction
// y - Negative y direction
// Z - Positive z direction
// z - Negative z direction
// positive X
cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
// negative X
cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
// positive Z
cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
// negative Z
cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
// positive Y
cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
// negative Y
cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
_shadowMapSize.x *= 4.0;
_shadowMapSize.y *= 2.0;
_viewportSize.copy( shadow.mapSize );
}
if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
if ( shadow.map === null ) {
console.warn( 'THREE.WebGLShadowMap:', light, 'has shadow exceeding max texture size, reducing' );
var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
if ( _shadowMapSize.x > maxTextureSize ) {
shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
shadow.map.texture.name = light.name + ".shadowMap";
_viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
_shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
shadow.mapSize.x = _viewportSize.x;
shadowCamera.updateProjectionMatrix();
}
}
if ( _shadowMapSize.y > maxTextureSize ) {
if ( shadow.isSpotLightShadow ) {
_viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
_shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
shadow.mapSize.y = _viewportSize.y;
shadow.update( light );
}
}
var shadowMap = shadow.map;
var shadowMatrix = shadow.matrix;
_lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
shadowCamera.position.copy( _lightPositionWorld );
if ( isPointLight ) {
faceCount = 6;
// for point lights we set the shadow matrix to be a translation-only matrix
// equal to inverse of the light's position
shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
} else {
faceCount = 1;
_lookTarget.setFromMatrixPosition( light.target.matrixWorld );
shadowCamera.lookAt( _lookTarget );
shadowCamera.updateMatrixWorld();
// compute shadow matrix
if ( shadow.map === null ) {
shadowMatrix.set(
0.5, 0.0, 0.0, 0.5,
0.0, 0.5, 0.0, 0.5,
0.0, 0.0, 0.5, 0.5,
0.0, 0.0, 0.0, 1.0
);
var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
shadow
Matrix.multiply( shadowCamera.projectionMatrix
);
shadow
Matrix.multiply( shadowCamera.matrixWorldInverse )
;
shadow
.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars
);
shadow
.map.texture.name = light.name + ".shadowMap"
;
}
_renderer.setRenderTarget( shadow
M
ap );
_renderer.setRenderTarget( shadow
.m
ap );
_renderer.clear();
// render shadow map for each cube face (if omni-directional) or
// run a single pass if not
for ( var face = 0; face < faceCount; face ++ ) {
var viewportCount = shadow.getViewportCount();
if ( isPointLight
) {
for ( var vp = 0; vp < viewportCount; vp ++
) {
_lookTarget.copy( shadowCamera.position );
_lookTarget.add( cubeDirections[ face ] );
shadowCamera.up.copy( cubeUps[ face ] );
shadowCamera.lookAt( _lookTarget );
shadowCamera.updateMatrixWorld();
var viewport = shadow.getViewport( vp );
var vpDimensions = cube2DViewPorts[ face ];
_state.viewport( vpDimensions );
}
_viewport.set(
_viewportSize.x * viewport.x,
_viewportSize.y * viewport.y,
_viewportSize.x * viewport.z,
_viewportSize.y * viewport.w
);
// update camera matrices and frustum
_state.viewport( _viewport );
_projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
_frustum.setFromMatrix( _projScreenMatrix );
shadow.updateMatrices( light, camera, vp );
// set object matrices & frustum culling
_frustum = shadow.getFrustum();
renderObject( scene, camera, shadow
Camera, isPointL
ight );
renderObject( scene, camera, shadow
.camera, l
ight );
}
...
...
@@ -19488,7 +19402,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
};
function getDepthMaterial( object, material,
isPointLight, lightPositionWorld
, shadowCameraNear, shadowCameraFar ) {
function getDepthMaterial( object, material,
light
, shadowCameraNear, shadowCameraFar ) {
var geometry = object.geometry;
...
...
@@ -19497,7 +19411,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
var materialVariants = _depthMaterials;
var customMaterial = object.customDepthMaterial;
if ( isPointLight ) {
if (
light.
isPointLight ) {
materialVariants = _distanceMaterials;
customMaterial = object.customDistanceMaterial;
...
...
@@ -19586,9 +19500,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
result.wireframeLinewidth = material.wireframeLinewidth;
result.linewidth = material.linewidth;
if ( isPointLight && result.isMeshDistanceMaterial ) {
if (
light.
isPointLight && result.isMeshDistanceMaterial ) {
result.referencePosition.
copy( lightPosition
World );
result.referencePosition.
setFromMatrixPosition( light.matrix
World );
result.nearDistance = shadowCameraNear;
result.farDistance = shadowCameraFar;
...
...
@@ -19598,7 +19512,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
}
function renderObject( object, camera, shadowCamera,
isPointL
ight ) {
function renderObject( object, camera, shadowCamera,
l
ight ) {
if ( object.visible === false ) return;
...
...
@@ -19624,7 +19538,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
if ( groupMaterial && groupMaterial.visible ) {
var depthMaterial = getDepthMaterial( object, groupMaterial,
isPointLight, _lightPositionWorld
, shadowCamera.near, shadowCamera.far );
var depthMaterial = getDepthMaterial( object, groupMaterial,
light
, shadowCamera.near, shadowCamera.far );
_renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
}
...
...
@@ -19633,7 +19547,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
} else if ( material.visible ) {
var depthMaterial = getDepthMaterial( object, material,
isPointLight, _lightPositionWorld
, shadowCamera.near, shadowCamera.far );
var depthMaterial = getDepthMaterial( object, material,
light
, shadowCamera.near, shadowCamera.far );
_renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
}
...
...
@@ -19646,7 +19560,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
for ( var i = 0, l = children.length; i < l; i ++ ) {
renderObject( children[ i ], camera, shadowCamera,
isPointL
ight );
renderObject( children[ i ], camera, shadowCamera,
l
ight );
}
...
...
@@ -37420,10 +37334,72 @@ function LightShadow( camera ) {
this.map = null;
this.matrix = new Matrix4();
this._frustum = new Frustum();
this._frameExtents = new Vector2( 1, 1 );
this._viewportCount = 1;
this._viewports = [
new Vector4( 0, 0, 1, 1 )
];
}
Object.assign( LightShadow.prototype, {
_projScreenMatrix: new Matrix4(),
_lightPositionWorld: new Vector3(),
_lookTarget: new Vector3(),
getViewportCount: function () {
return this._viewportCount;
},
getFrustum: function () {
return this._frustum;
},
updateMatrices: function () {
var shadowCamera = this.camera,
shadowMatrix = this.matrix,
projScreenMatrix = this._projScreenMatrix;
projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
this._frustum.setFromMatrix( projScreenMatrix );
shadowMatrix.set(
0.5, 0.0, 0.0, 0.5,
0.0, 0.5, 0.0, 0.5,
0.0, 0.0, 0.5, 0.5,
0.0, 0.0, 0.0, 1.0
);
shadowMatrix.multiply( shadowCamera.projectionMatrix );
shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
},
getViewport: function ( viewportIndex ) {
return this._viewports[ viewportIndex ];
},
getFrameExtents: function () {
return this._frameExtents;
},
copy: function ( source ) {
this.camera = source.camera.clone();
...
...
@@ -37476,9 +37452,11 @@ SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype
isSpotLightShadow: true,
update
: function ( light
) {
update
Matrices: function ( light, viewCamera, viewportIndex
) {
var camera = this.camera;
var camera = this.camera,
lookTarget = this._lookTarget,
lightPositionWorld = this._lightPositionWorld;
var fov = _Math.RAD2DEG * 2 * light.angle;
var aspect = this.mapSize.width / this.mapSize.height;
...
...
@@ -37493,6 +37471,15 @@ SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype
}
lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
camera.position.copy( lightPositionWorld );
lookTarget.setFromMatrixPosition( light.target.matrixWorld );
camera.lookAt( lookTarget );
camera.updateMatrixWorld();
LightShadow.prototype.updateMatrices.call( this, light, viewCamera, viewportIndex );
}
} );
...
...
@@ -37563,6 +37550,87 @@ SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
} );
function PointLightShadow() {
LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
this._frameExtents = new Vector2( 4, 2 );
this._viewportCount = 6;
this._viewports = [
// These viewports map a cube-map onto a 2D texture with the
// following orientation:
//
// xzXZ
// y Y
//
// X - Positive x direction
// x - Negative x direction
// Y - Positive y direction
// y - Negative y direction
// Z - Positive z direction
// z - Negative z direction
// positive X
new Vector4( 2, 1, 1, 1 ),
// negative X
new Vector4( 0, 1, 1, 1 ),
// positive Z
new Vector4( 3, 1, 1, 1 ),
// negative Z
new Vector4( 1, 1, 1, 1 ),
// positive Y
new Vector4( 3, 0, 1, 1 ),
// negative Y
new Vector4( 1, 0, 1, 1 )
];
this._cubeDirections = [
new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
];
this._cubeUps = [
new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
];
}
PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
constructor: PointLightShadow,
isPointLightShadow: true,
updateMatrices: function ( light, viewCamera, viewportIndex ) {
var camera = this.camera,
shadowMatrix = this.matrix,
lightPositionWorld = this._lightPositionWorld,
lookTarget = this._lookTarget,
shadowMatrix = this.matrix,
projScreenMatrix = this._projScreenMatrix;
lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
camera.position.copy( lightPositionWorld );
lookTarget.copy( camera.position );
lookTarget.add( this._cubeDirections[ viewportIndex ] );
camera.up.copy( this._cubeUps[ viewportIndex ] );
camera.lookAt( lookTarget );
camera.updateMatrixWorld();
shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
this._frustum.setFromMatrix( projScreenMatrix );
}
} );
/**
* @author mrdoob / http://mrdoob.com/
*/
...
...
@@ -37594,7 +37662,7 @@ function PointLight( color, intensity, distance, decay ) {
this.distance = ( distance !== undefined ) ? distance : 0;
this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
this.shadow = new
LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 )
);
this.shadow = new
PointLightShadow(
);
}
...
...
@@ -37765,7 +37833,7 @@ OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ),
* @author mrdoob / http://mrdoob.com/
*/
function DirectionalLightShadow(
) {
function DirectionalLightShadow() {
LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
...
...
@@ -37773,7 +37841,26 @@ function DirectionalLightShadow( ) {
DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
constructor: DirectionalLightShadow
constructor: DirectionalLightShadow,
isDirectionalLightShadow: true,
updateMatrices: function ( light, viewCamera, viewportIndex ) {
var camera = this.camera,
lightPositionWorld = this._lightPositionWorld,
lookTarget = this._lookTarget;
lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
camera.position.copy( lightPositionWorld );
lookTarget.setFromMatrixPosition( light.target.matrixWorld );
camera.lookAt( lookTarget );
camera.updateMatrixWorld();
LightShadow.prototype.updateMatrices.call( this, light, viewCamera, viewportIndex );
}
} );
...
...
@@ -38420,25 +38507,102 @@ var TYPED_ARRAYS = {
};
/**
* @author
mrdoob / http://mrdoob
.com/
* @author
alteredq / http://alteredqualia
.com/
*/
function
Object
Loader( manager ) {
function Loader( manager ) {
this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
this.crossOrigin = 'anonymous';
this.path = '';
this.resourcePath = '';
}
Object.assign(
Object
Loader.prototype, {
Object.assign( Loader.prototype, {
crossOrigin: 'anonymous',
load: function ( /* url, onLoad, onProgress, onError */ ) {},
parse: function ( /* data */ ) {},
setCrossOrigin: function ( crossOrigin ) {
this.crossOrigin = crossOrigin;
return this;
},
setPath: function ( path ) {
this.path = path;
return this;
},
setResourcePath: function ( resourcePath ) {
this.resourcePath = resourcePath;
return this;
}
} );
//
Loader.Handlers = {
handlers: [],
add: function ( regex, loader ) {
this.handlers.push( regex, loader );
},
get: function ( file ) {
var handlers = this.handlers;
for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
var regex = handlers[ i ];
var loader = handlers[ i + 1 ];
if ( regex.test( file ) ) {
return loader;
}
}
return null;
}
};
/**
* @author mrdoob / http://mrdoob.com/
*/
function ObjectLoader( manager ) {
Loader.call( this, manager );
}
ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
constructor: ObjectLoader,
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
var path = ( this.path ===
undefined
) ? LoaderUtils.extractUrlBase( url ) : this.path;
var path = ( this.path ===
''
) ? LoaderUtils.extractUrlBase( url ) : this.path;
this.resourcePath = this.resourcePath || path;
var loader = new FileLoader( scope.manager );
...
...
@@ -38476,27 +38640,6 @@ Object.assign( ObjectLoader.prototype, {
},
setPath: function ( value ) {
this.path = value;
return this;
},
setResourcePath: function ( value ) {
this.resourcePath = value;
return this;
},
setCrossOrigin: function ( value ) {
this.crossOrigin = value;
return this;
},
parse: function ( json, onLoad ) {
var shapes = this.parseShape( json.shapes );
...
...
@@ -39985,57 +40128,6 @@ Object.assign( FontLoader.prototype, {
} );
/**
* @author alteredq / http://alteredqualia.com/
*/
function Loader() {}
Loader.Handlers = {
handlers: [],
add: function ( regex, loader ) {
this.handlers.push( regex, loader );
},
get: function ( file ) {
var handlers = this.handlers;
for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
var regex = handlers[ i ];
var loader = handlers[ i + 1 ];
if ( regex.test( file ) ) {
return loader;
}
}
return null;
}
};
Object.assign( Loader.prototype, {
crossOrigin: 'anonymous',
onLoadStart: function () {},
onLoadProgress: function () {},
onLoadComplete: function () {}
} );
/**
* @author mrdoob / http://mrdoob.com/
*/
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录