Просмотр исходного кода

InstancedMesh: Add clone and dispose method for `morphTexture` (#27952)

* InstancedMesh: Clone morphTexture in copy method

* dispose morphTexture too

* dispatchEvent dispose
Renaud Rohlinger 1 год назад
Родитель
Сommit
43fbcefc20

+ 1 - 1
examples/jsm/nodes/accessors/MorphNode.js

@@ -190,7 +190,7 @@ class MorphNode extends Node {
 
 			const influence = float( 0 ).toVar();
 
-			if ( this.mesh.isInstancedMesh === true && this.mesh.morphTexture !== null ) {
+			if ( this.mesh.isInstancedMesh === true && ( this.mesh.morphTexture !== null && this.mesh.morphTexture !== undefined ) ) {
 
 				influence.assign( textureLoad( this.mesh.morphTexture, ivec2( int( i ).add( 1 ), int( instanceIndex ) ) ).r );
 

+ 1 - 1
examples/webgpu_parallax_uv.html

@@ -109,7 +109,7 @@
 
 				// renderer
 
-				renderer = new WebGPURenderer( { antialias: true, forceWebGL: false } );
+				renderer = new WebGPURenderer( { antialias: true } );
 				renderer.setPixelRatio( window.devicePixelRatio );
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				renderer.setAnimationLoop( animate );

+ 10 - 0
src/objects/InstancedMesh.js

@@ -109,6 +109,7 @@ class InstancedMesh extends Mesh {
 
 		this.instanceMatrix.copy( source.instanceMatrix );
 
+		if ( source.morphTexture !== null ) this.morphTexture = source.morphTexture.clone();
 		if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone();
 
 		this.count = source.count;
@@ -260,6 +261,15 @@ class InstancedMesh extends Mesh {
 
 		this.dispatchEvent( { type: 'dispose' } );
 
+		if ( this.morphTexture !== null ) {
+
+			this.morphTexture.dispose();
+			this.morphTexture = null;
+
+		}
+
+		return this;
+
 	}
 
 }