Merge pull request #2751 from muxanickms/export_fbx_bigger_than_2GB_fix
Fix for exporting fbx bigger than 2GBpull/2757/head
commit
78ec42fc17
|
@ -52,6 +52,35 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
template<size_t sizeOfPointer>
|
||||||
|
size_t select_ftell(FILE* file)
|
||||||
|
{
|
||||||
|
return ::ftell(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t sizeOfPointer>
|
||||||
|
int select_fseek(FILE* file, int64_t offset, int origin)
|
||||||
|
{
|
||||||
|
return ::fseek(file, static_cast<long>(offset), origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined _WIN32 && (!defined __GNUC__ || __MSVCRT_VERSION__ >= 0x0601)
|
||||||
|
template<>
|
||||||
|
size_t select_ftell<8>(FILE* file)
|
||||||
|
{
|
||||||
|
return ::_ftelli64(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
int select_fseek<8>(FILE* file, int64_t offset, int origin)
|
||||||
|
{
|
||||||
|
return ::_fseeki64(file, offset, origin);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
DefaultIOStream::~DefaultIOStream()
|
DefaultIOStream::~DefaultIOStream()
|
||||||
{
|
{
|
||||||
|
@ -93,7 +122,7 @@ aiReturn DefaultIOStream::Seek(size_t pOffset,
|
||||||
aiOrigin_END == SEEK_END && aiOrigin_SET == SEEK_SET");
|
aiOrigin_END == SEEK_END && aiOrigin_SET == SEEK_SET");
|
||||||
|
|
||||||
// do the seek
|
// do the seek
|
||||||
return (0 == ::fseek(mFile, (long)pOffset,(int)pOrigin) ? AI_SUCCESS : AI_FAILURE);
|
return (0 == select_fseek<sizeof(void*)>(mFile, (int64_t)pOffset,(int)pOrigin) ? AI_SUCCESS : AI_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
|
@ -102,7 +131,7 @@ size_t DefaultIOStream::Tell() const
|
||||||
if (!mFile) {
|
if (!mFile) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ::ftell(mFile);
|
return select_ftell<sizeof(void*)>(mFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -50,9 +50,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace FBX
|
namespace FBX
|
||||||
{
|
{
|
||||||
const std::string NULL_RECORD = { // 13 null bytes
|
const std::string NULL_RECORD = { // 25 null bytes in 64-bit and 13 null bytes in 32-bit
|
||||||
'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'
|
'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
|
||||||
}; // who knows why
|
'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'
|
||||||
|
}; // who knows why, it looks like two integers 32/64 bit (compressed and uncompressed sizes?) + 1 byte (might be compression type?)
|
||||||
const std::string SEPARATOR = {'\x00', '\x01'}; // for use inside strings
|
const std::string SEPARATOR = {'\x00', '\x01'}; // for use inside strings
|
||||||
const std::string MAGIC_NODE_TAG = "_$AssimpFbx$"; // from import
|
const std::string MAGIC_NODE_TAG = "_$AssimpFbx$"; // from import
|
||||||
const int64_t SECOND = 46186158000; // FBX's kTime unit
|
const int64_t SECOND = 46186158000; // FBX's kTime unit
|
||||||
|
|
|
@ -325,9 +325,9 @@ void FBX::Node::BeginBinary(Assimp::StreamWriterLE &s)
|
||||||
this->start_pos = s.Tell();
|
this->start_pos = s.Tell();
|
||||||
|
|
||||||
// placeholders for end pos and property section info
|
// placeholders for end pos and property section info
|
||||||
s.PutU4(0); // end pos
|
s.PutU8(0); // end pos
|
||||||
s.PutU4(0); // number of properties
|
s.PutU8(0); // number of properties
|
||||||
s.PutU4(0); // total property section length
|
s.PutU8(0); // total property section length
|
||||||
|
|
||||||
// node name
|
// node name
|
||||||
s.PutU1(uint8_t(name.size())); // length of node name
|
s.PutU1(uint8_t(name.size())); // length of node name
|
||||||
|
@ -352,9 +352,9 @@ void FBX::Node::EndPropertiesBinary(
|
||||||
size_t pos = s.Tell();
|
size_t pos = s.Tell();
|
||||||
ai_assert(pos > property_start);
|
ai_assert(pos > property_start);
|
||||||
size_t property_section_size = pos - property_start;
|
size_t property_section_size = pos - property_start;
|
||||||
s.Seek(start_pos + 4);
|
s.Seek(start_pos + 8); // 8 bytes of uint64_t of end_pos
|
||||||
s.PutU4(uint32_t(num_properties));
|
s.PutU8(num_properties);
|
||||||
s.PutU4(uint32_t(property_section_size));
|
s.PutU8(property_section_size);
|
||||||
s.Seek(pos);
|
s.Seek(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ void FBX::Node::EndBinary(
|
||||||
// now go back and write initial pos
|
// now go back and write initial pos
|
||||||
this->end_pos = s.Tell();
|
this->end_pos = s.Tell();
|
||||||
s.Seek(start_pos);
|
s.Seek(start_pos);
|
||||||
s.PutU4(uint32_t(end_pos));
|
s.PutU8(end_pos);
|
||||||
s.Seek(end_pos);
|
s.Seek(end_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,8 @@ using namespace Assimp::FBX;
|
||||||
// some constants that we'll use for writing metadata
|
// some constants that we'll use for writing metadata
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace FBX {
|
namespace FBX {
|
||||||
const std::string EXPORT_VERSION_STR = "7.4.0";
|
const std::string EXPORT_VERSION_STR = "7.5.0";
|
||||||
const uint32_t EXPORT_VERSION_INT = 7400; // 7.4 == 2014/2015
|
const uint32_t EXPORT_VERSION_INT = 7500; // 7.5 == 2016+
|
||||||
// FBX files have some hashed values that depend on the creation time field,
|
// FBX files have some hashed values that depend on the creation time field,
|
||||||
// but for now we don't actually know how to generate these.
|
// but for now we don't actually know how to generate these.
|
||||||
// what we can do is set them to a known-working version.
|
// what we can do is set them to a known-working version.
|
||||||
|
|
Loading…
Reference in New Issue