Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pointsOnSphere(numPoints: number): Array {
/* Random directions in tangent space. */
const donkey = new Array(numPoints);
for (let i = 0; i < donkey.length; ++i) {
const bound = 1.0 - 1e-4;
const x = auxiliaries.rand(-bound, bound);
const z = auxiliaries.rand(-bound, bound);
const y = Math.sqrt(Math.max(1.0 - x * x - z * z, 1e-4));
donkey[i] = vec3.normalize(vec3.create(), vec3.fromValues(x, y, z));
}
return donkey;
}
pointsInLight(llf: vec3, urb: vec3, minN: number): Array {
const lights = Array();
const min = vec3.min(vec3.create(), llf, urb);
const max = vec3.max(vec3.create(), llf, urb);
const size = vec3.subtract(vec3.create(), max, min);
const r = Math.ceil(Math.sqrt(1.0 * minN));
const step = vec3.scale(vec3.create(), size, (1.0 - 1e-4) / (r - 1.0)); // the "<=" and floating precision
for (let x = min[0]; x <= max[0]; x += step[0]) {
for (let z = min[2]; z <= max[2]; z += step[2]) {
lights.push(vec3.fromValues(x, auxiliaries.rand(min[1], max[1]), z));
}
}
return this.shuffle(lights);
}
pointsInLight(llf: vec3, urb: vec3, minN: number): Array {
const lights = Array();
const min = vec3.min(vec3.create(), llf, urb);
const max = vec3.max(vec3.create(), llf, urb);
const size = vec3.subtract(vec3.create(), max, min);
const r = Math.ceil(Math.sqrt(1.0 * minN));
const step = vec3.scale(vec3.create(), size, (1.0 - 1e-4) / (r - 1.0)); // the "<=" and floating precision
for (let x = min[0]; x <= max[0]; x += step[0]) {
for (let z = min[2]; z <= max[2]; z += step[2]) {
lights.push(vec3.fromValues(x, auxiliaries.rand(min[1], max[1]), z));
}
}
return this.shuffle(lights);
}
this._camera.viewport = [this._frameSize[0], this._frameSize[1]];
}
if (this._altered.canvasSize) {
this._camera.aspect = this._canvasSize[0] / this._canvasSize[1];
}
if (this._altered.clearColor) {
this._defaultFBO.clearColor(this._clearColor);
}
if (this._altered.multiFrameNumber) {
this._ndcOffsetKernel = new AntiAliasingKernel(this._multiFrameNumber);
// /* Create light samples along circle around eye (light position). */
const n = vec3.sub(vec3.create(), this._light.eye, this._light.center);
vec3.normalize(n, n);
const u = vec3.cross(vec3.create(), n, vec3.fromValues(0.0, 1.0, 0.0));
const v = vec3.cross(vec3.create(), n, u);
this._lightSamples = new Array(this._multiFrameNumber);
for (let i = 0; i < this._multiFrameNumber; ++i) {
const p = vec3.clone(this._light.eye);
const r = Math.random() * 0.25; // Math.sqrt(i / this._multiFrameNumber);
const theta = Math.random() * Math.PI * 2.0;
vec3.scaleAndAdd(p, p, u, r * Math.cos(theta));
vec3.scaleAndAdd(p, p, v, r * Math.sin(theta));
this._lightSamples[i] = p;
pointsInLight(llf: vec3, urb: vec3, minN: number): Array {
const lights = Array();
const min = vec3.min(vec3.create(), llf, urb);
const max = vec3.max(vec3.create(), llf, urb);
const size = vec3.subtract(vec3.create(), max, min);
const r = Math.ceil(Math.sqrt(1.0 * minN));
const step = vec3.scale(vec3.create(), size, (1.0 - 1e-4) / (r - 1.0)); // the "<=" and floating precision
for (let x = min[0]; x <= max[0]; x += step[0]) {
for (let z = min[2]; z <= max[2]; z += step[2]) {
lights.push(vec3.fromValues(x, auxiliaries.rand(min[1], max[1]), z));
}
}
return this.shuffle(lights);
}
pointsInLight(llf: vec3, urb: vec3, minN: number): Array {
const lights = Array();
const min = vec3.min(vec3.create(), llf, urb);
const max = vec3.max(vec3.create(), llf, urb);
const size = vec3.subtract(vec3.create(), max, min);
const r = Math.ceil(Math.sqrt(1.0 * minN));
const step = vec3.scale(vec3.create(), size, (1.0 - 1e-4) / (r - 1.0)); // the "<=" and floating precision
for (let x = min[0]; x <= max[0]; x += step[0]) {
for (let z = min[2]; z <= max[2]; z += step[2]) {
lights.push(vec3.fromValues(x, auxiliaries.rand(min[1], max[1]), z));
}
}
return this.shuffle(lights);
}
this._camera.aspect = this._canvasSize[0] / this._canvasSize[1];
}
if (this._altered.clearColor) {
this._defaultFBO.clearColor(this._clearColor);
}
if (this._altered.multiFrameNumber) {
this._ndcOffsetKernel = new AntiAliasingKernel(this._multiFrameNumber);
// /* Create light samples along circle around eye (light position). */
const n = vec3.sub(vec3.create(), this._light.eye, this._light.center);
vec3.normalize(n, n);
const u = vec3.cross(vec3.create(), n, vec3.fromValues(0.0, 1.0, 0.0));
const v = vec3.cross(vec3.create(), n, u);
this._lightSamples = new Array(this._multiFrameNumber);
for (let i = 0; i < this._multiFrameNumber; ++i) {
const p = vec3.clone(this._light.eye);
const r = Math.random() * 0.25; // Math.sqrt(i / this._multiFrameNumber);
const theta = Math.random() * Math.PI * 2.0;
vec3.scaleAndAdd(p, p, u, r * Math.cos(theta));
vec3.scaleAndAdd(p, p, v, r * Math.sin(theta));
this._lightSamples[i] = p;
}
this._lightSamples.sort((a: vec3, b: vec3) =>
encodeFloatArray(floats: Float32Array): Uint8Array {
const byteEncodedArray = new Uint8Array(floats.length * 3);
for (let i = 0; i < floats.length; i++) {
const encodedVec3 = this.encode_float24x1_to_uint8x3(vec3.create(), floats[i]);
byteEncodedArray[3 * i + 0] = encodedVec3[0];
byteEncodedArray[3 * i + 1] = encodedVec3[1];
byteEncodedArray[3 * i + 2] = encodedVec3[2];
}
return byteEncodedArray;
}
encodeFloatArrayAndScale(floats: Float32Array): Uint8Array {
const byteEncodedArray = new Uint8Array(floats.length * 3);
for (let i = 0; i < floats.length; i++) {
const encodedVec3 = this.encode_float24x1_to_uint8x3(vec3.create(), floats[i] * 0.5 + 0.5);
byteEncodedArray[3 * i + 0] = encodedVec3[0];
byteEncodedArray[3 * i + 1] = encodedVec3[1];
byteEncodedArray[3 * i + 2] = encodedVec3[2];
}
return byteEncodedArray;
}