瀏覽代碼

Merge pull request #1272 from assimp/issue-1262

closes https://github.com/assimp/assimp/issues/1262: fix .
Kim Kulling 8 年之前
父節點
當前提交
3d5e94477f

+ 40 - 3
code/OpenGEXImporter.cpp

@@ -196,7 +196,6 @@ namespace Grammar {
 
 
         return NoneType;
         return NoneType;
     }
     }
-
 } // Namespace Grammar
 } // Namespace Grammar
 
 
 namespace Assimp {
 namespace Assimp {
@@ -523,6 +522,10 @@ void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
         if ( !objRefNames.empty() ) {
         if ( !objRefNames.empty() ) {
             m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MeshRef, objRefNames ) );
             m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MeshRef, objRefNames ) );
         }
         }
+    } else if ( m_tokenType == Grammar::LightNodeToken ) {
+        // TODO!
+    } else if ( m_tokenType == Grammar::CameraNodeToken ) {
+        // TODO!
     }
     }
 }
 }
 
 
@@ -602,6 +605,13 @@ void OpenGEXImporter::handleCameraObject( ODDLParser::DDLNode *node, aiScene *pS
 
 
 //------------------------------------------------------------------------------------------------
 //------------------------------------------------------------------------------------------------
 void OpenGEXImporter::handleLightObject( ODDLParser::DDLNode *node, aiScene *pScene ) {
 void OpenGEXImporter::handleLightObject( ODDLParser::DDLNode *node, aiScene *pScene ) {
+    aiLight *light( new aiLight );
+    m_lightCache.push_back( light );
+    std::string objName = node->getName();
+    if ( !objName.empty() ) {
+        light->mName.Set( objName );
+    }
+    m_currentLight = light;
 
 
     Property *prop( node->findPropertyByName( "type" ) );
     Property *prop( node->findPropertyByName( "type" ) );
     if ( nullptr != prop ) {
     if ( nullptr != prop ) {
@@ -917,7 +927,7 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
 }
 }
 
 
 //------------------------------------------------------------------------------------------------
 //------------------------------------------------------------------------------------------------
-static void getColorRGB( aiColor3D *pColor, DataArrayList *colList ) {
+static void getColorRGB3( aiColor3D *pColor, DataArrayList *colList ) {
     if( nullptr == pColor || nullptr == colList ) {
     if( nullptr == pColor || nullptr == colList ) {
         return;
         return;
     }
     }
@@ -931,6 +941,23 @@ static void getColorRGB( aiColor3D *pColor, DataArrayList *colList ) {
     pColor->b = val->getFloat();
     pColor->b = val->getFloat();
 }
 }
 
 
+//------------------------------------------------------------------------------------------------
+static void getColorRGB4( aiColor4D *pColor, DataArrayList *colList ) {
+    if ( nullptr == pColor || nullptr == colList ) {
+        return;
+    }
+
+    ai_assert( 4 == colList->m_numItems );
+    Value *val( colList->m_dataList );
+    pColor->r = val->getFloat();
+    val = val->getNext();
+    pColor->g = val->getFloat();
+    val = val->getNext();
+    pColor->b = val->getFloat();
+    val = val->getNext();
+    pColor->a = val->getFloat();
+}
+
 //------------------------------------------------------------------------------------------------
 //------------------------------------------------------------------------------------------------
 enum ColorType {
 enum ColorType {
     NoneColor = 0,
     NoneColor = 0,
@@ -981,7 +1008,17 @@ void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScen
                 return;
                 return;
             }
             }
             aiColor3D col;
             aiColor3D col;
-            getColorRGB( &col, colList );
+            if ( 3 == colList->m_numItems ) {
+                aiColor3D col3;
+                getColorRGB3( &col3, colList );
+                col = col3;
+            } else {
+                aiColor4D col4;
+                getColorRGB4( &col4, colList );
+                col.r = col4.r;
+                col.g = col4.g;
+                col.b = col4.b;
+            }
             const ColorType colType( getColorType( prop->m_key ) );
             const ColorType colType( getColorType( prop->m_key ) );
             if( DiffuseColor == colType ) {
             if( DiffuseColor == colType ) {
                 m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_DIFFUSE );
                 m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_DIFFUSE );

+ 0 - 1
code/OpenGEXImporter.h

@@ -132,7 +132,6 @@ protected:
     void copyMeshes( aiScene *pScene );
     void copyMeshes( aiScene *pScene );
     void copyCameras( aiScene *pScene );
     void copyCameras( aiScene *pScene );
     void copyLights( aiScene *pScene );
     void copyLights( aiScene *pScene );
-
     void resolveReferences();
     void resolveReferences();
     void pushNode( aiNode *node, aiScene *pScene );
     void pushNode( aiNode *node, aiScene *pScene );
     aiNode *popNode();
     aiNode *popNode();

+ 1 - 0
test/CMakeLists.txt

@@ -106,6 +106,7 @@ SET( TEST_SRCS
   unit/SceneDiffer.cpp
   unit/SceneDiffer.cpp
   unit/utSIBImporter.cpp
   unit/utSIBImporter.cpp
   unit/utObjImportExport.cpp
   unit/utObjImportExport.cpp
+  unit/utOpenGEXImportExport.cpp
   unit/utPretransformVertices.cpp
   unit/utPretransformVertices.cpp
   unit/utPLYImportExport.cpp
   unit/utPLYImportExport.cpp
   unit/utPMXImporter.cpp
   unit/utPMXImporter.cpp

+ 21 - 0
test/models/OpenGEX/light_issue1262.ogex

@@ -0,0 +1,21 @@
+LightObject (type = "infinite") {
+    Param (attrib = "intensity") {
+        float { 3.0 }
+    }
+
+    Color (attrib = "light") {
+        float[3] { { 0.7, 1.0, 0.1 } }
+    }
+}
+
+LightObject (type = "point") {
+    Param (attrib = "intensity") {
+        float { 0.5 }
+    }
+}
+
+LightObject (type = "spot") {
+    Color (attrib = "light") {
+        float[4] { { 0.1, 0.0, 0.1, 1.0 } }
+    }
+}

+ 70 - 0
test/unit/utOpenGEXImportExport.cpp

@@ -0,0 +1,70 @@
+/*
+---------------------------------------------------------------------------
+Open Asset Import Library (assimp)
+---------------------------------------------------------------------------
+
+Copyright (c) 2006-2017, assimp team
+
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms,
+with or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+copyright notice, this list of conditions and the
+following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the
+following disclaimer in the documentation and/or other
+materials provided with the distribution.
+
+* Neither the name of the assimp team, nor the names of its
+contributors may be used to endorse or promote products
+derived from this software without specific prior
+written permission of the assimp team.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+---------------------------------------------------------------------------
+*/
+
+#include "UnitTestPCH.h"
+#include "AbstractImportExportBase.h"
+
+#include <assimp/Importer.hpp>
+
+using namespace Assimp;
+
+
+class utOpenGEXImportExport : public AbstractImportExportBase {
+public:
+    virtual bool importerTest() {
+        Assimp::Importer importer;
+        const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/OpenGEX/Example.ogex", 0 );
+        return nullptr != scene;
+
+        return true;
+    }
+};
+
+TEST_F( utOpenGEXImportExport, importLWSFromFileTest ) {
+    EXPECT_TRUE( importerTest() );
+}
+
+TEST_F( utOpenGEXImportExport, Importissue1262_NoCrash ) {
+    Assimp::Importer importer;
+    const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/OpenGEX/light_issue1262.ogex", 0 );
+
+}