diff --git a/rollup.config.mjs b/rollup.config.mjs index 0cab93c..88e6337 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -35,7 +35,7 @@ const outputHeader = () => { const RESET_OUT = `\x1b[0m`; const title = [ - `Building PlayCanvas Model Viewer`, + `Building SuperSplat`, `type ${BOLD_OUT}${BUILD_TYPE}${REGULAR_OUT}`, `engine ${BOLD_OUT}${ENGINE_DIR}${REGULAR_OUT}`, `pcui ${BOLD_OUT}${PCUI_DIR}${REGULAR_OUT}` diff --git a/src/file-handler.ts b/src/file-handler.ts index adfeb15..d49f0fa 100644 --- a/src/file-handler.ts +++ b/src/file-handler.ts @@ -88,37 +88,34 @@ const writeToFile = async (stream: FileSystemWritableFileStream, data: ArrayBuff await stream.close(); }; -const loadCameraPoses = (url: string, filename: string, events: Events) => { - return fetch(url) - .then((response) => response.json()) - .then((json) => { - if (json.length > 0) { - - // calculate the average position of the camera poses - const ave = new Vec3(0, 0, 0); - json.forEach((pose: any) => { - vec.set(pose.position[0], pose.position[1], pose.position[2]); - ave.add(vec); - }); - ave.mulScalar(1 / json.length); +const loadCameraPoses = async (url: string, filename: string, events: Events) => { + const response = await fetch(url); + const json = await response.json(); + if (json.length > 0) { + // calculate the average position of the camera poses + const ave = new Vec3(0, 0, 0); + json.forEach((pose: any) => { + vec.set(pose.position[0], pose.position[1], pose.position[2]); + ave.add(vec); + }); + ave.mulScalar(1 / json.length); - json.forEach((pose: any, i: number) => { - if (pose.hasOwnProperty('position') && pose.hasOwnProperty('rotation')) { - const p = new Vec3(pose.position); - const z = new Vec3(pose.rotation[0][2], pose.rotation[1][2], pose.rotation[2][2]); + json.forEach((pose: any, i: number) => { + if (pose.hasOwnProperty('position') && pose.hasOwnProperty('rotation')) { + const p = new Vec3(pose.position); + const z = new Vec3(pose.rotation[0][2], pose.rotation[1][2], pose.rotation[2][2]); - const dot = vec.sub2(ave, p).dot(z); - vec.copy(z).mulScalar(dot).add(p); + const dot = vec.sub2(ave, p).dot(z); + vec.copy(z).mulScalar(dot).add(p); - events.fire('camera.addPose', { - name: pose.img_name ?? `${filename}_${i}`, - position: new Vec3(-p.x, -p.y, p.z), - target: new Vec3(-vec.x, -vec.y, vec.z) - }); - } - }); - } - }) + events.fire('camera.addPose', { + name: pose.img_name ?? `${filename}_${i}`, + position: new Vec3(-p.x, -p.y, p.z), + target: new Vec3(-vec.x, -vec.y, vec.z) + }); + } + }); + } }; // initialize file handler events