ソースを参照

InstancedMesh: Add dispose().

Mugen87 4 年 前
コミット
4d9784f822

+ 5 - 0
docs/api/en/objects/InstancedMesh.html

@@ -66,6 +66,11 @@
 		<h2>Methods</h2>
 		<p>See the base [page:Mesh] class for common methods.</p>
 
+		<h3>[method:null dispose]()</h3>
+		<p>
+			Frees the internal resources of this instance.
+		</p>
+
 		<h3>[method:null getColorAt]( [param:Integer index], [param:Color color] )</h3>
 		<p>
 			[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

+ 5 - 0
docs/api/zh/objects/InstancedMesh.html

@@ -65,6 +65,11 @@
 		<h2>方法</h2>
 		<p>See the base [page:Mesh] class for common methods.</p>
 
+		<h3>[method:null dispose]()</h3>
+		<p>
+			Frees the internal resources of this instance.
+		</p>
+
 		<h3>[method:null getColorAt]( [param:Integer index], [param:Color color] )</h3>
 		<p>
 			[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

+ 1 - 0
src/objects/InstancedMesh.d.ts

@@ -26,5 +26,6 @@ export class InstancedMesh <
 	getMatrixAt( index: number, matrix: Matrix4 ): void;
 	setColorAt( index: number, color: Color ): void;
 	setMatrixAt( index: number, matrix: Matrix4 ): void;
+	dispose(): void;
 
 }

+ 6 - 0
src/objects/InstancedMesh.js

@@ -112,6 +112,12 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 	updateMorphTargets: function () {
 
+	},
+
+	dispose: function () {
+
+		this.dispatchEvent( { type: 'dispose' } );
+
 	}
 
 } );

+ 18 - 0
src/renderers/webgl/WebGLObjects.js

@@ -27,6 +27,12 @@ function WebGLObjects( gl, geometries, attributes, info ) {
 
 		if ( object.isInstancedMesh ) {
 
+			if ( object.hasEventListener( 'dispose', onInstancedMeshDispose ) === false ) {
+
+				object.addEventListener( 'dispose', onInstancedMeshDispose );
+
+			}
+
 			attributes.update( object.instanceMatrix, gl.ARRAY_BUFFER );
 
 			if ( object.instanceColor !== null ) {
@@ -47,6 +53,18 @@ function WebGLObjects( gl, geometries, attributes, info ) {
 
 	}
 
+	function onInstancedMeshDispose( event ) {
+
+		const instancedMesh = event.target;
+
+		instancedMesh.removeEventListener( 'dispose', onInstancedMeshDispose );
+
+		attributes.remove( instancedMesh.instanceMatrix );
+
+		if ( instancedMesh.instanceColor !== null ) attributes.remove( instancedMesh.instanceColor );
+
+	}
+
 	return {
 
 		update: update,