Closed baothientran closed 3 years ago
@likangning93 I think all the reviewed comments are addressed in the new commits. Please let me know if I miss anything
Some initial comments after reading the README and inspecting the San Diego output.
mkdir Build
from the build instructions. It might be unnecessary.--elevation-decimate-error
. What units are these? Meters? CDB data is always meters right? EDIT: see below - is it possible to "un-normalize" the option so that the units are meters?--elevation-threshold-indices
not sure if this option should be included. --elevation-decimate-error
is a more concrete option to most users.--elevation-LOD
- rename to --elevation-lod
SanDiego/tileset.json
) and a tileset.json for each geocell (e.g. Tiles/N32/W118/tileset.json
. The top-level tileset.json should point to all the geocell tilesets, and each geocell tileset should point to the layer tilesets.wrapR
property, but this property doesn't exist for glTF samplers. Looks like something in tinygltf...NEAREST_MIPMAP_LINEAR
) produces better results than 9985 (LINEAR_MIPMAP_NEAREST
) for the minFilter
min/max
for _BATCHID
accessors to save space in the glTF@lilleyse --elevation-decimate-error
is normalized to 0..1. So 0.01 means the simplifier will maintain the target error below 1% of the mesh extent. I've update the explanation in the CLI
@baothientran can you open issues for anything not finished in https://github.com/CesiumGS/cdb-to-3dtiles/pull/14#issuecomment-724351326?
Merging into master
!
Overall about the code base:
There are two main classes in the project:
CDB
class is responsible for traversing the CDB directory structure and retrieves the correct dataset with the mesh (e.g Elevation, GSModel, GTModel, etc) for each tile.Converter
class which is in theCDBTo3DTiles.cpp
file is used to convert CDB dataset totileset.json
. It handlesgltf
,b3dm
,i3dm
, andcmpt
conversion as well (those conversion functions are implemented as separate free functions inGltf.cpp
andTileFormatIO.cpp
)Converter::convert()
member function of theConverter
classOverall about each CDB dataset:
Tiling scheme:
CDBTile
andCDBTileset
are used to represent such structure. At negative level, eachCDBTile
will only has one children, and at positive level, it will have 4 children (includenullptr
)CDBTile
hasUREF
andRREF
.UREF
is similar to the y component of the quadtree, andRREF
is similar to the x component. They are indexed from the bottom left instead of the top left. In other word, (0, 0) quadtree coordinate will be at the bottom left. You can see the UREF value in the U directory and RREF value is embedded as R + number in the dataset filename.CDBPath/Tiles/N32/W118/201_RoadNetwork/LC/U0/N32W118_D201_S002_T004_LC05_U0_R0.shx
:N32
andW118
are the coordinates of a Geo Cell. The GeoCell is located at latitude 32 and longitude -118LC
directory.U0
indicates UREF of each tile is 0 (or y component = 0). RREF is embedded in the tile under the U symbol. SoLC05_U0_R0
means the tile is at level -5,UREF = 0
andRREF = 0
.D201_S002_T004
in the tile filename,D201
is the codename for RoadNetwork (All the dataset begin with D symbol).S002
is the component selector 1 andT004
is the component selector 4. They have a different meaning depend on the dataset in the CDB.L + number (e.g L00, L01, etc)
directoryElevation and Imagery:
CDBElevation
class. This class will convert the heightmap to a uniform grid mesh. I also provide theCDBElevation::createSimplifiedMesh()
to decimate the mesh before writing to b3dmCDBElevation::createSubRegion()
. It is wasteful but that seems to be the only option I have.Vector dataset (RoadNetwork, HydrographyNetwork, RailRoadNetwork, PowerlineNetwork)
All vector data are stored in the ESRI ShapeFile. They are in the Tiles directory with sub directory name being the same as those above. You can view the content of each ShapeFile with command
ogrinfo -al path-to-dbf-or-shapefile
with ogrinfo being installed with gdalVector data has the concept of instance and class metadata. They are stored in the ShapeFile format. However, the difference is that instance metadata will have vector geometry with it (For example, point, line, and polygon) and other metadata for each instance. Class metadata will only contain metadata of a class that will be shared by instances with the same class name.
Example of instance metadata:
Notice the
CNAM
attribute. It indicates the class name of the instance and used to connect with class metadata. LINESTRING attribute above indicates the line geometry of the vectorExample of class metadata:
Notice the
CNAM
of the class metadata is the same as CNAM of the instance metadata. That means if instance has the sameCNAM
with a class metadata will share the same class metadata.Other attributes have different meanings in CDB, but I just simply copy them to the feature table without any additional processing
Component selector 2 in the tile filename is used to distinguish which file contains instance metadata. The list can be found in the enum class
CDBVectorCS2
https://github.com/CesiumGS/cdb-to-3dtiles/blob/4102f433cde99ef21d7a1832a39dcb5ccf332267/CDBTo3DTiles/src/CDBAttributes.h#L12I only read in instance metadata file and deduce the filename for the class metadata. Also since 3DTiles doesn't have the concept of class metadata, class metadata is merged or copied to instance metadata before converting 3DTiles
Currently all the vector data above are represented by
CDBGeometryVectors
class. It stores the geometry (points, lines, and polygon) in the mesh and instances metadata in theCDBInstancesAttributes
CDBInstancesAttributes
andCDBClassAttributes
classes represents collection of class and instance metadata in a tile.CDBInstancesAttributes
are similar to struct of array rather than array of struct. This organization is similar to feature table spec https://github.com/CesiumGS/3d-tiles/blob/master/specification/TileFormats/FeatureTable/README.md.CDBClassAttributes
is organized as struct of array as well. However, it maps CNAM to the array of each class attributes to allow for easy query class attribute.GTModel dataset
GTModel is instance 3D model like trees. The mesh and texture are stored in
CDBPath/GTModel
. The position and metadata of each instance is stored in GTFeature directoryGTFeature data is stored in the ShapeFile similar to vector data above. The position of the instance is stored as point geometry. The orientation of the model is stored in
AO1
attribute. This is an example:To find the model name, we need class metadata:
Notice 3 fields above FACC, FSC, and MODL.
We use each character in FACC field to identify the directory in 500_GTModelGeometry directory. For example,
FACC=AL015
means the model is in500_GTModelGeometry/A_{custom name}/L_{custom name}/015_{custom name}
FSC and MODL are parts of model filename. So
FSC = 0
andMODL = coronado_bridge
means the model filename is in500_GTModelGeometry/A_{custom name}/L_{custom name}/015_{custom name}/D500_S001_T001_AL015_000_coronado_bridge
All GTModels are cached in the CDBGTModelCache class. It is used to prevent from parsing OpenFLight twice.
Similar to vector dataset above, all instance metadata are stored in
CDBInstancesAttributes
. You may notice there is classCDBModelsAttributes
. It is the wrapper ofCDBInstancesAttributes
and very similar toCDBGeometryVectors
. However, unlike CDBGeometryVectors, it doesn't convert point geometry into Cartesian 3 likeCDBGeometryVectors
, but leave it as Cartographic as it is used to clamp the model on the terrain laterGSModel dataset
GSModel meshes are stored in GSModelGeometry. Its textures can be stored in GTModel directory or GSModelTexture directory. For the first case, no special process is needed. However, when texture is stored in GSModelTexture, the texture filename is concealed in the zip file. It is necessary to unzip it to find the texture. Fortunately, OpenSceneGraph allows us to create a custom texture finder to locate unknown texture file. The code to handle it is located here: https://github.com/CesiumGS/cdb-to-3dtiles/blob/4102f433cde99ef21d7a1832a39dcb5ccf332267/CDBTo3DTiles/src/CDBModels.cpp#L691
It will use OSG existing finder. If the finder doesn't find it. We will look into zip file to see if the texture is there. If the texture is not found, we can return empty string to flag not found. Otherwise, read the image from zip archive
Similar to GTModel, position, orientation, and scales are stored in GSFeature directory. The model file is identified by FACC, FSC, and MODL attributes. For example, below is the class metadata of one tile:
Using the 3 attributes above, we can find the model file in the zip file in the GSModelGeometry directory with the same LOD coordinate as GSFeature tile:
300_GSModelGeometry/N32W118_D300_S001_T001_L00_U0_R0_{FACC}_{FSC}_{MODL}.flt