Redundant getFloatData in Geometry.setVerticesBuffer

Background

Currently in Geometry.setVerticesBuffer, it called this._updateExtend(buffer.getFloatData(this._totalVertices));, if setting a position buffer.

But the result of getFloatData is ignored, if this.useBoundingInfoFromGeometry && this._boundingInfo, which is true if the mesh is imported from gltf loader.

And getFloatData is a CPU and RAM heavy call, which costs ~27% of the CPU time of loading a gltf model in sandbox, and a Major GC.

Proposal

Lift the check in _updateExtend to setVerticesBuffer

diff --git a/packages/dev/core/src/Meshes/geometry.ts b/packages/dev/core/src/Meshes/geometry.ts
index 412ef07e3d..9bbc327d7d 100644
--- a/packages/dev/core/src/Meshes/geometry.ts
+++ b/packages/dev/core/src/Meshes/geometry.ts
@@ -310,7 +310,7 @@ export class Geometry implements IGetSetVerticesData {
         if (kind === VertexBuffer.PositionKind) {
             this._totalVertices = totalVertices ?? buffer._maxVerticesCount;

-            this._updateExtend(buffer.getFloatData(this._totalVertices));
+            this._updateExtend(this.useBoundingInfoFromGeometry && this._boundingInfo ? null : buffer.getFloatData(this._totalVertices));
             this._resetPointsArrayCache();

             // this._extend can be empty if buffer.getFloatData(this._totalVertices) returned null

2 Likes

YES! Totally! Excellent find!

Please author a PR so you can be remembered forever in the indestructible memory of github :smiley:

1 Like

Here it is:

2 Likes

Just one formatting issue and we can merge

I saw the CI log but failed to find the detailed info about the exact formatting err. Also I can not reproduce in my local repo with npm run format:check. Can you help with this?

let me check

I pushed a change on the last line we ll see what happen :slight_smile:

1 Like