Browse Source

closes https://github.com/assimp/assimp/issues/1721: set camera parameters instead of nonsense.

Kim Kulling 7 years ago
parent
commit
0b15d5cd46
6 changed files with 43 additions and 57 deletions
  1. 10 11
      code/FBXConverter.cpp
  2. 12 15
      code/FBXParser.cpp
  3. 1 4
      code/FBXProperties.cpp
  4. 0 2
      code/FBXTokenizer.cpp
  5. 14 20
      code/MDLLoader.cpp
  6. 6 5
      include/assimp/IOStream.hpp

+ 10 - 11
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<aiMesh>() );
     std::for_each( materials.begin(), materials.end(), Util::delete_fun<aiMaterial>() );
     std::for_each( animations.begin(), animations.end(), Util::delete_fun<aiAnimation>() );
@@ -493,8 +491,7 @@ Converter::~Converter()
     std::for_each( textures.begin(), textures.end(), Util::delete_fun<aiTexture>() );
 }
 
-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();

+ 12 - 15
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 <zlib.h>
 #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 'd':
-    case 'l':
-        stride = 8;
-        break;
-
-    default:
-        ai_assert(false);
+        case 'f':
+        case 'i':
+            stride = 4;
+            break;
+
+        case 'd':
+        case 'l':
+            stride = 8;
+            break;
+
+        default:
+            ai_assert(false);
     };
 
     const uint32_t full_length = stride * count;

+ 1 - 4
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<float>(ParseTokenAsFloat(*tok[4]));
     }
     return NULL;
@@ -138,7 +138,6 @@ PropertyTable::PropertyTable()
 {
 }
 
-
 // ------------------------------------------------------------------------------------------------
 PropertyTable::PropertyTable(const Element& element, std::shared_ptr<const PropertyTable> templateProps)
 : templateProps(templateProps)
@@ -229,8 +228,6 @@ DirectPropertyMap PropertyTable::GetUnparsedProperties() const
     return result;
 }
 
-
-
 } //! FBX
 } //! Assimp
 

+ 0 - 2
code/FBXTokenizer.cpp

@@ -76,13 +76,11 @@ Token::Token(const char* sbegin, const char* send, TokenType type, unsigned int
     ai_assert(static_cast<size_t>(send-sbegin) > 0);
 }
 
-
 // ------------------------------------------------------------------------------------------------
 Token::~Token()
 {
 }
 
-
 namespace {
 
 // ------------------------------------------------------------------------------------------------

+ 14 - 20
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

+ 6 - 5
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