From 0b15d5cd46caaa7fcb2d82e025a914f9e21cbeef Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 24 Jan 2018 21:20:34 +0100 Subject: [PATCH] closes https://github.com/assimp/assimp/issues/1721: set camera parameters instead of nonsense. --- code/FBXConverter.cpp | 21 ++++++++++----------- code/FBXParser.cpp | 23 ++++++++++------------- code/FBXProperties.cpp | 5 +---- code/FBXTokenizer.cpp | 2 -- code/MDLLoader.cpp | 34 ++++++++++++++-------------------- include/assimp/IOStream.hpp | 11 ++++++----- 6 files changed, 41 insertions(+), 55 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index f7a58ebdc..61883946c 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -443,10 +443,9 @@ private: }; Converter::Converter( aiScene* out, const Document& doc ) - : defaultMaterialIndex() - , out( out ) - , doc( doc ) -{ +: defaultMaterialIndex() +, out( out ) +, doc( doc ) { // animations need to be converted first since this will // populate the node_anim_chain_bits map, which is needed // to determine which nodes need to be generated. @@ -483,8 +482,7 @@ Converter::Converter( aiScene* out, const Document& doc ) } -Converter::~Converter() -{ +Converter::~Converter() { std::for_each( meshes.begin(), meshes.end(), Util::delete_fun() ); std::for_each( materials.begin(), materials.end(), Util::delete_fun() ); std::for_each( animations.begin(), animations.end(), Util::delete_fun() ); @@ -493,8 +491,7 @@ Converter::~Converter() std::for_each( textures.begin(), textures.end(), Util::delete_fun() ); } -void Converter::ConvertRootNode() -{ +void Converter::ConvertRootNode() { out->mRootNode = new aiNode(); out->mRootNode->mName.Set( "RootNode" ); @@ -721,10 +718,12 @@ void Converter::ConvertCamera( const Model& model, const Camera& cam ) out_camera->mName.Set( FixNodeName( model.Name() ) ); out_camera->mAspect = cam.AspectWidth() / cam.AspectHeight(); + //cameras are defined along positive x direction - out_camera->mPosition = aiVector3D(0.0f); - out_camera->mLookAt = aiVector3D(1.0f, 0.0f, 0.0f); - out_camera->mUp = aiVector3D(0.0f, 1.0f, 0.0f); + out_camera->mPosition = cam.Position(); + out_camera->mLookAt = ( cam.InterestPosition() - out_camera->mPosition ).Normalize(); + out_camera->mUp = cam.UpVector(); + out_camera->mHorizontalFOV = AI_DEG_TO_RAD( cam.FieldOfView() ); out_camera->mClipPlaneNear = cam.NearPlane(); out_camera->mClipPlaneFar = cam.FarPlane(); diff --git a/code/FBXParser.cpp b/code/FBXParser.cpp index e8e588b06..a49d96af1 100644 --- a/code/FBXParser.cpp +++ b/code/FBXParser.cpp @@ -45,7 +45,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER - #ifdef ASSIMP_BUILD_NO_OWN_ZLIB # include #else @@ -67,7 +66,6 @@ using namespace Assimp::FBX; namespace { - // ------------------------------------------------------------------------------------------------ // signal parse error, this is always unrecoverable. Throws DeadlyImportError. AI_WONT_RETURN void ParseError(const std::string& message, const Token& token) AI_WONT_RETURN_SUFFIX; @@ -213,7 +211,6 @@ Scope::~Scope() } } - // ------------------------------------------------------------------------------------------------ Parser::Parser (const TokenList& tokens, bool is_binary) : tokens(tokens) @@ -537,18 +534,18 @@ void ReadBinaryDataArray(char type, uint32_t count, const char*& data, const cha uint32_t stride = 0; switch(type) { - case 'f': - case 'i': - stride = 4; - break; + case 'f': + case 'i': + stride = 4; + break; - case 'd': - case 'l': - stride = 8; - break; + case 'd': + case 'l': + stride = 8; + break; - default: - ai_assert(false); + default: + ai_assert(false); }; const uint32_t full_length = stride * count; diff --git a/code/FBXProperties.cpp b/code/FBXProperties.cpp index 774beac3c..6126dc53c 100644 --- a/code/FBXProperties.cpp +++ b/code/FBXProperties.cpp @@ -108,7 +108,7 @@ Property* ReadTypedProperty(const Element& element) ParseTokenAsFloat(*tok[6])) ); } - else if (!strcmp(cs,"double") || !strcmp(cs,"Number") || !strcmp(cs,"Float") || !strcmp(cs,"FieldOfView")) { + else if (!strcmp(cs,"double") || !strcmp(cs,"Number") || !strcmp(cs,"Float") || !strcmp(cs,"FieldOfView") || !strcmp( cs, "UnitScaleFactor" ) ) { return new TypedProperty(ParseTokenAsFloat(*tok[4])); } return NULL; @@ -138,7 +138,6 @@ PropertyTable::PropertyTable() { } - // ------------------------------------------------------------------------------------------------ PropertyTable::PropertyTable(const Element& element, std::shared_ptr templateProps) : templateProps(templateProps) @@ -229,8 +228,6 @@ DirectPropertyMap PropertyTable::GetUnparsedProperties() const return result; } - - } //! FBX } //! Assimp diff --git a/code/FBXTokenizer.cpp b/code/FBXTokenizer.cpp index d94556b97..aa0274ab5 100644 --- a/code/FBXTokenizer.cpp +++ b/code/FBXTokenizer.cpp @@ -76,13 +76,11 @@ Token::Token(const char* sbegin, const char* send, TokenType type, unsigned int ai_assert(static_cast(send-sbegin) > 0); } - // ------------------------------------------------------------------------------------------------ Token::~Token() { } - namespace { // ------------------------------------------------------------------------------------------------ diff --git a/code/MDLLoader.cpp b/code/MDLLoader.cpp index 4597afe11..bbb1c24d5 100644 --- a/code/MDLLoader.cpp +++ b/code/MDLLoader.cpp @@ -340,9 +340,9 @@ void FlipQuakeHeader(BE_NCONST MDL::Header* pcHeader) // ------------------------------------------------------------------------------------------------ // Read a Quake 1 file -void MDLImporter::InternReadFile_Quake1( ) -{ +void MDLImporter::InternReadFile_Quake1() { ai_assert(NULL != pScene); + BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header*)this->mBuffer; #ifdef AI_BUILD_BIG_ENDIAN @@ -355,9 +355,11 @@ void MDLImporter::InternReadFile_Quake1( ) const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1); // need to read all textures - for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins;++i) - { - union{BE_NCONST MDL::Skin* pcSkin;BE_NCONST MDL::GroupSkin* pcGroupSkin;}; + for ( unsigned int i = 0; i < (unsigned int)pcHeader->num_skins; ++i) { + union { + BE_NCONST MDL::Skin* pcSkin; + BE_NCONST MDL::GroupSkin* pcGroupSkin; + }; if (szCurrent + sizeof(MDL::Skin) > this->mBuffer + this->iFileSize) { throw DeadlyImportError("[Quake 1 MDL] Unexpected EOF"); } @@ -365,17 +367,15 @@ void MDLImporter::InternReadFile_Quake1( ) AI_SWAP4( pcSkin->group ); - // Quake 1 groupskins - if (1 == pcSkin->group) - { + // Quake 1 group-skins + if (1 == pcSkin->group) { AI_SWAP4( pcGroupSkin->nb ); // need to skip multiple images const unsigned int iNumImages = (unsigned int)pcGroupSkin->nb; szCurrent += sizeof(uint32_t) * 2; - if (0 != iNumImages) - { + if (0 != iNumImages) { if (!i) { // however, create only one output image (the first) this->CreateTextureARGB8_3DGS_MDL3(szCurrent + iNumImages * sizeof(float)); @@ -384,10 +384,7 @@ void MDLImporter::InternReadFile_Quake1( ) szCurrent += pcHeader->skinheight * pcHeader->skinwidth + sizeof(float) * iNumImages; } - } - // 3DGS has a few files that are using other 3DGS like texture formats here - else - { + } else { szCurrent += sizeof(uint32_t); unsigned int iSkip = i ? UINT_MAX : 0; CreateTexture_3DGS_MDL4(szCurrent,pcSkin->group,&iSkip); @@ -407,17 +404,14 @@ void MDLImporter::InternReadFile_Quake1( ) BE_NCONST MDL::Frame* pcFrames = (BE_NCONST MDL::Frame*)szCurrent; BE_NCONST MDL::SimpleFrame* pcFirstFrame; - if (0 == pcFrames->type) - { + if (0 == pcFrames->type) { // get address of single frame pcFirstFrame = &pcFrames->frame; - } - else - { + } else { // get the first frame in the group #if 1 - // FIXME: the cast is wrong and causea a warning on clang 5.0 + // FIXME: the cast is wrong and cause a warning on clang 5.0 // disable thi code for now, fix it later ai_assert(false && "Bad pointer cast"); #else diff --git a/include/assimp/IOStream.hpp b/include/assimp/IOStream.hpp index ce5907a47..2d7ac52af 100644 --- a/include/assimp/IOStream.hpp +++ b/include/assimp/IOStream.hpp @@ -70,7 +70,7 @@ class ASSIMP_API IOStream { protected: /** Constructor protected, use IOSystem::Open() to create an instance. */ - IOStream(void); + IOStream(); public: // ------------------------------------------------------------------- @@ -124,17 +124,18 @@ public: }; //! class IOStream // ---------------------------------------------------------------------------------- -inline IOStream::IOStream() -{ +inline +IOStream::IOStream() { // empty } // ---------------------------------------------------------------------------------- -inline IOStream::~IOStream() -{ +inline +IOStream::~IOStream() { // empty } // ---------------------------------------------------------------------------------- + } //!namespace Assimp #endif //!!AI_IOSTREAM_H_INC