3 #include "AccessorView.h"
5 #include <CesiumGltf/MeshPrimitive.h>
7 #include <glm/common.hpp>
17 int64_t operator()(std::monostate) {
return 0; }
19 template <
typename T> int64_t operator()(
const AccessorView<T>& value) {
85 int32_t featureIdAttributeIndex);
96 int32_t featureIdAttributeIndex);
108 if (index < 0 || index >= value.
size()) {
111 return static_cast<int64_t
>(glm::round(value[index]));
114 template <
typename T> int64_t operator()(
const AccessorView<T>& value) {
115 if (index < 0 || index >= value.
size()) {
118 return static_cast<int64_t
>(value[index]);
129 typedef std::variant<
155 std::array<int64_t, 3> operator()(std::monostate) {
156 int64_t firstVertex = faceIndex;
157 int64_t numFaces = 0;
159 switch (primitiveMode) {
160 case MeshPrimitive::Mode::TRIANGLE_STRIP:
161 numFaces = vertexCount - 2;
163 case MeshPrimitive::Mode::TRIANGLE_FAN:
164 numFaces = vertexCount - 2;
167 case MeshPrimitive::Mode::TRIANGLES:
168 numFaces = vertexCount / 3;
176 if (faceIndex < 0 || faceIndex >= numFaces) {
180 std::array<int64_t, 3> result;
182 if (primitiveMode == MeshPrimitive::Mode::TRIANGLE_FAN) {
184 result[1] = firstVertex < vertexCount ? firstVertex : -1;
185 result[2] = firstVertex + 1 < vertexCount ? firstVertex + 1 : -1;
187 for (int64_t i = 0; i < 3; i++) {
188 int64_t vertexIndex = firstVertex + i;
189 result[i] = vertexIndex < vertexCount ? vertexIndex : -1;
196 template <
typename T>
198 int64_t firstIndex = faceIndex;
199 int64_t numFaces = 0;
201 switch (primitiveMode) {
202 case MeshPrimitive::Mode::TRIANGLE_STRIP:
203 numFaces = value.
size() - 2;
205 case MeshPrimitive::Mode::TRIANGLE_FAN:
206 numFaces = value.
size() - 2;
209 case MeshPrimitive::Mode::TRIANGLES:
210 numFaces = value.
size() / 3;
218 if (faceIndex < 0 || faceIndex >= numFaces) {
222 std::array<int64_t, 3> result;
224 if (primitiveMode == MeshPrimitive::Mode::TRIANGLE_FAN) {
225 result[0] = value[0];
226 result[1] = firstIndex < value.
size() ? value[firstIndex] : -1;
227 result[2] = firstIndex + 1 < value.
size() ? value[firstIndex + 1] : -1;
229 for (int64_t i = 0; i < 3; i++) {
230 int64_t index = firstIndex + i;
231 result[i] = index < value.
size() ? value[index] : -1;
240 int32_t primitiveMode;
252 int64_t operator()(std::monostate) {
return -1; }
254 template <
typename T>
256 if (index < 0 || index >= value.
size()) {
269 typedef std::variant<
283 int32_t textureCoordinateSetIndex);
293 std::optional<glm::dvec2>
295 if (index < 0 || index >= value.size()) {
299 return glm::dvec2(value[index].value[0], value[index].value[1]);
302 template <
typename T>
303 std::optional<glm::dvec2>
305 if (index < 0 || index >= value.size()) {
309 double u =
static_cast<double>(value[index].value[0]);
310 double v =
static_cast<double>(value[index].value[1]);
313 u /= std::numeric_limits<T>::max();
314 v /= std::numeric_limits<T>::max();
316 return glm::dvec2(u, v);
326 typedef std::variant<
335 getQuaternionAccessorView(
const Model& model,
const Accessor* accessor);
338 getQuaternionAccessorView(
const Model& model, int32_t accessorIndex);
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.
AccessorView< AccessorTypes::VEC3< float > > NormalAccessorType
std::variant< AccessorView< int8_t >, AccessorView< uint8_t >, AccessorView< int16_t >, AccessorView< uint16_t >, AccessorView< uint32_t >, AccessorView< float > > FeatureIdAccessorType
std::variant< std::monostate, AccessorView< uint8_t >, AccessorView< uint16_t >, AccessorView< uint32_t > > IndexAccessorType
std::variant< AccessorView< AccessorTypes::VEC4< uint8_t > >, AccessorView< AccessorTypes::VEC4< int8_t > >, AccessorView< AccessorTypes::VEC4< uint16_t > >, AccessorView< AccessorTypes::VEC4< int16_t > >, AccessorView< AccessorTypes::VEC4< float > > > QuaternionAccessorType
IndexAccessorType getIndexAccessorView(const Model &model, const MeshPrimitive &primitive)
FeatureIdAccessorType getFeatureIdAccessorView(const Model &model, const MeshPrimitive &primitive, int32_t featureIdAttributeIndex)
TexCoordAccessorType getTexCoordAccessorView(const Model &model, const MeshPrimitive &primitive, int32_t textureCoordinateSetIndex)
NormalAccessorType getNormalAccessorView(const Model &model, const MeshPrimitive &primitive)
AccessorViewStatus
Indicates the status of an accessor view.
@ InvalidAccessorIndex
The accessor index does not refer to a valid accessor.
std::variant< AccessorView< AccessorTypes::VEC2< uint8_t > >, AccessorView< AccessorTypes::VEC2< uint16_t > >, AccessorView< AccessorTypes::VEC2< float > > > TexCoordAccessorType
AccessorView< AccessorTypes::VEC3< float > > PositionAccessorType
PositionAccessorType getPositionAccessorView(const Model &model, const MeshPrimitive &primitive)
A 2D vector element for an AccessorView.
A typed view into a buffer view that contains raw binary data.
Visitor that retrieves the count of elements in the given accessor type as an int64_t.
Geometry to be rendered with the given material.
The root object for a glTF asset.
A node in the node hierarchy. When the node contains skin, all mesh.primitives MUST contain JOINTS_0 ...
Visitor that retrieves the status from the given accessor. Returns an invalid status for a std::monos...