diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index cce58d3cd..7065bbe81 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -84,7 +84,14 @@ namespace Grammar { static const std::string DiffuseColorToken = "diffuse"; static const std::string SpecularColorToken = "specular"; static const std::string EmissionColorToken = "emission"; + static const std::string DiffuseTextureToken = "diffuse"; + static const std::string DiffuseSpecularTextureToken = "specular"; + static const std::string SpecularPowerTextureToken = "specular_power"; + static const std::string EmissionTextureToken = "emission"; + static const std::string OpacyTextureToken = "opacity"; + static const std::string TransparencyTextureToken = "transparency"; + static const std::string NormalTextureToken = "normal"; static const char *TextureType = "Texture"; @@ -816,12 +823,30 @@ void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pSc Property *prop = node->findPropertyByName( "attrib" ); if( NULL != prop ) { if( NULL != prop->m_value ) { - if( prop->m_value->getString() == Grammar::DiffuseTextureToken ) { + Value *val( node->getValue() ); + if( NULL != val ) { aiString tex; - Value *val( node->getValue() ); - if( NULL != val ) { - tex.Set( val->getString() ); + tex.Set( val->getString() ); + if( prop->m_value->getString() == Grammar::DiffuseTextureToken ) { m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) ); + } else if( prop->m_value->getString() == Grammar::SpecularPowerTextureToken ) { + m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_SPECULAR( 0 ) ); + + } else if( prop->m_value->getString() == Grammar::EmissionTextureToken ) { + m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_EMISSIVE( 0 ) ); + + } else if( prop->m_value->getString() == Grammar::OpacyTextureToken ) { + m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_OPACITY( 0 ) ); + + } else if( prop->m_value->getString() == Grammar::TransparencyTextureToken ) { + // ToDo! + // m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) ); + } else if( prop->m_value->getString() == Grammar::NormalTextureToken ) { + m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_NORMALS( 0 ) ); + + } + else { + ai_assert( false ); } } } diff --git a/contrib/openddlparser/code/Value.cpp b/contrib/openddlparser/code/Value.cpp index f94ef081f..4106cea2c 100644 --- a/contrib/openddlparser/code/Value.cpp +++ b/contrib/openddlparser/code/Value.cpp @@ -27,8 +27,42 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. BEGIN_ODDLPARSER_NS -Value::Value() -: m_type( ddl_none ) +Value::Iterator::Iterator() +: m_start( ddl_nullptr ) +, m_current( ddl_nullptr ) { + // empty +} + +Value::Iterator::Iterator( Value *start ) +: m_start( start ) +, m_current( start ) { + // empty +} + +Value::Iterator::~Iterator() { + // empty +} + +bool Value::Iterator::hasNext() const { + if( ddl_nullptr == m_current ) { + return false; + } + return ( ddl_nullptr != m_current->getNext() ); +} + +Value *Value::Iterator::getNext() { + if( !hasNext() ) { + return ddl_nullptr; + } + + Value *v( m_current->getNext() ); + m_current = v; + + return v; +} + +Value::Value( ValueType type ) +: m_type( type ) , m_size( 0 ) , m_data( ddl_nullptr ) , m_next( ddl_nullptr ) { @@ -230,7 +264,7 @@ Value *ValueAllocator::allocPrimData( Value::ValueType type, size_t len ) { return ddl_nullptr; } - Value *data = new Value; + Value *data = new Value( type ); data->m_type = type; switch( type ) { case Value::ddl_bool: diff --git a/contrib/openddlparser/include/openddlparser/DDLNode.h b/contrib/openddlparser/include/openddlparser/DDLNode.h index cb69ab357..8fce95f53 100644 --- a/contrib/openddlparser/include/openddlparser/DDLNode.h +++ b/contrib/openddlparser/include/openddlparser/DDLNode.h @@ -37,32 +37,104 @@ struct Reference; struct Property; struct DataArrayList; +/// +/// @ingroup OpenDDLParser +/// @brief This class represents one single instance in the object tree of the parsed OpenDDL-file. +/// +/// A DDLNode represents one leaf in the OpenDDL-node tree. It can have one parent node and multiple children. +/// You can assign special properties to a single DDLNode instance. +/// A node instance can store values via a linked list. You can get the first value from the DDLNode. +/// A node can store data-array-lists and references as well. +/// class DLL_ODDLPARSER_EXPORT DDLNode { public: friend class OpenDDLParser; + /// @brief The child-node-list type. typedef std::vector DllNodeList; public: + /// @brief The class destructor. ~DDLNode(); + + /// @brief Will attach a parent node instance, an older one will be released. + /// @param parent [in] The parent node instance. void attachParent( DDLNode *parent ); + + /// @brief Will try to detach a parent node instance, if there is any. void detachParent(); + + /// @brief Returns the assigned parent node instance, will return ddl_nullptr id no parent is assigned. + /// @return The parent node instance. DDLNode *getParent() const; + + /// @brief Returns the child node list. + /// @return The list of child nodes. const DllNodeList &getChildNodeList() const; - void setType( const std::string &name ); + + /// Set the type of the DDLNode instance. + /// @param type [in] The type. + void setType( const std::string &type ); + + /// @brief Returns the type of the DDLNode instance. + /// @return The type of the DDLNode instance. const std::string &getType() const; + + /// Set the name of the DDLNode instance. + /// @param type [in] The name. void setName( const std::string &name ); + + /// @brief Returns the name of the DDLNode instance. + /// @return The name of the DDLNode instance. const std::string &getName() const; + + /// @brief Set a new property set. + /// @param prop [in] The first element of the property set. void setProperties( Property *prop ); + + /// @brief Returns the first element of the assigned property set. + /// @return The first property of the assigned property set. Property *getProperties() const; + + /// @brief Looks for a given property. + /// @param name [in] The name for the property to look for. + /// @return true, if a corresponding property is assigned to the node, false if not. bool hasProperty( const std::string &name ); + + /// @brief Search for a given property and returns it. Will return ddl_nullptr if no property was found. + /// @param name [in] The name for the property to look for. + /// @return The property or ddl_nullptr if no property was found. Property *findPropertyByName( const std::string &name ); + + /// @brief Set a new value set. + /// @param val [in] The first value instance of the value set. void setValue( Value *val ); + + /// @brief Returns the first element of the assigned value set. + /// @return The first property of the assigned value set. Value *getValue() const; - void setDataArrayList( DataArrayList *dtArrayList ); + + /// @brief Set a new DataArrayList. + /// @param val [in] The DataArrayList instance. + void setDataArrayList( DataArrayList *dtArrayList ); + + /// @brief Returns the DataArrayList. + /// @return The DataArrayList. DataArrayList *getDataArrayList() const; + + /// @brief Set a new Reference set. + /// @param val [in] The first value instance of the Reference set. void setReferences( Reference *refs ); + + /// @brief Returns the first element of the assigned Reference set. + /// @return The first property of the assigned Reference set. Reference *getReferences() const; + + /// @brief The creation method. + /// @param type [in] The DDLNode type. + /// @param name [in] The name for the new DDLNode instance. + /// @param parent [in] The parent node instance or ddl_nullptr if no parent node is there. + /// @return The new created node instance. static DDLNode *create( const std::string &type, const std::string &name, DDLNode *parent = ddl_nullptr ); private: diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h index 6dea65b9c..e5fe77777 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h @@ -44,15 +44,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # define DLL_ODDLPARSER_EXPORT #endif // _WIN32 +// Namespace declarations, override this to avoid any conflicts #define BEGIN_ODDLPARSER_NS namespace ODDLParser { #define END_ODDLPARSER_NS } // namespace ODDLParser #define USE_ODDLPARSER_NS using namespace ODDLParser; BEGIN_ODDLPARSER_NS +// We will use C++11 optional #ifndef OPENDDL_NO_USE_CPP11 + // All C++11 constructs # define ddl_nullptr nullptr #else + // Fallback for older compilers # define ddl_nullptr NULL #endif // OPENDDL_NO_USE_CPP11 @@ -65,26 +69,31 @@ struct Reference; struct Property; struct DataArrayList; -typedef char int8; -typedef short int16; -typedef int int32; -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned int uint32; - #ifdef _WIN32 -typedef __int64 int64; -typedef unsigned __int64 uint64; +typedef signed __int64 int64_impl; +typedef unsigned __int64 uint64_impl; #else -typedef int64_t int64; -typedef uint64_t uint64; +typedef int64_t int64_impl; +typedef uint64_t uint64_impl; #endif +// OpenDDL-specific data typedefs +typedef signed char int8; ///< Signed integer, 1 byte +typedef signed short int16; ///< Signed integer, 2 byte +typedef signed int int32; ///< Signed integer, 4 byte +typedef int64_impl int64; ///< Signed integer, 8 byte +typedef unsigned char uint8; ///< Unsigned integer, 1 byte +typedef unsigned short uint16; ///< Unsigned integer, 2 byte +typedef unsigned int uint32; ///< Unsigned integer, 4 byte +typedef uint64_impl uint64; ///< Unsigned integer, 8 byte + +/// @brief Description of the type of a name. enum NameType { - GlobalName, - LocalName + GlobalName, ///< Name is global. + LocalName ///< Name is local. }; +/// @brief Stores a text struct Text { size_t m_capacity; size_t m_len; @@ -124,8 +133,8 @@ struct Text { return false; } const int res( strncmp( m_buffer, name.c_str(), name.size() ) ); + return ( 0 == res ); - } bool operator == ( const Text &rhs ) const { @@ -133,7 +142,8 @@ struct Text { return false; } - const int res ( strncmp( m_buffer, rhs.m_buffer, m_len ) ); + const int res( strncmp( m_buffer, rhs.m_buffer, m_len ) ); + return ( 0 == res ); } @@ -142,6 +152,7 @@ private: Text &operator = ( const Text & ); }; +/// @brief Stores an OpenDDL-specific identifier type. struct Identifier { Text m_text; @@ -164,6 +175,7 @@ private: Identifier &operator = ( const Identifier & ); }; +/// @brief Stores an OpenDDL-specific name struct Name { NameType m_type; Identifier *m_id; @@ -179,6 +191,7 @@ private: Name &operator = ( const Name& ); }; +/// @brief Stores a bundle of references. struct Reference { size_t m_numRefs; Name **m_referencedName; @@ -199,11 +212,20 @@ struct Reference { } } + ~Reference() { + for( size_t i = 0; i < m_numRefs; i++ ) { + delete m_referencedName[ i ]; + } + m_numRefs = 0; + m_referencedName = ddl_nullptr; + } + private: Reference( const Reference & ); Reference &operator = ( const Reference & ); }; +/// @brief Stores a property list. struct Property { Identifier *m_key; Value *m_value; @@ -211,18 +233,26 @@ struct Property { Property *m_next; Property( Identifier *id ) - : m_key( id ) - , m_value( ddl_nullptr ) - , m_ref( ddl_nullptr ) - , m_next( ddl_nullptr ) { + : m_key( id ) + , m_value( ddl_nullptr ) + , m_ref( ddl_nullptr ) + , m_next( ddl_nullptr ) { // empty } + ~Property() { + m_key = ddl_nullptr; + m_value = ddl_nullptr; + m_ref = ddl_nullptr;; + m_next = ddl_nullptr;; + } + private: Property( const Property & ); Property &operator = ( const Property & ); }; +/// @brief Stores a data array list. struct DataArrayList { size_t m_numItems; Value *m_dataList; @@ -238,9 +268,9 @@ struct DataArrayList { private: DataArrayList( const DataArrayList & ); DataArrayList &operator = ( const DataArrayList & ); - }; +/// @brief Stores the context of a parsed OpenDDL declaration. struct Context { DDLNode *m_root; @@ -249,6 +279,10 @@ struct Context { // empty } + ~Context() { + m_root = ddl_nullptr; + } + private: Context( const Context & ); Context &operator = ( const Context & ); diff --git a/contrib/openddlparser/include/openddlparser/Value.h b/contrib/openddlparser/include/openddlparser/Value.h index 54ccf51ba..fc8cc1ee1 100644 --- a/contrib/openddlparser/include/openddlparser/Value.h +++ b/contrib/openddlparser/include/openddlparser/Value.h @@ -28,6 +28,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. BEGIN_ODDLPARSER_NS +struct ValueAllocator; + ///------------------------------------------------------------------------------------------------ /// @brief This class implements a value. /// @@ -36,7 +38,49 @@ BEGIN_ODDLPARSER_NS /// Values can be single items or lists of items. They are implemented as linked lists. ///------------------------------------------------------------------------------------------------ class DLL_ODDLPARSER_EXPORT Value { + friend struct ValueAllocator; + public: + /// @brief This class implements an iterator through a Value list. + /// + /// When getting a new value you need to know how to iterate through it. The Value::Iterator + /// will help you here: + /// @code + /// Value *val = node->getValue(); + /// Value::Iterator it( val ); + /// while( it.hasNext() ) { + /// Value v( it.getNext ); + /// } + /// @endcode + class DLL_ODDLPARSER_EXPORT Iterator { + public: + /// @brief The default class constructor. + Iterator(); + + /// @brief The class constructor with the start value. + /// @param start [in] The first value for iteration, + Iterator( Value *start ); + + /// @brief The class destructor. + ~Iterator(); + + /// @brief Will return true, if another value is in the list. + /// @return true if another value is there. + bool hasNext() const; + + /// @brief Returns the next item and moves the iterator to it. + /// @return The next value, is ddl_nullptr in case of being the last item. + Value *getNext(); + + private: + Value *m_start; + Value *m_current; + + private: + Iterator( const Iterator & ); + Iterator &operator = ( const Iterator & ); + }; + /// @brief This enum describes the data type stored in the value. enum ValueType { ddl_none = -1, ///< Nothing specified @@ -57,7 +101,7 @@ public: ddl_types_max }; - Value(); + Value( ValueType type ); ~Value(); void setBool( bool value ); bool getBool();