use bulk drawing
This commit is contained in:
@@ -10,9 +10,7 @@ window.BlockRenderer = class {
|
|||||||
let boundingBox = new BoundingBox(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
|
let boundingBox = new BoundingBox(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
|
||||||
|
|
||||||
for (let face = 0; face < 6; face++) {
|
for (let face = 0; face < 6; face++) {
|
||||||
this.tessellator.startDrawing();
|
|
||||||
this.renderFace(world, typeId, boundingBox, face, x, y, z);
|
this.renderFace(world, typeId, boundingBox, face, x, y, z);
|
||||||
this.tessellator.draw(group);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,22 +14,34 @@ window.Tessellator = class {
|
|||||||
startDrawing() {
|
startDrawing() {
|
||||||
this.verticies = [];
|
this.verticies = [];
|
||||||
this.uv = [];
|
this.uv = [];
|
||||||
|
this.index = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
addVertexWithUV(x, y, z, u, v) {
|
addVertexWithUV(x, y, z, u, v) {
|
||||||
|
// Add vertex
|
||||||
this.verticies.push(x);
|
this.verticies.push(x);
|
||||||
this.verticies.push(y);
|
this.verticies.push(y);
|
||||||
this.verticies.push(z);
|
this.verticies.push(z);
|
||||||
|
|
||||||
|
// Add UV
|
||||||
this.uv.push(u);
|
this.uv.push(u);
|
||||||
this.uv.push(v);
|
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) {
|
draw(group) {
|
||||||
let geometry = new THREE.BufferGeometry();
|
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.verticies), 3));
|
||||||
geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(this.uv), 2));
|
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);
|
let mesh = new THREE.Mesh(geometry, this.material);
|
||||||
group.add(mesh);
|
group.add(mesh);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ window.ChunkSection = class {
|
|||||||
this.dirty = false;
|
this.dirty = false;
|
||||||
this.group.clear();
|
this.group.clear();
|
||||||
|
|
||||||
|
renderer.blockRenderer.tessellator.startDrawing();
|
||||||
|
|
||||||
for (let x = 0; x < ChunkSection.SIZE; x++) {
|
for (let x = 0; x < ChunkSection.SIZE; x++) {
|
||||||
for (let y = 0; y < ChunkSection.SIZE; y++) {
|
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) {
|
getBlockAt(x, y, z) {
|
||||||
|
|||||||
Reference in New Issue
Block a user