You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tl;dr: There are some functions for accessing metadata in CesiumJS. These functions are generally declared to return * (aka any) in the JSDoc. This is converted to any for the TypeScript bindings. We could consider to narrow down the types that are returned by these functions.
Context
CesiumJS supports the 3D Metadata Specification in two flavors: Once as part of the 3D Tiles 1.1 support, and once as part of the Cesium EXT_structural_metadata glTF extension. On the level of the API, these are treated equally (and intentionally so).
There are examples like the MetadataGranularities sample where the metadata is accessed casually in the example sandcastle. But this is using a private API. The metadata is not exposed publicly right now. The representations of the metadata - in classes like TilesetMetadata, TileMetadata ... - follows (implicitly - not explicitly!) the interface that is defined as MetadataEntity. This might become part of a public API at some point. The main function in this interface for accessing metadata is the getProperty function, which returns the value of a metadata property. Beyond that, the only function to obtain metadata values right now is via Cesium3DTileFeature.getProperty/Inherited.
The types of these functions are currently documented as
@returns {*} The value of the property
This is translated to any on the TypeScript layer.
People might wish for more specific type information. This could be accomplished by adding "typedefs" on the JSDoc layer.
Possible approach
Translating the existing type system from the 3D Metadata Specification into TypeScript typings could be pretty straightforward. But there are caveats.
For example: In some cases, types like the VEC3/FLOAT32 from the metadata specification are represented as a number[] array, and in other cases, they are represented as a Cartesian3. Both can make sense, depending on the context. But for the case of users accessing that metadata, the context is simply not known. Converting these types back and forth is usually easy, with the pack/unpack functions. But this may be a bit inconvenient - and in order to know which function to call, the type has to be known, which is kind of a chicken-egg-problem.
Another caveat is that in many cases, the types that are (and can be) represented as metadata already are limited. For example, in EXT_structural_metadata, a 'property texture' cannot contain STRING valued metadata. Whether or not this is made explicit on the level of the type system at some point has to be decided.
Draft of a possible approach
The following is a draft of a (largely) 1:1 translation of the 3D Metadata Specification type system into TypeScript. This is shown as a standalone file here, for quicker feedback and iterations:
// Component typestypeINT8=number;typeUINT8=number;typeINT16=number;typeUINT16=number;typeINT32=number;typeUINT32=number;typeINT64=bigint;typeUINT64=bigint;typeFLOAT32=number;typeFLOAT64=number;// Non-numeric component typestypeSTRING=string;typeBOOLEAN=boolean;typeENUM=string;// TODO: Also number in some cases...// Numeric typestypeUnsignedInteger=UINT8|UINT16|UINT32|UINT64;typeSignedInteger=INT8|INT16|INT32|INT64;typeInteger=UnsignedInteger|SignedInteger;typeFloatingPoint=FLOAT32|FLOAT64;typeNumeric=Integer|FloatingPoint;// Vector typestypeVEC2=[Numeric,Numeric];typeVEC3=[Numeric,Numeric,Numeric];typeVEC4=[Numeric,Numeric,Numeric,Numeric];typeVector=VEC2|VEC3|VEC4;// Matrix typestypeMAT2=[Numeric,Numeric,Numeric,Numeric];typeMAT3=[Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric];typeMAT4=[Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric,Numeric];typeMatrix=MAT2|MAT3|MAT4;// HelperstypeNonNumeric=STRING|BOOLEAN|ENUM;typeMetadataValue=Numeric|NonNumeric|Vector|Matrix;//----------------------------------------------------------------------------// Usage/test:functiongetMetadataValue(): MetadataValue{//const value : STRING = "example";//const value : BOOLEAN = true;//const value : Numeric = 123;//const value : Vector = [0, 1, 2];constvalue: Matrix=[0,1,2,3];returnvalue;}functioncallIt(){letvalue: MetadataValue|undefined=undefined;value=getMetadataValue();}//----------------------------------------------------------------------------// Bridge to CesiumJS// Built-in in CesiumJS (dummy types here)typeCartesian2={name: "Cartesian2"};typeCartesian3={name: "Cartesian3"};typeCartesian4={name: "Cartesian4"};typeMatrix2={name: "Matrix2"};typeMatrix3={name: "Matrix3"};typeMatrix4={name: "Matrix4"};// HelperstypeCesiumVector=Cartesian2|Cartesian3|Cartesian4;typeCesiumMatrix=Matrix2|Matrix3|Matrix4;typeCesiumMetadataValue=Numeric|NonNumeric|CesiumVector|CesiumMatrix;functiongetMetadataValueCesium(): CesiumMetadataValue{//const value : STRING = "example";//const value : BOOLEAN = true;//const value : Numeric = 123;//const value : CesiumVector = "Cartesian2";constvalue: CesiumMatrix={name: "Matrix2"};returnvalue;}functioncallItForCesium(){letvalue: CesiumMetadataValue|undefined=undefined;value=getMetadataValueCesium();}
(EDIT: Array types are not covered here - in many cases, this could be solved by appending a [] at the right place. Whether or not this is made explicit is also to be decided)
Disclaimer:
One could make a case that this type information is of very limited use for clients. They can call a function (as drafted in the snippet above). And then they still don't know whether that value is a single boolean, or a bigint[], or a Matrix4. Actually using that type information will require it to be narrowed down - probably, by inspecting the ClassProperty of the metadata (if it is accessible...), or by some sort of runtime type checks.
The text was updated successfully, but these errors were encountered:
tl;dr: There are some functions for accessing metadata in CesiumJS. These functions are generally declared to return
*
(akaany
) in the JSDoc. This is converted toany
for the TypeScript bindings. We could consider to narrow down the types that are returned by these functions.Context
CesiumJS supports the 3D Metadata Specification in two flavors: Once as part of the 3D Tiles 1.1 support, and once as part of the Cesium
EXT_structural_metadata
glTF extension. On the level of the API, these are treated equally (and intentionally so).There are examples like the MetadataGranularities sample where the metadata is accessed casually in the example sandcastle. But this is using a
private
API. The metadata is not exposed publicly right now. The representations of the metadata - in classes likeTilesetMetadata
,TileMetadata
... - follows (implicitly - not explicitly!) the interface that is defined asMetadataEntity
. This might become part of a public API at some point. The main function in this interface for accessing metadata is thegetProperty
function, which returns the value of a metadata property. Beyond that, the only function to obtain metadata values right now is viaCesium3DTileFeature.getProperty/Inherited
.The types of these functions are currently documented as
This is translated to
any
on the TypeScript layer.People might wish for more specific type information. This could be accomplished by adding "typedefs" on the JSDoc layer.
Possible approach
Translating the existing type system from the 3D Metadata Specification into TypeScript typings could be pretty straightforward. But there are caveats.
For example: In some cases, types like the
VEC3/FLOAT32
from the metadata specification are represented as anumber[]
array, and in other cases, they are represented as aCartesian3
. Both can make sense, depending on the context. But for the case of users accessing that metadata, the context is simply not known. Converting these types back and forth is usually easy, with thepack/unpack
functions. But this may be a bit inconvenient - and in order to know which function to call, the type has to be known, which is kind of a chicken-egg-problem.Another caveat is that in many cases, the types that are (and can be) represented as metadata already are limited. For example, in
EXT_structural_metadata
, a 'property texture' cannot containSTRING
valued metadata. Whether or not this is made explicit on the level of the type system at some point has to be decided.Draft of a possible approach
The following is a draft of a (largely) 1:1 translation of the 3D Metadata Specification type system into TypeScript. This is shown as a standalone file here, for quicker feedback and iterations:
(EDIT: Array types are not covered here - in many cases, this could be solved by appending a
[]
at the right place. Whether or not this is made explicit is also to be decided)Disclaimer:
One could make a case that this type information is of very limited use for clients. They can call a function (as drafted in the snippet above). And then they still don't know whether that value is a single
boolean
, or abigint[]
, or aMatrix4
. Actually using that type information will require it to be narrowed down - probably, by inspecting theClassProperty
of the metadata (if it is accessible...), or by some sort of runtime type checks.The text was updated successfully, but these errors were encountered: