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

Make tileset sources and targets asynchronous #167

Merged
merged 25 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c5569a8
First draft of async sources and targets
javagl Nov 20, 2024
8c83bc5
Emit a linting error for floating promises
javagl Nov 20, 2024
a6e350d
Update demos for async API
javagl Nov 20, 2024
b5f538d
Merge remote-tracking branch 'upstream/main' into async-source-and-ta…
javagl Nov 24, 2024
6807ac4
Formatting for demos
javagl Nov 24, 2024
948b044
Fix typo
javagl Nov 24, 2024
d8cfe52
Generalizations. Utility methods. Moved internal methods.
javagl Nov 24, 2024
891ae58
Merge remote-tracking branch 'origin/main' into async-source-and-target
javagl Jan 19, 2025
3e7c3fc
Merge remote-tracking branch 'upstream/main' into async-source-and-ta…
javagl Jan 19, 2025
a345f5d
Update spec for async source and target
javagl Jan 19, 2025
bd9a171
Fix convenience function for creating source and target
javagl Jan 19, 2025
7b44e81
More sensible parameter names
javagl Jan 19, 2025
09493dc
Accept files for file-system based source and target
javagl Jan 19, 2025
4889d7f
Update eslintignore
javagl Jan 19, 2025
e1afcb4
Offer operations on source and target objects
javagl Jan 21, 2025
5afdeab
Return subtree URI only for implicit tiles
javagl Jan 22, 2025
385f8f1
Minor clarification in documentation
javagl Jan 22, 2025
2b8a91b
Offer merge directly on sources and target
javagl Jan 22, 2025
5af8202
Clarifications and cleanups for comments
javagl Jan 22, 2025
46ce350
Cleanup to use existing utility function
javagl Jan 24, 2025
e6a9739
Added filterAsync to Iterables
javagl Jan 25, 2025
5d7cdd0
Added resolveUri back to resource resolver
javagl Jan 25, 2025
9cb2bbb
Add tileset to traversed tile
javagl Jan 25, 2025
c7d0f31
Update mock resolver in spec for new function
javagl Jan 25, 2025
85f3ab5
Replace dummy B3DMs with valid ones
javagl Jan 26, 2025
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist
etc
generateThirdParty.js
src/ktx/ktx/external/basis_encoder.cjs
demos
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020
"ecmaVersion": 2020,
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"root": true,
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-interface": "off"
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-floating-promises": "error"
}
}
2 changes: 1 addition & 1 deletion demos/base/ContentDataTypeChecksDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ async function testContentDataTypeChecks() {
}
}

testContentDataTypeChecks();
void testContentDataTypeChecks();
2 changes: 1 addition & 1 deletion demos/base/ContentDataTypeRegistryDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ async function testContentDataTypeRegistry() {
}
}

testContentDataTypeRegistry();
void testContentDataTypeRegistry();
4 changes: 2 additions & 2 deletions demos/gltf-extensions/ExtInstanceFeaturesDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ async function runReadingExample() {
console.log(s);
}

runCreationExample();
runReadingExample();
void runCreationExample();
void runReadingExample();
4 changes: 2 additions & 2 deletions demos/gltf-extensions/ExtMeshFeaturesDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ async function runReadingExample() {
console.log(s);
}

runCreationExample();
runReadingExample();
void runCreationExample();
void runReadingExample();
4 changes: 2 additions & 2 deletions demos/gltf-extensions/ExtMeshFeaturesGeometryDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,5 @@ async function runReadingExample() {
console.log(s);
}

runCreationExample();
runReadingExample();
void runCreationExample();
void runReadingExample();
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ async function runCreationExample() {
console.log(JSON.stringify(written.json, null, 2));
}

runCreationExample();
void runCreationExample();
2 changes: 1 addition & 1 deletion demos/ktx/KtxDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ async function runDemo() {
await convertImageData();
}

runDemo();
void runDemo();
21 changes: 12 additions & 9 deletions demos/tilesets/PackageConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,22 @@ async function tilesetPackageConversion(options: any) {
overwrite
);
} else {
const tilesetSource = TilesetSources.createAndOpen(input);
const tilesetTarget = TilesetTargets.createAndBegin(output, overwrite);
const tilesetSource = await TilesetSources.createAndOpen(input);
const tilesetTarget = await TilesetTargets.createAndBegin(
output,
overwrite
);

const keys = tilesetSource.getKeys();
for (const key of keys) {
const content = tilesetSource.getValue(key);
const keys = await tilesetSource.getKeys();
for await (const key of keys) {
const content = await tilesetSource.getValue(key);
// TODO Compression or decompression could happen here...
if (content) {
tilesetTarget.addEntry(key, content);
await tilesetTarget.addEntry(key, content);
}
}

tilesetSource.close();
await tilesetSource.close();
await tilesetTarget.end();
}
}
Expand All @@ -103,7 +106,7 @@ async function run() {
if (options === undefined) {
return;
}
tilesetPackageConversion(options);
await tilesetPackageConversion(options);
}

run();
void run();
12 changes: 6 additions & 6 deletions demos/tilesets/PackageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function determineMimeType(fileName: string, content: Buffer | undefined) {
* @param req The request
* @param res The response
*/
function handleRequest(
async function handleRequest(
tilesetSource: TilesetSource,
req: http.IncomingMessage,
res: http.ServerResponse<http.IncomingMessage>
Expand Down Expand Up @@ -124,7 +124,7 @@ function handleRequest(
if (nameEnd != -1) {
path = path.substring(0, nameEnd);
}
const content = tilesetSource.getValue(path);
const content = await tilesetSource.getValue(path);

//console.log("Content for " + path + " is " + content?.length);

Expand Down Expand Up @@ -154,7 +154,7 @@ function handleRequest(
*
* @param options The options
*/
function startServer(options: any) {
async function startServer(options: any) {
const hostName = options.hostName;
const port = options.port;
const sourceName = options.sourceName;
Expand All @@ -165,7 +165,7 @@ function startServer(options: any) {
console.log("Could not create source for " + sourceName);
return;
}
tilesetSource.open(sourceName);
await tilesetSource.open(sourceName);
const server = http.createServer((req, res) =>
handleRequest(tilesetSource, req, res)
);
Expand All @@ -183,7 +183,7 @@ async function run() {
if (options === undefined) {
return;
}
startServer(options);
await startServer(options);
}

run();
void run();
22 changes: 13 additions & 9 deletions demos/tilesets/PackagesDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ async function createPackageExample(fileName: string) {
console.log("Creating package " + fileName);

const overwrite = true;
const tilesetTarget = TilesetTargets.createAndBegin(fileName, overwrite);
const tilesetTarget = await TilesetTargets.createAndBegin(
fileName,
overwrite
);

tilesetTarget.addEntry("example.json", Buffer.alloc(100));
tilesetTarget.addEntry("example.glb", Buffer.alloc(1000));
await tilesetTarget.addEntry("example.json", Buffer.alloc(100));
await tilesetTarget.addEntry("example.glb", Buffer.alloc(1000));

await tilesetTarget.end();

Expand All @@ -30,20 +33,21 @@ async function createPackageExample(fileName: string) {
async function readPackageExample(fileName: string) {
console.log("Reading package " + fileName);

const tilesetSource = TilesetSources.createAndOpen(fileName);
const tilesetSource = await TilesetSources.createAndOpen(fileName);

console.log("Package contents:");
for (const key of tilesetSource.getKeys()) {
const keys = await tilesetSource.getKeys();
for await (const key of keys) {
console.log(" key: " + key);
}

const valueA = tilesetSource.getValue("example.json");
const valueA = await tilesetSource.getValue("example.json");
console.log("Value for example.json ", valueA);

const valueB = tilesetSource.getValue("example.glb");
const valueB = await tilesetSource.getValue("example.glb");
console.log("Value for example.glb ", valueB);

tilesetSource.close();
await tilesetSource.close();

console.log("Reading package DONE");
}
Expand All @@ -67,4 +71,4 @@ async function run() {
console.log("Running test DONE");
}

run();
void run();
8 changes: 4 additions & 4 deletions demos/tilesets/TileFormatsDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function b3dmOrI3dmToGlb(inputFileName: string, outputFileName: string) {
fs.writeFileSync(outputFileName, upgradedOutputBuffer);
}

function testTileFormatsDemotConversions() {
async function testTileFormatsDemotConversions() {
Paths.ensureDirectoryExists(SPECS_DATA_BASE_DIRECTORY + "/output");

glbToB3dm(
Expand All @@ -55,15 +55,15 @@ function testTileFormatsDemotConversions() {
SPECS_DATA_BASE_DIRECTORY + "/output/CesiumTexturedBox.i3dm"
);

b3dmOrI3dmToGlb(
await b3dmOrI3dmToGlb(
SPECS_DATA_BASE_DIRECTORY + "/batchedWithBatchTableBinary.b3dm",
SPECS_DATA_BASE_DIRECTORY + "/output/batchedWithBatchTableBinary.glb"
);

b3dmOrI3dmToGlb(
await b3dmOrI3dmToGlb(
SPECS_DATA_BASE_DIRECTORY + "/instancedWithBatchTableBinary.i3dm",
SPECS_DATA_BASE_DIRECTORY + "/output/instancedWithBatchTableBinary.glb"
);
}

testTileFormatsDemotConversions();
void testTileFormatsDemotConversions();
2 changes: 1 addition & 1 deletion demos/tilesets/TraversalDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ async function runDemo() {
await runExternalDemo();
}

runDemo();
void runDemo();
2 changes: 1 addition & 1 deletion demos/tilesets/TraversalStatsDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ async function runDemo() {
await tilesetTraversalDemo(tilesetFileName);
}

runDemo();
void runDemo();
2 changes: 1 addition & 1 deletion demos/tools/BasicTilesetProcessorExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ async function example() {
await tilesetProcessor.end();
}

example();
void example();
2 changes: 1 addition & 1 deletion demos/tools/ImplicitToExplicitDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ async function runDemo() {
await runConversionDemo(tilesetSourceName, tilesetTargetName);
}

runDemo();
void runDemo();
2 changes: 1 addition & 1 deletion demos/tools/PipelineExperimentsContentStages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ async function example() {
);
}

example();
void example();
2 changes: 1 addition & 1 deletion demos/tools/PipelineExperimentsTilesetStages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ async function example() {
await PipelineExecutor.executePipeline(pipeline, overwrite);
}

example();
void example();
2 changes: 1 addition & 1 deletion demos/tools/SubtreeInfoDemos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ async function runDemos() {
await testSubtreeInfo();
}

runDemos();
void runDemos();
10 changes: 6 additions & 4 deletions demos/tools/TileContentProcessingDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TileContentProcessorsGltfpack } from "3d-tiles-tools";
import { GltfPackOptions } from "3d-tiles-tools";

// The intention of this demo is to show the effects of compression that
// may be applied with glTF-Transform, gltf-pipeline, or gltfpack. To
// may be applied with glTF-Transform, gltf-pipeline, or gltfpack. To
// show these effects, the input tilesets should be large and complex.
// Therefore, the input here is not part of the repository.
const tilesetSourceName = "./input/TestTileset";
Expand Down Expand Up @@ -92,6 +92,8 @@ async function runDemoGltfPack() {
);
}

runDemo();

runDemoGltfPack();
async function run() {
await runDemo();
await runDemoGltfPack();
}
void run();
2 changes: 1 addition & 1 deletion demos/tools/TilesetDataProcessorExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ async function example() {
await tilesetProcessor.end();
}

example();
void example();
2 changes: 1 addition & 1 deletion demos/tools/TilesetProcessingDemos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ async function tilesetProcessingDemos() {
);
}

tilesetProcessingDemos();
void tilesetProcessingDemos();
2 changes: 1 addition & 1 deletion demos/tools/TilesetUpgraderDemos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ async function tilesetUpgraderDemos() {
);
}

tilesetUpgraderDemos();
void tilesetUpgraderDemos();
32 changes: 17 additions & 15 deletions specs/SpecHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ export class SpecHelpers {
* @returns The tileset
* @throws DeveloperError if the tileset could not be read
*/
static parseTileset(tilesetSource: TilesetSource) {
const tilesetJsonBuffer = tilesetSource.getValue("tileset.json");
static async parseTileset(tilesetSource: TilesetSource): Promise<Tileset> {
const tilesetJsonBuffer = await tilesetSource.getValue("tileset.json");
if (!tilesetJsonBuffer) {
throw new DeveloperError("No tileset.json found in input");
}
Expand All @@ -262,20 +262,20 @@ export class SpecHelpers {
* @returns A string describing the difference, or `undefined`
* if there is no difference.
*/
static computePackageDifference(
static async computePackageDifference(
nameA: string,
nameB: string
): string | undefined {
const tilesetSourceA = TilesetSources.createAndOpen(nameA);
const tilesetSourceB = TilesetSources.createAndOpen(nameB);
const result = SpecHelpers.computePackageDifferenceInternal(
): Promise<string | undefined> {
const tilesetSourceA = await TilesetSources.createAndOpen(nameA);
const tilesetSourceB = await TilesetSources.createAndOpen(nameB);
const result = await SpecHelpers.computePackageDifferenceInternal(
nameA,
tilesetSourceA,
nameB,
tilesetSourceB
);
tilesetSourceA.close();
tilesetSourceB.close();
await tilesetSourceA.close();
await tilesetSourceB.close();
return result;
}

Expand All @@ -297,14 +297,16 @@ export class SpecHelpers {
* @returns A string describing the difference, or `undefined`
* if there is no difference.
*/
static computePackageDifferenceInternal(
static async computePackageDifferenceInternal(
nameA: string,
tilesetSourceA: TilesetSource,
nameB: string,
tilesetSourceB: TilesetSource
): string | undefined {
const keysA = [...tilesetSourceA.getKeys()].sort();
const keysB = [...tilesetSourceB.getKeys()].sort();
): Promise<string | undefined> {
const keysA = await Iterables.asyncToArray(await tilesetSourceA.getKeys());
const keysB = await Iterables.asyncToArray(await tilesetSourceB.getKeys());
keysA.sort();
keysB.sort();

if (keysA.length != keysB.length) {
return `There are ${keysA.length} keys in ${nameA} and ${keysB.length} keys in ${nameB}`;
Expand All @@ -315,8 +317,8 @@ export class SpecHelpers {
}
}
for (let i = 0; i < keysA.length; i++) {
const valueA = tilesetSourceA.getValue(keysA[i]);
const valueB = tilesetSourceB.getValue(keysB[i]);
const valueA = await tilesetSourceA.getValue(keysA[i]);
const valueB = await tilesetSourceB.getValue(keysB[i]);
const entryDifference = SpecHelpers.computeEntryDifference(
keysA[i],
nameA,
Expand Down
3 changes: 3 additions & 0 deletions specs/base/contentTypes/LazyContentDataSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { ResourceResolver } from "../../../src/base";

function createTestResourceResolver(): ResourceResolver {
return {
resolveUri(uri: string) {
return uri;
},
async resolveData(uri: string): Promise<Buffer | null> {
return null;
},
Expand Down
Loading