use bulk drawing

This commit is contained in:
LabyStudio
2022-01-31 20:24:53 +01:00
parent 293a6d9553
commit af525c88fa
3 changed files with 16 additions and 3 deletions
@@ -10,9 +10,7 @@ window.BlockRenderer = class {
let boundingBox = new BoundingBox(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
for (let face = 0; face < 6; face++) {
this.tessellator.startDrawing();
this.renderFace(world, typeId, boundingBox, face, x, y, z);
this.tessellator.draw(group);
}
}
@@ -14,22 +14,34 @@ window.Tessellator = class {
startDrawing() {
this.verticies = [];
this.uv = [];
this.index = [];
}
addVertexWithUV(x, y, z, u, v) {
// Add vertex
this.verticies.push(x);
this.verticies.push(y);
this.verticies.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('uv', new THREE.BufferAttribute(new Float32Array(this.uv), 2));
geometry.setIndex(new THREE.BufferAttribute(new Uint32Array([0, 2, 1, 0, 3, 2]), 1));
geometry.setIndex(new THREE.BufferAttribute(new Uint32Array(this.index), 1));
let mesh = new THREE.Mesh(geometry, this.material);
group.add(mesh);
@@ -27,6 +27,7 @@ window.ChunkSection = class {
this.dirty = false;
this.group.clear();
renderer.blockRenderer.tessellator.startDrawing();
for (let x = 0; x < ChunkSection.SIZE; x++) {
for (let y = 0; y < ChunkSection.SIZE; y++) {
@@ -43,6 +44,8 @@ window.ChunkSection = class {
}
}
}
renderer.blockRenderer.tessellator.draw(this.group);
}
getBlockAt(x, y, z) {