Debian Codegraph @

thirdparty/ufbx/ufbx.h

raw symbols SCIP
1 #ifndef UFBX_UFBX_H_INCLUDED
2 #define UFBX_UFBX_H_INCLUDED
3
4 // -- User configuration
5
6 #if defined(UFBX_CONFIG_HEADER)
7 #include UFBX_CONFIG_HEADER
8 #endif
9
10 // -- Headers
11
12 #if !defined(UFBX_NO_LIBC_TYPES)
13 #include <stdint.h>
14 #include <stddef.h>
15 #include <stdbool.h>
16 #endif
17
18 // -- Platform
19
20 #ifndef UFBX_STDC
21 #if defined(__STDC_VERSION__)
22 #define UFBX_STDC __STDC_VERSION__
23 #else
24 #define UFBX_STDC 0
25 #endif
26 #endif
27
28 #ifndef UFBX_CPP
29 #if defined(__cplusplus)
30 #define UFBX_CPP __cplusplus
31 #else
32 #define UFBX_CPP 0
33 #endif
34 #endif
35
36 #ifndef UFBX_PLATFORM_MSC
37 #if !defined(UFBX_STANDARD_C) && defined(_MSC_VER)
38 #define UFBX_PLATFORM_MSC _MSC_VER
39 #else
40 #define UFBX_PLATFORM_MSC 0
41 #endif
42 #endif
43
44 #ifndef UFBX_PLATFORM_GNUC
45 #if !defined(UFBX_STANDARD_C) && defined(__GNUC__)
46 #define UFBX_PLATFORM_GNUC __GNUC__
47 #else
48 #define UFBX_PLATFORM_GNUC 0
49 #endif
50 #endif
51
52 #ifndef UFBX_CPP11
53 // MSVC does not advertise C++11 by default so we need special detection
54 #if UFBX_CPP >= 201103L || (UFBX_CPP > 0 && UFBX_PLATFORM_MSC >= 1900)
55 #define UFBX_CPP11 1
56 #else
57 #define UFBX_CPP11 0
58 #endif
59 #endif
60
61 #if defined(_MSC_VER)
62 #pragma warning(push)
63 #pragma warning(disable: 4061) // enumerator 'ENUM' in switch of enum 'enum' is not explicitly handled by a case label
64 #pragma warning(disable: 4201) // nonstandard extension used: nameless struct/union
65 #pragma warning(disable: 4505) // unreferenced local function has been removed
66 #pragma warning(disable: 4820) // type': 'N' bytes padding added after data member 'member'
67 #elif defined(__clang__)
68 #pragma clang diagnostic push
69 #pragma clang diagnostic ignored "-Wpedantic"
70 #pragma clang diagnostic ignored "-Wpadded"
71 #if defined(__cplusplus)
72 #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
73 #pragma clang diagnostic ignored "-Wold-style-cast"
74 #endif
75 #elif defined(__GNUC__)
76 #pragma GCC diagnostic push
77 #pragma GCC diagnostic ignored "-Wpedantic"
78 #pragma GCC diagnostic ignored "-Wpadded"
79 #if defined(__cplusplus)
80 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
81 #pragma GCC diagnostic ignored "-Wold-style-cast"
82 #else
83 #if __GNUC__ >= 5
84 #pragma GCC diagnostic ignored "-Wc90-c99-compat"
85 #pragma GCC diagnostic ignored "-Wc99-c11-compat"
86 #endif
87 #endif
88 #endif
89
90 #if UFBX_PLATFORM_MSC
91 #define ufbx_inline static __forceinline
92 #elif UFBX_PLATFORM_GNUC
93 #define ufbx_inline static inline __attribute__((always_inline, unused))
94 #else
95 #define ufbx_inline static
96 #endif
97
98 // Assertion function used in ufbx, defaults to C standard `assert()`.
99 // You can define this to your custom preferred assert macro, but in that case
100 // make sure that it is also used within `ufbx.c`.
101 // Defining `UFBX_NO_ASSERT` to any value disables assertions.
102 #ifndef ufbx_assert
103 #if defined(UFBX_NO_ASSERT) || defined(UFBX_NO_LIBC)
104 #define ufbx_assert(cond) (void)0
105 #else
106 #include <assert.h>
107 #define ufbx_assert(cond) assert(cond)
108 #endif
109 #endif
110
111 // Pointer may be `NULL`.
112 #define ufbx_nullable
113
114 // Changing this value from default or calling this function can lead into
115 // breaking API guarantees.
116 #define ufbx_unsafe
117
118 // Linkage of the main ufbx API functions.
119 // Defaults to nothing, or `static` if `UFBX_STATIC` is defined.
120 // If you want to isolate ufbx to a single translation unit you can do the following:
121 // #define UFBX_STATIC
122 // #include "ufbx.h"
123 // #include "ufbx.c"
124 #ifndef ufbx_abi
125 #if defined(UFBX_STATIC)
126 #define ufbx_abi static
127 #else
128 #define ufbx_abi
129 #endif
130 #endif
131
132 // Linkage of the main ufbx data fields in the header.
133 // Defaults to `extern`, or `static` if `UFBX_STATIC` is defined.
134 #ifndef ufbx_abi_data
135 #if defined(UFBX_STATIC)
136 #define ufbx_abi_data static
137 #else
138 #define ufbx_abi_data extern
139 #endif
140 #endif
141
142 // Linkage of the main ufbx data fields in the source.
143 // Defaults to nothing, or `static` if `UFBX_STATIC` is defined.
144 #ifndef ufbx_abi_data_definition
145 #if defined(UFBX_STATIC)
146 #define ufbx_abi_data_def static
147 #else
148 #define ufbx_abi_data_def
149 #endif
150 #endif
151
152 // -- Configuration
153
154 #ifndef UFBX_REAL_TYPE
155 #if defined(UFBX_REAL_IS_FLOAT)
156 #define UFBX_REAL_TYPE float
157 #else
158 #define UFBX_REAL_TYPE double
159 #endif
160 #endif
161
162 // Limits for embedded arrays within structures.
163 #define UFBX_ERROR_STACK_MAX_DEPTH 8
164 #define UFBX_PANIC_MESSAGE_LENGTH 128
165 #define UFBX_ERROR_INFO_LENGTH 256
166
167 // Number of thread groups to use if threading is enabled.
168 // A thread group processes a number of tasks and is then waited and potentially
169 // re-used later. In essence, this controls the granularity of threading.
170 #define UFBX_THREAD_GROUP_COUNT 4
171
172 // -- Language
173
174 // bindgen-disable
175
176 #if UFBX_CPP11
177
178 template <typename T, typename U>
179 struct ufbxi_type_is { };
180
181 template <typename T>
182 struct ufbxi_type_is<T, T> { using type = int; };
183
184 template <typename T>
185 struct ufbx_converter { };
186
187 #define UFBX_CONVERSION_IMPL(p_name) \
188 template <typename T, typename S=typename ufbxi_type_is<T, decltype(ufbx_converter<T>::from(*(const p_name*)nullptr))>::type> \
189 operator T() const { return ufbx_converter<T>::from(*this); }
190
191 #define UFBX_CONVERSION_TO_IMPL(p_name) \
192 template <typename T, typename S=typename ufbxi_type_is<p_name, decltype(ufbx_converter<T>::to(*(const T*)nullptr))>::type> \
193 p_name(const T &t) { *this = ufbx_converter<T>::to(t); }
194
195 #define UFBX_CONVERSION_LIST_IMPL(p_name) \
196 template <typename T, typename S=typename ufbxi_type_is<T, decltype(ufbx_converter<T>::from_list((p_name*)nullptr, (size_t)0))>::type> \
197 operator T() const { return ufbx_converter<T>::from_list(data, count); }
198
199 #else
200
201 #define UFBX_CONVERSION_IMPL(p_name)
202 #define UFBX_CONVERSION_TO_IMPL(p_name)
203 #define UFBX_CONVERSION_LIST_IMPL(p_name)
204
205 #endif
206
207 #if defined(__cplusplus)
208 #define UFBX_LIST_TYPE(p_name, p_type) struct p_name { p_type *data; size_t count; \
209 p_type &operator[](size_t index) const { ufbx_assert(index < count); return data[index]; } \
210 p_type *begin() const { return data; } \
211 p_type *end() const { return data + count; } \
212 UFBX_CONVERSION_LIST_IMPL(p_type) \
213 }
214 #else
215 #define UFBX_LIST_TYPE(p_name, p_type) typedef struct p_name { p_type *data; size_t count; } p_name
216 #endif
217
218 // This cannot be enabled automatically if supported as the source file may be
219 // compiled with a different compiler using different settings than the header
220 // consumers, in practice it should work but it causes issues such as #70.
221 #if (UFBX_STDC >= 202311L || UFBX_CPP11) && defined(UFBX_USE_EXPLICIT_ENUM)
222 #define UFBX_ENUM_REPR : int
223 #define UFBX_ENUM_FORCE_WIDTH(p_prefix)
224 #define UFBX_FLAG_REPR : int
225 #define UFBX_FLAG_FORCE_WIDTH(p_prefix)
226 #define UFBX_HAS_FORCE_32BIT 0
227 #else
228 #define UFBX_ENUM_REPR
229 #define UFBX_ENUM_FORCE_WIDTH(p_prefix) p_prefix##_FORCE_32BIT = 0x7fffffff
230 #define UFBX_FLAG_REPR
231 #define UFBX_FLAG_FORCE_WIDTH(p_prefix) p_prefix##_FORCE_32BIT = 0x7fffffff
232 #define UFBX_HAS_FORCE_32BIT 1
233 #endif
234
235 #define UFBX_ENUM_TYPE(p_name, p_prefix, p_last) \
236 enum { p_prefix##_COUNT = p_last + 1 }
237
238 #if UFBX_CPP
239 #define UFBX_VERTEX_ATTRIB_IMPL(p_type) \
240 p_type &operator[](size_t index) const { ufbx_assert(index < indices.count); return values.data[indices.data[index]]; }
241 #else
242 #define UFBX_VERTEX_ATTRIB_IMPL(p_type)
243 #endif
244
245 #if UFBX_CPP11
246 #define UFBX_CALLBACK_IMPL(p_name, p_fn, p_return, p_params, p_args) \
247 template <typename F> static p_return _cpp_adapter p_params { F &f = *static_cast<F*>(user); return f p_args; } \
248 p_name() = default; \
249 p_name(p_fn *f) : fn(f), user(nullptr) { } \
250 template <typename F> p_name(F *f) : fn(&_cpp_adapter<F>), user(static_cast<void*>(f)) { }
251 #else
252 #define UFBX_CALLBACK_IMPL(p_name, p_fn, p_return, p_params, p_args)
253 #endif
254
255 // bindgen-enable
256
257 // -- Version
258
259 // Packing/unpacking for `UFBX_HEADER_VERSION` and `ufbx_source_version`.
260 #define ufbx_pack_version(major, minor, patch) ((major)*1000000u + (minor)*1000u + (patch))
261 #define ufbx_version_major(version) ((uint32_t)(version)/1000000u%1000u)
262 #define ufbx_version_minor(version) ((uint32_t)(version)/1000u%1000u)
263 #define ufbx_version_patch(version) ((uint32_t)(version)%1000u)
264
265 // Version of the ufbx header.
266 // `UFBX_VERSION` is simply an alias of `UFBX_HEADER_VERSION`.
267 // `ufbx_source_version` contains the version of the corresponding source file.
268 // HINT: The version can be compared numerically to the result of `ufbx_pack_version()`,
269 // for example `#if UFBX_VERSION >= ufbx_pack_version(0, 12, 0)`.
270 #define UFBX_HEADER_VERSION ufbx_pack_version(0, 20, 0)
271 #define UFBX_VERSION UFBX_HEADER_VERSION
272
273 // -- Basic types
274
275 // Main floating point type used everywhere in ufbx, defaults to `double`.
276 // If you define `UFBX_REAL_IS_FLOAT` to any value, `ufbx_real` will be defined
277 // as `float` instead.
278 // You can also manually define `UFBX_REAL_TYPE` to any floating point type.
279 typedef UFBX_REAL_TYPE ufbx_real;
280
281 // Null-terminated UTF-8 encoded string within an FBX file
282 typedef struct ufbx_string {
283 const char *data;
284 size_t length;
285
286 UFBX_CONVERSION_IMPL(ufbx_string)
287 } ufbx_string;
288
289 // Opaque byte buffer blob
290 typedef struct ufbx_blob {
291 const void *data;
292 size_t size;
293
294 UFBX_CONVERSION_IMPL(ufbx_blob)
295 } ufbx_blob;
296
297 // 2D vector
298 typedef struct ufbx_vec2 {
299 union {
300 struct { ufbx_real x, y; };
301 ufbx_real v[2];
302 };
303
304 UFBX_CONVERSION_IMPL(ufbx_vec2)
305 } ufbx_vec2;
306
307 // 3D vector
308 typedef struct ufbx_vec3 {
309 union {
310 struct { ufbx_real x, y, z; };
311 ufbx_real v[3];
312 };
313
314 UFBX_CONVERSION_IMPL(ufbx_vec3)
315 } ufbx_vec3;
316
317 // 4D vector
318 typedef struct ufbx_vec4 {
319 union {
320 struct { ufbx_real x, y, z, w; };
321 ufbx_real v[4];
322 };
323
324 UFBX_CONVERSION_IMPL(ufbx_vec4)
325 } ufbx_vec4;
326
327 // Quaternion
328 typedef struct ufbx_quat {
329 union {
330 struct { ufbx_real x, y, z, w; };
331 ufbx_real v[4];
332 };
333
334 UFBX_CONVERSION_IMPL(ufbx_quat)
335 } ufbx_quat;
336
337 // Order in which Euler-angle rotation axes are applied for a transform
338 // NOTE: The order in the name refers to the order of axes *applied*,
339 // not the multiplication order: eg. `UFBX_ROTATION_ORDER_XYZ` is `Z*Y*X`
340 // [TODO: Figure out what the spheric rotation order is...]
341 typedef enum ufbx_rotation_order UFBX_ENUM_REPR {
342 UFBX_ROTATION_ORDER_XYZ,
343 UFBX_ROTATION_ORDER_XZY,
344 UFBX_ROTATION_ORDER_YZX,
345 UFBX_ROTATION_ORDER_YXZ,
346 UFBX_ROTATION_ORDER_ZXY,
347 UFBX_ROTATION_ORDER_ZYX,
348 UFBX_ROTATION_ORDER_SPHERIC,
349
350 UFBX_ENUM_FORCE_WIDTH(UFBX_ROTATION_ORDER)
351 } ufbx_rotation_order;
352
353 UFBX_ENUM_TYPE(ufbx_rotation_order, UFBX_ROTATION_ORDER, UFBX_ROTATION_ORDER_SPHERIC);
354
355 // Explicit translation+rotation+scale transformation.
356 // NOTE: Rotation is a quaternion, not Euler angles!
357 typedef struct ufbx_transform {
358 ufbx_vec3 translation;
359 ufbx_quat rotation;
360 ufbx_vec3 scale;
361
362 UFBX_CONVERSION_IMPL(ufbx_transform)
363 } ufbx_transform;
364
365 // 4x3 matrix encoding an affine transformation.
366 // `cols[0..2]` are the X/Y/Z basis vectors, `cols[3]` is the translation
367 typedef struct ufbx_matrix {
368 union {
369 struct {
370 ufbx_real m00, m10, m20;
371 ufbx_real m01, m11, m21;
372 ufbx_real m02, m12, m22;
373 ufbx_real m03, m13, m23;
374 };
375 ufbx_vec3 cols[4];
376 ufbx_real v[12];
377 };
378
379 UFBX_CONVERSION_IMPL(ufbx_matrix)
380 } ufbx_matrix;
381
382 typedef struct ufbx_void_list {
383 void *data;
384 size_t count;
385 } ufbx_void_list;
386
387 UFBX_LIST_TYPE(ufbx_bool_list, bool);
388 UFBX_LIST_TYPE(ufbx_uint32_list, uint32_t);
389 UFBX_LIST_TYPE(ufbx_real_list, ufbx_real);
390 UFBX_LIST_TYPE(ufbx_vec2_list, ufbx_vec2);
391 UFBX_LIST_TYPE(ufbx_vec3_list, ufbx_vec3);
392 UFBX_LIST_TYPE(ufbx_vec4_list, ufbx_vec4);
393 UFBX_LIST_TYPE(ufbx_string_list, ufbx_string);
394
395 // Sentinel value used to represent a missing index.
396 #define UFBX_NO_INDEX ((uint32_t)~0u)
397
398 // -- Document object model
399
400 typedef enum ufbx_dom_value_type UFBX_ENUM_REPR {
401 UFBX_DOM_VALUE_NUMBER,
402 UFBX_DOM_VALUE_STRING,
403 UFBX_DOM_VALUE_BLOB,
404 UFBX_DOM_VALUE_ARRAY_I32,
405 UFBX_DOM_VALUE_ARRAY_I64,
406 UFBX_DOM_VALUE_ARRAY_F32,
407 UFBX_DOM_VALUE_ARRAY_F64,
408 UFBX_DOM_VALUE_ARRAY_BLOB,
409 UFBX_DOM_VALUE_ARRAY_IGNORED,
410
411 UFBX_ENUM_FORCE_WIDTH(UFBX_DOM_VALUE_TYPE)
412 } ufbx_dom_value_type;
413
414 UFBX_ENUM_TYPE(ufbx_dom_value_type, UFBX_DOM_VALUE_TYPE, UFBX_DOM_VALUE_ARRAY_IGNORED);
415
416 typedef struct ufbx_dom_node ufbx_dom_node;
417
418 UFBX_LIST_TYPE(ufbx_int32_list, int32_t);
419 UFBX_LIST_TYPE(ufbx_int64_list, int64_t);
420 UFBX_LIST_TYPE(ufbx_float_list, float);
421 UFBX_LIST_TYPE(ufbx_double_list, double);
422 UFBX_LIST_TYPE(ufbx_blob_list, ufbx_blob);
423
424 typedef struct ufbx_dom_value {
425 ufbx_dom_value_type type;
426 ufbx_string value_str;
427 ufbx_blob value_blob;
428 int64_t value_int;
429 double value_float;
430 } ufbx_dom_value;
431
432 UFBX_LIST_TYPE(ufbx_dom_node_list, ufbx_dom_node*);
433 UFBX_LIST_TYPE(ufbx_dom_value_list, ufbx_dom_value);
434
435 struct ufbx_dom_node {
436 ufbx_string name;
437 ufbx_dom_node_list children;
438 ufbx_dom_value_list values;
439 };
440
441 // -- Properties
442
443 // FBX elements have properties which are arbitrary key/value pairs that can
444 // have inherited default values or be animated. In most cases you don't need
445 // to access these unless you need a feature not implemented directly in ufbx.
446 // NOTE: Prefer using `ufbx_find_prop[_len](...)` to search for a property by
447 // name as it can find it from the defaults if necessary.
448
449 typedef struct ufbx_prop ufbx_prop;
450 typedef struct ufbx_props ufbx_props;
451
452 // Data type contained within the property. All the data fields are always
453 // populated regardless of type, so there's no need to switch by type usually
454 // eg. `prop->value_real` and `prop->value_int` have the same value (well, close)
455 // if `prop->type == UFBX_PROP_INTEGER`. String values are not converted from/to.
456 typedef enum ufbx_prop_type UFBX_ENUM_REPR {
457 UFBX_PROP_UNKNOWN,
458 UFBX_PROP_BOOLEAN,
459 UFBX_PROP_INTEGER,
460 UFBX_PROP_NUMBER,
461 UFBX_PROP_VECTOR,
462 UFBX_PROP_COLOR,
463 UFBX_PROP_COLOR_WITH_ALPHA,
464 UFBX_PROP_STRING,
465 UFBX_PROP_DATE_TIME,
466 UFBX_PROP_TRANSLATION,
467 UFBX_PROP_ROTATION,
468 UFBX_PROP_SCALING,
469 UFBX_PROP_DISTANCE,
470 UFBX_PROP_COMPOUND,
471 UFBX_PROP_BLOB,
472 UFBX_PROP_REFERENCE,
473
474 UFBX_ENUM_FORCE_WIDTH(UFBX_PROP_TYPE)
475 } ufbx_prop_type;
476
477 UFBX_ENUM_TYPE(ufbx_prop_type, UFBX_PROP_TYPE, UFBX_PROP_REFERENCE);
478
479 // Property flags: Advanced information about properties, not usually needed.
480 typedef enum ufbx_prop_flags UFBX_FLAG_REPR {
481 // Supports animation.
482 // NOTE: ufbx ignores this and allows animations on non-animatable properties.
483 UFBX_PROP_FLAG_ANIMATABLE = 0x1,
484
485 // User defined (custom) property.
486 UFBX_PROP_FLAG_USER_DEFINED = 0x2,
487
488 // Hidden in UI.
489 UFBX_PROP_FLAG_HIDDEN = 0x4,
490
491 // Disallow modification from UI for components.
492 UFBX_PROP_FLAG_LOCK_X = 0x10,
493 UFBX_PROP_FLAG_LOCK_Y = 0x20,
494 UFBX_PROP_FLAG_LOCK_Z = 0x40,
495 UFBX_PROP_FLAG_LOCK_W = 0x80,
496
497 // Disable animation from components.
498 UFBX_PROP_FLAG_MUTE_X = 0x100,
499 UFBX_PROP_FLAG_MUTE_Y = 0x200,
500 UFBX_PROP_FLAG_MUTE_Z = 0x400,
501 UFBX_PROP_FLAG_MUTE_W = 0x800,
502
503 // Property created by ufbx when an element has a connected `ufbx_anim_prop`
504 // but doesn't contain the `ufbx_prop` it's referring to.
505 // NOTE: The property may have been found in the templated defaults.
506 UFBX_PROP_FLAG_SYNTHETIC = 0x1000,
507
508 // The property has at least one `ufbx_anim_prop` in some layer.
509 UFBX_PROP_FLAG_ANIMATED = 0x2000,
510
511 // Used by `ufbx_evaluate_prop()` to indicate the the property was not found.
512 UFBX_PROP_FLAG_NOT_FOUND = 0x4000,
513
514 // The property is connected to another one.
515 // This use case is relatively rare so `ufbx_prop` does not track connections
516 // directly. You can find connections from `ufbx_element.connections_dst` where
517 // `ufbx_connection.dst_prop` is this property and `ufbx_connection.src_prop` is defined.
518 UFBX_PROP_FLAG_CONNECTED = 0x8000,
519
520 // The value of this property is undefined (represented as zero).
521 UFBX_PROP_FLAG_NO_VALUE = 0x10000,
522
523 // This property has been overridden by the user.
524 // See `ufbx_anim.prop_overrides` for more information.
525 UFBX_PROP_FLAG_OVERRIDDEN = 0x20000,
526
527 // Value type.
528 // `REAL/VEC2/VEC3/VEC4` are mutually exclusive but may coexist with eg. `STRING`
529 // in some rare cases where the string defines the unit for the vector.
530 UFBX_PROP_FLAG_VALUE_REAL = 0x100000,
531 UFBX_PROP_FLAG_VALUE_VEC2 = 0x200000,
532 UFBX_PROP_FLAG_VALUE_VEC3 = 0x400000,
533 UFBX_PROP_FLAG_VALUE_VEC4 = 0x800000,
534 UFBX_PROP_FLAG_VALUE_INT = 0x1000000,
535 UFBX_PROP_FLAG_VALUE_STR = 0x2000000,
536 UFBX_PROP_FLAG_VALUE_BLOB = 0x4000000,
537
538 UFBX_FLAG_FORCE_WIDTH(UFBX_PROP_FLAGS)
539 } ufbx_prop_flags;
540
541 // Single property with name/type/value.
542 struct ufbx_prop {
543 ufbx_string name;
544
545 uint32_t _internal_key;
546
547 ufbx_prop_type type;
548 ufbx_prop_flags flags;
549
550 ufbx_string value_str;
551 ufbx_blob value_blob;
552 int64_t value_int;
553 union {
554 ufbx_real value_real_arr[4];
555 ufbx_real value_real;
556 ufbx_vec2 value_vec2;
557 ufbx_vec3 value_vec3;
558 ufbx_vec4 value_vec4;
559 };
560 };
561
562 UFBX_LIST_TYPE(ufbx_prop_list, ufbx_prop);
563
564 // List of alphabetically sorted properties with potential defaults.
565 // For animated objects in as scene from `ufbx_evaluate_scene()` this list
566 // only has the animated properties, the originals are stored under `defaults`.
567 struct ufbx_props {
568 ufbx_prop_list props;
569 size_t num_animated;
570
571 ufbx_nullable ufbx_props *defaults;
572 };
573
574 typedef struct ufbx_scene ufbx_scene;
575
576 // -- Elements
577
578 // Element is the lowest level representation of the FBX file in ufbx.
579 // An element contains type, id, name, and properties (see `ufbx_props` above)
580 // Elements may be connected to each other arbitrarily via `ufbx_connection`
581
582 typedef struct ufbx_element ufbx_element;
583
584 // Unknown
585 typedef struct ufbx_unknown ufbx_unknown;
586
587 // Nodes
588 typedef struct ufbx_node ufbx_node;
589
590 // Node attributes (common)
591 typedef struct ufbx_mesh ufbx_mesh;
592 typedef struct ufbx_light ufbx_light;
593 typedef struct ufbx_camera ufbx_camera;
594 typedef struct ufbx_bone ufbx_bone;
595 typedef struct ufbx_empty ufbx_empty;
596
597 // Node attributes (curves/surfaces)
598 typedef struct ufbx_line_curve ufbx_line_curve;
599 typedef struct ufbx_nurbs_curve ufbx_nurbs_curve;
600 typedef struct ufbx_nurbs_surface ufbx_nurbs_surface;
601 typedef struct ufbx_nurbs_trim_surface ufbx_nurbs_trim_surface;
602 typedef struct ufbx_nurbs_trim_boundary ufbx_nurbs_trim_boundary;
603
604 // Node attributes (advanced)
605 typedef struct ufbx_procedural_geometry ufbx_procedural_geometry;
606 typedef struct ufbx_stereo_camera ufbx_stereo_camera;
607 typedef struct ufbx_camera_switcher ufbx_camera_switcher;
608 typedef struct ufbx_marker ufbx_marker;
609 typedef struct ufbx_lod_group ufbx_lod_group;
610
611 // Deformers
612 typedef struct ufbx_skin_deformer ufbx_skin_deformer;
613 typedef struct ufbx_skin_cluster ufbx_skin_cluster;
614 typedef struct ufbx_blend_deformer ufbx_blend_deformer;
615 typedef struct ufbx_blend_channel ufbx_blend_channel;
616 typedef struct ufbx_blend_shape ufbx_blend_shape;
617 typedef struct ufbx_cache_deformer ufbx_cache_deformer;
618 typedef struct ufbx_cache_file ufbx_cache_file;
619
620 // Materials
621 typedef struct ufbx_material ufbx_material;
622 typedef struct ufbx_texture ufbx_texture;
623 typedef struct ufbx_video ufbx_video;
624 typedef struct ufbx_shader ufbx_shader;
625 typedef struct ufbx_shader_binding ufbx_shader_binding;
626
627 // Animation
628 typedef struct ufbx_anim_stack ufbx_anim_stack;
629 typedef struct ufbx_anim_layer ufbx_anim_layer;
630 typedef struct ufbx_anim_value ufbx_anim_value;
631 typedef struct ufbx_anim_curve ufbx_anim_curve;
632
633 // Collections
634 typedef struct ufbx_display_layer ufbx_display_layer;
635 typedef struct ufbx_selection_set ufbx_selection_set;
636 typedef struct ufbx_selection_node ufbx_selection_node;
637
638 // Constraints
639 typedef struct ufbx_character ufbx_character;
640 typedef struct ufbx_constraint ufbx_constraint;
641
642 // Audio
643 typedef struct ufbx_audio_layer ufbx_audio_layer;
644 typedef struct ufbx_audio_clip ufbx_audio_clip;
645
646 // Miscellaneous
647 typedef struct ufbx_pose ufbx_pose;
648 typedef struct ufbx_metadata_object ufbx_metadata_object;
649
650 UFBX_LIST_TYPE(ufbx_element_list, ufbx_element*);
651 UFBX_LIST_TYPE(ufbx_unknown_list, ufbx_unknown*);
652 UFBX_LIST_TYPE(ufbx_node_list, ufbx_node*);
653 UFBX_LIST_TYPE(ufbx_mesh_list, ufbx_mesh*);
654 UFBX_LIST_TYPE(ufbx_light_list, ufbx_light*);
655 UFBX_LIST_TYPE(ufbx_camera_list, ufbx_camera*);
656 UFBX_LIST_TYPE(ufbx_bone_list, ufbx_bone*);
657 UFBX_LIST_TYPE(ufbx_empty_list, ufbx_empty*);
658 UFBX_LIST_TYPE(ufbx_line_curve_list, ufbx_line_curve*);
659 UFBX_LIST_TYPE(ufbx_nurbs_curve_list, ufbx_nurbs_curve*);
660 UFBX_LIST_TYPE(ufbx_nurbs_surface_list, ufbx_nurbs_surface*);
661 UFBX_LIST_TYPE(ufbx_nurbs_trim_surface_list, ufbx_nurbs_trim_surface*);
662 UFBX_LIST_TYPE(ufbx_nurbs_trim_boundary_list, ufbx_nurbs_trim_boundary*);
663 UFBX_LIST_TYPE(ufbx_procedural_geometry_list, ufbx_procedural_geometry*);
664 UFBX_LIST_TYPE(ufbx_stereo_camera_list, ufbx_stereo_camera*);
665 UFBX_LIST_TYPE(ufbx_camera_switcher_list, ufbx_camera_switcher*);
666 UFBX_LIST_TYPE(ufbx_marker_list, ufbx_marker*);
667 UFBX_LIST_TYPE(ufbx_lod_group_list, ufbx_lod_group*);
668 UFBX_LIST_TYPE(ufbx_skin_deformer_list, ufbx_skin_deformer*);
669 UFBX_LIST_TYPE(ufbx_skin_cluster_list, ufbx_skin_cluster*);
670 UFBX_LIST_TYPE(ufbx_blend_deformer_list, ufbx_blend_deformer*);
671 UFBX_LIST_TYPE(ufbx_blend_channel_list, ufbx_blend_channel*);
672 UFBX_LIST_TYPE(ufbx_blend_shape_list, ufbx_blend_shape*);
673 UFBX_LIST_TYPE(ufbx_cache_deformer_list, ufbx_cache_deformer*);
674 UFBX_LIST_TYPE(ufbx_cache_file_list, ufbx_cache_file*);
675 UFBX_LIST_TYPE(ufbx_material_list, ufbx_material*);
676 UFBX_LIST_TYPE(ufbx_texture_list, ufbx_texture*);
677 UFBX_LIST_TYPE(ufbx_video_list, ufbx_video*);
678 UFBX_LIST_TYPE(ufbx_shader_list, ufbx_shader*);
679 UFBX_LIST_TYPE(ufbx_shader_binding_list, ufbx_shader_binding*);
680 UFBX_LIST_TYPE(ufbx_anim_stack_list, ufbx_anim_stack*);
681 UFBX_LIST_TYPE(ufbx_anim_layer_list, ufbx_anim_layer*);
682 UFBX_LIST_TYPE(ufbx_anim_value_list, ufbx_anim_value*);
683 UFBX_LIST_TYPE(ufbx_anim_curve_list, ufbx_anim_curve*);
684 UFBX_LIST_TYPE(ufbx_display_layer_list, ufbx_display_layer*);
685 UFBX_LIST_TYPE(ufbx_selection_set_list, ufbx_selection_set*);
686 UFBX_LIST_TYPE(ufbx_selection_node_list, ufbx_selection_node*);
687 UFBX_LIST_TYPE(ufbx_character_list, ufbx_character*);
688 UFBX_LIST_TYPE(ufbx_constraint_list, ufbx_constraint*);
689 UFBX_LIST_TYPE(ufbx_audio_layer_list, ufbx_audio_layer*);
690 UFBX_LIST_TYPE(ufbx_audio_clip_list, ufbx_audio_clip*);
691 UFBX_LIST_TYPE(ufbx_pose_list, ufbx_pose*);
692 UFBX_LIST_TYPE(ufbx_metadata_object_list, ufbx_metadata_object*);
693
694 typedef enum ufbx_element_type UFBX_ENUM_REPR {
695 UFBX_ELEMENT_UNKNOWN, // < `ufbx_unknown`
696 UFBX_ELEMENT_NODE, // < `ufbx_node`
697 UFBX_ELEMENT_MESH, // < `ufbx_mesh`
698 UFBX_ELEMENT_LIGHT, // < `ufbx_light`
699 UFBX_ELEMENT_CAMERA, // < `ufbx_camera`
700 UFBX_ELEMENT_BONE, // < `ufbx_bone`
701 UFBX_ELEMENT_EMPTY, // < `ufbx_empty`
702 UFBX_ELEMENT_LINE_CURVE, // < `ufbx_line_curve`
703 UFBX_ELEMENT_NURBS_CURVE, // < `ufbx_nurbs_curve`
704 UFBX_ELEMENT_NURBS_SURFACE, // < `ufbx_nurbs_surface`
705 UFBX_ELEMENT_NURBS_TRIM_SURFACE, // < `ufbx_nurbs_trim_surface`
706 UFBX_ELEMENT_NURBS_TRIM_BOUNDARY, // < `ufbx_nurbs_trim_boundary`
707 UFBX_ELEMENT_PROCEDURAL_GEOMETRY, // < `ufbx_procedural_geometry`
708 UFBX_ELEMENT_STEREO_CAMERA, // < `ufbx_stereo_camera`
709 UFBX_ELEMENT_CAMERA_SWITCHER, // < `ufbx_camera_switcher`
710 UFBX_ELEMENT_MARKER, // < `ufbx_marker`
711 UFBX_ELEMENT_LOD_GROUP, // < `ufbx_lod_group`
712 UFBX_ELEMENT_SKIN_DEFORMER, // < `ufbx_skin_deformer`
713 UFBX_ELEMENT_SKIN_CLUSTER, // < `ufbx_skin_cluster`
714 UFBX_ELEMENT_BLEND_DEFORMER, // < `ufbx_blend_deformer`
715 UFBX_ELEMENT_BLEND_CHANNEL, // < `ufbx_blend_channel`
716 UFBX_ELEMENT_BLEND_SHAPE, // < `ufbx_blend_shape`
717 UFBX_ELEMENT_CACHE_DEFORMER, // < `ufbx_cache_deformer`
718 UFBX_ELEMENT_CACHE_FILE, // < `ufbx_cache_file`
719 UFBX_ELEMENT_MATERIAL, // < `ufbx_material`
720 UFBX_ELEMENT_TEXTURE, // < `ufbx_texture`
721 UFBX_ELEMENT_VIDEO, // < `ufbx_video`
722 UFBX_ELEMENT_SHADER, // < `ufbx_shader`
723 UFBX_ELEMENT_SHADER_BINDING, // < `ufbx_shader_binding`
724 UFBX_ELEMENT_ANIM_STACK, // < `ufbx_anim_stack`
725 UFBX_ELEMENT_ANIM_LAYER, // < `ufbx_anim_layer`
726 UFBX_ELEMENT_ANIM_VALUE, // < `ufbx_anim_value`
727 UFBX_ELEMENT_ANIM_CURVE, // < `ufbx_anim_curve`
728 UFBX_ELEMENT_DISPLAY_LAYER, // < `ufbx_display_layer`
729 UFBX_ELEMENT_SELECTION_SET, // < `ufbx_selection_set`
730 UFBX_ELEMENT_SELECTION_NODE, // < `ufbx_selection_node`
731 UFBX_ELEMENT_CHARACTER, // < `ufbx_character`
732 UFBX_ELEMENT_CONSTRAINT, // < `ufbx_constraint`
733 UFBX_ELEMENT_AUDIO_LAYER, // < `ufbx_audio_layer`
734 UFBX_ELEMENT_AUDIO_CLIP, // < `ufbx_audio_clip`
735 UFBX_ELEMENT_POSE, // < `ufbx_pose`
736 UFBX_ELEMENT_METADATA_OBJECT, // < `ufbx_metadata_object`
737
738 UFBX_ELEMENT_TYPE_FIRST_ATTRIB = UFBX_ELEMENT_MESH,
739 UFBX_ELEMENT_TYPE_LAST_ATTRIB = UFBX_ELEMENT_LOD_GROUP,
740
741 UFBX_ENUM_FORCE_WIDTH(UFBX_ELEMENT_TYPE)
742 } ufbx_element_type;
743
744 UFBX_ENUM_TYPE(ufbx_element_type, UFBX_ELEMENT_TYPE, UFBX_ELEMENT_METADATA_OBJECT);
745
746 // Connection between two elements.
747 // Source and destination are somewhat arbitrary but the destination is
748 // often the "container" like a parent node or mesh containing a deformer.
749 typedef struct ufbx_connection {
750 ufbx_element *src;
751 ufbx_element *dst;
752 ufbx_string src_prop;
753 ufbx_string dst_prop;
754 } ufbx_connection;
755
756 UFBX_LIST_TYPE(ufbx_connection_list, ufbx_connection);
757
758 // Element "base-class" common to each element.
759 // Some fields (like `connections_src`) are advanced and not visible
760 // in the specialized element structs.
761 // NOTE: The `element_id` value is consistent when loading the
762 // _same_ file, but re-exporting the file will invalidate them.
763 struct ufbx_element {
764 ufbx_string name;
765 ufbx_props props;
766 uint32_t element_id;
767 uint32_t typed_id;
768 ufbx_node_list instances;
769 ufbx_element_type type;
770 ufbx_connection_list connections_src;
771 ufbx_connection_list connections_dst;
772 ufbx_nullable ufbx_dom_node *dom_node;
773 ufbx_scene *scene;
774 };
775
776 // -- Unknown
777
778 struct ufbx_unknown {
779 // Shared "base-class" header, see `ufbx_element`.
780 union { ufbx_element element; struct {
781 ufbx_string name;
782 ufbx_props props;
783 uint32_t element_id;
784 uint32_t typed_id;
785 }; };
786
787 // FBX format specific type information.
788 // In ASCII FBX format:
789 // super_type: ID, "type::name", "sub_type" { ... }
790 ufbx_string type;
791 ufbx_string super_type;
792 ufbx_string sub_type;
793 };
794
795 // -- Nodes
796
797 // Inherit type specifies how hierarchial node transforms are combined.
798 // This only affects the final scaling, as rotation and translation are always
799 // inherited correctly.
800 // NOTE: These don't map to `"InheritType"` property as there may be new ones for
801 // compatibility with various exporters.
802 typedef enum ufbx_inherit_mode UFBX_ENUM_REPR {
803
804 // Normal matrix composition of hierarchy: `R*S*r*s`.
805 // child.node_to_world = parent.node_to_world * child.node_to_parent;
806 UFBX_INHERIT_MODE_NORMAL,
807
808 // Ignore parent scale when computing the transform: `R*r*s`.
809 // ufbx_transform t = node.local_transform;
810 // t.translation *= parent.inherit_scale;
811 // t.scale *= node.inherit_scale_node.inherit_scale;
812 // child.node_to_world = parent.unscaled_node_to_world * t;
813 // Also known as "Segment scale compensate" in some software.
814 UFBX_INHERIT_MODE_IGNORE_PARENT_SCALE,
815
816 // Apply parent scale component-wise: `R*r*S*s`.
817 // ufbx_transform t = node.local_transform;
818 // t.translation *= parent.inherit_scale;
819 // t.scale *= node.inherit_scale_node.inherit_scale;
820 // child.node_to_world = parent.unscaled_node_to_world * t;
821 UFBX_INHERIT_MODE_COMPONENTWISE_SCALE,
822
823 UFBX_ENUM_FORCE_WIDTH(UFBX_INHERIT_MODE)
824 } ufbx_inherit_mode;
825
826 UFBX_ENUM_TYPE(ufbx_inherit_mode, UFBX_INHERIT_MODE, UFBX_INHERIT_MODE_COMPONENTWISE_SCALE);
827
828 // Axis used to mirror transformations for handedness conversion.
829 typedef enum ufbx_mirror_axis UFBX_ENUM_REPR {
830
831 UFBX_MIRROR_AXIS_NONE,
832 UFBX_MIRROR_AXIS_X,
833 UFBX_MIRROR_AXIS_Y,
834 UFBX_MIRROR_AXIS_Z,
835
836 UFBX_ENUM_FORCE_WIDTH(UFBX_MIRROR_AXIS)
837 } ufbx_mirror_axis;
838
839 UFBX_ENUM_TYPE(ufbx_mirror_axis, UFBX_MIRROR_AXIS, UFBX_MIRROR_AXIS_Z);
840
841 // Nodes form the scene transformation hierarchy and can contain attached
842 // elements such as meshes or lights. In normal cases a single `ufbx_node`
843 // contains only a single attached element, so using `type/mesh/...` is safe.
844 struct ufbx_node {
845 union { ufbx_element element; struct {
846 ufbx_string name;
847 ufbx_props props;
848 uint32_t element_id;
849 uint32_t typed_id;
850 }; };
851
852 // Node hierarchy
853
854 // Parent node containing this one if not root.
855 //
856 // Always non-`NULL` for non-root nodes unless
857 // `ufbx_load_opts.allow_nodes_out_of_root` is enabled.
858 ufbx_nullable ufbx_node *parent;
859
860 // List of child nodes parented to this node.
861 ufbx_node_list children;
862
863 // Common attached element type and typed pointers. Set to `NULL` if not in
864 // use, so checking `attrib_type` is not required.
865 //
866 // HINT: If you need less common attributes access `ufbx_node.attrib`, you
867 // can use utility functions like `ufbx_as_nurbs_curve(attrib)` to convert
868 // and check the attribute in one step.
869 ufbx_nullable ufbx_mesh *mesh;
870 ufbx_nullable ufbx_light *light;
871 ufbx_nullable ufbx_camera *camera;
872 ufbx_nullable ufbx_bone *bone;
873
874 // Less common attributes use these fields.
875 //
876 // Defined even if it is one of the above, eg. `ufbx_mesh`. In case there
877 // is multiple attributes this will be the first one.
878 ufbx_nullable ufbx_element *attrib;
879
880 // Geometry transform helper if one exists.
881 // See `UFBX_GEOMETRY_TRANSFORM_HANDLING_HELPER_NODES`.
882 ufbx_nullable ufbx_node *geometry_transform_helper;
883
884 // Scale helper if one exists.
885 // See `UFBX_INHERIT_MODE_HANDLING_HELPER_NODES`.
886 ufbx_nullable ufbx_node *scale_helper;
887
888 // `attrib->type` if `attrib` is defined, otherwise `UFBX_ELEMENT_UNKNOWN`.
889 ufbx_element_type attrib_type;
890
891 // List of _all_ attached attribute elements.
892 //
893 // In most cases there is only zero or one attributes per node, but if you
894 // have a very exotic FBX file nodes may have multiple attributes.
895 ufbx_element_list all_attribs;
896
897 // Local transform in parent, geometry transform is a non-inherited
898 // transform applied only to attachments like meshes
899 ufbx_inherit_mode inherit_mode;
900 ufbx_inherit_mode original_inherit_mode;
901 ufbx_transform local_transform;
902 ufbx_transform geometry_transform;
903
904 // Combined scale when using `UFBX_INHERIT_MODE_COMPONENTWISE_SCALE`.
905 // Contains `local_transform.scale` otherwise.
906 ufbx_vec3 inherit_scale;
907
908 // Node where scale is inherited from for `UFBX_INHERIT_MODE_COMPONENTWISE_SCALE`
909 // and even for `UFBX_INHERIT_MODE_IGNORE_PARENT_SCALE`.
910 // For componentwise-scale nodes, this will point to `parent`, for scale ignoring
911 // nodes this will point to the parent of the nearest componentwise-scaled node
912 // in the parent chain.
913 ufbx_nullable ufbx_node *inherit_scale_node;
914
915 // Raw Euler angles in degrees for those who want them
916
917 // Specifies the axis order `euler_rotation` is applied in.
918 ufbx_rotation_order rotation_order;
919 // Rotation around the local X/Y/Z axes in `rotation_order`.
920 // The angles are specified in degrees.
921 ufbx_vec3 euler_rotation;
922
923 // Matrices derived from the transformations, for transforming geometry
924 // prefer using `geometry_to_world` as that supports geometric transforms.
925
926 // Transform from this node to `parent` space.
927 // Equivalent to `ufbx_transform_to_matrix(&local_transform)`.
928 ufbx_matrix node_to_parent;
929 // Transform from this node to the world space, ie. multiplying all the
930 // `node_to_parent` matrices of the parent chain together.
931 ufbx_matrix node_to_world;
932 // Transform from the attribute to this node. Does not affect the transforms
933 // of `children`!
934 // Equivalent to `ufbx_transform_to_matrix(&geometry_transform)`.
935 ufbx_matrix geometry_to_node;
936 // Transform from attribute space to world space.
937 // Equivalent to `ufbx_matrix_mul(&node_to_world, &geometry_to_node)`.
938 ufbx_matrix geometry_to_world;
939 // Transform from this node to world space, ignoring self scaling.
940 ufbx_matrix unscaled_node_to_world;
941
942 // ufbx-specific adjustment for switching between coodrinate/unit systems.
943 // HINT: In most cases you don't need to deal with these as these are baked
944 // into all the transforms above and into `ufbx_evaluate_transform()`.
945 ufbx_vec3 adjust_pre_translation; // < Translation applied between parent and self
946 ufbx_quat adjust_pre_rotation; // < Rotation applied between parent and self
947 ufbx_real adjust_pre_scale; // < Scaling applied between parent and self
948 ufbx_quat adjust_post_rotation; // < Rotation applied in local space at the end
949 ufbx_real adjust_post_scale; // < Scaling applied in local space at the end
950 ufbx_real adjust_translation_scale; // < Scaling applied to translation only
951 ufbx_mirror_axis adjust_mirror_axis; // < Mirror translation and rotation on this axis
952
953 // Materials used by `mesh` or other `attrib`.
954 // There may be multiple copies of a single `ufbx_mesh` with different materials
955 // in the `ufbx_node` instances.
956 ufbx_material_list materials;
957
958 // Bind pose
959 ufbx_nullable ufbx_pose *bind_pose;
960
961 // Visibility state.
962 bool visible;
963
964 // True if this node is the implicit root node of the scene.
965 bool is_root;
966
967 // True if the node has a non-identity `geometry_transform`.
968 bool has_geometry_transform;
969
970 // If `true` the transform is adjusted by ufbx, not enabled by default.
971 // See `adjust_pre_rotation`, `adjust_pre_scale`, `adjust_post_rotation`,
972 // and `adjust_post_scale`.
973 bool has_adjust_transform;
974
975 // Scale is adjusted by root scale.
976 bool has_root_adjust_transform;
977
978 // True if this node is a synthetic geometry transform helper.
979 // See `UFBX_GEOMETRY_TRANSFORM_HANDLING_HELPER_NODES`.
980 bool is_geometry_transform_helper;
981
982 // True if the node is a synthetic scale compensation helper.
983 // See `UFBX_INHERIT_MODE_HANDLING_HELPER_NODES`.
984 bool is_scale_helper;
985
986 // Parent node to children that can compensate for parent scale.
987 bool is_scale_compensate_parent;
988
989 // How deep is this node in the parent hierarchy. Root node is at depth `0`
990 // and the immediate children of root at `1`.
991 uint32_t node_depth;
992 };
993
994 // Vertex attribute: All attributes are stored in a consistent indexed format
995 // regardless of how it's actually stored in the file.
996 //
997 // `values` is a contiguous array of attribute values.
998 // `indices` maps each mesh index into a value in the `values` array.
999 //
1000 // If `unique_per_vertex` is set then the attribute is guaranteed to have a
1001 // single defined value per vertex accessible via:
1002 // attrib.values.data[attrib.indices.data[mesh->vertex_first_index[vertex_ix]]
1003 typedef struct ufbx_vertex_attrib {
1004 // Is this attribute defined by the mesh.
1005 bool exists;
1006 // List of values the attribute uses.
1007 ufbx_void_list values;
1008 // Indices into `values[]`, indexed up to `ufbx_mesh.num_indices`.
1009 ufbx_uint32_list indices;
1010 // Number of `ufbx_real` entries per value.
1011 size_t value_reals;
1012 // `true` if this attribute is defined per vertex, instead of per index.
1013 bool unique_per_vertex;
1014 // Optional 4th 'W' component for the attribute.
1015 // May be defined for the following:
1016 // ufbx_mesh.vertex_normal
1017 // ufbx_mesh.vertex_tangent / ufbx_uv_set.vertex_tangent
1018 // ufbx_mesh.vertex_bitangent / ufbx_uv_set.vertex_bitangent
1019 // NOTE: This is not loaded by default, set `ufbx_load_opts.retain_vertex_attrib_w`.
1020 ufbx_real_list values_w;
1021 } ufbx_vertex_attrib;
1022
1023 // 1D vertex attribute, see `ufbx_vertex_attrib` for information
1024 typedef struct ufbx_vertex_real {
1025 bool exists;
1026 ufbx_real_list values;
1027 ufbx_uint32_list indices;
1028 size_t value_reals;
1029 bool unique_per_vertex;
1030 ufbx_real_list values_w;
1031
1032 UFBX_VERTEX_ATTRIB_IMPL(ufbx_real)
1033 } ufbx_vertex_real;
1034
1035 // 2D vertex attribute, see `ufbx_vertex_attrib` for information
1036 typedef struct ufbx_vertex_vec2 {
1037 bool exists;
1038 ufbx_vec2_list values;
1039 ufbx_uint32_list indices;
1040 size_t value_reals;
1041 bool unique_per_vertex;
1042 ufbx_real_list values_w;
1043
1044 UFBX_VERTEX_ATTRIB_IMPL(ufbx_vec2)
1045 } ufbx_vertex_vec2;
1046
1047 // 3D vertex attribute, see `ufbx_vertex_attrib` for information
1048 typedef struct ufbx_vertex_vec3 {
1049 bool exists;
1050 ufbx_vec3_list values;
1051 ufbx_uint32_list indices;
1052 size_t value_reals;
1053 bool unique_per_vertex;
1054 ufbx_real_list values_w;
1055
1056 UFBX_VERTEX_ATTRIB_IMPL(ufbx_vec3)
1057 } ufbx_vertex_vec3;
1058
1059 // 4D vertex attribute, see `ufbx_vertex_attrib` for information
1060 typedef struct ufbx_vertex_vec4 {
1061 bool exists;
1062 ufbx_vec4_list values;
1063 ufbx_uint32_list indices;
1064 size_t value_reals;
1065 bool unique_per_vertex;
1066 ufbx_real_list values_w;
1067
1068 UFBX_VERTEX_ATTRIB_IMPL(ufbx_vec4)
1069 } ufbx_vertex_vec4;
1070
1071 // Vertex UV set/layer
1072 typedef struct ufbx_uv_set {
1073 ufbx_string name;
1074 uint32_t index;
1075
1076 // Vertex attributes, see `ufbx_mesh` attributes for more information
1077 ufbx_vertex_vec2 vertex_uv; // < UV / texture coordinates
1078 ufbx_vertex_vec3 vertex_tangent; // < (optional) Tangent vector in UV.x direction
1079 ufbx_vertex_vec3 vertex_bitangent; // < (optional) Tangent vector in UV.y direction
1080 } ufbx_uv_set;
1081
1082 // Vertex color set/layer
1083 typedef struct ufbx_color_set {
1084 ufbx_string name;
1085 uint32_t index;
1086
1087 // Vertex attributes, see `ufbx_mesh` attributes for more information
1088 ufbx_vertex_vec4 vertex_color; // < Per-vertex RGBA color
1089 } ufbx_color_set;
1090
1091 UFBX_LIST_TYPE(ufbx_uv_set_list, ufbx_uv_set);
1092 UFBX_LIST_TYPE(ufbx_color_set_list, ufbx_color_set);
1093
1094 // Edge between two _indices_ in a mesh
1095 typedef struct ufbx_edge {
1096 union {
1097 struct { uint32_t a, b; };
1098 uint32_t indices[2];
1099 };
1100 } ufbx_edge;
1101
1102 UFBX_LIST_TYPE(ufbx_edge_list, ufbx_edge);
1103
1104 // Polygonal face with arbitrary number vertices, a single face contains a
1105 // contiguous range of mesh indices, eg. `{5,3}` would have indices 5, 6, 7
1106 //
1107 // NOTE: `num_indices` maybe less than 3 in which case the face is invalid!
1108 // [TODO #23: should probably remove the bad faces at load time]
1109 typedef struct ufbx_face {
1110 uint32_t index_begin;
1111 uint32_t num_indices;
1112 } ufbx_face;
1113
1114 UFBX_LIST_TYPE(ufbx_face_list, ufbx_face);
1115
1116 // Subset of mesh faces used by a single material or group.
1117 typedef struct ufbx_mesh_part {
1118
1119 // Index of the mesh part.
1120 uint32_t index;
1121
1122 // Sub-set of the geometry
1123 size_t num_faces; // < Number of faces (polygons)
1124 size_t num_triangles; // < Number of triangles if triangulated
1125
1126 size_t num_empty_faces; // < Number of faces with zero vertices
1127 size_t num_point_faces; // < Number of faces with a single vertex
1128 size_t num_line_faces; // < Number of faces with two vertices
1129
1130 // Indices to `ufbx_mesh.faces[]`.
1131 // Always contains `num_faces` elements.
1132 ufbx_uint32_list face_indices;
1133
1134 } ufbx_mesh_part;
1135
1136 UFBX_LIST_TYPE(ufbx_mesh_part_list, ufbx_mesh_part);
1137
1138 typedef struct ufbx_face_group {
1139 int32_t id; // < Numerical ID for this group.
1140 ufbx_string name; // < Name for the face group.
1141 } ufbx_face_group;
1142
1143 UFBX_LIST_TYPE(ufbx_face_group_list, ufbx_face_group);
1144
1145 typedef struct ufbx_subdivision_weight_range {
1146 uint32_t weight_begin;
1147 uint32_t num_weights;
1148 } ufbx_subdivision_weight_range;
1149
1150 UFBX_LIST_TYPE(ufbx_subdivision_weight_range_list, ufbx_subdivision_weight_range);
1151
1152 typedef struct ufbx_subdivision_weight {
1153 ufbx_real weight;
1154 uint32_t index;
1155 } ufbx_subdivision_weight;
1156
1157 UFBX_LIST_TYPE(ufbx_subdivision_weight_list, ufbx_subdivision_weight);
1158
1159 typedef struct ufbx_subdivision_result {
1160 size_t result_memory_used;
1161 size_t temp_memory_used;
1162 size_t result_allocs;
1163 size_t temp_allocs;
1164
1165 // Weights of vertices in the source model.
1166 // Defined if `ufbx_subdivide_opts.evaluate_source_vertices` is set.
1167 ufbx_subdivision_weight_range_list source_vertex_ranges;
1168 ufbx_subdivision_weight_list source_vertex_weights;
1169
1170 // Weights of skin clusters in the source model.
1171 // Defined if `ufbx_subdivide_opts.evaluate_skin_weights` is set.
1172 ufbx_subdivision_weight_range_list skin_cluster_ranges;
1173 ufbx_subdivision_weight_list skin_cluster_weights;
1174
1175 } ufbx_subdivision_result;
1176
1177 typedef enum ufbx_subdivision_display_mode UFBX_ENUM_REPR {
1178 UFBX_SUBDIVISION_DISPLAY_DISABLED,
1179 UFBX_SUBDIVISION_DISPLAY_HULL,
1180 UFBX_SUBDIVISION_DISPLAY_HULL_AND_SMOOTH,
1181 UFBX_SUBDIVISION_DISPLAY_SMOOTH,
1182
1183 UFBX_ENUM_FORCE_WIDTH(UFBX_SUBDIVISION_DISPLAY_MODE)
1184 } ufbx_subdivision_display_mode;
1185
1186 UFBX_ENUM_TYPE(ufbx_subdivision_display_mode, UFBX_SUBDIVISION_DISPLAY_MODE, UFBX_SUBDIVISION_DISPLAY_SMOOTH);
1187
1188 typedef enum ufbx_subdivision_boundary UFBX_ENUM_REPR {
1189 UFBX_SUBDIVISION_BOUNDARY_DEFAULT,
1190 UFBX_SUBDIVISION_BOUNDARY_LEGACY,
1191 // OpenSubdiv: `VTX_BOUNDARY_EDGE_AND_CORNER` / `FVAR_LINEAR_CORNERS_ONLY`
1192 UFBX_SUBDIVISION_BOUNDARY_SHARP_CORNERS,
1193 // OpenSubdiv: `VTX_BOUNDARY_EDGE_ONLY` / `FVAR_LINEAR_NONE`
1194 UFBX_SUBDIVISION_BOUNDARY_SHARP_NONE,
1195 // OpenSubdiv: `FVAR_LINEAR_BOUNDARIES`
1196 UFBX_SUBDIVISION_BOUNDARY_SHARP_BOUNDARY,
1197 // OpenSubdiv: `FVAR_LINEAR_ALL`
1198 UFBX_SUBDIVISION_BOUNDARY_SHARP_INTERIOR,
1199
1200 UFBX_ENUM_FORCE_WIDTH(UFBX_SUBDIVISION_BOUNDARY)
1201 } ufbx_subdivision_boundary;
1202
1203 UFBX_ENUM_TYPE(ufbx_subdivision_boundary, UFBX_SUBDIVISION_BOUNDARY, UFBX_SUBDIVISION_BOUNDARY_SHARP_INTERIOR);
1204
1205 // Polygonal mesh geometry.
1206 //
1207 // Example mesh with two triangles (x, z) and a quad (y).
1208 // The faces have a constant UV coordinate x/y/z.
1209 // The vertices have _per vertex_ normals that point up/down.
1210 //
1211 // ^ ^ ^
1212 // A---B-----C
1213 // |x / /|
1214 // | / y / |
1215 // |/ / z|
1216 // D-----E---F
1217 // v v v
1218 //
1219 // Attributes may have multiple values within a single vertex, for example a
1220 // UV seam vertex has two UV coordinates. Thus polygons are defined using
1221 // an index that counts each corner of each face polygon. If an attribute is
1222 // defined (even per-vertex) it will always have a valid `indices` array.
1223 //
1224 // {0,3} {3,4} {7,3} faces ({ index_begin, num_indices })
1225 // 0 1 2 3 4 5 6 7 8 9 index
1226 //
1227 // 0 1 3 1 2 4 3 2 4 5 vertex_indices[index]
1228 // A B D B C E D C E F vertices[vertex_indices[index]]
1229 //
1230 // 0 0 1 0 0 1 1 0 1 1 vertex_normal.indices[index]
1231 // ^ ^ v ^ ^ v v ^ v v vertex_normal.data[vertex_normal.indices[index]]
1232 //
1233 // 0 0 0 1 1 1 1 2 2 2 vertex_uv.indices[index]
1234 // x x x y y y y z z z vertex_uv.data[vertex_uv.indices[index]]
1235 //
1236 // Vertex position can also be accessed uniformly through an accessor:
1237 // 0 1 3 1 2 4 3 2 4 5 vertex_position.indices[index]
1238 // A B D B C E D C E F vertex_position.data[vertex_position.indices[index]]
1239 //
1240 // Some geometry data is specified per logical vertex. Vertex positions are
1241 // the only attribute that is guaranteed to be defined _uniquely_ per vertex.
1242 // Vertex attributes _may_ be defined per vertex if `unique_per_vertex == true`.
1243 // You can access the per-vertex values by first finding the first index that
1244 // refers to the given vertex.
1245 //
1246 // 0 1 2 3 4 5 vertex
1247 // A B C D E F vertices[vertex]
1248 //
1249 // 0 1 4 2 5 9 vertex_first_index[vertex]
1250 // 0 0 0 1 1 1 vertex_normal.indices[vertex_first_index[vertex]]
1251 // ^ ^ ^ v v v vertex_normal.data[vertex_normal.indices[vertex_first_index[vertex]]]
1252 //
1253 struct ufbx_mesh {
1254 union { ufbx_element element; struct {
1255 ufbx_string name;
1256 ufbx_props props;
1257 uint32_t element_id;
1258 uint32_t typed_id;
1259 ufbx_node_list instances;
1260 }; };
1261
1262 // Number of "logical" vertices that would be treated as a single point,
1263 // one vertex may be split to multiple indices for split attributes, eg. UVs
1264 size_t num_vertices; // < Number of logical "vertex" points
1265 size_t num_indices; // < Number of combiend vertex/attribute tuples
1266 size_t num_faces; // < Number of faces (polygons) in the mesh
1267 size_t num_triangles; // < Number of triangles if triangulated
1268
1269 // Number of edges in the mesh.
1270 // NOTE: May be zero in valid meshes if the file doesn't contain edge adjacency data!
1271 size_t num_edges;
1272
1273 size_t max_face_triangles; // < Maximum number of triangles in a face in this mesh
1274
1275 size_t num_empty_faces; // < Number of faces with zero vertices
1276 size_t num_point_faces; // < Number of faces with a single vertex
1277 size_t num_line_faces; // < Number of faces with two vertices
1278
1279 // Faces and optional per-face extra data
1280 ufbx_face_list faces; // < Face index range
1281 ufbx_bool_list face_smoothing; // < Should the face have soft normals
1282 ufbx_uint32_list face_material; // < Indices to `ufbx_mesh.materials[]` and `ufbx_node.materials[]`
1283 ufbx_uint32_list face_group; // < Face polygon group index, indices to `ufbx_mesh.face_groups[]`
1284 ufbx_bool_list face_hole; // < Should the face be hidden as a "hole"
1285
1286 // Edges and optional per-edge extra data
1287 ufbx_edge_list edges; // < Edge index range
1288 ufbx_bool_list edge_smoothing; // < Should the edge have soft normals
1289 ufbx_real_list edge_crease; // < Crease value for subdivision surfaces
1290 ufbx_bool_list edge_visibility; // < Should the edge be visible
1291
1292 // Logical vertices and positions, alternatively you can use
1293 // `vertex_position` for consistent interface with other attributes.
1294 ufbx_uint32_list vertex_indices;
1295 ufbx_vec3_list vertices;
1296
1297 // First index referring to a given vertex, `UFBX_NO_INDEX` if the vertex is unused.
1298 ufbx_uint32_list vertex_first_index;
1299
1300 // Vertex attributes, see the comment over the struct.
1301 //
1302 // NOTE: Not all meshes have all attributes, in that case `indices/data == NULL`!
1303 //
1304 // NOTE: UV/tangent/bitangent and color are the from first sets,
1305 // use `uv_sets/color_sets` to access the other layers.
1306 ufbx_vertex_vec3 vertex_position; // < Vertex positions
1307 ufbx_vertex_vec3 vertex_normal; // < (optional) Normal vectors, always defined if `ufbx_load_opts.generate_missing_normals`
1308 ufbx_vertex_vec2 vertex_uv; // < (optional) UV / texture coordinates
1309 ufbx_vertex_vec3 vertex_tangent; // < (optional) Tangent vector in UV.x direction
1310 ufbx_vertex_vec3 vertex_bitangent; // < (optional) Tangent vector in UV.y direction
1311 ufbx_vertex_vec4 vertex_color; // < (optional) Per-vertex RGBA color
1312 ufbx_vertex_real vertex_crease; // < (optional) Crease value for subdivision surfaces
1313
1314 // Multiple named UV/color sets
1315 // NOTE: The first set contains the same data as `vertex_uv/color`!
1316 ufbx_uv_set_list uv_sets;
1317 ufbx_color_set_list color_sets;
1318
1319 // Materials used by the mesh.
1320 // NOTE: These can be wrong if you want to support per-instance materials!
1321 // Use `ufbx_node.materials[]` to get the per-instance materials at the same indices.
1322 ufbx_material_list materials;
1323
1324 // Face groups for this mesh.
1325 ufbx_face_group_list face_groups;
1326
1327 // Segments that use a given material.
1328 // Defined even if the mesh doesn't have any materials.
1329 ufbx_mesh_part_list material_parts;
1330
1331 // Segments for each face group.
1332 ufbx_mesh_part_list face_group_parts;
1333
1334 // Order of `material_parts` by first face that refers to it.
1335 // Useful for compatibility with FBX SDK and various importers using it,
1336 // as they use this material order by default.
1337 ufbx_uint32_list material_part_usage_order;
1338
1339 // Skinned vertex positions, for efficiency the skinned positions are the
1340 // same as the static ones for non-skinned meshes and `skinned_is_local`
1341 // is set to true meaning you need to transform them manually using
1342 // `ufbx_transform_position(&node->geometry_to_world, skinned_pos)`!
1343 bool skinned_is_local;
1344 ufbx_vertex_vec3 skinned_position;
1345 ufbx_vertex_vec3 skinned_normal;
1346
1347 // Deformers
1348 ufbx_skin_deformer_list skin_deformers;
1349 ufbx_blend_deformer_list blend_deformers;
1350 ufbx_cache_deformer_list cache_deformers;
1351 ufbx_element_list all_deformers;
1352
1353 // Subdivision
1354 uint32_t subdivision_preview_levels;
1355 uint32_t subdivision_render_levels;
1356 ufbx_subdivision_display_mode subdivision_display_mode;
1357 ufbx_subdivision_boundary subdivision_boundary;
1358 ufbx_subdivision_boundary subdivision_uv_boundary;
1359
1360 // The winding of the faces has been reversed.
1361 bool reversed_winding;
1362
1363 // Normals have been generated instead of evaluated.
1364 // Either from missing normals (via `ufbx_load_opts.generate_missing_normals`), skinning,
1365 // tessellation, or subdivision.
1366 bool generated_normals;
1367
1368 // Subdivision (result)
1369 bool subdivision_evaluated;
1370 ufbx_nullable ufbx_subdivision_result *subdivision_result;
1371
1372 // Tessellation (result)
1373 bool from_tessellated_nurbs;
1374 };
1375
1376 // The kind of light source
1377 typedef enum ufbx_light_type UFBX_ENUM_REPR {
1378 // Single point at local origin, at `node->world_transform.position`
1379 UFBX_LIGHT_POINT,
1380 // Infinite directional light pointing locally towards `light->local_direction`
1381 // For global: `ufbx_transform_direction(&node->node_to_world, light->local_direction)`
1382 UFBX_LIGHT_DIRECTIONAL,
1383 // Cone shaped light towards `light->local_direction`, between `light->inner/outer_angle`.
1384 // For global: `ufbx_transform_direction(&node->node_to_world, light->local_direction)`
1385 UFBX_LIGHT_SPOT,
1386 // Area light, shape specified by `light->area_shape`
1387 // TODO: Units?
1388 UFBX_LIGHT_AREA,
1389 // Volumetric light source
1390 // TODO: How does this work
1391 UFBX_LIGHT_VOLUME,
1392
1393 UFBX_ENUM_FORCE_WIDTH(UFBX_LIGHT_TYPE)
1394 } ufbx_light_type;
1395
1396 UFBX_ENUM_TYPE(ufbx_light_type, UFBX_LIGHT_TYPE, UFBX_LIGHT_VOLUME);
1397
1398 // How fast does the light intensity decay at a distance
1399 typedef enum ufbx_light_decay UFBX_ENUM_REPR {
1400 UFBX_LIGHT_DECAY_NONE, // < 1 (no decay)
1401 UFBX_LIGHT_DECAY_LINEAR, // < 1 / d
1402 UFBX_LIGHT_DECAY_QUADRATIC, // < 1 / d^2 (physically accurate)
1403 UFBX_LIGHT_DECAY_CUBIC, // < 1 / d^3
1404
1405 UFBX_ENUM_FORCE_WIDTH(UFBX_LIGHT_DECAY)
1406 } ufbx_light_decay;
1407
1408 UFBX_ENUM_TYPE(ufbx_light_decay, UFBX_LIGHT_DECAY, UFBX_LIGHT_DECAY_CUBIC);
1409
1410 typedef enum ufbx_light_area_shape UFBX_ENUM_REPR {
1411 UFBX_LIGHT_AREA_SHAPE_RECTANGLE,
1412 UFBX_LIGHT_AREA_SHAPE_SPHERE,
1413
1414 UFBX_ENUM_FORCE_WIDTH(UFBX_LIGHT_AREA_SHAPE)
1415 } ufbx_light_area_shape;
1416
1417 UFBX_ENUM_TYPE(ufbx_light_area_shape, UFBX_LIGHT_AREA_SHAPE, UFBX_LIGHT_AREA_SHAPE_SPHERE);
1418
1419 // Light source attached to a `ufbx_node`
1420 struct ufbx_light {
1421 union { ufbx_element element; struct {
1422 ufbx_string name;
1423 ufbx_props props;
1424 uint32_t element_id;
1425 uint32_t typed_id;
1426 ufbx_node_list instances;
1427 }; };
1428
1429 // Color and intensity of the light, usually you want to use `color * intensity`
1430 // NOTE: `intensity` is 0.01x of the property `"Intensity"` as that matches
1431 // matches values in DCC programs before exporting.
1432 ufbx_vec3 color;
1433 ufbx_real intensity;
1434
1435 // Direction the light is aimed at in node's local space, usually -Y
1436 ufbx_vec3 local_direction;
1437
1438 // Type of the light and shape parameters
1439 ufbx_light_type type;
1440 ufbx_light_decay decay;
1441 ufbx_light_area_shape area_shape;
1442 ufbx_real inner_angle;
1443 ufbx_real outer_angle;
1444
1445 bool cast_light;
1446 bool cast_shadows;
1447 };
1448
1449 typedef enum ufbx_projection_mode UFBX_ENUM_REPR {
1450 // Perspective projection.
1451 UFBX_PROJECTION_MODE_PERSPECTIVE,
1452
1453 // Orthographic projection.
1454 UFBX_PROJECTION_MODE_ORTHOGRAPHIC,
1455
1456 UFBX_ENUM_FORCE_WIDTH(UFBX_PROJECTION_MODE)
1457 } ufbx_projection_mode;
1458
1459 UFBX_ENUM_TYPE(ufbx_projection_mode, UFBX_PROJECTION_MODE, UFBX_PROJECTION_MODE_ORTHOGRAPHIC);
1460
1461 // Method of specifying the rendering resolution from properties
1462 // NOTE: Handled internally by ufbx, ignore unless you interpret `ufbx_props` directly!
1463 typedef enum ufbx_aspect_mode UFBX_ENUM_REPR {
1464 // No defined resolution
1465 UFBX_ASPECT_MODE_WINDOW_SIZE,
1466 // `"AspectWidth"` and `"AspectHeight"` are relative to each other
1467 UFBX_ASPECT_MODE_FIXED_RATIO,
1468 // `"AspectWidth"` and `"AspectHeight"` are both pixels
1469 UFBX_ASPECT_MODE_FIXED_RESOLUTION,
1470 // `"AspectWidth"` is pixels, `"AspectHeight"` is relative to width
1471 UFBX_ASPECT_MODE_FIXED_WIDTH,
1472 // < `"AspectHeight"` is pixels, `"AspectWidth"` is relative to height
1473 UFBX_ASPECT_MODE_FIXED_HEIGHT,
1474
1475 UFBX_ENUM_FORCE_WIDTH(UFBX_ASPECT_MODE)
1476 } ufbx_aspect_mode;
1477
1478 UFBX_ENUM_TYPE(ufbx_aspect_mode, UFBX_ASPECT_MODE, UFBX_ASPECT_MODE_FIXED_HEIGHT);
1479
1480 // Method of specifying the field of view from properties
1481 // NOTE: Handled internally by ufbx, ignore unless you interpret `ufbx_props` directly!
1482 typedef enum ufbx_aperture_mode UFBX_ENUM_REPR {
1483 // Use separate `"FieldOfViewX"` and `"FieldOfViewY"` as horizontal/vertical FOV angles
1484 UFBX_APERTURE_MODE_HORIZONTAL_AND_VERTICAL,
1485 // Use `"FieldOfView"` as horizontal FOV angle, derive vertical angle via aspect ratio
1486 UFBX_APERTURE_MODE_HORIZONTAL,
1487 // Use `"FieldOfView"` as vertical FOV angle, derive horizontal angle via aspect ratio
1488 UFBX_APERTURE_MODE_VERTICAL,
1489 // Compute the field of view from the render gate size and focal length
1490 UFBX_APERTURE_MODE_FOCAL_LENGTH,
1491
1492 UFBX_ENUM_FORCE_WIDTH(UFBX_APERTURE_MODE)
1493 } ufbx_aperture_mode;
1494
1495 UFBX_ENUM_TYPE(ufbx_aperture_mode, UFBX_APERTURE_MODE, UFBX_APERTURE_MODE_FOCAL_LENGTH);
1496
1497 // Method of specifying the render gate size from properties
1498 // NOTE: Handled internally by ufbx, ignore unless you interpret `ufbx_props` directly!
1499 typedef enum ufbx_gate_fit UFBX_ENUM_REPR {
1500 // Use the film/aperture size directly as the render gate
1501 UFBX_GATE_FIT_NONE,
1502 // Fit the render gate to the height of the film, derive width from aspect ratio
1503 UFBX_GATE_FIT_VERTICAL,
1504 // Fit the render gate to the width of the film, derive height from aspect ratio
1505 UFBX_GATE_FIT_HORIZONTAL,
1506 // Fit the render gate so that it is fully contained within the film gate
1507 UFBX_GATE_FIT_FILL,
1508 // Fit the render gate so that it fully contains the film gate
1509 UFBX_GATE_FIT_OVERSCAN,
1510 // Stretch the render gate to match the film gate
1511 // TODO: Does this differ from `UFBX_GATE_FIT_NONE`?
1512 UFBX_GATE_FIT_STRETCH,
1513
1514 UFBX_ENUM_FORCE_WIDTH(UFBX_GATE_FIT)
1515 } ufbx_gate_fit;
1516
1517 UFBX_ENUM_TYPE(ufbx_gate_fit, UFBX_GATE_FIT, UFBX_GATE_FIT_STRETCH);
1518
1519 // Camera film/aperture size defaults
1520 // NOTE: Handled internally by ufbx, ignore unless you interpret `ufbx_props` directly!
1521 typedef enum ufbx_aperture_format UFBX_ENUM_REPR {
1522 UFBX_APERTURE_FORMAT_CUSTOM, // < Use `"FilmWidth"` and `"FilmHeight"`
1523 UFBX_APERTURE_FORMAT_16MM_THEATRICAL, // < 0.404 x 0.295 inches
1524 UFBX_APERTURE_FORMAT_SUPER_16MM, // < 0.493 x 0.292 inches
1525 UFBX_APERTURE_FORMAT_35MM_ACADEMY, // < 0.864 x 0.630 inches
1526 UFBX_APERTURE_FORMAT_35MM_TV_PROJECTION, // < 0.816 x 0.612 inches
1527 UFBX_APERTURE_FORMAT_35MM_FULL_APERTURE, // < 0.980 x 0.735 inches
1528 UFBX_APERTURE_FORMAT_35MM_185_PROJECTION, // < 0.825 x 0.446 inches
1529 UFBX_APERTURE_FORMAT_35MM_ANAMORPHIC, // < 0.864 x 0.732 inches (squeeze ratio: 2)
1530 UFBX_APERTURE_FORMAT_70MM_PROJECTION, // < 2.066 x 0.906 inches
1531 UFBX_APERTURE_FORMAT_VISTAVISION, // < 1.485 x 0.991 inches
1532 UFBX_APERTURE_FORMAT_DYNAVISION, // < 2.080 x 1.480 inches
1533 UFBX_APERTURE_FORMAT_IMAX, // < 2.772 x 2.072 inches
1534
1535 UFBX_ENUM_FORCE_WIDTH(UFBX_APERTURE_FORMAT)
1536 } ufbx_aperture_format;
1537
1538 UFBX_ENUM_TYPE(ufbx_aperture_format, UFBX_APERTURE_FORMAT, UFBX_APERTURE_FORMAT_IMAX);
1539
1540 typedef enum ufbx_coordinate_axis UFBX_ENUM_REPR {
1541 UFBX_COORDINATE_AXIS_POSITIVE_X,
1542 UFBX_COORDINATE_AXIS_NEGATIVE_X,
1543 UFBX_COORDINATE_AXIS_POSITIVE_Y,
1544 UFBX_COORDINATE_AXIS_NEGATIVE_Y,
1545 UFBX_COORDINATE_AXIS_POSITIVE_Z,
1546 UFBX_COORDINATE_AXIS_NEGATIVE_Z,
1547 UFBX_COORDINATE_AXIS_UNKNOWN,
1548
1549 UFBX_ENUM_FORCE_WIDTH(UFBX_COORDINATE_AXIS)
1550 } ufbx_coordinate_axis;
1551
1552 UFBX_ENUM_TYPE(ufbx_coordinate_axis, UFBX_COORDINATE_AXIS, UFBX_COORDINATE_AXIS_UNKNOWN);
1553
1554 // Coordinate axes the scene is represented in.
1555 // NOTE: `front` is the _opposite_ from forward!
1556 typedef struct ufbx_coordinate_axes {
1557 ufbx_coordinate_axis right;
1558 ufbx_coordinate_axis up;
1559 ufbx_coordinate_axis front;
1560 } ufbx_coordinate_axes;
1561
1562 // Camera attached to a `ufbx_node`
1563 struct ufbx_camera {
1564 union { ufbx_element element; struct {
1565 ufbx_string name;
1566 ufbx_props props;
1567 uint32_t element_id;
1568 uint32_t typed_id;
1569 ufbx_node_list instances;
1570 }; };
1571
1572 // Projection mode (perspective/orthographic).
1573 ufbx_projection_mode projection_mode;
1574
1575 // If set to `true`, `resolution` represents actual pixel values, otherwise
1576 // it's only useful for its aspect ratio.
1577 bool resolution_is_pixels;
1578
1579 // Render resolution, either in pixels or arbitrary units, depending on above
1580 ufbx_vec2 resolution;
1581
1582 // Horizontal/vertical field of view in degrees
1583 // Valid if `projection_mode == UFBX_PROJECTION_MODE_PERSPECTIVE`.
1584 ufbx_vec2 field_of_view_deg;
1585
1586 // Component-wise `tan(field_of_view_deg)`, also represents the size of the
1587 // proection frustum slice at distance of 1.
1588 // Valid if `projection_mode == UFBX_PROJECTION_MODE_PERSPECTIVE`.
1589 ufbx_vec2 field_of_view_tan;
1590
1591 // Orthographic camera extents.
1592 // Valid if `projection_mode == UFBX_PROJECTION_MODE_ORTHOGRAPHIC`.
1593 ufbx_real orthographic_extent;
1594
1595 // Orthographic camera size.
1596 // Valid if `projection_mode == UFBX_PROJECTION_MODE_ORTHOGRAPHIC`.
1597 ufbx_vec2 orthographic_size;
1598
1599 // Size of the projection plane at distance 1.
1600 // Equal to `field_of_view_tan` if perspective, `orthographic_size` if orthographic.
1601 ufbx_vec2 projection_plane;
1602
1603 // Aspect ratio of the camera.
1604 ufbx_real aspect_ratio;
1605
1606 // Near plane of the frustum in units from the camera.
1607 ufbx_real near_plane;
1608
1609 // Far plane of the frustum in units from the camera.
1610 ufbx_real far_plane;
1611
1612 // Coordinate system that the projection uses.
1613 // FBX saves cameras with +X forward and +Y up, but you can override this using
1614 // `ufbx_load_opts.target_camera_axes` and it will be reflected here.
1615 ufbx_coordinate_axes projection_axes;
1616
1617 // Advanced properties used to compute the above
1618 ufbx_aspect_mode aspect_mode;
1619 ufbx_aperture_mode aperture_mode;
1620 ufbx_gate_fit gate_fit;
1621 ufbx_aperture_format aperture_format;
1622 ufbx_real focal_length_mm; // < Focal length in millimeters
1623 ufbx_vec2 film_size_inch; // < Film size in inches
1624 ufbx_vec2 aperture_size_inch; // < Aperture/film gate size in inches
1625 ufbx_real squeeze_ratio; // < Anamoprhic stretch ratio
1626 };
1627
1628 // Bone attached to a `ufbx_node`, provides the logical length of the bone
1629 // but most interesting information is directly in `ufbx_node`.
1630 struct ufbx_bone {
1631 union { ufbx_element element; struct {
1632 ufbx_string name;
1633 ufbx_props props;
1634 uint32_t element_id;
1635 uint32_t typed_id;
1636 ufbx_node_list instances;
1637 }; };
1638
1639 // Visual radius of the bone
1640 ufbx_real radius;
1641
1642 // Length of the bone relative to the distance between two nodes
1643 ufbx_real relative_length;
1644
1645 // Is the bone a root bone
1646 bool is_root;
1647 };
1648
1649 // Empty/NULL/locator connected to a node, actual details in `ufbx_node`
1650 struct ufbx_empty {
1651 union { ufbx_element element; struct {
1652 ufbx_string name;
1653 ufbx_props props;
1654 uint32_t element_id;
1655 uint32_t typed_id;
1656 ufbx_node_list instances;
1657 }; };
1658 };
1659
1660 // -- Node attributes (curves/surfaces)
1661
1662 // Segment of a `ufbx_line_curve`, indices refer to `ufbx_line_curve.point_indices[]`
1663 typedef struct ufbx_line_segment {
1664 uint32_t index_begin;
1665 uint32_t num_indices;
1666 } ufbx_line_segment;
1667
1668 UFBX_LIST_TYPE(ufbx_line_segment_list, ufbx_line_segment);
1669
1670 struct ufbx_line_curve {
1671 union { ufbx_element element; struct {
1672 ufbx_string name;
1673 ufbx_props props;
1674 uint32_t element_id;
1675 uint32_t typed_id;
1676 ufbx_node_list instances;
1677 }; };
1678
1679 ufbx_vec3 color;
1680
1681 ufbx_vec3_list control_points; // < List of possible values the line passes through
1682 ufbx_uint32_list point_indices; // < Indices to `control_points[]` the line goes through
1683
1684 ufbx_line_segment_list segments;
1685
1686 // Tessellation (result)
1687 bool from_tessellated_nurbs;
1688 };
1689
1690 typedef enum ufbx_nurbs_topology UFBX_ENUM_REPR {
1691 // The endpoints are not connected.
1692 UFBX_NURBS_TOPOLOGY_OPEN,
1693 // Repeats first `ufbx_nurbs_basis.order - 1` control points after the end.
1694 UFBX_NURBS_TOPOLOGY_PERIODIC,
1695 // Repeats the first control point after the end.
1696 UFBX_NURBS_TOPOLOGY_CLOSED,
1697
1698 UFBX_ENUM_FORCE_WIDTH(UFBX_NURBS_TOPOLOGY)
1699 } ufbx_nurbs_topology;
1700
1701 UFBX_ENUM_TYPE(ufbx_nurbs_topology, UFBX_NURBS_TOPOLOGY, UFBX_NURBS_TOPOLOGY_CLOSED);
1702
1703 // NURBS basis functions for an axis
1704 typedef struct ufbx_nurbs_basis {
1705
1706 // Number of control points influencing a point on the curve/surface.
1707 // Equal to the degree plus one.
1708 uint32_t order;
1709
1710 // Topology (periodicity) of the dimension.
1711 ufbx_nurbs_topology topology;
1712
1713 // Subdivision of the parameter range to control points.
1714 ufbx_real_list knot_vector;
1715
1716 // Range for the parameter value.
1717 ufbx_real t_min;
1718 ufbx_real t_max;
1719
1720 // Parameter values of control points.
1721 ufbx_real_list spans;
1722
1723 // `true` if this axis is two-dimensional.
1724 bool is_2d;
1725
1726 // Number of control points that need to be copied to the end.
1727 // This is just for convenience as it could be derived from `topology` and
1728 // `order`. If for example `num_wrap_control_points == 3` you should repeat
1729 // the first 3 control points after the end.
1730 // HINT: You don't need to worry about this if you use ufbx functions
1731 // like `ufbx_evaluate_nurbs_curve()` as they handle this internally.
1732 size_t num_wrap_control_points;
1733
1734 // `true` if the parametrization is well defined.
1735 bool valid;
1736
1737 } ufbx_nurbs_basis;
1738
1739 struct ufbx_nurbs_curve {
1740 union { ufbx_element element; struct {
1741 ufbx_string name;
1742 ufbx_props props;
1743 uint32_t element_id;
1744 uint32_t typed_id;
1745 ufbx_node_list instances;
1746 }; };
1747
1748 // Basis in the U axis
1749 ufbx_nurbs_basis basis;
1750
1751 // Linear array of control points
1752 // NOTE: The control points are _not_ homogeneous, meaning you have to multiply
1753 // them by `w` before evaluating the surface.
1754 ufbx_vec4_list control_points;
1755 };
1756
1757 struct ufbx_nurbs_surface {
1758 union { ufbx_element element; struct {
1759 ufbx_string name;
1760 ufbx_props props;
1761 uint32_t element_id;
1762 uint32_t typed_id;
1763 ufbx_node_list instances;
1764 }; };
1765
1766 // Basis in the U/V axes
1767 ufbx_nurbs_basis basis_u;
1768 ufbx_nurbs_basis basis_v;
1769
1770 // Number of control points for the U/V axes
1771 size_t num_control_points_u;
1772 size_t num_control_points_v;
1773
1774 // 2D array of control points.
1775 // Memory layout: `V * num_control_points_u + U`
1776 // NOTE: The control points are _not_ homogeneous, meaning you have to multiply
1777 // them by `w` before evaluating the surface.
1778 ufbx_vec4_list control_points;
1779
1780 // How many segments tessellate each span in `ufbx_nurbs_basis.spans`.
1781 uint32_t span_subdivision_u;
1782 uint32_t span_subdivision_v;
1783
1784 // If `true` the resulting normals should be flipped when evaluated.
1785 bool flip_normals;
1786
1787 // Material for the whole surface.
1788 // NOTE: May be `NULL`!
1789 ufbx_nullable ufbx_material *material;
1790 };
1791
1792 struct ufbx_nurbs_trim_surface {
1793 union { ufbx_element element; struct {
1794 ufbx_string name;
1795 ufbx_props props;
1796 uint32_t element_id;
1797 uint32_t typed_id;
1798 ufbx_node_list instances;
1799 }; };
1800 };
1801
1802 struct ufbx_nurbs_trim_boundary {
1803 union { ufbx_element element; struct {
1804 ufbx_string name;
1805 ufbx_props props;
1806 uint32_t element_id;
1807 uint32_t typed_id;
1808 ufbx_node_list instances;
1809 }; };
1810 };
1811
1812 // -- Node attributes (advanced)
1813
1814 struct ufbx_procedural_geometry {
1815 union { ufbx_element element; struct {
1816 ufbx_string name;
1817 ufbx_props props;
1818 uint32_t element_id;
1819 uint32_t typed_id;
1820 ufbx_node_list instances;
1821 }; };
1822 };
1823
1824 struct ufbx_stereo_camera {
1825 union { ufbx_element element; struct {
1826 ufbx_string name;
1827 ufbx_props props;
1828 uint32_t element_id;
1829 uint32_t typed_id;
1830 ufbx_node_list instances;
1831 }; };
1832
1833 ufbx_nullable ufbx_camera *left;
1834 ufbx_nullable ufbx_camera *right;
1835 };
1836
1837 struct ufbx_camera_switcher {
1838 union { ufbx_element element; struct {
1839 ufbx_string name;
1840 ufbx_props props;
1841 uint32_t element_id;
1842 uint32_t typed_id;
1843 ufbx_node_list instances;
1844 }; };
1845 };
1846
1847 typedef enum ufbx_marker_type UFBX_ENUM_REPR {
1848 UFBX_MARKER_UNKNOWN, // < Unknown marker type
1849 UFBX_MARKER_FK_EFFECTOR, // < FK (Forward Kinematics) effector
1850 UFBX_MARKER_IK_EFFECTOR, // < IK (Inverse Kinematics) effector
1851
1852 UFBX_ENUM_FORCE_WIDTH(UFBX_MARKER_TYPE)
1853 } ufbx_marker_type;
1854
1855 UFBX_ENUM_TYPE(ufbx_marker_type, UFBX_MARKER_TYPE, UFBX_MARKER_IK_EFFECTOR);
1856
1857 // Tracking marker for effectors
1858 struct ufbx_marker {
1859 union { ufbx_element element; struct {
1860 ufbx_string name;
1861 ufbx_props props;
1862 uint32_t element_id;
1863 uint32_t typed_id;
1864 ufbx_node_list instances;
1865 }; };
1866
1867 // Type of the marker
1868 ufbx_marker_type type;
1869 };
1870
1871 // LOD level display mode.
1872 typedef enum ufbx_lod_display UFBX_ENUM_REPR {
1873 UFBX_LOD_DISPLAY_USE_LOD, // < Display the LOD level if the distance is appropriate.
1874 UFBX_LOD_DISPLAY_SHOW, // < Always display the LOD level.
1875 UFBX_LOD_DISPLAY_HIDE, // < Never display the LOD level.
1876
1877 UFBX_ENUM_FORCE_WIDTH(UFBX_LOD_DISPLAY)
1878 } ufbx_lod_display;
1879
1880 UFBX_ENUM_TYPE(ufbx_lod_display, UFBX_LOD_DISPLAY, UFBX_LOD_DISPLAY_HIDE);
1881
1882 // Single LOD level within an LOD group.
1883 // Specifies properties of the Nth child of the _node_ containing the LOD group.
1884 typedef struct ufbx_lod_level {
1885
1886 // Minimum distance to show this LOD level.
1887 // NOTE: In world units by default, or in screen percentage if
1888 // `ufbx_lod_group.relative_distances` is set.
1889 ufbx_real distance;
1890
1891 // LOD display mode.
1892 // NOTE: Mostly for editing, you should probably ignore this
1893 // unless making a modeling program.
1894 ufbx_lod_display display;
1895
1896 } ufbx_lod_level;
1897
1898 UFBX_LIST_TYPE(ufbx_lod_level_list, ufbx_lod_level);
1899
1900 // Group of LOD (Level of Detail) levels for an object.
1901 // The actual LOD models are defined in the parent `ufbx_node.children`.
1902 struct ufbx_lod_group {
1903 union { ufbx_element element; struct {
1904 ufbx_string name;
1905 ufbx_props props;
1906 uint32_t element_id;
1907 uint32_t typed_id;
1908 ufbx_node_list instances;
1909 }; };
1910
1911 // If set to `true`, `ufbx_lod_level.distance` represents a screen size percentage.
1912 bool relative_distances;
1913
1914 // LOD levels matching in order to `ufbx_node.children`.
1915 ufbx_lod_level_list lod_levels;
1916
1917 // If set to `true` don't account for parent transform when computing the distance.
1918 bool ignore_parent_transform;
1919
1920 // If `use_distance_limit` is enabled hide the group if the distance is not between
1921 // `distance_limit_min` and `distance_limit_max`.
1922 bool use_distance_limit;
1923 ufbx_real distance_limit_min;
1924 ufbx_real distance_limit_max;
1925 };
1926
1927 // -- Deformers
1928
1929 // Method to evaluate the skinning on a per-vertex level
1930 typedef enum ufbx_skinning_method UFBX_ENUM_REPR {
1931 // Linear blend skinning: Blend transformation matrices by vertex weights
1932 UFBX_SKINNING_METHOD_LINEAR,
1933 // One vertex should have only one bone attached
1934 UFBX_SKINNING_METHOD_RIGID,
1935 // Convert the transformations to dual quaternions and blend in that space
1936 UFBX_SKINNING_METHOD_DUAL_QUATERNION,
1937 // Blend between `UFBX_SKINNING_METHOD_LINEAR` and `UFBX_SKINNING_METHOD_BLENDED_DQ_LINEAR`
1938 // The blend weight can be found either per-vertex in `ufbx_skin_vertex.dq_weight`
1939 // or in `ufbx_skin_deformer.dq_vertices/dq_weights` (indexed by vertex).
1940 UFBX_SKINNING_METHOD_BLENDED_DQ_LINEAR,
1941
1942 UFBX_ENUM_FORCE_WIDTH(UFBX_SKINNING_METHOD)
1943 } ufbx_skinning_method;
1944
1945 UFBX_ENUM_TYPE(ufbx_skinning_method, UFBX_SKINNING_METHOD, UFBX_SKINNING_METHOD_BLENDED_DQ_LINEAR);
1946
1947 // Skin weight information for a single mesh vertex
1948 typedef struct ufbx_skin_vertex {
1949
1950 // Each vertex is influenced by weights from `ufbx_skin_deformer.weights[]`
1951 // The weights are sorted by decreasing weight so you can take the first N
1952 // weights to get a cheaper approximation of the vertex.
1953 // NOTE: The weights are not guaranteed to be normalized!
1954 uint32_t weight_begin; // < Index to start from in the `weights[]` array
1955 uint32_t num_weights; // < Number of weights influencing the vertex
1956
1957 // Blend weight between Linear Blend Skinning (0.0) and Dual Quaternion (1.0).
1958 // Should be used if `skinning_method == UFBX_SKINNING_METHOD_BLENDED_DQ_LINEAR`
1959 ufbx_real dq_weight;
1960
1961 } ufbx_skin_vertex;
1962
1963 UFBX_LIST_TYPE(ufbx_skin_vertex_list, ufbx_skin_vertex);
1964
1965 // Single per-vertex per-cluster weight, see `ufbx_skin_vertex`
1966 typedef struct ufbx_skin_weight {
1967 uint32_t cluster_index; // < Index into `ufbx_skin_deformer.clusters[]`
1968 ufbx_real weight; // < Amount this bone influence the vertex
1969 } ufbx_skin_weight;
1970
1971 UFBX_LIST_TYPE(ufbx_skin_weight_list, ufbx_skin_weight);
1972
1973 // Skin deformer specifies a binding between a logical set of bones (a skeleton)
1974 // and a mesh. Each bone is represented by a `ufbx_skin_cluster` that contains
1975 // the binding matrix and a `ufbx_node *bone` that has the current transformation.
1976 struct ufbx_skin_deformer {
1977 union { ufbx_element element; struct {
1978 ufbx_string name;
1979 ufbx_props props;
1980 uint32_t element_id;
1981 uint32_t typed_id;
1982 }; };
1983
1984 ufbx_skinning_method skinning_method;
1985
1986 // Clusters (bones) in the skin
1987 ufbx_skin_cluster_list clusters;
1988
1989 // Per-vertex weight information
1990 ufbx_skin_vertex_list vertices;
1991 ufbx_skin_weight_list weights;
1992
1993 // Largest amount of weights a single vertex can have
1994 size_t max_weights_per_vertex;
1995
1996 // Blend weights between Linear Blend Skinning (0.0) and Dual Quaternion (1.0).
1997 // HINT: You probably want to use `vertices` and `ufbx_skin_vertex.dq_weight` instead!
1998 // NOTE: These may be out-of-bounds for a given mesh, `vertices` is always safe.
1999 size_t num_dq_weights;
2000 ufbx_uint32_list dq_vertices;
2001 ufbx_real_list dq_weights;
2002 };
2003
2004 // Cluster of vertices bound to a single bone.
2005 struct ufbx_skin_cluster {
2006 union { ufbx_element element; struct {
2007 ufbx_string name;
2008 ufbx_props props;
2009 uint32_t element_id;
2010 uint32_t typed_id;
2011 }; };
2012
2013 // The bone node the cluster is attached to
2014 // NOTE: Always valid if found from `ufbx_skin_deformer.clusters[]` unless
2015 // `ufbx_load_opts.connect_broken_elements` is `true`.
2016 ufbx_nullable ufbx_node *bone_node;
2017
2018 // Binding matrix from local mesh vertices to the bone
2019 ufbx_matrix geometry_to_bone;
2020
2021 // Binding matrix from local mesh _node_ to the bone.
2022 // NOTE: Prefer `geometry_to_bone` in most use cases!
2023 ufbx_matrix mesh_node_to_bone;
2024
2025 // Matrix that specifies the rest/bind pose transform of the node,
2026 // not generally needed for skinning, use `geometry_to_bone` instead.
2027 ufbx_matrix bind_to_world;
2028
2029 // Precomputed matrix/transform that accounts for the current bone transform
2030 // ie. `ufbx_matrix_mul(&cluster->bone->node_to_world, &cluster->geometry_to_bone)`
2031 ufbx_matrix geometry_to_world;
2032 ufbx_transform geometry_to_world_transform;
2033
2034 // Raw weights indexed by each _vertex_ of a mesh (not index!)
2035 // HINT: It may be simpler to use `ufbx_skin_deformer.vertices[]/weights[]` instead!
2036 // NOTE: These may be out-of-bounds for a given mesh, `ufbx_skin_deformer.vertices` is always safe.
2037 size_t num_weights; // < Number of vertices in the cluster
2038 ufbx_uint32_list vertices; // < Vertex indices in `ufbx_mesh.vertices[]`
2039 ufbx_real_list weights; // < Per-vertex weight values
2040 };
2041
2042 // Blend shape deformer can contain multiple channels (think of sliders between morphs)
2043 // that may optionally have in-between keyframes.
2044 struct ufbx_blend_deformer {
2045 union { ufbx_element element; struct {
2046 ufbx_string name;
2047 ufbx_props props;
2048 uint32_t element_id;
2049 uint32_t typed_id;
2050 }; };
2051
2052 // Independent morph targets of the deformer.
2053 ufbx_blend_channel_list channels;
2054 };
2055
2056 // Blend shape associated with a target weight in a series of morphs
2057 typedef struct ufbx_blend_keyframe {
2058 // The target blend shape offsets.
2059 ufbx_blend_shape *shape;
2060
2061 // Weight value at which to apply the keyframe at full strength
2062 ufbx_real target_weight;
2063
2064 // The weight the shape should be currently applied with
2065 ufbx_real effective_weight;
2066 } ufbx_blend_keyframe;
2067
2068 UFBX_LIST_TYPE(ufbx_blend_keyframe_list, ufbx_blend_keyframe);
2069
2070 // Blend channel consists of multiple morph-key targets that are interpolated.
2071 // In simple cases there will be only one keyframe that is the target shape.
2072 struct ufbx_blend_channel {
2073 union { ufbx_element element; struct {
2074 ufbx_string name;
2075 ufbx_props props;
2076 uint32_t element_id;
2077 uint32_t typed_id;
2078 }; };
2079
2080 // Current weight of the channel
2081 ufbx_real weight;
2082
2083 // Key morph targets to blend between depending on `weight`
2084 // In usual cases there's only one target per channel
2085 ufbx_blend_keyframe_list keyframes;
2086
2087 // Final blend shape ignoring any intermediate blend shapes.
2088 ufbx_nullable ufbx_blend_shape *target_shape;
2089 };
2090
2091 // Blend shape target containing the actual vertex offsets
2092 struct ufbx_blend_shape {
2093 union { ufbx_element element; struct {
2094 ufbx_string name;
2095 ufbx_props props;
2096 uint32_t element_id;
2097 uint32_t typed_id;
2098 }; };
2099
2100 // Vertex offsets to apply over the base mesh
2101 // NOTE: The `offset_vertices` may be out-of-bounds for a given mesh!
2102 size_t num_offsets; // < Number of vertex offsets in the following arrays
2103 ufbx_uint32_list offset_vertices; // < Indices to `ufbx_mesh.vertices[]`
2104 ufbx_vec3_list position_offsets; // < Always specified per-vertex offsets
2105 ufbx_vec3_list normal_offsets; // < Empty if not specified
2106
2107 // Optional weights for the offsets.
2108 // NOTE: These are technically not supported in FBX and are only written by Blender.
2109 ufbx_real_list offset_weights;
2110 };
2111
2112 typedef enum ufbx_cache_file_format UFBX_ENUM_REPR {
2113 UFBX_CACHE_FILE_FORMAT_UNKNOWN, // < Unknown cache file format
2114 UFBX_CACHE_FILE_FORMAT_PC2, // < .pc2 Point cache file
2115 UFBX_CACHE_FILE_FORMAT_MC, // < .mc/.mcx Maya cache file
2116
2117 UFBX_ENUM_FORCE_WIDTH(UFBX_CACHE_FILE_FORMAT)
2118 } ufbx_cache_file_format;
2119
2120 UFBX_ENUM_TYPE(ufbx_cache_file_format, UFBX_CACHE_FILE_FORMAT, UFBX_CACHE_FILE_FORMAT_MC);
2121
2122 typedef enum ufbx_cache_data_format UFBX_ENUM_REPR {
2123 UFBX_CACHE_DATA_FORMAT_UNKNOWN, // < Unknown data format
2124 UFBX_CACHE_DATA_FORMAT_REAL_FLOAT, // < `float data[]`
2125 UFBX_CACHE_DATA_FORMAT_VEC3_FLOAT, // < `struct { float x, y, z; } data[]`
2126 UFBX_CACHE_DATA_FORMAT_REAL_DOUBLE, // < `double data[]`
2127 UFBX_CACHE_DATA_FORMAT_VEC3_DOUBLE, // < `struct { double x, y, z; } data[]`
2128
2129 UFBX_ENUM_FORCE_WIDTH(UFBX_CACHE_DATA_FORMAT)
2130 } ufbx_cache_data_format;
2131
2132 UFBX_ENUM_TYPE(ufbx_cache_data_format, UFBX_CACHE_DATA_FORMAT, UFBX_CACHE_DATA_FORMAT_VEC3_DOUBLE);
2133
2134 typedef enum ufbx_cache_data_encoding UFBX_ENUM_REPR {
2135 UFBX_CACHE_DATA_ENCODING_UNKNOWN, // < Unknown data encoding
2136 UFBX_CACHE_DATA_ENCODING_LITTLE_ENDIAN, // < Contiguous little-endian array
2137 UFBX_CACHE_DATA_ENCODING_BIG_ENDIAN, // < Contiguous big-endian array
2138
2139 UFBX_ENUM_FORCE_WIDTH(UFBX_CACHE_DATA_ENCODING)
2140 } ufbx_cache_data_encoding;
2141
2142 UFBX_ENUM_TYPE(ufbx_cache_data_encoding, UFBX_CACHE_DATA_ENCODING, UFBX_CACHE_DATA_ENCODING_BIG_ENDIAN);
2143
2144 // Known interpretations of geometry cache data.
2145 typedef enum ufbx_cache_interpretation UFBX_ENUM_REPR {
2146 // Unknown interpretation, see `ufbx_cache_channel.interpretation_name` for more information.
2147 UFBX_CACHE_INTERPRETATION_UNKNOWN,
2148
2149 // Generic "points" interpretation, FBX SDK default. Usually fine to interpret
2150 // as vertex positions if no other cache channels are specified.
2151 UFBX_CACHE_INTERPRETATION_POINTS,
2152
2153 // Vertex positions.
2154 UFBX_CACHE_INTERPRETATION_VERTEX_POSITION,
2155
2156 // Vertex normals.
2157 UFBX_CACHE_INTERPRETATION_VERTEX_NORMAL,
2158
2159 UFBX_ENUM_FORCE_WIDTH(UFBX_CACHE_INTERPRETATION)
2160 } ufbx_cache_interpretation;
2161
2162 UFBX_ENUM_TYPE(ufbx_cache_interpretation, UFBX_CACHE_INTERPRETATION, UFBX_CACHE_INTERPRETATION_VERTEX_NORMAL);
2163
2164 typedef struct ufbx_cache_frame {
2165
2166 // Name of the channel this frame belongs to.
2167 ufbx_string channel;
2168
2169 // Time of this frame in seconds.
2170 double time;
2171
2172 // Name of the file containing the data.
2173 // The specified file may contain multiple frames, use `data_offset` etc. to
2174 // read at the right position.
2175 ufbx_string filename;
2176
2177 // Format of the wrapper file.
2178 ufbx_cache_file_format file_format;
2179
2180 // Axis to mirror the read data by.
2181 ufbx_mirror_axis mirror_axis;
2182
2183 // Factor to scale the geometry by.
2184 ufbx_real scale_factor;
2185
2186 ufbx_cache_data_format data_format; // < Format of the data in the file
2187 ufbx_cache_data_encoding data_encoding; // < Binary encoding of the data
2188 uint64_t data_offset; // < Byte offset into the file
2189 uint32_t data_count; // < Number of data elements
2190 uint32_t data_element_bytes; // < Size of a single data element in bytes
2191 uint64_t data_total_bytes; // < Size of the whole data blob in bytes
2192 } ufbx_cache_frame;
2193
2194 UFBX_LIST_TYPE(ufbx_cache_frame_list, ufbx_cache_frame);
2195
2196 typedef struct ufbx_cache_channel {
2197
2198 // Name of the geometry cache channel.
2199 ufbx_string name;
2200
2201 // What does the data in this channel represent.
2202 ufbx_cache_interpretation interpretation;
2203
2204 // Source name for `interpretation`, especially useful if `interpretation` is
2205 // `UFBX_CACHE_INTERPRETATION_UNKNOWN`.
2206 ufbx_string interpretation_name;
2207
2208 // List of frames belonging to this channel.
2209 // Sorted by time (`ufbx_cache_frame.time`).
2210 ufbx_cache_frame_list frames;
2211
2212 // Axis to mirror the frames by.
2213 ufbx_mirror_axis mirror_axis;
2214
2215 // Factor to scale the geometry by.
2216 ufbx_real scale_factor;
2217
2218 } ufbx_cache_channel;
2219
2220 UFBX_LIST_TYPE(ufbx_cache_channel_list, ufbx_cache_channel);
2221
2222 typedef struct ufbx_geometry_cache {
2223 ufbx_string root_filename;
2224 ufbx_cache_channel_list channels;
2225 ufbx_cache_frame_list frames;
2226 ufbx_string_list extra_info;
2227 } ufbx_geometry_cache;
2228
2229 struct ufbx_cache_deformer {
2230 union { ufbx_element element; struct {
2231 ufbx_string name;
2232 ufbx_props props;
2233 uint32_t element_id;
2234 uint32_t typed_id;
2235 }; };
2236
2237 ufbx_string channel;
2238 ufbx_nullable ufbx_cache_file *file;
2239
2240 // Only valid if `ufbx_load_opts.load_external_files` is set!
2241 ufbx_nullable ufbx_geometry_cache *external_cache;
2242 ufbx_nullable ufbx_cache_channel *external_channel;
2243 };
2244
2245 struct ufbx_cache_file {
2246 union { ufbx_element element; struct {
2247 ufbx_string name;
2248 ufbx_props props;
2249 uint32_t element_id;
2250 uint32_t typed_id;
2251 }; };
2252
2253 // Filename relative to the currently loaded file.
2254 // HINT: If using functions other than `ufbx_load_file()`, you can provide
2255 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
2256 ufbx_string filename;
2257 // Absolute filename specified in the file.
2258 ufbx_string absolute_filename;
2259 // Relative filename specified in the file.
2260 // NOTE: May be absolute if the file is saved in a different drive.
2261 ufbx_string relative_filename;
2262
2263 // Filename relative to the loaded file, non-UTF-8 encoded.
2264 // HINT: If using functions other than `ufbx_load_file()`, you can provide
2265 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
2266 ufbx_blob raw_filename;
2267 // Absolute filename specified in the file, non-UTF-8 encoded.
2268 ufbx_blob raw_absolute_filename;
2269 // Relative filename specified in the file, non-UTF-8 encoded.
2270 // NOTE: May be absolute if the file is saved in a different drive.
2271 ufbx_blob raw_relative_filename;
2272
2273 ufbx_cache_file_format format;
2274
2275 // Only valid if `ufbx_load_opts.load_external_files` is set!
2276 ufbx_nullable ufbx_geometry_cache *external_cache;
2277 };
2278
2279 // -- Materials
2280
2281 // Material property, either specified with a constant value or a mapped texture
2282 typedef struct ufbx_material_map {
2283
2284 // Constant value or factor for the map.
2285 // May be specified simultaneously with a texture, in this case most shading models
2286 // use multiplicative tinting of the texture values.
2287 union {
2288 ufbx_real value_real;
2289 ufbx_vec2 value_vec2;
2290 ufbx_vec3 value_vec3;
2291 ufbx_vec4 value_vec4;
2292 };
2293 int64_t value_int;
2294
2295 // Texture if connected, otherwise `NULL`.
2296 // May be valid but "disabled" (application specific) if `texture_enabled == false`.
2297 ufbx_nullable ufbx_texture *texture;
2298
2299 // `true` if the file has specified any of the values above.
2300 // NOTE: The value may be set to a non-zero default even if `has_value == false`,
2301 // for example missing factors are set to `1.0` if a color is defined.
2302 bool has_value;
2303
2304 // Controls whether shading should use `texture`.
2305 // NOTE: Some shading models allow this to be `true` even if `texture == NULL`.
2306 bool texture_enabled;
2307
2308 // Set to `true` if this feature should be disabled (specific to shader type).
2309 bool feature_disabled;
2310
2311 // Number of components in the value from 1 to 4 if defined, 0 if not.
2312 uint8_t value_components;
2313
2314 } ufbx_material_map;
2315
2316 // Material feature
2317 typedef struct ufbx_material_feature_info {
2318
2319 // Whether the material model uses this feature or not.
2320 // NOTE: The feature can be enabled but still not used if eg. the corresponding factor is at zero!
2321 bool enabled;
2322
2323 // Explicitly enabled/disabled by the material.
2324 bool is_explicit;
2325
2326 } ufbx_material_feature_info;
2327
2328 // Texture attached to an FBX property
2329 typedef struct ufbx_material_texture {
2330 ufbx_string material_prop; // < Name of the property in `ufbx_material.props`
2331 ufbx_string shader_prop; // < Shader-specific property mapping name
2332
2333 // Texture attached to the property.
2334 ufbx_texture *texture;
2335
2336 } ufbx_material_texture;
2337
2338 UFBX_LIST_TYPE(ufbx_material_texture_list, ufbx_material_texture);
2339
2340 // Shading model type
2341 typedef enum ufbx_shader_type UFBX_ENUM_REPR {
2342 // Unknown shading model
2343 UFBX_SHADER_UNKNOWN,
2344 // FBX builtin diffuse material
2345 UFBX_SHADER_FBX_LAMBERT,
2346 // FBX builtin diffuse+specular material
2347 UFBX_SHADER_FBX_PHONG,
2348 // Open Shading Language standard surface
2349 // https://github.com/Autodesk/standard-surface
2350 UFBX_SHADER_OSL_STANDARD_SURFACE,
2351 // Arnold standard surface
2352 // https://docs.arnoldrenderer.com/display/A5AFMUG/Standard+Surface
2353 UFBX_SHADER_ARNOLD_STANDARD_SURFACE,
2354 // 3ds Max Physical Material
2355 // https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2022/ENU/3DSMax-Lighting-Shading/files/GUID-C1328905-7783-4917-AB86-FC3CC19E8972-htm.html
2356 UFBX_SHADER_3DS_MAX_PHYSICAL_MATERIAL,
2357 // 3ds Max PBR (Metal/Rough) material
2358 // https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2021/ENU/3DSMax-Lighting-Shading/files/GUID-A16234A5-6500-4662-8B20-A5EC9FE1B255-htm.html
2359 UFBX_SHADER_3DS_MAX_PBR_METAL_ROUGH,
2360 // 3ds Max PBR (Spec/Gloss) material
2361 // https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2021/ENU/3DSMax-Lighting-Shading/files/GUID-18087194-B2A6-43EF-9B80-8FD1736FAE52-htm.html
2362 UFBX_SHADER_3DS_MAX_PBR_SPEC_GLOSS,
2363 // 3ds glTF Material
2364 // https://help.autodesk.com/view/3DSMAX/2023/ENU/?guid=GUID-7ABFB805-1D9F-417E-9C22-704BFDF160FA
2365 UFBX_SHADER_GLTF_MATERIAL,
2366 // 3ds OpenPBR Material
2367 // https://help.autodesk.com/view/3DSMAX/2025/ENU/?guid=GUID-CD90329C-1E2B-4BBA-9285-3BB46253B9C2
2368 UFBX_SHADER_OPENPBR_MATERIAL,
2369 // Stingray ShaderFX shader graph.
2370 // Contains a serialized `"ShaderGraph"` in `ufbx_props`.
2371 UFBX_SHADER_SHADERFX_GRAPH,
2372 // Variation of the FBX phong shader that can recover PBR properties like
2373 // `metalness` or `roughness` from the FBX non-physical values.
2374 // NOTE: Enable `ufbx_load_opts.use_blender_pbr_material`.
2375 UFBX_SHADER_BLENDER_PHONG,
2376 // Wavefront .mtl format shader (used by .obj files)
2377 UFBX_SHADER_WAVEFRONT_MTL,
2378
2379 UFBX_ENUM_FORCE_WIDTH(UFBX_SHADER_TYPE)
2380 } ufbx_shader_type;
2381
2382 UFBX_ENUM_TYPE(ufbx_shader_type, UFBX_SHADER_TYPE, UFBX_SHADER_WAVEFRONT_MTL);
2383
2384 // FBX builtin material properties, matches maps in `ufbx_material_fbx_maps`
2385 typedef enum ufbx_material_fbx_map UFBX_ENUM_REPR {
2386 UFBX_MATERIAL_FBX_DIFFUSE_FACTOR,
2387 UFBX_MATERIAL_FBX_DIFFUSE_COLOR,
2388 UFBX_MATERIAL_FBX_SPECULAR_FACTOR,
2389 UFBX_MATERIAL_FBX_SPECULAR_COLOR,
2390 UFBX_MATERIAL_FBX_SPECULAR_EXPONENT,
2391 UFBX_MATERIAL_FBX_REFLECTION_FACTOR,
2392 UFBX_MATERIAL_FBX_REFLECTION_COLOR,
2393 UFBX_MATERIAL_FBX_TRANSPARENCY_FACTOR,
2394 UFBX_MATERIAL_FBX_TRANSPARENCY_COLOR,
2395 UFBX_MATERIAL_FBX_EMISSION_FACTOR,
2396 UFBX_MATERIAL_FBX_EMISSION_COLOR,
2397 UFBX_MATERIAL_FBX_AMBIENT_FACTOR,
2398 UFBX_MATERIAL_FBX_AMBIENT_COLOR,
2399 UFBX_MATERIAL_FBX_NORMAL_MAP,
2400 UFBX_MATERIAL_FBX_BUMP,
2401 UFBX_MATERIAL_FBX_BUMP_FACTOR,
2402 UFBX_MATERIAL_FBX_DISPLACEMENT_FACTOR,
2403 UFBX_MATERIAL_FBX_DISPLACEMENT,
2404 UFBX_MATERIAL_FBX_VECTOR_DISPLACEMENT_FACTOR,
2405 UFBX_MATERIAL_FBX_VECTOR_DISPLACEMENT,
2406
2407 UFBX_ENUM_FORCE_WIDTH(UFBX_MATERIAL_FBX_MAP)
2408 } ufbx_material_fbx_map;
2409
2410 UFBX_ENUM_TYPE(ufbx_material_fbx_map, UFBX_MATERIAL_FBX_MAP, UFBX_MATERIAL_FBX_VECTOR_DISPLACEMENT);
2411
2412 // Known PBR material properties, matches maps in `ufbx_material_pbr_maps`
2413 typedef enum ufbx_material_pbr_map UFBX_ENUM_REPR {
2414 UFBX_MATERIAL_PBR_BASE_FACTOR,
2415 UFBX_MATERIAL_PBR_BASE_COLOR,
2416 UFBX_MATERIAL_PBR_ROUGHNESS,
2417 UFBX_MATERIAL_PBR_METALNESS,
2418 UFBX_MATERIAL_PBR_DIFFUSE_ROUGHNESS,
2419 UFBX_MATERIAL_PBR_SPECULAR_FACTOR,
2420 UFBX_MATERIAL_PBR_SPECULAR_COLOR,
2421 UFBX_MATERIAL_PBR_SPECULAR_IOR,
2422 UFBX_MATERIAL_PBR_SPECULAR_ANISOTROPY,
2423 UFBX_MATERIAL_PBR_SPECULAR_ROTATION,
2424 UFBX_MATERIAL_PBR_TRANSMISSION_FACTOR,
2425 UFBX_MATERIAL_PBR_TRANSMISSION_COLOR,
2426 UFBX_MATERIAL_PBR_TRANSMISSION_DEPTH,
2427 UFBX_MATERIAL_PBR_TRANSMISSION_SCATTER,
2428 UFBX_MATERIAL_PBR_TRANSMISSION_SCATTER_ANISOTROPY,
2429 UFBX_MATERIAL_PBR_TRANSMISSION_DISPERSION,
2430 UFBX_MATERIAL_PBR_TRANSMISSION_ROUGHNESS,
2431 UFBX_MATERIAL_PBR_TRANSMISSION_EXTRA_ROUGHNESS,
2432 UFBX_MATERIAL_PBR_TRANSMISSION_PRIORITY,
2433 UFBX_MATERIAL_PBR_TRANSMISSION_ENABLE_IN_AOV,
2434 UFBX_MATERIAL_PBR_SUBSURFACE_FACTOR,
2435 UFBX_MATERIAL_PBR_SUBSURFACE_COLOR,
2436 UFBX_MATERIAL_PBR_SUBSURFACE_RADIUS,
2437 UFBX_MATERIAL_PBR_SUBSURFACE_SCALE,
2438 UFBX_MATERIAL_PBR_SUBSURFACE_ANISOTROPY,
2439 UFBX_MATERIAL_PBR_SUBSURFACE_TINT_COLOR,
2440 UFBX_MATERIAL_PBR_SUBSURFACE_TYPE,
2441 UFBX_MATERIAL_PBR_SHEEN_FACTOR,
2442 UFBX_MATERIAL_PBR_SHEEN_COLOR,
2443 UFBX_MATERIAL_PBR_SHEEN_ROUGHNESS,
2444 UFBX_MATERIAL_PBR_COAT_FACTOR,
2445 UFBX_MATERIAL_PBR_COAT_COLOR,
2446 UFBX_MATERIAL_PBR_COAT_ROUGHNESS,
2447 UFBX_MATERIAL_PBR_COAT_IOR,
2448 UFBX_MATERIAL_PBR_COAT_ANISOTROPY,
2449 UFBX_MATERIAL_PBR_COAT_ROTATION,
2450 UFBX_MATERIAL_PBR_COAT_NORMAL,
2451 UFBX_MATERIAL_PBR_COAT_AFFECT_BASE_COLOR,
2452 UFBX_MATERIAL_PBR_COAT_AFFECT_BASE_ROUGHNESS,
2453 UFBX_MATERIAL_PBR_THIN_FILM_FACTOR,
2454 UFBX_MATERIAL_PBR_THIN_FILM_THICKNESS,
2455 UFBX_MATERIAL_PBR_THIN_FILM_IOR,
2456 UFBX_MATERIAL_PBR_EMISSION_FACTOR,
2457 UFBX_MATERIAL_PBR_EMISSION_COLOR,
2458 UFBX_MATERIAL_PBR_OPACITY,
2459 UFBX_MATERIAL_PBR_INDIRECT_DIFFUSE,
2460 UFBX_MATERIAL_PBR_INDIRECT_SPECULAR,
2461 UFBX_MATERIAL_PBR_NORMAL_MAP,
2462 UFBX_MATERIAL_PBR_TANGENT_MAP,
2463 UFBX_MATERIAL_PBR_DISPLACEMENT_MAP,
2464 UFBX_MATERIAL_PBR_MATTE_FACTOR,
2465 UFBX_MATERIAL_PBR_MATTE_COLOR,
2466 UFBX_MATERIAL_PBR_AMBIENT_OCCLUSION,
2467 UFBX_MATERIAL_PBR_GLOSSINESS,
2468 UFBX_MATERIAL_PBR_COAT_GLOSSINESS,
2469 UFBX_MATERIAL_PBR_TRANSMISSION_GLOSSINESS,
2470
2471 UFBX_ENUM_FORCE_WIDTH(UFBX_MATERIAL_PBR_MAP)
2472 } ufbx_material_pbr_map;
2473
2474 UFBX_ENUM_TYPE(ufbx_material_pbr_map, UFBX_MATERIAL_PBR_MAP, UFBX_MATERIAL_PBR_TRANSMISSION_GLOSSINESS);
2475
2476 // Known material features
2477 typedef enum ufbx_material_feature UFBX_ENUM_REPR {
2478 UFBX_MATERIAL_FEATURE_PBR,
2479 UFBX_MATERIAL_FEATURE_METALNESS,
2480 UFBX_MATERIAL_FEATURE_DIFFUSE,
2481 UFBX_MATERIAL_FEATURE_SPECULAR,
2482 UFBX_MATERIAL_FEATURE_EMISSION,
2483 UFBX_MATERIAL_FEATURE_TRANSMISSION,
2484 UFBX_MATERIAL_FEATURE_COAT,
2485 UFBX_MATERIAL_FEATURE_SHEEN,
2486 UFBX_MATERIAL_FEATURE_OPACITY,
2487 UFBX_MATERIAL_FEATURE_AMBIENT_OCCLUSION,
2488 UFBX_MATERIAL_FEATURE_MATTE,
2489 UFBX_MATERIAL_FEATURE_UNLIT,
2490 UFBX_MATERIAL_FEATURE_IOR,
2491 UFBX_MATERIAL_FEATURE_DIFFUSE_ROUGHNESS,
2492 UFBX_MATERIAL_FEATURE_TRANSMISSION_ROUGHNESS,
2493 UFBX_MATERIAL_FEATURE_THIN_WALLED,
2494 UFBX_MATERIAL_FEATURE_CAUSTICS,
2495 UFBX_MATERIAL_FEATURE_EXIT_TO_BACKGROUND,
2496 UFBX_MATERIAL_FEATURE_INTERNAL_REFLECTIONS,
2497 UFBX_MATERIAL_FEATURE_DOUBLE_SIDED,
2498 UFBX_MATERIAL_FEATURE_ROUGHNESS_AS_GLOSSINESS,
2499 UFBX_MATERIAL_FEATURE_COAT_ROUGHNESS_AS_GLOSSINESS,
2500 UFBX_MATERIAL_FEATURE_TRANSMISSION_ROUGHNESS_AS_GLOSSINESS,
2501
2502 UFBX_ENUM_FORCE_WIDTH(UFBX_MATERIAL_FEATURE)
2503 } ufbx_material_feature;
2504
2505 UFBX_ENUM_TYPE(ufbx_material_feature, UFBX_MATERIAL_FEATURE, UFBX_MATERIAL_FEATURE_TRANSMISSION_ROUGHNESS_AS_GLOSSINESS);
2506
2507 typedef struct ufbx_material_fbx_maps {
2508 union {
2509 ufbx_material_map maps[UFBX_MATERIAL_FBX_MAP_COUNT];
2510 struct {
2511 ufbx_material_map diffuse_factor;
2512 ufbx_material_map diffuse_color;
2513 ufbx_material_map specular_factor;
2514 ufbx_material_map specular_color;
2515 ufbx_material_map specular_exponent;
2516 ufbx_material_map reflection_factor;
2517 ufbx_material_map reflection_color;
2518 ufbx_material_map transparency_factor;
2519 ufbx_material_map transparency_color;
2520 ufbx_material_map emission_factor;
2521 ufbx_material_map emission_color;
2522 ufbx_material_map ambient_factor;
2523 ufbx_material_map ambient_color;
2524 ufbx_material_map normal_map;
2525 ufbx_material_map bump;
2526 ufbx_material_map bump_factor;
2527 ufbx_material_map displacement_factor;
2528 ufbx_material_map displacement;
2529 ufbx_material_map vector_displacement_factor;
2530 ufbx_material_map vector_displacement;
2531 };
2532 };
2533 } ufbx_material_fbx_maps;
2534
2535 typedef struct ufbx_material_pbr_maps {
2536 union {
2537 ufbx_material_map maps[UFBX_MATERIAL_PBR_MAP_COUNT];
2538 struct {
2539 ufbx_material_map base_factor;
2540 ufbx_material_map base_color;
2541 ufbx_material_map roughness;
2542 ufbx_material_map metalness;
2543 ufbx_material_map diffuse_roughness;
2544 ufbx_material_map specular_factor;
2545 ufbx_material_map specular_color;
2546 ufbx_material_map specular_ior;
2547 ufbx_material_map specular_anisotropy;
2548 ufbx_material_map specular_rotation;
2549 ufbx_material_map transmission_factor;
2550 ufbx_material_map transmission_color;
2551 ufbx_material_map transmission_depth;
2552 ufbx_material_map transmission_scatter;
2553 ufbx_material_map transmission_scatter_anisotropy;
2554 ufbx_material_map transmission_dispersion;
2555 ufbx_material_map transmission_roughness;
2556 ufbx_material_map transmission_extra_roughness;
2557 ufbx_material_map transmission_priority;
2558 ufbx_material_map transmission_enable_in_aov;
2559 ufbx_material_map subsurface_factor;
2560 ufbx_material_map subsurface_color;
2561 ufbx_material_map subsurface_radius;
2562 ufbx_material_map subsurface_scale;
2563 ufbx_material_map subsurface_anisotropy;
2564 ufbx_material_map subsurface_tint_color;
2565 ufbx_material_map subsurface_type;
2566 ufbx_material_map sheen_factor;
2567 ufbx_material_map sheen_color;
2568 ufbx_material_map sheen_roughness;
2569 ufbx_material_map coat_factor;
2570 ufbx_material_map coat_color;
2571 ufbx_material_map coat_roughness;
2572 ufbx_material_map coat_ior;
2573 ufbx_material_map coat_anisotropy;
2574 ufbx_material_map coat_rotation;
2575 ufbx_material_map coat_normal;
2576 ufbx_material_map coat_affect_base_color;
2577 ufbx_material_map coat_affect_base_roughness;
2578 ufbx_material_map thin_film_factor;
2579 ufbx_material_map thin_film_thickness;
2580 ufbx_material_map thin_film_ior;
2581 ufbx_material_map emission_factor;
2582 ufbx_material_map emission_color;
2583 ufbx_material_map opacity;
2584 ufbx_material_map indirect_diffuse;
2585 ufbx_material_map indirect_specular;
2586 ufbx_material_map normal_map;
2587 ufbx_material_map tangent_map;
2588 ufbx_material_map displacement_map;
2589 ufbx_material_map matte_factor;
2590 ufbx_material_map matte_color;
2591 ufbx_material_map ambient_occlusion;
2592 ufbx_material_map glossiness;
2593 ufbx_material_map coat_glossiness;
2594 ufbx_material_map transmission_glossiness;
2595 };
2596 };
2597 } ufbx_material_pbr_maps;
2598
2599 typedef struct ufbx_material_features {
2600 union {
2601 ufbx_material_feature_info features[UFBX_MATERIAL_FEATURE_COUNT];
2602 struct {
2603 ufbx_material_feature_info pbr;
2604 ufbx_material_feature_info metalness;
2605 ufbx_material_feature_info diffuse;
2606 ufbx_material_feature_info specular;
2607 ufbx_material_feature_info emission;
2608 ufbx_material_feature_info transmission;
2609 ufbx_material_feature_info coat;
2610 ufbx_material_feature_info sheen;
2611 ufbx_material_feature_info opacity;
2612 ufbx_material_feature_info ambient_occlusion;
2613 ufbx_material_feature_info matte;
2614 ufbx_material_feature_info unlit;
2615 ufbx_material_feature_info ior;
2616 ufbx_material_feature_info diffuse_roughness;
2617 ufbx_material_feature_info transmission_roughness;
2618 ufbx_material_feature_info thin_walled;
2619 ufbx_material_feature_info caustics;
2620 ufbx_material_feature_info exit_to_background;
2621 ufbx_material_feature_info internal_reflections;
2622 ufbx_material_feature_info double_sided;
2623 ufbx_material_feature_info roughness_as_glossiness;
2624 ufbx_material_feature_info coat_roughness_as_glossiness;
2625 ufbx_material_feature_info transmission_roughness_as_glossiness;
2626 };
2627 };
2628 } ufbx_material_features;
2629
2630 // Surface material properties such as color, roughness, etc. Each property may
2631 // be optionally bound to an `ufbx_texture`.
2632 struct ufbx_material {
2633 union { ufbx_element element; struct {
2634 ufbx_string name;
2635 ufbx_props props;
2636 uint32_t element_id;
2637 uint32_t typed_id;
2638 }; };
2639
2640 // FBX builtin properties
2641 // NOTE: These may be empty if the material is using a custom shader
2642 ufbx_material_fbx_maps fbx;
2643
2644 // PBR material properties, defined for all shading models but may be
2645 // somewhat approximate if `shader == NULL`.
2646 ufbx_material_pbr_maps pbr;
2647
2648 // Material features, primarily applies to `pbr`.
2649 ufbx_material_features features;
2650
2651 // Shading information
2652 ufbx_shader_type shader_type; // < Always defined
2653 ufbx_nullable ufbx_shader *shader; // < Optional extended shader information
2654 ufbx_string shading_model_name; // < Often one of `{ "lambert", "phong", "unknown" }`
2655
2656 // Prefix before shader property names with trailing `|`.
2657 // For example `"3dsMax|Parameters|"` where properties would have names like
2658 // `"3dsMax|Parameters|base_color"`. You can ignore this if you use the built-in
2659 // `ufbx_material_fbx_maps fbx` and `ufbx_material_pbr_maps pbr` structures.
2660 ufbx_string shader_prop_prefix;
2661
2662 // All textures attached to the material, if you want specific maps if might be
2663 // more convenient to use eg. `fbx.diffuse_color.texture` or `pbr.base_color.texture`
2664 ufbx_material_texture_list textures; // < Sorted by `material_prop`
2665 };
2666
2667 typedef enum ufbx_texture_type UFBX_ENUM_REPR {
2668
2669 // Texture associated with an image file/sequence. `texture->filename` and
2670 // and `texture->relative_filename` contain the texture's path. If the file
2671 // has embedded content `texture->content` may hold `texture->content_size`
2672 // bytes of raw image data.
2673 UFBX_TEXTURE_FILE,
2674
2675 // The texture consists of multiple texture layers blended together.
2676 UFBX_TEXTURE_LAYERED,
2677
2678 // Reserved as these _should_ exist in FBX files.
2679 UFBX_TEXTURE_PROCEDURAL,
2680
2681 // Node in a shader graph.
2682 // Use `ufbx_texture.shader` for more information.
2683 UFBX_TEXTURE_SHADER,
2684
2685 UFBX_ENUM_FORCE_WIDTH(UFBX_TEXTURE_TYPE)
2686 } ufbx_texture_type;
2687
2688 UFBX_ENUM_TYPE(ufbx_texture_type, UFBX_TEXTURE_TYPE, UFBX_TEXTURE_SHADER);
2689
2690 // Blend modes to combine layered textures with, compatible with common blend
2691 // mode definitions in many art programs. Simpler blend modes have equations
2692 // specified below where `src` is the layer to composite over `dst`.
2693 // See eg. https://www.w3.org/TR/2013/WD-compositing-1-20131010/#blendingseparable
2694 typedef enum ufbx_blend_mode UFBX_ENUM_REPR {
2695 UFBX_BLEND_TRANSLUCENT, // < `src` effects result alpha
2696 UFBX_BLEND_ADDITIVE, // < `src + dst`
2697 UFBX_BLEND_MULTIPLY, // < `src * dst`
2698 UFBX_BLEND_MULTIPLY_2X, // < `2 * src * dst`
2699 UFBX_BLEND_OVER, // < `src * src_alpha + dst * (1-src_alpha)`
2700 UFBX_BLEND_REPLACE, // < `src` Replace the contents
2701 UFBX_BLEND_DISSOLVE, // < `random() + src_alpha >= 1.0 ? src : dst`
2702 UFBX_BLEND_DARKEN, // < `min(src, dst)`
2703 UFBX_BLEND_COLOR_BURN, // < `src > 0 ? 1 - min(1, (1-dst) / src) : 0`
2704 UFBX_BLEND_LINEAR_BURN, // < `src + dst - 1`
2705 UFBX_BLEND_DARKER_COLOR, // < `value(src) < value(dst) ? src : dst`
2706 UFBX_BLEND_LIGHTEN, // < `max(src, dst)`
2707 UFBX_BLEND_SCREEN, // < `1 - (1-src)*(1-dst)`
2708 UFBX_BLEND_COLOR_DODGE, // < `src < 1 ? dst / (1 - src)` : (dst>0?1:0)`
2709 UFBX_BLEND_LINEAR_DODGE, // < `src + dst`
2710 UFBX_BLEND_LIGHTER_COLOR, // < `value(src) > value(dst) ? src : dst`
2711 UFBX_BLEND_SOFT_LIGHT, // < https://www.w3.org/TR/2013/WD-compositing-1-20131010/#blendingsoftlight
2712 UFBX_BLEND_HARD_LIGHT, // < https://www.w3.org/TR/2013/WD-compositing-1-20131010/#blendinghardlight
2713 UFBX_BLEND_VIVID_LIGHT, // < Combination of `COLOR_DODGE` and `COLOR_BURN`
2714 UFBX_BLEND_LINEAR_LIGHT, // < Combination of `LINEAR_DODGE` and `LINEAR_BURN`
2715 UFBX_BLEND_PIN_LIGHT, // < Combination of `DARKEN` and `LIGHTEN`
2716 UFBX_BLEND_HARD_MIX, // < Produces primary colors depending on similarity
2717 UFBX_BLEND_DIFFERENCE, // < `abs(src - dst)`
2718 UFBX_BLEND_EXCLUSION, // < `dst + src - 2 * src * dst`
2719 UFBX_BLEND_SUBTRACT, // < `dst - src`
2720 UFBX_BLEND_DIVIDE, // < `dst / src`
2721 UFBX_BLEND_HUE, // < Replace hue
2722 UFBX_BLEND_SATURATION, // < Replace saturation
2723 UFBX_BLEND_COLOR, // < Replace hue and saturatio
2724 UFBX_BLEND_LUMINOSITY, // < Replace value
2725 UFBX_BLEND_OVERLAY, // < Same as `HARD_LIGHT` but with `src` and `dst` swapped
2726
2727 UFBX_ENUM_FORCE_WIDTH(UFBX_BLEND_MODE)
2728 } ufbx_blend_mode;
2729
2730 UFBX_ENUM_TYPE(ufbx_blend_mode, UFBX_BLEND_MODE, UFBX_BLEND_OVERLAY);
2731
2732 // Blend modes to combine layered textures with, compatible with common blend
2733 typedef enum ufbx_wrap_mode UFBX_ENUM_REPR {
2734 UFBX_WRAP_REPEAT, // < Repeat the texture past the [0,1] range
2735 UFBX_WRAP_CLAMP, // < Clamp the normalized texture coordinates to [0,1]
2736
2737 UFBX_ENUM_FORCE_WIDTH(UFBX_WRAP_MODE)
2738 } ufbx_wrap_mode;
2739
2740 UFBX_ENUM_TYPE(ufbx_wrap_mode, UFBX_WRAP_MODE, UFBX_WRAP_CLAMP);
2741
2742 // Single layer in a layered texture
2743 typedef struct ufbx_texture_layer {
2744 ufbx_texture *texture; // < The inner texture to evaluate, never `NULL`
2745 ufbx_blend_mode blend_mode; // < Equation to combine the layer to the background
2746 ufbx_real alpha; // < Blend weight of this layer
2747 } ufbx_texture_layer;
2748
2749 UFBX_LIST_TYPE(ufbx_texture_layer_list, ufbx_texture_layer);
2750
2751 typedef enum ufbx_shader_texture_type UFBX_ENUM_REPR {
2752 UFBX_SHADER_TEXTURE_UNKNOWN,
2753
2754 // Select an output of a multi-output shader.
2755 // HINT: If this type is used the `ufbx_shader_texture.main_texture` and
2756 // `ufbx_shader_texture.main_texture_output_index` fields are set.
2757 UFBX_SHADER_TEXTURE_SELECT_OUTPUT,
2758
2759 // Open Shading Language (OSL) shader.
2760 // https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
2761 UFBX_SHADER_TEXTURE_OSL,
2762
2763 UFBX_ENUM_FORCE_WIDTH(UFBX_SHADER_TEXTURE_TYPE)
2764 } ufbx_shader_texture_type;
2765
2766 UFBX_ENUM_TYPE(ufbx_shader_texture_type, UFBX_SHADER_TEXTURE_TYPE, UFBX_SHADER_TEXTURE_OSL);
2767
2768 // Input to a shader texture, see `ufbx_shader_texture`.
2769 typedef struct ufbx_shader_texture_input {
2770
2771 // Name of the input.
2772 ufbx_string name;
2773
2774 // Constant value of the input.
2775 union {
2776 ufbx_real value_real;
2777 ufbx_vec2 value_vec2;
2778 ufbx_vec3 value_vec3;
2779 ufbx_vec4 value_vec4;
2780 };
2781 int64_t value_int;
2782 ufbx_string value_str;
2783 ufbx_blob value_blob;
2784
2785 // Texture connected to this input.
2786 ufbx_nullable ufbx_texture *texture;
2787
2788 // Index of the output to use if `texture` is a multi-output shader node.
2789 int64_t texture_output_index;
2790
2791 // Controls whether shading should use `texture`.
2792 // NOTE: Some shading models allow this to be `true` even if `texture == NULL`.
2793 bool texture_enabled;
2794
2795 // Property representing this input.
2796 ufbx_prop *prop;
2797
2798 // Property representing `texture`.
2799 ufbx_nullable ufbx_prop *texture_prop;
2800
2801 // Property representing `texture_enabled`.
2802 ufbx_nullable ufbx_prop *texture_enabled_prop;
2803
2804 } ufbx_shader_texture_input;
2805
2806 UFBX_LIST_TYPE(ufbx_shader_texture_input_list, ufbx_shader_texture_input);
2807
2808 // Texture that emulates a shader graph node.
2809 // 3ds Max exports some materials as node graphs serialized to textures.
2810 // ufbx can parse a small subset of these, as normal maps are often hidden behind
2811 // some kind of bump node.
2812 // NOTE: These encode a lot of details of 3ds Max internals, not recommended for direct use.
2813 // HINT: `ufbx_texture.file_textures[]` contains a list of "real" textures that are connected
2814 // to the `ufbx_texture` that is pretending to be a shader node.
2815 typedef struct ufbx_shader_texture {
2816
2817 // Type of this shader node.
2818 ufbx_shader_texture_type type;
2819
2820 // Name of the shader to use.
2821 ufbx_string shader_name;
2822
2823 // 64-bit opaque identifier for the shader type.
2824 uint64_t shader_type_id;
2825
2826 // Input values/textures (possibly further shader textures) to the shader.
2827 // Sorted by `ufbx_shader_texture_input.name`.
2828 ufbx_shader_texture_input_list inputs;
2829
2830 // Shader source code if found.
2831 ufbx_string shader_source;
2832 ufbx_blob raw_shader_source;
2833
2834 // Representative texture for this shader.
2835 // Only specified if `main_texture.outputs[main_texture_output_index]` is semantically
2836 // equivalent to this texture.
2837 ufbx_texture *main_texture;
2838
2839 // Output index of `main_texture` if it is a multi-output shader.
2840 int64_t main_texture_output_index;
2841
2842 // Prefix for properties related to this shader in `ufbx_texture`.
2843 // NOTE: Contains the trailing '|' if not empty.
2844 ufbx_string prop_prefix;
2845
2846 } ufbx_shader_texture;
2847
2848 // Unique texture within the file.
2849 typedef struct ufbx_texture_file {
2850
2851 // Index in `ufbx_scene.texture_files[]`.
2852 uint32_t index;
2853
2854 // Paths to the resource.
2855
2856 // Filename relative to the currently loaded file.
2857 // HINT: If using functions other than `ufbx_load_file()`, you can provide
2858 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
2859 ufbx_string filename;
2860 // Absolute filename specified in the file.
2861 ufbx_string absolute_filename;
2862 // Relative filename specified in the file.
2863 // NOTE: May be absolute if the file is saved in a different drive.
2864 ufbx_string relative_filename;
2865
2866 // Filename relative to the loaded file, non-UTF-8 encoded.
2867 // HINT: If using functions other than `ufbx_load_file()`, you can provide
2868 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
2869 ufbx_blob raw_filename;
2870 // Absolute filename specified in the file, non-UTF-8 encoded.
2871 ufbx_blob raw_absolute_filename;
2872 // Relative filename specified in the file, non-UTF-8 encoded.
2873 // NOTE: May be absolute if the file is saved in a different drive.
2874 ufbx_blob raw_relative_filename;
2875
2876 // Optional embedded content blob, eg. raw .png format data
2877 ufbx_blob content;
2878
2879 } ufbx_texture_file;
2880
2881 UFBX_LIST_TYPE(ufbx_texture_file_list, ufbx_texture_file);
2882
2883 // Texture that controls material appearance
2884 struct ufbx_texture {
2885 union { ufbx_element element; struct {
2886 ufbx_string name;
2887 ufbx_props props;
2888 uint32_t element_id;
2889 uint32_t typed_id;
2890 }; };
2891
2892 // Texture type (file / layered / procedural / shader)
2893 ufbx_texture_type type;
2894
2895 // FILE: Paths to the resource
2896
2897 // Filename relative to the currently loaded file.
2898 // HINT: If using functions other than `ufbx_load_file()`, you can provide
2899 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
2900 ufbx_string filename;
2901 // Absolute filename specified in the file.
2902 ufbx_string absolute_filename;
2903 // Relative filename specified in the file.
2904 // NOTE: May be absolute if the file is saved in a different drive.
2905 ufbx_string relative_filename;
2906
2907 // Filename relative to the loaded file, non-UTF-8 encoded.
2908 // HINT: If using functions other than `ufbx_load_file()`, you can provide
2909 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
2910 ufbx_blob raw_filename;
2911 // Absolute filename specified in the file, non-UTF-8 encoded.
2912 ufbx_blob raw_absolute_filename;
2913 // Relative filename specified in the file, non-UTF-8 encoded.
2914 // NOTE: May be absolute if the file is saved in a different drive.
2915 ufbx_blob raw_relative_filename;
2916
2917 // FILE: Optional embedded content blob, eg. raw .png format data
2918 ufbx_blob content;
2919
2920 // FILE: Optional video texture
2921 ufbx_nullable ufbx_video *video;
2922
2923 // FILE: Index into `ufbx_scene.texture_files[]` or `UFBX_NO_INDEX`.
2924 uint32_t file_index;
2925
2926 // FILE: True if `file_index` has a valid value.
2927 bool has_file;
2928
2929 // LAYERED: Inner texture layers, ordered from _bottom_ to _top_
2930 ufbx_texture_layer_list layers;
2931
2932 // SHADER: Shader information
2933 // NOTE: May be specified even if `type == UFBX_TEXTURE_FILE` if `ufbx_load_opts.disable_quirks`
2934 // is _not_ specified. Some known shaders that represent files are interpreted as `UFBX_TEXTURE_FILE`.
2935 ufbx_nullable ufbx_shader_texture *shader;
2936
2937 // List of file textures representing this texture.
2938 // Defined even if `type == UFBX_TEXTURE_FILE` in which case the array contains only itself.
2939 ufbx_texture_list file_textures;
2940
2941 // Name of the UV set to use
2942 ufbx_string uv_set;
2943
2944 // Wrapping mode
2945 ufbx_wrap_mode wrap_u;
2946 ufbx_wrap_mode wrap_v;
2947
2948 // UV transform
2949 bool has_uv_transform; // < Has a non-identity `transform` and derived matrices.
2950 ufbx_transform uv_transform; // < Texture transformation in UV space
2951 ufbx_matrix texture_to_uv; // < Matrix representation of `transform`
2952 ufbx_matrix uv_to_texture; // < UV coordinate to normalized texture coordinate matrix
2953 };
2954
2955 // TODO: Video textures
2956 struct ufbx_video {
2957 union { ufbx_element element; struct {
2958 ufbx_string name;
2959 ufbx_props props;
2960 uint32_t element_id;
2961 uint32_t typed_id;
2962 }; };
2963
2964 // Paths to the resource
2965
2966 // Filename relative to the currently loaded file.
2967 // HINT: If using functions other than `ufbx_load_file()`, you can provide
2968 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
2969 ufbx_string filename;
2970 // Absolute filename specified in the file.
2971 ufbx_string absolute_filename;
2972 // Relative filename specified in the file.
2973 // NOTE: May be absolute if the file is saved in a different drive.
2974 ufbx_string relative_filename;
2975
2976 // Filename relative to the loaded file, non-UTF-8 encoded.
2977 // HINT: If using functions other than `ufbx_load_file()`, you can provide
2978 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
2979 ufbx_blob raw_filename;
2980 // Absolute filename specified in the file, non-UTF-8 encoded.
2981 ufbx_blob raw_absolute_filename;
2982 // Relative filename specified in the file, non-UTF-8 encoded.
2983 // NOTE: May be absolute if the file is saved in a different drive.
2984 ufbx_blob raw_relative_filename;
2985
2986 // Optional embedded content blob
2987 ufbx_blob content;
2988 };
2989
2990 // Shader specifies a shading model and contains `ufbx_shader_binding` elements
2991 // that define how to interpret FBX properties in the shader.
2992 struct ufbx_shader {
2993 union { ufbx_element element; struct {
2994 ufbx_string name;
2995 ufbx_props props;
2996 uint32_t element_id;
2997 uint32_t typed_id;
2998 }; };
2999
3000 // Known shading model
3001 ufbx_shader_type type;
3002
3003 // TODO: Expose actual properties here
3004
3005 // Bindings from FBX properties to the shader
3006 // HINT: `ufbx_find_shader_prop()` translates shader properties to FBX properties
3007 ufbx_shader_binding_list bindings;
3008 };
3009
3010 // Binding from a material property to shader implementation
3011 typedef struct ufbx_shader_prop_binding {
3012 ufbx_string shader_prop; // < Property name used by the shader implementation
3013 ufbx_string material_prop; // < Property name inside `ufbx_material.props`
3014 } ufbx_shader_prop_binding;
3015
3016 UFBX_LIST_TYPE(ufbx_shader_prop_binding_list, ufbx_shader_prop_binding);
3017
3018 // Shader binding table
3019 struct ufbx_shader_binding {
3020 union { ufbx_element element; struct {
3021 ufbx_string name;
3022 ufbx_props props;
3023 uint32_t element_id;
3024 uint32_t typed_id;
3025 }; };
3026
3027 ufbx_shader_prop_binding_list prop_bindings; // < Sorted by `shader_prop`
3028 };
3029
3030 // -- Animation
3031
3032 typedef struct ufbx_prop_override {
3033 uint32_t element_id;
3034
3035 uint32_t _internal_key;
3036
3037 ufbx_string prop_name;
3038 ufbx_vec4 value;
3039 ufbx_string value_str;
3040 int64_t value_int;
3041 } ufbx_prop_override;
3042
3043 UFBX_LIST_TYPE(ufbx_prop_override_list, ufbx_prop_override);
3044
3045 typedef struct ufbx_transform_override {
3046 uint32_t node_id;
3047 ufbx_transform transform;
3048 } ufbx_transform_override;
3049
3050 UFBX_LIST_TYPE(ufbx_transform_override_list, ufbx_transform_override);
3051
3052 // Animation descriptor used for evaluating animation.
3053 // Usually obtained from `ufbx_scene` via either global animation `ufbx_scene.anim`,
3054 // per-stack animation `ufbx_anim_stack.anim` or per-layer animation `ufbx_anim_layer.anim`.
3055 //
3056 // For advanced usage you can use `ufbx_create_anim()` to create animation descriptors
3057 // with custom layers, property overrides, special flags, etc.
3058 typedef struct ufbx_anim {
3059
3060 // Time begin/end for the animation, both may be zero if absent.
3061 double time_begin;
3062 double time_end;
3063
3064 // List of layers in the animation.
3065 ufbx_anim_layer_list layers;
3066
3067 // Optional overrides for weights for each layer in `layers[]`.
3068 ufbx_real_list override_layer_weights;
3069
3070 // Sorted by `element_id, prop_name`
3071 ufbx_prop_override_list prop_overrides;
3072
3073 // Sorted by `node_id`
3074 ufbx_transform_override_list transform_overrides;
3075
3076 // Evaluate connected properties as if they would not be connected.
3077 bool ignore_connections;
3078
3079 // Custom `ufbx_anim` created by `ufbx_create_anim()`.
3080 bool custom;
3081
3082 } ufbx_anim;
3083
3084 struct ufbx_anim_stack {
3085 union { ufbx_element element; struct {
3086 ufbx_string name;
3087 ufbx_props props;
3088 uint32_t element_id;
3089 uint32_t typed_id;
3090 }; };
3091
3092 double time_begin;
3093 double time_end;
3094
3095 ufbx_anim_layer_list layers;
3096 ufbx_anim *anim;
3097 };
3098
3099 typedef struct ufbx_anim_prop {
3100 ufbx_element *element;
3101
3102 uint32_t _internal_key;
3103
3104 ufbx_string prop_name;
3105 ufbx_anim_value *anim_value;
3106 } ufbx_anim_prop;
3107
3108 UFBX_LIST_TYPE(ufbx_anim_prop_list, ufbx_anim_prop);
3109
3110 struct ufbx_anim_layer {
3111 union { ufbx_element element; struct {
3112 ufbx_string name;
3113 ufbx_props props;
3114 uint32_t element_id;
3115 uint32_t typed_id;
3116 }; };
3117
3118 ufbx_real weight;
3119 bool weight_is_animated;
3120 bool blended;
3121 bool additive;
3122 bool compose_rotation;
3123 bool compose_scale;
3124
3125 ufbx_anim_value_list anim_values;
3126 ufbx_anim_prop_list anim_props; // < Sorted by `element,prop_name`
3127
3128 ufbx_anim *anim;
3129
3130 uint32_t _min_element_id;
3131 uint32_t _max_element_id;
3132 uint32_t _element_id_bitmask[4];
3133 };
3134
3135 struct ufbx_anim_value {
3136 union { ufbx_element element; struct {
3137 ufbx_string name;
3138 ufbx_props props;
3139 uint32_t element_id;
3140 uint32_t typed_id;
3141 }; };
3142
3143 ufbx_vec3 default_value;
3144 ufbx_nullable ufbx_anim_curve *curves[3];
3145 };
3146
3147 // Animation curve segment interpolation mode between two keyframes
3148 typedef enum ufbx_interpolation UFBX_ENUM_REPR {
3149 UFBX_INTERPOLATION_CONSTANT_PREV, // < Hold previous key value
3150 UFBX_INTERPOLATION_CONSTANT_NEXT, // < Hold next key value
3151 UFBX_INTERPOLATION_LINEAR, // < Linear interpolation between two keys
3152 UFBX_INTERPOLATION_CUBIC, // < Cubic interpolation, see `ufbx_tangent`
3153
3154 UFBX_ENUM_FORCE_WIDTH(UFBX_INTERPOLATION)
3155 } ufbx_interpolation;
3156
3157 UFBX_ENUM_TYPE(ufbx_interpolation, UFBX_INTERPOLATION, UFBX_INTERPOLATION_CUBIC);
3158
3159 typedef enum ufbx_extrapolation_mode UFBX_ENUM_REPR {
3160 UFBX_EXTRAPOLATION_CONSTANT, // < Use the value of the first/last keyframe
3161 UFBX_EXTRAPOLATION_REPEAT, // < Repeat the whole animation curve
3162 UFBX_EXTRAPOLATION_MIRROR, // < Repeat with mirroring
3163 UFBX_EXTRAPOLATION_SLOPE, // < Use the tangent of the last keyframe to linearly extrapolate
3164 UFBX_EXTRAPOLATION_REPEAT_RELATIVE, // < Repeat the animation curve but connect the first and last keyframe values
3165
3166 UFBX_ENUM_FORCE_WIDTH(UFBX_EXTRAPOLATION)
3167 } ufbx_extrapolation_mode;
3168
3169 UFBX_ENUM_TYPE(ufbx_extrapolation_mode, UFBX_EXTRAPOLATION_MODE, UFBX_EXTRAPOLATION_REPEAT_RELATIVE);
3170
3171 typedef struct ufbx_extrapolation {
3172 ufbx_extrapolation_mode mode;
3173
3174 // Count used for repeating modes.
3175 // Negative values mean infinite repetition.
3176 int32_t repeat_count;
3177 } ufbx_extrapolation;
3178
3179 // Tangent vector at a keyframe, may be split into left/right
3180 typedef struct ufbx_tangent {
3181 float dx; // < Derivative in the time axis
3182 float dy; // < Derivative in the (curve specific) value axis
3183 } ufbx_tangent;
3184
3185 // Single real `value` at a specified `time`, interpolation between two keyframes
3186 // is determined by the `interpolation` field of the _previous_ key.
3187 // If `interpolation == UFBX_INTERPOLATION_CUBIC` the span is evaluated as a
3188 // cubic bezier curve through the following points:
3189 //
3190 // (prev->time, prev->value)
3191 // (prev->time + prev->right.dx, prev->value + prev->right.dy)
3192 // (next->time - next->left.dx, next->value - next->left.dy)
3193 // (next->time, next->value)
3194 //
3195 // HINT: You can use `ufbx_evaluate_curve(ufbx_anim_curve *curve, double time)`
3196 // rather than trying to manually handle all the interpolation modes.
3197 typedef struct ufbx_keyframe {
3198 double time;
3199 ufbx_real value;
3200 ufbx_interpolation interpolation;
3201 ufbx_tangent left;
3202 ufbx_tangent right;
3203 } ufbx_keyframe;
3204
3205 UFBX_LIST_TYPE(ufbx_keyframe_list, ufbx_keyframe);
3206
3207 struct ufbx_anim_curve {
3208 union { ufbx_element element; struct {
3209 ufbx_string name;
3210 ufbx_props props;
3211 uint32_t element_id;
3212 uint32_t typed_id;
3213 }; };
3214
3215 // List of keyframes that define the curve.
3216 ufbx_keyframe_list keyframes;
3217
3218 // Extrapolation before the curve.
3219 ufbx_extrapolation pre_extrapolation;
3220 // Extrapolation after the curve.
3221 ufbx_extrapolation post_extrapolation;
3222
3223 // Value range for all the keyframes.
3224 ufbx_real min_value;
3225 ufbx_real max_value;
3226
3227 // Time range for all the keyframes.
3228 double min_time;
3229 double max_time;
3230 };
3231
3232 // -- Collections
3233
3234 // Collection of nodes to hide/freeze
3235 struct ufbx_display_layer {
3236 union { ufbx_element element; struct {
3237 ufbx_string name;
3238 ufbx_props props;
3239 uint32_t element_id;
3240 uint32_t typed_id;
3241 }; };
3242
3243 // Nodes included in the layer (exclusively at most one layer per node)
3244 ufbx_node_list nodes;
3245
3246 // Layer state
3247 bool visible; // < Contained nodes are visible
3248 bool frozen; // < Contained nodes cannot be edited
3249
3250 ufbx_vec3 ui_color; // < Visual color for UI
3251 };
3252
3253 // Named set of nodes/geometry features to select.
3254 struct ufbx_selection_set {
3255 union { ufbx_element element; struct {
3256 ufbx_string name;
3257 ufbx_props props;
3258 uint32_t element_id;
3259 uint32_t typed_id;
3260 }; };
3261
3262 // Included nodes and geometry features
3263 ufbx_selection_node_list nodes;
3264 };
3265
3266 // Selection state of a node, potentially contains vertex/edge/face selection as well.
3267 struct ufbx_selection_node {
3268 union { ufbx_element element; struct {
3269 ufbx_string name;
3270 ufbx_props props;
3271 uint32_t element_id;
3272 uint32_t typed_id;
3273 }; };
3274
3275 // Selection targets, possibly `NULL`
3276 ufbx_nullable ufbx_node *target_node;
3277 ufbx_nullable ufbx_mesh *target_mesh;
3278 bool include_node; // < Is `target_node` included in the selection
3279
3280 // Indices to selected components.
3281 // Guaranteed to be valid as per `ufbx_load_opts.index_error_handling`
3282 // if `target_mesh` is not `NULL`.
3283 ufbx_uint32_list vertices; // < Indices to `ufbx_mesh.vertices`
3284 ufbx_uint32_list edges; // < Indices to `ufbx_mesh.edges`
3285 ufbx_uint32_list faces; // < Indices to `ufbx_mesh.faces`
3286 };
3287
3288 // -- Constraints
3289
3290 struct ufbx_character {
3291 union { ufbx_element element; struct {
3292 ufbx_string name;
3293 ufbx_props props;
3294 uint32_t element_id;
3295 uint32_t typed_id;
3296 }; };
3297 };
3298
3299 // Type of property constrain eg. position or look-at
3300 typedef enum ufbx_constraint_type UFBX_ENUM_REPR {
3301 UFBX_CONSTRAINT_UNKNOWN,
3302 UFBX_CONSTRAINT_AIM,
3303 UFBX_CONSTRAINT_PARENT,
3304 UFBX_CONSTRAINT_POSITION,
3305 UFBX_CONSTRAINT_ROTATION,
3306 UFBX_CONSTRAINT_SCALE,
3307 // Inverse kinematic chain to a single effector `ufbx_constraint.ik_effector`
3308 // `targets` optionally contains a list of pole targets!
3309 UFBX_CONSTRAINT_SINGLE_CHAIN_IK,
3310
3311 UFBX_ENUM_FORCE_WIDTH(UFBX_CONSTRAINT_TYPE)
3312 } ufbx_constraint_type;
3313
3314 UFBX_ENUM_TYPE(ufbx_constraint_type, UFBX_CONSTRAINT_TYPE, UFBX_CONSTRAINT_SINGLE_CHAIN_IK);
3315
3316 // Target to follow with a constraint
3317 typedef struct ufbx_constraint_target {
3318 ufbx_node *node; // < Target node reference
3319 ufbx_real weight; // < Relative weight to other targets (does not always sum to 1)
3320 ufbx_transform transform; // < Offset from the actual target
3321 } ufbx_constraint_target;
3322
3323 UFBX_LIST_TYPE(ufbx_constraint_target_list, ufbx_constraint_target);
3324
3325 // Method to determine the up vector in aim constraints
3326 typedef enum ufbx_constraint_aim_up_type UFBX_ENUM_REPR {
3327 UFBX_CONSTRAINT_AIM_UP_SCENE, // < Align the up vector to the scene global up vector
3328 UFBX_CONSTRAINT_AIM_UP_TO_NODE, // < Aim the up vector at `ufbx_constraint.aim_up_node`
3329 UFBX_CONSTRAINT_AIM_UP_ALIGN_NODE, // < Copy the up vector from `ufbx_constraint.aim_up_node`
3330 UFBX_CONSTRAINT_AIM_UP_VECTOR, // < Use `ufbx_constraint.aim_up_vector` as the up vector
3331 UFBX_CONSTRAINT_AIM_UP_NONE, // < Don't align the up vector to anything
3332
3333 UFBX_ENUM_FORCE_WIDTH(UFBX_CONSTRAINT_AIM_UP_TYPE)
3334 } ufbx_constraint_aim_up_type;
3335
3336 UFBX_ENUM_TYPE(ufbx_constraint_aim_up_type, UFBX_CONSTRAINT_AIM_UP_TYPE, UFBX_CONSTRAINT_AIM_UP_NONE);
3337
3338 // Method to determine the up vector in aim constraints
3339 typedef enum ufbx_constraint_ik_pole_type UFBX_ENUM_REPR {
3340 UFBX_CONSTRAINT_IK_POLE_VECTOR, // < Use towards calculated from `ufbx_constraint.targets`
3341 UFBX_CONSTRAINT_IK_POLE_NODE, // < Use `ufbx_constraint.ik_pole_vector` directly
3342
3343 UFBX_ENUM_FORCE_WIDTH(UFBX_CONSTRAINT_IK_POLE_TYPE)
3344 } ufbx_constraint_ik_pole_type;
3345
3346 UFBX_ENUM_TYPE(ufbx_constraint_ik_pole_type, UFBX_CONSTRAINT_IK_POLE_TYPE, UFBX_CONSTRAINT_IK_POLE_NODE);
3347
3348 struct ufbx_constraint {
3349 union { ufbx_element element; struct {
3350 ufbx_string name;
3351 ufbx_props props;
3352 uint32_t element_id;
3353 uint32_t typed_id;
3354 }; };
3355
3356 // Type of constraint to use
3357 ufbx_constraint_type type;
3358 ufbx_string type_name;
3359
3360 // Node to be constrained
3361 ufbx_nullable ufbx_node *node;
3362
3363 // List of weighted targets for the constraint (pole vectors for IK)
3364 ufbx_constraint_target_list targets;
3365
3366 // State of the constraint
3367 ufbx_real weight;
3368 bool active;
3369
3370 // Translation/rotation/scale axes the constraint is applied to
3371 bool constrain_translation[3];
3372 bool constrain_rotation[3];
3373 bool constrain_scale[3];
3374
3375 // Offset from the constrained position
3376 ufbx_transform transform_offset;
3377
3378 // AIM: Target and up vectors
3379 ufbx_vec3 aim_vector;
3380 ufbx_constraint_aim_up_type aim_up_type;
3381 ufbx_nullable ufbx_node *aim_up_node;
3382 ufbx_vec3 aim_up_vector;
3383
3384 // SINGLE_CHAIN_IK: Target for the IK, `targets` contains pole vectors!
3385 ufbx_nullable ufbx_node *ik_effector;
3386 ufbx_nullable ufbx_node *ik_end_node;
3387 ufbx_vec3 ik_pole_vector;
3388 };
3389
3390 // -- Audio
3391
3392 struct ufbx_audio_layer {
3393 union { ufbx_element element; struct {
3394 ufbx_string name;
3395 ufbx_props props;
3396 uint32_t element_id;
3397 uint32_t typed_id;
3398 }; };
3399
3400 // Clips contained in this layer.
3401 ufbx_audio_clip_list clips;
3402 };
3403
3404 struct ufbx_audio_clip {
3405 union { ufbx_element element; struct {
3406 ufbx_string name;
3407 ufbx_props props;
3408 uint32_t element_id;
3409 uint32_t typed_id;
3410 }; };
3411
3412 // Filename relative to the currently loaded file.
3413 // HINT: If using functions other than `ufbx_load_file()`, you can provide
3414 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
3415 ufbx_string filename;
3416 // Absolute filename specified in the file.
3417 ufbx_string absolute_filename;
3418 // Relative filename specified in the file.
3419 // NOTE: May be absolute if the file is saved in a different drive.
3420 ufbx_string relative_filename;
3421
3422 // Filename relative to the loaded file, non-UTF-8 encoded.
3423 // HINT: If using functions other than `ufbx_load_file()`, you can provide
3424 // `ufbx_load_opts.filename/raw_filename` to let ufbx resolve this.
3425 ufbx_blob raw_filename;
3426 // Absolute filename specified in the file, non-UTF-8 encoded.
3427 ufbx_blob raw_absolute_filename;
3428 // Relative filename specified in the file, non-UTF-8 encoded.
3429 // NOTE: May be absolute if the file is saved in a different drive.
3430 ufbx_blob raw_relative_filename;
3431
3432 // Optional embedded content blob, eg. raw .png format data
3433 ufbx_blob content;
3434 };
3435
3436 // -- Miscellaneous
3437
3438 typedef struct ufbx_bone_pose {
3439
3440 // Node to apply the pose to.
3441 ufbx_node *bone_node;
3442
3443 // Matrix from node local space to world space.
3444 ufbx_matrix bone_to_world;
3445
3446 // Matrix from node local space to parent space.
3447 // NOTE: FBX only stores world transformations so this is approximated from
3448 // the parent world transform.
3449 ufbx_matrix bone_to_parent;
3450
3451 } ufbx_bone_pose;
3452
3453 UFBX_LIST_TYPE(ufbx_bone_pose_list, ufbx_bone_pose);
3454
3455 struct ufbx_pose {
3456 union { ufbx_element element; struct {
3457 ufbx_string name;
3458 ufbx_props props;
3459 uint32_t element_id;
3460 uint32_t typed_id;
3461 }; };
3462
3463 // Set if this pose is marked as a bind pose.
3464 bool is_bind_pose;
3465
3466 // List of bone poses.
3467 // Sorted by `ufbx_node.typed_id`.
3468 ufbx_bone_pose_list bone_poses;
3469 };
3470
3471 struct ufbx_metadata_object {
3472 union { ufbx_element element; struct {
3473 ufbx_string name;
3474 ufbx_props props;
3475 uint32_t element_id;
3476 uint32_t typed_id;
3477 }; };
3478 };
3479
3480 // -- Named elements
3481
3482 typedef struct ufbx_name_element {
3483 ufbx_string name;
3484 ufbx_element_type type;
3485
3486 uint32_t _internal_key;
3487
3488 ufbx_element *element;
3489 } ufbx_name_element;
3490
3491 UFBX_LIST_TYPE(ufbx_name_element_list, ufbx_name_element);
3492
3493 // -- Scene
3494
3495 // Scene is the root object loaded by ufbx that everything is accessed from.
3496
3497 typedef enum ufbx_exporter UFBX_ENUM_REPR {
3498 UFBX_EXPORTER_UNKNOWN,
3499 UFBX_EXPORTER_FBX_SDK,
3500 UFBX_EXPORTER_BLENDER_BINARY,
3501 UFBX_EXPORTER_BLENDER_ASCII,
3502 UFBX_EXPORTER_MOTION_BUILDER,
3503
3504 UFBX_ENUM_FORCE_WIDTH(UFBX_EXPORTER)
3505 } ufbx_exporter;
3506
3507 UFBX_ENUM_TYPE(ufbx_exporter, UFBX_EXPORTER, UFBX_EXPORTER_MOTION_BUILDER);
3508
3509 typedef struct ufbx_application {
3510 ufbx_string vendor;
3511 ufbx_string name;
3512 ufbx_string version;
3513 } ufbx_application;
3514
3515 typedef enum ufbx_file_format UFBX_ENUM_REPR {
3516 UFBX_FILE_FORMAT_UNKNOWN, // < Unknown file format
3517 UFBX_FILE_FORMAT_FBX, // < .fbx Kaydara/Autodesk FBX file
3518 UFBX_FILE_FORMAT_OBJ, // < .obj Wavefront OBJ file
3519 UFBX_FILE_FORMAT_MTL, // < .mtl Wavefront MTL (Material template library) file
3520
3521 UFBX_ENUM_FORCE_WIDTH(UFBX_FILE_FORMAT)
3522 } ufbx_file_format;
3523
3524 UFBX_ENUM_TYPE(ufbx_file_format, UFBX_FILE_FORMAT, UFBX_FILE_FORMAT_MTL);
3525
3526 typedef enum ufbx_warning_type UFBX_ENUM_REPR {
3527 // Missing external file file (for example .mtl for Wavefront .obj file or a
3528 // geometry cache)
3529 UFBX_WARNING_MISSING_EXTERNAL_FILE,
3530
3531 // Loaded a Wavefront .mtl file derived from the filename instead of a proper
3532 // `mtllib` statement.
3533 UFBX_WARNING_IMPLICIT_MTL,
3534
3535 // Truncated array has been auto-expanded.
3536 UFBX_WARNING_TRUNCATED_ARRAY,
3537
3538 // Geometry data has been defined but has no data.
3539 UFBX_WARNING_MISSING_GEOMETRY_DATA,
3540
3541 // Duplicated connection between two elements that shouldn't have.
3542 UFBX_WARNING_DUPLICATE_CONNECTION,
3543
3544 // Vertex 'W' attribute length differs from main attribute.
3545 UFBX_WARNING_BAD_VERTEX_W_ATTRIBUTE,
3546
3547 // Missing polygon mapping type.
3548 UFBX_WARNING_MISSING_POLYGON_MAPPING,
3549
3550 // Unsupported version, loaded but may be incorrect.
3551 // If the loading fails `UFBX_ERROR_UNSUPPORTED_VERSION` is issued instead.
3552 UFBX_WARNING_UNSUPPORTED_VERSION,
3553
3554 // Out-of-bounds index has been clamped to be in-bounds.
3555 // HINT: You can use `ufbx_index_error_handling` to adjust behavior.
3556 UFBX_WARNING_INDEX_CLAMPED,
3557
3558 // Non-UTF8 encoded strings.
3559 // HINT: You can use `ufbx_unicode_error_handling` to adjust behavior.
3560 UFBX_WARNING_BAD_UNICODE,
3561
3562 // Invalid base64-encoded embedded content ignored.
3563 UFBX_WARNING_BAD_BASE64_CONTENT,
3564
3565 // Non-node element connected to root.
3566 UFBX_WARNING_BAD_ELEMENT_CONNECTED_TO_ROOT,
3567
3568 // Duplicated object ID in the file, connections will be wrong.
3569 UFBX_WARNING_DUPLICATE_OBJECT_ID,
3570
3571 // Empty face has been removed.
3572 // Use `ufbx_load_opts.allow_empty_faces` if you want to allow them.
3573 UFBX_WARNING_EMPTY_FACE_REMOVED,
3574
3575 // Unknown .obj file directive.
3576 UFBX_WARNING_UNKNOWN_OBJ_DIRECTIVE,
3577
3578 // Warnings after this one are deduplicated.
3579 // See `ufbx_warning.count` for how many times they happened.
3580 UFBX_WARNING_TYPE_FIRST_DEDUPLICATED = UFBX_WARNING_INDEX_CLAMPED,
3581
3582 UFBX_ENUM_FORCE_WIDTH(UFBX_WARNING_TYPE)
3583 } ufbx_warning_type;
3584
3585 UFBX_ENUM_TYPE(ufbx_warning_type, UFBX_WARNING_TYPE, UFBX_WARNING_UNKNOWN_OBJ_DIRECTIVE);
3586
3587 // Warning about a non-fatal issue in the file.
3588 // Often contains information about issues that ufbx has corrected about the
3589 // file but it might indicate something is not working properly.
3590 typedef struct ufbx_warning {
3591 // Type of the warning.
3592 ufbx_warning_type type;
3593 // Description of the warning.
3594 ufbx_string description;
3595 // The element related to this warning or `UFBX_NO_INDEX` if not related to a specific element.
3596 uint32_t element_id;
3597 // Number of times this warning was encountered.
3598 size_t count;
3599 } ufbx_warning;
3600
3601 UFBX_LIST_TYPE(ufbx_warning_list, ufbx_warning);
3602
3603 typedef enum ufbx_thumbnail_format UFBX_ENUM_REPR {
3604 UFBX_THUMBNAIL_FORMAT_UNKNOWN, // < Unknown format
3605 UFBX_THUMBNAIL_FORMAT_RGB_24, // < 8-bit RGB pixels, in memory R,G,B
3606 UFBX_THUMBNAIL_FORMAT_RGBA_32, // < 8-bit RGBA pixels, in memory R,G,B,A
3607
3608 UFBX_ENUM_FORCE_WIDTH(UFBX_THUMBNAIL_FORMAT)
3609 } ufbx_thumbnail_format;
3610
3611 UFBX_ENUM_TYPE(ufbx_thumbnail_format, UFBX_THUMBNAIL_FORMAT, UFBX_THUMBNAIL_FORMAT_RGBA_32);
3612
3613 // Specify how unit / coordinate system conversion should be performed.
3614 // Affects how `ufbx_load_opts.target_axes` and `ufbx_load_opts.target_unit_meters` work,
3615 // has no effect if neither is specified.
3616 typedef enum ufbx_space_conversion UFBX_ENUM_REPR {
3617
3618 // Store the space conversion transform in the root node.
3619 // Sets `ufbx_node.local_transform` of the root node.
3620 UFBX_SPACE_CONVERSION_TRANSFORM_ROOT,
3621
3622 // Perform the conversion by using "adjust" transforms.
3623 // Compensates for the transforms using `ufbx_node.adjust_pre_rotation` and
3624 // `ufbx_node.adjust_pre_scale`. You don't need to account for these unless
3625 // you are manually building transforms from `ufbx_props`.
3626 UFBX_SPACE_CONVERSION_ADJUST_TRANSFORMS,
3627
3628 // Perform the conversion by scaling geometry in addition to adjusting transforms.
3629 // Compensates transforms like `UFBX_SPACE_CONVERSION_ADJUST_TRANSFORMS` but
3630 // applies scaling to geometry as well.
3631 UFBX_SPACE_CONVERSION_MODIFY_GEOMETRY,
3632
3633 UFBX_ENUM_FORCE_WIDTH(UFBX_SPACE_CONVERSION)
3634 } ufbx_space_conversion;
3635
3636 UFBX_ENUM_TYPE(ufbx_space_conversion, UFBX_SPACE_CONVERSION, UFBX_SPACE_CONVERSION_MODIFY_GEOMETRY);
3637
3638 // How to handle FBX node geometry transforms.
3639 // FBX nodes can have "geometry transforms" that affect only the attached meshes,
3640 // but not the children. This is not allowed in many scene representations so
3641 // ufbx provides some ways to simplify them.
3642 // Geometry transforms can also be used to transform any other attributes such
3643 // as lights or cameras.
3644 typedef enum ufbx_geometry_transform_handling UFBX_ENUM_REPR {
3645
3646 // Preserve the geometry transforms as-is.
3647 // To be correct for all files you have to use `ufbx_node.geometry_transform`,
3648 // `ufbx_node.geometry_to_node`, or `ufbx_node.geometry_to_world` to compensate
3649 // for any potential geometry transforms.
3650 UFBX_GEOMETRY_TRANSFORM_HANDLING_PRESERVE,
3651
3652 // Add helper nodes between the nodes and geometry where needed.
3653 // The created nodes have `ufbx_node.is_geometry_transform_helper` set and are
3654 // named `ufbx_load_opts.geometry_transform_helper_name`.
3655 UFBX_GEOMETRY_TRANSFORM_HANDLING_HELPER_NODES,
3656
3657 // Modify the geometry of meshes attached to nodes with geometry transforms.
3658 // Will add helper nodes like `UFBX_GEOMETRY_TRANSFORM_HANDLING_HELPER_NODES` if
3659 // necessary, for example if there are multiple instances of the same mesh with
3660 // geometry transforms.
3661 UFBX_GEOMETRY_TRANSFORM_HANDLING_MODIFY_GEOMETRY,
3662
3663 // Modify the geometry of meshes attached to nodes with geometry transforms.
3664 // NOTE: This will not work correctly for instanced geometry.
3665 UFBX_GEOMETRY_TRANSFORM_HANDLING_MODIFY_GEOMETRY_NO_FALLBACK,
3666
3667 UFBX_ENUM_FORCE_WIDTH(UFBX_GEOMETRY_TRANSFORM_HANDLING)
3668 } ufbx_geometry_transform_handling;
3669
3670 UFBX_ENUM_TYPE(ufbx_geometry_transform_handling, UFBX_GEOMETRY_TRANSFORM_HANDLING, UFBX_GEOMETRY_TRANSFORM_HANDLING_MODIFY_GEOMETRY_NO_FALLBACK);
3671
3672 // How to handle FBX transform inherit modes.
3673 typedef enum ufbx_inherit_mode_handling UFBX_ENUM_REPR {
3674
3675 // Preserve inherit mode in `ufbx_node.inherit_mode`.
3676 // NOTE: To correctly handle all scenes you would need to handle the
3677 // non-standard inherit modes.
3678 UFBX_INHERIT_MODE_HANDLING_PRESERVE,
3679
3680 // Create scale helper nodes parented to nodes that need special inheritance.
3681 // Scale helper nodes will have `ufbx_node.is_scale_helper` and parents of
3682 // scale helpers will have `ufbx_node.scale_helper` pointing to it.
3683 UFBX_INHERIT_MODE_HANDLING_HELPER_NODES,
3684
3685 // Attempt to compensate for bone scale by inversely scaling children.
3686 // NOTE: This only works for uniform non-animated scaling, if scale is
3687 // non-uniform or animated, ufbx will add scale helpers in the same way
3688 // as `UFBX_INHERIT_MODE_HANDLING_HELPER_NODES`.
3689 UFBX_INHERIT_MODE_HANDLING_COMPENSATE,
3690
3691 // Attempt to compensate for bone scale by inversely scaling children.
3692 // Will never create helper nodes.
3693 UFBX_INHERIT_MODE_HANDLING_COMPENSATE_NO_FALLBACK,
3694
3695 // Ignore non-standard inheritance modes.
3696 // Forces all nodes to have `UFBX_INHERIT_MODE_NORMAL` regardless of the
3697 // inherit mode specified in the file. This can be useful for emulating
3698 // results from importers/programs that don't support inherit modes.
3699 UFBX_INHERIT_MODE_HANDLING_IGNORE,
3700
3701 UFBX_ENUM_FORCE_WIDTH(UFBX_INHERIT_MODE_HANDLING)
3702 } ufbx_inherit_mode_handling;
3703
3704 UFBX_ENUM_TYPE(ufbx_inherit_mode_handling, UFBX_INHERIT_MODE_HANDLING, UFBX_INHERIT_MODE_HANDLING_IGNORE);
3705
3706 // How to handle FBX transform pivots.
3707 typedef enum ufbx_pivot_handling UFBX_ENUM_REPR {
3708
3709 // Take pivots into account when computing the transform.
3710 UFBX_PIVOT_HANDLING_RETAIN,
3711
3712 // Translate objects to be located at their pivot.
3713 // NOTE: Only applied if rotation and scaling pivots are equal.
3714 // NOTE: Results in geometric translation. Use `ufbx_geometry_transform_handling`
3715 // to interpret these in a standard scene graph.
3716 UFBX_PIVOT_HANDLING_ADJUST_TO_PIVOT,
3717
3718 // Translate objects to be located at their rotation pivot.
3719 // NOTE: Results in geometric translation. Use `ufbx_geometry_transform_handling`
3720 // to interpret these in a standard scene graph.
3721 // NOTE: By default the original transforms of empties are not retained when using this,
3722 // use `ufbx_load_opts.pivot_handling_retain_empties` to prevent adjusting these pivots.
3723 UFBX_PIVOT_HANDLING_ADJUST_TO_ROTATION_PIVOT,
3724
3725 UFBX_ENUM_FORCE_WIDTH(UFBX_PIVOT_HANDLING)
3726 } ufbx_pivot_handling;
3727
3728 UFBX_ENUM_TYPE(ufbx_pivot_handling, UFBX_PIVOT_HANDLING, UFBX_PIVOT_HANDLING_ADJUST_TO_ROTATION_PIVOT);
3729
3730 // Embedded thumbnail in the file, valid if the dimensions are non-zero.
3731 typedef struct ufbx_thumbnail {
3732 ufbx_props props;
3733
3734 // Extents of the thumbnail
3735 uint32_t width;
3736 uint32_t height;
3737
3738 // Format of `ufbx_thumbnail.data`.
3739 ufbx_thumbnail_format format;
3740
3741 // Thumbnail pixel data, layout as contiguous rows from bottom to top.
3742 // See `ufbx_thumbnail.format` for the pixel format.
3743 ufbx_blob data;
3744 } ufbx_thumbnail;
3745
3746 // Miscellaneous data related to the loaded file
3747 typedef struct ufbx_metadata {
3748
3749 // List of non-fatal warnings about the file.
3750 // If you need to only check whether a specific warning was triggered you
3751 // can use `ufbx_metadata.has_warning[]`.
3752 ufbx_warning_list warnings;
3753
3754 // FBX ASCII file format.
3755 bool ascii;
3756
3757 // FBX version in integer format, eg. 7400 for 7.4.
3758 uint32_t version;
3759
3760 // File format of the source file.
3761 ufbx_file_format file_format;
3762
3763 // Index arrays may contain `UFBX_NO_INDEX` instead of a valid index
3764 // to indicate gaps.
3765 bool may_contain_no_index;
3766
3767 // May contain meshes with no defined vertex position.
3768 // NOTE: `ufbx_mesh.vertex_position.exists` may be `false`!
3769 bool may_contain_missing_vertex_position;
3770
3771 // Arrays may contain items with `NULL` element references.
3772 // See `ufbx_load_opts.connect_broken_elements`.
3773 bool may_contain_broken_elements;
3774
3775 // Some API guarantees do not apply (depending on unsafe options used).
3776 // Loaded with `ufbx_load_opts.allow_unsafe` enabled.
3777 bool is_unsafe;
3778
3779 // Flag for each possible warning type.
3780 // See `ufbx_metadata.warnings[]` for detailed warning information.
3781 bool has_warning[UFBX_WARNING_TYPE_COUNT];
3782
3783 ufbx_string creator;
3784 bool big_endian;
3785
3786 ufbx_string filename;
3787 ufbx_string relative_root;
3788
3789 ufbx_blob raw_filename;
3790 ufbx_blob raw_relative_root;
3791
3792 ufbx_exporter exporter;
3793 uint32_t exporter_version;
3794
3795 ufbx_props scene_props;
3796
3797 ufbx_application original_application;
3798 ufbx_application latest_application;
3799
3800 ufbx_thumbnail thumbnail;
3801
3802 bool geometry_ignored;
3803 bool animation_ignored;
3804 bool embedded_ignored;
3805
3806 size_t max_face_triangles;
3807
3808 size_t result_memory_used;
3809 size_t temp_memory_used;
3810 size_t result_allocs;
3811 size_t temp_allocs;
3812
3813 size_t element_buffer_size;
3814 size_t num_shader_textures;
3815
3816 ufbx_real bone_prop_size_unit;
3817 bool bone_prop_limb_length_relative;
3818
3819 ufbx_real ortho_size_unit;
3820
3821 int64_t ktime_second; // < One second in internal KTime units
3822
3823 ufbx_string original_file_path;
3824 ufbx_blob raw_original_file_path;
3825
3826 // Conversion methods applied for the scene.
3827 ufbx_space_conversion space_conversion;
3828 ufbx_geometry_transform_handling geometry_transform_handling;
3829 ufbx_inherit_mode_handling inherit_mode_handling;
3830 ufbx_pivot_handling pivot_handling;
3831 ufbx_mirror_axis handedness_conversion_axis;
3832
3833 // Transform that has been applied to root for axis/unit conversion.
3834 ufbx_quat root_rotation;
3835 ufbx_real root_scale;
3836
3837 // Axis that the scene has been mirrored by.
3838 // All geometry has been mirrored in this axis.
3839 ufbx_mirror_axis mirror_axis;
3840
3841 // Amount geometry has been scaled.
3842 // See `UFBX_SPACE_CONVERSION_MODIFY_GEOMETRY`.
3843 ufbx_real geometry_scale;
3844
3845 } ufbx_metadata;
3846
3847 typedef enum ufbx_time_mode UFBX_ENUM_REPR {
3848 UFBX_TIME_MODE_DEFAULT,
3849 UFBX_TIME_MODE_120_FPS,
3850 UFBX_TIME_MODE_100_FPS,
3851 UFBX_TIME_MODE_60_FPS,
3852 UFBX_TIME_MODE_50_FPS,
3853 UFBX_TIME_MODE_48_FPS,
3854 UFBX_TIME_MODE_30_FPS,
3855 UFBX_TIME_MODE_30_FPS_DROP,
3856 UFBX_TIME_MODE_NTSC_DROP_FRAME,
3857 UFBX_TIME_MODE_NTSC_FULL_FRAME,
3858 UFBX_TIME_MODE_PAL,
3859 UFBX_TIME_MODE_24_FPS,
3860 UFBX_TIME_MODE_1000_FPS,
3861 UFBX_TIME_MODE_FILM_FULL_FRAME,
3862 UFBX_TIME_MODE_CUSTOM,
3863 UFBX_TIME_MODE_96_FPS,
3864 UFBX_TIME_MODE_72_FPS,
3865 UFBX_TIME_MODE_59_94_FPS,
3866
3867 UFBX_ENUM_FORCE_WIDTH(UFBX_TIME_MODE)
3868 } ufbx_time_mode;
3869
3870 UFBX_ENUM_TYPE(ufbx_time_mode, UFBX_TIME_MODE, UFBX_TIME_MODE_59_94_FPS);
3871
3872 typedef enum ufbx_time_protocol UFBX_ENUM_REPR {
3873 UFBX_TIME_PROTOCOL_SMPTE,
3874 UFBX_TIME_PROTOCOL_FRAME_COUNT,
3875 UFBX_TIME_PROTOCOL_DEFAULT,
3876
3877 UFBX_ENUM_FORCE_WIDTH(UFBX_TIME_PROTOCOL)
3878 } ufbx_time_protocol;
3879
3880 UFBX_ENUM_TYPE(ufbx_time_protocol, UFBX_TIME_PROTOCOL, UFBX_TIME_PROTOCOL_DEFAULT);
3881
3882 typedef enum ufbx_snap_mode UFBX_ENUM_REPR {
3883 UFBX_SNAP_MODE_NONE,
3884 UFBX_SNAP_MODE_SNAP,
3885 UFBX_SNAP_MODE_PLAY,
3886 UFBX_SNAP_MODE_SNAP_AND_PLAY,
3887
3888 UFBX_ENUM_FORCE_WIDTH(UFBX_SNAP_MODE)
3889 } ufbx_snap_mode;
3890
3891 UFBX_ENUM_TYPE(ufbx_snap_mode, UFBX_SNAP_MODE, UFBX_SNAP_MODE_SNAP_AND_PLAY);
3892
3893 // Global settings: Axes and time/unit scales
3894 typedef struct ufbx_scene_settings {
3895 ufbx_props props;
3896
3897 // Mapping of X/Y/Z axes to world-space directions.
3898 // HINT: Use `ufbx_load_opts.target_axes` to normalize this.
3899 // NOTE: This contains the _original_ axes even if you supply `ufbx_load_opts.target_axes`.
3900 ufbx_coordinate_axes axes;
3901
3902 // How many meters does a single world-space unit represent.
3903 // FBX files usually default to centimeters, reported as `0.01` here.
3904 // HINT: Use `ufbx_load_opts.target_unit_meters` to normalize this.
3905 ufbx_real unit_meters;
3906
3907 // Frames per second the animation is defined at.
3908 double frames_per_second;
3909
3910 ufbx_vec3 ambient_color;
3911 ufbx_string default_camera;
3912
3913 // Animation user interface settings.
3914 // HINT: Use `ufbx_scene_settings.frames_per_second` instead of interpreting these yourself.
3915 ufbx_time_mode time_mode;
3916 ufbx_time_protocol time_protocol;
3917 ufbx_snap_mode snap_mode;
3918
3919 // Original settings (?)
3920 ufbx_coordinate_axis original_axis_up;
3921 ufbx_real original_unit_meters;
3922 } ufbx_scene_settings;
3923
3924 struct ufbx_scene {
3925 ufbx_metadata metadata;
3926
3927 // Global settings
3928 ufbx_scene_settings settings;
3929
3930 // Node instances in the scene
3931 ufbx_node *root_node;
3932
3933 // Default animation descriptor
3934 ufbx_anim *anim;
3935
3936 union {
3937 struct {
3938 ufbx_unknown_list unknowns;
3939
3940 // Nodes
3941 ufbx_node_list nodes;
3942
3943 // Node attributes (common)
3944 ufbx_mesh_list meshes;
3945 ufbx_light_list lights;
3946 ufbx_camera_list cameras;
3947 ufbx_bone_list bones;
3948 ufbx_empty_list empties;
3949
3950 // Node attributes (curves/surfaces)
3951 ufbx_line_curve_list line_curves;
3952 ufbx_nurbs_curve_list nurbs_curves;
3953 ufbx_nurbs_surface_list nurbs_surfaces;
3954 ufbx_nurbs_trim_surface_list nurbs_trim_surfaces;
3955 ufbx_nurbs_trim_boundary_list nurbs_trim_boundaries;
3956
3957 // Node attributes (advanced)
3958 ufbx_procedural_geometry_list procedural_geometries;
3959 ufbx_stereo_camera_list stereo_cameras;
3960 ufbx_camera_switcher_list camera_switchers;
3961 ufbx_marker_list markers;
3962 ufbx_lod_group_list lod_groups;
3963
3964 // Deformers
3965 ufbx_skin_deformer_list skin_deformers;
3966 ufbx_skin_cluster_list skin_clusters;
3967 ufbx_blend_deformer_list blend_deformers;
3968 ufbx_blend_channel_list blend_channels;
3969 ufbx_blend_shape_list blend_shapes;
3970 ufbx_cache_deformer_list cache_deformers;
3971 ufbx_cache_file_list cache_files;
3972
3973 // Materials
3974 ufbx_material_list materials;
3975 ufbx_texture_list textures;
3976 ufbx_video_list videos;
3977 ufbx_shader_list shaders;
3978 ufbx_shader_binding_list shader_bindings;
3979
3980 // Animation
3981 ufbx_anim_stack_list anim_stacks;
3982 ufbx_anim_layer_list anim_layers;
3983 ufbx_anim_value_list anim_values;
3984 ufbx_anim_curve_list anim_curves;
3985
3986 // Collections
3987 ufbx_display_layer_list display_layers;
3988 ufbx_selection_set_list selection_sets;
3989 ufbx_selection_node_list selection_nodes;
3990
3991 // Constraints
3992 ufbx_character_list characters;
3993 ufbx_constraint_list constraints;
3994
3995 // Audio
3996 ufbx_audio_layer_list audio_layers;
3997 ufbx_audio_clip_list audio_clips;
3998
3999 // Miscellaneous
4000 ufbx_pose_list poses;
4001 ufbx_metadata_object_list metadata_objects;
4002 };
4003
4004 ufbx_element_list elements_by_type[UFBX_ELEMENT_TYPE_COUNT];
4005 };
4006
4007 // Unique texture files referenced by the scene.
4008 ufbx_texture_file_list texture_files;
4009
4010 // All elements and connections in the whole file
4011 ufbx_element_list elements; // < Sorted by `id`
4012 ufbx_connection_list connections_src; // < Sorted by `src,src_prop`
4013 ufbx_connection_list connections_dst; // < Sorted by `dst,dst_prop`
4014
4015 // Elements sorted by name, type
4016 ufbx_name_element_list elements_by_name;
4017
4018 // Enabled if `ufbx_load_opts.retain_dom == true`.
4019 ufbx_nullable ufbx_dom_node *dom_root;
4020 };
4021
4022 // -- Curves
4023
4024 typedef struct ufbx_curve_point {
4025 bool valid;
4026 ufbx_vec3 position;
4027 ufbx_vec3 derivative;
4028 } ufbx_curve_point;
4029
4030 typedef struct ufbx_surface_point {
4031 bool valid;
4032 ufbx_vec3 position;
4033 ufbx_vec3 derivative_u;
4034 ufbx_vec3 derivative_v;
4035 } ufbx_surface_point;
4036
4037 // -- Mesh topology
4038
4039 typedef enum ufbx_topo_flags UFBX_FLAG_REPR {
4040 UFBX_TOPO_NON_MANIFOLD = 0x1, // < Edge with three or more faces
4041
4042 UFBX_FLAG_FORCE_WIDTH(UFBX_TOPO_FLAGS)
4043 } ufbx_topo_flags;
4044
4045 typedef struct ufbx_topo_edge {
4046 uint32_t index; // < Starting index of the edge, always defined
4047 uint32_t next; // < Ending index of the edge / next per-face `ufbx_topo_edge`, always defined
4048 uint32_t prev; // < Previous per-face `ufbx_topo_edge`, always defined
4049 uint32_t twin; // < `ufbx_topo_edge` on the opposite side, `UFBX_NO_INDEX` if not found
4050 uint32_t face; // < Index into `mesh->faces[]`, always defined
4051 uint32_t edge; // < Index into `mesh->edges[]`, `UFBX_NO_INDEX` if not found
4052
4053 ufbx_topo_flags flags;
4054 } ufbx_topo_edge;
4055
4056 // Vertex data array for `ufbx_generate_indices()`.
4057 // NOTE: `ufbx_generate_indices()` compares the vertices using `memcmp()`, so
4058 // any padding should be cleared to zero.
4059 typedef struct ufbx_vertex_stream {
4060 void *data; // < Data pointer of shape `char[vertex_count][vertex_size]`.
4061 size_t vertex_count; // < Number of vertices in this stream, for sanity checking.
4062 size_t vertex_size; // < Size of a vertex in bytes.
4063 } ufbx_vertex_stream;
4064
4065 // -- Memory callbacks
4066
4067 // You can optionally provide an allocator to ufbx, the default is to use the
4068 // CRT malloc/realloc/free
4069
4070 // Allocate `size` bytes, must be at least 8 byte aligned
4071 typedef void *ufbx_alloc_fn(void *user, size_t size);
4072
4073 // Reallocate `old_ptr` from `old_size` to `new_size`
4074 // NOTE: If omit `alloc_fn` and `free_fn` they will be translated to:
4075 // `alloc(size)` -> `realloc_fn(user, NULL, 0, size)`
4076 // `free_fn(ptr, size)` -> `realloc_fn(user, ptr, size, 0)`
4077 typedef void *ufbx_realloc_fn(void *user, void *old_ptr, size_t old_size, size_t new_size);
4078
4079 // Free pointer `ptr` (of `size` bytes) returned by `alloc_fn` or `realloc_fn`
4080 typedef void ufbx_free_fn(void *user, void *ptr, size_t size);
4081
4082 // Free the allocator itself
4083 typedef void ufbx_free_allocator_fn(void *user);
4084
4085 // Allocator callbacks and user context
4086 // NOTE: The allocator will be stored to the loaded scene and will be called
4087 // again from `ufbx_free_scene()` so make sure `user` outlives that!
4088 // You can use `free_allocator_fn()` to free the allocator yourself.
4089 typedef struct ufbx_allocator {
4090 // Callback functions, see `typedef`s above for information
4091 ufbx_alloc_fn *alloc_fn;
4092 ufbx_realloc_fn *realloc_fn;
4093 ufbx_free_fn *free_fn;
4094 ufbx_free_allocator_fn *free_allocator_fn;
4095 void *user;
4096 } ufbx_allocator;
4097
4098 typedef struct ufbx_allocator_opts {
4099 // Allocator callbacks
4100 ufbx_allocator allocator;
4101
4102 // Maximum number of bytes to allocate before failing
4103 size_t memory_limit;
4104
4105 // Maximum number of allocations to attempt before failing
4106 size_t allocation_limit;
4107
4108 // Threshold to swap from batched allocations to individual ones
4109 // Defaults to 1MB if set to zero
4110 // NOTE: If set to `1` ufbx will allocate everything in the smallest
4111 // possible chunks which may be useful for debugging (eg. ASAN)
4112 size_t huge_threshold;
4113
4114 // Maximum size of a single allocation containing sub-allocations.
4115 // Defaults to 16MB if set to zero
4116 // The maximum amount of wasted memory depends on `max_chunk_size` and
4117 // `huge_threshold`: each chunk can waste up to `huge_threshold` bytes
4118 // internally and the last chunk might be incomplete. So for example
4119 // with the defaults we can waste around 1MB/16MB = 6.25% overall plus
4120 // up to 32MB due to the two incomplete blocks. The actual amounts differ
4121 // slightly as the chunks start out at 4kB and double in size each time,
4122 // meaning that the maximum fixed overhead (up to 32MB with defaults) is
4123 // at most ~30% of the total allocation size.
4124 size_t max_chunk_size;
4125
4126 } ufbx_allocator_opts;
4127
4128 // -- IO callbacks
4129
4130 // Try to read up to `size` bytes to `data`, return the amount of read bytes.
4131 // Return `SIZE_MAX` to indicate an IO error.
4132 typedef size_t ufbx_read_fn(void *user, void *data, size_t size);
4133
4134 // Skip `size` bytes in the file.
4135 typedef bool ufbx_skip_fn(void *user, size_t size);
4136
4137 // Get the size of the file.
4138 // Return `0` if unknown, `UINT64_MAX` if error.
4139 typedef uint64_t ufbx_size_fn(void *user);
4140
4141 // Close the file
4142 typedef void ufbx_close_fn(void *user);
4143
4144 typedef struct ufbx_stream {
4145 ufbx_read_fn *read_fn; // < Required
4146 ufbx_skip_fn *skip_fn; // < Optional: Will use `read_fn()` if missing
4147 ufbx_size_fn *size_fn; // < Optional
4148 ufbx_close_fn *close_fn; // < Optional
4149
4150 // Context passed to other functions
4151 void *user;
4152 } ufbx_stream;
4153
4154 typedef enum ufbx_open_file_type UFBX_ENUM_REPR {
4155 UFBX_OPEN_FILE_MAIN_MODEL, // < Main model file
4156 UFBX_OPEN_FILE_GEOMETRY_CACHE, // < Unknown geometry cache file
4157 UFBX_OPEN_FILE_OBJ_MTL, // < .mtl material library file
4158
4159 UFBX_ENUM_FORCE_WIDTH(UFBX_OPEN_FILE_TYPE)
4160 } ufbx_open_file_type;
4161
4162 UFBX_ENUM_TYPE(ufbx_open_file_type, UFBX_OPEN_FILE_TYPE, UFBX_OPEN_FILE_OBJ_MTL);
4163
4164 typedef uintptr_t ufbx_open_file_context;
4165
4166 typedef struct ufbx_open_file_info {
4167 // Context that can be passed to the following functions to use a shared allocator:
4168 // ufbx_open_file_ctx()
4169 // ufbx_open_memory_ctx()
4170 ufbx_open_file_context context;
4171
4172 // Kind of file to load.
4173 ufbx_open_file_type type;
4174
4175 // Original filename in the file, not resolved or UTF-8 encoded.
4176 // NOTE: Not necessarily NULL-terminated!
4177 ufbx_blob original_filename;
4178 } ufbx_open_file_info;
4179
4180 // Callback for opening an external file from the filesystem
4181 typedef bool ufbx_open_file_fn(void *user, ufbx_stream *stream, const char *path, size_t path_len, const ufbx_open_file_info *info);
4182
4183 typedef struct ufbx_open_file_cb {
4184 ufbx_open_file_fn *fn;
4185 void *user;
4186
4187 UFBX_CALLBACK_IMPL(ufbx_open_file_cb, ufbx_open_file_fn, bool,
4188 (void *user, ufbx_stream *stream, const char *path, size_t path_len, const ufbx_open_file_info *info),
4189 (stream, path, path_len, info))
4190 } ufbx_open_file_cb;
4191
4192 // Options for `ufbx_open_file()`.
4193 typedef struct ufbx_open_file_opts {
4194 uint32_t _begin_zero;
4195
4196 // Allocator to allocate the memory with.
4197 ufbx_allocator_opts allocator;
4198
4199 // The filename is guaranteed to be NULL-terminated.
4200 ufbx_unsafe bool filename_null_terminated;
4201
4202 uint32_t _end_zero;
4203 } ufbx_open_file_opts;
4204
4205 // Memory stream options
4206 typedef void ufbx_close_memory_fn(void *user, void *data, size_t data_size);
4207
4208 typedef struct ufbx_close_memory_cb {
4209 ufbx_close_memory_fn *fn;
4210 void *user;
4211
4212 UFBX_CALLBACK_IMPL(ufbx_close_memory_cb, ufbx_close_memory_fn, void,
4213 (void *user, void *data, size_t data_size),
4214 (data, data_size))
4215 } ufbx_close_memory_cb;
4216
4217 // Options for `ufbx_open_memory()`.
4218 typedef struct ufbx_open_memory_opts {
4219 uint32_t _begin_zero;
4220
4221 // Allocator to allocate the memory with.
4222 // NOTE: Used even if no copy is made to allocate a small metadata block.
4223 ufbx_allocator_opts allocator;
4224
4225 // Do not copy the memory.
4226 // You can use `close_cb` to free the memory when the stream is closed.
4227 // NOTE: This means the provided data pointer is referenced after creating
4228 // the memory stream, make sure the data stays valid until the stream is closed!
4229 ufbx_unsafe bool no_copy;
4230
4231 // Callback to free the memory blob.
4232 ufbx_close_memory_cb close_cb;
4233
4234 uint32_t _end_zero;
4235 } ufbx_open_memory_opts;
4236
4237 // Detailed error stack frame.
4238 // NOTE: You must compile `ufbx.c` with `UFBX_ENABLE_ERROR_STACK` to enable the error stack.
4239 typedef struct ufbx_error_frame {
4240 uint32_t source_line;
4241 ufbx_string function;
4242 ufbx_string description;
4243 } ufbx_error_frame;
4244
4245 // Error causes (and `UFBX_ERROR_NONE` for no error).
4246 typedef enum ufbx_error_type UFBX_ENUM_REPR {
4247
4248 // No error, operation has been performed successfully.
4249 UFBX_ERROR_NONE,
4250
4251 // Unspecified error, most likely caused by an invalid FBX file or a file
4252 // that contains something ufbx can't handle.
4253 UFBX_ERROR_UNKNOWN,
4254
4255 // File not found.
4256 UFBX_ERROR_FILE_NOT_FOUND,
4257
4258 // Empty file.
4259 UFBX_ERROR_EMPTY_FILE,
4260
4261 // External file not found.
4262 // See `ufbx_load_opts.load_external_files` for more information.
4263 UFBX_ERROR_EXTERNAL_FILE_NOT_FOUND,
4264
4265 // Out of memory (allocator returned `NULL`).
4266 UFBX_ERROR_OUT_OF_MEMORY,
4267
4268 // `ufbx_allocator_opts.memory_limit` exhausted.
4269 UFBX_ERROR_MEMORY_LIMIT,
4270
4271 // `ufbx_allocator_opts.allocation_limit` exhausted.
4272 UFBX_ERROR_ALLOCATION_LIMIT,
4273
4274 // File ended abruptly.
4275 UFBX_ERROR_TRUNCATED_FILE,
4276
4277 // IO read error.
4278 // eg. returning `SIZE_MAX` from `ufbx_stream.read_fn` or stdio `ferror()` condition.
4279 UFBX_ERROR_IO,
4280
4281 // User cancelled the loading via `ufbx_load_opts.progress_cb` returning `UFBX_PROGRESS_CANCEL`.
4282 UFBX_ERROR_CANCELLED,
4283
4284 // Could not detect file format from file data or filename.
4285 // HINT: You can supply it manually using `ufbx_load_opts.file_format` or use `ufbx_load_opts.filename`
4286 // when using `ufbx_load_memory()` to let ufbx guess the format from the extension.
4287 UFBX_ERROR_UNRECOGNIZED_FILE_FORMAT,
4288
4289 // Options struct (eg. `ufbx_load_opts`) is not cleared to zero.
4290 // Make sure you initialize the structure to zero via eg.
4291 // ufbx_load_opts opts = { 0 }; // C
4292 // ufbx_load_opts opts = { }; // C++
4293 UFBX_ERROR_UNINITIALIZED_OPTIONS,
4294
4295 // The vertex streams in `ufbx_generate_indices()` are empty.
4296 UFBX_ERROR_ZERO_VERTEX_SIZE,
4297
4298 // Vertex stream passed to `ufbx_generate_indices()`.
4299 UFBX_ERROR_TRUNCATED_VERTEX_STREAM,
4300
4301 // Invalid UTF-8 encountered in a file when loading with `UFBX_UNICODE_ERROR_HANDLING_ABORT_LOADING`.
4302 UFBX_ERROR_INVALID_UTF8,
4303
4304 // Feature needed for the operation has been compiled out.
4305 UFBX_ERROR_FEATURE_DISABLED,
4306
4307 // Attempting to tessellate an invalid NURBS object.
4308 // See `ufbx_nurbs_basis.valid`.
4309 UFBX_ERROR_BAD_NURBS,
4310
4311 // Out of bounds index in the file when loading with `UFBX_INDEX_ERROR_HANDLING_ABORT_LOADING`.
4312 UFBX_ERROR_BAD_INDEX,
4313
4314 // Node is deeper than `ufbx_load_opts.node_depth_limit` in the hierarchy.
4315 UFBX_ERROR_NODE_DEPTH_LIMIT,
4316
4317 // Error parsing ASCII array in a thread.
4318 // Threaded ASCII parsing is slightly more strict than non-threaded, for cursed files,
4319 // set `ufbx_load_opts.force_single_thread_ascii_parsing` to `true`.
4320 UFBX_ERROR_THREADED_ASCII_PARSE,
4321
4322 // Unsafe options specified without enabling `ufbx_load_opts.allow_unsafe`.
4323 UFBX_ERROR_UNSAFE_OPTIONS,
4324
4325 // Duplicated override property in `ufbx_create_anim()`
4326 UFBX_ERROR_DUPLICATE_OVERRIDE,
4327
4328 // Unsupported file format version.
4329 // ufbx still tries to load files with unsupported versions, see `UFBX_WARNING_UNSUPPORTED_VERSION`.
4330 UFBX_ERROR_UNSUPPORTED_VERSION,
4331
4332 UFBX_ENUM_FORCE_WIDTH(UFBX_ERROR_TYPE)
4333 } ufbx_error_type;
4334
4335 UFBX_ENUM_TYPE(ufbx_error_type, UFBX_ERROR_TYPE, UFBX_ERROR_UNSUPPORTED_VERSION);
4336
4337 // Error description with detailed stack trace
4338 // HINT: You can use `ufbx_format_error()` for formatting the error
4339 typedef struct ufbx_error {
4340
4341 // Type of the error, or `UFBX_ERROR_NONE` if successful.
4342 ufbx_error_type type;
4343
4344 // Description of the error type.
4345 ufbx_string description;
4346
4347 // Internal error stack.
4348 // NOTE: You must compile `ufbx.c` with `UFBX_ENABLE_ERROR_STACK` to enable the error stack.
4349 uint32_t stack_size;
4350 ufbx_error_frame stack[UFBX_ERROR_STACK_MAX_DEPTH];
4351
4352 // Additional error information, such as missing file filename.
4353 // `info` is a NULL-terminated UTF-8 string containing `info_length` bytes, excluding the trailing `'\0'`.
4354 size_t info_length;
4355 char info[UFBX_ERROR_INFO_LENGTH];
4356
4357 } ufbx_error;
4358
4359 // -- Progress callbacks
4360
4361 // Loading progress information.
4362 typedef struct ufbx_progress {
4363 uint64_t bytes_read;
4364 uint64_t bytes_total;
4365 } ufbx_progress;
4366
4367 // Progress result returned from `ufbx_progress_fn()` callback.
4368 // Determines whether ufbx should continue or abort the loading.
4369 typedef enum ufbx_progress_result UFBX_ENUM_REPR {
4370
4371 // Continue loading the file.
4372 UFBX_PROGRESS_CONTINUE = 0x100,
4373
4374 // Cancel loading and fail with `UFBX_ERROR_CANCELLED`.
4375 UFBX_PROGRESS_CANCEL = 0x200,
4376
4377 UFBX_ENUM_FORCE_WIDTH(UFBX_PROGRESS_RESULT)
4378 } ufbx_progress_result;
4379
4380 // Called periodically with the current progress.
4381 // Return `UFBX_PROGRESS_CANCEL` to cancel further processing.
4382 typedef ufbx_progress_result ufbx_progress_fn(void *user, const ufbx_progress *progress);
4383
4384 typedef struct ufbx_progress_cb {
4385 ufbx_progress_fn *fn;
4386 void *user;
4387
4388 UFBX_CALLBACK_IMPL(ufbx_progress_cb, ufbx_progress_fn, ufbx_progress_result,
4389 (void *user, const ufbx_progress *progress),
4390 (progress))
4391 } ufbx_progress_cb;
4392
4393 // -- Inflate
4394
4395 typedef struct ufbx_inflate_input ufbx_inflate_input;
4396 typedef struct ufbx_inflate_retain ufbx_inflate_retain;
4397
4398 // Source data/stream to decompress with `ufbx_inflate()`
4399 struct ufbx_inflate_input {
4400 // Total size of the data in bytes
4401 size_t total_size;
4402
4403 // (optional) Initial or complete data chunk
4404 const void *data;
4405 size_t data_size;
4406
4407 // (optional) Temporary buffer, defaults to 256b stack buffer
4408 void *buffer;
4409 size_t buffer_size;
4410
4411 // (optional) Streaming read function, concatenated after `data`
4412 ufbx_read_fn *read_fn;
4413 void *read_user;
4414
4415 // (optional) Progress reporting
4416 ufbx_progress_cb progress_cb;
4417 uint64_t progress_interval_hint; // < Bytes between progress report calls
4418
4419 // (optional) Change the progress scope
4420 uint64_t progress_size_before;
4421 uint64_t progress_size_after;
4422
4423 // (optional) No the DEFLATE header
4424 bool no_header;
4425
4426 // (optional) No the Adler32 checksum
4427 bool no_checksum;
4428
4429 // (optional) Force internal fast lookup bit amount
4430 size_t internal_fast_bits;
4431 };
4432
4433 // Persistent data between `ufbx_inflate()` calls
4434 // NOTE: You must set `initialized` to `false`, but `data` may be uninitialized
4435 struct ufbx_inflate_retain {
4436 bool initialized;
4437 uint64_t data[1024];
4438 };
4439
4440 typedef enum ufbx_index_error_handling UFBX_ENUM_REPR {
4441 // Clamp to a valid value.
4442 UFBX_INDEX_ERROR_HANDLING_CLAMP,
4443 // Set bad indices to `UFBX_NO_INDEX`.
4444 // This is the recommended way if you need to deal with files with gaps in information.
4445 // HINT: If you use this `ufbx_get_vertex_TYPE()` functions will return zero
4446 // on invalid indices instead of failing.
4447 UFBX_INDEX_ERROR_HANDLING_NO_INDEX,
4448 // Fail loading entierely when encountering a bad index.
4449 UFBX_INDEX_ERROR_HANDLING_ABORT_LOADING,
4450 // Pass bad indices through as-is.
4451 // Requires `ufbx_load_opts.allow_unsafe`.
4452 // UNSAFE: Breaks any API guarantees regarding indexes being in bounds and makes
4453 // `ufbx_get_vertex_TYPE()` memory-unsafe to use.
4454 UFBX_INDEX_ERROR_HANDLING_UNSAFE_IGNORE,
4455
4456 UFBX_ENUM_FORCE_WIDTH(UFBX_INDEX_ERROR_HANDLING)
4457 } ufbx_index_error_handling;
4458
4459 UFBX_ENUM_TYPE(ufbx_index_error_handling, UFBX_INDEX_ERROR_HANDLING, UFBX_INDEX_ERROR_HANDLING_UNSAFE_IGNORE);
4460
4461 typedef enum ufbx_unicode_error_handling UFBX_ENUM_REPR {
4462 // Replace errors with U+FFFD "Replacement Character"
4463 UFBX_UNICODE_ERROR_HANDLING_REPLACEMENT_CHARACTER,
4464 // Replace errors with '_' U+5F "Low Line"
4465 UFBX_UNICODE_ERROR_HANDLING_UNDERSCORE,
4466 // Replace errors with '?' U+3F "Question Mark"
4467 UFBX_UNICODE_ERROR_HANDLING_QUESTION_MARK,
4468 // Remove errors from the output
4469 UFBX_UNICODE_ERROR_HANDLING_REMOVE,
4470 // Fail loading on encountering an Unicode error
4471 UFBX_UNICODE_ERROR_HANDLING_ABORT_LOADING,
4472 // Ignore and pass-through non-UTF-8 string data.
4473 // Requires `ufbx_load_opts.allow_unsafe`.
4474 // UNSAFE: Breaks API guarantee that `ufbx_string` is UTF-8 encoded.
4475 UFBX_UNICODE_ERROR_HANDLING_UNSAFE_IGNORE,
4476
4477 UFBX_ENUM_FORCE_WIDTH(UFBX_UNICODE_ERROR_HANDLING)
4478 } ufbx_unicode_error_handling;
4479
4480 UFBX_ENUM_TYPE(ufbx_unicode_error_handling, UFBX_UNICODE_ERROR_HANDLING, UFBX_UNICODE_ERROR_HANDLING_UNSAFE_IGNORE);
4481
4482 typedef enum ufbx_baked_key_flags UFBX_FLAG_REPR {
4483 // This keyframe represents a constant step from the left side
4484 UFBX_BAKED_KEY_STEP_LEFT = 0x1,
4485 // This keyframe represents a constant step from the right side
4486 UFBX_BAKED_KEY_STEP_RIGHT = 0x2,
4487 // This keyframe is the main part of a step
4488 // Bordering either `UFBX_BAKED_KEY_STEP_LEFT` or `UFBX_BAKED_KEY_STEP_RIGHT`.
4489 UFBX_BAKED_KEY_STEP_KEY = 0x4,
4490 // This keyframe is a real keyframe in the source animation
4491 UFBX_BAKED_KEY_KEYFRAME = 0x8,
4492 // This keyframe has been reduced by maximum sample rate.
4493 // See `ufbx_bake_opts.maximum_sample_rate`.
4494 UFBX_BAKED_KEY_REDUCED = 0x10,
4495
4496 UFBX_FLAG_FORCE_WIDTH(UFBX_BAKED_KEY)
4497 } ufbx_baked_key_flags;
4498
4499 typedef struct ufbx_baked_vec3 {
4500 double time; // < Time of the keyframe, in seconds
4501 ufbx_vec3 value; // < Value at `time`, can be linearly interpolated
4502 ufbx_baked_key_flags flags; // < Additional information about the keyframe
4503 } ufbx_baked_vec3;
4504
4505 UFBX_LIST_TYPE(ufbx_baked_vec3_list, ufbx_baked_vec3);
4506
4507 typedef struct ufbx_baked_quat {
4508 double time; // < Time of the keyframe, in seconds
4509 ufbx_quat value; // < Value at `time`, can be (spherically) linearly interpolated
4510 ufbx_baked_key_flags flags; // < Additional information about the keyframe
4511 } ufbx_baked_quat;
4512
4513 UFBX_LIST_TYPE(ufbx_baked_quat_list, ufbx_baked_quat);
4514
4515 // Baked transform animation for a single node.
4516 typedef struct ufbx_baked_node {
4517
4518 // Typed ID of the node, maps to `ufbx_scene.nodes[]`.
4519 uint32_t typed_id;
4520 // Element ID of the element, maps to `ufbx_scene.elements[]`.
4521 uint32_t element_id;
4522
4523 // The translation channel has constant values for the whole animation.
4524 bool constant_translation;
4525 // The rotation channel has constant values for the whole animation.
4526 bool constant_rotation;
4527 // The scale channel has constant values for the whole animation.
4528 bool constant_scale;
4529
4530 // Translation keys for the animation, maps to `ufbx_node.local_transform.translation`.
4531 ufbx_baked_vec3_list translation_keys;
4532 // Rotation keyframes, maps to `ufbx_node.local_transform.rotation`.
4533 ufbx_baked_quat_list rotation_keys;
4534 // Scale keyframes, maps to `ufbx_node.local_transform.scale`.
4535 ufbx_baked_vec3_list scale_keys;
4536
4537 } ufbx_baked_node;
4538
4539 UFBX_LIST_TYPE(ufbx_baked_node_list, ufbx_baked_node);
4540
4541 // Baked property animation.
4542 typedef struct ufbx_baked_prop {
4543 // Name of the property, eg. `"Visibility"`.
4544 ufbx_string name;
4545 // The value of the property is constant for the whole animation.
4546 bool constant_value;
4547 // Property value keys.
4548 ufbx_baked_vec3_list keys;
4549 } ufbx_baked_prop;
4550
4551 UFBX_LIST_TYPE(ufbx_baked_prop_list, ufbx_baked_prop);
4552
4553 // Baked property animation for a single element.
4554 typedef struct ufbx_baked_element {
4555 // Element ID of the element, maps to `ufbx_scene.elements[]`.
4556 uint32_t element_id;
4557 // List of properties the animation modifies.
4558 ufbx_baked_prop_list props;
4559 } ufbx_baked_element;
4560
4561 UFBX_LIST_TYPE(ufbx_baked_element_list, ufbx_baked_element);
4562
4563 typedef struct ufbx_baked_anim_metadata {
4564 // Memory statistics
4565 size_t result_memory_used;
4566 size_t temp_memory_used;
4567 size_t result_allocs;
4568 size_t temp_allocs;
4569 } ufbx_baked_anim_metadata;
4570
4571 // Animation baked into linearly interpolated keyframes.
4572 // See `ufbx_bake_anim()`.
4573 typedef struct ufbx_baked_anim {
4574
4575 // Nodes that are modified by the animation.
4576 // Some nodes may be missing if the specified animation does not transform them.
4577 // Conversely, some non-obviously animated nodes may be included as exporters
4578 // often may add dummy keyframes for objects.
4579 ufbx_baked_node_list nodes;
4580
4581 // Element properties modified by the animation.
4582 ufbx_baked_element_list elements;
4583
4584 // Playback time range for the animation.
4585 double playback_time_begin;
4586 double playback_time_end;
4587 double playback_duration;
4588
4589 // Keyframe time range.
4590 double key_time_min;
4591 double key_time_max;
4592
4593 // Additional bake information.
4594 ufbx_baked_anim_metadata metadata;
4595
4596 } ufbx_baked_anim;
4597
4598 // -- Thread API
4599
4600 // Internal thread pool handle.
4601 // Passed to `ufbx_thread_pool_run_task()` from an user thread to run ufbx tasks.
4602 // HINT: This context can store a user pointer via `ufbx_thread_pool_set_user_ptr()`.
4603 typedef uintptr_t ufbx_thread_pool_context;
4604
4605 // Thread pool creation information from ufbx.
4606 typedef struct ufbx_thread_pool_info {
4607 uint32_t max_concurrent_tasks;
4608 } ufbx_thread_pool_info;
4609
4610 // Initialize the thread pool.
4611 // Return `true` on success.
4612 typedef bool ufbx_thread_pool_init_fn(void *user, ufbx_thread_pool_context ctx, const ufbx_thread_pool_info *info);
4613
4614 // Run tasks `count` tasks in threads.
4615 // You must call `ufbx_thread_pool_run_task()` with indices `[start_index, start_index + count)`.
4616 // The threads are launched in batches indicated by `group`, see `UFBX_THREAD_GROUP_COUNT` for more information.
4617 // Ideally, you should run all the task indices in parallel within each `ufbx_thread_pool_run_fn()` call.
4618 typedef void ufbx_thread_pool_run_fn(void *user, ufbx_thread_pool_context ctx, uint32_t group, uint32_t start_index, uint32_t count);
4619
4620 // Wait for previous tasks spawned in `ufbx_thread_pool_run_fn()` to finish.
4621 // `group` specifies the batch to wait for, `max_index` contains `start_index + count` from that group instance.
4622 typedef void ufbx_thread_pool_wait_fn(void *user, ufbx_thread_pool_context ctx, uint32_t group, uint32_t max_index);
4623
4624 // Free the thread pool.
4625 typedef void ufbx_thread_pool_free_fn(void *user, ufbx_thread_pool_context ctx);
4626
4627 // Thread pool interface.
4628 // See functions above for more information.
4629 //
4630 // Hypothetical example of calls, where `UFBX_THREAD_GROUP_COUNT=2` for simplicity:
4631 //
4632 // run_fn(group=0, start_index=0, count=4) -> t0 := threaded { ufbx_thread_pool_run_task(0..3) }
4633 // run_fn(group=1, start_index=4, count=10) -> t1 := threaded { ufbx_thread_pool_run_task(4..10) }
4634 // wait_fn(group=0, max_index=4) -> wait_threads(t0)
4635 // run_fn(group=0, start_index=10, count=15) -> t0 := threaded { ufbx_thread_pool_run_task(10..14) }
4636 // wait_fn(group=1, max_index=10) -> wait_threads(t1)
4637 // wait_fn(group=0, max_index=15) -> wait_threads(t0)
4638 //
4639 typedef struct ufbx_thread_pool {
4640 ufbx_thread_pool_init_fn *init_fn; // < Optional
4641 ufbx_thread_pool_run_fn *run_fn; // < Required
4642 ufbx_thread_pool_wait_fn *wait_fn; // < Required
4643 ufbx_thread_pool_free_fn *free_fn; // < Optional
4644 void *user;
4645 } ufbx_thread_pool;
4646
4647 // Thread pool options.
4648 typedef struct ufbx_thread_opts {
4649
4650 // Thread pool interface.
4651 // HINT: You can use `extra/ufbx_os.h` to provide a thread pool.
4652 ufbx_thread_pool pool;
4653
4654 // Maximum of tasks to have in-flight.
4655 // Default: 2048
4656 size_t num_tasks;
4657
4658 // Maximum amount of memory to use for batched threaded processing.
4659 // Default: 32MB
4660 // NOTE: The actual used memory usage might be higher, if there are individual tasks
4661 // that rqeuire a high amount of memory.
4662 size_t memory_limit;
4663
4664 } ufbx_thread_opts;
4665
4666 // Flags to control nanimation evaluation functions.
4667 typedef enum ufbx_evaluate_flags UFBX_FLAG_REPR {
4668
4669 // Do not extrapolate past the keyframes.
4670 UFBX_EVALUATE_FLAG_NO_EXTRAPOLATION = 0x1,
4671
4672 UFBX_FLAG_FORCE_WIDTH(ufbx_evaluate_flags)
4673 } ufbx_evaluate_flags;
4674
4675 // -- Main API
4676
4677 // Options for `ufbx_load_file/memory/stream/stdio()`
4678 // NOTE: Initialize to zero with `{ 0 }` (C) or `{ }` (C++)
4679 typedef struct ufbx_load_opts {
4680 uint32_t _begin_zero;
4681
4682 ufbx_allocator_opts temp_allocator; // < Allocator used during loading
4683 ufbx_allocator_opts result_allocator; // < Allocator used for the final scene
4684 ufbx_thread_opts thread_opts; // < Threading options
4685
4686 // Preferences
4687 bool ignore_geometry; // < Do not load geometry datsa (vertices, indices, etc)
4688 bool ignore_animation; // < Do not load animation curves
4689 bool ignore_embedded; // < Do not load embedded content
4690 bool ignore_all_content; // < Do not load any content (geometry, animation, embedded)
4691
4692 bool evaluate_skinning; // < Evaluate skinning (see ufbx_mesh.skinned_vertices)
4693 bool evaluate_caches; // < Evaluate vertex caches (see ufbx_mesh.skinned_vertices)
4694
4695 // Try to open external files referenced by the main file automatically.
4696 // Applies to geometry caches and .mtl files for OBJ.
4697 // NOTE: This may be risky for untrusted data as the input files may contain
4698 // references to arbitrary paths in the filesystem.
4699 // NOTE: This only applies to files *implicitly* referenced by the scene, if
4700 // you request additional files via eg. `ufbx_load_opts.obj_mtl_path` they
4701 // are still loaded.
4702 // NOTE: Will fail loading if any external files are not found by default, use
4703 // `ufbx_load_opts.ignore_missing_external_files` to suppress this, in this case
4704 // you can find the errors at `ufbx_metadata.warnings[]` as `UFBX_WARNING_MISSING_EXTERNAL_FILE`.
4705 bool load_external_files;
4706
4707 // Don't fail loading if external files are not found.
4708 bool ignore_missing_external_files;
4709
4710 // Don't compute `ufbx_skin_deformer` `vertices` and `weights` arrays saving
4711 // a bit of memory and time if not needed
4712 bool skip_skin_vertices;
4713
4714 // Skip computing `ufbx_mesh.material_parts[]` and `ufbx_mesh.face_group_parts[]`.
4715 bool skip_mesh_parts;
4716
4717 // Clean-up skin weights by removing negative, zero and NAN weights.
4718 bool clean_skin_weights;
4719
4720 // Read Blender materials as PBR values.
4721 // Blender converts PBR materials to legacy FBX Phong materials in a deterministic way.
4722 // If this setting is enabled, such materials will be read as `UFBX_SHADER_BLENDER_PHONG`,
4723 // which means ufbx will be able to parse roughness and metallic textures.
4724 bool use_blender_pbr_material;
4725
4726 // Don't adjust reading the FBX file depending on the detected exporter
4727 bool disable_quirks;
4728
4729 // Don't allow partially broken FBX files to load
4730 bool strict;
4731
4732 // Force ASCII parsing to use a single thread.
4733 // The multi-threaded ASCII parsing is slightly more lenient as it ignores
4734 // the self-reported size of ASCII arrays, that threaded parsing depends on.
4735 bool force_single_thread_ascii_parsing;
4736
4737 // UNSAFE: If enabled allows using unsafe options that may fundamentally
4738 // break the API guarantees.
4739 ufbx_unsafe bool allow_unsafe;
4740
4741 // Specify how to handle broken indices.
4742 ufbx_index_error_handling index_error_handling;
4743
4744 // Connect related elements even if they are broken. If `false` (default)
4745 // `ufbx_skin_cluster` with a missing `bone` field are _not_ included in
4746 // the `ufbx_skin_deformer.clusters[]` array for example.
4747 bool connect_broken_elements;
4748
4749 // Allow nodes that are not connected in any way to the root. Conversely if
4750 // disabled, all lone nodes will be parented under `ufbx_scene.root_node`.
4751 bool allow_nodes_out_of_root;
4752
4753 // Allow meshes with no vertex position attribute.
4754 // NOTE: If this is set `ufbx_mesh.vertex_position.exists` may be `false`.
4755 bool allow_missing_vertex_position;
4756
4757 // Allow faces with zero indices.
4758 bool allow_empty_faces;
4759
4760 // Generate vertex normals for a meshes that are missing normals.
4761 // You can see if the normals have been generated from `ufbx_mesh.generated_normals`.
4762 bool generate_missing_normals;
4763
4764 // Ignore `open_file_cb` when loading the main file.
4765 bool open_main_file_with_default;
4766
4767 // Path separator character, defaults to '\' on Windows and '/' otherwise.
4768 char path_separator;
4769
4770 // Maximum depth of the node hirerachy.
4771 // Will fail with `UFBX_ERROR_NODE_DEPTH_LIMIT` if a node is deeper than this limit.
4772 // NOTE: The default of 0 allows arbitrarily deep hierarchies. Be careful if using
4773 // recursive algorithms without setting this limit.
4774 uint32_t node_depth_limit;
4775
4776 // Estimated file size for progress reporting
4777 uint64_t file_size_estimate;
4778
4779 // Buffer size in bytes to use for reading from files or IO callbacks
4780 size_t read_buffer_size;
4781
4782 // Filename to use as a base for relative file paths if not specified using
4783 // `ufbx_load_file()`. Use `length = SIZE_MAX` for NULL-terminated strings.
4784 // `raw_filename` will be derived from this if empty.
4785 ufbx_string filename;
4786
4787 // Raw non-UTF8 filename. Does not support NULL termination.
4788 // `filename` will be derived from this if empty.
4789 ufbx_blob raw_filename;
4790
4791 // Progress reporting
4792 ufbx_progress_cb progress_cb;
4793 uint64_t progress_interval_hint; // < Bytes between progress report calls
4794
4795 // External file callbacks (defaults to stdio.h)
4796 ufbx_open_file_cb open_file_cb;
4797
4798 // How to handle geometry transforms in the nodes.
4799 // See `ufbx_geometry_transform_handling` for an explanation.
4800 ufbx_geometry_transform_handling geometry_transform_handling;
4801
4802 // How to handle unconventional transform inherit modes.
4803 // See `ufbx_inherit_mode_handling` for an explanation.
4804 ufbx_inherit_mode_handling inherit_mode_handling;
4805
4806 // How to perform space conversion by `target_axes` and `target_unit_meters`.
4807 // See `ufbx_space_conversion` for an explanation.
4808 ufbx_space_conversion space_conversion;
4809
4810 // How to handle pivots.
4811 // See `ufbx_pivot_handling` for an explanation.
4812 ufbx_pivot_handling pivot_handling;
4813
4814 // Retain the original transforms of empties when converting pivots.
4815 bool pivot_handling_retain_empties;
4816
4817 // Axis used to mirror for conversion between left-handed and right-handed coordinates.
4818 ufbx_mirror_axis handedness_conversion_axis;
4819
4820 // Do not change winding of faces when converting handedness.
4821 bool handedness_conversion_retain_winding;
4822
4823 // Reverse winding of all faces.
4824 // If `handedness_conversion_retain_winding` is not specified, mirrored meshes
4825 // will retain their original winding.
4826 bool reverse_winding;
4827
4828 // Apply an implicit root transformation to match axes.
4829 // Used if `ufbx_coordinate_axes_valid(target_axes)`.
4830 ufbx_coordinate_axes target_axes;
4831
4832 // Scale the scene so that one world-space unit is `target_unit_meters` meters.
4833 // By default units are not scaled.
4834 ufbx_real target_unit_meters;
4835
4836 // Target space for camera.
4837 // By default FBX cameras point towards the positive X axis.
4838 // Used if `ufbx_coordinate_axes_valid(target_camera_axes)`.
4839 ufbx_coordinate_axes target_camera_axes;
4840
4841 // Target space for directed lights.
4842 // By default FBX lights point towards the negative Y axis.
4843 // Used if `ufbx_coordinate_axes_valid(target_light_axes)`.
4844 ufbx_coordinate_axes target_light_axes;
4845
4846 // Name for dummy geometry transform helper nodes.
4847 // See `UFBX_GEOMETRY_TRANSFORM_HANDLING_HELPER_NODES`.
4848 ufbx_string geometry_transform_helper_name;
4849
4850 // Name for dummy scale helper nodes.
4851 // See `UFBX_INHERIT_MODE_HANDLING_HELPER_NODES`.
4852 ufbx_string scale_helper_name;
4853
4854 // Normalize vertex normals.
4855 bool normalize_normals;
4856
4857 // Normalize tangents and bitangents.
4858 bool normalize_tangents;
4859
4860 // Override for the root transform
4861 bool use_root_transform;
4862 ufbx_transform root_transform;
4863
4864 // Animation keyframe clamp threshold, only applies to specific interpolation modes.
4865 double key_clamp_threshold;
4866
4867 // Specify how to handle Unicode errors in strings.
4868 ufbx_unicode_error_handling unicode_error_handling;
4869
4870 // Retain the 'W' component of mesh normal/tangent/bitangent.
4871 // See `ufbx_vertex_attrib.values_w`.
4872 bool retain_vertex_attrib_w;
4873
4874 // Retain the raw document structure using `ufbx_dom_node`.
4875 bool retain_dom;
4876
4877 // Force a specific file format instead of detecting it.
4878 ufbx_file_format file_format;
4879
4880 // How far to read into the file to determine the file format.
4881 // Default: 16kB
4882 size_t file_format_lookahead;
4883
4884 // Do not attempt to detect file format from file content.
4885 bool no_format_from_content;
4886
4887 // Do not attempt to detect file format from filename extension.
4888 // ufbx primarily detects file format from the file header,
4889 // this is just used as a fallback.
4890 bool no_format_from_extension;
4891
4892 // (.obj) Try to find .mtl file with matching filename as the .obj file.
4893 // Used if the file specified `mtllib` line is not found, eg. for a file called
4894 // `model.obj` that contains the line `usemtl materials.mtl`, ufbx would first
4895 // try to open `materials.mtl` and if that fails it tries to open `model.mtl`.
4896 bool obj_search_mtl_by_filename;
4897
4898 // (.obj) Don't split geometry into meshes by object.
4899 bool obj_merge_objects;
4900
4901 // (.obj) Don't split geometry into meshes by groups.
4902 bool obj_merge_groups;
4903
4904 // (.obj) Force splitting groups even on object boundaries.
4905 bool obj_split_groups;
4906
4907 // (.obj) Path to the .mtl file.
4908 // Use `length = SIZE_MAX` for NULL-terminated strings.
4909 // NOTE: This is used _instead_ of the one in the file even if not found
4910 // and sidesteps `load_external_files` as it's _explicitly_ requested.
4911 ufbx_string obj_mtl_path;
4912
4913 // (.obj) Data for the .mtl file.
4914 ufbx_blob obj_mtl_data;
4915
4916 // The world unit in meters that .obj files are assumed to be in.
4917 // .obj files do not define the working units. By default the unit scale
4918 // is read as zero, and no unit conversion is performed.
4919 ufbx_real obj_unit_meters;
4920
4921 // Coordinate space .obj files are assumed to be in.
4922 // .obj files do not define the coordinate space they use. By default no
4923 // coordinate space is assumed and no conversion is performed.
4924 ufbx_coordinate_axes obj_axes;
4925
4926 uint32_t _end_zero;
4927 } ufbx_load_opts;
4928
4929 // Options for `ufbx_evaluate_scene()`
4930 // NOTE: Initialize to zero with `{ 0 }` (C) or `{ }` (C++)
4931 typedef struct ufbx_evaluate_opts {
4932 uint32_t _begin_zero;
4933
4934 ufbx_allocator_opts temp_allocator; // < Allocator used during evaluation
4935 ufbx_allocator_opts result_allocator; // < Allocator used for the final scene
4936
4937 bool evaluate_skinning; // < Evaluate skinning (see ufbx_mesh.skinned_vertices)
4938 bool evaluate_caches; // < Evaluate vertex caches (see ufbx_mesh.skinned_vertices)
4939
4940 // Evaluation flags.
4941 // See `ufbx_evaluate_flags` for information.
4942 uint32_t evaluate_flags;
4943
4944 // WARNING: Potentially unsafe! Try to open external files such as geometry caches
4945 bool load_external_files;
4946
4947 // External file callbacks (defaults to stdio.h)
4948 ufbx_open_file_cb open_file_cb;
4949
4950 uint32_t _end_zero;
4951 } ufbx_evaluate_opts;
4952
4953 UFBX_LIST_TYPE(ufbx_const_uint32_list, const uint32_t);
4954 UFBX_LIST_TYPE(ufbx_const_real_list, const ufbx_real);
4955
4956 typedef struct ufbx_prop_override_desc {
4957 // Element (`ufbx_element.element_id`) to override the property from
4958 uint32_t element_id;
4959
4960 // Property name to override.
4961 ufbx_string prop_name;
4962
4963 // Override value, use `value.x` for scalars. `value_int` is initialized
4964 // from `value.x` if zero so keep `value` zeroed even if you don't need it!
4965 ufbx_vec4 value;
4966 ufbx_string value_str;
4967 int64_t value_int;
4968 } ufbx_prop_override_desc;
4969
4970 UFBX_LIST_TYPE(ufbx_const_prop_override_desc_list, const ufbx_prop_override_desc);
4971
4972 UFBX_LIST_TYPE(ufbx_const_transform_override_list, const ufbx_transform_override);
4973
4974 typedef struct ufbx_anim_opts {
4975 uint32_t _begin_zero;
4976
4977 // Animation layers indices.
4978 // Corresponding to `ufbx_scene.anim_layers[]`, aka `ufbx_anim_layer.typed_id`.
4979 ufbx_const_uint32_list layer_ids;
4980
4981 // Override layer weights, parallel to `ufbx_anim_opts.layer_ids[]`.
4982 ufbx_const_real_list override_layer_weights;
4983
4984 // Property overrides.
4985 // These allow you to override FBX properties, such as 'UFBX_Lcl_Rotation`.
4986 ufbx_const_prop_override_desc_list prop_overrides;
4987
4988 // Transform overrides.
4989 // These allow you to override individual nodes' `ufbx_node.local_transform`.
4990 ufbx_const_transform_override_list transform_overrides;
4991
4992 // Ignore connected properties
4993 bool ignore_connections;
4994
4995 ufbx_allocator_opts result_allocator; // < Allocator used to create the `ufbx_anim`
4996
4997 uint32_t _end_zero;
4998 } ufbx_anim_opts;
4999
5000 // Specifies how to handle stepped tangents.
5001 typedef enum ufbx_bake_step_handling UFBX_ENUM_REPR {
5002
5003 // One millisecond default step duration, with potential extra slack for converting to `float`.
5004 UFBX_BAKE_STEP_HANDLING_DEFAULT,
5005
5006 // Use a custom interpolation duration for the constant step.
5007 // See `ufbx_bake_opts.step_custom_duration` and optionally `ufbx_bake_opts.step_custom_epsilon`.
5008 UFBX_BAKE_STEP_HANDLING_CUSTOM_DURATION,
5009
5010 // Stepped keyframes are represented as keyframes at the exact same time.
5011 // Use flags `UFBX_BAKED_KEY_STEP_LEFT` and `UFBX_BAKED_KEY_STEP_RIGHT` to differentiate
5012 // between the primary key and edge limits.
5013 UFBX_BAKE_STEP_HANDLING_IDENTICAL_TIME,
5014
5015 // Represent stepped keyframe times as the previous/next representable `double` value.
5016 // Using this and robust linear interpolation will handle stepped tangents correctly
5017 // without having to look at the key flags.
5018 // NOTE: Casting these values to `float` or otherwise modifying them can collapse
5019 // the keyframes to have the identical time.
5020 UFBX_BAKE_STEP_HANDLING_ADJACENT_DOUBLE,
5021
5022 // Treat all stepped tangents as linearly interpolated.
5023 UFBX_BAKE_STEP_HANDLING_IGNORE,
5024
5025 UFBX_ENUM_FORCE_WIDTH(ufbx_bake_step_handling)
5026 } ufbx_bake_step_handling;
5027
5028 UFBX_ENUM_TYPE(ufbx_bake_step_handling, UFBX_BAKE_STEP_HANDLING, UFBX_BAKE_STEP_HANDLING_IGNORE);
5029
5030 typedef struct ufbx_bake_opts {
5031 uint32_t _begin_zero;
5032
5033 ufbx_allocator_opts temp_allocator; // < Allocator used during loading
5034 ufbx_allocator_opts result_allocator; // < Allocator used for the final baked animation
5035
5036 // Move the keyframe times to start from zero regardless of the animation start time.
5037 // For example, for an animation spanning between frames [30, 60] will be moved to
5038 // [0, 30] in the baked animation.
5039 // NOTE: This is in general not equivalent to subtracting `ufbx_anim.time_begin`
5040 // from each keyframe, as this trimming is done exactly using internal FBX ticks.
5041 bool trim_start_time;
5042
5043 // Samples per second to use for resampling non-linear animation.
5044 // Default: 30
5045 double resample_rate;
5046
5047 // Minimum sample rate to not resample.
5048 // Many exporters resample animation by default. To avoid double-resampling
5049 // keyframe rates higher or equal to this will not be resampled.
5050 // Default: 19.5
5051 double minimum_sample_rate;
5052
5053 // Maximum sample rate to use, this will remove keys if they are too close together.
5054 // Default: unlimited
5055 double maximum_sample_rate;
5056
5057 // Bake the raw versions of properties related to transforms.
5058 bool bake_transform_props;
5059
5060 // Do not bake node transforms.
5061 bool skip_node_transforms;
5062
5063 // Do not resample linear rotation keyframes.
5064 // FBX interpolates rotation in Euler angles, so this might cause incorrect interpolation.
5065 bool no_resample_rotation;
5066
5067 // Ignore layer weight animation.
5068 bool ignore_layer_weight_animation;
5069
5070 // Maximum number of segments to generate from one keyframe.
5071 // Default: 32
5072 size_t max_keyframe_segments;
5073
5074 // How to handle stepped tangents.
5075 ufbx_bake_step_handling step_handling;
5076
5077 // Interpolation duration used by `UFBX_BAKE_STEP_HANDLING_CUSTOM_DURATION`.
5078 double step_custom_duration;
5079
5080 // Interpolation epsilon used by `UFBX_BAKE_STEP_HANDLING_CUSTOM_DURATION`.
5081 // Defined as the minimum fractional decrease/increase in key time, ie.
5082 // `time / (1.0 + step_custom_epsilon)` and `time * (1.0 + step_custom_epsilon)`.
5083 double step_custom_epsilon;
5084
5085 // Flags passed to animation evaluation functions.
5086 // See `ufbx_evaluate_flags`.
5087 uint32_t evaluate_flags;
5088
5089 // Enable key reduction.
5090 bool key_reduction_enabled;
5091
5092 // Enable key reduction for non-constant rotations.
5093 // Assumes rotations will be interpolated using a spherical linear interpolation at runtime.
5094 bool key_reduction_rotation;
5095
5096 // Threshold for reducing keys for linear segments.
5097 // Default `0.000001`, use negative to disable.
5098 double key_reduction_threshold;
5099
5100 // Maximum passes over the keys to reduce.
5101 // Every pass can potentially halve the the amount of keys.
5102 // Default: `4`
5103 size_t key_reduction_passes;
5104
5105 uint32_t _end_zero;
5106 } ufbx_bake_opts;
5107
5108 // Options for `ufbx_tessellate_nurbs_curve()`
5109 // NOTE: Initialize to zero with `{ 0 }` (C) or `{ }` (C++)
5110 typedef struct ufbx_tessellate_curve_opts {
5111 uint32_t _begin_zero;
5112
5113 ufbx_allocator_opts temp_allocator; // < Allocator used during tessellation
5114 ufbx_allocator_opts result_allocator; // < Allocator used for the final line curve
5115
5116 // How many segments tessellate each span in `ufbx_nurbs_basis.spans`.
5117 size_t span_subdivision;
5118
5119 uint32_t _end_zero;
5120 } ufbx_tessellate_curve_opts;
5121
5122 // Options for `ufbx_tessellate_nurbs_surface()`
5123 // NOTE: Initialize to zero with `{ 0 }` (C) or `{ }` (C++)
5124 typedef struct ufbx_tessellate_surface_opts {
5125 uint32_t _begin_zero;
5126
5127 ufbx_allocator_opts temp_allocator; // < Allocator used during tessellation
5128 ufbx_allocator_opts result_allocator; // < Allocator used for the final mesh
5129
5130 // How many segments tessellate each span in `ufbx_nurbs_basis.spans`.
5131 // NOTE: Default is `4`, _not_ `ufbx_nurbs_surface.span_subdivision_u/v` as that
5132 // would make it easy to create an FBX file with an absurdly high subdivision
5133 // rate (similar to mesh subdivision). Please enforce copy the value yourself
5134 // enforcing whatever limits you deem reasonable.
5135 size_t span_subdivision_u;
5136 size_t span_subdivision_v;
5137
5138 // Skip computing `ufbx_mesh.material_parts[]`
5139 bool skip_mesh_parts;
5140
5141 uint32_t _end_zero;
5142 } ufbx_tessellate_surface_opts;
5143
5144 // Options for `ufbx_subdivide_mesh()`
5145 // NOTE: Initialize to zero with `{ 0 }` (C) or `{ }` (C++)
5146 typedef struct ufbx_subdivide_opts {
5147 uint32_t _begin_zero;
5148
5149 ufbx_allocator_opts temp_allocator; // < Allocator used during subdivision
5150 ufbx_allocator_opts result_allocator; // < Allocator used for the final mesh
5151
5152 ufbx_subdivision_boundary boundary;
5153 ufbx_subdivision_boundary uv_boundary;
5154
5155 // Do not generate normals
5156 bool ignore_normals;
5157
5158 // Interpolate existing normals using the subdivision rules
5159 // instead of generating new normals
5160 bool interpolate_normals;
5161
5162 // Subdivide also tangent attributes
5163 bool interpolate_tangents;
5164
5165 // Map subdivided vertices into weighted original vertices.
5166 // NOTE: May be O(n^2) if `max_source_vertices` is not specified!
5167 bool evaluate_source_vertices;
5168
5169 // Limit source vertices per subdivided vertex.
5170 size_t max_source_vertices;
5171
5172 // Calculate bone influences over subdivided vertices (if applicable).
5173 // NOTE: May be O(n^2) if `max_skin_weights` is not specified!
5174 bool evaluate_skin_weights;
5175
5176 // Limit bone influences per subdivided vertex.
5177 size_t max_skin_weights;
5178
5179 // Index of the skin deformer to use for `evaluate_skin_weights`.
5180 size_t skin_deformer_index;
5181
5182 uint32_t _end_zero;
5183 } ufbx_subdivide_opts;
5184
5185 // Options for `ufbx_load_geometry_cache()`
5186 // NOTE: Initialize to zero with `{ 0 }` (C) or `{ }` (C++)
5187 typedef struct ufbx_geometry_cache_opts {
5188 uint32_t _begin_zero;
5189
5190 ufbx_allocator_opts temp_allocator; // < Allocator used during loading
5191 ufbx_allocator_opts result_allocator; // < Allocator used for the final scene
5192
5193 // External file callbacks (defaults to stdio.h)
5194 ufbx_open_file_cb open_file_cb;
5195
5196 // FPS value for converting frame times to seconds
5197 double frames_per_second;
5198
5199 // Axis to mirror the geometry by.
5200 ufbx_mirror_axis mirror_axis;
5201
5202 // Enable scaling `scale_factor` all geometry by.
5203 bool use_scale_factor;
5204
5205 // Factor to scale the geometry by.
5206 ufbx_real scale_factor;
5207
5208 uint32_t _end_zero;
5209 } ufbx_geometry_cache_opts;
5210
5211 // Options for `ufbx_read_geometry_cache_TYPE()`
5212 // NOTE: Initialize to zero with `{ 0 }` (C) or `{ }` (C++)
5213 typedef struct ufbx_geometry_cache_data_opts {
5214 uint32_t _begin_zero;
5215
5216 // External file callbacks (defaults to stdio.h)
5217 ufbx_open_file_cb open_file_cb;
5218
5219 bool additive;
5220 bool use_weight;
5221 ufbx_real weight;
5222
5223 // Ignore scene transform.
5224 bool ignore_transform;
5225
5226 uint32_t _end_zero;
5227 } ufbx_geometry_cache_data_opts;
5228
5229 typedef struct ufbx_panic {
5230 bool did_panic;
5231 size_t message_length;
5232 char message[UFBX_PANIC_MESSAGE_LENGTH];
5233 } ufbx_panic;
5234
5235 // -- API
5236
5237 #ifdef __cplusplus
5238 extern "C" {
5239 #endif
5240
5241 // Various zero/empty/identity values
5242 ufbx_abi_data const ufbx_string ufbx_empty_string;
5243 ufbx_abi_data const ufbx_blob ufbx_empty_blob;
5244 ufbx_abi_data const ufbx_matrix ufbx_identity_matrix;
5245 ufbx_abi_data const ufbx_transform ufbx_identity_transform;
5246 ufbx_abi_data const ufbx_vec2 ufbx_zero_vec2;
5247 ufbx_abi_data const ufbx_vec3 ufbx_zero_vec3;
5248 ufbx_abi_data const ufbx_vec4 ufbx_zero_vec4;
5249 ufbx_abi_data const ufbx_quat ufbx_identity_quat;
5250
5251 // Commonly used coordinate axes.
5252 ufbx_abi_data const ufbx_coordinate_axes ufbx_axes_right_handed_y_up;
5253 ufbx_abi_data const ufbx_coordinate_axes ufbx_axes_right_handed_z_up;
5254 ufbx_abi_data const ufbx_coordinate_axes ufbx_axes_left_handed_y_up;
5255 ufbx_abi_data const ufbx_coordinate_axes ufbx_axes_left_handed_z_up;
5256
5257 // Sizes of element types. eg `sizeof(ufbx_node)`
5258 ufbx_abi_data const size_t ufbx_element_type_size[UFBX_ELEMENT_TYPE_COUNT];
5259
5260 // Version of the source file, comparable to `UFBX_HEADER_VERSION`
5261 ufbx_abi_data const uint32_t ufbx_source_version;
5262
5263
5264 // Practically always `true` (see below), if not you need to be careful with threads.
5265 //
5266 // Guaranteed to be `true` in _any_ of the following conditions:
5267 // - ufbx.c has been compiled using: GCC / Clang / MSVC / ICC / EMCC / TCC
5268 // - ufbx.c has been compiled as C++11 or later
5269 // - ufbx.c has been compiled as C11 or later with `<stdatomic.h>` support
5270 //
5271 // If `false` you can't call the following functions concurrently:
5272 // ufbx_evaluate_scene()
5273 // ufbx_free_scene()
5274 // ufbx_subdivide_mesh()
5275 // ufbx_tessellate_nurbs_surface()
5276 // ufbx_free_mesh()
5277 ufbx_abi bool ufbx_is_thread_safe(void);
5278
5279 // Load a scene from a `size` byte memory buffer at `data`
5280 ufbx_abi ufbx_scene *ufbx_load_memory(
5281 const void *data, size_t data_size,
5282 const ufbx_load_opts *opts, ufbx_error *error);
5283
5284 // Load a scene by opening a file named `filename`
5285 ufbx_abi ufbx_scene *ufbx_load_file(
5286 const char *filename,
5287 const ufbx_load_opts *opts, ufbx_error *error);
5288 ufbx_abi ufbx_scene *ufbx_load_file_len(
5289 const char *filename, size_t filename_len,
5290 const ufbx_load_opts *opts, ufbx_error *error);
5291
5292 // Load a scene by reading from an `FILE *file` stream
5293 // NOTE: `file` is passed as a `void` pointer to avoid including <stdio.h>
5294 ufbx_abi ufbx_scene *ufbx_load_stdio(
5295 void *file,
5296 const ufbx_load_opts *opts, ufbx_error *error);
5297
5298 // Load a scene by reading from an `FILE *file` stream with a prefix
5299 // NOTE: `file` is passed as a `void` pointer to avoid including <stdio.h>
5300 ufbx_abi ufbx_scene *ufbx_load_stdio_prefix(
5301 void *file,
5302 const void *prefix, size_t prefix_size,
5303 const ufbx_load_opts *opts, ufbx_error *error);
5304
5305 // Load a scene from a user-specified stream
5306 ufbx_abi ufbx_scene *ufbx_load_stream(
5307 const ufbx_stream *stream,
5308 const ufbx_load_opts *opts, ufbx_error *error);
5309
5310 // Load a scene from a user-specified stream with a prefix
5311 ufbx_abi ufbx_scene *ufbx_load_stream_prefix(
5312 const ufbx_stream *stream,
5313 const void *prefix, size_t prefix_size,
5314 const ufbx_load_opts *opts, ufbx_error *error);
5315
5316 // Free a previously loaded or evaluated scene
5317 ufbx_abi void ufbx_free_scene(ufbx_scene *scene);
5318
5319 // Increment `scene` refcount
5320 ufbx_abi void ufbx_retain_scene(ufbx_scene *scene);
5321
5322 // Format a textual description of `error`.
5323 // Always produces a NULL-terminated string to `char dst[dst_size]`, truncating if
5324 // necessary. Returns the number of characters written not including the NULL terminator.
5325 ufbx_abi size_t ufbx_format_error(char *dst, size_t dst_size, const ufbx_error *error);
5326
5327 // Query
5328
5329 // Find a property `name` from `props`, returns `NULL` if not found.
5330 // Searches through `ufbx_props.defaults` as well.
5331 ufbx_abi ufbx_prop *ufbx_find_prop_len(const ufbx_props *props, const char *name, size_t name_len);
5332 ufbx_abi ufbx_prop *ufbx_find_prop(const ufbx_props *props, const char *name);
5333
5334 // Utility functions for finding the value of a property, returns `def` if not found.
5335 // NOTE: For `ufbx_string` you need to ensure the lifetime of the default is
5336 // sufficient as no copy is made.
5337 ufbx_abi ufbx_real ufbx_find_real_len(const ufbx_props *props, const char *name, size_t name_len, ufbx_real def);
5338 ufbx_abi ufbx_real ufbx_find_real(const ufbx_props *props, const char *name, ufbx_real def);
5339 ufbx_abi ufbx_vec3 ufbx_find_vec3_len(const ufbx_props *props, const char *name, size_t name_len, ufbx_vec3 def);
5340 ufbx_abi ufbx_vec3 ufbx_find_vec3(const ufbx_props *props, const char *name, ufbx_vec3 def);
5341 ufbx_abi int64_t ufbx_find_int_len(const ufbx_props *props, const char *name, size_t name_len, int64_t def);
5342 ufbx_abi int64_t ufbx_find_int(const ufbx_props *props, const char *name, int64_t def);
5343 ufbx_abi bool ufbx_find_bool_len(const ufbx_props *props, const char *name, size_t name_len, bool def);
5344 ufbx_abi bool ufbx_find_bool(const ufbx_props *props, const char *name, bool def);
5345 ufbx_abi ufbx_string ufbx_find_string_len(const ufbx_props *props, const char *name, size_t name_len, ufbx_string def);
5346 ufbx_abi ufbx_string ufbx_find_string(const ufbx_props *props, const char *name, ufbx_string def);
5347 ufbx_abi ufbx_blob ufbx_find_blob_len(const ufbx_props *props, const char *name, size_t name_len, ufbx_blob def);
5348 ufbx_abi ufbx_blob ufbx_find_blob(const ufbx_props *props, const char *name, ufbx_blob def);
5349
5350 // Find property in `props` with concatenated `parts[num_parts]`.
5351 ufbx_abi ufbx_prop *ufbx_find_prop_concat(const ufbx_props *props, const ufbx_string *parts, size_t num_parts);
5352
5353 // Get an element connected to a property.
5354 ufbx_abi ufbx_element *ufbx_get_prop_element(const ufbx_element *element, const ufbx_prop *prop, ufbx_element_type type);
5355
5356 // Find an element connected to a property by name.
5357 ufbx_abi ufbx_element *ufbx_find_prop_element_len(const ufbx_element *element, const char *name, size_t name_len, ufbx_element_type type);
5358 ufbx_abi ufbx_element *ufbx_find_prop_element(const ufbx_element *element, const char *name, ufbx_element_type type);
5359
5360 // Find any element of type `type` in `scene` by `name`.
5361 // For example if you want to find `ufbx_material` named `Mat`:
5362 // (ufbx_material*)ufbx_find_element(scene, UFBX_ELEMENT_MATERIAL, "Mat");
5363 ufbx_abi ufbx_element *ufbx_find_element_len(const ufbx_scene *scene, ufbx_element_type type, const char *name, size_t name_len);
5364 ufbx_abi ufbx_element *ufbx_find_element(const ufbx_scene *scene, ufbx_element_type type, const char *name);
5365
5366 // Find node in `scene` by `name` (shorthand for `ufbx_find_element(UFBX_ELEMENT_NODE)`).
5367 ufbx_abi ufbx_node *ufbx_find_node_len(const ufbx_scene *scene, const char *name, size_t name_len);
5368 ufbx_abi ufbx_node *ufbx_find_node(const ufbx_scene *scene, const char *name);
5369
5370 // Find an animation stack in `scene` by `name` (shorthand for `ufbx_find_element(UFBX_ELEMENT_ANIM_STACK)`)
5371 ufbx_abi ufbx_anim_stack *ufbx_find_anim_stack_len(const ufbx_scene *scene, const char *name, size_t name_len);
5372 ufbx_abi ufbx_anim_stack *ufbx_find_anim_stack(const ufbx_scene *scene, const char *name);
5373
5374 // Find a material in `scene` by `name` (shorthand for `ufbx_find_element(UFBX_ELEMENT_MATERIAL)`).
5375 ufbx_abi ufbx_material *ufbx_find_material_len(const ufbx_scene *scene, const char *name, size_t name_len);
5376 ufbx_abi ufbx_material *ufbx_find_material(const ufbx_scene *scene, const char *name);
5377
5378 // Find a single animated property `prop` of `element` in `layer`.
5379 // Returns `NULL` if not found.
5380 ufbx_abi ufbx_anim_prop *ufbx_find_anim_prop_len(const ufbx_anim_layer *layer, const ufbx_element *element, const char *prop, size_t prop_len);
5381 ufbx_abi ufbx_anim_prop *ufbx_find_anim_prop(const ufbx_anim_layer *layer, const ufbx_element *element, const char *prop);
5382
5383 // Find all animated properties of `element` in `layer`.
5384 ufbx_abi ufbx_anim_prop_list ufbx_find_anim_props(const ufbx_anim_layer *layer, const ufbx_element *element);
5385
5386 // Get a matrix that transforms normals in the same way as Autodesk software.
5387 // NOTE: The resulting normals are slightly incorrect as this function deliberately
5388 // inverts geometric transformation wrong. For better results use
5389 // `ufbx_matrix_for_normals(&node->geometry_to_world)`.
5390 ufbx_abi ufbx_matrix ufbx_get_compatible_matrix_for_normals(const ufbx_node *node);
5391
5392 // Utility
5393
5394 // Decompress a DEFLATE compressed buffer.
5395 // Returns the decompressed size or a negative error code (see source for details).
5396 // NOTE: You must supply a valid `retain` with `ufbx_inflate_retain.initialized == false`
5397 // but the rest can be uninitialized.
5398 ufbx_abi ptrdiff_t ufbx_inflate(void *dst, size_t dst_size, const ufbx_inflate_input *input, ufbx_inflate_retain *retain);
5399
5400 // Same as `ufbx_open_file()` but compatible with the callback in `ufbx_open_file_fn`.
5401 // The `user` parameter is actually not used here.
5402 ufbx_abi bool ufbx_default_open_file(void *user, ufbx_stream *stream, const char *path, size_t path_len, const ufbx_open_file_info *info);
5403
5404 // Open a `ufbx_stream` from a file.
5405 // Use `path_len == SIZE_MAX` for NULL terminated string.
5406 ufbx_abi bool ufbx_open_file(ufbx_stream *stream, const char *path, size_t path_len, const ufbx_open_file_opts *opts, ufbx_error *error);
5407 ufbx_unsafe ufbx_abi bool ufbx_open_file_ctx(ufbx_stream *stream, ufbx_open_file_context ctx, const char *path, size_t path_len, const ufbx_open_file_opts *opts, ufbx_error *error);
5408
5409 // NOTE: Uses the default ufbx allocator!
5410 ufbx_abi bool ufbx_open_memory(ufbx_stream *stream, const void *data, size_t data_size, const ufbx_open_memory_opts *opts, ufbx_error *error);
5411 ufbx_unsafe ufbx_abi bool ufbx_open_memory_ctx(ufbx_stream *stream, ufbx_open_file_context ctx, const void *data, size_t data_size, const ufbx_open_memory_opts *opts, ufbx_error *error);
5412
5413 // Animation evaluation
5414
5415 // Evaluate a single animation `curve` at a `time`.
5416 // Returns `default_value` only if `curve == NULL` or it has no keyframes.
5417 ufbx_abi ufbx_real ufbx_evaluate_curve(const ufbx_anim_curve *curve, double time, ufbx_real default_value);
5418 ufbx_abi ufbx_real ufbx_evaluate_curve_flags(const ufbx_anim_curve *curve, double time, ufbx_real default_value, uint32_t flags);
5419
5420 // Evaluate a value from bundled animation curves.
5421 ufbx_abi ufbx_real ufbx_evaluate_anim_value_real(const ufbx_anim_value *anim_value, double time);
5422 ufbx_abi ufbx_vec3 ufbx_evaluate_anim_value_vec3(const ufbx_anim_value *anim_value, double time);
5423 ufbx_abi ufbx_real ufbx_evaluate_anim_value_real_flags(const ufbx_anim_value *anim_value, double time, uint32_t flags);
5424 ufbx_abi ufbx_vec3 ufbx_evaluate_anim_value_vec3_flags(const ufbx_anim_value *anim_value, double time, uint32_t flags);
5425
5426 // Evaluate an animated property `name` from `element` at `time`.
5427 // NOTE: If the property is not found it will have the flag `UFBX_PROP_FLAG_NOT_FOUND`.
5428 ufbx_abi ufbx_prop ufbx_evaluate_prop_len(const ufbx_anim *anim, const ufbx_element *element, const char *name, size_t name_len, double time);
5429 ufbx_abi ufbx_prop ufbx_evaluate_prop(const ufbx_anim *anim, const ufbx_element *element, const char *name, double time);
5430 ufbx_abi ufbx_prop ufbx_evaluate_prop_len_flags(const ufbx_anim *anim, const ufbx_element *element, const char *name, size_t name_len, double time, uint32_t flags);
5431 ufbx_abi ufbx_prop ufbx_evaluate_prop_flags(const ufbx_anim *anim, const ufbx_element *element, const char *name, double time, uint32_t flags);
5432
5433 // Evaluate all _animated_ properties of `element`.
5434 // HINT: This function returns an `ufbx_props` structure with the original properties as
5435 // `ufbx_props.defaults`. This lets you use `ufbx_find_prop/value()` for the results.
5436 ufbx_abi ufbx_props ufbx_evaluate_props(const ufbx_anim *anim, const ufbx_element *element, double time, ufbx_prop *buffer, size_t buffer_size);
5437 ufbx_abi ufbx_props ufbx_evaluate_props_flags(const ufbx_anim *anim, const ufbx_element *element, double time, ufbx_prop *buffer, size_t buffer_size, uint32_t flags);
5438
5439 // Flags to control `ufbx_evaluate_transform_flags()`.
5440 typedef enum ufbx_transform_flags UFBX_FLAG_REPR {
5441
5442 // Ignore parent scale helper.
5443 UFBX_TRANSFORM_FLAG_IGNORE_SCALE_HELPER = 0x1,
5444
5445 // Ignore componentwise scale.
5446 // Note that if you don't specify this, ufbx will have to potentially
5447 // evaluate the entire parent chain in the worst case.
5448 UFBX_TRANSFORM_FLAG_IGNORE_COMPONENTWISE_SCALE = 0x2,
5449
5450 // Require explicit components
5451 UFBX_TRANSFORM_FLAG_EXPLICIT_INCLUDES = 0x4,
5452
5453 // If `UFBX_TRANSFORM_FLAG_EXPLICIT_INCLUDES`: Evaluate `ufbx_transform.translation`.
5454 UFBX_TRANSFORM_FLAG_INCLUDE_TRANSLATION = 0x10,
5455 // If `UFBX_TRANSFORM_FLAG_EXPLICIT_INCLUDES`: Evaluate `ufbx_transform.rotation`.
5456 UFBX_TRANSFORM_FLAG_INCLUDE_ROTATION = 0x20,
5457 // If `UFBX_TRANSFORM_FLAG_EXPLICIT_INCLUDES`: Evaluate `ufbx_transform.scale`.
5458 UFBX_TRANSFORM_FLAG_INCLUDE_SCALE = 0x40,
5459
5460 // Do not extrapolate keyframes.
5461 // See `UFBX_EVALUATE_FLAG_NO_EXTRAPOLATION`.
5462 UFBX_TRANSFORM_FLAG_NO_EXTRAPOLATION = 0x80,
5463
5464 UFBX_FLAG_FORCE_WIDTH(UFBX_TRANSFORM_FLAGS)
5465 } ufbx_transform_flags;
5466
5467 // Evaluate the animated transform of a node given a time.
5468 // The returned transform is the local transform of the node (ie. relative to the parent),
5469 // comparable to `ufbx_node.local_transform`.
5470 ufbx_abi ufbx_transform ufbx_evaluate_transform(const ufbx_anim *anim, const ufbx_node *node, double time);
5471 ufbx_abi ufbx_transform ufbx_evaluate_transform_flags(const ufbx_anim *anim, const ufbx_node *node, double time, uint32_t flags);
5472
5473 // Evaluate the blend shape weight of a blend channel.
5474 // NOTE: Return value uses `1.0` for full weight, instead of `100.0` that the internal property `UFBX_Weight` uses.
5475 ufbx_abi ufbx_real ufbx_evaluate_blend_weight(const ufbx_anim *anim, const ufbx_blend_channel *channel, double time);
5476 ufbx_abi ufbx_real ufbx_evaluate_blend_weight_flags(const ufbx_anim *anim, const ufbx_blend_channel *channel, double time, uint32_t flags);
5477
5478 // Evaluate the whole `scene` at a specific `time` in the animation `anim`.
5479 // The returned scene behaves as if it had been exported at a specific time
5480 // in the specified animation, except that animated elements' properties contain
5481 // only the animated values, the original ones are in `props->defaults`.
5482 //
5483 // NOTE: The returned scene refers to the original `scene` so the original
5484 // scene cannot be freed until all evaluated scenes are freed.
5485 ufbx_abi ufbx_scene *ufbx_evaluate_scene(const ufbx_scene *scene, const ufbx_anim *anim, double time, const ufbx_evaluate_opts *opts, ufbx_error *error);
5486
5487 // Create a custom animation descriptor.
5488 // `ufbx_anim_opts` is used to specify animation layers and weights.
5489 // HINT: You can also leave `ufbx_anim_opts.layer_ids[]` empty and only specify
5490 // overrides to evaluate the scene with different properties or local transforms.
5491 ufbx_abi ufbx_anim *ufbx_create_anim(const ufbx_scene *scene, const ufbx_anim_opts *opts, ufbx_error *error);
5492
5493 // Free an animation returned by `ufbx_create_anim()`.
5494 ufbx_abi void ufbx_free_anim(ufbx_anim *anim);
5495
5496 // Increase the animation reference count.
5497 ufbx_abi void ufbx_retain_anim(ufbx_anim *anim);
5498
5499 // Animation baking
5500
5501 // "Bake" an animation to linearly interpolated keyframes.
5502 // Composites the FBX transformation chain into quaternion rotations.
5503 ufbx_abi ufbx_baked_anim *ufbx_bake_anim(const ufbx_scene *scene, const ufbx_anim *anim, const ufbx_bake_opts *opts, ufbx_error *error);
5504
5505 ufbx_abi void ufbx_retain_baked_anim(ufbx_baked_anim *bake);
5506 ufbx_abi void ufbx_free_baked_anim(ufbx_baked_anim *bake);
5507
5508 ufbx_abi ufbx_baked_node *ufbx_find_baked_node_by_typed_id(ufbx_baked_anim *bake, uint32_t typed_id);
5509 ufbx_abi ufbx_baked_node *ufbx_find_baked_node(ufbx_baked_anim *bake, ufbx_node *node);
5510
5511 ufbx_abi ufbx_baked_element *ufbx_find_baked_element_by_element_id(ufbx_baked_anim *bake, uint32_t element_id);
5512 ufbx_abi ufbx_baked_element *ufbx_find_baked_element(ufbx_baked_anim *bake, ufbx_element *element);
5513
5514 // Evaluate baked animation `keyframes` at `time`.
5515 // Internally linearly interpolates between two adjacent keyframes.
5516 // Handles stepped tangents cleanly, which is not strictly necessary for custom interpolation.
5517 ufbx_abi ufbx_vec3 ufbx_evaluate_baked_vec3(ufbx_baked_vec3_list keyframes, double time);
5518
5519 // Evaluate baked animation `keyframes` at `time`.
5520 // Internally spherically interpolates (`ufbx_quat_slerp()`) between two adjacent keyframes.
5521 // Handles stepped tangents cleanly, which is not strictly necessary for custom interpolation.
5522 ufbx_abi ufbx_quat ufbx_evaluate_baked_quat(ufbx_baked_quat_list keyframes, double time);
5523
5524 // Poses
5525
5526 // Retrieve the bone pose for `node`.
5527 // Returns `NULL` if the pose does not contain `node`.
5528 ufbx_abi ufbx_bone_pose *ufbx_get_bone_pose(const ufbx_pose *pose, const ufbx_node *node);
5529
5530 // Materials
5531
5532 // Find a texture for a given material FBX property.
5533 ufbx_abi ufbx_texture *ufbx_find_prop_texture_len(const ufbx_material *material, const char *name, size_t name_len);
5534 ufbx_abi ufbx_texture *ufbx_find_prop_texture(const ufbx_material *material, const char *name);
5535
5536 // Find a texture for a given shader property.
5537 ufbx_abi ufbx_string ufbx_find_shader_prop_len(const ufbx_shader *shader, const char *name, size_t name_len);
5538 ufbx_abi ufbx_string ufbx_find_shader_prop(const ufbx_shader *shader, const char *name);
5539
5540 // Map from a shader property to material property.
5541 ufbx_abi ufbx_shader_prop_binding_list ufbx_find_shader_prop_bindings_len(const ufbx_shader *shader, const char *name, size_t name_len);
5542 ufbx_abi ufbx_shader_prop_binding_list ufbx_find_shader_prop_bindings(const ufbx_shader *shader, const char *name);
5543
5544 // Find an input in a shader texture.
5545 ufbx_abi ufbx_shader_texture_input *ufbx_find_shader_texture_input_len(const ufbx_shader_texture *shader, const char *name, size_t name_len);
5546 ufbx_abi ufbx_shader_texture_input *ufbx_find_shader_texture_input(const ufbx_shader_texture *shader, const char *name);
5547
5548 // Math
5549
5550 // Returns `true` if `axes` forms a valid coordinate space.
5551 ufbx_abi bool ufbx_coordinate_axes_valid(ufbx_coordinate_axes axes);
5552
5553 // Vector math utility functions.
5554 ufbx_abi ufbx_vec3 ufbx_vec3_normalize(ufbx_vec3 v);
5555
5556 // Quaternion math utility functions.
5557 ufbx_abi ufbx_real ufbx_quat_dot(ufbx_quat a, ufbx_quat b);
5558 ufbx_abi ufbx_quat ufbx_quat_mul(ufbx_quat a, ufbx_quat b);
5559 ufbx_abi ufbx_quat ufbx_quat_normalize(ufbx_quat q);
5560 ufbx_abi ufbx_quat ufbx_quat_fix_antipodal(ufbx_quat q, ufbx_quat reference);
5561 ufbx_abi ufbx_quat ufbx_quat_slerp(ufbx_quat a, ufbx_quat b, ufbx_real t);
5562 ufbx_abi ufbx_vec3 ufbx_quat_rotate_vec3(ufbx_quat q, ufbx_vec3 v);
5563 ufbx_abi ufbx_vec3 ufbx_quat_to_euler(ufbx_quat q, ufbx_rotation_order order);
5564 ufbx_abi ufbx_quat ufbx_euler_to_quat(ufbx_vec3 v, ufbx_rotation_order order);
5565
5566 // Matrix math utility functions.
5567 ufbx_abi ufbx_matrix ufbx_matrix_mul(const ufbx_matrix *a, const ufbx_matrix *b);
5568 ufbx_abi ufbx_real ufbx_matrix_determinant(const ufbx_matrix *m);
5569 ufbx_abi ufbx_matrix ufbx_matrix_invert(const ufbx_matrix *m);
5570
5571 // Get a matrix that can be used to transform geometry normals.
5572 // NOTE: You must normalize the normals after transforming them with this matrix,
5573 // eg. using `ufbx_vec3_normalize()`.
5574 // NOTE: This function flips the normals if the determinant is negative.
5575 ufbx_abi ufbx_matrix ufbx_matrix_for_normals(const ufbx_matrix *m);
5576
5577 // Matrix transformation utilities.
5578 ufbx_abi ufbx_vec3 ufbx_transform_position(const ufbx_matrix *m, ufbx_vec3 v);
5579 ufbx_abi ufbx_vec3 ufbx_transform_direction(const ufbx_matrix *m, ufbx_vec3 v);
5580
5581 // Conversions between `ufbx_matrix` and `ufbx_transform`.
5582 ufbx_abi ufbx_matrix ufbx_transform_to_matrix(const ufbx_transform *t);
5583 ufbx_abi ufbx_transform ufbx_matrix_to_transform(const ufbx_matrix *m);
5584
5585 // Skinning
5586
5587 // Get a matrix representing the deformation for a single vertex.
5588 // Returns `fallback` if the vertex is not skinned.
5589 ufbx_abi ufbx_matrix ufbx_catch_get_skin_vertex_matrix(ufbx_panic *panic, const ufbx_skin_deformer *skin, size_t vertex, const ufbx_matrix *fallback);
5590 ufbx_inline ufbx_matrix ufbx_get_skin_vertex_matrix(const ufbx_skin_deformer *skin, size_t vertex, const ufbx_matrix *fallback) {
5591 return ufbx_catch_get_skin_vertex_matrix(NULL, skin, vertex, fallback);
5592 }
5593
5594 // Resolve the index into `ufbx_blend_shape.position_offsets[]` given a vertex.
5595 // Returns `UFBX_NO_INDEX` if the vertex is not included in the blend shape.
5596 ufbx_abi uint32_t ufbx_get_blend_shape_offset_index(const ufbx_blend_shape *shape, size_t vertex);
5597
5598 // Get the offset for a given vertex in the blend shape.
5599 // Returns `ufbx_zero_vec3` if the vertex is not a included in the blend shape.
5600 ufbx_abi ufbx_vec3 ufbx_get_blend_shape_vertex_offset(const ufbx_blend_shape *shape, size_t vertex);
5601
5602 // Get the _current_ blend offset given a blend deformer.
5603 // NOTE: This depends on the current animated blend weight of the deformer.
5604 ufbx_abi ufbx_vec3 ufbx_get_blend_vertex_offset(const ufbx_blend_deformer *blend, size_t vertex);
5605
5606 // Apply the blend shape with `weight` to given vertices.
5607 ufbx_abi void ufbx_add_blend_shape_vertex_offsets(const ufbx_blend_shape *shape, ufbx_vec3 *vertices, size_t num_vertices, ufbx_real weight);
5608
5609 // Apply the blend deformer with `weight` to given vertices.
5610 // NOTE: This depends on the current animated blend weight of the deformer.
5611 ufbx_abi void ufbx_add_blend_vertex_offsets(const ufbx_blend_deformer *blend, ufbx_vec3 *vertices, size_t num_vertices, ufbx_real weight);
5612
5613 // Curves/surfaces
5614
5615 // Low-level utility to evaluate NURBS the basis functions.
5616 ufbx_abi size_t ufbx_evaluate_nurbs_basis(const ufbx_nurbs_basis *basis, ufbx_real u, ufbx_real *weights, size_t num_weights, ufbx_real *derivatives, size_t num_derivatives);
5617
5618 // Evaluate a point on a NURBS curve given the parameter `u`.
5619 ufbx_abi ufbx_curve_point ufbx_evaluate_nurbs_curve(const ufbx_nurbs_curve *curve, ufbx_real u);
5620
5621 // Evaluate a point on a NURBS surface given the parameter `u` and `v`.
5622 ufbx_abi ufbx_surface_point ufbx_evaluate_nurbs_surface(const ufbx_nurbs_surface *surface, ufbx_real u, ufbx_real v);
5623
5624 // Tessellate a NURBS curve into a polyline.
5625 ufbx_abi ufbx_line_curve *ufbx_tessellate_nurbs_curve(const ufbx_nurbs_curve *curve, const ufbx_tessellate_curve_opts *opts, ufbx_error *error);
5626
5627 // Tessellate a NURBS surface into a mesh.
5628 ufbx_abi ufbx_mesh *ufbx_tessellate_nurbs_surface(const ufbx_nurbs_surface *surface, const ufbx_tessellate_surface_opts *opts, ufbx_error *error);
5629
5630 // Free a line returned by `ufbx_tessellate_nurbs_curve()`.
5631 ufbx_abi void ufbx_free_line_curve(ufbx_line_curve *curve);
5632
5633 // Increase the refcount of the line.
5634 ufbx_abi void ufbx_retain_line_curve(ufbx_line_curve *curve);
5635
5636 // Mesh Topology
5637
5638 // Find the face that contains a given `index`.
5639 // Returns `UFBX_NO_INDEX` if out of bounds.
5640 ufbx_abi uint32_t ufbx_find_face_index(ufbx_mesh *mesh, size_t index);
5641
5642 // Triangulate a mesh face, returning the number of triangles.
5643 // NOTE: You need to space for `(face.num_indices - 2) * 3 - 1` indices!
5644 // HINT: Using `ufbx_mesh.max_face_triangles * 3` is always safe.
5645 ufbx_abi uint32_t ufbx_catch_triangulate_face(ufbx_panic *panic, uint32_t *indices, size_t num_indices, const ufbx_mesh *mesh, ufbx_face face);
5646 ufbx_abi uint32_t ufbx_triangulate_face(uint32_t *indices, size_t num_indices, const ufbx_mesh *mesh, ufbx_face face);
5647
5648 // Generate the half-edge representation of `mesh` to `topo[mesh->num_indices]`
5649 ufbx_abi void ufbx_catch_compute_topology(ufbx_panic *panic, const ufbx_mesh *mesh, ufbx_topo_edge *topo, size_t num_topo);
5650 ufbx_abi void ufbx_compute_topology(const ufbx_mesh *mesh, ufbx_topo_edge *topo, size_t num_topo);
5651
5652 // Get the next/previous edge around a vertex
5653 // NOTE: Does not return the half-edge on the opposite side (ie. `topo[index].twin`)
5654
5655 // Get the next half-edge in `topo`.
5656 ufbx_abi uint32_t ufbx_catch_topo_next_vertex_edge(ufbx_panic *panic, const ufbx_topo_edge *topo, size_t num_topo, uint32_t index);
5657 ufbx_abi uint32_t ufbx_topo_next_vertex_edge(const ufbx_topo_edge *topo, size_t num_topo, uint32_t index);
5658
5659 // Get the previous half-edge in `topo`.
5660 ufbx_abi uint32_t ufbx_catch_topo_prev_vertex_edge(ufbx_panic *panic, const ufbx_topo_edge *topo, size_t num_topo, uint32_t index);
5661 ufbx_abi uint32_t ufbx_topo_prev_vertex_edge(const ufbx_topo_edge *topo, size_t num_topo, uint32_t index);
5662
5663 // Calculate a normal for a given face.
5664 // The returned normal is weighted by face area.
5665 ufbx_abi ufbx_vec3 ufbx_catch_get_weighted_face_normal(ufbx_panic *panic, const ufbx_vertex_vec3 *positions, ufbx_face face);
5666 ufbx_abi ufbx_vec3 ufbx_get_weighted_face_normal(const ufbx_vertex_vec3 *positions, ufbx_face face);
5667
5668 // Generate indices for normals from the topology.
5669 // Respects smoothing groups.
5670 ufbx_abi size_t ufbx_catch_generate_normal_mapping(ufbx_panic *panic, const ufbx_mesh *mesh,
5671 const ufbx_topo_edge *topo, size_t num_topo,
5672 uint32_t *normal_indices, size_t num_normal_indices, bool assume_smooth);
5673 ufbx_abi size_t ufbx_generate_normal_mapping(const ufbx_mesh *mesh,
5674 const ufbx_topo_edge *topo, size_t num_topo,
5675 uint32_t *normal_indices, size_t num_normal_indices, bool assume_smooth);
5676
5677 // Compute normals given normal indices.
5678 // You can use `ufbx_generate_normal_mapping()` to generate the normal indices.
5679 ufbx_abi void ufbx_catch_compute_normals(ufbx_panic *panic, const ufbx_mesh *mesh, const ufbx_vertex_vec3 *positions,
5680 const uint32_t *normal_indices, size_t num_normal_indices,
5681 ufbx_vec3 *normals, size_t num_normals);
5682 ufbx_abi void ufbx_compute_normals(const ufbx_mesh *mesh, const ufbx_vertex_vec3 *positions,
5683 const uint32_t *normal_indices, size_t num_normal_indices,
5684 ufbx_vec3 *normals, size_t num_normals);
5685
5686 // Subdivide a mesh using the Catmull-Clark subdivision `level` times.
5687 ufbx_abi ufbx_mesh *ufbx_subdivide_mesh(const ufbx_mesh *mesh, size_t level, const ufbx_subdivide_opts *opts, ufbx_error *error);
5688
5689 // Free a mesh returned from `ufbx_subdivide_mesh()` or `ufbx_tessellate_nurbs_surface()`.
5690 ufbx_abi void ufbx_free_mesh(ufbx_mesh *mesh);
5691
5692 // Increase the mesh reference count.
5693 ufbx_abi void ufbx_retain_mesh(ufbx_mesh *mesh);
5694
5695 // Geometry caches
5696
5697 // Load geometry cache information from a file.
5698 // As geometry caches can be massive, this does not actually read the data, but
5699 // only seeks through the files to form the metadata.
5700 ufbx_abi ufbx_geometry_cache *ufbx_load_geometry_cache(
5701 const char *filename,
5702 const ufbx_geometry_cache_opts *opts, ufbx_error *error);
5703 ufbx_abi ufbx_geometry_cache *ufbx_load_geometry_cache_len(
5704 const char *filename, size_t filename_len,
5705 const ufbx_geometry_cache_opts *opts, ufbx_error *error);
5706
5707 // Free a geometry cache returned from `ufbx_load_geometry_cache()`.
5708 ufbx_abi void ufbx_free_geometry_cache(ufbx_geometry_cache *cache);
5709 // Increase the geometry cache reference count.
5710 ufbx_abi void ufbx_retain_geometry_cache(ufbx_geometry_cache *cache);
5711
5712 // Read a frame from a geometry cache.
5713 ufbx_abi size_t ufbx_read_geometry_cache_real(const ufbx_cache_frame *frame, ufbx_real *data, size_t num_data, const ufbx_geometry_cache_data_opts *opts);
5714 ufbx_abi size_t ufbx_read_geometry_cache_vec3(const ufbx_cache_frame *frame, ufbx_vec3 *data, size_t num_data, const ufbx_geometry_cache_data_opts *opts);
5715 // Sample the a geometry cache channel, linearly blending between adjacent frames.
5716 ufbx_abi size_t ufbx_sample_geometry_cache_real(const ufbx_cache_channel *channel, double time, ufbx_real *data, size_t num_data, const ufbx_geometry_cache_data_opts *opts);
5717 ufbx_abi size_t ufbx_sample_geometry_cache_vec3(const ufbx_cache_channel *channel, double time, ufbx_vec3 *data, size_t num_data, const ufbx_geometry_cache_data_opts *opts);
5718
5719 // DOM
5720
5721 // Find a DOM node given a name.
5722 ufbx_abi ufbx_dom_node *ufbx_dom_find_len(const ufbx_dom_node *parent, const char *name, size_t name_len);
5723 ufbx_abi ufbx_dom_node *ufbx_dom_find(const ufbx_dom_node *parent, const char *name);
5724
5725 // Utility
5726
5727 // Generate an index buffer for a flat vertex buffer.
5728 // `streams` specifies one or more vertex data arrays, each stream must contain `num_indices` vertices.
5729 // This function compacts the data within `streams` in-place, writing the deduplicated indices to `indices`.
5730 ufbx_abi size_t ufbx_generate_indices(const ufbx_vertex_stream *streams, size_t num_streams, uint32_t *indices, size_t num_indices, const ufbx_allocator_opts *allocator, ufbx_error *error);
5731
5732 // Thread pool
5733
5734 // Run a single thread pool task.
5735 // See `ufbx_thread_pool_run_fn` for more information.
5736 ufbx_unsafe ufbx_abi void ufbx_thread_pool_run_task(ufbx_thread_pool_context ctx, uint32_t index);
5737
5738 // Get or set an arbitrary user pointer for the thread pool context.
5739 // `ufbx_thread_pool_get_user_ptr()` returns `NULL` if unset.
5740 ufbx_unsafe ufbx_abi void ufbx_thread_pool_set_user_ptr(ufbx_thread_pool_context ctx, void *user_ptr);
5741 ufbx_unsafe ufbx_abi void *ufbx_thread_pool_get_user_ptr(ufbx_thread_pool_context ctx);
5742
5743 // -- Inline API
5744
5745 // Utility functions for reading geometry data for a single index.
5746 ufbx_abi ufbx_real ufbx_catch_get_vertex_real(ufbx_panic *panic, const ufbx_vertex_real *v, size_t index);
5747 ufbx_abi ufbx_vec2 ufbx_catch_get_vertex_vec2(ufbx_panic *panic, const ufbx_vertex_vec2 *v, size_t index);
5748 ufbx_abi ufbx_vec3 ufbx_catch_get_vertex_vec3(ufbx_panic *panic, const ufbx_vertex_vec3 *v, size_t index);
5749 ufbx_abi ufbx_vec4 ufbx_catch_get_vertex_vec4(ufbx_panic *panic, const ufbx_vertex_vec4 *v, size_t index);
5750
5751 // Utility functions for reading geometry data for a single index.
5752 ufbx_inline ufbx_real ufbx_get_vertex_real(const ufbx_vertex_real *v, size_t index) { ufbx_assert(index < v->indices.count); return v->values.data[(int32_t)v->indices.data[index]]; }
5753 ufbx_inline ufbx_vec2 ufbx_get_vertex_vec2(const ufbx_vertex_vec2 *v, size_t index) { ufbx_assert(index < v->indices.count); return v->values.data[(int32_t)v->indices.data[index]]; }
5754 ufbx_inline ufbx_vec3 ufbx_get_vertex_vec3(const ufbx_vertex_vec3 *v, size_t index) { ufbx_assert(index < v->indices.count); return v->values.data[(int32_t)v->indices.data[index]]; }
5755 ufbx_inline ufbx_vec4 ufbx_get_vertex_vec4(const ufbx_vertex_vec4 *v, size_t index) { ufbx_assert(index < v->indices.count); return v->values.data[(int32_t)v->indices.data[index]]; }
5756
5757 ufbx_abi ufbx_real ufbx_catch_get_vertex_w_vec3(ufbx_panic *panic, const ufbx_vertex_vec3 *v, size_t index);
5758 ufbx_inline ufbx_real ufbx_get_vertex_w_vec3(const ufbx_vertex_vec3 *v, size_t index) { ufbx_assert(index < v->indices.count); return v->values_w.count > 0 ? v->values_w.data[(int32_t)v->indices.data[index]] : 0.0f; }
5759
5760 // Functions for converting an untyped `ufbx_element` to a concrete type.
5761 // Returns `NULL` if the element is not that type.
5762 ufbx_abi ufbx_unknown *ufbx_as_unknown(const ufbx_element *element);
5763 ufbx_abi ufbx_node *ufbx_as_node(const ufbx_element *element);
5764 ufbx_abi ufbx_mesh *ufbx_as_mesh(const ufbx_element *element);
5765 ufbx_abi ufbx_light *ufbx_as_light(const ufbx_element *element);
5766 ufbx_abi ufbx_camera *ufbx_as_camera(const ufbx_element *element);
5767 ufbx_abi ufbx_bone *ufbx_as_bone(const ufbx_element *element);
5768 ufbx_abi ufbx_empty *ufbx_as_empty(const ufbx_element *element);
5769 ufbx_abi ufbx_line_curve *ufbx_as_line_curve(const ufbx_element *element);
5770 ufbx_abi ufbx_nurbs_curve *ufbx_as_nurbs_curve(const ufbx_element *element);
5771 ufbx_abi ufbx_nurbs_surface *ufbx_as_nurbs_surface(const ufbx_element *element);
5772 ufbx_abi ufbx_nurbs_trim_surface *ufbx_as_nurbs_trim_surface(const ufbx_element *element);
5773 ufbx_abi ufbx_nurbs_trim_boundary *ufbx_as_nurbs_trim_boundary(const ufbx_element *element);
5774 ufbx_abi ufbx_procedural_geometry *ufbx_as_procedural_geometry(const ufbx_element *element);
5775 ufbx_abi ufbx_stereo_camera *ufbx_as_stereo_camera(const ufbx_element *element);
5776 ufbx_abi ufbx_camera_switcher *ufbx_as_camera_switcher(const ufbx_element *element);
5777 ufbx_abi ufbx_marker *ufbx_as_marker(const ufbx_element *element);
5778 ufbx_abi ufbx_lod_group *ufbx_as_lod_group(const ufbx_element *element);
5779 ufbx_abi ufbx_skin_deformer *ufbx_as_skin_deformer(const ufbx_element *element);
5780 ufbx_abi ufbx_skin_cluster *ufbx_as_skin_cluster(const ufbx_element *element);
5781 ufbx_abi ufbx_blend_deformer *ufbx_as_blend_deformer(const ufbx_element *element);
5782 ufbx_abi ufbx_blend_channel *ufbx_as_blend_channel(const ufbx_element *element);
5783 ufbx_abi ufbx_blend_shape *ufbx_as_blend_shape(const ufbx_element *element);
5784 ufbx_abi ufbx_cache_deformer *ufbx_as_cache_deformer(const ufbx_element *element);
5785 ufbx_abi ufbx_cache_file *ufbx_as_cache_file(const ufbx_element *element);
5786 ufbx_abi ufbx_material *ufbx_as_material(const ufbx_element *element);
5787 ufbx_abi ufbx_texture *ufbx_as_texture(const ufbx_element *element);
5788 ufbx_abi ufbx_video *ufbx_as_video(const ufbx_element *element);
5789 ufbx_abi ufbx_shader *ufbx_as_shader(const ufbx_element *element);
5790 ufbx_abi ufbx_shader_binding *ufbx_as_shader_binding(const ufbx_element *element);
5791 ufbx_abi ufbx_anim_stack *ufbx_as_anim_stack(const ufbx_element *element);
5792 ufbx_abi ufbx_anim_layer *ufbx_as_anim_layer(const ufbx_element *element);
5793 ufbx_abi ufbx_anim_value *ufbx_as_anim_value(const ufbx_element *element);
5794 ufbx_abi ufbx_anim_curve *ufbx_as_anim_curve(const ufbx_element *element);
5795 ufbx_abi ufbx_display_layer *ufbx_as_display_layer(const ufbx_element *element);
5796 ufbx_abi ufbx_selection_set *ufbx_as_selection_set(const ufbx_element *element);
5797 ufbx_abi ufbx_selection_node *ufbx_as_selection_node(const ufbx_element *element);
5798 ufbx_abi ufbx_character *ufbx_as_character(const ufbx_element *element);
5799 ufbx_abi ufbx_constraint *ufbx_as_constraint(const ufbx_element *element);
5800 ufbx_abi ufbx_audio_layer *ufbx_as_audio_layer(const ufbx_element *element);
5801 ufbx_abi ufbx_audio_clip *ufbx_as_audio_clip(const ufbx_element *element);
5802 ufbx_abi ufbx_pose *ufbx_as_pose(const ufbx_element *element);
5803 ufbx_abi ufbx_metadata_object *ufbx_as_metadata_object(const ufbx_element *element);
5804
5805 // Functions for interfacing with DOM lists
5806 ufbx_abi bool ufbx_dom_is_array(const ufbx_dom_node *node);
5807 ufbx_abi size_t ufbx_dom_array_size(const ufbx_dom_node *node);
5808 ufbx_abi ufbx_int32_list ufbx_dom_as_int32_list(const ufbx_dom_node *node);
5809 ufbx_abi ufbx_int64_list ufbx_dom_as_int64_list(const ufbx_dom_node *node);
5810 ufbx_abi ufbx_float_list ufbx_dom_as_float_list(const ufbx_dom_node *node);
5811 ufbx_abi ufbx_double_list ufbx_dom_as_double_list(const ufbx_dom_node *node);
5812 ufbx_abi ufbx_real_list ufbx_dom_as_real_list(const ufbx_dom_node *node);
5813 ufbx_abi ufbx_blob_list ufbx_dom_as_blob_list(const ufbx_dom_node *node);
5814
5815 #ifdef __cplusplus
5816 }
5817 #endif
5818
5819 // bindgen-disable
5820
5821 #if UFBX_CPP11
5822
5823 struct ufbx_string_view {
5824 const char *data;
5825 size_t length;
5826
5827 ufbx_string_view() : data(nullptr), length(0) { }
5828 ufbx_string_view(const char *data_, size_t length_) : data(data_), length(length_) { }
5829 UFBX_CONVERSION_TO_IMPL(ufbx_string_view)
5830 };
5831
5832 ufbx_inline ufbx_scene *ufbx_load_file(ufbx_string_view filename, const ufbx_load_opts *opts, ufbx_error *error) { return ufbx_load_file_len(filename.data, filename.length, opts, error); }
5833 ufbx_inline ufbx_prop *ufbx_find_prop(const ufbx_props *props, ufbx_string_view name) { return ufbx_find_prop_len(props, name.data, name.length); }
5834 ufbx_inline ufbx_real ufbx_find_real(const ufbx_props *props, ufbx_string_view name, ufbx_real def) { return ufbx_find_real_len(props, name.data, name.length, def); }
5835 ufbx_inline ufbx_vec3 ufbx_find_vec3(const ufbx_props *props, ufbx_string_view name, ufbx_vec3 def) { return ufbx_find_vec3_len(props, name.data, name.length, def); }
5836 ufbx_inline int64_t ufbx_find_int(const ufbx_props *props, ufbx_string_view name, int64_t def) { return ufbx_find_int_len(props, name.data, name.length, def); }
5837 ufbx_inline bool ufbx_find_bool(const ufbx_props *props, ufbx_string_view name, bool def) { return ufbx_find_bool_len(props, name.data, name.length, def); }
5838 ufbx_inline ufbx_string ufbx_find_string(const ufbx_props *props, ufbx_string_view name, ufbx_string def) { return ufbx_find_string_len(props, name.data, name.length, def); }
5839 ufbx_inline ufbx_blob ufbx_find_blob(const ufbx_props *props, ufbx_string_view name, ufbx_blob def) { return ufbx_find_blob_len(props, name.data, name.length, def); }
5840 ufbx_inline ufbx_element *ufbx_find_prop_element(const ufbx_element *element, ufbx_string_view name, ufbx_element_type type) { return ufbx_find_prop_element_len(element, name.data, name.length, type); }
5841 ufbx_inline ufbx_element *ufbx_find_element(const ufbx_scene *scene, ufbx_element_type type, ufbx_string_view name) { return ufbx_find_element_len(scene, type, name.data, name.length); }
5842 ufbx_inline ufbx_node *ufbx_find_node(const ufbx_scene *scene, ufbx_string_view name) { return ufbx_find_node_len(scene, name.data, name.length); }
5843 ufbx_inline ufbx_anim_stack *ufbx_find_anim_stack(const ufbx_scene *scene, ufbx_string_view name) { return ufbx_find_anim_stack_len(scene, name.data, name.length); }
5844 ufbx_inline ufbx_material *ufbx_find_material(const ufbx_scene *scene, ufbx_string_view name) { return ufbx_find_material_len(scene, name.data, name.length); }
5845 ufbx_inline ufbx_anim_prop *ufbx_find_anim_prop(const ufbx_anim_layer *layer, const ufbx_element *element, ufbx_string_view prop) { return ufbx_find_anim_prop_len(layer, element, prop.data, prop.length); }
5846 ufbx_inline ufbx_prop ufbx_evaluate_prop(const ufbx_anim *anim, const ufbx_element *element, ufbx_string_view name, double time) { return ufbx_evaluate_prop_len(anim, element, name.data, name.length, time); }
5847 ufbx_inline ufbx_texture *ufbx_find_prop_texture(const ufbx_material *material, ufbx_string_view name) { return ufbx_find_prop_texture_len(material, name.data, name.length); }
5848 ufbx_inline ufbx_string ufbx_find_shader_prop(const ufbx_shader *shader, ufbx_string_view name) { return ufbx_find_shader_prop_len(shader, name.data, name.length); }
5849 ufbx_inline ufbx_shader_prop_binding_list ufbx_find_shader_prop_bindings(const ufbx_shader *shader, ufbx_string_view name) { return ufbx_find_shader_prop_bindings_len(shader, name.data, name.length); }
5850 ufbx_inline ufbx_shader_texture_input *ufbx_find_shader_texture_input(const ufbx_shader_texture *shader, ufbx_string_view name) { return ufbx_find_shader_texture_input_len(shader, name.data, name.length); }
5851 ufbx_inline ufbx_geometry_cache *ufbx_load_geometry_cache(ufbx_string_view filename, const ufbx_geometry_cache_opts *opts, ufbx_error *error) { return ufbx_load_geometry_cache_len(filename.data, filename.length, opts, error); }
5852 ufbx_inline ufbx_dom_node *ufbx_dom_find(const ufbx_dom_node *parent, ufbx_string_view name) { return ufbx_dom_find_len(parent, name.data, name.length); }
5853
5854 #endif
5855
5856 #if UFBX_CPP11
5857
5858 template <typename T>
5859 struct ufbx_type_traits { enum { valid = 0 }; };
5860
5861 template<> struct ufbx_type_traits<ufbx_scene> {
5862 enum { valid = 1 };
5863 static void retain(ufbx_scene *ptr) { ufbx_retain_scene(ptr); }
5864 static void free(ufbx_scene *ptr) { ufbx_free_scene(ptr); }
5865 };
5866
5867 template<> struct ufbx_type_traits<ufbx_mesh> {
5868 enum { valid = 1 };
5869 static void retain(ufbx_mesh *ptr) { ufbx_retain_mesh(ptr); }
5870 static void free(ufbx_mesh *ptr) { ufbx_free_mesh(ptr); }
5871 };
5872
5873 template<> struct ufbx_type_traits<ufbx_line_curve> {
5874 enum { valid = 1 };
5875 static void retain(ufbx_line_curve *ptr) { ufbx_retain_line_curve(ptr); }
5876 static void free(ufbx_line_curve *ptr) { ufbx_free_line_curve(ptr); }
5877 };
5878
5879 template<> struct ufbx_type_traits<ufbx_geometry_cache> {
5880 enum { valid = 1 };
5881 static void retain(ufbx_geometry_cache *ptr) { ufbx_retain_geometry_cache(ptr); }
5882 static void free(ufbx_geometry_cache *ptr) { ufbx_free_geometry_cache(ptr); }
5883 };
5884
5885 template<> struct ufbx_type_traits<ufbx_anim> {
5886 enum { valid = 1 };
5887 static void retain(ufbx_anim *ptr) { ufbx_retain_anim(ptr); }
5888 static void free(ufbx_anim *ptr) { ufbx_free_anim(ptr); }
5889 };
5890
5891 template<> struct ufbx_type_traits<ufbx_baked_anim> {
5892 enum { valid = 1 };
5893 static void retain(ufbx_baked_anim *ptr) { ufbx_retain_baked_anim(ptr); }
5894 static void free(ufbx_baked_anim *ptr) { ufbx_free_baked_anim(ptr); }
5895 };
5896
5897 class ufbx_deleter {
5898 public:
5899 template <typename T>
5900 void operator()(T *ptr) const {
5901 static_assert(ufbx_type_traits<T>::valid, "ufbx_deleter() unsupported for type");
5902 ufbx_type_traits<T>::free(ptr);
5903 }
5904 };
5905
5906 // RAII wrapper over refcounted ufbx types.
5907
5908 // Behaves like `std::unique_ptr<T>`.
5909 template <typename T>
5910 class ufbx_unique_ptr {
5911 T *ptr;
5912 using traits = ufbx_type_traits<T>;
5913 static_assert(ufbx_type_traits<T>::valid, "ufbx_unique_ptr unsupported for type");
5914 public:
5915 ufbx_unique_ptr() noexcept : ptr(nullptr) { }
5916 explicit ufbx_unique_ptr(T *ptr_) noexcept : ptr(ptr_) { }
5917 ufbx_unique_ptr(ufbx_unique_ptr &&ref) noexcept : ptr(ref.ptr) { ref.ptr = nullptr; }
5918 ~ufbx_unique_ptr() { traits::free(ptr); }
5919
5920 ufbx_unique_ptr &operator=(ufbx_unique_ptr &&ref) noexcept {
5921 if (&ref == this) return *this;
5922 ptr = ref.ptr;
5923 ref.ptr = nullptr;
5924 return *this;
5925 }
5926
5927 void reset(T *new_ptr=nullptr) noexcept {
5928 traits::free(ptr);
5929 ptr = new_ptr;
5930 }
5931
5932 void swap(ufbx_unique_ptr &ref) noexcept {
5933 T *tmp = ptr;
5934 ptr = ref.ptr;
5935 ref.ptr = tmp;
5936 }
5937
5938 T &operator*() const noexcept { return *ptr; }
5939 T *operator->() const noexcept { return ptr; }
5940 T *get() const noexcept { return ptr; }
5941 explicit operator bool() const noexcept { return ptr != nullptr; }
5942 };
5943
5944 // Behaves like `std::shared_ptr<T>` except uses ufbx's internal reference counting,
5945 // so it is half the size of a standard `shared_ptr` but might be marginally slower.
5946 template <typename T>
5947 class ufbx_shared_ptr {
5948 T *ptr;
5949 using traits = ufbx_type_traits<T>;
5950 static_assert(ufbx_type_traits<T>::valid, "ufbx_shared_ptr unsupported for type");
5951 public:
5952
5953 ufbx_shared_ptr() noexcept : ptr(nullptr) { }
5954 explicit ufbx_shared_ptr(T *ptr_) noexcept : ptr(ptr_) { }
5955 ufbx_shared_ptr(const ufbx_shared_ptr &ref) noexcept : ptr(ref.ptr) { traits::retain(ref.ptr); }
5956 ufbx_shared_ptr(ufbx_shared_ptr &&ref) noexcept : ptr(ref.ptr) { ref.ptr = nullptr; }
5957 ~ufbx_shared_ptr() { traits::free(ptr); }
5958
5959 ufbx_shared_ptr &operator=(const ufbx_shared_ptr &ref) noexcept {
5960 if (&ref == this) return *this;
5961 traits::free(ptr);
5962 traits::retain(ref.ptr);
5963 ptr = ref.ptr;
5964 return *this;
5965 }
5966
5967 ufbx_shared_ptr &operator=(ufbx_shared_ptr &&ref) noexcept {
5968 if (&ref == this) return *this;
5969 ptr = ref.ptr;
5970 ref.ptr = nullptr;
5971 return *this;
5972 }
5973
5974 void reset(T *new_ptr=nullptr) noexcept {
5975 traits::free(ptr);
5976 ptr = new_ptr;
5977 }
5978
5979 void swap(ufbx_shared_ptr &ref) noexcept {
5980 T *tmp = ptr;
5981 ptr = ref.ptr;
5982 ref.ptr = tmp;
5983 }
5984
5985 T &operator*() const noexcept { return *ptr; }
5986 T *operator->() const noexcept { return ptr; }
5987 T *get() const noexcept { return ptr; }
5988 explicit operator bool() const noexcept { return ptr != nullptr; }
5989 };
5990
5991 #endif
5992 // bindgen-enable
5993
5994 // -- Properties
5995
5996 // Names of common properties in `ufbx_props`.
5997 // Some of these differ from ufbx interpretations.
5998
5999 // Local translation.
6000 // Used by: `ufbx_node`
6001 #define UFBX_Lcl_Translation "Lcl Translation"
6002
6003 // Local rotation expressed in Euler degrees.
6004 // Used by: `ufbx_node`
6005 // The rotation order is defined by the `UFBX_RotationOrder` property.
6006 #define UFBX_Lcl_Rotation "Lcl Rotation"
6007
6008 // Local scaling factor, 3D vector.
6009 // Used by: `ufbx_node`
6010 #define UFBX_Lcl_Scaling "Lcl Scaling"
6011
6012 // Euler rotation interpretation, used by `UFBX_Lcl_Rotation`.
6013 // Used by: `ufbx_node`, enum value `ufbx_rotation_order`.
6014 #define UFBX_RotationOrder "RotationOrder"
6015
6016 // Scaling pivot: point around which scaling is performed.
6017 // Used by: `ufbx_node`.
6018 #define UFBX_ScalingPivot "ScalingPivot"
6019
6020 // Scaling pivot: point around which rotation is performed.
6021 // Used by: `ufbx_node`.
6022 #define UFBX_RotationPivot "RotationPivot"
6023
6024 // Scaling offset: translation added after scaling is performed.
6025 // Used by: `ufbx_node`.
6026 #define UFBX_ScalingOffset "ScalingOffset"
6027
6028 // Rotation offset: translation added after rotation is performed.
6029 // Used by: `ufbx_node`.
6030 #define UFBX_RotationOffset "RotationOffset"
6031
6032 // Pre-rotation: Rotation applied _after_ `UFBX_Lcl_Rotation`.
6033 // Used by: `ufbx_node`.
6034 // Affected by `UFBX_RotationPivot` but not `UFBX_RotationOrder`.
6035 #define UFBX_PreRotation "PreRotation"
6036
6037 // Post-rotation: Rotation applied _before_ `UFBX_Lcl_Rotation`.
6038 // Used by: `ufbx_node`.
6039 // Affected by `UFBX_RotationPivot` but not `UFBX_RotationOrder`.
6040 #define UFBX_PostRotation "PostRotation"
6041
6042 // Controls whether the node should be displayed or not.
6043 // Used by: `ufbx_node`.
6044 #define UFBX_Visibility "Visibility"
6045
6046 // Weight of an animation layer in percentage (100.0 being full).
6047 // Used by: `ufbx_anim_layer`.
6048 #define UFBX_Weight "Weight"
6049
6050 // Blend shape deformation weight (100.0 being full).
6051 // Used by: `ufbx_blend_channel`.
6052 #define UFBX_DeformPercent "DeformPercent"
6053
6054 #if defined(_MSC_VER)
6055 #pragma warning(pop)
6056 #elif defined(__clang__)
6057 #pragma clang diagnostic pop
6058 #elif defined(__GNUC__)
6059 #pragma GCC diagnostic pop
6060 #endif
6061
6062 #endif