Update OpenFBX to Jun 22, 2024
This commit is contained in:
38
Source/ThirdParty/OpenFBX/ofbx.cpp
vendored
38
Source/ThirdParty/OpenFBX/ofbx.cpp
vendored
@@ -12,7 +12,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string.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)
|
#include <bit> // for std::bit_cast (C++20 and later)
|
||||||
#endif
|
#endif
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -20,6 +20,12 @@
|
|||||||
namespace ofbx
|
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)
|
static int decodeIndex(int idx)
|
||||||
{
|
{
|
||||||
return (idx < 0) ? (-idx - 1) : idx;
|
return (idx < 0) ? (-idx - 1) : idx;
|
||||||
@@ -47,11 +53,12 @@ struct Allocator {
|
|||||||
Page* first = nullptr;
|
Page* first = nullptr;
|
||||||
|
|
||||||
~Allocator() {
|
~Allocator() {
|
||||||
while (first) {
|
Page* p = first;
|
||||||
Page* page = first;
|
while (p) {
|
||||||
first = first->header.next;
|
Page* n = p->header.next;
|
||||||
delete page;
|
delete p;
|
||||||
}
|
p = n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename... Args> T* allocate(Args&&... args)
|
template <typename T, typename... Args> T* allocate(Args&&... args)
|
||||||
@@ -416,7 +423,7 @@ bool DataView::operator==(const char* rhs) const
|
|||||||
++c;
|
++c;
|
||||||
++c2;
|
++c2;
|
||||||
}
|
}
|
||||||
return *c2 == '\0' || c2 == (const char*)end && *c == '\0';
|
return (*c2 == '\0' || c2 == (const char*)end) && *c == '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -585,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)
|
template <typename T> static OptionalError<T> read(Cursor* cursor)
|
||||||
{
|
{
|
||||||
if (cursor->current + sizeof(T) > cursor->end) return Error("Reading past the end");
|
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);
|
cursor->current += sizeof(T);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -774,7 +781,8 @@ static OptionalError<Element*> readElement(Cursor* cursor, u32 version, Allocato
|
|||||||
|
|
||||||
static bool isEndLine(const Cursor& cursor)
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1043,7 +1051,7 @@ static OptionalError<Element*> tokenize(const u8* data, size_t size, u32& versio
|
|||||||
cursor.current = data;
|
cursor.current = data;
|
||||||
cursor.end = data + size;
|
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);
|
const Header* header = std::bit_cast<const Header*>(cursor.current);
|
||||||
#else
|
#else
|
||||||
Header header_temp;
|
Header header_temp;
|
||||||
@@ -1939,7 +1947,7 @@ struct Scene : IScene
|
|||||||
int getGeometryCount() const override { return (int)m_geometries.size(); }
|
int getGeometryCount() const override { return (int)m_geometries.size(); }
|
||||||
int getMeshCount() const override { return (int)m_meshes.size(); }
|
int getMeshCount() const override { return (int)m_meshes.size(); }
|
||||||
float getSceneFrameRate() const override { return m_scene_frame_rate; }
|
float getSceneFrameRate() const override { return m_scene_frame_rate; }
|
||||||
const GlobalInfo* getGlobalInfo() const override { return &m_info; }
|
const GlobalInfo* getGlobalInfo() const override { return &m_info; }
|
||||||
const GlobalSettings* getGlobalSettings() const override { return &m_settings; }
|
const GlobalSettings* getGlobalSettings() const override { return &m_settings; }
|
||||||
|
|
||||||
const Object* const* getAllObjects() const override { return m_all_objects.empty() ? nullptr : &m_all_objects[0]; }
|
const Object* const* getAllObjects() const override { return m_all_objects.empty() ? nullptr : &m_all_objects[0]; }
|
||||||
@@ -2904,8 +2912,8 @@ static bool parseMemory(const Property& property, T* out, int max_size_bytes) {
|
|||||||
const u8* data = property.value.begin + sizeof(u32) * 3;
|
const u8* data = property.value.begin + sizeof(u32) * 3;
|
||||||
if (data > property.value.end) return false;
|
if (data > property.value.end) return false;
|
||||||
|
|
||||||
u32 enc = *(const u32*)(property.value.begin + 4);
|
u32 enc = read_value<u32>(property.value.begin + 4);
|
||||||
u32 len = *(const u32*)(property.value.begin + 8);
|
u32 len = read_value<u32>(property.value.begin + 8);
|
||||||
|
|
||||||
if (enc == 0) {
|
if (enc == 0) {
|
||||||
if ((int)len > max_size_bytes) return false;
|
if ((int)len > max_size_bytes) return false;
|
||||||
@@ -3518,7 +3526,7 @@ static bool parseObjects(const Element& root, Scene& scene, u16 flags, Allocator
|
|||||||
{
|
{
|
||||||
obj = allocator.allocate<AnimationCurveNodeImpl>(scene, *iter.second.element);
|
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);
|
IElementProperty* class_prop = iter.second.element->getProperty(2);
|
||||||
if (!class_prop) class_prop = iter.second.element->getProperty(1);
|
if (!class_prop) class_prop = iter.second.element->getProperty(1);
|
||||||
@@ -3571,7 +3579,7 @@ static bool parseObjects(const Element& root, Scene& scene, u16 flags, Allocator
|
|||||||
obj = mesh;
|
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);
|
obj = allocator.allocate<LimbNodeImpl>(scene, *iter.second.element);
|
||||||
else
|
else
|
||||||
obj = allocator.allocate<NullImpl>(scene, *iter.second.element);
|
obj = allocator.allocate<NullImpl>(scene, *iter.second.element);
|
||||||
|
|||||||
7
Source/ThirdParty/OpenFBX/ofbx.h
vendored
7
Source/ThirdParty/OpenFBX/ofbx.h
vendored
@@ -8,7 +8,7 @@ namespace ofbx
|
|||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
typedef unsigned short u16;
|
typedef unsigned short u16;
|
||||||
typedef unsigned int u32;
|
typedef unsigned int u32;
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32) || defined(__ANDROID__)
|
||||||
typedef long long i64;
|
typedef long long i64;
|
||||||
typedef unsigned long long u64;
|
typedef unsigned long long u64;
|
||||||
#else
|
#else
|
||||||
@@ -70,8 +70,7 @@ struct FVec4 { float x, y, z, w; };
|
|||||||
struct FMatrix { float m[16]; };
|
struct FMatrix { float m[16]; };
|
||||||
struct FQuat{ float x, y, z, w; };
|
struct FQuat{ float x, y, z, w; };
|
||||||
|
|
||||||
#define OFBX_SINGLE_PRECISION
|
#ifndef OFBX_DOUBLE_PRECISION
|
||||||
#ifdef OFBX_SINGLE_PRECISION
|
|
||||||
// use floats for vertices, normals, uvs, ...
|
// use floats for vertices, normals, uvs, ...
|
||||||
using Vec2 = FVec2;
|
using Vec2 = FVec2;
|
||||||
using Vec3 = FVec3;
|
using Vec3 = FVec3;
|
||||||
@@ -770,7 +769,7 @@ struct IScene
|
|||||||
virtual const TakeInfo* getTakeInfo(const char* name) const = 0;
|
virtual const TakeInfo* getTakeInfo(const char* name) const = 0;
|
||||||
virtual float getSceneFrameRate() const = 0;
|
virtual float getSceneFrameRate() const = 0;
|
||||||
virtual const GlobalSettings* getGlobalSettings() const = 0;
|
virtual const GlobalSettings* getGlobalSettings() const = 0;
|
||||||
virtual const GlobalInfo* getGlobalInfo() const = 0;
|
virtual const GlobalInfo* getGlobalInfo() const = 0;
|
||||||
|
|
||||||
virtual ~IScene() {}
|
virtual ~IScene() {}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user