HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLTF_Types.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) COPYRIGHTYEAR
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 #ifndef __SOP_GLTFTYPES_H__
28 #define __SOP_GLTFTYPES_H__
29 
30 #include "GLTF_API.h"
31 
32 #include <UT/UT_Array.h>
33 #include <UT/UT_Matrix4.h>
34 #include <UT/UT_Optional.h>
35 #include <UT/UT_SharedPtr.h>
36 #include <UT/UT_String.h>
37 #include <UT/UT_StringHolder.h>
38 #include <UT/UT_StringMap.h>
39 #include <UT/UT_StringSet.h>
40 #include <UT/UT_Vector3.h>
41 #include <UT/UT_Vector4.h>
42 
43 namespace GLTF_NAMESPACE
44 {
45 #define GLTF_INVALID_IDX uint32(~0)
46 
47 typedef uint32 GLTF_Int;
50 
52 const uint32 GLTF_GLB_MAGIC = 0x46546C67;
53 const uint32 GLTF_GLB_JSON = 0x4E4F534A;
54 const uint32 GLTF_GLB_BIN = 0x004E4942;
55 
56 constexpr const char *GLTF_PROJECTION_NAME_ORTHOGRAPHIC = "ORTHOGRAPHIC";
57 constexpr const char *GLTF_PROJECTION_NAME_PERSPECTIVE = "PERSPECTIVE";
58 constexpr const char *GLTF_TYPE_NAME_SCALAR = "SCALAR";
59 constexpr const char *GLTF_TYPE_NAME_VEC2 = "VEC2";
60 constexpr const char *GLTF_TYPE_NAME_VEC3 = "VEC3";
61 constexpr const char *GLTF_TYPE_NAME_VEC4 = "VEC4";
62 constexpr const char *GLTF_TYPE_NAME_MAT2 = "MAT2";
63 constexpr const char *GLTF_TYPE_NAME_MAT3 = "MAT3";
64 constexpr const char *GLTF_TYPE_NAME_MAT4 = "MAT4";
65 
67 {
76 };
77 
79 {
87 };
88 
90 {
94 };
95 
97 {
105 };
106 
108 {
113 };
114 
115 //=================================================
116 
117 // Represented as a string in the GLTF file
119 {
128 };
129 
131 {
135 };
136 
138 {
143 };
144 
146 {
150 };
151 
153 {
158 };
159 
161 {
166 };
167 
169 {
175 };
176 
177 //=========================================================================
178 
179 // GLTF types - unimplemented fields are currently displayed as comments in the
180 // structure declarations
181 
182 // Interface for supported GLTF Extensions
184 {
185  virtual ~GLTF_Extension() = default;
186  virtual GLTF_ExtensionType getType() const = 0;
187 
188  // The name the extension uses in the "extensions" array
189  virtual const UT_StringHolder &getExtensionName() const = 0;
190 
191  virtual bool isRequired() const { return false; }
192 
193  static const UT_StringSet& getSupportedExtensions();
194 };
196 
198 {
200  GLTF_Int texCoord = 0;
201  // extensions
202  // extras
203 };
204 
206 {
208  // extensions
209  // extras
210 };
211 
213 {
214  fpreal32 strength = 1.0;
215  // extensions
216  // extras
217 };
218 
220 {
222  GLTF_Handle indicesBufferView = GLTF_INVALID_IDX;
223  GLTF_Int indicesByteOffset = 0;
225  GLTF_Handle valuesBufferView = GLTF_INVALID_IDX;
226  GLTF_Int valuesByteOffset = 0;
227 };
228 
230 {
232  GLTF_Int byteOffset = 0;
233  GLTF_ComponentType componentType = GLTF_COMPONENT_INVALID; // Required
234  bool normalized = false;
237 
238  // A double has a 53 bit mantissa, we can therefore cast to either float
239  // or int32 without loss of precision
242 
245  // extensions
246  // extras
247 };
248 
249 // Types for animation --------------------------
250 
252 {
256 };
257 
259 {
262  // extensions
263  // extras
264 };
265 
267 {
270  // extensions
271  // extras
272 };
273 
274 // ---------------------------------------------
275 
277 {
281  // extensions
282  // extras
283 };
284 
286 {
287  UT_StringHolder copyright = "";
288  UT_String generator = "";
290  UT_String minversion = "";
291  // extensions
292  // extras
293 };
294 
296 {
297  UT_String myURI = "";
300  // extensions
301  // extras
302 };
303 
305 {
306  GLTF_Handle buffer = 0; // Required
307  GLTF_Int byteOffset = 0;
308  GLTF_Int byteLength = 0; // Required
309  GLTF_Int byteStride = 0;
312  // extensions
313  // extras
314 };
315 
317 {
322  // extensions
323  //
324 };
325 
327 {
332  // extensions
333  // extras
334 };
335 
337 {
342  // extensions
343  // extras
344 };
345 
347 {
351  // extensions
352  // extras
353 };
354 
356 {
360  // extensions
361  // extras
362 };
363 
365 {
366  UT_Vector4 baseColorFactor = {0.0f, 0.0f, 0.0f, 1.0f};
368  fpreal32 metallicFactor = 1.0f;
369  fpreal32 roughnessFactor = 1.0f;
371 };
372 
374 {
376  // extensions
377  // extras
382  UT_Vector3F emissiveFactor = {0.0f, 0.0f, 0.0f};
386 };
387 
389 {
392 };
393 
395 {
401  // extensions
402  // extras
403 };
404 
406 {
410  // extensions
411  // extras
412 };
413 
415 {
421  // extensions
422  // extras
423 };
424 
426 {
427  UT_String uri = "";
428  UT_String mimeType = "";
431  // extensions
432  // extras
433 };
434 
436 {
442  UT_Vector4 rotation = {0, 0, 0, 1};
443  UT_Vector3 scale = {1, 1, 1};
444  UT_Vector3 translation = {0, 0, 0};
445  // weights
448  // Extras
449 
450  // GLTF standard specifies that only a Matrix OR TRS transform
451  // is stored.
452  GLTF_TRANSFORM_TYPE getTransformType() const;
453  void getTransformAsMatrix(UT_Matrix4F &mat) const;
454 };
455 
457 {
460  // extensions
461  // extras
462 };
463 
465 {
466  GLTF_Handle inverseBindMatrices = GLTF_INVALID_IDX; // Accessor handle
467  GLTF_Handle skeleton = GLTF_INVALID_IDX; // Node handle
468  UT_Array<GLTF_Handle> joints; // Array of node handles
469  // extensions
470  // extras
471 };
472 
474 {
478  // extensions
479  // extras
480 };
481 
482 //=========================================================================
483 
484 // Extension types
485 
487 {
488  virtual ~GLTF_Light() = default;
489 
491  UT_Vector3 color = {1.0f, 1.0f, 1.0f};
492  fpreal32 intesity = 1.0f;
494  // range
495 
496  // For spot lights only:
497  // innerConeAngle
499 };
500 
501 // Top-level lights array
503 {
504  ~GLTF_LightArray() override = default;
505  GLTF_ExtensionType getType() const override;
506  const UT_StringHolder &getExtensionName() const override;
507  bool isRequired() const override { return true; }
508 
510 };
511 
512 // Node-level index into the lights array
514 {
515  ~GLTF_LightIndex() override = default;
516  GLTF_ExtensionType getType() const override;
517  const UT_StringHolder &getExtensionName() const override;
518  bool isRequired() const override { return true; }
519 
521 };
522 
523 // ========================================================================
524 
525 // Error handling
527 {
528 public:
529  virtual ~GLTF_BaseErrorManager() = default;
530  virtual void AddError(int code, const char *msg = 0) const = 0;
531  virtual void AddWarning(int code, const char *msg = 0) const = 0;
532 };
533 
534 } // namespace GLTF_NAMESPACE
535 
536 #endif
constexpr const char * GLTF_TYPE_NAME_MAT2
Definition: GLTF_Types.h:62
uint32 GLTF_Int
Definition: GLTF_Types.h:47
UT_Optional< GLTF_Orthographic > orthographic
Definition: GLTF_Types.h:338
#define GLTF_API
Definition: GLTF_API.h:37
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
UT_Array< fpreal32 > weights
Definition: GLTF_Types.h:408
bool isRequired() const override
Definition: GLTF_Types.h:518
UT_StringMap< uint32 > attributes
Definition: GLTF_Types.h:391
UT_Array< GLTF_ExtensionHandle > extensions
Definition: GLTF_Types.h:447
constexpr const char * GLTF_PROJECTION_NAME_ORTHOGRAPHIC
Definition: GLTF_Types.h:56
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
UT_Optional< GLTF_PBRMetallicRoughness > metallicRoughness
Definition: GLTF_Types.h:378
uint32 GLTF_Handle
Definition: GLTF_Types.h:49
UT_Optional< GLTF_Perspective > perspective
Definition: GLTF_Types.h:339
GLuint sampler
Definition: glcorearb.h:1656
float fpreal32
Definition: SYS_Types.h:200
UT_Array< uint32 > children
Definition: GLTF_Types.h:438
UT_StringHolder name
Definition: GLTF_Types.h:409
UT_Optional< GLTF_TextureInfo > baseColorTexture
Definition: GLTF_Types.h:367
uint32 GLTF_Offset
Definition: GLTF_Types.h:48
const uint32 GLTF_GLB_JSON
Definition: GLTF_Types.h:53
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
UT_Optional< GLTF_TextureInfo > metallicRoughnessTexture
Definition: GLTF_Types.h:370
GA_API const UT_StringHolder scale
const uint32 GLTF_GLB_MAGIC
Definition: GLTF_Types.h:52
#define GLTF_NAMESPACE
Definition: GLTF_API.h:42
Definition: core.h:760
UT_Array< GLTF_Light > lights
Definition: GLTF_Types.h:509
constexpr const char * GLTF_TYPE_NAME_VEC4
Definition: GLTF_Types.h:61
constexpr const char * GLTF_TYPE_NAME_VEC3
Definition: GLTF_Types.h:60
UT_Optional< GLTF_TextureInfo > emissiveTexture
Definition: GLTF_Types.h:381
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
UT_Optional< GLTF_NormalTextureInfo > normalTexture
Definition: GLTF_Types.h:379
static const UT_Matrix4T< float > & getIdentityMatrix()
UT_Array< GLTF_Primitive > primitives
Definition: GLTF_Types.h:407
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
constexpr const char * GLTF_PROJECTION_NAME_PERSPECTIVE
Definition: GLTF_Types.h:57
constexpr const char * GLTF_TYPE_NAME_MAT4
Definition: GLTF_Types.h:64
GLTF_ComponentType componentType
Definition: GLTF_Types.h:359
constexpr const char * GLTF_TYPE_NAME_SCALAR
Definition: GLTF_Types.h:58
GLenum target
Definition: glcorearb.h:1667
SIM_API const UT_StringHolder rotation
UT_Array< GLTF_AnimSampler > samplers
Definition: GLTF_Types.h:279
GLuint const GLchar * name
Definition: glcorearb.h:786
constexpr const char * GLTF_TYPE_NAME_MAT3
Definition: GLTF_Types.h:63
GLint GLenum GLboolean normalized
Definition: glcorearb.h:872
UT_Array< GLTF_MorphTarget > targets
Definition: GLTF_Types.h:400
#define GLTF_INVALID_IDX
Definition: GLTF_Types.h:45
UT_Array< fpreal64 > max
Definition: GLTF_Types.h:240
virtual bool isRequired() const
Definition: GLTF_Types.h:191
UT_Optional< fpreal32 > aspectRatio
Definition: GLTF_Types.h:328
bool isRequired() const override
Definition: GLTF_Types.h:507
GLenum mode
Definition: glcorearb.h:99
UT_Array< GLTF_Channel > channels
Definition: GLTF_Types.h:278
virtual void AddWarning(int code, const char *msg=0) const =0
UT_Array< GLTF_Handle > joints
Definition: GLTF_Types.h:468
virtual void AddError(int code, const char *msg=0) const =0
UT_Optional< GLTF_OcclusionTextureInfo > occlusionTexture
Definition: GLTF_Types.h:380
UT_Optional< fpreal32 > zfar
Definition: GLTF_Types.h:330
GLuint color
Definition: glcorearb.h:1261
GLuint index
Definition: glcorearb.h:786
unsigned int uint32
Definition: SYS_Types.h:40
constexpr const char * GLTF_TYPE_NAME_VEC2
Definition: GLTF_Types.h:59
const uint32 GLB_BUFFER_IDX
Definition: GLTF_Types.h:51
const uint32 GLTF_GLB_BIN
Definition: GLTF_Types.h:54
UT_Optional< GLTF_Sparse > sparse
Definition: GLTF_Types.h:243
UT_Array< uint32 > nodes
Definition: GLTF_Types.h:458
type
Definition: core.h:1059
UT_Optional< fpreal32 > outerConeAngle
Definition: GLTF_Types.h:498
UT_StringMap< uint32 > attributes
Definition: GLTF_Types.h:396
UT_SharedPtr< GLTF_Extension > GLTF_ExtensionHandle
Definition: GLTF_Types.h:195
GLint GLsizei count
Definition: glcorearb.h:405
UT_Array< fpreal64 > min
Definition: GLTF_Types.h:241