浏览代码

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

* InstancedMesh: Clone morphTexture in copy method

* dispose morphTexture too

* dispatchEvent dispose
Renaud Rohlinger 1 年之前
父节点
当前提交
43fbcefc20
共有 3 个文件被更改,包括 12 次插入2 次删除
  1. 1 1
      examples/jsm/nodes/accessors/MorphNode.js
  2. 1 1
      examples/webgpu_parallax_uv.html
  3. 10 0
      src/objects/InstancedMesh.js

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

@@ -190,7 +190,7 @@ class MorphNode extends Node {
 
 
 			const influence = float( 0 ).toVar();
 			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 );
 				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
 
 
-				renderer = new WebGPURenderer( { antialias: true, forceWebGL: false } );
+				renderer = new WebGPURenderer( { antialias: true } );
 				renderer.setPixelRatio( window.devicePixelRatio );
 				renderer.setPixelRatio( window.devicePixelRatio );
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				renderer.setAnimationLoop( animate );
 				renderer.setAnimationLoop( animate );

+ 10 - 0
src/objects/InstancedMesh.js

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