Skip to content

Commit 4c76e27

Browse files
committed
Scene: Introduce .dispose()
1 parent cc7deb9 commit 4c76e27

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

docs/api/en/scenes/Scene.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ <h3>[method:JSON toJSON]</h3>
5151
Return the scene data in JSON format.
5252
</p>
5353

54+
<h3>[method:null dispose]()</h3>
55+
<p>
56+
Clears scene related data internally cached by [page:WebGLRenderer].
57+
</p>
58+
5459
<h2>Source</h2>
5560

5661
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

docs/api/zh/scenes/Scene.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ <h3>[method:JSON toJSON]</h3>
5454
使用JSON格式返回场景数据。
5555
</p>
5656

57+
<h3>[method:null dispose]()</h3>
58+
<p>
59+
TODO
60+
</p>
61+
5762
<h2>源代码</h2>
5863

5964
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

src/renderers/webgl/WebGLRenderStates.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ function WebGLRenderStates() {
5858

5959
var renderStates = {};
6060

61+
function onSceneDispose( event ) {
62+
63+
var scene = event.target;
64+
65+
scene.removeEventListener( 'dispose', onSceneDispose );
66+
67+
delete renderStates[ scene.id ];
68+
69+
}
70+
6171
function get( scene, camera ) {
6272

6373
var renderState;
@@ -68,6 +78,8 @@ function WebGLRenderStates() {
6878
renderStates[ scene.id ] = {};
6979
renderStates[ scene.id ][ camera.id ] = renderState;
7080

81+
scene.addEventListener( 'dispose', onSceneDispose );
82+
7183
} else {
7284

7385
if ( renderStates[ scene.id ][ camera.id ] === undefined ) {

src/scenes/Scene.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
4646

4747
return data;
4848

49+
},
50+
51+
dispose: function () {
52+
53+
this.dispatchEvent( { type: 'dispose' } );
54+
4955
}
5056

5157
} );

0 commit comments

Comments
 (0)