From af525c88fae8a09862f78cb8f97cad2828e227fe Mon Sep 17 00:00:00 2001 From: LabyStudio Date: Mon, 31 Jan 2022 20:24:53 +0100 Subject: [PATCH] use bulk drawing --- .../net/minecraft/client/render/BlockRenderer.js | 2 -- src/js/net/minecraft/client/render/Tessellator.js | 14 +++++++++++++- src/js/net/minecraft/client/world/ChunkSection.js | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/js/net/minecraft/client/render/BlockRenderer.js b/src/js/net/minecraft/client/render/BlockRenderer.js index 695e6ef..9679958 100644 --- a/src/js/net/minecraft/client/render/BlockRenderer.js +++ b/src/js/net/minecraft/client/render/BlockRenderer.js @@ -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); } } diff --git a/src/js/net/minecraft/client/render/Tessellator.js b/src/js/net/minecraft/client/render/Tessellator.js index dfb3046..115f0ca 100644 --- a/src/js/net/minecraft/client/render/Tessellator.js +++ b/src/js/net/minecraft/client/render/Tessellator.js @@ -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); diff --git a/src/js/net/minecraft/client/world/ChunkSection.js b/src/js/net/minecraft/client/world/ChunkSection.js index d049675..44e678f 100644 --- a/src/js/net/minecraft/client/world/ChunkSection.js +++ b/src/js/net/minecraft/client/world/ChunkSection.js @@ -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) {