Skip to content

Commit 3f5991e

Browse files
authored
Merge pull request #15523 from Mugen87/dev23
Scene: Introduce .dispose()
2 parents 9602d77 + 86383c5 commit 3f5991e

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-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/WebGLRenderLists.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ function WebGLRenderLists() {
152152

153153
var lists = {};
154154

155+
function onSceneDispose( event ) {
156+
157+
var scene = event.target;
158+
159+
scene.removeEventListener( 'dispose', onSceneDispose );
160+
161+
delete lists[ scene.id ];
162+
163+
}
164+
155165
function get( scene, camera ) {
156166

157167
var cameras = lists[ scene.id ];
@@ -162,6 +172,8 @@ function WebGLRenderLists() {
162172
lists[ scene.id ] = {};
163173
lists[ scene.id ][ camera.id ] = list;
164174

175+
scene.addEventListener( 'dispose', onSceneDispose );
176+
165177
} else {
166178

167179
list = cameras[ camera.id ];

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)