-
Notifications
You must be signed in to change notification settings - Fork 213
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
Open
andremig-bentley
wants to merge
15
commits into
master
Choose a base branch
from
andremig/texture-baseurl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a87a3cd
obtain base url for texture requests within reality tile loader
andremig-bentley de815e3
rush change
andremig-bentley 3f3e40e
Merge branch 'master' into andremig/texture-baseurl
andremig-bentley 6417760
rm treeid parsing, add rdsourceid, add tests
andremig-bentley 14f8930
extract api
andremig-bentley 68887c3
Merge branch 'andremig/texture-baseurl' of https://github.com/iTwin/i…
andremig-bentley 63541ff
Merge branch 'master' into andremig/texture-baseurl
andremig-bentley dba5f2d
Merge branch 'master' into andremig/texture-baseurl
andremig-bentley 5dcf8b8
Merge branch 'master' into andremig/texture-baseurl
pmconne 17e33c2
get url from TilesetUrlImpl, update tests
andremig-bentley 3840554
extract-api
andremig-bentley 8ce805d
Merge branch 'master' into andremig/texture-baseurl
andremig-bentley ba3f493
Merge branch 'master' into andremig/texture-baseurl
andremig-bentley ef6f8c0
Update core/frontend/src/tile/RealityTileLoader.ts
andremig-bentley 37131be
Merge branch 'master' into andremig/texture-baseurl
andremig-bentley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
common/changes/@itwin/core-frontend/andremig-texture-baseurl_2024-12-05-15-48.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", () => { | ||
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?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, "someIdThatIsNotAUrl"); | ||
expect(props?.baseUrl).to.be.undefined; | ||
|
||
props = createReaderPropsWithBaseUrl(glb, false, ""); | ||
expect(props?.baseUrl).to.be.undefined; | ||
|
||
props = createReaderPropsWithBaseUrl(glb, false, "textures/someRelativePath"); | ||
expect(props?.baseUrl).to.be.undefined; | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.