-
Notifications
You must be signed in to change notification settings - Fork 216
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
Obtain Base Url for Texture Requests within Reality Tile Loader #7450
base: master
Are you sure you want to change the base?
Changes from 13 commits
a87a3cd
de815e3
3f3e40e
6417760
14f8930
68887c3
63541ff
dba5f2d
5dcf8b8
17e33c2
3840554
8ce805d
ba3f493
ef6f8c0
37131be
64ad23a
24c76f9
9bc4447
913f3cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@itwin/core-frontend", | ||
"comment": "", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@itwin/core-frontend" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { describe, expect, it } from "vitest"; | ||
import { createReaderPropsWithBaseUrl } from "../../tile/RealityTileLoader"; | ||
import { GltfV2ChunkTypes, GltfVersions, TileFormat } from "@itwin/core-common"; | ||
|
||
const minimalBin = new Uint8Array([12, 34, 0xfe, 0xdc]); | ||
const minimalJson = { asset: { version: "02.00" }, meshes: [] }; | ||
|
||
function jsonToBytes(json: object, alignment = 4): Uint8Array { | ||
let str = JSON.stringify(json); | ||
while (str.length % alignment !== 0) | ||
str += " "; | ||
|
||
const bytes = new TextEncoder().encode(str); | ||
expect(bytes.length).toEqual(str.length); // pure ASCII | ||
return bytes; | ||
} | ||
|
||
function setHeader(data: Uint8Array | DataView, length: number, format = TileFormat.Gltf, version = GltfVersions.Version2): void { | ||
if (data instanceof Uint8Array) | ||
data = new DataView(data.buffer); | ||
|
||
data.setUint32(0, format, true); | ||
data.setUint32(4, version, true); | ||
data.setUint32(8, length, true); | ||
} | ||
|
||
interface Chunk { | ||
len?: number; | ||
type: number; | ||
data: Uint8Array; | ||
} | ||
|
||
interface Header { | ||
len?: number; | ||
format: number; | ||
version: number; | ||
} | ||
function glbFromChunks(chunks: Chunk[], header?: Header): Uint8Array { | ||
let numBytes = 12; | ||
for (const chunk of chunks) | ||
numBytes += 8 + (chunk.len ?? chunk.data.length); | ||
|
||
const glb = new Uint8Array(numBytes); | ||
const view = new DataView(glb.buffer); | ||
|
||
header = header ?? { format: TileFormat.Gltf, version: GltfVersions.Version2 }; | ||
setHeader(view, header.len ?? numBytes, header.format, header.version); | ||
|
||
let chunkStart = 12; | ||
for (const chunk of chunks) { | ||
view.setUint32(chunkStart + 0, chunk.len ?? chunk.data.length, true); | ||
view.setUint32(chunkStart + 4, chunk.type, true); | ||
glb.set(chunk.data, chunkStart + 8); | ||
chunkStart += chunk.data.length + 8; | ||
} | ||
|
||
return glb; | ||
} | ||
|
||
function makeGlb(json: object | undefined, binary?: Uint8Array, header?: Header): Uint8Array { | ||
const chunks = []; | ||
if (json) | ||
chunks.push({ type: GltfV2ChunkTypes.JSON, data: jsonToBytes(json) }); | ||
|
||
if (binary) | ||
chunks.push({ type: GltfV2ChunkTypes.Binary, data: binary }); | ||
|
||
return glbFromChunks(chunks, header); | ||
} | ||
|
||
describe("createReaderPropsWithBaseUrl", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests don't prove much. A much more valuable test would confirm that you successfully resolve a resource inside the glTF with a relative URL where prior to your change you would have failed to do so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests have been added now to |
||
const glb = makeGlb(minimalJson, minimalBin); | ||
it("should add a valid base url to the reader props", {}, () => { | ||
let props = createReaderPropsWithBaseUrl(glb, false, "http://localhost:8080/tileset.json"); | ||
expect(props?.baseUrl?.toString()).to.equal("http://localhost:8080/tileset.json"); | ||
|
||
props = createReaderPropsWithBaseUrl(glb, false, "https://some-blob-storage.com/tileset.json"); | ||
expect(props?.baseUrl?.toString()).to.equal("https://some-blob-storage.com/tileset.json"); | ||
|
||
props = createReaderPropsWithBaseUrl(glb, false, "https://some-blob-storage.com/tileset.json?with-some-query-params"); | ||
expect(props?.baseUrl?.toString()).to.equal("https://some-blob-storage.com/tileset.json?with-some-query-params"); | ||
}); | ||
|
||
it("should not add an invalid base url to the reader props", {}, () => { | ||
let props = createReaderPropsWithBaseUrl(glb, false, ""); | ||
expect(props?.baseUrl).to.be.undefined; | ||
|
||
props = createReaderPropsWithBaseUrl(glb, false, "some-invalid-url"); | ||
expect(props?.baseUrl).to.be.undefined; | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this, add an optional method on the
RealityDataSource
interface, and implement it inRealityDataSourceTilesetUrlImpl
. That will allow any other implementations ofRealityDataSource
to implement it themselves if they so choose.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in the latest commit