@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in
63 lines • 2.02 kB
JavaScript
import { Color } from "three";
import { Mathf } from "../../engine/engine_math.js";
/**
* RGBAColor is a class that represents a color with red, green, blue and alpha components.
*/
export class RGBAColor extends Color {
alpha = 1;
get isRGBAColor() { return true; }
set a(val) { this.alpha = val; }
get a() { return this.alpha; }
constructor(r, g, b, a) {
// if the user passed in the r, g, b, a components
if (g != undefined && b != undefined) {
super(r, g, b);
this.alpha = a;
}
// if the user passed in a color representation
else {
super(r);
this.alpha = 1;
}
}
clone() {
const cloned = super.clone();
cloned.alpha = this.alpha;
return cloned;
}
copy(col) {
this.r = col.r;
this.g = col.g;
this.b = col.b;
if ("alpha" in col && typeof col.alpha === "number") {
this.alpha = col.alpha;
}
else if (typeof col["a"] === "number")
this.alpha = col["a"];
return this;
}
lerp(color, alpha) {
const rgba = color;
if (rgba.alpha != undefined)
this.alpha = Mathf.lerp(this.alpha, rgba.alpha, alpha);
return super.lerp(color, alpha);
}
lerpColors(color1, color2, alpha) {
const rgba1 = color1;
const rgba2 = color2;
if (rgba1.alpha != undefined && rgba2.alpha != undefined)
this.alpha = Mathf.lerp(rgba1.alpha, rgba2.alpha, alpha);
return super.lerpColors(color1, color2, alpha);
}
multiply(color) {
const rgba = color;
if (rgba.alpha != undefined)
this.alpha = this.alpha * rgba.alpha;
return super.multiply(color);
}
fromArray(array, offset = 0) {
this.alpha = array[offset + 3];
return super.fromArray(array, offset);
}
}
//# sourceMappingURL=RGBAColor.js.map