Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use provided xhrRequest when loading Potree2 hierarchy and octree #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/loading2/octree-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class NodeLoader {
gltfColorsPath = '';
gltfPositionsPath = '';

constructor(public getUrl: GetUrlFn, public url: string, public workerPool: WorkerPool, public metadata: Metadata) {
constructor(public getUrl: GetUrlFn, public url: string, public workerPool: WorkerPool, public metadata: Metadata, public xhrRequest: XhrRequest) {
}

async load(node: OctreeGeometryNode) {
Expand Down Expand Up @@ -63,15 +63,15 @@ export class NodeLoader {
const lastPositions = byteOffset * 4n * 3n + byteSize * 4n * 3n - 1n;

const headersPositions = { Range: `bytes=${firstPositions}-${lastPositions}` };
const responsePositions = await fetch(urlPositions, { headers: headersPositions });
const responsePositions = await this.xhrRequest(urlPositions, { headers: headersPositions });

const bufferPositions = await responsePositions.arrayBuffer();

const firstColors = byteOffset * 4n;
const lastColors = byteOffset * 4n + byteSize * 4n - 1n;

const headersColors = { Range: `bytes=${firstColors}-${lastColors}` };
const responseColors = await fetch(urlColors, { headers: headersColors });
const responseColors = await this.xhrRequest(urlColors, { headers: headersColors });
const bufferColors = await responseColors.arrayBuffer();

buffer = appendBuffer(bufferPositions, bufferColors);
Expand All @@ -88,7 +88,7 @@ export class NodeLoader {
console.warn(`loaded node with 0 bytes: ${node.name}`);
} else {
const headers = { Range: `bytes=${first}-${last}` };
const response = await fetch(urlOctree, { headers });
const response = await this.xhrRequest(urlOctree, { headers });

buffer = await response.arrayBuffer();
}
Expand Down Expand Up @@ -257,7 +257,7 @@ export class NodeLoader {
const last = first + hierarchyByteSize - BigInt(1);

const headers = { Range: `bytes=${first}-${last}` };
const response = await fetch(hierarchyUrl, { headers });
const response = await this.xhrRequest(hierarchyUrl, { headers });

const buffer = await response.arrayBuffer();

Expand Down Expand Up @@ -452,7 +452,7 @@ export class OctreeLoader {

this.applyCustomBufferURI(metadata.encoding, attributes);

const loader = this.createLoader(url, metadata, attributes);
const loader = this.createLoader(url, metadata, attributes, xhrRequest);

const boundingBox = this.createBoundingBox(metadata);
const offset = this.getOffset(boundingBox);
Expand All @@ -479,8 +479,8 @@ export class OctreeLoader {
}
}

private createLoader(url: string, metadata: Metadata, attributes: any): NodeLoader {
const loader = new NodeLoader(this.getUrl, url, this.workerPool, metadata);
private createLoader(url: string, metadata: Metadata, attributes: any, xhrRequest: XhrRequest): NodeLoader {
const loader = new NodeLoader(this.getUrl, url, this.workerPool, metadata, xhrRequest);
loader.attributes = attributes;
loader.scale = metadata.scale;
loader.offset = metadata.offset;
Expand Down