Skip to content

Commit

Permalink
update ofbx
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Jun 22, 2024
1 parent d04c545 commit 412c5b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
25 changes: 16 additions & 9 deletions external/openfbx/ofbx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@
#include <inttypes.h>
#include <string.h>

#if __cplusplus >= 202002L
#if __cplusplus >= 202002L && defined(__cpp_lib_bit_cast)
#include <bit> // for std::bit_cast (C++20 and later)
#endif
#include <map>

namespace ofbx
{

template<typename T> 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;
Expand Down Expand Up @@ -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';
}


Expand Down Expand Up @@ -586,7 +592,7 @@ static bool decompress(const u8* in, size_t in_size, u8* out, size_t out_size)
template <typename T> static OptionalError<T> 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<T>(cursor->current);
cursor->current += sizeof(T);
return value;
}
Expand Down Expand Up @@ -775,7 +781,8 @@ static OptionalError<Element*> 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');
}


Expand Down Expand Up @@ -1044,7 +1051,7 @@ static OptionalError<Element*> 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<const Header*>(cursor.current);
#else
Header header_temp;
Expand Down Expand Up @@ -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<u32>(property.value.begin + 4);
u32 len = read_value<u32>(property.value.begin + 8);

if (enc == 0) {
if ((int)len > max_size_bytes) return false;
Expand Down Expand Up @@ -3472,7 +3479,7 @@ static bool parseObjects(const Element& root, Scene& scene, u16 flags, Allocator
{
obj = allocator.allocate<AnimationCurveNodeImpl>(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);
Expand Down Expand Up @@ -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<LimbNodeImpl>(scene, *iter.second.element);
else
obj = allocator.allocate<NullImpl>(scene, *iter.second.element);
Expand Down
5 changes: 2 additions & 3 deletions external/openfbx/ofbx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 412c5b9

Please sign in to comment.