fix render glitches

This commit is contained in:
LabyStudio
2022-01-31 21:18:20 +01:00
parent af525c88fa
commit c63bf36bca
8 changed files with 66 additions and 30 deletions
@@ -12,36 +12,29 @@ window.Tessellator = class {
}
startDrawing() {
this.verticies = [];
this.addedVertices = 0;
this.vertices = [];
this.uv = [];
this.index = [];
}
addVertexWithUV(x, y, z, u, v) {
this.addedVertices++;
// Add vertex
this.verticies.push(x);
this.verticies.push(y);
this.verticies.push(z);
this.vertices.push(x);
this.vertices.push(y);
this.vertices.push(z);
// Add UV
this.uv.push(u);
this.uv.push(v);
// Add index
let index = this.index.length / 6;
this.index.push(index + 0);
this.index.push(index + 2);
this.index.push(index + 1);
this.index.push(index + 0);
this.index.push(index + 3);
this.index.push(index + 2);
}
draw(group) {
let geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.verticies), 3));
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.vertices), 3));
geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(this.uv), 2));
geometry.setIndex(new THREE.BufferAttribute(new Uint32Array(this.index), 1));
geometry.setIndex(new THREE.BufferAttribute(new Uint32Array([0, 2, 1, 0, 3, 2]), 1));
let mesh = new THREE.Mesh(geometry, this.material);
group.add(mesh);