Skip to content

Commit

Permalink
Merge branch 'main' into feature-4-diffuse-radiation-from-file
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianK13 authored May 13, 2024
2 parents bac77de + 8c9e476 commit 3b8e538
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 117 deletions.
14 changes: 11 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ export default class Scene {
* @param numberSimulations Number of random sun positions that are used to calculate the PV yield
* @returns
*/
async calculate(numberSimulations: number = 80, irradianceUrl: string | undefined) {

async calculate(
numberSimulations: number = 80,
irradianceUrl: string | undefined
progressCallback: (progress: number, total: number) => void = (progress, total) =>
console.log(`Progress: ${progress}/${total}%`),
) {
console.log('Simulation package was called to calculate');
let simulationGeometry = BufferGeometryUtils.mergeGeometries(this.simulationGeometries);
let shadingGeometry = BufferGeometryUtils.mergeGeometries(this.shadingGeometries);
Expand Down Expand Up @@ -141,7 +147,8 @@ export default class Scene {
}
}
// Compute unique intensities
const intensities = await this.rayTrace(midpointsArray, normalsArray, meshArray, numberSimulations, irradianceUrl);

const intensities = await this.rayTrace(midpointsArray, normalsArray, meshArray, numberSimulations, irradianceUrl, progressCallback);

if (intensities === null) {
throw new Error('Error raytracing in WebGL.');
Expand Down Expand Up @@ -205,6 +212,7 @@ export default class Scene {
meshArray: Float32Array,
numberSimulations: number,
diffuseIrradianceUrl: string | undefined = undefined,
progressCallback: (progress: number, total: number) => void,
) {
let directIrradiance: Point[] = [];
let diffuseIrradiance: Point[] = [];
Expand All @@ -225,6 +233,6 @@ export default class Scene {
}
}

return rayTracingWebGL(midpoints, normals, meshArray, directIrradiance, diffuseIrradiance);
return rayTracingWebGL(midpoints, normals, meshArray, directIrradiance, diffuseIrradiance, progressCallback);
}
}
5 changes: 4 additions & 1 deletion src/rayTracingWebGL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function rayTracingWebGL(
trianglesArray: TypedArray,
directRadiance: Point[],
diffuseRadiance: Point[],
progressCallback: (progress: number, total: number) => void,
): Float32Array | null {
const N_TRIANGLES = trianglesArray.length / 9;
const width = pointsArray.length / 3; // Change this to the number of horizontal points in the grid
Expand Down Expand Up @@ -180,8 +181,10 @@ export function rayTracingWebGL(

var colorCodedArray = null;
var isShadowedArray = null;

for (var i = 0; i < directRadiance.length; i += 1) {
console.log('Simulating sun position #', i, '/', directRadiance.length);
progressCallback(i, sunDirections.length);

// TODO: Iterate over sunDirection
let sunDirectionUniformLocation = gl.getUniformLocation(program, 'u_sun_direction');
gl.uniform3fv(sunDirectionUniformLocation, [
Expand Down
Loading

0 comments on commit 3b8e538

Please sign in to comment.