AnimEngine
GltfCommon.h
1 #pragma once
2 #ifndef GLTF_COMMON_HEADER_HAS_BEEN_INCLUDED_
3 #define GLTF_COMMON_HEADER_HAS_BEEN_INCLUDED_
4 
5 #define TINYGLTF_NO_INCLUDE_JSON
6 #define TINYGLTF_NO_INCLUDE_STB_IMAGE
7 #define TINYGLTF_NO_INCLUDE_STB_IMAGE_WRITE
8 #include "TinyGltf/tiny_gltf.h"
9 
10 #include <stdint.h>
11 #include <limits>
12 #include <tuple>
13 #include <memory>
14 
15 namespace gltf{
16 
19 
20  using Accessor = tinygltf::Accessor;
21  using BufferView = tinygltf::BufferView;
22  using Buffer = tinygltf::Buffer;
23 
25  {
26  Accessor accessor;
27  BufferView buffer_view;
28  std::shared_ptr<const Buffer> bufferPtr = nullptr;
29  // Duplicating the buffer was silly and costly sure, but it
30  // shouldn't have resulted in a memory leak since it's a vector
31  // and the object should get destroyed automatically. Either way
32  // using a shared_ptr here is an easy fix.
33  };
34 
35  enum class DataType : int32_t {
36  SCALAR = TINYGLTF_TYPE_SCALAR,
37  VEC2 = TINYGLTF_TYPE_VEC2,
38  VEC3 = TINYGLTF_TYPE_VEC3,
39  VEC4 = TINYGLTF_TYPE_VEC4,
40  MAT2 = TINYGLTF_TYPE_MAT2,
41  MAT3 = TINYGLTF_TYPE_MAT3,
42  MAT4 = TINYGLTF_TYPE_MAT4,
43  INVALID = std::numeric_limits<int32_t>::max()
44  };
45 
46  enum class ComponentType : int32_t {
47  BYTE = TINYGLTF_COMPONENT_TYPE_BYTE,
48  UNSIGNED_BYTE = TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE,
49  SHORT = TINYGLTF_COMPONENT_TYPE_SHORT,
50  UNSIGNED_SHORT = TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT,
51  INT = TINYGLTF_COMPONENT_TYPE_INT,
52  UNSIGNED_INT = TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT,
53  FLOAT = TINYGLTF_COMPONENT_TYPE_FLOAT,
54  DOUBLE = TINYGLTF_COMPONENT_TYPE_DOUBLE,
55  INVALID = std::numeric_limits<int32_t>::max()
56  };
57 
58  struct TypePair{const DataType data_type = DataType::INVALID; const ComponentType component_type = ComponentType::INVALID;};
59 
60  template <DataType T_dataType = DataType::INVALID>
61  struct DataTypeInfo{
62  static inline constexpr size_t count() noexcept {return(0);}
63  static inline constexpr bool isScalar() noexcept {return(false);}
64  static inline constexpr bool isVector() noexcept {return(false);}
65  static inline constexpr bool isMatrix() noexcept {return(false);}
66  };
67 
68  template <ComponentType T_compType>
70 
71 
72  template<>
73  struct DataTypeInfo<DataType::SCALAR>{
74  static inline constexpr size_t count() noexcept {return(1);}
75  static inline constexpr bool isScalar() noexcept {return(true);}
76  static inline constexpr bool isVector() noexcept {return(false);}
77  static inline constexpr bool isMatrix() noexcept {return(false);}
78  };
79  template<>
80  struct DataTypeInfo<DataType::VEC2>{
81  static inline constexpr size_t count() noexcept {return(2);}
82  static inline constexpr bool isScalar() noexcept {return(false);}
83  static inline constexpr bool isVector() noexcept {return(true);}
84  static inline constexpr bool isMatrix() noexcept {return(false);}
85  };
86  template<>
87  struct DataTypeInfo<DataType::VEC3>{
88  static inline constexpr size_t count() noexcept {return(3);}
89  static inline constexpr bool isScalar() noexcept {return(false);}
90  static inline constexpr bool isVector() noexcept {return(true);}
91  static inline constexpr bool isMatrix() noexcept {return(false);}
92  };
93  template<>
94  struct DataTypeInfo<DataType::VEC4>{
95  static inline constexpr size_t count() noexcept {return(4);}
96  static inline constexpr bool isScalar() noexcept {return(false);}
97  static inline constexpr bool isVector() noexcept {return(true);}
98  static inline constexpr bool isMatrix() noexcept {return(false);}
99  };
100  template<>
101  struct DataTypeInfo<DataType::MAT2>{
102  static inline constexpr size_t count() noexcept {return(4);}
103  static inline constexpr bool isScalar() noexcept {return(false);}
104  static inline constexpr bool isVector() noexcept {return(false);}
105  static inline constexpr bool isMatrix() noexcept {return(true);}
106  };
107  template<>
108  struct DataTypeInfo<DataType::MAT3>{
109  static inline constexpr size_t count() noexcept {return(9);}
110  static inline constexpr bool isScalar() noexcept {return(false);}
111  static inline constexpr bool isVector() noexcept {return(false);}
112  static inline constexpr bool isMatrix() noexcept {return(true);}
113  };
114  template<>
115  struct DataTypeInfo<DataType::MAT4>{
116  static inline constexpr size_t count() noexcept {return(16);}
117  static inline constexpr bool isScalar() noexcept {return(false);}
118  static inline constexpr bool isVector() noexcept {return(false);}
119  static inline constexpr bool isMatrix() noexcept {return(true);}
120  };
121 
122  template <>
123  struct ComponentTypeInfo<ComponentType::BYTE>{
124  using data_t = int8_t;
125  };
126  template <>
127  struct ComponentTypeInfo<ComponentType::UNSIGNED_BYTE>{
128  using data_t = uint8_t;
129  };
130  template <>
131  struct ComponentTypeInfo<ComponentType::SHORT>{
132  using data_t = int16_t;
133  };
134  template <>
135  struct ComponentTypeInfo<ComponentType::UNSIGNED_SHORT>{
136  using data_t = uint16_t;
137  };
138  template <>
139  struct ComponentTypeInfo<ComponentType::INT>{
140  using data_t = int32_t;
141  };
142  template <>
143  struct ComponentTypeInfo<ComponentType::UNSIGNED_INT>{
144  using data_t = uint32_t;
145  };
146  template <>
147  struct ComponentTypeInfo<ComponentType::FLOAT>{
148  using data_t = float;
149  };
150  template <>
151  struct ComponentTypeInfo<ComponentType::DOUBLE>{
152  using data_t = double;
153  };
154 
155 
156 
157 
158 
159 }
160 
161 #endif
Definition: GltfCommon.h:58
Definition: GltfCommon.h:15
Definition: GltfCommon.h:61
Definition: GltfCommon.h:69
Definition: GltfCommon.h:24