implement shading

This commit is contained in:
LabyStudio
2022-01-31 21:32:35 +01:00
parent c63bf36bca
commit 00af52a66a
3 changed files with 38 additions and 2 deletions
@@ -2,8 +2,10 @@ window.Tessellator = class {
constructor() {
this.material = new THREE.MeshBasicMaterial({
vertexColors: THREE.VertexColors,
color: 0xffffff,
side: THREE.BackSide
side: THREE.BackSide,
overdraw: 1
});
}
@@ -15,6 +17,13 @@ window.Tessellator = class {
this.addedVertices = 0;
this.vertices = [];
this.uv = [];
this.colors = [];
}
setColor(red, green, blue) {
this.red = red;
this.green = green;
this.blue = blue;
}
addVertexWithUV(x, y, z, u, v) {
@@ -28,11 +37,17 @@ window.Tessellator = class {
// Add UV
this.uv.push(u);
this.uv.push(v);
// Add colors
this.colors.push(this.red);
this.colors.push(this.green);
this.colors.push(this.blue);
}
draw(group) {
let geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.vertices), 3));
geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(this.colors), 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));