cesium-native 0.43.0
Loading...
Searching...
No Matches
GltfConverterUtility.h
1#pragma once
2
3#include <Cesium3DTilesContent/GltfConverters.h>
4#include <CesiumAsync/IAssetAccessor.h>
5#include <CesiumAsync/IAssetRequest.h>
6#include <CesiumGltf/AccessorView.h>
7#include <CesiumGltf/PropertyTransformations.h>
8#include <CesiumUtility/ErrorList.h>
9
10#include <glm/fwd.hpp>
11#include <rapidjson/document.h>
12
13#include <cstdint>
14#include <optional>
15#include <vector>
16
17namespace CesiumGltf {
18struct Model;
19struct Buffer;
20} // namespace CesiumGltf
21
22namespace Cesium3DTilesContent {
23
24namespace GltfConverterUtility {
25std::optional<uint32_t> parseOffsetForSemantic(
26 const rapidjson::Document& document,
27 const char* semantic,
28 CesiumUtility::ErrorList& errorList);
29
30typedef bool (rapidjson::Value::*ValuePredicate)() const;
31
32template <typename T> bool isValue(const rapidjson::Value& value);
33template <typename T> T getValue(const rapidjson::Value& value);
34
35template <typename T>
36std::optional<T> getOptional(const rapidjson::Value& value) {
37 if (isValue<T>(value)) {
38 return std::make_optional(getValue<T>(value));
39 }
40 return {};
41}
42
43template <typename T>
44std::optional<T>
45getValue(const rapidjson::Document& document, const char* semantic) {
46 const auto valueIt = document.FindMember(semantic);
47 if (valueIt == document.MemberEnd() || !isValue<T>(valueIt->value)) {
48 return {};
49 }
50 return std::make_optional(getValue<T>(valueIt->value));
51}
52
53template <> inline bool isValue<bool>(const rapidjson::Value& value) {
54 return value.IsBool();
55}
56
57template <> inline bool getValue<bool>(const rapidjson::Value& value) {
58 return value.GetBool();
59}
60
61template <> inline bool isValue<uint32_t>(const rapidjson::Value& value) {
62 return value.IsUint();
63}
64
65template <> inline uint32_t getValue<uint32_t>(const rapidjson::Value& value) {
66 return value.GetUint();
67}
68
69bool validateJsonArrayValues(
70 const rapidjson::Value& arrayValue,
71 uint32_t expectedLength,
72 ValuePredicate predicate);
73
74std::optional<glm::dvec3>
75parseArrayValueDVec3(const rapidjson::Value& arrayValue);
76
77std::optional<glm::dvec3>
78parseArrayValueDVec3(const rapidjson::Document& document, const char* name);
79
80int32_t
81createBufferInGltf(CesiumGltf::Model& gltf, std::vector<std::byte> buffer = {});
82
83int32_t createBufferViewInGltf(
85 const int32_t bufferId,
86 const int64_t byteLength,
87 const int64_t byteStride);
88
89int32_t createAccessorInGltf(
91 const int32_t bufferViewId,
92 const int32_t componentType,
93 const int64_t count,
94 const std::string type);
95
103void applyRtcToNodes(CesiumGltf::Model& gltf, const glm::dvec3& rtc);
104
105template <typename GlmType, typename GLTFType>
106GlmType toGlm(const GLTFType& gltfVal);
107
108template <typename GlmType, typename ComponentType>
109GlmType toGlm(const CesiumGltf::AccessorTypes::VEC3<ComponentType>& gltfVal) {
110 return GlmType(gltfVal.value[0], gltfVal.value[1], gltfVal.value[2]);
111}
112
113template <typename GlmType, typename ComponentType>
114GlmType
115toGlmQuat(const CesiumGltf::AccessorTypes::VEC4<ComponentType>& gltfVal) {
116 if constexpr (std::is_same<ComponentType, float>()) {
117 return GlmType(
118 gltfVal.value[3],
119 gltfVal.value[0],
120 gltfVal.value[1],
121 gltfVal.value[2]);
122 } else {
123 return GlmType(
124 CesiumGltf::normalize(gltfVal.value[3]),
125 CesiumGltf::normalize(gltfVal.value[0]),
126 CesiumGltf::normalize(gltfVal.value[1]),
127 CesiumGltf::normalize(gltfVal.value[2]));
128 }
129}
130
131} // namespace GltfConverterUtility
132} // namespace Cesium3DTilesContent
Classes that support loading and converting 3D Tiles tile content.
Classes for working with glTF models.
double normalize(T value)
Normalizes the given value between [0, 1] if unsigned or [-1, 1] if signed, based on the type's maxim...
A 3D vector element for an AccessorView.
T value[3]
The component values of this element.
A 4D vector element for an AccessorView.
T value[4]
The component values of this element.
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
The container to store the error and warning list when loading a tile or glTF content.
Definition ErrorList.h:17