cesium-native 0.43.0
Loading...
Searching...
No Matches
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
11namespace CesiumGltf {
12
14struct CESIUMGLTF_API Model : public ModelSpec {
15 Model() = default;
16
29
33 typedef void ForEachRootNodeInSceneCallback(Model& gltf, Node& node);
34
38 typedef void
40
62 int32_t sceneID,
63 std::function<ForEachRootNodeInSceneCallback>&& callback);
64
67 int32_t sceneID,
68 std::function<ForEachRootNodeInSceneConstCallback>&& callback) const;
69
74 Model& gltf,
75 Node& node,
76 const glm::dmat4& transform);
77
99 int32_t sceneID,
100 std::function<ForEachNodeInSceneCallback>&& callback);
101
106 const Model& gltf,
107 const Node& node,
108 const glm::dmat4& transform);
109
112 int32_t sceneID,
113 std::function<ForEachNodeInSceneConstCallback>&& callback) const;
114
119 Model& gltf,
120 Node& node,
121 Mesh& mesh,
122 MeshPrimitive& primitive,
123 const glm::dmat4& transform);
124
147 int32_t sceneID,
148 std::function<ForEachPrimitiveInSceneCallback>&& callback);
149
154 const Model& gltf,
155 const Node& node,
156 const Mesh& mesh,
157 const MeshPrimitive& primitive,
158 const glm::dmat4& transform);
159
162 int32_t sceneID,
163 std::function<ForEachPrimitiveInSceneConstCallback>&& callback) const;
164
169
180 template <typename T>
181 static const T& getSafe(const std::vector<T>& items, int32_t index) {
182 static T defaultObject;
183 if (index < 0 || size_t(index) >= items.size()) {
184 return defaultObject;
185 } else {
186 return items[size_t(index)];
187 }
188 }
189
200 template <typename T>
201 static const T*
202 getSafe(const std::vector<T>* pItems, int32_t index) noexcept {
203 if (index < 0 || size_t(index) >= pItems->size()) {
204 return nullptr;
205 } else {
206 return &(*pItems)[size_t(index)];
207 }
208 }
209
220 template <typename T>
221 static T* getSafe(std::vector<T>* pItems, int32_t index) noexcept {
222 if (index < 0 || size_t(index) >= pItems->size()) {
223 return nullptr;
224 } else {
225 return &(*pItems)[size_t(index)];
226 }
227 }
228
235 void addExtensionUsed(const std::string& extensionName);
236
246 void addExtensionRequired(const std::string& extensionName);
247
254 void removeExtensionUsed(const std::string& extensionName);
255
264 void removeExtensionRequired(const std::string& extensionName);
265
274 bool isExtensionUsed(const std::string& extensionName) const noexcept;
275
284 bool isExtensionRequired(const std::string& extensionName) const noexcept;
285};
286
287} // namespace CesiumGltf
Classes for working with glTF models.
Geometry to be rendered with the given material.
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:30
This class is not meant to be instantiated directly. Use Model instead.
Definition Model.h:14
void removeExtensionRequired(const std::string &extensionName)
Removes an extension from the ModelSpec::extensionsRequired property.
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:73
void forEachNodeInScene(int32_t sceneID, std::function< ForEachNodeInSceneConstCallback > &&callback) const
Apply the given callback to all nodes in the scene.
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:221
void ForEachNodeInSceneConstCallback(const Model &gltf, const Node &node, const glm::dmat4 &transform)
A callback function for forEachNodeInScene.
Definition Model.h:105
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.
void forEachRootNodeInScene(int32_t sceneID, std::function< ForEachRootNodeInSceneCallback > &&callback)
Apply the given callback to the root nodes of the scene.
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:153
void forEachNodeInScene(int32_t sceneID, std::function< ForEachNodeInSceneCallback > &&callback)
Apply the given callback to all nodes in the scene.
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:202
void forEachRootNodeInScene(int32_t sceneID, std::function< ForEachRootNodeInSceneConstCallback > &&callback) const
Apply the given callback to the root nodes of the scene.
void removeExtensionUsed(const std::string &extensionName)
Removes an extension from the ModelSpec::extensionsUsed property.
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:181
void addExtensionUsed(const std::string &extensionName)
Adds an extension to the ModelSpec::extensionsUsed property, if it is not already present.
void ForEachPrimitiveInSceneCallback(Model &gltf, Node &node, Mesh &mesh, MeshPrimitive &primitive, const glm::dmat4 &transform)
A callback function for forEachPrimitiveInScene.
Definition Model.h:118
void ForEachRootNodeInSceneCallback(Model &gltf, Node &node)
A callback function for forEachRootNodeInScene.
Definition Model.h:33
void ForEachRootNodeInSceneConstCallback(const Model &gltf, const Node &node)
A callback function for forEachRootNodeInScene.
Definition Model.h:39
void forEachPrimitiveInScene(int32_t sceneID, std::function< ForEachPrimitiveInSceneConstCallback > &&callback) const
Apply the given callback to all relevant primitives.
CesiumUtility::ErrorList merge(Model &&rhs)
Merges another model into this one.
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