未验证 提交 dd542a41 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #13815 from WestLangley/dev-pmrem_dispose

PMREM and EquiangularToCubeGenerator: added dispose() methods
......@@ -2,18 +2,18 @@
* @author Richard M. / https://github.com/richardmonette
*/
THREE.EquiangularToCubeGenerator = function( sourceTexture, resolution ) {
THREE.EquiangularToCubeGenerator = function ( sourceTexture, resolution ) {
this.sourceTexture = sourceTexture;
this.resolution = resolution;
this.views = [
{ t: [1.0, 0.0, 0.0 ], u: [0.0, -1.0, 0.0] },
{ t: [-1.0, 0.0, 0.0], u: [0.0, -1.0, 0.0] },
{ t: [0.0, 1.0, 0.0], u: [0.0, 0.0, 1.0] },
{ t: [0.0, -1.0, 0.0], u: [0.0, 0.0, -1.0] },
{ t: [0.0, 0.0, 1.0], u: [0.0, -1.0, 0.0] },
{ t: [0.0, 0.0, -1.0], u: [0.0, -1.0, 0.0] },
{ t: [ 1, 0, 0 ], u: [ 0, - 1, 0 ] },
{ t: [ - 1, 0, 0 ], u: [ 0, - 1, 0 ] },
{ t: [ 0, 1, 0 ], u: [ 0, 0, 1 ] },
{ t: [ 0, - 1, 0 ], u: [ 0, 0, - 1 ] },
{ t: [ 0, 0, 1 ], u: [ 0, - 1, 0 ] },
{ t: [ 0, 0, - 1 ], u: [ 0, - 1, 0 ] },
];
this.camera = new THREE.PerspectiveCamera( 90, 1, 0.1, 10 );
......@@ -22,49 +22,47 @@ THREE.EquiangularToCubeGenerator = function( sourceTexture, resolution ) {
this.scene = new THREE.Scene();
this.scene.add( this.boxMesh );
};
var params = {
format: THREE.RGBAFormat,
magFilter: this.sourceTexture.magFilter,
minFilter: this.sourceTexture.minFilter,
type: this.sourceTexture.type,
generateMipmaps: this.sourceTexture.generateMipmaps,
anisotropy: this.sourceTexture.anisotropy,
encoding: this.sourceTexture.encoding
};
THREE.EquiangularToCubeGenerator.prototype = {
this.renderTarget = new THREE.WebGLRenderTargetCube( this.resolution, this.resolution, params );
constructor : THREE.EquiangularToCubeGenerator,
};
generate: function( renderer ) {
THREE.EquiangularToCubeGenerator.prototype = {
var params = {
format: THREE.RGBAFormat,
magFilter: this.sourceTexture.magFilter,
minFilter: this.sourceTexture.minFilter,
type: this.sourceTexture.type,
generateMipmaps: this.sourceTexture.generateMipmaps,
anisotropy: this.sourceTexture.anisotropy,
encoding: this.sourceTexture.encoding
};
constructor: THREE.EquiangularToCubeGenerator,
var renderTarget = new THREE.WebGLRenderTargetCube( this.resolution, this.resolution, params );
update: function ( renderer ) {
for ( var i = 0; i < 6; i++ ) {
for ( var i = 0; i < 6; i ++ ) {
renderTarget.activeCubeFace = i;
this.renderTarget.activeCubeFace = i;
var v = this.views[i];
var v = this.views[ i ];
this.camera.position.set( 0, 0, 0 );
this.camera.up.set( v.u[ 0 ], v.u[ 1 ], v.u[ 2 ] );
this.camera.lookAt( v.t[ 0 ], v.t[ 1 ], v.t[ 2 ] );
this.camera.updateProjectionMatrix();
renderer.render( this.scene, this.camera, renderTarget, true );
renderer.render( this.scene, this.camera, this.renderTarget, true );
}
return renderTarget.texture;
return this.renderTarget.texture;
},
getShader: function() {
getShader: function () {
return new THREE.ShaderMaterial( {
var shaderMaterial = new THREE.ShaderMaterial( {
uniforms: {
"equirectangularMap": { value: this.sourceTexture },
......@@ -107,7 +105,18 @@ THREE.EquiangularToCubeGenerator.prototype = {
} );
shaderMaterial.type = 'EquiangularToCubeGenerator';
return shaderMaterial;
},
dispose: function () {
this.boxMesh.geometry.dispose();
this.boxMesh.material.dispose();
this.renderTarget.dispose();
}
};
......@@ -13,10 +13,9 @@
* The arrangement of the faces is fixed, as assuming this arrangement, the sampling function has been written.
*/
THREE.PMREMCubeUVPacker = function ( cubeTextureLods, numLods ) {
THREE.PMREMCubeUVPacker = function ( cubeTextureLods ) {
this.cubeLods = cubeTextureLods;
this.numLods = numLods;
var size = cubeTextureLods[ 0 ].width * 4;
var sourceTexture = cubeTextureLods[ 0 ].texture;
......@@ -189,8 +188,22 @@ THREE.PMREMCubeUVPacker.prototype = {
} );
shaderMaterial.type = 'PMREMCubeUVPacker';
return shaderMaterial;
},
dispose: function () {
for ( var i = 0, l = this.objects.length; i < l; i ++ ) {
this.objects[ i ].material.dispose();
}
this.objects[ 0 ].geometry.dispose();
}
};
......@@ -138,7 +138,7 @@ THREE.PMREMGenerator.prototype = {
getShader: function () {
return new THREE.ShaderMaterial( {
var shaderMaterial = new THREE.ShaderMaterial( {
defines: {
"SAMPLES_PER_LEVEL": 20,
......@@ -269,6 +269,23 @@ THREE.PMREMGenerator.prototype = {
} );
shaderMaterial.type = 'PMREMGenerator';
return shaderMaterial;
},
dispose: function () {
for ( var i = 0, l = this.cubeLods.length; i < l; i ++ ) {
this.cubeLods[ i ].dispose();
}
this.planeMesh.geometry.dispose();
this.planeMesh.material.dispose();
}
};
......@@ -67,7 +67,7 @@
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 0.0, 0, 120 );
camera.position.set( 0, 0, 120 );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x000000 );
......@@ -107,7 +107,7 @@
texture.encoding = THREE.LinearEncoding;
var cubemapGenerator = new THREE.EquiangularToCubeGenerator( texture, 512 );
var cubeMapTexture = cubemapGenerator.generate( renderer );
var cubeMapTexture = cubemapGenerator.update( renderer );
var pmremGenerator = new THREE.PMREMGenerator( cubeMapTexture );
pmremGenerator.update( renderer );
......@@ -117,6 +117,11 @@
exrCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;
texture.dispose();
cubemapGenerator.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();
} );
new THREE.TextureLoader().load( 'textures/equiangular.png', function ( texture ) {
......@@ -124,7 +129,7 @@
texture.encoding = THREE.sRGBEncoding;
var cubemapGenerator = new THREE.EquiangularToCubeGenerator( texture, 512 );
var cubeMapTexture = cubemapGenerator.generate( renderer );
var cubeMapTexture = cubemapGenerator.update( renderer );
var pmremGenerator = new THREE.PMREMGenerator( cubeMapTexture );
pmremGenerator.update( renderer );
......@@ -134,6 +139,11 @@
pngCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;
texture.dispose();
cubemapGenerator.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();
} );
renderer.setPixelRatio( window.devicePixelRatio );
......
......@@ -68,7 +68,7 @@
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 0.0, 0, 120 );
camera.position.set( 0, 0, 120 );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x000000 );
......@@ -77,7 +77,6 @@
renderer.toneMapping = THREE.LinearToneMapping;
standardMaterial = new THREE.MeshStandardMaterial( {
map: null,
color: 0xffffff,
metalness: params.metalness,
roughness: params.roughness
......@@ -119,6 +118,10 @@
hdrCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;
hdrCubeMap.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();
} );
var ldrUrls = genCubeUrls( './textures/cube/pisa/', '.png' );
......@@ -134,6 +137,10 @@
ldrCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;
ldrCubeMap.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();
} );
......@@ -150,6 +157,10 @@
rgbmCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;
rgbmCubeMap.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();
} );
renderer.setPixelRatio( window.devicePixelRatio );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册