HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLTF_CgltfUtils.h
Go to the documentation of this file.
1 #ifndef __GLTF_CgltfUtils_h__
2 #define __GLTF_CgltfUtils_h__
3 
4 #include "GLTF_Channel.h"
5 #include "GLTF_SceneData.h"
6 #include "GLTF_Translator.h"
7 
9 #include <SYS/SYS_Math.h>
10 #include <UT/UT_StringHolder.h>
11 #include <UT/UT_Vector3.h>
12 
13 #include <cgltf.h>
14 
15 class GLTF_AnimationData;
16 class GLTF_Reader;
17 class GLTF_Writer;
18 class OBJ_Node;
19 class UT_StringArray;
20 
21 namespace GLTF_CgltfUtils
22 {
24  {
25  AccessorMinMax() = delete;
26  AccessorMinMax(const UT_Vector3F& initial)
27  : myMinBounds(initial)
28  , myMaxBounds(initial)
29  {
30 
31  }
32 
33  void checkAndUpdate(const UT_Vector3F& vec)
34  {
35  myMinBounds.x() = SYSmin(myMinBounds.x(), vec.x());
36  myMinBounds.y() = SYSmin(myMinBounds.y(), vec.y());
37  myMinBounds.z() = SYSmin(myMinBounds.z(), vec.z());
38  myMaxBounds.x() = SYSmax(myMaxBounds.x(), vec.x());
39  myMaxBounds.y() = SYSmax(myMaxBounds.y(), vec.y());
40  myMaxBounds.z() = SYSmax(myMaxBounds.z(), vec.z());
41  }
42 
45  };
46 
49 
51  const char* suffix = "");
52 
54 
55  // Getters
57  const cgltf_data& data,
58  const GLTF_Index mesh_id,
59  const GLTF_Index prim_id);
60 
61  // Geometry helpers
62 
64  const cgltf_data& data,
65  const cgltf_animation& anim);
67  const cgltf_data& data,
68  const cgltf_node& node);
70  const cgltf_data& data,
71  const cgltf_mesh& mesh);
73  const cgltf_data& data,
74  const cgltf_scene& scene);
76  const cgltf_data& data,
77  const cgltf_skin& skin);
78 
79  void getAnimationNames(
80  const cgltf_data& data,
81  UT_StringArray& names);
82 
84  const cgltf_data& data,
85  const cgltf_camera& camera);
86 
87  // Material helpers
88 
90  const cgltf_data& data,
91  const cgltf_material& mat);
92 
93  bool hasDiffuseTexture(const cgltf_material& mat);
95  const cgltf_material& mat);
96  bool hasNormalTexture(const cgltf_material& mat);
98  const cgltf_material& mat);
99  bool hasEmissiveTexture(
100  const cgltf_material& mat);
102  const cgltf_material& mat);
104  const cgltf_material& mat);
105 
108 
109  // WARNING: this method will const_cast the cgltf_imge in order to call
110  // cgltf_decode_uri on its URI, which modifies it in place.
112  const char* gltf_filepath,
113  const cgltf_image& image);
114 
116  {
117  return UT_Matrix4F(
118  gltf_mat[0], gltf_mat[1], gltf_mat[2], gltf_mat[3],
119  gltf_mat[4], gltf_mat[5], gltf_mat[6], gltf_mat[7],
120  gltf_mat[8], gltf_mat[9], gltf_mat[10], gltf_mat[11],
121  gltf_mat[12], gltf_mat[13], gltf_mat[14], gltf_mat[15]);
122  }
123 
124  GLTFZ_API void setNodeName(
125  const GLTF_Index node_id,
126  GLTF_Writer& writer,
127  const char* name);
128 
129  void setNodeTransform(
130  OBJ_Node* object,
131  const GLTF_Index node_id,
132  GLTF_Writer& writer,
133  fpreal time);
134 
135  GLTFZ_API void setMeshName(
136  const GLTF_Index mesh_id,
137  GLTF_Writer& writer,
138  const char* name);
139 
141  const GLTF_SceneData::Node& node,
142  const float time,
143  const GLTF_AnimationData& anim_data);
144 
146  const GLTF_SceneData& scene,
147  const GLTF_SceneData::Node& node,
148  const float time,
149  const GLTF_AnimationData& anim_data);
150 
152  const cgltf_data& data,
153  const GLTF_Index node_id);
154 
156  const GLTF_Translator::Node& node,
158  float time);
159 
161  const cgltf_node& node);
162 
164  const GLTF_Reader& reader,
165  const cgltf_size extensions_count,
166  char** extensions);
167 
168  void addChildNodeToNode(
169  GLTF_Writer& writer,
170  cgltf_data& data,
171  GLTF_Index parent_id,
172  GLTF_Index child_id);
173 
174  bool isDefault(const cgltf_texture_view& tv);
175  bool isDefault(const cgltf_pbr_metallic_roughness& pbr);
176  bool isDefault(const cgltf_ior& ior);
177  bool isDefault(const cgltf_specular& specular);
178 };
179 
180 #endif // __GLTF_CgltfUtils_h__
#define SYSmax(a, b)
Definition: SYS_Math.h:1952
UT_StringHolder getImageFilePath(const char *gltf_filepath, const cgltf_image &image)
bool hasOcclusionTexture(const cgltf_material &mat)
GLTFZ_API UT_Matrix4F getAnimatedTransformWorld(const GLTF_SceneData &scene, const GLTF_SceneData::Node &node, const float time, const GLTF_AnimationData &anim_data)
bool hasNormalTexture(const cgltf_material &mat)
bool isDefault(const cgltf_texture_view &tv)
UT_StringHolder buildNodePath(const cgltf_data &data, const cgltf_node &node)
cgltf_attribute_type
Definition: cgltf.h:164
GLTF_AttributeType
Definition: GLTF_Types.h:15
size_t cgltf_size
Definition: cgltf.h:104
GT_API const UT_StringHolder time
UT_StringArray getUnsupportedImporterExtensions(const GLTF_Reader &reader, const cgltf_size extensions_count, char **extensions)
cgltf_result
Definition: cgltf.h:119
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:669
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
UT_StringHolder getHoudiniAttributeName(cgltf_attribute_type type)
UT_StringHolder getSkinName(const cgltf_data &data, const cgltf_skin &skin)
UT_StringHolder getAnimationName(const cgltf_data &data, const cgltf_animation &anim)
GLTFZ_API void setNodeName(const GLTF_Index node_id, GLTF_Writer &writer, const char *name)
UT_StringHolder getCgltfResultMessage(const cgltf_result &res)
UT_StringHolder getNodeName(const cgltf_data &data, const cgltf_node &node)
AccessorMinMax(const UT_Vector3F &initial)
GLTFZ_API void setMeshName(const GLTF_Index mesh_id, GLTF_Writer &writer, const char *name)
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
float cgltf_float
Definition: cgltf.h:106
void checkAndUpdate(const UT_Vector3F &vec)
GLTFZ_API UT_Matrix4F getAnimatedTransformLocal(const GLTF_SceneData::Node &node, const float time, const GLTF_AnimationData &anim_data)
UT_StringHolder getCameraName(const cgltf_data &data, const cgltf_camera &camera)
UT_Matrix4T< fpreal32 > UT_Matrix4F
UT_Matrix4F getMatrix4F(cgltf_float *gltf_mat)
GLuint const GLchar * name
Definition: glcorearb.h:786
UT_StringHolder getMaterialName(const cgltf_data &data, const cgltf_material &mat)
cgltf_image * getTextureImage(const cgltf_texture_view &tv)
std::size_t GLTF_Index
Definition: GLTF_Types.h:13
UT_StringHolder getGltfAttributeName(const GLTF_AttributeType type, const char *suffix="")
bool hasSpecularColorTexture(const cgltf_material &mat)
bool hasEmissiveTexture(const cgltf_material &mat)
bool hasDiffuseTexture(const cgltf_material &mat)
UT_StringHolder getSceneName(const cgltf_data &data, const cgltf_scene &scene)
fpreal64 fpreal
Definition: SYS_Types.h:283
UT_StringHolder getMeshName(const cgltf_data &data, const cgltf_mesh &mesh)
void setNodeTransform(OBJ_Node *object, const GLTF_Index node_id, GLTF_Writer &writer, fpreal time)
cgltf_primitive * getPrimitive(const cgltf_data &data, const GLTF_Index mesh_id, const GLTF_Index prim_id)
void addChildNodeToNode(GLTF_Writer &writer, cgltf_data &data, GLTF_Index parent_id, GLTF_Index child_id)
void getAnimationNames(const cgltf_data &data, UT_StringArray &names)
GLTFZ_API GLTF_Index findRootNode(const cgltf_data &data, const GLTF_Index node_id)
GLTF_TextureTransform getTextureTransform(const cgltf_texture_view &tv)
bool hasMetallicRoughnessTexture(const cgltf_material &mat)
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:667
#define GLTFZ_API
Definition: GLTFZ_API.h:37
#define SYSmin(a, b)
Definition: SYS_Math.h:1953
bool hasTransmissionTexture(const cgltf_material &mat)
Definition: format.h:1821
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:665