diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index 08e4d00..d713ec1 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -77,6 +77,15 @@ return; } + // if the number of points has changed we will need to recreate the arraybuffers + if (this.vertices.length / 4 !== points.length) + { + this.vertices = new Float32Array(points.length * 4); + this.uvs = new Float32Array(points.length * 4); + this.colors = new Float32Array(points.length * 2); + this.indices = new Uint16Array(points.length * 2); + } + const uvs = this.uvs; const indices = this.indices; @@ -120,8 +129,9 @@ indices[index + 1] = index + 1; } - this.dirty = true; - this.indexDirty = true; + // ensure that the changes are uploaded + this.dirty++; + this.indexDirty++; } /** diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index 08e4d00..d713ec1 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -77,6 +77,15 @@ return; } + // if the number of points has changed we will need to recreate the arraybuffers + if (this.vertices.length / 4 !== points.length) + { + this.vertices = new Float32Array(points.length * 4); + this.uvs = new Float32Array(points.length * 4); + this.colors = new Float32Array(points.length * 2); + this.indices = new Uint16Array(points.length * 2); + } + const uvs = this.uvs; const indices = this.indices; @@ -120,8 +129,9 @@ indices[index + 1] = index + 1; } - this.dirty = true; - this.indexDirty = true; + // ensure that the changes are uploaded + this.dirty++; + this.indexDirty++; } /** diff --git a/src/mesh/webgl/MeshRenderer.js b/src/mesh/webgl/MeshRenderer.js index 73d78e6..d2625d4 100644 --- a/src/mesh/webgl/MeshRenderer.js +++ b/src/mesh/webgl/MeshRenderer.js @@ -77,17 +77,19 @@ if (mesh.dirty !== glData.dirty) { + glData.dirty = mesh.dirty; - glData.uvBuffer.upload(); + glData.uvBuffer.upload(mesh.uvs); } if (mesh.indexDirty !== glData.indexDirty) { glData.indexDirty = mesh.indexDirty; - glData.indexBuffer.upload(); + glData.indexBuffer.upload(mesh.indices); } - glData.vertexBuffer.upload(); + + glData.vertexBuffer.upload(mesh.vertices); renderer.bindShader(glData.shader); renderer.bindTexture(texture, 0);