From 412c5b97a2ae6b0f12933fdd900434de7ff10f6a Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Sat, 22 Jun 2024 10:39:54 +0200 Subject: [PATCH] update ofbx --- external/openfbx/ofbx.cpp | 25 ++++++++++++++++--------- external/openfbx/ofbx.h | 5 ++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/external/openfbx/ofbx.cpp b/external/openfbx/ofbx.cpp index 9f75a2e6b3..93210fadbe 100644 --- a/external/openfbx/ofbx.cpp +++ b/external/openfbx/ofbx.cpp @@ -12,7 +12,7 @@ #include #include -#if __cplusplus >= 202002L +#if __cplusplus >= 202002L && defined(__cpp_lib_bit_cast) #include // for std::bit_cast (C++20 and later) #endif #include @@ -20,6 +20,12 @@ namespace ofbx { +template static T read_value(const u8* value_ptr) { + T value; + memcpy(&value, value_ptr, sizeof(T)); + return value; +} + static int decodeIndex(int idx) { return (idx < 0) ? (-idx - 1) : idx; @@ -417,7 +423,7 @@ bool DataView::operator==(const char* rhs) const ++c; ++c2; } - return *c2 == '\0' || c2 == (const char*)end && *c == '\0'; + return (*c2 == '\0' || c2 == (const char*)end) && *c == '\0'; } @@ -586,7 +592,7 @@ static bool decompress(const u8* in, size_t in_size, u8* out, size_t out_size) template static OptionalError read(Cursor* cursor) { if (cursor->current + sizeof(T) > cursor->end) return Error("Reading past the end"); - T value = *(const T*)cursor->current; + T value = read_value(cursor->current); cursor->current += sizeof(T); return value; } @@ -775,7 +781,8 @@ static OptionalError readElement(Cursor* cursor, u32 version, Allocato static bool isEndLine(const Cursor& cursor) { - return *cursor.current == '\n' || *cursor.current == '\r' && cursor.current + 1 < cursor.end && *(cursor.current + 1) != '\n'; + return (*cursor.current == '\n') + || (*cursor.current == '\r' && cursor.current + 1 < cursor.end && *(cursor.current + 1) != '\n'); } @@ -1044,7 +1051,7 @@ static OptionalError tokenize(const u8* data, size_t size, u32& versio cursor.current = data; cursor.end = data + size; -#if __cplusplus >= 202002L +#if __cplusplus >= 202002L && defined(__cpp_lib_bit_cast) const Header* header = std::bit_cast(cursor.current); #else Header header_temp; @@ -2903,8 +2910,8 @@ static bool parseMemory(const Property& property, T* out, int max_size_bytes) { const u8* data = property.value.begin + sizeof(u32) * 3; if (data > property.value.end) return false; - u32 enc = *(const u32*)(property.value.begin + 4); - u32 len = *(const u32*)(property.value.begin + 8); + u32 enc = read_value(property.value.begin + 4); + u32 len = read_value(property.value.begin + 8); if (enc == 0) { if ((int)len > max_size_bytes) return false; @@ -3472,7 +3479,7 @@ static bool parseObjects(const Element& root, Scene& scene, u16 flags, Allocator { obj = allocator.allocate(scene, *iter.second.element); } - else if (iter.second.element->id == "Deformer" && !ignore_blend_shapes) + else if (iter.second.element->id == "Deformer") { IElementProperty* class_prop = iter.second.element->getProperty(2); if (!class_prop) class_prop = iter.second.element->getProperty(1); @@ -3525,7 +3532,7 @@ static bool parseObjects(const Element& root, Scene& scene, u16 flags, Allocator obj = mesh; } } - else if (class_prop->getValue() == "LimbNode" && !ignore_limbs) + else if ((class_prop->getValue() == "LimbNode" || class_prop->getValue() == "Root") && !ignore_limbs) obj = allocator.allocate(scene, *iter.second.element); else obj = allocator.allocate(scene, *iter.second.element); diff --git a/external/openfbx/ofbx.h b/external/openfbx/ofbx.h index 28b6ebbfd5..6c0edef1e2 100644 --- a/external/openfbx/ofbx.h +++ b/external/openfbx/ofbx.h @@ -8,7 +8,7 @@ namespace ofbx typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; -#ifdef _WIN32 +#if defined(_WIN32) || defined(__ANDROID__) typedef long long i64; typedef unsigned long long u64; #else @@ -70,8 +70,7 @@ struct FVec4 { float x, y, z, w; }; struct FMatrix { float m[16]; }; struct FQuat{ float x, y, z, w; }; -#define OFBX_SINGLE_PRECISION -#ifdef OFBX_SINGLE_PRECISION +#ifndef OFBX_DOUBLE_PRECISION // use floats for vertices, normals, uvs, ... using Vec2 = FVec2; using Vec3 = FVec3;