fix read for precision-depending data.

pull/3012/head
kimkulling 2020-03-14 11:16:44 +01:00
parent dc04759492
commit 255758e6ff
2 changed files with 200 additions and 203 deletions

View File

@ -53,10 +53,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Assbin/AssbinLoader.h" #include "Assbin/AssbinLoader.h"
#include "Common/assbin_chunks.h" #include "Common/assbin_chunks.h"
#include <assimp/MemoryIOWrapper.h> #include <assimp/MemoryIOWrapper.h>
#include <assimp/mesh.h>
#include <assimp/anim.h> #include <assimp/anim.h>
#include <assimp/scene.h>
#include <assimp/importerdesc.h> #include <assimp/importerdesc.h>
#include <assimp/mesh.h>
#include <assimp/scene.h>
#include <memory> #include <memory>
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB #ifdef ASSIMP_BUILD_NO_OWN_ZLIB
@ -114,9 +114,9 @@ T Read(IOStream * stream) {
template <> template <>
aiVector3D Read<aiVector3D>(IOStream *stream) { aiVector3D Read<aiVector3D>(IOStream *stream) {
aiVector3D v; aiVector3D v;
v.x = Read<float>(stream); v.x = Read<ai_real>(stream);
v.y = Read<float>(stream); v.y = Read<ai_real>(stream);
v.z = Read<float>(stream); v.z = Read<ai_real>(stream);
return v; return v;
} }
@ -124,10 +124,10 @@ aiVector3D Read<aiVector3D>(IOStream * stream) {
template <> template <>
aiColor4D Read<aiColor4D>(IOStream *stream) { aiColor4D Read<aiColor4D>(IOStream *stream) {
aiColor4D c; aiColor4D c;
c.r = Read<float>(stream); c.r = Read<ai_real>(stream);
c.g = Read<float>(stream); c.g = Read<ai_real>(stream);
c.b = Read<float>(stream); c.b = Read<ai_real>(stream);
c.a = Read<float>(stream); c.a = Read<ai_real>(stream);
return c; return c;
} }
@ -135,10 +135,10 @@ aiColor4D Read<aiColor4D>(IOStream * stream) {
template <> template <>
aiQuaternion Read<aiQuaternion>(IOStream *stream) { aiQuaternion Read<aiQuaternion>(IOStream *stream) {
aiQuaternion v; aiQuaternion v;
v.w = Read<float>(stream); v.w = Read<ai_real>(stream);
v.x = Read<float>(stream); v.x = Read<ai_real>(stream);
v.y = Read<float>(stream); v.y = Read<ai_real>(stream);
v.z = Read<float>(stream); v.z = Read<ai_real>(stream);
return v; return v;
} }
@ -147,9 +147,11 @@ template <>
aiString Read<aiString>(IOStream *stream) { aiString Read<aiString>(IOStream *stream) {
aiString s; aiString s;
stream->Read(&s.length, 4, 1); stream->Read(&s.length, 4, 1);
if(s.length) if (s.length) {
stream->Read(s.data, s.length, 1); stream->Read(s.data, s.length, 1);
}
s.data[s.length] = 0; s.data[s.length] = 0;
return s; return s;
} }
@ -158,7 +160,7 @@ template <>
aiVertexWeight Read<aiVertexWeight>(IOStream *stream) { aiVertexWeight Read<aiVertexWeight>(IOStream *stream) {
aiVertexWeight w; aiVertexWeight w;
w.mVertexId = Read<unsigned int>(stream); w.mVertexId = Read<unsigned int>(stream);
w.mWeight = Read<float>(stream); w.mWeight = Read<ai_real>(stream);
return w; return w;
} }
@ -168,7 +170,7 @@ aiMatrix4x4 Read<aiMatrix4x4>(IOStream * stream) {
aiMatrix4x4 m; aiMatrix4x4 m;
for (unsigned int i = 0; i < 4; ++i) { for (unsigned int i = 0; i < 4; ++i) {
for (unsigned int i2 = 0; i2 < 4; ++i2) { for (unsigned int i2 = 0; i2 < 4; ++i2) {
m[i][i2] = Read<float>(stream); m[i][i2] = Read<ai_real>(stream);
} }
} }
return m; return m;
@ -228,8 +230,7 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** onode, aiNode*
node->mParent = parent; node->mParent = parent;
} }
if (numMeshes) if (numMeshes) {
{
node->mMeshes = new unsigned int[numMeshes]; node->mMeshes = new unsigned int[numMeshes];
for (unsigned int i = 0; i < numMeshes; ++i) { for (unsigned int i = 0; i < numMeshes; ++i) {
node->mMeshes[i] = Read<unsigned int>(stream); node->mMeshes[i] = Read<unsigned int>(stream);
@ -263,7 +264,7 @@ void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** onode, aiNode*
data = new uint64_t(Read<uint64_t>(stream)); data = new uint64_t(Read<uint64_t>(stream));
break; break;
case AI_FLOAT: case AI_FLOAT:
data = new float(Read<float>(stream)); data = new ai_real(Read<ai_real>(stream));
break; break;
case AI_DOUBLE: case AI_DOUBLE:
data = new double(Read<double>(stream)); data = new double(Read<double>(stream));
@ -448,10 +449,8 @@ void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat) {
/*uint32_t size =*/Read<uint32_t>(stream); /*uint32_t size =*/Read<uint32_t>(stream);
mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(stream); mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(stream);
if (mat->mNumProperties) if (mat->mNumProperties) {
{ if (mat->mProperties) {
if (mat->mProperties)
{
delete[] mat->mProperties; delete[] mat->mProperties;
} }
mat->mProperties = new aiMaterialProperty *[mat->mNumProperties]; mat->mProperties = new aiMaterialProperty *[mat->mNumProperties];
@ -666,7 +665,6 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene ) {
ReadBinaryCamera(stream, scene->mCameras[i]); ReadBinaryCamera(stream, scene->mCameras[i]);
} }
} }
} }
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
@ -709,8 +707,7 @@ void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
unsigned char *uncompressedData = new unsigned char[uncompressedSize]; unsigned char *uncompressedData = new unsigned char[uncompressedSize];
int res = uncompress(uncompressedData, &uncompressedSize, compressedData, (uLong)len); int res = uncompress(uncompressedData, &uncompressedSize, compressedData, (uLong)len);
if(res != Z_OK) if (res != Z_OK) {
{
delete[] uncompressedData; delete[] uncompressedData;
delete[] compressedData; delete[] compressedData;
pIOHandler->Close(stream); pIOHandler->Close(stream);

View File

@ -220,7 +220,7 @@ struct aiVertexWeight {
//! The strength of the influence in the range (0...1). //! The strength of the influence in the range (0...1).
//! The influence from all bones at one vertex amounts to 1. //! The influence from all bones at one vertex amounts to 1.
float mWeight; ai_real mWeight;
#ifdef __cplusplus #ifdef __cplusplus