3#include <CesiumGltf/AccessorView.h>
4#include <CesiumGltf/MeshPrimitive.h>
6#include <glm/common.hpp>
7#include <glm/ext/quaternion_double.hpp>
16template <
typename T>
double denormalize(T value) {
17 if constexpr (std::is_floating_point_v<T>) {
19 }
else if constexpr (std::is_signed_v<T>) {
20 return glm::max(
double(value) / std::numeric_limits<T>::max(), -1.0);
22 return double(value) / std::numeric_limits<T>::max();
66 AccessorView<AccessorTypes::VEC3<int8_t>>,
67 AccessorView<AccessorTypes::VEC3<uint8_t>>,
68 AccessorView<AccessorTypes::VEC3<int16_t>>,
69 AccessorView<AccessorTypes::VEC3<uint16_t>>,
70 AccessorView<AccessorTypes::VEC3<float>>>
100 template <
typename T>
101 std::optional<glm::dvec3>
107 if (value.normalized()) {
109 CesiumImpl::denormalize(value[
index].value[0]),
110 CesiumImpl::denormalize(value[
index].value[1]),
111 CesiumImpl::denormalize(value[
index].value[2]));
114 value[
index].value[0],
115 value[
index].value[1],
116 value[
index].value[2]);
160 template <
typename T>
161 std::optional<glm::dvec3>
167 if (value.normalized()) {
169 CesiumImpl::denormalize(value[
index].value[0]),
170 CesiumImpl::denormalize(value[
index].value[1]),
171 CesiumImpl::denormalize(value[
index].value[2]));
174 value[
index].value[0],
175 value[
index].value[1],
176 value[
index].value[2]);
212 int32_t featureIdSetIndex);
230 int32_t featureIdSetIndex);
248 return static_cast<int64_t
>(glm::round(value[
index]));
256 return static_cast<int64_t
>(value[
index]);
338 return static_cast<int64_t
>(std::numeric_limits<T>::max());
357 int64_t numFaces = 0;
380 std::array<int64_t, 3> result;
384 result[1] = firstVertex <
vertexCount ? firstVertex : -1;
385 result[2] = firstVertex + 1 <
vertexCount ? firstVertex + 1 : -1;
387 for (int64_t i = 0; i < 3; i++) {
388 int64_t vertexIndex = firstVertex + i;
389 result[
static_cast<size_t>(i)] =
400 template <
typename T>
403 int64_t numFaces = 0;
407 numFaces = value.
size() - 2;
410 numFaces = value.
size() - 2;
414 numFaces = value.
size() / 3;
426 std::array<int64_t, 3> result;
429 result[0] = value[0];
430 result[1] = firstIndex < value.
size()
431 ?
static_cast<int64_t
>(value[firstIndex])
433 result[2] = firstIndex + 1 < value.
size()
434 ?
static_cast<int64_t
>(value[firstIndex + 1])
437 for (int64_t i = 0; i < 3; i++) {
438 int64_t index = firstIndex + i;
439 result[
static_cast<size_t>(i)] =
440 index < value.
size() ?
static_cast<int64_t
>(value[index]) : -1;
470 template <
typename T>
510 int32_t textureCoordinateSetIndex);
526 template <
typename T>
527 std::optional<glm::dvec2>
533 if (value.normalized()) {
535 CesiumImpl::denormalize(value[
index].value[0]),
536 CesiumImpl::denormalize(value[
index].value[1]));
538 return glm::dvec2(value[
index].value[0], value[
index].value[1]);
596 template <
typename T>
597 std::optional<glm::dquat>
603 if (value.normalized()) {
606 CesiumImpl::denormalize(value[
index].value[3]),
607 CesiumImpl::denormalize(value[
index].value[0]),
608 CesiumImpl::denormalize(value[
index].value[1]),
609 CesiumImpl::denormalize(value[
index].value[2]));
613 value[
index].value[3],
614 value[
index].value[0],
615 value[
index].value[1],
616 value[
index].value[2]);
650 int32_t colorSetIndex);
664 template <
typename T>
665 std::optional<glm::dvec4>
671 if (value.normalized()) {
673 CesiumImpl::denormalize(value[
index].value[0]),
674 CesiumImpl::denormalize(value[
index].value[1]),
675 CesiumImpl::denormalize(value[
index].value[2]),
679 value[
index].value[0],
680 value[
index].value[1],
681 value[
index].value[2],
692 template <
typename T>
693 std::optional<glm::dvec4>
699 if (value.normalized()) {
701 CesiumImpl::denormalize(value[
index].value[0]),
702 CesiumImpl::denormalize(value[
index].value[1]),
703 CesiumImpl::denormalize(value[
index].value[2]),
704 CesiumImpl::denormalize(value[
index].value[3]));
707 value[
index].value[0],
708 value[
index].value[1],
709 value[
index].value[2],
710 value[
index].value[3]);
A view on the data of one accessor of a glTF asset.
int64_t size() const noexcept
Returns the size (number of elements) of this accessor.
AccessorViewStatus status() const noexcept
Gets the status of this accessor view.
Classes for working with glTF models.
std::variant< AccessorView< AccessorTypes::VEC3< int8_t > >, AccessorView< AccessorTypes::VEC3< uint8_t > >, AccessorView< AccessorTypes::VEC3< int16_t > >, AccessorView< AccessorTypes::VEC3< uint16_t > >, AccessorView< AccessorTypes::VEC3< float > > > PositionAccessorType
Type definition for all kinds of position (POSITION) accessors.
ColorAccessorType getColorAccessorView(const Model &model, const MeshPrimitive &primitive, int32_t colorSetIndex)
Retrieves an accessor view for the specified color attribute from the given glTF primitive and model....
std::variant< AccessorView< int8_t >, AccessorView< uint8_t >, AccessorView< int16_t >, AccessorView< uint16_t >, AccessorView< uint32_t >, AccessorView< float > > FeatureIdAccessorType
Type definition for all kinds of feature ID (_FEATURE_ID_n) attribute accessors.
std::variant< std::monostate, AccessorView< uint8_t >, AccessorView< uint16_t >, AccessorView< uint32_t > > IndexAccessorType
Type definition for all kinds of index accessors. std::monostate indicates a nonexistent accessor,...
std::variant< AccessorView< AccessorTypes::VEC4< int8_t > >, AccessorView< AccessorTypes::VEC4< uint8_t > >, AccessorView< AccessorTypes::VEC4< int16_t > >, AccessorView< AccessorTypes::VEC4< uint16_t > >, AccessorView< AccessorTypes::VEC4< float > > > QuaternionAccessorType
Type definition for quaternion accessors, as used in ExtMeshGpuInstancing rotations and animation sam...
IndexAccessorType getIndexAccessorView(const Model &model, const MeshPrimitive &primitive)
Retrieves an accessor view for the indices of the given glTF primitive from the model....
QuaternionAccessorType getQuaternionAccessorView(const Model &model, const Accessor &accessor)
Obtains a QuaternionAccessorType from the given Accessor on the given Model.
FeatureIdAccessorType getFeatureIdAccessorView(const Model &model, const MeshPrimitive &primitive, int32_t featureIdSetIndex)
Retrieves an accessor view for the specified feature ID attribute from the given glTF primitive and m...
TexCoordAccessorType getTexCoordAccessorView(const Model &model, const MeshPrimitive &primitive, int32_t textureCoordinateSetIndex)
Retrieves an accessor view for the specified texture coordinate set from the given glTF primitive and...
std::variant< AccessorView< AccessorTypes::VEC3< uint8_t > >, AccessorView< AccessorTypes::VEC3< uint16_t > >, AccessorView< AccessorTypes::VEC3< float > >, AccessorView< AccessorTypes::VEC4< uint8_t > >, AccessorView< AccessorTypes::VEC4< uint16_t > >, AccessorView< AccessorTypes::VEC4< float > > > ColorAccessorType
Type definition for all kinds of color (COLOR_n) accessors.
NormalAccessorType getNormalAccessorView(const Model &model, const MeshPrimitive &primitive)
Retrieves an accessor view for the normal attribute from the given glTF primitive and model....
AccessorViewStatus
Indicates the status of an accessor view.
@ InvalidAccessorIndex
The accessor index does not refer to a valid accessor.
std::variant< AccessorView< AccessorTypes::VEC3< int8_t > >, AccessorView< AccessorTypes::VEC3< int16_t > >, AccessorView< AccessorTypes::VEC3< float > > > NormalAccessorType
Type definition for all kinds of normal (NORMAL) accessors.
std::variant< AccessorView< AccessorTypes::VEC2< int8_t > >, AccessorView< AccessorTypes::VEC2< uint8_t > >, AccessorView< AccessorTypes::VEC2< int16_t > >, AccessorView< AccessorTypes::VEC2< uint16_t > >, AccessorView< AccessorTypes::VEC2< float > > > TexCoordAccessorType
Type definition for all kinds of texture coordinate (TEXCOORD_n) accessors.
PositionAccessorType getPositionAccessorView(const Model &model, const MeshPrimitive &primitive)
Retrieves an accessor view for the position attribute from the given glTF primitive and model....
A 2D vector element for an AccessorView.
A 3D vector element for an AccessorView.
A 4D vector element for an AccessorView.
This class is not meant to be instantiated directly. Use Accessor instead.
Visitor that retrieves the color from the given accessor type as a glm::dvec4.
std::optional< glm::dvec4 > operator()(const AccessorView< AccessorTypes::VEC3< T > > &value)
Attempts to obtain a glm::dvec4 at the given index from an accessor over a vec3. The values will be c...
std::optional< glm::dvec4 > operator()(const AccessorView< AccessorTypes::VEC4< T > > &value)
Attempts to obtain a glm::dvec4 at the given index from an accessor over a vec4. The values will be c...
int64_t index
The index of the color to obtain.
Visitor that retrieves the count of elements in the given accessor type as an int64_t.
int64_t operator()(const AccessorView< T > &value)
Attempts to obtain an element count from an AccessorView.
int64_t operator()(std::monostate)
Attempts to obtain an element count from an empty accessor variant, resulting in 0.
Visitor that retrieves the feature ID from the given accessor type as an int64_t. This should be init...
int64_t operator()(const AccessorView< float > &value)
Attempts to obtain a feature ID from an AccessorView over float values, returning the float value rou...
int64_t operator()(const AccessorView< T > &value)
Attempts to obtain a feature ID from an AccessorView.
int64_t index
The index of the vertex whose feature ID is being queried.
Visitor that retrieves the vertex index from the given accessor type as an int64_t....
int64_t operator()(const CesiumGltf::AccessorView< T > &value)
Attempts to obtain a vertex index from an CesiumGltf::AccessorView.
int64_t index
The index of the vertex index within the accessor itself.
int64_t operator()(std::monostate)
Attempts to obtain a vertex index from an empty IndexAccessorType, resulting in -1.
Visitor that retrieves the vertex indices from the given accessor type corresponding to a given face ...
std::array< int64_t, 3 > operator()(const AccessorView< T > &value)
Attempts to obtain the indices for the given face from an AccessorView, using the view's size and con...
int64_t faceIndex
The index of the face to obtain indices for.
std::array< int64_t, 3 > operator()(std::monostate)
Attempts to obtain the indices for the given face from an empty accessor variant, using the vertexCou...
int64_t vertexCount
The total number of vertices in the data being accessed.
int32_t primitiveMode
The MeshPrimitive::Mode of the data being accessed.
Returns the maximum possible index value for the given IndexAccessorType.
int64_t operator()(const AccessorView< T > &)
Attempts to obtain a maximum index value from an AccessorView.
int64_t operator()(std::monostate)
Attempts to obtain a maximum index value from an empty IndexAccessorType, resulting in -1.
static constexpr int32_t TRIANGLES
TRIANGLES (4)
static constexpr int32_t TRIANGLE_FAN
TRIANGLE_FAN (6)
static constexpr int32_t TRIANGLE_STRIP
TRIANGLE_STRIP (5)
Geometry to be rendered with the given material.
This class is not meant to be instantiated directly. Use Model instead.
A node in the node hierarchy. When the node contains skin, all mesh.primitives MUST contain JOINTS_0 ...
Visitor that retrieves the normal from the given accessor type as a glm::dvec3.
std::optional< glm::dvec3 > operator()(const AccessorView< AccessorTypes::VEC3< T > > &value)
Attempts to obtain a glm::dvec3 at the given index from an accessor over a vec3. The values will be c...
int64_t index
The index of the normal to obtain.
Visitor that returns the number of indices contained in an IndexAccessorType variant.
int64_t operator()(std::monostate)
Attempts to obtain a number of indices from an empty IndexAccessorType, resulting in 0.
int64_t operator()(const AccessorView< T > &value)
Attempts to obtain a number of indices from an AccessorView.
Visitor that retrieves the position from the given accessor type as a glm::dvec3.
int64_t index
The index of the position to obtain.
std::optional< glm::dvec3 > operator()(const AccessorView< AccessorTypes::VEC3< T > > &value)
Attempts to obtain a glm::dvec3 at the given index from an accessor over a vec3. The values will be c...
Visitor that retrieves the quaternion from the given accessor type as a glm::dquat.
std::optional< glm::dquat > operator()(const AccessorView< AccessorTypes::VEC4< T > > &value)
Attempts to obtain a glm::dquat at the given index from an accessor over a vec4. The values will be c...
int64_t index
The index of the quaternion to obtain.
Visitor that retrieves the status from the given accessor. Returns an invalid status for a std::monos...
AccessorViewStatus operator()(std::monostate)
Attempts to obtain an AccessorViewStatus from an empty accessor variant, resulting in AccessorViewSta...
AccessorViewStatus operator()(const AccessorView< T > &value)
Attempts to obtain an AccessorViewStatus from an AccessorView.
Visitor that retrieves the texture coordinates from the given accessor type as a glm::dvec2....
int64_t index
The index of texcoords to obtain.
std::optional< glm::dvec2 > operator()(const AccessorView< AccessorTypes::VEC2< T > > &value)
Attempts to obtain a glm::dvec2 at the given index from an accessor over a vec2. The values will be c...