cesium-native 0.43.0
Loading...
Searching...
No Matches
GltfUtilities.h
1#pragma once
2
3#include "Library.h"
4
5#include <CesiumGeospatial/BoundingRegion.h>
6#include <CesiumGeospatial/Ellipsoid.h>
7#include <CesiumGeospatial/GlobeRectangle.h>
8
9#include <glm/fwd.hpp>
10
11#include <optional>
12#include <string>
13#include <string_view>
14#include <vector>
15
16namespace CesiumGltf {
17struct Buffer;
18struct Model;
19struct Node;
20} // namespace CesiumGltf
21
22namespace CesiumGeometry {
23class Ray;
24} // namespace CesiumGeometry
25
31struct CESIUMGLTFCONTENT_API GltfUtilities {
43 static std::optional<glm::dmat4x4>
45
55 static void
56 setNodeTransform(CesiumGltf::Node& node, const glm::dmat4x4& newTransform);
57
71 static glm::dmat4x4 applyRtcCenter(
72 const CesiumGltf::Model& gltf,
73 const glm::dmat4x4& rootTransform);
74
93 static glm::dmat4x4 applyGltfUpAxisTransform(
94 const CesiumGltf::Model& model,
95 const glm::dmat4x4& rootTransform);
96
116 const CesiumGltf::Model& gltf,
117 const glm::dmat4& transform,
118 const CesiumGeospatial::Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID);
119
130 static std::vector<std::string_view>
132
143
156 static void moveBufferContent(
157 CesiumGltf::Model& gltf,
158 CesiumGltf::Buffer& destination,
159 CesiumGltf::Buffer& source);
160
170 CesiumGltf::Model& gltf,
171 const std::vector<int32_t>& extraUsedTextureIndices = {});
172
182 CesiumGltf::Model& gltf,
183 const std::vector<int32_t>& extraUsedSamplerIndices = {});
184
194 CesiumGltf::Model& gltf,
195 const std::vector<int32_t>& extraUsedImageIndices = {});
196
206 CesiumGltf::Model& gltf,
207 const std::vector<int32_t>& extraUsedAccessorIndices = {});
208
218 CesiumGltf::Model& gltf,
219 const std::vector<int32_t>& extraUsedBufferViewIndices = {});
220
230 CesiumGltf::Model& gltf,
231 const std::vector<int32_t>& extraUsedBufferIndices = {});
232
242 CesiumGltf::Model& gltf,
243 const std::vector<int32_t>& extraUsedMeshIndices = {});
244
254 CesiumGltf::Model& gltf,
255 const std::vector<int32_t>& extraUsedMaterialIndices = {});
256
264
272 static void compactBuffer(CesiumGltf::Model& gltf, int32_t bufferIndex);
273
277 struct RayGltfHit {
281 glm::dvec3 primitivePoint = {};
282
286 glm::dmat4x4 primitiveToWorld = {};
287
291 glm::dvec3 worldPoint = {};
292
296 double rayToWorldPointDistanceSq = -1.0;
297
301 int32_t meshId = -1;
302
306 int32_t primitiveId = -1;
307 };
308
316 std::optional<RayGltfHit> hit;
317
321 std::vector<std::string> warnings{};
322 };
323
339 const CesiumGeometry::Ray& ray,
340 const CesiumGltf::Model& gltf,
341 bool cullBackFaces = true,
342 const glm::dmat4x4& gltfTransform = glm::dmat4(1.0));
343};
344} // namespace CesiumGltfContent
A ray that extends infinitely from the provided origin in the provided direction.
Definition Ray.h:14
A bounding volume specified as a longitude/latitude bounding box and a minimum and maximum height.
A quadratic surface defined in Cartesian coordinates.
Definition Ellipsoid.h:38
Basic geometry classes for Cesium.
Classes that support manipulating the content of a glTF.
Classes for working with glTF models.
Hit result data for intersectRayGltfModel.
std::optional< RayGltfHit > hit
Optional hit result, if an intersection occurred.
Data describing a hit from a ray / gltf intersection test.
static void compactBuffers(CesiumGltf::Model &gltf)
Shrink buffers by removing any sections that are not referenced by any BufferView.
static void removeUnusedSamplers(CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedSamplerIndices={})
Removes unused samplers from the given glTF model.
static void removeUnusedBufferViews(CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedBufferViewIndices={})
Removes unused buffer views from the given glTF model.
static glm::dmat4x4 applyRtcCenter(const CesiumGltf::Model &gltf, const glm::dmat4x4 &rootTransform)
Applies the glTF's RTC_CENTER, if any, to the given transform.
static IntersectResult intersectRayGltfModel(const CesiumGeometry::Ray &ray, const CesiumGltf::Model &gltf, bool cullBackFaces=true, const glm::dmat4x4 &gltfTransform=glm::dmat4(1.0))
Intersects a ray with a glTF model and returns the first intersection point.
static std::vector< std::string_view > parseGltfCopyright(const CesiumGltf::Model &gltf)
Parse the copyright field of a glTF model and return the individual credits.
static void setNodeTransform(CesiumGltf::Node &node, const glm::dmat4x4 &newTransform)
Sets the transformation matrix for a given node.
static void moveBufferContent(CesiumGltf::Model &gltf, CesiumGltf::Buffer &destination, CesiumGltf::Buffer &source)
Copies the content of one CesiumGltf::Buffer to the end of another, updates all CesiumGltf::BufferVie...
static void removeUnusedAccessors(CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedAccessorIndices={})
Removes unused accessors from the given glTF model.
static void removeUnusedBuffers(CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedBufferIndices={})
Removes unused buffers from the given glTF model.
static std::optional< glm::dmat4x4 > getNodeTransform(const CesiumGltf::Node &node)
Gets the transformation matrix for a given node.
static glm::dmat4x4 applyGltfUpAxisTransform(const CesiumGltf::Model &model, const glm::dmat4x4 &rootTransform)
Applies the glTF's gltfUpAxis, if any, to the given transform.
static CesiumGeospatial::BoundingRegion computeBoundingRegion(const CesiumGltf::Model &gltf, const glm::dmat4 &transform, const CesiumGeospatial::Ellipsoid &ellipsoid=CesiumGeospatial::Ellipsoid::WGS84)
Computes a bounding region from the vertex positions in a glTF model.
static void removeUnusedMaterials(CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedMaterialIndices={})
Removes unused materials from the given glTF model.
static void removeUnusedImages(CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedImageIndices={})
Removes unused images from the given glTF model.
static void removeUnusedTextures(CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedTextureIndices={})
Removes unused textures from the given glTF model.
static void collapseToSingleBuffer(CesiumGltf::Model &gltf)
Merges all of the glTF's buffers into a single buffer (the first one).
static void compactBuffer(CesiumGltf::Model &gltf, int32_t bufferIndex)
Shrink a buffer by removing any sections that are not referenced by any BufferView.
static void removeUnusedMeshes(CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedMeshIndices={})
Removes unused meshes from the given glTF model.
This class is not meant to be instantiated directly. Use Buffer instead.
Definition Buffer.h:9
This class is not meant to be instantiated directly. Use Model instead.
Definition Model.h:14
A node in the node hierarchy. When the node contains skin, all mesh.primitives MUST contain JOINTS_0 ...
Definition Node.h:23