VTK  9.4.20241031
vtkGLTFUtils.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
14#ifndef vtkGLTFUtils_h
15#define vtkGLTFUtils_h
16
17#include "vtkABINamespace.h"
18
19#include <vtk_nlohmannjson.h>
20#include VTK_NLOHMANN_JSON(json.hpp)
21
22#include <string> // For string
23#include <vector> // For vector
24
25VTK_ABI_NAMESPACE_BEGIN
27class vtkURILoader;
28VTK_ABI_NAMESPACE_END
29
30namespace vtkGLTFUtils
31{
32VTK_ABI_NAMESPACE_BEGIN
33using ChunkInfoType = std::pair<std::string, uint32_t>;
34// Binary glTF constants
35static constexpr uint32_t GLBWordSize = 4;
36static constexpr uint32_t GLBHeaderSize = 12;
37static constexpr uint32_t GLBChunkHeaderSize = 8;
38static constexpr uint32_t GLBVersion = 2;
39
45bool ValidateGLBFile(const std::string& magic, uint32_t version, uint32_t fileLength,
46 std::vector<vtkGLTFUtils::ChunkInfoType> chunkInfo);
47
51bool ExtractGLBFileInformation(vtkResourceStream* stream, uint32_t& version, uint32_t& fileLength,
52 uint32_t glbStart, std::vector<vtkGLTFUtils::ChunkInfoType>& chunkInfo);
53
57bool GetIntValue(const nlohmann::json& root, const std::string& key, int& value);
58
62bool GetUIntValue(const nlohmann::json& root, const std::string& key, unsigned int& value);
63
67bool GetDoubleValue(const nlohmann::json& root, const std::string& key, double& value);
68
72bool GetStringValue(const nlohmann::json& root, const std::string& key, std::string& value);
73
77bool GetBoolValue(const nlohmann::json& root, const std::string& key, bool& value);
78
82bool GetIntArray(const nlohmann::json& root, const std::string& key, std::vector<int>& value);
83
88 const nlohmann::json& root, const std::string& key, std::vector<unsigned int>& value);
89
93bool GetFloatArray(const nlohmann::json& root, const std::string& key, std::vector<float>& value);
94
98bool GetDoubleArray(const nlohmann::json& root, const std::string& key, std::vector<double>& value);
99
103bool CheckVersion(const nlohmann::json& glTFAsset);
104
109 const std::string& uri, vtkURILoader* loader, std::vector<char>& buffer, size_t bufferSize);
110
111VTK_ABI_NAMESPACE_END
112}
113
114#endif
115
116// VTK-HeaderTest-Exclude: vtkGLTFUtils.h
Abstract class used for custom streams.
Helper class for readers and importer that need to load more than one resource.
bool GetDoubleValue(const nlohmann::json &root, const std::string &key, double &value)
Get double value from Json variable, with existence and type checks.
bool GetUIntValue(const nlohmann::json &root, const std::string &key, unsigned int &value)
Get int value from Json variable, with existence and type checks.
static constexpr uint32_t GLBWordSize
bool GetIntArray(const nlohmann::json &root, const std::string &key, std::vector< int > &value)
Get int array from Json variable, with existence and type checks.
bool CheckVersion(const nlohmann::json &glTFAsset)
Check document version.
static constexpr uint32_t GLBChunkHeaderSize
static constexpr uint32_t GLBVersion
bool ValidateGLBFile(const std::string &magic, uint32_t version, uint32_t fileLength, std::vector< vtkGLTFUtils::ChunkInfoType > chunkInfo)
Checks various binary glTF elements for validity.
bool GetUIntArray(const nlohmann::json &root, const std::string &key, std::vector< unsigned int > &value)
Get int array from Json variable, with existence and type checks.
bool ExtractGLBFileInformation(vtkResourceStream *stream, uint32_t &version, uint32_t &fileLength, uint32_t glbStart, std::vector< vtkGLTFUtils::ChunkInfoType > &chunkInfo)
Extract all header information from a binary glTF file.
bool GetBinaryBufferFromUri(const std::string &uri, vtkURILoader *loader, std::vector< char > &buffer, size_t bufferSize)
Load binary buffer from uri information.
bool GetFloatArray(const nlohmann::json &root, const std::string &key, std::vector< float > &value)
Get float array from Json variable, with existence and type checks.
bool GetDoubleArray(const nlohmann::json &root, const std::string &key, std::vector< double > &value)
Get double array from Json variable, with existence and type checks.
static constexpr uint32_t GLBHeaderSize
bool GetIntValue(const nlohmann::json &root, const std::string &key, int &value)
Get int value from Json variable, with existence and type checks.
std::pair< std::string, uint32_t > ChunkInfoType
bool GetStringValue(const nlohmann::json &root, const std::string &key, std::string &value)
Get string value from Json variable, with existence and type checks.
bool GetBoolValue(const nlohmann::json &root, const std::string &key, bool &value)
Get bool value from Json variable, with existence and type checks.