tileset
v1.0.1
Published
A TypeScript library for working with 3D Tiles tileset.json files
Maintainers
Readme
tileset
A TypeScript library for working with 3D Tiles tileset.json files. This library provides functionality to parse, validate, and manipulate 3D Tiles datasets.
Installation
npm install tileset
Usage
Parsing a tileset.json
import { Tileset } from 'tileset'; import * as fs from 'fs';
// Read the tileset.json file const jsonContent = fs.readFileSync('path/to/tileset.json', 'utf8');
// Parse the JSON content into a Tileset instance const tileset = Tileset.parse(jsonContent, { validate: true });
// Validate the tileset (if not already validated during parsing) const validationResult = tileset.validate(); if (!validationResult.valid) { console.error('Invalid tileset:', validationResult.errors); }
Creating a new tileset
import { Tileset } from 'tileset';
// Create a basic tileset structure const tilesetData = { asset: { version: '1.1' }, geometricError: 1000.0, root: { boundingVolume: { region: [116.3, 39.9, 116.4, 40.0, 0, 500] }, geometricError: 500.0, children: [ // Add child tiles here ] } };
// Create a Tileset instance from the data const tileset = Tileset.fromObject(tilesetData, { validate: true });
Traversing tiles
// Traverse all tiles
tileset.traverse((tile, depth) => {
console.log(Depth ${depth}: Tile with geometric error ${tile.geometricError});
});
// Get all tiles in an array
const allTiles = tileset.getAllTiles();
console.log(Total tiles: ${allTiles.length});
// Find specific tiles
const highDetailTiles = tileset.findAllTiles(tile => tile.geometricError < 100);
console.log(High detail tiles: ${highDetailTiles.length});
Exporting the tileset
// Convert to JSON string const jsonOutput = tileset.toJSON(2); // 2 spaces indentation fs.writeFileSync('output/tileset.json', jsonOutput, 'utf8');
// Get the raw object const tilesetObject = tileset.toObject();
API Documentation
Tileset Class
static parse(json: string, options?: ParseOptions): Tileset- Parses a JSON string into a Tileset instancestatic fromObject(data: Tileset, options?: ParseOptions): Tileset- Creates a Tileset instance from an objectvalidate(): ValidationResult- Validates the tileset structuretoJSON(space?: number): string- Converts the tileset to a JSON stringtoObject(): Tileset- Returns a deep copy of the tileset datagetRootTile(): Tile- Returns the root tilegetAllTiles(): Tile[]- Returns all tiles in an arraytraverse(callback: (tile: Tile, depth: number) => void)- Traverses all tiles recursivelyfindTile(predicate: (tile: Tile) => boolean): Tile | undefined- Finds the first tile matching the predicatefindAllTiles(predicate: (tile: Tile) => boolean): Tile[]- Finds all tiles matching the predicategetTileCount(): number- Returns the total number of tilesgetVersion(): string- Returns the 3D Tiles versiongetProperties(): Record<string, any> | undefined- Returns custom propertiessetProperties(properties: Record<string, any>): void- Sets custom propertiesgetExtensionsUsed(): string[] | undefined- Returns used extensionsaddExtension(extension: string): void- Adds an extension to the used extensions listcomputeOverallBoundingVolume(): BoundingVolume- Computes the overall bounding volume
License
MIT
