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_Vector3.h>
40 #include <UT/UT_Vector4.h>
41 
42 namespace GLTF_NAMESPACE
43 {
44 #define GLTF_INVALID_IDX uint32(~0)
45 
46 typedef uint32 GLTF_Int;
49 
51 const uint32 GLTF_GLB_MAGIC = 0x46546C67;
52 const uint32 GLTF_GLB_JSON = 0x4E4F534A;
53 const uint32 GLTF_GLB_BIN = 0x004E4942;
54 
55 constexpr const char *GLTF_PROJECTION_NAME_ORTHOGRAPHIC = "ORTHOGRAPHIC";
56 constexpr const char *GLTF_PROJECTION_NAME_PERSPECTIVE = "PERSPECTIVE";
57 constexpr const char *GLTF_TYPE_NAME_SCALAR = "SCALAR";
58 constexpr const char *GLTF_TYPE_NAME_VEC2 = "VEC2";
59 constexpr const char *GLTF_TYPE_NAME_VEC3 = "VEC3";
60 constexpr const char *GLTF_TYPE_NAME_VEC4 = "VEC4";
61 constexpr const char *GLTF_TYPE_NAME_MAT2 = "MAT2";
62 constexpr const char *GLTF_TYPE_NAME_MAT3 = "MAT3";
63 constexpr const char *GLTF_TYPE_NAME_MAT4 = "MAT4";
64 
66 {
75 };
76 
78 {
86 };
87 
89 {
93 };
94 
96 {
104 };
105 
107 {
112 };
113 
114 //=================================================
115 
116 // Represented as a string in the GLTF file
118 {
127 };
128 
130 {
134 };
135 
137 {
142 };
143 
145 {
149 };
150 
152 {
157 };
158 
160 {
165 };
166 
168 {
174 };
175 
176 //=========================================================================
177 
178 // GLTF types - unimplemented fields are currently displayed as comments in the
179 // structure declarations
180 
181 // Interface for supported GLTF Extensions
183 {
184  virtual ~GLTF_Extension() = default;
185  virtual GLTF_ExtensionType getType() const = 0;
186 
187  // The name the extension uses in the "extensions" array
188  virtual const UT_StringHolder &getExtensionName() const = 0;
189 
190  virtual bool isRequired() const { return false; }
191 };
193 
195 {
197  GLTF_Int texCoord = 0;
198  // extensions
199  // extras
200 };
201 
203 {
205  // extensions
206  // extras
207 };
208 
210 {
211  fpreal32 strength = 1.0;
212  // extensions
213  // extras
214 };
215 
217 {
219  GLTF_Handle indicesBufferView = GLTF_INVALID_IDX;
220  GLTF_Int indicesByteOffset = 0;
222  GLTF_Handle valuesBufferView = GLTF_INVALID_IDX;
223  GLTF_Int valuesByteOffset = 0;
224 };
225 
227 {
229  GLTF_Int byteOffset = 0;
230  GLTF_ComponentType componentType = GLTF_COMPONENT_INVALID; // Required
231  bool normalized = false;
234 
235  // A double has a 53 bit mantissa, we can therefore cast to either float
236  // or int32 without loss of precision
239 
242  // extensions
243  // extras
244 };
245 
246 // Types for animation --------------------------
247 
249 {
253 };
254 
256 {
259  // extensions
260  // extras
261 };
262 
264 {
267  // extensions
268  // extras
269 };
270 
271 // ---------------------------------------------
272 
274 {
278  // extensions
279  // extras
280 };
281 
283 {
284  UT_StringHolder copyright = "";
285  UT_String generator = "";
287  UT_String minversion = "";
288  // extensions
289  // extras
290 };
291 
293 {
294  UT_String myURI = "";
297  // extensions
298  // extras
299 };
300 
302 {
303  GLTF_Handle buffer = 0; // Required
304  GLTF_Int byteOffset = 0;
305  GLTF_Int byteLength = 0; // Required
306  GLTF_Int byteStride = 0;
309  // extensions
310  // extras
311 };
312 
314 {
319  // extensions
320  //
321 };
322 
324 {
329  // extensions
330  // extras
331 };
332 
334 {
339  // extensions
340  // extras
341 };
342 
344 {
348  // extensions
349  // extras
350 };
351 
353 {
357  // extensions
358  // extras
359 };
360 
362 {
363  UT_Vector4 baseColorFactor = {0.0f, 0.0f, 0.0f, 1.0f};
365  fpreal32 metallicFactor = 1.0f;
366  fpreal32 roughnessFactor = 1.0f;
368 };
369 
371 {
373  // extensions
374  // extras
379  UT_Vector3F emissiveFactor = {0.0f, 0.0f, 0.0f};
383 };
384 
386 {
389 };
390 
392 {
398  // extensions
399  // extras
400 };
401 
403 {
407  // extensions
408  // extras
409 };
410 
412 {
418  // extensions
419  // extras
420 };
421 
423 {
424  UT_String uri = "";
425  UT_String mimeType = "";
428  // extensions
429  // extras
430 };
431 
433 {
439  UT_Vector4 rotation = {0, 0, 0, 1};
440  UT_Vector3 scale = {1, 1, 1};
441  UT_Vector3 translation = {0, 0, 0};
442  // weights
445  // Extras
446 
447  // GLTF standard specifies that only a Matrix OR TRS transform
448  // is stored.
449  GLTF_TRANSFORM_TYPE getTransformType() const;
450  void getTransformAsMatrix(UT_Matrix4F &mat) const;
451 };
452 
454 {
457  // extensions
458  // extras
459 };
460 
462 {
463  GLTF_Handle inverseBindMatrices = GLTF_INVALID_IDX; // Accessor handle
464  GLTF_Handle skeleton = GLTF_INVALID_IDX; // Node handle
465  UT_Array<GLTF_Handle> joints; // Array of node handles
466  // extensions
467  // extras
468 };
469 
471 {
475  // extensions
476  // extras
477 };
478 
479 //=========================================================================
480 
481 // Extension types
482 
484 {
485  virtual ~GLTF_Light() = default;
486 
488  UT_Vector3 color = {1.0f, 1.0f, 1.0f};
489  fpreal32 intesity = 1.0f;
491  // range
492 
493  // For spot lights only:
494  // innerConeAngle
496 };
497 
498 // Top-level lights array
500 {
501  ~GLTF_LightArray() override = default;
502  GLTF_ExtensionType getType() const override;
503  const UT_StringHolder &getExtensionName() const override;
504  bool isRequired() const override { return true; }
505 
507 };
508 
509 // Node-level index into the lights array
511 {
512  ~GLTF_LightIndex() override = default;
513  GLTF_ExtensionType getType() const override;
514  const UT_StringHolder &getExtensionName() const override;
515  bool isRequired() const override { return true; }
516 
518 };
519 
520 // ========================================================================
521 
522 // Error handling
524 {
525 public:
526  virtual ~GLTF_BaseErrorManager() = default;
527  virtual void AddError(int code, const char *msg = 0) const = 0;
528  virtual void AddWarning(int code, const char *msg = 0) const = 0;
529 };
530 
531 } // namespace GLTF_NAMESPACE
532 
533 #endif
constexpr const char * GLTF_TYPE_NAME_MAT2
Definition: GLTF_Types.h:61
uint32 GLTF_Int
Definition: GLTF_Types.h:46
UT_Optional< GLTF_Orthographic > orthographic
Definition: GLTF_Types.h:335
#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:405
bool isRequired() const override
Definition: GLTF_Types.h:515
UT_StringMap< uint32 > attributes
Definition: GLTF_Types.h:388
UT_Array< GLTF_ExtensionHandle > extensions
Definition: GLTF_Types.h:444
constexpr const char * GLTF_PROJECTION_NAME_ORTHOGRAPHIC
Definition: GLTF_Types.h:55
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
UT_Optional< GLTF_PBRMetallicRoughness > metallicRoughness
Definition: GLTF_Types.h:375
uint32 GLTF_Handle
Definition: GLTF_Types.h:48
UT_Optional< GLTF_Perspective > perspective
Definition: GLTF_Types.h:336
GLuint sampler
Definition: glcorearb.h:1656
float fpreal32
Definition: SYS_Types.h:200
UT_Array< uint32 > children
Definition: GLTF_Types.h:435
UT_StringHolder name
Definition: GLTF_Types.h:406
UT_Optional< GLTF_TextureInfo > baseColorTexture
Definition: GLTF_Types.h:364
uint32 GLTF_Offset
Definition: GLTF_Types.h:47
const uint32 GLTF_GLB_JSON
Definition: GLTF_Types.h:52
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
UT_Optional< GLTF_TextureInfo > metallicRoughnessTexture
Definition: GLTF_Types.h:367
GA_API const UT_StringHolder scale
const uint32 GLTF_GLB_MAGIC
Definition: GLTF_Types.h:51
#define GLTF_NAMESPACE
Definition: GLTF_API.h:42
Definition: core.h:760
UT_Array< GLTF_Light > lights
Definition: GLTF_Types.h:506
constexpr const char * GLTF_TYPE_NAME_VEC4
Definition: GLTF_Types.h:60
constexpr const char * GLTF_TYPE_NAME_VEC3
Definition: GLTF_Types.h:59
UT_Optional< GLTF_TextureInfo > emissiveTexture
Definition: GLTF_Types.h:378
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:376
static const UT_Matrix4T< float > & getIdentityMatrix()
UT_Array< GLTF_Primitive > primitives
Definition: GLTF_Types.h:404
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
constexpr const char * GLTF_PROJECTION_NAME_PERSPECTIVE
Definition: GLTF_Types.h:56
constexpr const char * GLTF_TYPE_NAME_MAT4
Definition: GLTF_Types.h:63
GLTF_ComponentType componentType
Definition: GLTF_Types.h:356
constexpr const char * GLTF_TYPE_NAME_SCALAR
Definition: GLTF_Types.h:57
GLenum target
Definition: glcorearb.h:1667
SIM_API const UT_StringHolder rotation
UT_Array< GLTF_AnimSampler > samplers
Definition: GLTF_Types.h:276
GLuint const GLchar * name
Definition: glcorearb.h:786
constexpr const char * GLTF_TYPE_NAME_MAT3
Definition: GLTF_Types.h:62
GLint GLenum GLboolean normalized
Definition: glcorearb.h:872
UT_Array< GLTF_MorphTarget > targets
Definition: GLTF_Types.h:397
#define GLTF_INVALID_IDX
Definition: GLTF_Types.h:44
UT_Array< fpreal64 > max
Definition: GLTF_Types.h:237
virtual bool isRequired() const
Definition: GLTF_Types.h:190
UT_Optional< fpreal32 > aspectRatio
Definition: GLTF_Types.h:325
bool isRequired() const override
Definition: GLTF_Types.h:504
GLenum mode
Definition: glcorearb.h:99
UT_Array< GLTF_Channel > channels
Definition: GLTF_Types.h:275
virtual void AddWarning(int code, const char *msg=0) const =0
UT_Array< GLTF_Handle > joints
Definition: GLTF_Types.h:465
virtual void AddError(int code, const char *msg=0) const =0
UT_Optional< GLTF_OcclusionTextureInfo > occlusionTexture
Definition: GLTF_Types.h:377
UT_Optional< fpreal32 > zfar
Definition: GLTF_Types.h:327
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:58
const uint32 GLB_BUFFER_IDX
Definition: GLTF_Types.h:50
const uint32 GLTF_GLB_BIN
Definition: GLTF_Types.h:53
UT_Optional< GLTF_Sparse > sparse
Definition: GLTF_Types.h:240
UT_Array< uint32 > nodes
Definition: GLTF_Types.h:455
type
Definition: core.h:1059
UT_Optional< fpreal32 > outerConeAngle
Definition: GLTF_Types.h:495
UT_StringMap< uint32 > attributes
Definition: GLTF_Types.h:393
UT_SharedPtr< GLTF_Extension > GLTF_ExtensionHandle
Definition: GLTF_Types.h:192
GLint GLsizei count
Definition: glcorearb.h:405
UT_Array< fpreal64 > min
Definition: GLTF_Types.h:238