3D Tiles Tools

repository·main·Indexed 19 days ago

https://github.com/cesiumgs/3d-tiles-tools

A suite of CLI and programmatic utilities for converting, optimizing, processing, and analyzing 3D Tiles data. Key features include upgrading tilesets to 3D Tiles 1.0 or 1.1, merging and combining tilesets, converting between formats (such as B3DM, I3DM, PNTS, and glTF/GLB), and optimizing content via gltf-pipeline. It also provides tools for gzipping/ungzipping tilesets, creating tileset.json files from content, and serving tilesets via a local server.

Tokens
16.7K
Snippets
49
Records
91
Agent score
67%

What's inside 3d-tiles-tools

  1. Overview of 3D Tiles Tools

    main

    3D Tiles Tools is a collection of utilities designed for managing 3D Tiles data. Key capabilities include:

    • Converting: Changing data formats.
    • Optimizing: Improving performance and structure.
    • Processing: Applying transformations or modifications to tilesets.
    • Analyzing: Inspecting and evaluating 3D Tiles data.
  2. Overview of 3D Tiles Tools Demo Functions

    main

    The demos repository provides examples for various functional areas of the 3D Tiles tools. Use these as a reference for how to interact with the following capabilities:

    Metadata and Data Types

    • BinaryMetadataDemos: Creating and accessing BinaryPropertyTableModel instances with different property types.
    • MetadataDemos: Working with MetadataEntityModel instances for JSON-based metadata entities.
    • ContentDataTypeChecksDemo: Using ContentDataTypeChecks to verify content data types.
    • ContentDataTypeRegistryDemo: Querying content data types via ContentDataTypeRegistry.
    • SubtreeInfoDemos: Using the SubtreeInfo class to access binary subtree data.

    Package and Format Management

    • PackageConversion: CLI tool for converting between formats (e.g., files/3TZ/3DTILES/ZIP to files/3TZ/3DTILES).
    • PackagesDemo: Reading, creating, and writing 3D Tiles packages.
    • PackageServer: A basic server for serving data from an arbitrary 3D Tiles package (intended for use with PackageSandcastle).
    • TileFormatsDemoBasic: Basic usage of the TileFormats class.
    • TileFormatsDemoConversions: Using TileFormats for conversions, such as extracting GLB from B3DM.

    Tileset Processing and Traversal

    • TilesetProcessingDemos: Using combine, merge, and upgrade functions.
    • TilesetProcessorExamples: Basic usage of BasicTilesetProcessor functions.
    • TilesetUpgraderDemos: Fine-grained demonstrations of upgrade functionality.
    • TraversalDemo: Basic tileset traversal.
    • TraversalStatsDemo: Traversing a tileset while collecting statistical information.

    Spatial and Pipeline

    • SpatialDemos: Using quadtree and octree classes in the spatial module.
    • Pipeline...: Preliminary drafts for upcoming pipelines functionalities.
  3. Merge and Combine tilesets

    main

    There are three primary ways to merge tilesets, depending on whether you want to inline content or maintain external references:

    1. combine: Takes a tileset that refers to external tilesets and "inlines" them, creating a single tileset without external references.
    2. merge: Creates a new tileset that refers to the input tilesets as external tilesets. The resulting tileset is incomplete without the original input files.
    3. mergeJson: Similar to merge, but only creates the JSON file. It does not copy input tilesets to the output directory; instead, it uses relative paths to refer to them. This is useful for organizing tilesets in subdirectories.
    4. mergeJson3tz: Merges tilesets packaged as .3tz files into a single tileset JSON using the MAXAR_content_3tz extension. If a directory is provided, it recursively includes all .3tz files within it.
    # Combine (inline external tilesets)
    npx 3d-tiles-tools combine -i ./specs/data/combineTilesets/input -o ./specs/data/combineTilesets/output
    
    # Merge (create new tileset with external references)
    npx 3d-tiles-tools merge -i ./specs/data/mergeTilesets/TilesetA -i ./specs/data/mergeTilesets/sub/TilesetA -o ./specs/data/mergeTilesets/output
    
    # Merge JSON only (relative paths, no file copying)
    npx 3d-tiles-tools mergeJson -i ./example/TilesetA/tileset.json -i ./example/TilesetB/tileset.json -o ./example/mergedTileset.json
    
    # Merge 3TZ files
    npx 3d-tiles-tools mergeJson3tz -i ./example/tilesetA.3tz -i ./example/tilesetB.3tz -o ./example/tileset.json
  4. How the `combine` command handles multiple contents

    main

    When using the combine command to merge tilesets, the tool differentiates between tiles referring to a single content versus multiple contents. This behavior determines how external tilesets are integrated into the resulting hierarchy:

    1. Single Content (External Tileset): If a tile refers to a single content that is an external tileset, the properties of that tile are replaced with the properties of the external root.
    2. Multiple Contents (Including External Tilesets): If a tile refers to multiple contents (including external tilesets), the external roots are added as children to the original tile instead of replacing it.
  5. Handle 3D Tiles content data types

    main

    The ContentDataTypeRegistry and ContentDataTypes allow for identifying and checking the type of content associated with a tile (e.g., GLB, B3DM, PNTS). You can use ContentDataTypeRegistry.findContentDataType to determine the type of a ContentData object.

    Supported content types include:

    • CONTENT_TYPE_B3DM (Batched 3D Model)
    • CONTENT_TYPE_GLB (glTF Binary)
    • CONTENT_TYPE_GLTF (glTF)
    • CONTENT_TYPE_I3DM (Instanced 3D Model)
    • CONTENT_TYPE_PNTS (Point Cloud)
    • CONTENT_TYPE_SUBT (Subtree)
    • CONTENT_TYPE_TILESET (3D Tileset)
    • ...and others like GEOJSON, JPEG, PNG, VCTR.
  6. Understand the legacy tile format to glTF migration testing process

    main

    The migration testing process validates the conversion of legacy 3D Tiles formats (like B3DM) to the modern glTF-based format. The process involves:

    1. Processing Inputs: Running Tilesets.upgrade on legacy tilesets located in the input directory.
    2. Generating Outputs: Writing the upgraded tilesets to the output directory and extracting the JSON components of the resulting GLB files into the output_gltf directory.
    3. Validation: Comparing the extracted JSON against the reference data stored in the golden_gltf directory.
    4. Reviewing Changes: If differences are found between the output and the 'golden' reference, they must be reviewed. If the changes are correct, the new files should be moved to the golden_gltf directory and committed.

    Visual inspection of these inputs and outputs can be performed using the TileFormatsMigrationTestSandcastle.js sandcastle.

  7. Understand the project structure

    main

    The source code is organized into subdirectories that are designed to function as individual packages in a monorepo. The key directories are:

    • base: Basic utility classes shared across packages.
    • structure: TypeScript types for 3D Tiles tileset JSON elements.
    • ktx: Wrapper for the BinomialLLC basis (KTX) encoder WASM module.
    • gltf-extensions: Implementations of Cesium glTF extensions (based on glTF-Transform).
    • metadata: Classes for the 3D Metadata Specification.
    • tilesets: Classes for handling 3D Tiles tileset data (tile content and tileset packages).
    • tools: Main classes implementing 3D Tiles Tools functionalities.
    • cli: The main command line application.
    • spec-helpers: Internal utilities for running unit tests.
  8. Understanding external tileset reference structures

    main

    When testing tileset processing operations (such as converting B3DM to GLB), the tools must correctly resolve paths for both internal tile content and external tilesets. The following directory structures represent common scenarios for testing path resolution:

    • Same Directory: tileset.json refers to tile.b3dm and externalA.json where all files reside in the same folder.
    • Subdirectory External Tileset: externalA.json refers to tileA.b3dm and ExternalB/externalB.json, where the external tileset is located in a subdirectory.
    • Parent and Sibling Directories: externalB.json refers to tileB.b3dm, ../tileX.b3dm, and ../ExternalC/externalC.json. This tests resolution of content in the parent directory and external tilesets in sibling directories.
    • Relative Parent Content: externalC.json refers to tileC0.b3dm and ../tileC1.b3dm to test content located in the parent directory.

    Note on Deduplication: In complex structures, a single content file (e.g., tileX.b3dm) may be referred to by multiple tilesets. The processing engine should identify these and ensure the content is processed only once.

  9. Manage tileset sources and targets

    main

    The library uses TilesetSource and TilesetTarget abstractions to handle different storage formats (e.g., 3D Tiles, 3tz, or File System).

    TilesetSource

    Implement or use existing sources to read tileset data. Common implementations include:

    • TilesetSource3dtiles: For standard 3D Tiles.
    • TilesetSource3tz: For 3tz formatted tilesets.
    • TilesetSourceFs: For direct File System access.

    TilesetTarget

    Implement or use existing targets to write tileset data. Common implementations include:

    • TilesetTarget3dtiles: For standard 3D Tiles output.
    • TilesetTarget3tz: For 3tz formatted output.
    • TilesetTargetFs: For direct File System output.
  10. Execute a sequence of operations via a Pipeline

    main

    The pipeline feature (preliminary) allows you to execute a sequence of operations defined in a JSON file. A pipeline consists of an input, an output, and an array of tilesetStages and contentStages.

    Pipeline Structure:

    • Tileset Stages: Operations applied to the tileset structure (e.g., upgrade, combine, gzip, ungzip).
    • Content Stages: Operations applied to individual tile contents (e.g., glbToB3dm, b3dmToGlb, optimizeB3dm, optimizeI3dm).

    If a stage name is not a predefined operation, it should start with an underscore (_) to indicate a custom operation.

    Example Pipeline JSON:

    {
      "input": "./specs/data/TilesetOfTilesetsWithUris",
      "output": "./output/TilesetOfTilesetsWithUris.3tz",
      "tilesetStages": [
        {
          "name": "_b3dmToGlb",
          "description": "Convert B3DM to GLB",
          "contentStages": [
            {
              "name": "b3dmToGlb",
              "description": "Convert each B3DM content into GLB"
            }
          ]
        }
      ]
    }
  11. Understand Subtree JSON structure and availability fields

    main

    A Subtree JSON object defines how availability information for tiles, content, and child subtrees is encoded and stored. It uses buffers and bufferViews to point to binary data that represents availability bitstreams.

    Key availability fields include:

    • tileAvailability: Indicates which tiles are available. Can be defined by a constant value or a bitstream (referencing a buffer).
    • contentAvailability: An array of availability objects (one per content type) indicating if content is available for specific tiles. Can be defined by constant or bitstream.
    • childSubtreeAvailability: Indicates the availability of child subtrees. Can be defined by constant or bitstream.

    When constant is used, the availability is uniform across the specified availableCount. When bitstream is used, the availability is determined by reading bits from the specified bufferViews.

    {
      "buffers" : [
        {
          "byteLength" : 8
        }
      ],
      "bufferViews" : [
        {
          "buffer" : 0,
          "byteOffset" : 0,
          "byteLength" : 2
        }
      ],
      "tileAvailability" : {
        "availableCount" : 5,
        "constant" : 1
      },
      "contentAvailability" : [
        {
          "availableCount" : 5,
          "constant" : 1
        }
      ],
      "childSubtreeAvailability" : {
        "bitstream" : 0,
        "availableCount" : 4
      }
    }
  12. Understand glTF up-axis handling during tileset upgrades

    main

    When using the upgrade command with --targetVersion 1.1, the tool converts glTF 1.0 data contained within B3DM or I3DM tiles into standard glTF 2.0.

    Pre-1.0 tilesets may specify an asset.gltfUpAxis value of X, Y, or Z to denote the up-axis convention used in the original glTF 1.0 data. The upgrade process must account for these values to ensure the resulting glTF 2.0 content is correctly oriented.