cesium-native  0.41.0
Model.h
1 #pragma once
2 
3 #include <CesiumGltf/Library.h>
4 #include <CesiumGltf/ModelSpec.h>
5 #include <CesiumUtility/ErrorList.h>
6 
7 #include <glm/mat4x4.hpp>
8 
9 #include <functional>
10 
11 namespace CesiumGltf {
12 
14 struct CESIUMGLTF_API Model : public ModelSpec {
27 
31  typedef void ForEachRootNodeInSceneCallback(Model& gltf, Node& node);
32 
36  typedef void
37  ForEachRootNodeInSceneConstCallback(const Model& gltf, const Node& node);
38 
60  int32_t sceneID,
61  std::function<ForEachRootNodeInSceneCallback>&& callback);
62 
65  int32_t sceneID,
66  std::function<ForEachRootNodeInSceneConstCallback>&& callback) const;
67 
72  Model& gltf,
73  Node& node,
74  const glm::dmat4& transform);
75 
97  int32_t sceneID,
98  std::function<ForEachNodeInSceneCallback>&& callback);
99 
104  const Model& gltf,
105  const Node& node,
106  const glm::dmat4& transform);
107 
110  int32_t sceneID,
111  std::function<ForEachNodeInSceneConstCallback>&& callback) const;
112 
117  Model& gltf,
118  Node& node,
119  Mesh& mesh,
120  MeshPrimitive& primitive,
121  const glm::dmat4& transform);
122 
145  int32_t sceneID,
146  std::function<ForEachPrimitiveInSceneCallback>&& callback);
147 
152  const Model& gltf,
153  const Node& node,
154  const Mesh& mesh,
155  const MeshPrimitive& primitive,
156  const glm::dmat4& transform);
157 
160  int32_t sceneID,
161  std::function<ForEachPrimitiveInSceneConstCallback>&& callback) const;
162 
167 
178  template <typename T>
179  static const T& getSafe(const std::vector<T>& items, int32_t index) {
180  static T defaultObject;
181  if (index < 0 || size_t(index) >= items.size()) {
182  return defaultObject;
183  } else {
184  return items[size_t(index)];
185  }
186  }
187 
198  template <typename T>
199  static const T*
200  getSafe(const std::vector<T>* pItems, int32_t index) noexcept {
201  if (index < 0 || size_t(index) >= pItems->size()) {
202  return nullptr;
203  } else {
204  return &(*pItems)[size_t(index)];
205  }
206  }
207 
218  template <typename T>
219  static T* getSafe(std::vector<T>* pItems, int32_t index) noexcept {
220  if (index < 0 || size_t(index) >= pItems->size()) {
221  return nullptr;
222  } else {
223  return &(*pItems)[size_t(index)];
224  }
225  }
226 
233  void addExtensionUsed(const std::string& extensionName);
234 
244  void addExtensionRequired(const std::string& extensionName);
245 
252  void removeExtensionUsed(const std::string& extensionName);
253 
262  void removeExtensionRequired(const std::string& extensionName);
263 
272  bool isExtensionUsed(const std::string& extensionName) const noexcept;
273 
282  bool isExtensionRequired(const std::string& extensionName) const noexcept;
283 };
284 
285 } // namespace CesiumGltf
Classes for working with glTF models.
Geometry to be rendered with the given material.
Definition: MeshPrimitive.h:18
A set of primitives to be rendered. Its global transform is defined by a node that references it.
Definition: Mesh.h:16
The root object for a glTF asset.
Definition: ModelSpec.h:31
The root object for a glTF asset.
Definition: Model.h:14
void removeExtensionRequired(const std::string &extensionName)
Removes an extension from the ModelSpec::extensionsRequired property.
void ForEachPrimitiveInSceneCallback(Model &gltf, Node &node, Mesh &mesh, MeshPrimitive &primitive, const glm::dmat4 &transform)
A callback function for forEachPrimitiveInScene.
Definition: Model.h:116
void addExtensionRequired(const std::string &extensionName)
Adds an extension to the ModelSpec::extensionsRequired property, if it is not already present.
void ForEachNodeInSceneCallback(Model &gltf, Node &node, const glm::dmat4 &transform)
A callback function for forEachNodeInScene.
Definition: Model.h:71
void ForEachNodeInSceneConstCallback(const Model &gltf, const Node &node, const glm::dmat4 &transform)
A callback function for forEachNodeInScene.
Definition: Model.h:103
void forEachNodeInScene(int32_t sceneID, std::function< ForEachNodeInSceneConstCallback > &&callback) const
bool isExtensionUsed(const std::string &extensionName) const noexcept
Determines whether a given extension name is listed in the model's ModelSpec::extensionsUsed property...
bool isExtensionRequired(const std::string &extensionName) const noexcept
Determines whether a given extension name is listed in the model's ModelSpec::extensionsRequired prop...
void generateMissingNormalsSmooth()
Fills in smooth normals for any primitives with missing normals.
void forEachPrimitiveInScene(int32_t sceneID, std::function< ForEachPrimitiveInSceneCallback > &&callback)
Apply the given callback to all relevant primitives.
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 ...
Definition: Model.h:179
void ForEachRootNodeInSceneConstCallback(const Model &gltf, const Node &node)
A callback function for forEachRootNodeInScene.
Definition: Model.h:37
void forEachRootNodeInScene(int32_t sceneID, std::function< ForEachRootNodeInSceneCallback > &&callback)
Apply the given callback to the root nodes of the scene.
void forEachNodeInScene(int32_t sceneID, std::function< ForEachNodeInSceneCallback > &&callback)
Apply the given callback to all nodes in the scene.
void forEachRootNodeInScene(int32_t sceneID, std::function< ForEachRootNodeInSceneConstCallback > &&callback) const
void removeExtensionUsed(const std::string &extensionName)
Removes an extension from the ModelSpec::extensionsUsed property.
void addExtensionUsed(const std::string &extensionName)
Adds an extension to the ModelSpec::extensionsUsed property, if it is not already present.
void ForEachPrimitiveInSceneConstCallback(const Model &gltf, const Node &node, const Mesh &mesh, const MeshPrimitive &primitive, const glm::dmat4 &transform)
A callback function for forEachPrimitiveInScene.
Definition: Model.h:151
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 th...
Definition: Model.h:200
void forEachPrimitiveInScene(int32_t sceneID, std::function< ForEachPrimitiveInSceneConstCallback > &&callback) const
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 th...
Definition: Model.h:219
CesiumUtility::ErrorList merge(Model &&rhs)
Merges another model into this one.
void ForEachRootNodeInSceneCallback(Model &gltf, Node &node)
A callback function for forEachRootNodeInScene.
Definition: Model.h:31
A node in the node hierarchy. When the node contains skin, all mesh.primitives MUST contain JOINTS_0 ...
Definition: Node.h:23
The container to store the error and warning list when loading a tile or glTF content.
Definition: ErrorList.h:17