Skip to content

Commit a99b794

Browse files
authored
Update ModelViewBatchedMesh.js
1 parent 266ea45 commit a99b794

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

example/src/plugins/batched/ModelViewBatchedMesh.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ export class ModelViewBatchedMesh extends BatchedMesh {
2525

2626
onBeforeRender( renderer, scene, camera, geometry, material, group ) {
2727

28+
// ensure matrices are complete and up to date
2829
super.onBeforeRender( renderer, scene, camera, geometry, material, group );
2930

31+
// retrieve camera before and after camera positions
3032
vec1.setFromMatrixPosition( camera.matrixWorld );
3133
vec2.setFromMatrixPosition( this._lastCameraPos );
3234

35+
// initialize the model-view matrix texture if needed
3336
const matricesTexture = this._matricesTexture;
3437
let modelViewMatricesTexture = this._modelViewMatricesTexture;
35-
3638
if (
3739
! modelViewMatricesTexture ||
3840
modelViewMatricesTexture.image.width !== matricesTexture.image.width ||
@@ -55,9 +57,10 @@ export class ModelViewBatchedMesh extends BatchedMesh {
5557

5658
}
5759

58-
60+
// check if we need to update the model view matrices
5961
if ( this._forceUpdate || vec1.distanceTo( vec2 ) > this.resetDistance ) {
6062

63+
// transform each objects matrix into local camera frame to avoid precision issues
6164
const matricesArray = matricesTexture.image.data;
6265
const modelViewArray = modelViewMatricesTexture.image.data;
6366
for ( let i = 0; i < this.maxInstanceCount; i ++ ) {
@@ -76,6 +79,8 @@ export class ModelViewBatchedMesh extends BatchedMesh {
7679

7780
}
7881

82+
// save handles, and transform the matrix world into the camera frame used to position the mesh instances
83+
// to offset the position shift.
7984
this._matricesTextureHandle = this._matricesTexture;
8085
this._matricesTexture = this._modelViewMatricesTexture;
8186
this.matrixWorld.copy( this._lastCameraPos );

0 commit comments

Comments
 (0)