- OpenDDL-Parser: latest greatest.

- Add support of OpenGEX-texture types.
pull/580/head
Kim Kulling 2015-05-31 20:36:55 +02:00
parent ab95b1a3c1
commit 9c26f229a3
5 changed files with 239 additions and 30 deletions

View File

@ -84,7 +84,14 @@ namespace Grammar {
static const std::string DiffuseColorToken = "diffuse"; static const std::string DiffuseColorToken = "diffuse";
static const std::string SpecularColorToken = "specular"; static const std::string SpecularColorToken = "specular";
static const std::string EmissionColorToken = "emission"; static const std::string EmissionColorToken = "emission";
static const std::string DiffuseTextureToken = "diffuse"; 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"; static const char *TextureType = "Texture";
@ -816,12 +823,30 @@ void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pSc
Property *prop = node->findPropertyByName( "attrib" ); Property *prop = node->findPropertyByName( "attrib" );
if( NULL != prop ) { if( NULL != prop ) {
if( NULL != prop->m_value ) { if( NULL != prop->m_value ) {
if( prop->m_value->getString() == Grammar::DiffuseTextureToken ) {
aiString tex;
Value *val( node->getValue() ); Value *val( node->getValue() );
if( NULL != val ) { if( NULL != val ) {
aiString tex;
tex.Set( val->getString() ); tex.Set( val->getString() );
if( prop->m_value->getString() == Grammar::DiffuseTextureToken ) {
m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) ); 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 );
} }
} }
} }

View File

@ -27,8 +27,42 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
BEGIN_ODDLPARSER_NS BEGIN_ODDLPARSER_NS
Value::Value() Value::Iterator::Iterator()
: m_type( ddl_none ) : 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_size( 0 )
, m_data( ddl_nullptr ) , m_data( ddl_nullptr )
, m_next( ddl_nullptr ) { , m_next( ddl_nullptr ) {
@ -230,7 +264,7 @@ Value *ValueAllocator::allocPrimData( Value::ValueType type, size_t len ) {
return ddl_nullptr; return ddl_nullptr;
} }
Value *data = new Value; Value *data = new Value( type );
data->m_type = type; data->m_type = type;
switch( type ) { switch( type ) {
case Value::ddl_bool: case Value::ddl_bool:

View File

@ -37,32 +37,104 @@ struct Reference;
struct Property; struct Property;
struct DataArrayList; 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 { class DLL_ODDLPARSER_EXPORT DDLNode {
public: public:
friend class OpenDDLParser; friend class OpenDDLParser;
/// @brief The child-node-list type.
typedef std::vector<DDLNode*> DllNodeList; typedef std::vector<DDLNode*> DllNodeList;
public: public:
/// @brief The class destructor.
~DDLNode(); ~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 ); void attachParent( DDLNode *parent );
/// @brief Will try to detach a parent node instance, if there is any.
void detachParent(); 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; DDLNode *getParent() const;
/// @brief Returns the child node list.
/// @return The list of child nodes.
const DllNodeList &getChildNodeList() const; 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; const std::string &getType() const;
/// Set the name of the DDLNode instance.
/// @param type [in] The name.
void setName( const std::string &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; 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 ); 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; 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 ); 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 ); 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 ); 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; Value *getValue() const;
/// @brief Set a new DataArrayList.
/// @param val [in] The DataArrayList instance.
void setDataArrayList( DataArrayList *dtArrayList ); void setDataArrayList( DataArrayList *dtArrayList );
/// @brief Returns the DataArrayList.
/// @return The DataArrayList.
DataArrayList *getDataArrayList() const; DataArrayList *getDataArrayList() const;
/// @brief Set a new Reference set.
/// @param val [in] The first value instance of the Reference set.
void setReferences( Reference *refs ); 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; 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 ); static DDLNode *create( const std::string &type, const std::string &name, DDLNode *parent = ddl_nullptr );
private: private:

View File

@ -44,15 +44,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# define DLL_ODDLPARSER_EXPORT # define DLL_ODDLPARSER_EXPORT
#endif // _WIN32 #endif // _WIN32
// Namespace declarations, override this to avoid any conflicts
#define BEGIN_ODDLPARSER_NS namespace ODDLParser { #define BEGIN_ODDLPARSER_NS namespace ODDLParser {
#define END_ODDLPARSER_NS } // namespace ODDLParser #define END_ODDLPARSER_NS } // namespace ODDLParser
#define USE_ODDLPARSER_NS using namespace ODDLParser; #define USE_ODDLPARSER_NS using namespace ODDLParser;
BEGIN_ODDLPARSER_NS BEGIN_ODDLPARSER_NS
// We will use C++11 optional
#ifndef OPENDDL_NO_USE_CPP11 #ifndef OPENDDL_NO_USE_CPP11
// All C++11 constructs
# define ddl_nullptr nullptr # define ddl_nullptr nullptr
#else #else
// Fallback for older compilers
# define ddl_nullptr NULL # define ddl_nullptr NULL
#endif // OPENDDL_NO_USE_CPP11 #endif // OPENDDL_NO_USE_CPP11
@ -65,26 +69,31 @@ struct Reference;
struct Property; struct Property;
struct DataArrayList; 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 #ifdef _WIN32
typedef __int64 int64; typedef signed __int64 int64_impl;
typedef unsigned __int64 uint64; typedef unsigned __int64 uint64_impl;
#else #else
typedef int64_t int64; typedef int64_t int64_impl;
typedef uint64_t uint64; typedef uint64_t uint64_impl;
#endif #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 { enum NameType {
GlobalName, GlobalName, ///< Name is global.
LocalName LocalName ///< Name is local.
}; };
/// @brief Stores a text
struct Text { struct Text {
size_t m_capacity; size_t m_capacity;
size_t m_len; size_t m_len;
@ -124,8 +133,8 @@ struct Text {
return false; return false;
} }
const int res( strncmp( m_buffer, name.c_str(), name.size() ) ); const int res( strncmp( m_buffer, name.c_str(), name.size() ) );
return ( 0 == res );
return ( 0 == res );
} }
bool operator == ( const Text &rhs ) const { bool operator == ( const Text &rhs ) const {
@ -133,7 +142,8 @@ struct Text {
return false; 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 ); return ( 0 == res );
} }
@ -142,6 +152,7 @@ private:
Text &operator = ( const Text & ); Text &operator = ( const Text & );
}; };
/// @brief Stores an OpenDDL-specific identifier type.
struct Identifier { struct Identifier {
Text m_text; Text m_text;
@ -164,6 +175,7 @@ private:
Identifier &operator = ( const Identifier & ); Identifier &operator = ( const Identifier & );
}; };
/// @brief Stores an OpenDDL-specific name
struct Name { struct Name {
NameType m_type; NameType m_type;
Identifier *m_id; Identifier *m_id;
@ -179,6 +191,7 @@ private:
Name &operator = ( const Name& ); Name &operator = ( const Name& );
}; };
/// @brief Stores a bundle of references.
struct Reference { struct Reference {
size_t m_numRefs; size_t m_numRefs;
Name **m_referencedName; 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: private:
Reference( const Reference & ); Reference( const Reference & );
Reference &operator = ( const Reference & ); Reference &operator = ( const Reference & );
}; };
/// @brief Stores a property list.
struct Property { struct Property {
Identifier *m_key; Identifier *m_key;
Value *m_value; Value *m_value;
@ -218,11 +240,19 @@ struct Property {
// empty // empty
} }
~Property() {
m_key = ddl_nullptr;
m_value = ddl_nullptr;
m_ref = ddl_nullptr;;
m_next = ddl_nullptr;;
}
private: private:
Property( const Property & ); Property( const Property & );
Property &operator = ( const Property & ); Property &operator = ( const Property & );
}; };
/// @brief Stores a data array list.
struct DataArrayList { struct DataArrayList {
size_t m_numItems; size_t m_numItems;
Value *m_dataList; Value *m_dataList;
@ -238,9 +268,9 @@ struct DataArrayList {
private: private:
DataArrayList( const DataArrayList & ); DataArrayList( const DataArrayList & );
DataArrayList &operator = ( const DataArrayList & ); DataArrayList &operator = ( const DataArrayList & );
}; };
/// @brief Stores the context of a parsed OpenDDL declaration.
struct Context { struct Context {
DDLNode *m_root; DDLNode *m_root;
@ -249,6 +279,10 @@ struct Context {
// empty // empty
} }
~Context() {
m_root = ddl_nullptr;
}
private: private:
Context( const Context & ); Context( const Context & );
Context &operator = ( const Context & ); Context &operator = ( const Context & );

View File

@ -28,6 +28,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
BEGIN_ODDLPARSER_NS BEGIN_ODDLPARSER_NS
struct ValueAllocator;
///------------------------------------------------------------------------------------------------ ///------------------------------------------------------------------------------------------------
/// @brief This class implements a value. /// @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. /// Values can be single items or lists of items. They are implemented as linked lists.
///------------------------------------------------------------------------------------------------ ///------------------------------------------------------------------------------------------------
class DLL_ODDLPARSER_EXPORT Value { class DLL_ODDLPARSER_EXPORT Value {
friend struct ValueAllocator;
public: 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. /// @brief This enum describes the data type stored in the value.
enum ValueType { enum ValueType {
ddl_none = -1, ///< Nothing specified ddl_none = -1, ///< Nothing specified
@ -57,7 +101,7 @@ public:
ddl_types_max ddl_types_max
}; };
Value(); Value( ValueType type );
~Value(); ~Value();
void setBool( bool value ); void setBool( bool value );
bool getBool(); bool getBool();