From 141a4d6158dd605dc044d2f8129259df0bac52fa Mon Sep 17 00:00:00 2001 From: Vegar Ringdal Date: Thu, 24 Apr 2025 16:23:37 +0200 Subject: [PATCH 1/2] make batchMesh._matricesTexture optional --- src/nodes/accessors/BatchNode.js | 28 +++++++++++++++++----------- src/renderers/common/RenderObject.js | 6 +++++- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/nodes/accessors/BatchNode.js b/src/nodes/accessors/BatchNode.js index 221682606faaf9..59b1e0694d4bb3 100644 --- a/src/nodes/accessors/BatchNode.js +++ b/src/nodes/accessors/BatchNode.js @@ -91,17 +91,23 @@ class BatchNode extends Node { const matricesTexture = this.batchMesh._matricesTexture; - const size = int( textureSize( textureLoad( matricesTexture ), 0 ).x ); - const j = float( indirectId ).mul( 4 ).toInt().toVar(); - - const x = j.mod( size ); - const y = j.div( size ); - const batchingMatrix = mat4( - textureLoad( matricesTexture, ivec2( x, y ) ), - textureLoad( matricesTexture, ivec2( x.add( 1 ), y ) ), - textureLoad( matricesTexture, ivec2( x.add( 2 ), y ) ), - textureLoad( matricesTexture, ivec2( x.add( 3 ), y ) ) - ); + let batchingMatrix = mat4(); + + if ( matricesTexture !== null ) { + + const size = int( textureSize( textureLoad( matricesTexture ), 0 ).x ); + const j = float( indirectId ).mul( 4 ).toInt().toVar(); + + const x = j.mod( size ); + const y = j.div( size ); + batchingMatrix = mat4( + textureLoad( matricesTexture, ivec2( x, y ) ), + textureLoad( matricesTexture, ivec2( x.add( 1 ), y ) ), + textureLoad( matricesTexture, ivec2( x.add( 2 ), y ) ), + textureLoad( matricesTexture, ivec2( x.add( 3 ), y ) ) + ); + + } const colorsTexture = this.batchMesh._colorsTexture; diff --git a/src/renderers/common/RenderObject.js b/src/renderers/common/RenderObject.js index eb112879f68708..9284d56747a808 100644 --- a/src/renderers/common/RenderObject.js +++ b/src/renderers/common/RenderObject.js @@ -703,8 +703,12 @@ class RenderObject { } if ( object.isBatchedMesh ) { + + if ( object._matricesTexture !== null ) { - cacheKey += object._matricesTexture.uuid + ','; + cacheKey += object._matricesTexture.uuid + ','; + + } if ( object._colorsTexture !== null ) { From d4c158587a635d5f57a922797e52050249f67e22 Mon Sep 17 00:00:00 2001 From: Vegar Ringdal Date: Thu, 24 Apr 2025 16:35:12 +0200 Subject: [PATCH 2/2] lint fix --- src/nodes/accessors/BatchNode.js | 2 +- src/renderers/common/RenderObject.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nodes/accessors/BatchNode.js b/src/nodes/accessors/BatchNode.js index 59b1e0694d4bb3..9a50cc6f34ef6d 100644 --- a/src/nodes/accessors/BatchNode.js +++ b/src/nodes/accessors/BatchNode.js @@ -107,7 +107,7 @@ class BatchNode extends Node { textureLoad( matricesTexture, ivec2( x.add( 3 ), y ) ) ); - } + } const colorsTexture = this.batchMesh._colorsTexture; diff --git a/src/renderers/common/RenderObject.js b/src/renderers/common/RenderObject.js index 9284d56747a808..bd206139bb05a9 100644 --- a/src/renderers/common/RenderObject.js +++ b/src/renderers/common/RenderObject.js @@ -703,7 +703,7 @@ class RenderObject { } if ( object.isBatchedMesh ) { - + if ( object._matricesTexture !== null ) { cacheKey += object._matricesTexture.uuid + ',';