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 };
191 
193 {
195  GLTF_Int texCoord = 0;
196  // extensions
197  // extras
198 };
199 
201 {
203  // extensions
204  // extras
205 };
206 
208 {
209  fpreal32 strength = 1.0;
210  // extensions
211  // extras
212 };
213 
215 {
217  GLTF_Handle indicesBufferView = GLTF_INVALID_IDX;
218  GLTF_Int indicesByteOffset = 0;
220  GLTF_Handle valuesBufferView = GLTF_INVALID_IDX;
221  GLTF_Int valuesByteOffset = 0;
222 };
223 
225 {
227  GLTF_Int byteOffset = 0;
228  GLTF_ComponentType componentType = GLTF_COMPONENT_INVALID; // Required
229  bool normalized = false;
232 
233  // A double has a 53 bit mantissa, we can therefore cast to either float
234  // or int32 without loss of precision
237 
240  // extensions
241  // extras
242 };
243 
244 // Types for animation --------------------------
245 
247 {
251 };
252 
254 {
257  // extensions
258  // extras
259 };
260 
262 {
265  // extensions
266  // extras
267 };
268 
269 // ---------------------------------------------
270 
272 {
276  // extensions
277  // extras
278 };
279 
281 {
282  UT_String copyright = "";
283  UT_String generator = "";
285  UT_String minversion = "";
286  // extensions
287  // extras
288 };
289 
291 {
292  UT_String myURI = "";
295  // extensions
296  // extras
297 };
298 
300 {
301  GLTF_Handle buffer = 0; // Required
302  GLTF_Int byteOffset = 0;
303  GLTF_Int byteLength = 0; // Required
304  GLTF_Int byteStride = 0;
307  // extensions
308  // extras
309 };
310 
312 {
317  // extensions
318  //
319 };
320 
322 {
327  // extensions
328  // extras
329 };
330 
332 {
337  // extensions
338  // extras
339 };
340 
342 {
346  // extensions
347  // extras
348 };
349 
351 {
355  // extensions
356  // extras
357 };
358 
360 {
361  UT_Vector4 baseColorFactor = {0.0f, 0.0f, 0.0f, 1.0f};
363  fpreal32 metallicFactor = 1.0f;
364  fpreal32 roughnessFactor = 1.0f;
366 };
367 
369 {
371  // extensions
372  // extras
377  UT_Vector3F emissiveFactor = {0.0f, 0.0f, 0.0f};
381 };
382 
384 {
387 };
388 
390 {
396  // extensions
397  // extras
398 };
399 
401 {
405  // extensions
406  // extras
407 };
408 
410 {
416  // extensions
417  // extras
418 };
419 
421 {
422  UT_String uri = "";
423  UT_String mimeType = "";
426  // extensions
427  // extras
428 };
429 
431 {
437  UT_Vector4 rotation = {0, 0, 0, 1};
438  UT_Vector3 scale = {1, 1, 1};
439  UT_Vector3 translation = {0, 0, 0};
440  // weights
443  // Extras
444 
445  // GLTF standard specifies that only a Matrix OR TRS transform
446  // is stored.
447  GLTF_TRANSFORM_TYPE getTransformType() const;
448  void getTransformAsMatrix(UT_Matrix4F &mat) const;
449 };
450 
452 {
455  // extensions
456  // extras
457 };
458 
460 {
461  GLTF_Handle inverseBindMatrices = GLTF_INVALID_IDX; // Accessor handle
462  GLTF_Handle skeleton = GLTF_INVALID_IDX; // Node handle
463  UT_Array<GLTF_Handle> joints; // Array of node handles
464  // extensions
465  // extras
466 };
467 
469 {
473  // extensions
474  // extras
475 };
476 
477 //=========================================================================
478 
479 // Extension types
480 
482 {
483  virtual ~GLTF_Light() = default;
484 
486  UT_Vector3 color = {1.0f, 1.0f, 1.0f};
487  fpreal32 intesity = 1.0f;
489  // range
490 
491  // For spot lights only:
492  // innerConeAngle
494 };
495 
496 // Top-level lights array
498 {
499  ~GLTF_LightArray() override = default;
500  GLTF_ExtensionType getType() const override;
501  const UT_StringHolder &getExtensionName() const override;
502 
504 };
505 
506 // Node-level index into the lights array
508 {
509  ~GLTF_LightIndex() override = default;
510  GLTF_ExtensionType getType() const override;
511  const UT_StringHolder &getExtensionName() const override;
512 
514 };
515 
516 // ========================================================================
517 
518 // Error handling
520 {
521 public:
522  virtual ~GLTF_BaseErrorManager() = default;
523  virtual void AddError(int code, const char *msg = 0) const = 0;
524  virtual void AddWarning(int code, const char *msg = 0) const = 0;
525 };
526 
527 } // namespace GLTF_NAMESPACE
528 
529 #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:333
#define GLTF_API
Definition: GLTF_API.h:37
GLenum GLenum GLenum GLenum GLenum scale
Definition: glew.h:14163
UT_Array< fpreal32 > weights
Definition: GLTF_Types.h:403
UT_StringMap< uint32 > attributes
Definition: GLTF_Types.h:386
UT_Array< GLTF_ExtensionHandle > extensions
Definition: GLTF_Types.h:442
constexpr const char * GLTF_PROJECTION_NAME_ORTHOGRAPHIC
Definition: GLTF_Types.h:55
GLuint color
Definition: glcorearb.h:1260
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
UT_Optional< GLTF_PBRMetallicRoughness > metallicRoughness
Definition: GLTF_Types.h:373
uint32 GLTF_Handle
Definition: GLTF_Types.h:48
UT_Optional< GLTF_Perspective > perspective
Definition: GLTF_Types.h:334
GLuint const GLchar * name
Definition: glcorearb.h:785
GLuint sampler
Definition: glcorearb.h:1655
float fpreal32
Definition: SYS_Types.h:200
GLuint buffer
Definition: glcorearb.h:659
UT_Array< uint32 > children
Definition: GLTF_Types.h:433
UT_Optional< GLTF_TextureInfo > baseColorTexture
Definition: GLTF_Types.h:362
uint32 GLTF_Offset
Definition: GLTF_Types.h:47
GLuint in
Definition: glew.h:11552
const uint32 GLTF_GLB_JSON
Definition: GLTF_Types.h:52
GLenum target
Definition: glcorearb.h:1666
UT_Optional< GLTF_TextureInfo > metallicRoughnessTexture
Definition: GLTF_Types.h:365
const uint32 GLTF_GLB_MAGIC
Definition: GLTF_Types.h:51
#define GLTF_NAMESPACE
Definition: GLTF_API.h:42
UT_Array< GLTF_Light > lights
Definition: GLTF_Types.h:503
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
hboost::optional< T > UT_Optional
Definition: UT_Optional.h:16
constexpr const char * GLTF_TYPE_NAME_VEC4
Definition: GLTF_Types.h:60
constexpr const char * GLTF_TYPE_NAME_VEC3
Definition: GLTF_Types.h:59
GLint GLenum GLboolean normalized
Definition: glcorearb.h:871
UT_Optional< GLTF_TextureInfo > emissiveTexture
Definition: GLTF_Types.h:376
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:30
UT_Optional< GLTF_NormalTextureInfo > normalTexture
Definition: GLTF_Types.h:374
static const UT_Matrix4T< float > & getIdentityMatrix()
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
GLsizei GLenum const void * indices
Definition: glcorearb.h:405
UT_Array< GLTF_Primitive > primitives
Definition: GLTF_Types.h:402
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:354
constexpr const char * GLTF_TYPE_NAME_SCALAR
Definition: GLTF_Types.h:57
UT_Array< GLTF_AnimSampler > samplers
Definition: GLTF_Types.h:274
GLint GLsizei count
Definition: glcorearb.h:404
constexpr const char * GLTF_TYPE_NAME_MAT3
Definition: GLTF_Types.h:62
UT_Array< GLTF_MorphTarget > targets
Definition: GLTF_Types.h:395
#define GLTF_INVALID_IDX
Definition: GLTF_Types.h:44
UT_Array< fpreal64 > max
Definition: GLTF_Types.h:235
UT_Optional< fpreal32 > aspectRatio
Definition: GLTF_Types.h:323
GLuint GLenum matrix
Definition: glew.h:15055
GLenum mode
Definition: glcorearb.h:98
UT_Array< GLTF_Channel > channels
Definition: GLTF_Types.h:273
virtual void AddWarning(int code, const char *msg=0) const =0
UT_Array< GLTF_Handle > joints
Definition: GLTF_Types.h:463
virtual void AddError(int code, const char *msg=0) const =0
UT_Optional< GLTF_OcclusionTextureInfo > occlusionTexture
Definition: GLTF_Types.h:375
UT_Optional< fpreal32 > zfar
Definition: GLTF_Types.h:325
GLuint index
Definition: glcorearb.h:785
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:238
UT_Array< uint32 > nodes
Definition: GLTF_Types.h:453
UT_Optional< fpreal32 > outerConeAngle
Definition: GLTF_Types.h:493
UT_StringMap< uint32 > attributes
Definition: GLTF_Types.h:391
UT_SharedPtr< GLTF_Extension > GLTF_ExtensionHandle
Definition: GLTF_Types.h:190
UT_Array< fpreal64 > min
Definition: GLTF_Types.h:236
MatType rotation(const Quat< typename MatType::value_type > &q, typename MatType::value_type eps=static_cast< typename MatType::value_type >(1.0e-8))
Return the rotation matrix specified by the given quaternion.
Definition: Mat.h:194