Cesium Getting Started Ten: Cesium Loads 3DTiles Data

Introduction to 3DTiles

3DTiles is a grid-oriented and displayable large-scale 3D spatial data format, specially designed for streaming and rendering massive 3D geospatial data, and used to store and manage grid-based 3D model data. Its data structure is based on B3DM and PNTS formats, can support multiple levels of LOD, and uses Tilesets (tile collections) to organize and manage data. 3DTiles has the following characteristics:

  • Support large-scale, high-precision 3D model data display.
  • Use standard json format to describe data structure and metadata.
  • Use compression algorithms such as DRACO and LZMA to improve data transmission and storage efficiency.
  • Supports multi-level LOD, and supports quick opening and closing of different levels of data layers.

3DTiles data structure

In 3DTiles, a tile set (Tileset) is organized by a group of tiles (Tile) according to the spatial data structure (tree structure), which contains at least one JSON file for describing the tile set (including tile The metadata and tile objects of the tile set), where each tile object can refer to one of the following formats for rendering tile content:
insert image description here
b3dm and i3dm formats are built based on glTF, and their tile content is in binary The glTF resource is embedded in the body, including the geometry and texture information of the model; the pnts format does not embed the glTF resource.
In the 3DTiles data structure, Tileset (tile set) is the main management unit of 3DTiles, including Tileset global information, Tileset resource path, Tileset root Tile, etc. Each Tileset contains multiple Tiles, representing different data levels and view levels, and each Tile contains multiple sub-Tiles. The bottom Tile can contain specific 3D model data, called Leaf Tile.

Classes related to 3DTiles in Cesium

1. Cesium3DTileset class

The Cesium3DTileset class is the main management class for 3DTiles data, responsible for loading and rendering Tilesets. The Cesium3DTileset class allows multiple 3D tiles of the 3D tileset to switch between different levels of detail, so as to provide appropriate details at different distances and viewing angles. This class also provides an easy-to-use interface to control the visibility, style, position and rotation of the 3D tile set, as well as manage functions such as preloading, caching and unloading, which can be used to develop efficient, reliable and interactive 3D Earth application.

Common attributes:

  • url: The URL address of the 3D tile data.
  • modelMatrix: The model matrix for this 3D tileset.
  • boundingSphere: The bounding sphere of the 3D tile set, used to calculate and process visibility and collision detection, etc.
  • root: The root tile of the 3D tile set.
  • ready: A Boolean type property used to indicate whether the 3D tile is ready to render.

Common methods:

  • destroy(): Destroys the 3D tile and its contents.
  • getProperty(name): Obtain the attribute value of the 3D tile according to the attribute name.
  • setProperty(name, value): Set the attribute value of the 3D tile.
  • hasProperty(name): Determine whether the 3D tile contains the attribute with the specified name.
  • makeStyleDirty(): Notify that the 3D tile set needs to reapply the style.
  • show: Set the visibility of the 3D tile set.

2. Cesium3DTileStyle class

Cesium3DTileStyle is a class used to specify and apply the style of 3D tile sets; it can control the color, point size, label style and text content of 3D tiles; it can classify and color 3D tiles, and create attribute-based (such as height, category, or time) for dynamic styling.

Common attributes:

  • color: The color of the 3D tile, which can be rgba, rgb or hexadecimal color value.
  • pointSize: The size of the midpoint of the 3D tile.
  • labelStyle: The style of the label in the 3D tile.
  • labelText: The text content of the label in the 3D tile.
  • show: The visibility of the 3D tile.
  • style: All style attributes of the 3D tile.

3. Cesium3DTileContent class

Cesium3DTileContent is a class used to represent the content and geometric information of a single 3D tile. It can use the Cesium3DTileContent class to set and get the geometry and metadata properties stored in the 3D tile, and apply them to the 3D objects in the 3D tile.

common attributes

  • featuresLength: The number of features contained in the 3D tile content.
  • pointsLength: The number of points contained in the 3D tile content.
  • trianglesLength: The number of triangles contained in the 3D tile content.
  • geometryByteLength: The geometry data byte length of the 3D tile content.
  • texturesByteLength: The texture data byte length of the 3D tile content.

common method

  • hasProperty(batchId,name): Checks whether an attribute value with the specified name exists in the 3D tile content. This method takes two parameters:
    batchId: The index in the batch table of the feature whose attributes are to be checked.
    name: The property name to check.

This method will return a Boolean value indicating whether the specified attribute exists in the context of the specified batch ID in the batch table.

This method is mainly used to dynamically create and apply 3D tile styles. Methods that use 3D tile content hasPropertycan check whether a 3D tile has an attribute with a specified name in order to selectively apply styles. For example, you can check for the existence of a "height" property in a 3D tile, then sort and color the 3D tile based on the condition, or start a specific animation effect.

  • getFeature(batchId): Get the set of attribute values ​​of the features at the specified index in the batch table. This method requires one parameter:
    batchId: The index in the batch table of the feature whose attributes are to be retrieved.

This method will return a JavaScript object containing all the attribute values ​​of the specified feature, which are in the bulk table object, and the name of the attribute's key is the same as its name in the bulk table.

This method is mainly used to interact and operate with 3D tiles in Cesium. In addition to getting attribute values ​​in bulk tables, this method can also be used to attach metadata to features to support metadata functionality. For example, after calling this method, you can store additional metadata names and values ​​in the feature object, and then use these metadata properties in applying specific 3D tile styles, dynamic filter queries, or other operations that interact with the feature .

Note that this method will return if an attempt is made to get a feature attribute for a batch ID that does not exist undefined. Also, if the feature being fetched has incomplete or wrong attribute data, the method may return wrong or partial attribute data.

4. Cesium3DTileFeature class

The Cesium3DTileFeature class is used to represent a single feature (feature) and its related attributes in a 3D tile.

common attributes

  • color: Color attribute, used to set the color of 3D tile elements. The color supports RGBA (red/green/blue/transparency channel) format, which can be an array, the structure of the array is [red, green, blue, alpha], and each value ranges from 0 to 1. The Cesium3DTileFeature class allows setting colors to override the default colors for 3D tiles.
  • featureId: Feature ID attribute, which is a value of any type, used to define the unique identifier of each feature in the 3D tile. Developers can use this attribute to track specific 3D tile features and selectively manipulate them when needed.
  • polylinePositions: An attribute that stores the feature's line location, if present. This attribute is used for line style features in 3D tiles and contains an array of numeric values ​​specifying the position of the line style for this feature. Each numeric array is interpreted as a Cartesian3 coordinate.
  • primitive: The primitive object related to the feature, which can be used to retrieve the geometry information of the feature and perform interactive operations. This property allows developers to directly access features and their associated attribute data in a 3D tile.
  • tileset: The 3D tile set object associated with the feature. This attribute is used to obtain the 3D tile set object where the feature is located, so as to perform interactive operations and operations.

common method

  • getProperty(name): Get the attribute value of the feature with the specified name in the batch table.
  • setProperty(name, value): Set the attribute value of the specified name.
  • hasProperty(name): Checks if a feature has an attribute with the specified name in the bulk table.

5. Cesium3DTile class

The Cesium3DTile class is used to represent 3D tile data.

common attributes

  • boundingSphere: A minimal spherical bounding volume containing 3D tiles. This property is used to crop and optimize the display performance of 3D tiles. The boundingSphere is computed from the bounding box and can be update()updated by calling methods.
  • children: An array containing all subtiles. Each subtile is a Cesium3DTile instance. When the content objects of 3D tiles contain multiple arrays, they will usually create sub-tiles for each array to manage these arrays.
  • computedTransform: An array containing a 4x4 matrix from the parent tile to the current tile. This matrix is ​​used to convert the content object of the current tile to the coordinate system of the parent tile. computedTransform is recomputed when updating the tile transformation matrix. If the tile has no parent tile, computedTransform is the identity matrix.
  • content: The content object of a 3D tile, usually containing related information such as geographic information and attribute data.
  • geometricError: The geometric error of the 3D tile, indicating the maximum distance error of the 3D tile. Cesium uses this property to calculate the display priority and level of detail of 3D tiles.
  • extras: An object containing arbitrary additional data for the 3D tile. The extras property in Cesium3DTile allows developers to store and access any extra data associated with the tile.
  • parent: A pointer to the parent tile. The parent tile is the immediate superior of the current tile. If the current tile has no parent tile, the parent property will be null.
  • transform: A 4x4 matrix from model coordinate system to world coordinate system. This matrix is ​​used to transform the 3D tile content object from the model coordinate system to the world coordinate system. update()The transform matrix is ​​usually calculated by calling a method when loading a 3D tile .
  • tileset: The 3D tile set object associated with the 3D tile.

Example of loading 3DTiles data in Cesium

 try {
    
    
    const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(75343);
    viewer.scene.primitives.add(tileset);
  } catch (error) {
    
    
    console.log(`Error loading tileset: ${
     
     error}`);
  }
  viewer.scene.globe.depthTestAgainstTerrain = true;

Guess you like

Origin blog.csdn.net/w137160164/article/details/131179513
Recommended