implement sunrise and sunset, improve sky coloring, implement alpha channel in Tessellator, update threejs
This commit is contained in:
@@ -2,11 +2,16 @@ export default class Tessellator {
|
||||
|
||||
constructor() {
|
||||
this.material = new THREE.MeshBasicMaterial({
|
||||
vertexColors: THREE.VertexColors,
|
||||
side: THREE.FrontSide,
|
||||
transparent: true,
|
||||
depthTest: true
|
||||
depthTest: true,
|
||||
vertexColors: true
|
||||
});
|
||||
|
||||
this.red = 0;
|
||||
this.green = 0;
|
||||
this.blue = 0;
|
||||
this.alpha = 0;
|
||||
}
|
||||
|
||||
bindTexture(texture) {
|
||||
@@ -20,13 +25,14 @@ export default class Tessellator {
|
||||
this.colors = [];
|
||||
}
|
||||
|
||||
setColor(red, green, blue) {
|
||||
setColor(red, green, blue, alpha = 1) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
addVertexWithUV(x, y, z, u, v) {
|
||||
addVertex(x, y, z) {
|
||||
this.addedVertices++;
|
||||
|
||||
// Add vertex
|
||||
@@ -34,27 +40,36 @@ export default class Tessellator {
|
||||
this.vertices.push(y);
|
||||
this.vertices.push(z);
|
||||
|
||||
// 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);
|
||||
this.colors.push(this.alpha);
|
||||
}
|
||||
|
||||
addVertexWithUV(x, y, z, u, v) {
|
||||
this.addVertex(x, y, z);
|
||||
|
||||
// Add UV
|
||||
this.uv.push(u);
|
||||
this.uv.push(v);
|
||||
}
|
||||
|
||||
transformBrightness(brightness) {
|
||||
for (let i in this.colors) {
|
||||
this.colors[i] *= brightness;
|
||||
for (let i = 0; i < this.colors.length / 4; i++) {
|
||||
this.colors[i * 4 + 0] *= brightness;
|
||||
this.colors[i * 4 + 1] *= brightness;
|
||||
this.colors[i * 4 + 2] *= brightness;
|
||||
}
|
||||
}
|
||||
|
||||
draw(group) {
|
||||
let geometry = new THREE.BufferGeometry();
|
||||
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.vertices), 3));
|
||||
geometry.setAttribute('color', new THREE.BufferAttribute(new Float32Array(this.colors), 3));
|
||||
geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(this.uv), 2));
|
||||
geometry.setAttribute('color', new THREE.BufferAttribute(new Float32Array(this.colors), 4));
|
||||
if (this.uv.length > 0) {
|
||||
geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(this.uv), 2));
|
||||
}
|
||||
|
||||
// Create index array
|
||||
let index = [];
|
||||
|
||||
Reference in New Issue
Block a user