Skip to content

Commit

Permalink
changes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck committed Oct 2, 2024
1 parent ab8b38a commit 03ce96d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
53 changes: 25 additions & 28 deletions src/file-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03ce96d

Please sign in to comment.