瀏覽代碼

first version of material handling for opengex

Signed-off-by: Kim Kulling <[email protected]>
Kim Kulling 10 年之前
父節點
當前提交
ead3e8d275
共有 2 個文件被更改,包括 51 次插入0 次删除
  1. 49 0
      code/OpenGEXImporter.cpp
  2. 2 0
      code/OpenGEXImporter.h

+ 49 - 0
code/OpenGEXImporter.cpp

@@ -217,6 +217,7 @@ OpenGEXImporter::OpenGEXImporter()
 , m_ctx( NULL )
 , m_currentNode( NULL )
 , m_currentMesh( NULL )
+, m_currentMaterial( NULL )
 , m_nodeStack()
 , m_unresolvedRefStack() {
     // empty
@@ -722,14 +723,62 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
     }
 }
 
+//------------------------------------------------------------------------------------------------
+static void getColorRGBA( aiColor3D *pColor, Value *data ) {
+    if( NULL == pColor || NULL == data ) {
+        return;
+    }
+
+    pColor->r = data->getFloat();
+    data = data->getNext();
+    pColor->g = data->getFloat();
+    data = data->getNext();
+    pColor->b = data->getFloat();
+    data = data->getNext();
+}
+
+//------------------------------------------------------------------------------------------------
+enum ColorType {
+    NoneColor = 0,
+    DiffuseColor
+};
+
+//------------------------------------------------------------------------------------------------
+static ColorType getColorType( Identifier *id ) {
+    const int res(strncmp("diffuse", id->m_buffer, id->m_len ) );
+    if( 0 == res ) {
+        return DiffuseColor;
+    }
+
+    return NoneColor;
+}
+
 //------------------------------------------------------------------------------------------------
 void OpenGEXImporter::handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
+    m_currentMaterial = new aiMaterial;
+    m_materialCache.push_back( m_currentMaterial );
+
+    handleNodes( node, pScene );
 
 }
 
 //------------------------------------------------------------------------------------------------
 void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
+    if( NULL == node ) {
+        return;
+    }
 
+    Property *colorProp = node->getProperties();
+    if( NULL != colorProp ) {
+        if( NULL != colorProp->m_id ) {
+            ColorType type( getColorType( colorProp->m_primData ) );
+            if( type == DiffuseColor ) {
+                aiColor3D *col = new aiColor3D;
+                getColorRGBA( col, node->getValue() );
+                m_currentMaterial->AddProperty( col, 1, AI_MATKEY_COLOR_DIFFUSE );
+            }
+        }
+    }
 }
 
 //------------------------------------------------------------------------------------------------

+ 2 - 0
code/OpenGEXImporter.h

@@ -174,6 +174,8 @@ private:
     aiNode *m_currentNode;
     VertexContainer m_currentVertices;
     aiMesh *m_currentMesh;
+    aiMaterial *m_currentMaterial;
+    std::vector<aiMaterial*> m_materialCache;
     std::vector<aiNode*> m_nodeStack;
     std::vector<RefInfo*> m_unresolvedRefStack;
 };