VTK  9.3.0
vtkGLTFReader.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 
52 #ifndef vtkGLTFReader_h
53 #define vtkGLTFReader_h
54 
55 #include "vtkIOGeometryModule.h" // For export macro
57 #include "vtkResourceStream.h" // For vtkResourceStream
58 #include "vtkSmartPointer.h" // For vtkSmartPointer
59 #include "vtkURILoader.h" // For vtkURILoader
60 
61 #include <string> // For std::string
62 #include <vector> // For std::vector
63 
64 VTK_ABI_NAMESPACE_BEGIN
66 class vtkFieldData;
68 class vtkImageData;
69 class vtkStringArray;
70 
71 class VTKIOGEOMETRY_EXPORT vtkGLTFReader : public vtkMultiBlockDataSetAlgorithm
72 {
73 public:
74  static vtkGLTFReader* New();
76  void PrintSelf(ostream& os, vtkIndent indent) override;
77 
79 
84  struct GLTFTexture
85  {
87  unsigned short MinFilterValue;
88  unsigned short MaxFilterValue;
89  unsigned short WrapSValue;
90  unsigned short WrapTValue;
91  };
92 
96 
98 
104 
106 
113 
115 
123 
125 
132  vtkGetMacro(ApplyDeformationsToGeometry, bool);
133  vtkBooleanMacro(ApplyDeformationsToGeometry, bool);
135 
137 
143  vtkGetMacro(NumberOfAnimations, vtkIdType);
145  float GetAnimationDuration(vtkIdType animationIndex);
147 
149 
154  void EnableAnimation(vtkIdType animationIndex);
155  void DisableAnimation(vtkIdType animationIndex);
156  bool IsAnimationEnabled(vtkIdType animationIndex);
158 
160 
165  vtkGetMacro(NumberOfScenes, vtkIdType);
167 
169 
172  vtkGetMacro(CurrentScene, vtkIdType);
173  vtkSetMacro(CurrentScene, vtkIdType);
174  void SetScene(const std::string& scene);
176 
178 
187  vtkGetMacro(FrameRate, unsigned int);
188  vtkSetMacro(FrameRate, unsigned int);
190 
197 
202 
203 protected:
205  ~vtkGLTFReader() override;
206 
208 
210 
211  std::vector<GLTFTexture> Textures;
212 
217 
218  char* FileName = nullptr;
220  vtkMTimeType LastStreamTimeStamp = 0;
222 
223  vtkIdType CurrentScene = 0;
224  unsigned int FrameRate = 60;
225  vtkIdType NumberOfAnimations = 0;
226  vtkIdType NumberOfScenes = 0;
227 
228  bool IsModelLoaded = false;
229  bool IsMetaDataLoaded = false;
230 
231  bool ApplyDeformationsToGeometry = true;
232 
234 
237 
240 
246 
252 
253 private:
254  vtkGLTFReader(const vtkGLTFReader&) = delete;
255  void operator=(const vtkGLTFReader&) = delete;
256 };
257 
258 VTK_ABI_NAMESPACE_END
259 #endif
Store on/off settings for data arrays, etc.
represent and manipulate fields of data
Definition: vtkFieldData.h:52
Deserialize a GLTF model file.
Read a GLTF file.
Definition: vtkGLTFReader.h:72
vtkSmartPointer< vtkGLTFDocumentLoader > Loader
void DisableAnimation(vtkIdType animationIndex)
Enable/Disable an animation.
~vtkGLTFReader() override
vtkSetFilePathMacro(FileName)
Set/Get the name of the file from which to read points.
std::string GetAnimationName(vtkIdType animationIndex)
glTF models can contain multiple animations, with various names and duration.
vtkGetSmartPointerMacro(URILoader, vtkURILoader)
Set/Get the URI loader to use when reading from a Stream.
std::vector< GLTFTexture > Textures
vtkSmartPointer< vtkResourceStream > Stream
void StoreTextureData()
Create and store GLTFTexture struct for each image present in the model.
void SetScene(const std::string &scene)
Get/Set the scene to be used by the reader.
void CreateSceneNamesArray()
Create the SceneNames array, generate unique identifiers for each scene based on their glTF name,...
GLTFTexture GetGLTFTexture(vtkIdType textureIndex)
vtkSmartPointer< vtkDataArraySelection > AnimationSelection
float GetAnimationDuration(vtkIdType animationIndex)
glTF models can contain multiple animations, with various names and duration.
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
void SetApplyDeformationsToGeometry(bool flag)
The model's skinning transforms are computed and added to the different vtkPolyData objects' field da...
vtkSmartPointer< vtkStringArray > SceneNames
std::string GetSceneName(vtkIdType sceneIndex)
glTF models can contain multiple scene descriptions.
void CreateAnimationSelection()
Fill the AnimationSelection vtkDataArraySelection with animation names.
vtkSetSmartPointerMacro(Stream, vtkResourceStream)
Set/Get the stream from which to read the glTF.
vtkSmartPointer< vtkMultiBlockDataSet > OutputDataSet
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkSmartPointer< vtkURILoader > URILoader
static vtkGLTFReader * New()
void EnableAnimation(vtkIdType animationIndex)
Enable/Disable an animation.
vtkSetSmartPointerMacro(URILoader, vtkURILoader)
Set/Get the URI loader to use when reading from a Stream.
vtkIdType GetNumberOfTextures()
bool IsAnimationEnabled(vtkIdType animationIndex)
Enable/Disable an animation.
vtkDataArraySelection * GetAnimationSelection()
Get the vtkDataArraySelection object to enable/disable animations.
vtkGetFilePathMacro(FileName)
Set/Get the name of the file from which to read points.
vtkStringArray * GetAllSceneNames()
Get a list all scenes names as a vtkStringArray, with duplicate names numbered and empty names replac...
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
vtkGetSmartPointerMacro(Stream, vtkResourceStream)
Set/Get the stream from which to read the glTF.
vtkSmartPointer< vtkDataArraySelection > PreviousAnimationSelection
topologically and geometrically regular array of data
Definition: vtkImageData.h:43
a simple class to control print indentation
Definition: vtkIndent.h:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
Abstract class used for custom streams.
a vtkAbstractArray subclass for strings
Helper class for readers and importer that need to load more than one resource.
Definition: vtkURILoader.h:100
@ string
Definition: vtkX3D.h:490
Materials are not directly applied to this reader's output.
Definition: vtkGLTFReader.h:85
unsigned short MinFilterValue
Definition: vtkGLTFReader.h:87
unsigned short MaxFilterValue
Definition: vtkGLTFReader.h:88
vtkSmartPointer< vtkImageData > Image
Definition: vtkGLTFReader.h:86
int vtkIdType
Definition: vtkType.h:315
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270