VTK  9.2.6
vtkGLTFUtils.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkGLTFUtils.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
26 #ifndef vtkGLTFUtils_h
27 #define vtkGLTFUtils_h
28 
29 #include <vtk_nlohmannjson.h>
30 #include VTK_NLOHMANN_JSON(json.hpp)
31 
32 #include <string> // For string
33 #include <vector> // For vector
34 
35 namespace vtkGLTFUtils
36 {
37 using ChunkInfoType = std::pair<std::string, uint32_t>;
38 // Binary glTF constants
39 const uint32_t GLBWordSize = 4;
40 const uint32_t GLBHeaderSize = 12;
41 const uint32_t GLBChunkHeaderSize = 8;
42 const uint32_t GLBVersion = 2;
43 
49 bool ValidateGLBFile(const std::string& magic, uint32_t version, uint32_t fileLength,
50  std::vector<vtkGLTFUtils::ChunkInfoType> chunkInfo);
51 
55 bool ExtractGLBFileInformation(const std::string& fileName, std::string& magic, uint32_t& version,
56  uint32_t& fileLength, std::vector<vtkGLTFUtils::ChunkInfoType>& chunkInfo);
57 
61 bool GetIntValue(const nlohmann::json& root, const std::string& key, int& value);
62 
66 bool GetUIntValue(const nlohmann::json& root, const std::string& key, unsigned int& value);
67 
71 bool GetDoubleValue(const nlohmann::json& root, const std::string& key, double& value);
72 
76 bool GetStringValue(const nlohmann::json& root, const std::string& key, std::string& value);
77 
81 bool GetBoolValue(const nlohmann::json& root, const std::string& key, bool& value);
82 
86 bool GetIntArray(const nlohmann::json& root, const std::string& key, std::vector<int>& value);
87 
91 bool GetUIntArray(
92  const nlohmann::json& root, const std::string& key, std::vector<unsigned int>& value);
93 
97 bool GetFloatArray(const nlohmann::json& root, const std::string& key, std::vector<float>& value);
98 
102 bool GetDoubleArray(const nlohmann::json& root, const std::string& key, std::vector<double>& value);
103 
107 bool CheckVersion(const nlohmann::json& glTFAsset);
108 
113 std::string GetResourceFullPath(const std::string& resourcePath, const std::string& glTFFilePath);
114 
118 bool GetBinaryBufferFromUri(const std::string& uri, const std::string& glTFFileName,
119  std::vector<char>& buffer, size_t bufferSize);
120 
125 }
126 
127 #endif
128 
129 // VTK-HeaderTest-Exclude: vtkGLTFUtils.h
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.
Helper functions for glTF parsing and validation.
Definition: vtkGLTFUtils.h:35
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 CheckVersion(const nlohmann::json &glTFAsset)
Check document version.
bool GetBoolValue(const nlohmann::json &root, const std::string &key, bool &value)
Get bool value from Json variable, with existence and type checks.
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 GetBinaryBufferFromUri(const std::string &uri, const std::string &glTFFileName, std::vector< char > &buffer, size_t bufferSize)
Load binary buffer from uri information.
const uint32_t GLBVersion
Definition: vtkGLTFUtils.h:42
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.
const uint32_t GLBWordSize
Definition: vtkGLTFUtils.h:39
std::string GetDataUriMimeType(const std::string &uri)
Extract MIME-Type from data-uri.
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.
std::pair< std::string, uint32_t > ChunkInfoType
Definition: vtkGLTFUtils.h:37
bool GetIntValue(const nlohmann::json &root, const std::string &key, int &value)
Get int value from Json variable, with existence and type checks.
const uint32_t GLBHeaderSize
Definition: vtkGLTFUtils.h:40
std::string GetResourceFullPath(const std::string &resourcePath, const std::string &glTFFilePath)
Compute the path to a resource from its path as specified in the glTF file, and the glTF file's path...
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 GetStringValue(const nlohmann::json &root, const std::string &key, std::string &value)
Get string value from Json variable, with existence and type checks.
const uint32_t GLBChunkHeaderSize
Definition: vtkGLTFUtils.h:41
bool ExtractGLBFileInformation(const std::string &fileName, std::string &magic, uint32_t &version, uint32_t &fileLength, std::vector< vtkGLTFUtils::ChunkInfoType > &chunkInfo)
Extract all header information from a binary glTF file.