cesium-native  0.41.0
CesiumGltf::Model Struct Reference

The root object for a glTF asset. More...

#include <CesiumGltf/Model.h>

Inheritance diagram for CesiumGltf::Model:
CesiumGltf::ModelSpec CesiumUtility::ExtensibleObject

Public Types

typedef void ForEachRootNodeInSceneCallback(Model &gltf, Node &node)
 A callback function for forEachRootNodeInScene.
 
typedef void ForEachRootNodeInSceneConstCallback(const Model &gltf, const Node &node)
 A callback function for forEachRootNodeInScene.
 
typedef void ForEachNodeInSceneCallback(Model &gltf, Node &node, const glm::dmat4 &transform)
 A callback function for forEachNodeInScene.
 
typedef void ForEachNodeInSceneConstCallback(const Model &gltf, const Node &node, const glm::dmat4 &transform)
 A callback function for forEachNodeInScene.
 
typedef void ForEachPrimitiveInSceneCallback(Model &gltf, Node &node, Mesh &mesh, MeshPrimitive &primitive, const glm::dmat4 &transform)
 A callback function for forEachPrimitiveInScene.
 
typedef void ForEachPrimitiveInSceneConstCallback(const Model &gltf, const Node &node, const Mesh &mesh, const MeshPrimitive &primitive, const glm::dmat4 &transform)
 A callback function for forEachPrimitiveInScene.
 

Public Member Functions

CesiumUtility::ErrorList merge (Model &&rhs)
 Merges another model into this one. More...
 
void forEachRootNodeInScene (int32_t sceneID, std::function< ForEachRootNodeInSceneCallback > &&callback)
 Apply the given callback to the root nodes of the scene. More...
 
void forEachRootNodeInScene (int32_t sceneID, std::function< ForEachRootNodeInSceneConstCallback > &&callback) const
 
void forEachNodeInScene (int32_t sceneID, std::function< ForEachNodeInSceneCallback > &&callback)
 Apply the given callback to all nodes in the scene. More...
 
void forEachNodeInScene (int32_t sceneID, std::function< ForEachNodeInSceneConstCallback > &&callback) const
 
void forEachPrimitiveInScene (int32_t sceneID, std::function< ForEachPrimitiveInSceneCallback > &&callback)
 Apply the given callback to all relevant primitives. More...
 
void forEachPrimitiveInScene (int32_t sceneID, std::function< ForEachPrimitiveInSceneConstCallback > &&callback) const
 
void generateMissingNormalsSmooth ()
 Fills in smooth normals for any primitives with missing normals.
 
void addExtensionUsed (const std::string &extensionName)
 Adds an extension to the ModelSpec::extensionsUsed property, if it is not already present. More...
 
void addExtensionRequired (const std::string &extensionName)
 Adds an extension to the ModelSpec::extensionsRequired property, if it is not already present. More...
 
void removeExtensionUsed (const std::string &extensionName)
 Removes an extension from the ModelSpec::extensionsUsed property. More...
 
void removeExtensionRequired (const std::string &extensionName)
 Removes an extension from the ModelSpec::extensionsRequired property. More...
 
bool isExtensionUsed (const std::string &extensionName) const noexcept
 Determines whether a given extension name is listed in the model's ModelSpec::extensionsUsed property. More...
 
bool isExtensionRequired (const std::string &extensionName) const noexcept
 Determines whether a given extension name is listed in the model's ModelSpec::extensionsRequired property. More...
 
- Public Member Functions inherited from CesiumUtility::ExtensibleObject
template<typename T >
bool hasExtension () const noexcept
 Checks if an extension exists given its static type. More...
 
template<typename T >
const T * getExtension () const noexcept
 Gets an extension given its static type. More...
 
template<typename T >
T * getExtension () noexcept
 Gets an extension given its static type. More...
 
const JsonValuegetGenericExtension (const std::string &extensionName) const noexcept
 Gets a generic extension with the given name as a CesiumUtility::JsonValue. More...
 
JsonValuegetGenericExtension (const std::string &extensionName) noexcept
 Gets a generic extension with the given name as a CesiumUtility::JsonValue. More...
 
template<typename T , typename... ConstructorArgumentTypes>
T & addExtension (ConstructorArgumentTypes &&... constructorArguments)
 Adds a statically-typed extension to this object. More...
 
template<typename T >
void removeExtension ()
 Removes a statically-typed extension from this object. More...
 

Static Public Member Functions

template<typename T >
static const T & getSafe (const std::vector< T > &items, int32_t index)
 Safely gets the element with a given index, returning a default instance if the index is outside the range. More...
 
template<typename T >
static const T * getSafe (const std::vector< T > *pItems, int32_t index) noexcept
 Safely gets a pointer to the element with a given index, returning nullptr if the index is outside the range. More...
 
template<typename T >
static T * getSafe (std::vector< T > *pItems, int32_t index) noexcept
 Safely gets a pointer to the element with a given index, returning nullptr if the index is outside the range. More...
 

Additional Inherited Members

- Public Attributes inherited from CesiumGltf::ModelSpec
std::vector< std::string > extensionsUsed
 Names of glTF extensions used in this asset.
 
std::vector< std::string > extensionsRequired
 Names of glTF extensions required to properly load this asset.
 
std::vector< CesiumGltf::Accessoraccessors
 An array of accessors. More...
 
std::vector< CesiumGltf::Animationanimations
 An array of keyframe animations.
 
CesiumGltf::Asset asset
 Metadata about the glTF asset.
 
std::vector< CesiumGltf::Bufferbuffers
 An array of buffers. More...
 
std::vector< CesiumGltf::BufferViewbufferViews
 An array of bufferViews. More...
 
std::vector< CesiumGltf::Cameracameras
 An array of cameras. More...
 
std::vector< CesiumGltf::Imageimages
 An array of images. More...
 
std::vector< CesiumGltf::Materialmaterials
 An array of materials. More...
 
std::vector< CesiumGltf::Meshmeshes
 An array of meshes. More...
 
std::vector< CesiumGltf::Nodenodes
 An array of nodes.
 
std::vector< CesiumGltf::Samplersamplers
 An array of samplers. More...
 
int32_t scene = -1
 The index of the default scene. More...
 
std::vector< CesiumGltf::Scenescenes
 An array of scenes.
 
std::vector< CesiumGltf::Skinskins
 An array of skins. More...
 
std::vector< CesiumGltf::Texturetextures
 An array of textures.
 
- Public Attributes inherited from CesiumUtility::ExtensibleObject
std::unordered_map< std::string, std::any > extensions
 The extensions attached to this object. More...
 
JsonValue::Object extras
 Application-specific data. More...
 
JsonValue::Object unknownProperties
 Unknown properties that exist on this object but do not have any representation in the statically-typed classes. More...
 
- Static Public Attributes inherited from CesiumGltf::ModelSpec
static constexpr const char * TypeName = "Model"
 

Detailed Description

The root object for a glTF asset.

Definition at line 14 of file Model.h.

Member Function Documentation

◆ addExtensionRequired()

void CesiumGltf::Model::addExtensionRequired ( const std::string &  extensionName)

Adds an extension to the ModelSpec::extensionsRequired property, if it is not already present.

Calling this function also adds the extension to extensionsUsed, if it's not already present.

Parameters
extensionNameThe name of the required extension.

◆ addExtensionUsed()

void CesiumGltf::Model::addExtensionUsed ( const std::string &  extensionName)

Adds an extension to the ModelSpec::extensionsUsed property, if it is not already present.

Parameters
extensionNameThe name of the used extension.

◆ forEachNodeInScene() [1/2]

void CesiumGltf::Model::forEachNodeInScene ( int32_t  sceneID,
std::function< ForEachNodeInSceneCallback > &&  callback 
)

Apply the given callback to all nodes in the scene.

If the given sceneID is non-negative and exists in the given glTF, then the given callback will be applied to all nodes in this scene.

If the given sceneId is negative, then the nodes that the callback will be applied to depends on the structure of the glTF model:

  • If the glTF model has a default scene, then it will be applied to all nodes in the default scene.
  • Otherwise, it will be applied to all nodes in the first scene.
  • Otherwise (if the glTF model does not contain any scenes), it will be applied to the first node.
  • Otherwise (if there are no scenes and no nodes), then this method will do nothing.
Parameters
sceneIDThe scene ID (index)
callbackThe callback to apply

◆ forEachNodeInScene() [2/2]

void CesiumGltf::Model::forEachNodeInScene ( int32_t  sceneID,
std::function< ForEachNodeInSceneConstCallback > &&  callback 
) const

◆ forEachPrimitiveInScene() [1/2]

void CesiumGltf::Model::forEachPrimitiveInScene ( int32_t  sceneID,
std::function< ForEachPrimitiveInSceneCallback > &&  callback 
)

Apply the given callback to all relevant primitives.

If the given sceneID is non-negative and exists in the given glTF, then the given callback will be applied to all meshes of this scene.

If the given sceneId is negative, then the meshes that the callback will be applied to depends on the structure of the glTF model:

  • If the glTF model has a default scene, then it will be applied to all meshes of the default scene.
  • Otherwise, it will be applied to all meshes of the the first scene.
  • Otherwise (if the glTF model does not contain any scenes), it will be applied to all meshes that can be found by starting a traversal at the root node.
  • Otherwise (if there are no scenes and no nodes), then all meshes will be traversed.
Parameters
sceneIDThe scene ID (index)
callbackThe callback to apply

◆ forEachPrimitiveInScene() [2/2]

void CesiumGltf::Model::forEachPrimitiveInScene ( int32_t  sceneID,
std::function< ForEachPrimitiveInSceneConstCallback > &&  callback 
) const

◆ forEachRootNodeInScene() [1/2]

void CesiumGltf::Model::forEachRootNodeInScene ( int32_t  sceneID,
std::function< ForEachRootNodeInSceneCallback > &&  callback 
)

Apply the given callback to the root nodes of the scene.

If the given sceneID is non-negative and exists in the given glTF, then the given callback will be applied to all root nodes of this scene.

If the given sceneId is negative, then the nodes that the callback will be applied to depends on the structure of the glTF model:

  • If the glTF model has a default scene, then it will be applied to all root nodes of the default scene.
  • Otherwise, it will be applied to all root nodes of the first scene.
  • Otherwise (if the glTF model does not contain any scenes), it will be applied to the first node.
  • Otherwise (if there are no scenes and no nodes), then this method will do nothing.
Parameters
sceneIDThe scene ID (index)
callbackThe callback to apply

◆ forEachRootNodeInScene() [2/2]

void CesiumGltf::Model::forEachRootNodeInScene ( int32_t  sceneID,
std::function< ForEachRootNodeInSceneConstCallback > &&  callback 
) const

◆ getSafe() [1/3]

template<typename T >
static const T& CesiumGltf::Model::getSafe ( const std::vector< T > &  items,
int32_t  index 
)
inlinestatic

Safely gets the element with a given index, returning a default instance if the index is outside the range.

Template Parameters
TThe type of the array.
Parameters
itemsThe array.
indexThe index of the array element to retrieve.
Returns
The requested element, or a default instance if the index is invalid.

Definition at line 179 of file Model.h.

◆ getSafe() [2/3]

template<typename T >
static const T* CesiumGltf::Model::getSafe ( const std::vector< T > *  pItems,
int32_t  index 
)
inlinestaticnoexcept

Safely gets a pointer to the element with a given index, returning nullptr if the index is outside the range.

Template Parameters
TThe type of the array.
Parameters
pItemsThe array.
indexThe index of the array element to retrieve.
Returns
A pointer to the requested element, or nullptr if the index is invalid.

Definition at line 200 of file Model.h.

◆ getSafe() [3/3]

template<typename T >
static T* CesiumGltf::Model::getSafe ( std::vector< T > *  pItems,
int32_t  index 
)
inlinestaticnoexcept

Safely gets a pointer to the element with a given index, returning nullptr if the index is outside the range.

Template Parameters
TThe type of the array.
Parameters
pItemsThe array.
indexThe index of the array element to retrieve.
Returns
A pointer to the requested element, or nullptr if the index is invalid.

Definition at line 219 of file Model.h.

◆ isExtensionRequired()

bool CesiumGltf::Model::isExtensionRequired ( const std::string &  extensionName) const
noexcept

Determines whether a given extension name is listed in the model's ModelSpec::extensionsRequired property.

Parameters
extensionNameThe extension name to check.
Returns
True if the extension is found in extensionsRequired; otherwise, false.

◆ isExtensionUsed()

bool CesiumGltf::Model::isExtensionUsed ( const std::string &  extensionName) const
noexcept

Determines whether a given extension name is listed in the model's ModelSpec::extensionsUsed property.

Parameters
extensionNameThe extension name to check.
Returns
True if the extension is found in extensionsUsed; otherwise, false.

◆ merge()

CesiumUtility::ErrorList CesiumGltf::Model::merge ( Model &&  rhs)

Merges another model into this one.

After this method returns, this Model contains all of the elements that were originally in it plus all of the elements that were in rhs. Element indices are updated accordingly. However, element indices in ExtensibleObject::extras, if any, are not updated.

Parameters
rhsThe model to merge into this one.

◆ removeExtensionRequired()

void CesiumGltf::Model::removeExtensionRequired ( const std::string &  extensionName)

Removes an extension from the ModelSpec::extensionsRequired property.

Calling this function also removes the extension from extensionsUsed.

Parameters
extensionNameThe name of the required extension.

◆ removeExtensionUsed()

void CesiumGltf::Model::removeExtensionUsed ( const std::string &  extensionName)

Removes an extension from the ModelSpec::extensionsUsed property.

Parameters
extensionNameThe name of the used extension.

The documentation for this struct was generated from the following file: