cesium-native 0.44.2
Loading...
Searching...
No Matches
GltfUtilities.h
1#pragma once
2
3#include <CesiumGeospatial/BoundingRegion.h>
4#include <CesiumGeospatial/Ellipsoid.h>
5#include <CesiumGeospatial/GlobeRectangle.h>
6#include <CesiumGltfContent/Library.h>
7
8#include <glm/fwd.hpp>
9
10#include <optional>
11#include <string>
12#include <string_view>
13#include <vector>
14
15namespace CesiumGltf {
16struct Buffer;
17struct Model;
18struct Node;
19} // namespace CesiumGltf
20
21namespace CesiumGeometry {
22class Ray;
23} // namespace CesiumGeometry
24
30struct CESIUMGLTFCONTENT_API GltfUtilities {
42 static std::optional<glm::dmat4x4>
44
54 static void
55 setNodeTransform(CesiumGltf::Node& node, const glm::dmat4x4& newTransform);
56
70 static glm::dmat4x4 applyRtcCenter(
71 const CesiumGltf::Model& gltf,
72 const glm::dmat4x4& rootTransform);
73
92 static glm::dmat4x4 applyGltfUpAxisTransform(
93 const CesiumGltf::Model& model,
94 const glm::dmat4x4& rootTransform);
95
115 const CesiumGltf::Model& gltf,
116 const glm::dmat4& transform,
117 const CesiumGeospatial::Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID);
118
129 static std::vector<std::string_view>
131
139 static std::vector<std::string_view>
140 parseGltfCopyright(const std::string_view& s);
141
152
165 static void moveBufferContent(
166 CesiumGltf::Model& gltf,
167 CesiumGltf::Buffer& destination,
168 CesiumGltf::Buffer& source);
169
179 CesiumGltf::Model& gltf,
180 const std::vector<int32_t>& extraUsedTextureIndices = {});
181
191 CesiumGltf::Model& gltf,
192 const std::vector<int32_t>& extraUsedSamplerIndices = {});
193
203 CesiumGltf::Model& gltf,
204 const std::vector<int32_t>& extraUsedImageIndices = {});
205
215 CesiumGltf::Model& gltf,
216 const std::vector<int32_t>& extraUsedAccessorIndices = {});
217
227 CesiumGltf::Model& gltf,
228 const std::vector<int32_t>& extraUsedBufferViewIndices = {});
229
239 CesiumGltf::Model& gltf,
240 const std::vector<int32_t>& extraUsedBufferIndices = {});
241
251 CesiumGltf::Model& gltf,
252 const std::vector<int32_t>& extraUsedMeshIndices = {});
253
263 CesiumGltf::Model& gltf,
264 const std::vector<int32_t>& extraUsedMaterialIndices = {});
265
273
281 static void compactBuffer(CesiumGltf::Model& gltf, int32_t bufferIndex);
282
286 struct RayGltfHit {
290 glm::dvec3 primitivePoint = {};
291
295 glm::dmat4x4 primitiveToWorld = {};
296
300 glm::dvec3 worldPoint = {};
301
305 double rayToWorldPointDistanceSq = -1.0;
306
310 int32_t meshId = -1;
311
315 int32_t primitiveId = -1;
316 };
317
325 std::optional<RayGltfHit> hit;
326
330 std::vector<std::string> warnings{};
331 };
332
348 const CesiumGeometry::Ray& ray,
349 const CesiumGltf::Model& gltf,
350 bool cullBackFaces = true,
351 const glm::dmat4x4& gltfTransform = glm::dmat4(1.0));
352};
353} // 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:39
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 std::vector< std::string_view > parseGltfCopyright(const std::string_view &s)
Parse a semicolon-separated string, such as the copyright field of a glTF model, and return the indiv...
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