From 8a8d0700e0d3264d3e9250dfe44c9fb0cb3cd48a Mon Sep 17 00:00:00 2001 From: lindsay Date: Thu, 12 Oct 2023 18:00:11 +0200 Subject: [PATCH] Fix SceneModel instanced points --- src/viewer/scene/model/SceneModel.js | 3 ++- .../pointsInstancing/PointsInstancingLayer.js | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/viewer/scene/model/SceneModel.js b/src/viewer/scene/model/SceneModel.js index 4b331814c3..af38fda4c1 100644 --- a/src/viewer/scene/model/SceneModel.js +++ b/src/viewer/scene/model/SceneModel.js @@ -2916,7 +2916,8 @@ export class SceneModel extends Component { countIndices += cfg.positions ? cfg.positions.length : cfg.positionsCompressed.length; break; case VBO_INSTANCED: - countIndices += cfg.positions ? cfg.positions.length : cfg.positionsCompressed.length; + const geometry = cfg.geometry; + countIndices += geometry.positions ? geometry.positions.length : geometry.positionsCompressed.length; break; } return Math.round(countIndices); diff --git a/src/viewer/scene/model/vbo/pointsInstancing/PointsInstancingLayer.js b/src/viewer/scene/model/vbo/pointsInstancing/PointsInstancingLayer.js index 9a792f2e5b..5cfd117c0a 100644 --- a/src/viewer/scene/model/vbo/pointsInstancing/PointsInstancingLayer.js +++ b/src/viewer/scene/model/vbo/pointsInstancing/PointsInstancingLayer.js @@ -60,6 +60,7 @@ class PointsInstancingLayer { numInstances: 0, origin: cfg.origin ? math.vec3(cfg.origin) : null, geometry: cfg.geometry, + positionsDecodeMatrix: cfg.geometry.positionsDecodeMatrix, // So we can null the geometry for GC colorsBuf: null, flagsBuf: null, offsetsBuf: null, @@ -198,34 +199,46 @@ class PointsInstancingLayer { } const gl = this.model.scene.canvas.gl; const flagsLength = this._pickColors.length / 4; + const state = this._state; + const geometry = state.geometry; if (flagsLength > 0) { // Because we only build flags arrays here, // get their length from the colors array let notNormalized = false; - this._state.flagsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(flagsLength), flagsLength, 1, gl.DYNAMIC_DRAW, notNormalized); + state.flagsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(flagsLength), flagsLength, 1, gl.DYNAMIC_DRAW, notNormalized); } if (this.model.scene.entityOffsetsEnabled) { if (this._offsets.length > 0) { const notNormalized = false; - this._state.offsetsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._offsets), this._offsets.length, 3, gl.DYNAMIC_DRAW, notNormalized); + state.offsetsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._offsets), this._offsets.length, 3, gl.DYNAMIC_DRAW, notNormalized); this._offsets = []; // Release memory } } + if (geometry.positionsCompressed && geometry.positionsCompressed.length > 0) { + const normalized = false; + state.positionsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, geometry.positionsCompressed, geometry.positionsCompressed.length, 3, gl.STATIC_DRAW, normalized); + state.positionsDecodeMatrix = math.mat4(geometry.positionsDecodeMatrix); + } + if (geometry.colorsCompressed && geometry.colorsCompressed.length > 0) { + const colorsCompressed = new Uint8Array(geometry.colorsCompressed); + const notNormalized = false; + state.colorsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, colorsCompressed, colorsCompressed.length, 4, gl.STATIC_DRAW, notNormalized); + } if (this._modelMatrixCol0.length > 0) { const normalized = false; - this._state.modelMatrixCol0Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelMatrixCol0), this._modelMatrixCol0.length, 4, gl.STATIC_DRAW, normalized); - this._state.modelMatrixCol1Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelMatrixCol1), this._modelMatrixCol1.length, 4, gl.STATIC_DRAW, normalized); - this._state.modelMatrixCol2Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelMatrixCol2), this._modelMatrixCol2.length, 4, gl.STATIC_DRAW, normalized); + state.modelMatrixCol0Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelMatrixCol0), this._modelMatrixCol0.length, 4, gl.STATIC_DRAW, normalized); + state.modelMatrixCol1Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelMatrixCol1), this._modelMatrixCol1.length, 4, gl.STATIC_DRAW, normalized); + state.modelMatrixCol2Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelMatrixCol2), this._modelMatrixCol2.length, 4, gl.STATIC_DRAW, normalized); this._modelMatrixCol0 = []; this._modelMatrixCol1 = []; this._modelMatrixCol2 = []; } if (this._pickColors.length > 0) { const normalized = false; - this._state.pickColorsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Uint8Array(this._pickColors), this._pickColors.length, 4, gl.STATIC_DRAW, normalized); + state.pickColorsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Uint8Array(this._pickColors), this._pickColors.length, 4, gl.STATIC_DRAW, normalized); this._pickColors = []; // Release memory } - this._state.geometry = null; + state.geometry = null; this._finalized = true; }