kzhsw
August 14, 2025, 8:00am
1
Background
Currently in Geometry.setVerticesBuffer, it called this._updateExtend(buffer.getFloatData(this._totalVertices));, if setting a position buffer.
buffer._buffer._increaseReferences();
}
this._vertexBuffers[kind] = buffer;
const meshes = this._meshes;
const numOfMeshes = meshes.length;
if (kind === VertexBuffer.PositionKind) {
this._totalVertices = totalVertices ?? buffer._maxVerticesCount;
this._updateExtend(buffer.getFloatData(this._totalVertices));
this._resetPointsArrayCache();
// this._extend can be empty if buffer.getFloatData(this._totalVertices) returned null
const minimum = (this._extend && this._extend.minimum) || new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
const maximum = (this._extend && this._extend.maximum) || new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
for (let index = 0; index < numOfMeshes; index++) {
const mesh = meshes[index];
mesh.buildBoundingInfo(minimum, maximum);
mesh._createGlobalSubMesh(mesh.isUnIndexed);
But the result of getFloatData is ignored, if this.useBoundingInfoFromGeometry && this._boundingInfo, which is true if the mesh is imported from gltf loader.
meshes.push(mesh);
if (this.isReady()) {
this._applyToMesh(mesh);
} else if (this._boundingInfo) {
mesh.setBoundingInfo(this._boundingInfo);
}
}
private _updateExtend(data: Nullable<FloatArray> = null) {
if (this.useBoundingInfoFromGeometry && this._boundingInfo) {
this._extend = {
minimum: this._boundingInfo.minimum.clone(),
maximum: this._boundingInfo.maximum.clone(),
};
} else {
if (!data) {
data = this.getVerticesData(VertexBuffer.PositionKind)!;
// This can happen if the buffer comes from a Hardware Buffer where
// The data have not been uploaded by Babylon. (ex: Compute Shaders and Storage Buffers)
if (!data) {
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
1 Like
Just one formatting issue and we can merge
kzhsw
August 16, 2025, 12:25am
5
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?
I pushed a change on the last line we ll see what happen
1 Like