VTK  9.3.0
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 
25 VTK_ABI_NAMESPACE_BEGIN
26 class vtkResourceStream;
27 class vtkURILoader;
28 VTK_ABI_NAMESPACE_END
29 
30 namespace vtkGLTFUtils
31 {
32 VTK_ABI_NAMESPACE_BEGIN
33 using ChunkInfoType = std::pair<std::string, uint32_t>;
34 // Binary glTF constants
35 static constexpr uint32_t GLBWordSize = 4;
36 static constexpr uint32_t GLBHeaderSize = 12;
37 static constexpr uint32_t GLBChunkHeaderSize = 8;
38 static constexpr uint32_t GLBVersion = 2;
39 
45 bool ValidateGLBFile(const std::string& magic, uint32_t version, uint32_t fileLength,
46  std::vector<vtkGLTFUtils::ChunkInfoType> chunkInfo);
47 
51 bool ExtractGLBFileInformation(vtkResourceStream* stream, uint32_t& version, uint32_t& fileLength,
52  std::vector<vtkGLTFUtils::ChunkInfoType>& chunkInfo);
53 
57 bool GetIntValue(const nlohmann::json& root, const std::string& key, int& value);
58 
62 bool GetUIntValue(const nlohmann::json& root, const std::string& key, unsigned int& value);
63 
67 bool GetDoubleValue(const nlohmann::json& root, const std::string& key, double& value);
68 
72 bool GetStringValue(const nlohmann::json& root, const std::string& key, std::string& value);
73 
77 bool GetBoolValue(const nlohmann::json& root, const std::string& key, bool& value);
78 
82 bool 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 
93 bool GetFloatArray(const nlohmann::json& root, const std::string& key, std::vector<float>& value);
94 
98 bool GetDoubleArray(const nlohmann::json& root, const std::string& key, std::vector<double>& value);
99 
103 bool CheckVersion(const nlohmann::json& glTFAsset);
104 
109  const std::string& uri, vtkURILoader* loader, std::vector<char>& buffer, size_t bufferSize);
110 
111 VTK_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.
Definition: vtkURILoader.h:100
bool ExtractGLBFileInformation(vtkResourceStream *stream, uint32_t &version, uint32_t &fileLength, std::vector< vtkGLTFUtils::ChunkInfoType > &chunkInfo)
Extract all header information from a binary glTF file.
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
Definition: vtkGLTFUtils.h:35
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
Definition: vtkGLTFUtils.h:37
static constexpr uint32_t GLBVersion
Definition: vtkGLTFUtils.h:38
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 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
Definition: vtkGLTFUtils.h:36
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
Definition: vtkGLTFUtils.h:33
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.
@ key
Definition: vtkX3D.h:257
@ value
Definition: vtkX3D.h:220
@ version
Definition: vtkX3D.h:526
@ string
Definition: vtkX3D.h:490