Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory usage in bakeTransformIntoVertices #13193

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/dev/core/src/Meshes/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2657,22 +2657,23 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {

let data = <FloatArray>this.getVerticesData(VertexBuffer.PositionKind);

let temp = new Array<number>();
const temp = Vector3.Zero();
let index: number;
for (index = 0; index < data.length; index += 3) {
Vector3.TransformCoordinates(Vector3.FromArray(data, index), transform).toArray(temp, index);
Vector3.TransformCoordinatesFromFloatsToRef(data[index], data[index + 1], data[index + 2], transform, temp).toArray(data, index);
}

this.setVerticesData(VertexBuffer.PositionKind, temp, (<VertexBuffer>this.getVertexBuffer(VertexBuffer.PositionKind)).isUpdatable());
this.setVerticesData(VertexBuffer.PositionKind, data, (<VertexBuffer>this.getVertexBuffer(VertexBuffer.PositionKind)).isUpdatable());

// Normals
if (this.isVerticesDataPresent(VertexBuffer.NormalKind)) {
data = <FloatArray>this.getVerticesData(VertexBuffer.NormalKind);
temp = [];
for (index = 0; index < data.length; index += 3) {
Vector3.TransformNormal(Vector3.FromArray(data, index), transform).normalize().toArray(temp, index);
Vector3.TransformNormalFromFloatsToRef(data[index], data[index + 1], data[index + 2], transform, temp)
.normalize()
.toArray(data, index);
}
this.setVerticesData(VertexBuffer.NormalKind, temp, (<VertexBuffer>this.getVertexBuffer(VertexBuffer.NormalKind)).isUpdatable());
this.setVerticesData(VertexBuffer.NormalKind, data, (<VertexBuffer>this.getVertexBuffer(VertexBuffer.NormalKind)).isUpdatable());
}

// flip faces?
Expand Down