Skip to content

Commit

Permalink
Improve path tracer type handling
Browse files Browse the repository at this point in the history
Add documentation and explicit types
  • Loading branch information
StuckiSimon committed Aug 14, 2024
1 parent 46d7a1b commit 0399f3c
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions strahl-lib/src/path-tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import {
ViewProjectionConfiguration,
} from "./camera";
import { buildAbortEventHub } from "./util/abort-event-hub.ts";
import { Group } from "three";

function prepareGeometry(model: any) {
function prepareGeometry(model: { scene: Group }) {
const reducedModel = consolidateMesh([model.scene]);
const cpuLogGroup = logGroup("cpu");
const boundsTree = new MeshBVH(reducedModel.geometry, {
Expand Down Expand Up @@ -74,6 +75,9 @@ function prepareGeometry(model: any) {
};
}

/**
* Configuration options for the path tracer.
*/
export type PathTracerOptions = {
targetSamples?: number;
kTextureWidth?: number;
Expand All @@ -82,15 +86,26 @@ export type PathTracerOptions = {
samplesPerIteration?: number;
clearColor?: number[];
maxRayDepth?: number;
// todo: add real type
finishedSampling?: (result: any) => void;
finishedSampling?: (result: {
bvhBuildTime: number;
fullRenderLoopTime: number;
allRenderTime: number;
renderTimes: number[];
}) => void;
signal?: AbortSignal;
enableTimestampQuery?: boolean;
};

/**
* Main routine to generate renderings.
* @param target ID of the canvas element to render to
* @param model The model to render
* @param options Options for the path tracer
* @returns A promise that resolves when the path tracer has finished setting up, but not when the path tracer has finished rendering.
*/
async function runPathTracer(
target: string,
model: any,
model: { scene: Group },
{
targetSamples = 300,
kTextureWidth = 512,
Expand All @@ -109,7 +124,7 @@ async function runPathTracer(
clearColor = [1.0, 1.0, 1.0],
maxRayDepth = 5,
enableTimestampQuery = true,
finishedSampling = () => {},
finishedSampling,
signal = new AbortController().signal,
}: PathTracerOptions = {},
) {
Expand Down

0 comments on commit 0399f3c

Please sign in to comment.