cesium-native  0.41.0
CesiumGltf::AccessorView< T > Class Template Referencefinal

A view on the data of one accessor of a glTF asset. More...

#include <CesiumGltf/AccessorView.h>

Public Types

typedef T value_type
 The type of the elements in the accessor.
 

Public Member Functions

 AccessorView (AccessorViewStatus status=AccessorViewStatus::InvalidAccessorIndex)
 Construct a new instance not pointing to any data. More...
 
 AccessorView (const std::byte *pData, int64_t stride, int64_t offset, int64_t size)
 Creates a new instance from low-level parameters. More...
 
 AccessorView (const Model &model, const Accessor &accessor) noexcept
 Creates a new instance from a given model and Accessor. More...
 
 AccessorView (const Model &model, int32_t accessorIndex) noexcept
 Creates a new instance from a given model and accessor index. More...
 
const T & operator[] (int64_t i) const
 Provides the specified accessor element. More...
 
int64_t size () const noexcept
 Returns the size (number of elements) of this accessor. More...
 
AccessorViewStatus status () const noexcept
 Gets the status of this accessor view. More...
 
int64_t stride () const noexcept
 Returns the stride of this accessor, which is the number of bytes from the start of one element to the start of the next. More...
 
const std::byte * data () const noexcept
 Returns a pointer to the first byte of this accessor view's data. The elements are stored contiguously, so the next one starts stride bytes later. More...
 

Detailed Description

template<class T>
class CesiumGltf::AccessorView< T >

A view on the data of one accessor of a glTF asset.

It provides the actual accessor data like an array of elements. The type of the accessor elements is determined by the template parameter. Instances are usually from an Accessor, and the operator[]() can be used to access the elements:

CesiumGltf::Model model = anyOldFunctionToGetAModel();
glm::vec3 firstPosition = positions[0];
A view on the data of one accessor of a glTF asset.
Definition: AccessorView.h:80
The root object for a glTF asset.
Definition: Model.h:14
Template Parameters
TThe type of the elements in the accessor.

Definition at line 80 of file AccessorView.h.

Constructor & Destructor Documentation

◆ AccessorView() [1/4]

Construct a new instance not pointing to any data.

The new instance will have a size of 0 and a status of AccessorViewStatus::InvalidAccessorIndex.

Parameters
statusThe status of the new accessor. Defaults to AccessorViewStatus::InvalidAccessorIndex.

Definition at line 103 of file AccessorView.h.

◆ AccessorView() [2/4]

template<class T >
CesiumGltf::AccessorView< T >::AccessorView ( const std::byte *  pData,
int64_t  stride,
int64_t  offset,
int64_t  size 
)
inline

Creates a new instance from low-level parameters.

The provided parameters are not validated in any way, and so this overload can easily be used to access invalid memory.

Parameters
pDataThe raw data buffer from which to read.
strideThe stride, in bytes, between successive elements.
offsetThe offset from the start of the buffer to the first element.
sizeThe total number of elements.

Definition at line 118 of file AccessorView.h.

◆ AccessorView() [3/4]

template<class T >
CesiumGltf::AccessorView< T >::AccessorView ( const Model model,
const Accessor accessor 
)
inlinenoexcept

Creates a new instance from a given model and Accessor.

If the accessor cannot be viewed, the construct will still complete successfully without throwing an exception. However, size will return 0 and status will indicate what went wrong.

Parameters
modelThe model to access.
accessorThe accessor to view.

Definition at line 140 of file AccessorView.h.

◆ AccessorView() [4/4]

template<class T >
CesiumGltf::AccessorView< T >::AccessorView ( const Model model,
int32_t  accessorIndex 
)
inlinenoexcept

Creates a new instance from a given model and accessor index.

If the accessor cannot be viewed, the construct will still complete successfully without throwing an exception. However, size will return 0 and status will indicate what went wrong.

Parameters
modelThe model to access.
accessorIndexThe index of the accessor to view in the model's Model::accessors list.

Definition at line 157 of file AccessorView.h.

Member Function Documentation

◆ data()

template<class T >
const std::byte* CesiumGltf::AccessorView< T >::data ( ) const
inlinenoexcept

Returns a pointer to the first byte of this accessor view's data. The elements are stored contiguously, so the next one starts stride bytes later.

Returns
The start of this view.

Definition at line 216 of file AccessorView.h.

◆ operator[]()

template<class T >
const T& CesiumGltf::AccessorView< T >::operator[] ( int64_t  i) const
inline

Provides the specified accessor element.

Parameters
iThe index of the element.
Returns
The constant reference to the accessor element.
Exceptions
Astd::range_error if the given index is negative or not smaller than the size of this accessor.

Definition at line 176 of file AccessorView.h.

◆ size()

template<class T >
int64_t CesiumGltf::AccessorView< T >::size ( ) const
inlinenoexcept

Returns the size (number of elements) of this accessor.

This is the number of elements of type T that this accessor contains.

Returns
The size.

Definition at line 192 of file AccessorView.h.

◆ status()

template<class T >
AccessorViewStatus CesiumGltf::AccessorView< T >::status ( ) const
inlinenoexcept

Gets the status of this accessor view.

Indicates whether the view accurately reflects the accessor's data, or whether an error occurred.

Definition at line 200 of file AccessorView.h.

◆ stride()

template<class T >
int64_t CesiumGltf::AccessorView< T >::stride ( ) const
inlinenoexcept

Returns the stride of this accessor, which is the number of bytes from the start of one element to the start of the next.

Returns
The stride.

Definition at line 208 of file AccessorView.h.


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