Hello!
I hope it’s okay to ask a question which does not have a specific issue. My colleague and I wondered what difference it actually makes to set the “updateable” flag, but couldn’t articulate any answer.
I tried to follow the code in the library to figure out what happens. Two things I found:
- The updatable flag is simply passed almost 5 times until it’s actually read.
- I know that we currently use the ThinEngine class, which seems to be important, because the last method I could follow it to, accesses the engine instance.
Here my small “stackTrace” of what happens when I use: this.renderData.vertexData.applyToMesh(this.renderData.mesh, true)
Try to focus where the updateable is passed.
- mesh.vertexData.js (e.g if we set positions on a mesh)
*_applyToCoroutine(meshOrGeometry, updatable = false, isAsync) {
if (this.positions) {
meshOrGeometry.setVerticesData(VertexBuffer.PositionKind, this.positions, updatable);
if (isAsync) {
yield;
}
}
- mesh.js
setVerticesData(kind, data, updatable = false, stride) {
if (!this._geometry) {
const vertexData = new VertexData();
vertexData.set(data, kind);
const scene = this.getScene();
new Geometry(Geometry.RandomId(), scene, vertexData, updatable, this);
}
else {
this._geometry.setVerticesData(kind, data, updatable, stride);
}
return this;
}
- geometry.js
setVerticesData(kind, data, updatable = false, stride) {
if (updatable && Array.isArray(data)) {
// to avoid converting to Float32Array at each draw call in engine.updateDynamicVertexBuffer, we make the conversion a single time here
data = new Float32Array(data);
}
const buffer = new VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);
this.setVerticesBuffer(buffer);
}
- Buffer.js
create(data = null) {
if (!data && this._buffer) {
return; // nothing to do
}
data = data || this._data;
if (!data) {
return;
}
if (!this._buffer) {
// create buffer
if (this._updatable) {
this._buffer = this._engine.createDynamicVertexBuffer(data);
this._data = data;
}
else {
this._buffer = this._engine.createVertexBuffer(data);
}
console.log(this._engine)
}
else if (this._updatable) {
// update buffer
this._engine.updateDynamicVertexBuffer(this._buffer, data);
this._data = data;
}
}
This is where I stopped. I finally found the actually difference the flag is having, but I could not explain myself where the difference is beteam a DynamicVertexBuffer and VertexBuffer.
To give you some context:
We create Pointclouds on an event, and update the Points with the positions in a mesh.
To whoever reads this and takes the timer to answer, thanks already!