Skip to content

Commit

Permalink
InstancedMesh: Add clone and dispose method for morphTexture (mrdoo…
Browse files Browse the repository at this point in the history
…b#27952)

* InstancedMesh: Clone morphTexture in copy method

* dispose morphTexture too

* dispatchEvent dispose
  • Loading branch information
RenaudRohlinger committed Mar 20, 2024
1 parent bd2845f commit 43fbcef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/jsm/nodes/accessors/MorphNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_parallax_uv.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
10 changes: 10 additions & 0 deletions src/objects/InstancedMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -260,6 +261,15 @@ class InstancedMesh extends Mesh {

this.dispatchEvent( { type: 'dispose' } );

if ( this.morphTexture !== null ) {

this.morphTexture.dispose();
this.morphTexture = null;

}

return this;

}

}
Expand Down

0 comments on commit 43fbcef

Please sign in to comment.