A Node.js library that converts CityJSON files into Cesium 3D Tilesβcomplete with automatic texture atlas packing, Basis compression, three LOD levels, and customizable threading.
npm install @csi-foxbyte/cityjson-to-3d-tilesbash
npm install @csi-foxbyte/cityjson-to-3d-tiles
`
π» Usage
`js
import { generate3DTilesFromTileDatabase } from "cityjson-to-3d-tiles/3dtiles/index.js";
import { generateTileDatabaseFromCityJSON } from "cityjson-to-3d-tiles/cityjson/index.js";
const inputFolder = "D:\\generator_test\\src"; // Folder containing CityJSON files π
const appearance = "rgbTexture"; // Texture appearance (e.g., "rgbTexture", "vertexColor") π¨
const outputFolder = "D:\\generator_test"; // Base output folder for the tile database and tiles π
(async () => {
// Step 1: Convert CityJSON to an on-disk tile database ποΈ
const { dbFilePath } = await generateTileDatabaseFromCityJSON(
inputFolder, // Source folder
outputFolder, // Destination folder
appearance, // Appearance mode
console.log, // Progress callback π
{ threadCount: 1 } // Options: number of worker threads π§΅
);
// Step 2: Generate Cesium 3D Tiles from the tile database π οΈ
await generate3DTilesFromTileDatabase(
dbFilePath, // Path to the generated tile database
"D:\\generator_test\\tiles", // Output folder for 3D Tiles ποΈ
console.log, // Progress callback π
{ threadCount: 1 } // Options: number of worker threads π§
);
})();
export { generate3DTilesFromTileDatabase, generateTileDatabaseFromCityJSON };
`
βοΈ API
$3
- inputFolder (string) β Path to a directory containing CityJSON files. π
- outputFolder (string) β Directory where the tile database will be created. π
- appearance (string) β Appearance: e.g. "rgbTexture" -> which appearence to use. π
- progressCallback (function) β Function called with log messages or progress updates. π’
- options (object):
- threadCount (number) β Number of worker threads to use (default: number of CPU cores). π§΅
Returns: A promise that resolves with an object containing:
- dbFilePath (string) β File path to the generated tile database (.db file). π
$3
- dbFilePath (string) β Path to the tile database generated in the previous step. π
- tilesOutputFolder (string) β Directory where the Cesium 3D Tiles will be written. ποΈ
- progressCallback (function) β Function called with log messages or progress updates. π
- options (object):
- threadCount (number) β Number of worker threads for tile generation (default: number of CPU cores). π§΅
Returns: A promise that resolves when 3D Tiles generation is complete. β
π οΈ Options Overview
| Option | Default | Description |
| ------------- | ------------------ | ---------------------------------------------------- |
| appearance | "rgbTexture" | Which CityGML appearance to use. π¨ |
| threadCount | os.cpus().length | Number of parallel worker threads. π§΅ |
π CLI Wrapper Example
Wrap the functions in a simple CLI script:
`js
#!/usr/bin/env node
import path from "path";
import { generateTileDatabaseFromCityJSON } from "cityjson-to-3d-tiles/cityjson/index.js";
import { generate3DTilesFromTileDatabase } from "cityjson-to-3d-tiles/3dtiles/index.js";
const [, , src, out, appearance] = process.argv;
(async () => {
const { dbFilePath } = await generateTileDatabaseFromCityJSON(
path.resolve(src),
path.resolve(out),
appearance || "rgbTexture",
console.log,
{ threadCount: 4 }
);
await generate3DTilesFromTileDatabase(
dbFilePath,
path.join(out, "tiles"),
console.log,
{ threadCount: 4 }
);
})();
`
Building from source
pnpm is required to build this library.
`bash
pnpm install
pnpm run build
``