cesium-native 0.43.0
Loading...
Searching...
No Matches
CesiumGltfContent::GltfUtilities Struct Reference

#include <CesiumGltfContent/GltfUtilities.h>

Classes

struct  IntersectResult
 Hit result data for intersectRayGltfModel. More...
 
struct  RayGltfHit
 Data describing a hit from a ray / gltf intersection test. More...
 

Static Public Member Functions

static std::optional< glm::dmat4x4 > getNodeTransform (const CesiumGltf::Node &node)
 Gets the transformation matrix for a given node.
 
static void setNodeTransform (CesiumGltf::Node &node, const glm::dmat4x4 &newTransform)
 Sets the transformation matrix for a given node.
 
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 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 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 collapseToSingleBuffer (CesiumGltf::Model &gltf)
 Merges all of the glTF's buffers into a single buffer (the first one).
 
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::BufferView instances to refer to the destination buffer, and clears the contents of the original buffer.
 
static void removeUnusedTextures (CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedTextureIndices={})
 Removes unused textures from the given glTF model.
 
static void removeUnusedSamplers (CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedSamplerIndices={})
 Removes unused samplers 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 removeUnusedAccessors (CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedAccessorIndices={})
 Removes unused accessors 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 void removeUnusedBuffers (CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedBufferIndices={})
 Removes unused buffers from the given glTF model.
 
static void removeUnusedMeshes (CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedMeshIndices={})
 Removes unused meshes from the given glTF model.
 
static void removeUnusedMaterials (CesiumGltf::Model &gltf, const std::vector< int32_t > &extraUsedMaterialIndices={})
 Removes unused materials from the given glTF model.
 
static void compactBuffers (CesiumGltf::Model &gltf)
 Shrink buffers by removing any sections that are not referenced by any BufferView.
 
static void compactBuffer (CesiumGltf::Model &gltf, int32_t bufferIndex)
 Shrink a buffer by removing any sections that are not referenced by any BufferView.
 
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.
 

Detailed Description

A collection of utility functions that are used to process and transform a gltf model

Definition at line 31 of file GltfUtilities.h.

Member Function Documentation

◆ applyGltfUpAxisTransform()

static glm::dmat4x4 CesiumGltfContent::GltfUtilities::applyGltfUpAxisTransform ( const CesiumGltf::Model & model,
const glm::dmat4x4 & rootTransform )
static

Applies the glTF's gltfUpAxis, if any, to the given transform.

By default, the up-axis of a glTF model will the the Y-axis.

If the tileset that contained the model had the asset.gltfUpAxis string property, then the information about the up-axis has been stored in as a number property called gltfUpAxis in the extras of the given model.

Depending on whether this value is CesiumGeometry::Axis::X, Y, or Z, the given matrix will be multiplied with a matrix that converts the respective axis to be the Z-axis, as required by the 3D Tiles standard.

Parameters
modelThe glTF model
rootTransformThe matrix that will be multiplied with the transform
Returns
The result of multiplying the rootTransform with the gltfUpAxis.

◆ applyRtcCenter()

static glm::dmat4x4 CesiumGltfContent::GltfUtilities::applyRtcCenter ( const CesiumGltf::Model & gltf,
const glm::dmat4x4 & rootTransform )
static

Applies the glTF's RTC_CENTER, if any, to the given transform.

If the glTF has a CESIUM_RTC extension, this function will multiply the given matrix with the (translation) matrix that is created from the RTC_CENTER in the. If the given model does not have this extension, then this function will return the rootTransform unchanged.

Parameters
gltfThe glTF model
rootTransformThe matrix that will be multiplied with the transform
Returns
The result of multiplying the RTC_CENTER with the rootTransform.

◆ collapseToSingleBuffer()

static void CesiumGltfContent::GltfUtilities::collapseToSingleBuffer ( CesiumGltf::Model & gltf)
static

Merges all of the glTF's buffers into a single buffer (the first one).

This is useful when writing the glTF as a GLB, which supports only a single embedded buffer.

Parameters
gltfThe glTF in which to merge buffers.

◆ compactBuffer()

static void CesiumGltfContent::GltfUtilities::compactBuffer ( CesiumGltf::Model & gltf,
int32_t bufferIndex )
static

Shrink a buffer by removing any sections that are not referenced by any BufferView.

Parameters
gltfThe glTF to modify.
bufferIndexThe index of the buffer to compact.

◆ compactBuffers()

static void CesiumGltfContent::GltfUtilities::compactBuffers ( CesiumGltf::Model & gltf)
static

Shrink buffers by removing any sections that are not referenced by any BufferView.

Parameters
gltfThe glTF to modify.

◆ computeBoundingRegion()

static CesiumGeospatial::BoundingRegion CesiumGltfContent::GltfUtilities::computeBoundingRegion ( const CesiumGltf::Model & gltf,
const glm::dmat4 & transform,
const CesiumGeospatial::Ellipsoid & ellipsoid = CesiumGeospatial::Ellipsoid::WGS84 )
static

Computes a bounding region from the vertex positions in a glTF model.

If the glTF model spans the anti-meridian, the west and east longitude values will be in the usual -PI to PI range, but east will have a smaller value than west.

If the glTF contains no geometry, the returned region's rectangle will be CesiumGeospatial::GlobeRectangle::EMPTY, its minimum height will be 1.0, and its maximum height will be -1.0 (the minimum will be greater than the maximum).

Parameters
gltfThe model.
transformThe transform from model coordinates to ECEF coordinates.
ellipsoidThe CesiumGeospatial::Ellipsoid.
Returns
The computed bounding region.

◆ getNodeTransform()

static std::optional< glm::dmat4x4 > CesiumGltfContent::GltfUtilities::getNodeTransform ( const CesiumGltf::Node & node)
static

Gets the transformation matrix for a given node.

This returns the node's local transform as-is. It does not incorporate transforms from any of the node's ancestors.

Parameters
nodeThe node from which to get the transformation matrix.
Returns
The transformation matrix, or std::nullopt if the node's transformation is invalid, .e.g, because it has a matrix with fewer than 16 elements in it.

◆ intersectRayGltfModel()

static IntersectResult CesiumGltfContent::GltfUtilities::intersectRayGltfModel ( const CesiumGeometry::Ray & ray,
const CesiumGltf::Model & gltf,
bool cullBackFaces = true,
const glm::dmat4x4 & gltfTransform = glm::dmat4(1.0) )
static

Intersects a ray with a glTF model and returns the first intersection point.

Supports all mesh primitive modes. Points and lines are assumed to have no area, and are ignored

Parameters
rayA ray in world space.
gltfThe glTF model to intersect.
cullBackFacesIgnore triangles that face away from ray. Front faces use CCW winding order.
gltfTransformOptional matrix to apply to entire gltf model.
Returns
IntersectResult describing outcome

◆ moveBufferContent()

static void CesiumGltfContent::GltfUtilities::moveBufferContent ( CesiumGltf::Model & gltf,
CesiumGltf::Buffer & destination,
CesiumGltf::Buffer & source )
static

Copies the content of one CesiumGltf::Buffer to the end of another, updates all CesiumGltf::BufferView instances to refer to the destination buffer, and clears the contents of the original buffer.

The source buffer is not removed, but it has a byteLength of zero after this function completes.

Parameters
gltfThe glTF model to modify.
destinationThe destination Buffer into which to move content.
sourceThe source Buffer from which to move content.

◆ parseGltfCopyright()

static std::vector< std::string_view > CesiumGltfContent::GltfUtilities::parseGltfCopyright ( const CesiumGltf::Model & gltf)
static

Parse the copyright field of a glTF model and return the individual credits.

Credits are read from the glTF's asset.copyright field. This method assumes that individual credits are separated by semicolons.

Parameters
gltfThe model.
Returns
The credits from the glTF.

◆ removeUnusedAccessors()

static void CesiumGltfContent::GltfUtilities::removeUnusedAccessors ( CesiumGltf::Model & gltf,
const std::vector< int32_t > & extraUsedAccessorIndices = {} )
static

Removes unused accessors from the given glTF model.

Parameters
gltfThe glTF to remove unused accessors from.
extraUsedAccessorIndicesIndices of accessors that should be considered "used" even if they're not referenced by anything else in the glTF.

◆ removeUnusedBuffers()

static void CesiumGltfContent::GltfUtilities::removeUnusedBuffers ( CesiumGltf::Model & gltf,
const std::vector< int32_t > & extraUsedBufferIndices = {} )
static

Removes unused buffers from the given glTF model.

Parameters
gltfThe glTF to remove unused buffers from.
extraUsedBufferIndicesIndices of buffers that should be considered "used" even if they're not referenced by anything else in the glTF.

◆ removeUnusedBufferViews()

static void CesiumGltfContent::GltfUtilities::removeUnusedBufferViews ( CesiumGltf::Model & gltf,
const std::vector< int32_t > & extraUsedBufferViewIndices = {} )
static

Removes unused buffer views from the given glTF model.

Parameters
gltfThe glTF to remove unused buffer views from.
extraUsedBufferViewIndicesIndices of buffer views that should be considered "used" even if they're not referenced by anything else in the glTF.

◆ removeUnusedImages()

static void CesiumGltfContent::GltfUtilities::removeUnusedImages ( CesiumGltf::Model & gltf,
const std::vector< int32_t > & extraUsedImageIndices = {} )
static

Removes unused images from the given glTF model.

Parameters
gltfThe glTF to remove unused images from.
extraUsedImageIndicesIndices of images that should be considered "used" even if they're not referenced by anything else in the glTF.

◆ removeUnusedMaterials()

static void CesiumGltfContent::GltfUtilities::removeUnusedMaterials ( CesiumGltf::Model & gltf,
const std::vector< int32_t > & extraUsedMaterialIndices = {} )
static

Removes unused materials from the given glTF model.

Parameters
gltfThe glTF to remove unused materials from.
extraUsedMaterialIndicesIndices of materials that should be considered "used" even if they're not referenced by anything else in the glTF.

◆ removeUnusedMeshes()

static void CesiumGltfContent::GltfUtilities::removeUnusedMeshes ( CesiumGltf::Model & gltf,
const std::vector< int32_t > & extraUsedMeshIndices = {} )
static

Removes unused meshes from the given glTF model.

Parameters
gltfThe glTF to remove unused meshes from.
extraUsedMeshIndicesIndices of meshes that should be considered "used" even if they're not referenced by anything else in the glTF.

◆ removeUnusedSamplers()

static void CesiumGltfContent::GltfUtilities::removeUnusedSamplers ( CesiumGltf::Model & gltf,
const std::vector< int32_t > & extraUsedSamplerIndices = {} )
static

Removes unused samplers from the given glTF model.

Parameters
gltfThe glTF to remove unused samplers from.
extraUsedSamplerIndicesIndices of samplers that should be considered "used" even if they're not referenced by anything else in the glTF.

◆ removeUnusedTextures()

static void CesiumGltfContent::GltfUtilities::removeUnusedTextures ( CesiumGltf::Model & gltf,
const std::vector< int32_t > & extraUsedTextureIndices = {} )
static

Removes unused textures from the given glTF model.

Parameters
gltfThe glTF to remove unused textures from.
extraUsedTextureIndicesIndices of textures that should be considered "used" even if they're not referenced by anything else in the glTF.

◆ setNodeTransform()

static void CesiumGltfContent::GltfUtilities::setNodeTransform ( CesiumGltf::Node & node,
const glm::dmat4x4 & newTransform )
static

Sets the transformation matrix for a given node.

This sets only the local transform of the node. It does not affect the transforms of any ancestor or descendant nodes, if present.

Parameters
nodeThe node on which to set the transformation matrix.
newTransformThe new transformation matrix.

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