VTK  9.1.0
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_jsoncpp_fwd.h" // For Json forward declaration
30 
31 #include <string> // For string
32 #include <vector> // For vector
33 
34 namespace vtkGLTFUtils
35 {
36 using ChunkInfoType = std::pair<std::string, uint32_t>;
37 // Binary glTF constants
38 const uint32_t GLBWordSize = 4;
39 const uint32_t GLBHeaderSize = 12;
40 const uint32_t GLBChunkHeaderSize = 8;
41 const uint32_t GLBVersion = 2;
42 
48 bool ValidateGLBFile(const std::string& magic, uint32_t version, uint32_t fileLength,
49  std::vector<vtkGLTFUtils::ChunkInfoType> chunkInfo);
50 
54 bool ExtractGLBFileInformation(const std::string& fileName, std::string& magic, uint32_t& version,
55  uint32_t& fileLength, std::vector<vtkGLTFUtils::ChunkInfoType>& chunkInfo);
56 
60 bool GetIntValue(const Json::Value& root, int& value);
61 
65 bool GetUIntValue(const Json::Value& root, unsigned int& value);
66 
70 bool GetDoubleValue(const Json::Value& root, double& value);
71 
75 bool GetStringValue(const Json::Value& root, std::string& value);
76 
80 bool GetBoolValue(const Json::Value& root, bool& value);
81 
85 bool GetIntArray(const Json::Value& root, std::vector<int>& value);
86 
90 bool GetUIntArray(const Json::Value& root, std::vector<unsigned int>& value);
91 
95 bool GetFloatArray(const Json::Value& root, std::vector<float>& value);
96 
100 bool GetDoubleArray(const Json::Value& root, std::vector<double>& value);
101 
105 bool CheckVersion(const Json::Value& glTFAsset);
106 
111 std::string GetResourceFullPath(const std::string& resourcePath, const std::string& glTFFilePath);
112 
116 bool GetBinaryBufferFromUri(const std::string& uri, const std::string& glTFFileName,
117  std::vector<char>& buffer, size_t bufferSize);
118 
123 }
124 
125 #endif
126 
127 // VTK-HeaderTest-Exclude: vtkGLTFUtils.h
Helper functions for glTF parsing and validation.
Definition: vtkGLTFUtils.h:35
std::string GetDataUriMimeType(const std::string &uri)
Extract MIME-Type from data-uri.
const uint32_t GLBChunkHeaderSize
Definition: vtkGLTFUtils.h:40
bool GetFloatArray(const Json::Value &root, std::vector< float > &value)
Get float array from Json variable, with existence and type checks.
const uint32_t GLBHeaderSize
Definition: vtkGLTFUtils.h:39
bool GetIntArray(const Json::Value &root, std::vector< int > &value)
Get int array from Json variable, with existence and type checks.
bool GetUIntArray(const Json::Value &root, std::vector< unsigned int > &value)
Get int array from Json variable, with existence and type checks.
const uint32_t GLBVersion
Definition: vtkGLTFUtils.h:41
const uint32_t GLBWordSize
Definition: vtkGLTFUtils.h:38
bool GetBoolValue(const Json::Value &root, 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 CheckVersion(const Json::Value &glTFAsset)
Check document version.
bool GetUIntValue(const Json::Value &root, unsigned int &value)
Get int value from Json variable, with existence and type checks.
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 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.
bool GetBinaryBufferFromUri(const std::string &uri, const std::string &glTFFileName, std::vector< char > &buffer, size_t bufferSize)
Load binary buffer from uri information.
bool GetStringValue(const Json::Value &root, std::string &value)
Get string value from Json variable, with existence and type checks.
std::pair< std::string, uint32_t > ChunkInfoType
Definition: vtkGLTFUtils.h:36
bool GetDoubleValue(const Json::Value &root, double &value)
Get double value from Json variable, with existence and type checks.
bool GetDoubleArray(const Json::Value &root, std::vector< double > &value)
Get double array from Json variable, with existence and type checks.
bool GetIntValue(const Json::Value &root, int &value)
Get int value from Json variable, with existence and type checks.
@ value
Definition: vtkX3D.h:226
@ version
Definition: vtkX3D.h:532
@ string
Definition: vtkX3D.h:496