Skip to content

Commit

Permalink
fix relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
sguimmara committed Sep 14, 2023
1 parent 116bc8b commit 64ace50
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ export function frameObject(obj: Node, camera: Camera) {
frameBounds(bounds, camera);
}

export async function loadPLYModel(): Promise<Mesh> {
function buildUrl(url: string) {
let base = '';
if (import.meta.env.PROD) {
base = import.meta.env.BASE_URL;
}
const res = await fetch(`${base}/files/hammerhead.ply`);

return `${base}${url}`;
}

export async function loadPLYModel(): Promise<Mesh> {
const res = await fetch(buildUrl('/files/hammerhead.ply'));
const text = await res.text();
const data = await parse(text, ply.PLYLoader);

Expand All @@ -56,7 +61,7 @@ export function load8bitImage(url: string): Promise<Texture> {
const img = new Image();
return new Promise((resolve, reject) => {
img.crossOrigin = 'anonymous';
img.src = url;
img.src = buildUrl(url);
img.onerror = reject;
img.onload = () => {
const source = new ImageSource(img);
Expand Down

0 comments on commit 64ace50

Please sign in to comment.