refactor project structure, implement tessellator

This commit is contained in:
LabyStudio
2022-01-31 20:15:27 +01:00
parent 192417f626
commit 293a6d9553
15 changed files with 160 additions and 36 deletions
@@ -0,0 +1,38 @@
window.Tessellator = class {
constructor() {
this.material = new THREE.MeshBasicMaterial({
color: 0xffffff,
side: THREE.BackSide
});
}
bindTexture(texture) {
this.material.map = texture;
}
startDrawing() {
this.verticies = [];
this.uv = [];
}
addVertexWithUV(x, y, z, u, v) {
this.verticies.push(x);
this.verticies.push(y);
this.verticies.push(z);
this.uv.push(u);
this.uv.push(v);
}
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));
let mesh = new THREE.Mesh(geometry, this.material);
group.add(mesh);
}
}