1 #ifndef __GLTF_CgltfWrapper_h__
2 #define __GLTF_CgltfWrapper_h__
24 #define GLTF_DEFINE_APPEND_FUNC( \
25 func_name, cgltf_type, container, count_member) \
26 cgltf_type& func_name() \
28 cgltf_type& new_elem = appendProperty(&container, count_member); \
29 initProperty(&new_elem); \
44 return reinterpret_cast<T*
>(
id + 1);
61 myCgltfData = std::move(
data);
73 inline static void gltf_free_func(
void* user,
void*
ptr) { free(ptr); }
78 *prop = (
char*)malloc(
sizeof(
char) * (strlen(src) + 1));
85 memset(prop, 0,
sizeof(*prop));
90 initProperty(&myCgltfOptions);
92 myCgltfData.reset(
nullptr);
94 initProperty(new_data);
95 myCgltfData.reset(new_data);
97 myCgltfData->memory.free_func = &gltf_free_func;
100 initAsHoudiniAsset(myCgltfData->asset);
114 initProperty(&asset.
extras);
123 attrib.
name = (
char*)malloc(
sizeof(
char) * (strlen(name) + 1));
124 strcpy(attrib.
name, name);
126 attrib.
index = accessor_index;
127 attrib.
data = data_accessor;
130 template <
typename T>
133 if (*propList ==
nullptr && propSize == 0)
135 *propList = (
T*)malloc(
sizeof(
T));
137 return (*propList)[0];
141 T* old_prop = *propList;
144 *propList = (
T*)malloc(
sizeof(
T) * propSize);
147 (*propList)[i] = old_prop[i];
152 return (*propList)[propSize - 1];
155 template <
typename T>
158 if (*propList ==
nullptr && propSize == 0)
160 *propList = (
T**)malloc(
sizeof(
T*));
162 return (*propList)[0];
166 T** old_prop = *propList;
169 *propList = (
T**)malloc(
sizeof(
T*) * propSize);
172 (*propList)[i] = old_prop[i];
177 return (*propList)[propSize - 1];
183 myCgltfData->bin =
data;
184 myCgltfData->bin_size =
size;
187 template <
typename T>
190 return prop->extras.data !=
nullptr;
197 options.
load(parser,
false,
nullptr,
false);
211 myCgltfData->accessors,
212 myCgltfData->accessors_count);
216 myCgltfData->animations,
217 myCgltfData->animations_count);
221 myCgltfData->buffers,
222 myCgltfData->buffers_count);
226 myCgltfData->buffer_views,
227 myCgltfData->buffer_views_count);
231 myCgltfData->cameras,
232 myCgltfData->cameras_count);
237 myCgltfData->images_count);
242 myCgltfData->lights_count);
246 myCgltfData->materials,
247 myCgltfData->materials_count);
252 myCgltfData->meshes_count);
257 myCgltfData->nodes_count);
261 myCgltfData->textures,
262 myCgltfData->textures_count);
267 &myCgltfData->scenes, myCgltfData->scenes_count);
268 initProperty(&new_scene);
269 cgltf_size scene_id = myCgltfData->scenes_count - 1;
270 myCgltfData->scene =
reinterpret_cast<cgltf_scene*
>(scene_id + 1);
281 UT_ASSERT(mesh_id < myCgltfData->meshes_count);
282 cgltf_mesh& mesh = myCgltfData->meshes[mesh_id];
290 new_attrib, accessor_id, name,
291 INDEX_TO_CGLTF_PTR<cgltf_accessor>(accessor_id));
303 UT_ASSERT(mesh_id < myCgltfData->meshes_count);
304 cgltf_mesh& mesh = myCgltfData->meshes[mesh_id];
313 new_attrib, draco_id, name,
314 INDEX_TO_CGLTF_PTR<cgltf_accessor>(draco_id));
321 UT_ASSERT(mesh_id < myCgltfData->meshes_count);
322 cgltf_mesh& mesh = myCgltfData->meshes[mesh_id];
325 initProperty(&new_prim);
334 initProperty(&anim_sampler);
342 initProperty(&anim_channel);
351 const char* gltf_path,
359 #endif // __GLTF_CgltfWrapper_h__
void initCgltfData(bool writing_mode=false)
GLenum GLuint GLenum GLsizei const GLchar * buf
GLTF_Index CGLTF_PTR_TO_INDEX(T *ptr)
T *& appendPropertyRef(T ***propList, cgltf_size &propSize)
T * INDEX_TO_CGLTF_PTR(GLTF_Index id)
cgltf_scene & appendSceneAndSetToDefault()
cgltf_data * getCgltfData()
cgltf_size channels_count
void initAttribute(cgltf_attribute &attrib, cgltf_size accessor_index, const char *name, cgltf_accessor *data_accessor=nullptr)
cgltf_animation_sampler & appendAnimationSampler(cgltf_animation &anim)
cgltf_primitive * primitives
cgltf_extension * extensions
cgltf_attribute * attributes
static void writeCharProperty(char **prop, const char *src)
void initAsHoudiniAsset(cgltf_asset &asset)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
constexpr const char * cgltf_GltfVersion
GLint GLint GLsizei GLint GLenum GLenum type
constexpr const char * cgltf_GltfGenerator
cgltf_size primitives_count
bool load(const char *filename)
cgltf_primitive_type type
cgltf_attribute & appendAttribute(cgltf_size mesh_id, cgltf_size prim_id, cgltf_size accessor_id, cgltf_attribute_type type, const char *name)
T & appendProperty(T **propList, cgltf_size &propSize)
GLuint const GLchar * name
cgltf_size samplers_count
static UT_Options getExtrasAsOptions(const cgltf_extras &extras)
#define GLTF_DEFINE_APPEND_FUNC(func_name, cgltf_type, container, count_member)
static void initProperty(T *prop)
void setMainBuffer(cgltf_buffer &buf, uint8_t *data, cgltf_size size)
A map of string to various well defined value types.
cgltf_primitive & appendPrimitive(cgltf_size mesh_id)
cgltf_size attributes_count
cgltf_attribute * attributes
cgltf_animation_sampler * samplers
cgltf_animation_channel * channels
cgltf_attribute & appendDracoAttribute(cgltf_size mesh_id, cgltf_size prim_id, cgltf_size draco_id, cgltf_attribute_type type, const char *name)
cgltf_draco_mesh_compression draco_mesh_compression
cgltf_animation_channel & appendAnimationChannel(cgltf_animation &anim)
cgltf_size attributes_count
cgltf_attribute_type type
void setCgltfData(UT_UniquePtr< cgltf_data, CgltfDataDeleter > &&data)
const cgltf_options & getCgltfOptions() const
static bool propHasExtras(const T *prop)
cgltf_options & getCgltfOptions()
const cgltf_data * getCgltfData() const