File: vtkGLTFDocumentLoaderInternals.h

package info (click to toggle)
vtk9 9.3.0%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 267,116 kB
  • sloc: cpp: 2,195,914; ansic: 285,452; python: 104,858; sh: 4,061; yacc: 4,035; java: 3,977; xml: 2,771; perl: 2,189; lex: 1,762; objc: 153; makefile: 150; javascript: 90; tcl: 59
file content (202 lines) | stat: -rw-r--r-- 7,636 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause

/**
 * @class vtkGLTFDocumentLoaderInternals
 * @brief Internal class for vtkGLTFDocumentLoader
 *
 * This class provides json-related methods for vtkGLTFDocumentLoader
 */

#ifndef vtkGLTFDocumentLoaderInternals_h
#define vtkGLTFDocumentLoaderInternals_h

#include "vtkGLTFDocumentLoader.h" // For vtkGLTFDocumentLoader
#include <vtk_nlohmannjson.h>
#include VTK_NLOHMANN_JSON(json.hpp)

#include <string> // For string
#include <vector> // For vector

VTK_ABI_NAMESPACE_BEGIN

class vtkGLTFDocumentLoaderInternals
{
public:
  vtkGLTFDocumentLoaderInternals() = default;

  /**
   * Reset internal Model struct, and serialize glTF metadata (all json information) into it.
   * Fill usedExtensions vector with the list of used and supported extensions in the glTF file.
   * To load buffers, use LoadModelData
   */
  bool LoadModelMetaData(std::vector<std::string>& extensionsUsedByLoader);

  /**
   * Reads the model's buffer metadata, then uses it to load all buffers into the model.
   */
  bool LoadBuffers(bool firstBufferIsGLB);

  vtkGLTFDocumentLoader* Self = nullptr;

  static const unsigned short GL_POINTS = 0x0000;
  static const unsigned short GL_LINES = 0x0001;
  static const unsigned short GL_LINE_LOOP = 0x0002;
  static const unsigned short GL_LINE_STRIP = 0x0003;
  static const unsigned short GL_TRIANGLES = 0x0004;
  static const unsigned short GL_TRIANGLE_STRIP = 0x0005;
  static const unsigned short GL_TRIANGLE_FAN = 0x0006;

private:
  /**
   * Load node-level extension metadata into the Node::Extensions struct.
   */
  bool LoadNodeExtensions(
    const nlohmann::json& root, vtkGLTFDocumentLoader::Node::Extensions& nodeExtensions);

  /**
   * Load root-level extension metadata into the Extensions struct.
   */
  bool LoadExtensions(const nlohmann::json& root, vtkGLTFDocumentLoader::Extensions& extensions);

  /**
   * Reads a Json value describing a glTF buffer object, then uses this information to load the
   * corresponding binary buffer into an std::vector<char> array.
   * Needs to know the .glTF file's location in order to interpret relative paths.
   */
  bool LoadBuffer(const nlohmann::json& root, std::vector<char>& buffer);

  /**
   * Load a glTF file and parse it into a Json value. File extension can be either .gltf
   * or .glb. In case of a binary glTF file, only the Json part will be read.
   */
  bool LoadFileMetaData(nlohmann::json& gltfRoot);

  /**
   * Populate a Skin struct with data from a Json variable describing the object.
   * This method only loads metadata from the json file, it does not load the bind matrices from the
   * buffer.
   */
  bool LoadSkin(const nlohmann::json& root, vtkGLTFDocumentLoader::Skin& skin);

  /**
   * Populate a BufferView struct with data from a Json variable describing the object.
   */
  bool LoadBufferView(const nlohmann::json& root, vtkGLTFDocumentLoader::BufferView& bufferView);

  /**
   * Populate a Sparse struct with data from a Json variable describing the object.
   */
  bool LoadSparse(const nlohmann::json& root, vtkGLTFDocumentLoader::Accessor::Sparse& sparse);

  /**
   * Sets an Accessor's min and max fields with values from a Json variable.
   */
  bool LoadAccessorBounds(const nlohmann::json& root, vtkGLTFDocumentLoader::Accessor& accessor);

  /**
   * Populate a Camera struct with data from a Json variable describing the object.
   */
  bool LoadCamera(const nlohmann::json& root, vtkGLTFDocumentLoader::Camera& camera);

  /**
   * Populate an Accessor struct with data from a Json variable describing the object.
   */
  bool LoadAccessor(const nlohmann::json& root, vtkGLTFDocumentLoader::Accessor& accessor);

  /**
   * Populate a Primitive struct with data from a Json variable describing the object.
   * This method only loads integer indices to accessors, it does not extract any value from a
   * buffer.
   */
  bool LoadPrimitive(const nlohmann::json& root, vtkGLTFDocumentLoader::Primitive& primitive);

  /**
   * Populate a Mesh structure with data from a Json variable describing the object.
   */
  bool LoadMesh(const nlohmann::json& root, vtkGLTFDocumentLoader::Mesh& mesh);

  /**
   * Populate a TextureInfo struct with data from a Json variable describing the object.
   */
  bool LoadTextureInfo(const nlohmann::json& root, vtkGLTFDocumentLoader::TextureInfo& textureInfo);

  /**
   * Populate a Material struct with data from a Json variable describing the object.
   */
  bool LoadMaterial(const nlohmann::json& root, vtkGLTFDocumentLoader::Material& material);

  /**
   * Populate an Animation struct with data from a Json variable describing the object.
   * This function only loads indices to the keyframe accessors, not the data they contain.
   */
  bool LoadAnimation(const nlohmann::json& root, vtkGLTFDocumentLoader::Animation& animation);

  /**
   * Populate a Scene struct with data from a Json variable describing the object.
   * Does not check for node's existence.
   */
  bool LoadScene(const nlohmann::json& root, vtkGLTFDocumentLoader::Scene& scene);

  /**
   * Populate a Node struct with data from a Json variable describing the object.
   * Does not check for the node's children's existence.
   */
  bool LoadNode(const nlohmann::json& root, vtkGLTFDocumentLoader::Node& node);

  /**
   * Populate an Image struct with data from a Json variable describing the object.
   * This loads a glTF object, not an actual image file.
   */
  bool LoadImage(const nlohmann::json& root, vtkGLTFDocumentLoader::Image& image);

  /**
   * Populate a Texture struct with data from a Json variable describing the object.
   * This loads a glTF object from a Json value, no files are loaded by this function.
   * Discounting the 'name' field, glTF texture objects contain two indices: one to an image
   * object (the object that references to an actual image file), and one to a sampler
   * object (which specifies filter and wrapping options for a texture).
   */
  bool LoadTexture(const nlohmann::json& root, vtkGLTFDocumentLoader::Texture& texture);

  /**
   * Populate a Sampler struct with data from a Json variable describing the object.
   */
  bool LoadSampler(const nlohmann::json& root, vtkGLTFDocumentLoader::Sampler& sampler);

  /**
   * Associates an accessor type string to the corresponding enum value.
   */
  vtkGLTFDocumentLoader::AccessorType AccessorTypeStringToEnum(std::string typeName);

  /**
   * Associate a material's alphaMode string to the corresponding enum value.
   */
  vtkGLTFDocumentLoader::Material::AlphaModeType MaterialAlphaModeStringToEnum(
    std::string alphaModeString);

  /**
   * Load node-specific KHR_lights_punctual metadata into the Node::Extensions::KHRLightsPunctual
   * struct (load light indices).
   */
  bool LoadKHRLightsPunctualNodeExtension(const nlohmann::json& root,
    vtkGLTFDocumentLoader::Node::Extensions::KHRLightsPunctual& lightsExtension);

  /**
   * Load root-level KHR_lights_punctual metadata into the Extensions::KHRLightsPunctual struct
   * (load all lights).
   */
  bool LoadKHRLightsPunctualExtension(
    const nlohmann::json& root, vtkGLTFDocumentLoader::Extensions::KHRLightsPunctual& lights);

  /**
   * Load a KHR_lights_punctual light object into the Extensions::KHRLightsPunctual::Light struct.
   */
  bool LoadKHRLightsPunctualExtensionLight(
    const nlohmann::json& root, vtkGLTFDocumentLoader::Extensions::KHRLightsPunctual::Light& light);
};

VTK_ABI_NAMESPACE_END
#endif

// VTK-HeaderTest-Exclude: vtkGLTFDocumentLoaderInternals.h