From: <jud...@us...> - 2009-02-11 11:00:35
|
Revision: 352 http://colladamaya.svn.sourceforge.net/colladamaya/?rev=352&view=rev Author: judithschenk Date: 2009-02-11 11:00:27 +0000 (Wed, 11 Feb 2009) Log Message: ----------- Framework: Management of ids and names; COLLADAMaya: start of material import; COLLADASax: end_COLLADA, finish reading document Modified Paths: -------------- branches/nextgen/COLLADAFramework/include/COLLADAFWGeometry.h branches/nextgen/COLLADAFramework/include/COLLADAFWInstanceGeometry.h branches/nextgen/COLLADAFramework/include/COLLADAFWNode.h branches/nextgen/COLLADAFramework/include/COLLADAFWSceneGraphInstance.h branches/nextgen/COLLADAFramework/include/COLLADAFWVisualScene.h branches/nextgen/COLLADAFramework/src/COLLADAFWInstanceGeometry.cpp branches/nextgen/COLLADAMaya/include/COLLADAMayaBaseImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaDocumentImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaGeometryImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaMaterialImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaNode.h branches/nextgen/COLLADAMaya/include/COLLADAMayaVisualSceneImporter.h branches/nextgen/COLLADAMaya/scripts/COLLADAMaya.vcproj branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaGeometryImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaMaterialImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaVisualSceneImporter.cpp branches/nextgen/COLLADASaxFrameworkLoader/include/COLLADASaxFWLFileLoader.h branches/nextgen/COLLADASaxFrameworkLoader/include/COLLADASaxFWLGeometryMaterialIdInfo.h branches/nextgen/COLLADASaxFrameworkLoader/include/COLLADASaxFWLVisualSceneLoader.h branches/nextgen/COLLADASaxFrameworkLoader/src/COLLADASaxFWLFileLoader.cpp branches/nextgen/COLLADASaxFrameworkLoader/src/COLLADASaxFWLLibraryMaterialsLoader.cpp branches/nextgen/COLLADASaxFrameworkLoader/src/COLLADASaxFWLMeshLoader.cpp branches/nextgen/COLLADASaxFrameworkLoader/src/COLLADASaxFWLNodeLoader.cpp Added Paths: ----------- branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h branches/nextgen/COLLADAMaya/src/COLLADAMayaBaseImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaEffectImporter.cpp branches/nextgen/COLLADAMaya/template/ branches/nextgen/COLLADAMaya/template/template.cpp branches/nextgen/COLLADAMaya/template/template.h Modified: branches/nextgen/COLLADAFramework/include/COLLADAFWGeometry.h =================================================================== --- branches/nextgen/COLLADAFramework/include/COLLADAFWGeometry.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAFramework/include/COLLADAFWGeometry.h 2009-02-11 11:00:27 UTC (rev 352) @@ -68,14 +68,6 @@ /** Destructor. */ virtual ~Geometry(); - /** A text string containing the unique identifier of the <geometry> element. This - value must be unique within the instance document. Optional. */ - const String getId () const { return mId; } - - /** A text string containing the unique identifier of the <geometry> element. This - value must be unique within the instance document. Optional. */ - void setId ( const String id ) { mId = id; } - /** A text string containing the name of the <geometry> element. Optional. */ const String getName () const { return mName; } Modified: branches/nextgen/COLLADAFramework/include/COLLADAFWInstanceGeometry.h =================================================================== --- branches/nextgen/COLLADAFramework/include/COLLADAFWInstanceGeometry.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAFramework/include/COLLADAFWInstanceGeometry.h 2009-02-11 11:00:27 UTC (rev 352) @@ -29,13 +29,20 @@ class MaterialBinding { private: + /** The MaterialId of the mesh primitives that should get bind to a material.*/ MaterialId mMaterialId; + /** Unique id of the material that should get bind to the mesh primitives.*/ UniqueId mReferencedMaterial; + + /** The name of the shading engine. */ + String mName; + public: - MaterialBinding(MaterialId materialId, UniqueId referencedMaterial); + MaterialBinding ( const MaterialId& materialId, const UniqueId& referencedMaterial ); + /** @return MaterialId of the mesh primitives that should get bind to a material.*/ COLLADAFW::MaterialId getMaterialId() const { return mMaterialId; } @@ -51,6 +58,10 @@ /** The comparison operator that only compares the material ids.*/ bool operator<( const MaterialBinding& rhs) const { return mMaterialId < rhs.mMaterialId; } + /** The name of the shading engine. */ + const String& getName () const { return mName; } + void setName ( const String& val ) { mName = val; } + private: friend class Array<MaterialBinding>; MaterialBinding(){} Modified: branches/nextgen/COLLADAFramework/include/COLLADAFWNode.h =================================================================== --- branches/nextgen/COLLADAFramework/include/COLLADAFWNode.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAFramework/include/COLLADAFWNode.h 2009-02-11 11:00:27 UTC (rev 352) @@ -57,11 +57,6 @@ */ String mName; - /** A text string containing the unique identifier of the element. This value must be - unique within the instance document. Optional. - */ - String mSid; - /** The type of the <node> element. Valid values are JOINT or NODE. The default is NODE. Optional. */ NodeType mType; @@ -90,12 +85,6 @@ /** Sets the name of the node*/ void setName(const String& name) { mName = name; } - /** Returns the sid of the node*/ - const String& getSid() const { return mSid; } - - /** Sets the id of the node*/ - void setSid(const String& sid) { mSid = sid; } - /** The type of the <node> element. Valid values are JOINT or NODE. The default is NODE. Optional. */ const COLLADAFW::Node::NodeType getType () const { return mType; } Modified: branches/nextgen/COLLADAFramework/include/COLLADAFWSceneGraphInstance.h =================================================================== --- branches/nextgen/COLLADAFramework/include/COLLADAFWSceneGraphInstance.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAFramework/include/COLLADAFWSceneGraphInstance.h 2009-02-11 11:00:27 UTC (rev 352) @@ -28,15 +28,9 @@ */ String mName; - /** A text string containing the unique identifier of the element. This value must be - unique within the instance document. Optional. - */ - String mSid; - /** The unique id of the instantiated object.*/ UniqueId mInstanciatedObjectId; - public: /** Constructor. Creates an instance of an object with UniqueId @a instanciatedObjectId. @@ -51,12 +45,6 @@ /** Sets the name of the node*/ void getName(const String& name) { mName = name; } - /** Returns the sid of the node*/ - const String& getSid() const { return mSid; } - - /** Sets the id of the node*/ - void getSid(const String& sid) { mSid = sid; } - /** Returns the unique id of the instantiated object.*/ const UniqueId& getInstanciatedObjectId() const { return mInstanciatedObjectId; } Modified: branches/nextgen/COLLADAFramework/include/COLLADAFWVisualScene.h =================================================================== --- branches/nextgen/COLLADAFramework/include/COLLADAFWVisualScene.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAFramework/include/COLLADAFWVisualScene.h 2009-02-11 11:00:27 UTC (rev 352) @@ -30,6 +30,7 @@ NodePointerArray mRootNodes; public: + VisualScene(); virtual ~VisualScene(); Modified: branches/nextgen/COLLADAFramework/src/COLLADAFWInstanceGeometry.cpp =================================================================== --- branches/nextgen/COLLADAFramework/src/COLLADAFWInstanceGeometry.cpp 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAFramework/src/COLLADAFWInstanceGeometry.cpp 2009-02-11 11:00:27 UTC (rev 352) @@ -14,11 +14,13 @@ namespace COLLADAFW { + // ---------------------------------- InstanceGeometry::InstanceGeometry( UniqueId instanciatedGeometryId ) : SceneGraphInstance(instanciatedGeometryId) { } + // ---------------------------------- InstanceGeometry::InstanceGeometry( const InstanceGeometry& pre ) : SceneGraphInstance(pre) , mMaterialBindings() @@ -30,12 +32,13 @@ mMaterialBindings[i] = pre.mMaterialBindings[i]; } - //-------------------------------------------------------------------- + // ---------------------------------- InstanceGeometry::~InstanceGeometry() { } - InstanceGeometry::MaterialBinding::MaterialBinding( MaterialId materialId, UniqueId referencedMaterial ) + // ---------------------------------- + InstanceGeometry::MaterialBinding::MaterialBinding ( const MaterialId& materialId, const UniqueId& referencedMaterial ) : mMaterialId(materialId) , mReferencedMaterial(referencedMaterial) { Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaBaseImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaBaseImporter.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaBaseImporter.h 2009-02-11 11:00:27 UTC (rev 352) @@ -31,7 +31,10 @@ This is the base class for all importers. */ class BaseImporter { + public: + typedef std::map<COLLADAFW::UniqueId, String> UniqueIdNamesMap; + private: /** Pointer to the current document importer. */ @@ -53,14 +56,7 @@ * For example, 1.0 for the name "meter"; 1000 for the name "kilometer"; * 0.3048 for the name "foot". */ - MayaDM::double3 toLinearUnit ( const MayaDM::double3& val ) - { - if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::X_UP ) - return ( MayaDM::double3 ( toLinearUnit ( val[1] ), toLinearUnit ( val[0]*(-1) ), toLinearUnit ( val[2] ) ) ); - else if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::Z_UP ) - return ( MayaDM::double3 ( toLinearUnit ( val[0] ), toLinearUnit ( val[2] ), toLinearUnit ( val[1]*(-1) ) ) ); - else return ( MayaDM::double3 ( toLinearUnit ( val[0] ), toLinearUnit ( val[1] ), toLinearUnit ( val[2] ) ) ); - } + MayaDM::double3 toLinearUnit ( const MayaDM::double3& val ); /** * Converts the given value to the linear unit in meters. @@ -68,14 +64,7 @@ * For example, 1.0 for the name "meter"; 1000 for the name "kilometer"; * 0.3048 for the name "foot". */ - MVector toLinearUnit ( const MVector& val ) - { - if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::X_UP ) - return ( MVector ( toLinearUnit ( val[1] ), toLinearUnit ( val[0]*(-1) ), toLinearUnit ( val[2] ) ) ); - else if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::Z_UP ) - return ( MVector ( toLinearUnit ( val[0] ), toLinearUnit ( val[2] ), toLinearUnit ( val[1]*(-1) ) ) ); - else return ( MVector ( toLinearUnit ( val[0] ), toLinearUnit ( val[1] ), toLinearUnit ( val[2] ) ) ); - } + MVector toLinearUnit ( const MVector& val ); /** * Converts the given value to the linear unit in meters. @@ -83,27 +72,7 @@ * For example, 1.0 for the name "meter"; 1000 for the name "kilometer"; * 0.3048 for the name "foot". */ - void toLinearUnit ( const double val0, const double val1, const double val2, COLLADABU::Math::Vector3& retVal ) - { - if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::X_UP ) - { - retVal [0] = toLinearUnit ( val1 ); - retVal [1] = toLinearUnit ( val0*(-1) ); - retVal [2] = toLinearUnit ( val2 ); - } - else if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::Z_UP ) - { - retVal [0] = toLinearUnit ( val0 ); - retVal [1] = toLinearUnit ( val2 ); - retVal [2] = toLinearUnit ( val1*(-1) ); - } - else - { - retVal [0] = toLinearUnit ( val0 ); - retVal [1] = toLinearUnit ( val1 ); - retVal [2] = toLinearUnit ( val2 ); - } - } + void toLinearUnit ( const double val0, const double val1, const double val2, COLLADABU::Math::Vector3& retVal ); protected: Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaDocumentImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaDocumentImporter.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaDocumentImporter.h 2009-02-11 11:00:27 UTC (rev 352) @@ -26,6 +26,8 @@ #include "COLLADAFWGeometry.h" #include "COLLADAFWMaterial.h" #include "COLLADAFWEffect.h" + +#include "MayaDMMesh.h" #include <set> @@ -34,9 +36,13 @@ { class VisualSceneImporter; class GeometryImporter; + class MaterialImporter; + class EffectImporter; + typedef std::map<COLLADAFW::UniqueId, std::set<const COLLADAFW::UniqueId>> UniqueIdUniqueIdsMap; typedef std::map<COLLADAFW::UniqueId, MayaNode> UniqueIdMayaNodesMap; + typedef std::map<COLLADAFW::UniqueId, MayaDM::Mesh> UniqueIdMayaDMMeshMap; /** The main importer class. This class imports all data of the scene. */ @@ -81,6 +87,15 @@ /** Pointer to the geometry importer. */ GeometryImporter* mGeometryImporter; + /** Pointer to the geometry importer. */ + MaterialImporter* mMaterialImporter; + + /** Pointer to the geometry importer. */ + EffectImporter* mEffectImporter; + + /** The variable tells, how many times the document is read. */ + size_t mDocumentReads; + public: /** Constructor. */ @@ -118,12 +133,19 @@ /** Pointer to the visual scene importer. */ VisualSceneImporter* getVisualSceneImporter () { return mVisualSceneImporter; } const VisualSceneImporter* getVisualSceneImporter () const { return mVisualSceneImporter; } - void setVisualSceneImporter ( VisualSceneImporter* val ) { mVisualSceneImporter = val; } /** Pointer to the geometry importer. */ + GeometryImporter* getGeometryImporter () { return mGeometryImporter; } const GeometryImporter* getGeometryImporter () const { return mGeometryImporter; } - void setGeometryImporter ( GeometryImporter* val ) { mGeometryImporter = val; } + /** Pointer to the geometry importer. */ + MaterialImporter* getMaterialImporter () { return mMaterialImporter; } + const MaterialImporter* getMaterialImporter () const { return mMaterialImporter; } + + /** Pointer to the geometry importer. */ + EffectImporter* getEffectImporter () { return mEffectImporter; } + const EffectImporter* getEffectImporter () const { return mEffectImporter; } + /** This method will be called if an error in the loading process occurred and the loader cannot continue to to load. The writer should undo all operations that have been performed. @param errorMessage A message containing informations about the error that occurred. @@ -133,8 +155,10 @@ /** This is the method called. The writer hast to prepare to receive data.*/ virtual void start (); - /** This method is called after the last write method. - No other methods will be called after this.*/ + /** + * This method is called after the last write method. No other methods will be called after this. + * After the read of the collada document, the connections can be written into the maya file. + */ virtual void finish (); /** Start the import of the model. @@ -147,6 +171,7 @@ void getCurrentDate ( std::stringstream& curDate ); + /** Returns the type of the current up axis. */ const COLLADAFW::FileInfo::UpAxisType& getUpAxisType () const { return mUpAxisType; } /** @@ -171,11 +196,11 @@ /** When this method is called, the writer must write the material. @return The writer should return true, if writing succeeded, false otherwise.*/ - virtual bool writeMaterial( const COLLADAFW::Material* material ) { return true; } + virtual bool writeMaterial ( const COLLADAFW::Material* material ); /** When this method is called, the writer must write the effect. @return The writer should return true, if writing succeeded, false otherwise.*/ - virtual bool writeEffect( const COLLADAFW::Effect* effect ) { return true; } + virtual bool writeEffect ( const COLLADAFW::Effect* effect ); private: Added: branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h (rev 0) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h 2009-02-11 11:00:27 UTC (rev 352) @@ -0,0 +1,107 @@ +/* + Copyright (c) 2008 NetAllied Systems GmbH + + This file is part of COLLADAFramework. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __COLLADAMAYA_EFFECTIMPORTER_H__ +#define __COLLADAMAYA_EFFECTIMPORTER_H__ + +#include "COLLADAFWPrerequisites.h" +#include "COLLADAMayaBaseImporter.h" + +#include "COLLADABUIDList.h" + + +namespace COLLADAMaya +{ + + /** TODO Documentation */ + class EffectImporter : public BaseImporter + { + public: + + typedef std::map<COLLADAFW::UniqueId, MayaDM::DependNode*> UniqueIdMayaDependNodeMap; + typedef std::map<COLLADAFW::UniqueId, std::vector<MayaDM::DependNode*>> UniqueIdDependNodesMap; + + private: + + /** The standard name for a effect without name. */ + static const String EFFECT_NAME; + + private: + + /** + * The list of the unique maya effect names. + */ + COLLADABU::IDList mEffectIdList; + + /** + * The map holds the unique ids of the nodes to the maya effect name. + */ + UniqueIdNamesMap mMayaEffectNamesMap; + + /** + * The map holds the maya effect objects. + */ + UniqueIdMayaDependNodeMap mMayaEffectMap; + + /** + * One effect can have multiple materials. But one material just one effect. + */ + UniqueIdDependNodesMap mEffectMaterialsMap; + + public: + + /** Constructor. */ + EffectImporter ( DocumentImporter* documentImporter ); + + /** Destructor. */ + virtual ~EffectImporter (); + + /** Imports the given material. */ + bool importEffect ( const COLLADAFW::Effect* effect ); + + /** + * The map holds the maya material objects. + */ + const UniqueIdMayaDependNodeMap& getMayaEffectMap () const { return mMayaEffectMap; } + + /** + * The map holds the maya material objects. + */ + MayaDM::DependNode* findMayaEffect ( const COLLADAFW::UniqueId& val ) const; + + /** + * The map holds the maya material objects. + */ + void appendEffect ( const COLLADAFW::UniqueId& id, MayaDM::DependNode* effectNode ); + + /** + * One effect can have multiple materials. But one material just one effect. + */ + const UniqueIdDependNodesMap getEffectMaterialsMap () const { return mEffectMaterialsMap; } + + + private: + + /** + * Imports a lambert shader effect. + */ + void importLambertShader ( const COLLADAFW::Effect* effect ); + + /** Disable default copy ctor. */ + EffectImporter( const EffectImporter& pre ); + + /** Disable default assignment operator. */ + const EffectImporter& operator= ( const EffectImporter& pre ); + + }; + +} // namespace COLLADAMAYA + +#endif // __COLLADAMAYA_EFFECTIMPORTER_H__ Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaGeometryImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaGeometryImporter.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaGeometryImporter.h 2009-02-11 11:00:27 UTC (rev 352) @@ -40,6 +40,9 @@ private: + /** The standard name for geometry without name. */ + static const String GEOMETRY_NAME; + /** * The list of the unique maya mesh node names. */ @@ -50,6 +53,11 @@ */ UniqueIdMayaNodesMap mMayaMeshNodesMap; + /** + * The map holds the unique ids of the nodes to the specific nodes. + */ + UniqueIdMayaDMMeshMap mMayaDMMeshNodesMap; + public: /** Constructor. */ @@ -61,8 +69,6 @@ /** Imports the geometry element. */ bool importGeometry ( const COLLADAFW::Geometry* geometry ); - private: - /** * The map holds the unique ids of the nodes to the maya specific nodes. */ @@ -73,6 +79,11 @@ */ MayaNode* getMayaMeshNode ( const COLLADAFW::UniqueId& uniqueId ); + MayaDM::Mesh* getMayaDMMeshNode ( const COLLADAFW::UniqueId& uniqueId ); + const MayaDM::Mesh* getMayaDMMeshNode ( const COLLADAFW::UniqueId& uniqueId ) const; + + private: + /** * Imports the data of the current mesh element. */ @@ -83,9 +94,18 @@ */ void createMesh ( const COLLADAFW::Mesh* mesh, - MayaNode* parentMayaNode ); + MayaNode* parentMayaNode, + size_t numNodeInstances ); /** + * Create the object group instances and the object groups and write it into the maya file. + */ + void writeObjectGroups ( + const COLLADAFW::Mesh* mesh, + MayaDM::Mesh &meshNode, + size_t numNodeInstances ); + + /** * Iterates over the mesh primitives and reads the edge indices. */ void getEdgeIndices ( @@ -234,6 +254,7 @@ const COLLADAFW::Edge& edge, const std::map<COLLADAFW::Edge,size_t>& edgeIndicesMap, int& edgeIndex ); + }; } Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaMaterialImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaMaterialImporter.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaMaterialImporter.h 2009-02-11 11:00:27 UTC (rev 352) @@ -19,14 +19,43 @@ #include "COLLADAMayaStableHeaders.h" #include "COLLADAMayaBaseImporter.h" +#include "COLLADABUIDList.h" +#include "MayaDMDependNode.h" + + namespace COLLADAMaya { /** Declares the importer class for import materials. */ class MaterialImporter : public BaseImporter { + public: + typedef std::map<COLLADAFW::UniqueId, MayaDM::DependNode*> UniqueIdMayaMaterialMap; + + private: + + /** The standard name for a material without name. */ + static const String MATERIAL_NAME; + + private: + + /** + * The list of the unique maya material names. + */ + COLLADABU::IDList mMaterialIdList; + + /** + * The map holds the unique ids of the nodes to the maya material name. + */ + UniqueIdNamesMap mMayaMaterialNamesMap; + + /** + * The map holds the maya material objects. + */ + UniqueIdMayaMaterialMap mMayaMaterialMap; + public: /** Constructor. */ @@ -35,14 +64,25 @@ /** Destructor. */ virtual ~MaterialImporter () {} - /** Imports all materials from the current collada document. */ - void importMaterials(); + /** Imports the given material. */ + bool importMaterial ( const COLLADAFW::Material* material ); - private: + /** + * The map holds the maya material objects. + */ + const UniqueIdMayaMaterialMap& getMayaMaterialMap () const { return mMayaMaterialMap; } -// /** Imports the current material into the maya scene. */ -// void importMaterial ( domMaterial& material ); + /** + * The map holds the maya material objects. + */ + MayaDM::DependNode* findMayaMaterial ( const COLLADAFW::UniqueId& val ) const; + /** + * The map holds the maya material objects. + */ + void appendMaterial ( const COLLADAFW::UniqueId& id, MayaDM::DependNode* materialNode ); + + }; } Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaNode.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaNode.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaNode.h 2009-02-11 11:00:27 UTC (rev 352) @@ -8,6 +8,9 @@ namespace COLLADAMaya { + /** + * This class exist to have the node path for a node. + */ class MayaNode { private: Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaVisualSceneImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaVisualSceneImporter.h 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaVisualSceneImporter.h 2009-02-11 11:00:27 UTC (rev 352) @@ -21,11 +21,14 @@ #include "COLLADAMayaNode.h" #include "MayaDMTransform.h" +#include "MayaDMShadingEngine.h" +#include "MayaDMMaterialInfo.h" #include "COLLADAFWVisualScene.h" #include "COLLADAFWSkew.h" #include "COLLADABUIDList.h" + #include "Math/COLLADABUMathUtils.h" #include "Math/COLLADABUMathMatrix4.h" #include "Math/COLLADABUMathQuaternion.h" @@ -43,6 +46,48 @@ private: + class ShaderData + { + private: + MayaDM::ShadingEngine* mShadingEngine; + MayaDM::MaterialInfo* mMaterialInfo; + + public: + ShaderData () : mShadingEngine (0), mMaterialInfo (0) {} + ShaderData ( + MayaDM::ShadingEngine* shadingEngine, + MayaDM::MaterialInfo* materialInfo ) + : mShadingEngine ( shadingEngine ) + , mMaterialInfo ( materialInfo ) + {} + virtual ~ShaderData() {} + + MayaDM::ShadingEngine* getShadingEngine () const { return mShadingEngine; } + MayaDM::MaterialInfo* getMaterialInfo () const { return mMaterialInfo; } + + private: + /** Disable default copy ctor. */ + ShaderData( const ShaderData& pre ); + /** Disable default assignment operator. */ + const ShaderData& operator= ( const ShaderData& pre ); + + }; + + typedef std::map<COLLADAFW::MaterialId, ShaderData*> ShaderDataMap; + + private: + + /** The standard name for a transform node without name. */ + static const String TRANSFORM_NODE_NAME; + + /** The standard name for a shading engine. */ + static const String SHADING_ENGINE_NAME; + + /** The standard name for a material info. */ + static const String MATERIAL_INFO_NAME; + + private: + /** * The list of the unique maya transform node names. */ @@ -59,6 +104,17 @@ */ UniqueIdMayaNodesMap mMayaTransformNodesMap; + /** + * The list of the unique maya shading engine names. + */ + COLLADABU::IDList mShadingEngineIdList; + COLLADABU::IDList mMaterialInfoIdList; + + /** + * The map with the unique ids of the shading engine to the shading engines itself. + */ + ShaderDataMap mShaderDataMap; + /* * Helper class, to handle the transformations. */ @@ -122,13 +178,6 @@ */ bool importVisualScene ( const COLLADAFW::VisualScene* visualScene ); - /* - * Imports the data of the current node. - */ - void importNode ( - const COLLADAFW::Node* rootNode, - const COLLADAFW::UniqueId* parentNodeId = NULL ); - /** * The map holds the unique ids of the nodes to the full node pathes (contains the name). */ @@ -149,6 +198,13 @@ private: + /* + * Imports the data of the current node. + */ + void importNode ( + const COLLADAFW::Node* rootNode, + const COLLADAFW::UniqueId* parentNodeId = NULL ); + /** * Save the transformation ids to the geometry ids. */ @@ -157,6 +213,11 @@ MayaDM::Transform* transformNode ); /** + * Read the shading engines. + */ + void readMaterialInstances ( const COLLADAFW::InstanceGeometry* instanceGeometry ); + + /** * Handle the node instances. */ bool readNodeInstances ( const COLLADAFW::Node* node ); @@ -215,6 +276,29 @@ */ void skewValuesToMayaMatrix ( const COLLADAFW::Skew* skew, MMatrix& matrix ) const; + /** + * The list of the unique maya shading engine names. + */ + const COLLADABU::IDList& getShadingEngineIdList () const { return mShadingEngineIdList; } + + /** + * The map with the unique ids of the shading engine to the shading engines itself. + */ + const ShaderDataMap& getShadingEnginesMap () const { return mShaderDataMap; } + + /** + * The map with the unique ids of the shading engine to the shading engines itself. + */ + ShaderData* findShaderData ( const COLLADAFW::MaterialId& val ); + + /** + * The map with the unique ids of the shading engine to the shading engines itself. + */ + void appendShaderData ( + const COLLADAFW::MaterialId& val, + MayaDM::ShadingEngine* shadingEngine, + MayaDM::MaterialInfo* materialInfo ); + }; } Modified: branches/nextgen/COLLADAMaya/scripts/COLLADAMaya.vcproj =================================================================== --- branches/nextgen/COLLADAMaya/scripts/COLLADAMaya.vcproj 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/scripts/COLLADAMaya.vcproj 2009-02-11 11:00:27 UTC (rev 352) @@ -2671,6 +2671,10 @@ Name="Importers" > <File + RelativePath="..\src\COLLADAMayaBaseImporter.cpp" + > + </File> + <File RelativePath="..\src\COLLADAMayaDocumentImporter.cpp" > <FileConfiguration @@ -2738,13 +2742,6 @@ /> </FileConfiguration> <FileConfiguration - Name="ReleasePlugin2009|Win32" - > - <Tool - Name="VCCLCompilerTool" - /> - </FileConfiguration> - <FileConfiguration Name="ReleasePlugin2009|x64" ExcludedFromBuild="true" > @@ -2858,6 +2855,10 @@ </FileConfiguration> </File> <File + RelativePath="..\src\COLLADAMayaEffectImporter.cpp" + > + </File> + <File RelativePath="..\src\COLLADAMayaGeometryImporter.cpp" > <FileConfiguration @@ -2925,13 +2926,6 @@ /> </FileConfiguration> <FileConfiguration - Name="ReleasePlugin2009|Win32" - > - <Tool - Name="VCCLCompilerTool" - /> - </FileConfiguration> - <FileConfiguration Name="ReleasePlugin2009|x64" ExcludedFromBuild="true" > @@ -3241,7 +3235,6 @@ </FileConfiguration> <FileConfiguration Name="DebugConsole2009|Win32" - ExcludedFromBuild="true" > <Tool Name="VCCLCompilerTool" @@ -3344,13 +3337,6 @@ /> </FileConfiguration> <FileConfiguration - Name="ReleasePlugin2009|Win32" - > - <Tool - Name="VCCLCompilerTool" - /> - </FileConfiguration> - <FileConfiguration Name="ReleasePlugin2009|x64" ExcludedFromBuild="true" > @@ -4349,6 +4335,10 @@ </FileConfiguration> </File> <File + RelativePath="..\include\COLLADAMayaEffectImporter.h" + > + </File> + <File RelativePath="..\include\COLLADAMayaGeometryImporter.h" > <FileConfiguration @@ -4767,7 +4757,6 @@ </FileConfiguration> <FileConfiguration Name="DebugConsole2009|Win32" - ExcludedFromBuild="true" > <Tool Name="VCCustomBuildTool" Added: branches/nextgen/COLLADAMaya/src/COLLADAMayaBaseImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaBaseImporter.cpp (rev 0) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaBaseImporter.cpp 2009-02-11 11:00:27 UTC (rev 352) @@ -0,0 +1,50 @@ +#include "COLLADAMayaStableHeaders.h" +#include "COLLADAMayaBaseImporter.h" + +namespace COLLADAMaya +{ + + //----------------------------- + MayaDM::double3 BaseImporter::toLinearUnit ( const MayaDM::double3& val ) + { + if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::X_UP ) + return ( MayaDM::double3 ( toLinearUnit ( val[1] ), toLinearUnit ( val[0]*(-1) ), toLinearUnit ( val[2] ) ) ); + else if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::Z_UP ) + return ( MayaDM::double3 ( toLinearUnit ( val[0] ), toLinearUnit ( val[2] ), toLinearUnit ( val[1]*(-1) ) ) ); + else return ( MayaDM::double3 ( toLinearUnit ( val[0] ), toLinearUnit ( val[1] ), toLinearUnit ( val[2] ) ) ); + } + + //----------------------------- + MVector BaseImporter::toLinearUnit ( const MVector& val ) + { + if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::X_UP ) + return ( MVector ( toLinearUnit ( val[1] ), toLinearUnit ( val[0]*(-1) ), toLinearUnit ( val[2] ) ) ); + else if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::Z_UP ) + return ( MVector ( toLinearUnit ( val[0] ), toLinearUnit ( val[2] ), toLinearUnit ( val[1]*(-1) ) ) ); + else return ( MVector ( toLinearUnit ( val[0] ), toLinearUnit ( val[1] ), toLinearUnit ( val[2] ) ) ); + } + + //----------------------------- + void BaseImporter::toLinearUnit ( const double val0, const double val1, const double val2, COLLADABU::Math::Vector3& retVal ) + { + if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::X_UP ) + { + retVal [0] = toLinearUnit ( val1 ); + retVal [1] = toLinearUnit ( val0*(-1) ); + retVal [2] = toLinearUnit ( val2 ); + } + else if ( mDocumentImporter->getUpAxisType () == COLLADAFW::FileInfo::Z_UP ) + { + retVal [0] = toLinearUnit ( val0 ); + retVal [1] = toLinearUnit ( val2 ); + retVal [2] = toLinearUnit ( val1*(-1) ); + } + else + { + retVal [0] = toLinearUnit ( val0 ); + retVal [1] = toLinearUnit ( val1 ); + retVal [2] = toLinearUnit ( val2 ); + } + } + +} // namespace COLLADAMaya Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp 2009-02-11 11:00:27 UTC (rev 352) @@ -18,6 +18,7 @@ #include "COLLADAMayaReferenceManager.h" #include "COLLADAMayaImportOptions.h" #include "COLLADAMayaMaterialImporter.h" +#include "COLLADAMayaEffectImporter.h" #include "COLLADAMayaGeometryImporter.h" #include "COLLADAMayaCameraImporter.h" #include "COLLADAMayaVisualSceneImporter.h" @@ -44,12 +45,15 @@ , mFile ( 0 ) , mVisualSceneImporter (0) , mGeometryImporter (0) + , mMaterialImporter (0) + , mEffectImporter (0) , mSceneGraphWritten ( false ) , mGeometryWritten ( false ) , mAssetWritten ( false ) , mSceneGraphRead ( false ) , mGeometryRead ( false ) , mLinearUnitMeter (1) + , mDocumentReads (0) { } @@ -70,6 +74,8 @@ mVisualSceneImporter = new VisualSceneImporter ( this ); mGeometryImporter = new GeometryImporter ( this ); + mMaterialImporter = new MaterialImporter ( this ); + mEffectImporter = new EffectImporter ( this ); // Get the sceneID (assign a name to the scene) MString sceneName = MFileIO::currentFile (); @@ -84,6 +90,8 @@ { delete mVisualSceneImporter; delete mGeometryImporter; + delete mMaterialImporter; + delete mEffectImporter; } //----------------------------- @@ -163,8 +171,17 @@ //----------------------------- void DocumentImporter::finish () { - // Close the file. - if ( mFile != 0 ) fclose ( mFile ); + // If the last read is ready, we can write the connections and close the file. + --mDocumentReads; + if ( mDocumentReads == 0 ) + { + // TODO After the read of the collada document, + // the connections can be written into the maya file. + + + // Close the file + if ( mFile != 0 ) fclose ( mFile ); + } } //----------------------------- @@ -275,6 +292,8 @@ COLLADAFW::Root root ( &loader, this ); String filename = getColladaFilename (); String fileUriString = URI::nativePathToUri ( filename ); + + ++mDocumentReads; root.loadDocument ( fileUriString ); } @@ -339,4 +358,33 @@ // TODO return false; } + + //----------------------------- + bool DocumentImporter::writeMaterial ( const COLLADAFW::Material* material ) + { + bool retValue = false; + + // Create the file, if not already done. + if ( mFile == 0 ) start(); + + retValue = mMaterialImporter->importMaterial ( material ); + mGeometryWritten = true; + + return retValue; + } + + //----------------------------- + bool DocumentImporter::writeEffect ( const COLLADAFW::Effect* effect ) + { + bool retValue = false; + + // Create the file, if not already done. + if ( mFile == 0 ) start(); + + retValue = mEffectImporter->importEffect ( effect ); + mGeometryWritten = true; + + return retValue; + } + } \ No newline at end of file Added: branches/nextgen/COLLADAMaya/src/COLLADAMayaEffectImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaEffectImporter.cpp (rev 0) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaEffectImporter.cpp 2009-02-11 11:00:27 UTC (rev 352) @@ -0,0 +1,115 @@ +/* + Copyright (c) 2008 NetAllied Systems GmbH + + This file is part of COLLADAFramework. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#include "COLLADAMayaStableHeaders.h" +#include "COLLADAMayaEffectImporter.h" + +#include "MayaDMLambert.h" + + +namespace COLLADAMaya +{ + + const String EffectImporter::EFFECT_NAME = "Effect"; + + //------------------------------ + EffectImporter::EffectImporter ( DocumentImporter* documentImporter ) + : BaseImporter ( documentImporter ) + {} + + //------------------------------ + EffectImporter::~EffectImporter() + {} + + //------------------------------ + bool EffectImporter::importEffect ( const COLLADAFW::Effect* effect ) + { + const COLLADAFW::CommonEffectPointerArray& commonEffects = effect->getCommonEffects (); + size_t numCommonEffects = commonEffects.getCount (); + for ( size_t i=0; i<numCommonEffects; ++i ) + { + COLLADAFW::EffectCommon* commonEffect = commonEffects [i]; + const COLLADAFW::EffectCommon::ShaderType& shaderType = commonEffect->getShaderType (); + switch ( shaderType ) + { + case COLLADAFW::EffectCommon::SHADER_BLINN: + break; + case COLLADAFW::EffectCommon::SHADER_CONSTANT: + break; + case COLLADAFW::EffectCommon::SHADER_PHONG: + break; + case COLLADAFW::EffectCommon::SHADER_LAMBERT: + importLambertShader ( effect ); + break; + case COLLADAFW::EffectCommon::SHADER_UNKNOWN: + default: + // Standard shader (lambert?) + break; + } + } + + return true; + } + + //------------------------------ + void EffectImporter::importLambertShader ( const COLLADAFW::Effect* effect ) + { + // Get the material name. + String effectName ( effect->getName () ); + if ( COLLADABU::Utils::equals ( effectName, COLLADABU::Utils::EMPTY_STRING ) ) + effectName = EFFECT_NAME; + effectName = mEffectIdList.addId ( effectName ); + + const COLLADAFW::UniqueId& effectId = effect->getUniqueId (); + mMayaEffectNamesMap [effectId] = effectName; + + const COLLADAFW::Color& color = effect->getStandardColor (); + + FILE* file = getDocumentImporter ()->getFile (); + MayaDM::Lambert* lambert = new MayaDM::Lambert ( file, effectName ); + + appendEffect ( effectId, lambert ); + + // TODO + // Find all geometries, which use this effect and create the connections. + MaterialImporter* materialImporter = getDocumentImporter ()->getMaterialImporter (); +// std::vector<COLLADAFW::UniqueId>& materials = materialImporter->findEffectMaterials ( effectId ); +// +// // Iterate over the materials and get all geometries, which use it. +// size_t numMaterials = materials.size (); +// for ( size_t i=0; i<numMaterials; ++i ) +// { +// COLLADAFW::UniqueId& materialId = materials [i]; +// +// // Get the geometries, which use this material +// VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter (); +// visualSceneImporter->f +// } + + } + + // -------------------------- + MayaDM::DependNode* EffectImporter::findMayaEffect ( const COLLADAFW::UniqueId& val ) const + { + UniqueIdMayaDependNodeMap::const_iterator it = mMayaEffectMap.find ( val ); + if ( it != mMayaEffectMap.end () ) + { + return it->second; + } + return 0; + } + + // -------------------------- + void EffectImporter::appendEffect ( const COLLADAFW::UniqueId& id, MayaDM::DependNode* effectNode ) + { + mMayaEffectMap [id] = effectNode; + } + +} // namespace COLLADAMaya Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaGeometryImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaGeometryImporter.cpp 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaGeometryImporter.cpp 2009-02-11 11:00:27 UTC (rev 352) @@ -25,7 +25,6 @@ #pragma warning(disable:4172) #include "MayaDMTransform.h" -#include "MayaDMPolyCube.h" #include "MayaDMCommands.h" #include "COLLADAFWPolygons.h" @@ -37,6 +36,9 @@ namespace COLLADAMaya { + const String GeometryImporter::GEOMETRY_NAME = "Geometry"; + + // -------------------------------------------- GeometryImporter::GeometryImporter( DocumentImporter* documentImporter ) : BaseImporter ( documentImporter ) @@ -75,17 +77,17 @@ void GeometryImporter::importMesh ( const COLLADAFW::Mesh* mesh ) { // Get the unique framework mesh id - const COLLADAFW::UniqueId& meshUniqueId = mesh->getUniqueId (); + const COLLADAFW::UniqueId& geometryId = mesh->getUniqueId (); // Get the transform node of the current mesh. DocumentImporter* documentImporter = getDocumentImporter (); VisualSceneImporter* visualSceneImporter = documentImporter->getVisualSceneImporter (); - // Get all visual scene nodes, which use this geometry an make the parent connection + // Get all visual scene nodes, which use this geometry and make the parent connections. const std::set<const COLLADAFW::UniqueId>* transformNodesSet = - visualSceneImporter->getGeometryTransformIds ( meshUniqueId ); - size_t numNodes = transformNodesSet->size (); + visualSceneImporter->getGeometryTransformIds ( geometryId ); + size_t numNodeInstances = transformNodesSet->size (); std::set<const COLLADAFW::UniqueId>::const_iterator nodesIter = transformNodesSet->begin (); while ( nodesIter != transformNodesSet->end () ) { @@ -98,7 +100,7 @@ if ( nodesIter == transformNodesSet->begin() ) { // Create the current mesh node. - createMesh ( mesh, mayaTransformNode ); + createMesh ( mesh, mayaTransformNode, numNodeInstances ); } else { @@ -122,14 +124,13 @@ // -------------------------------------------- void GeometryImporter::createMesh ( const COLLADAFW::Mesh* mesh, - MayaNode* mayaTransformNode ) + MayaNode* mayaTransformNode, + size_t numNodeInstances ) { // Create a unique name. String meshName = mesh->getName (); if ( COLLADABU::Utils::equals ( meshName, "" ) ) - meshName = mesh->getId (); - if ( COLLADABU::Utils::equals ( meshName, "" ) ) - meshName = "Mesh"; + meshName = GEOMETRY_NAME; meshName = mMeshNodeIdList.addId ( meshName ); // Create a maya node object of the current node and push it into the map. @@ -144,7 +145,12 @@ // Create the current mesh node. FILE* file = getDocumentImporter ()->getFile (); MayaDM::Mesh meshNode ( file, meshName, transformNodePath ); + mMayaDMMeshNodesMap [uniqueId] = meshNode; + // TODO Writes the object groups for every mesh primitive and + // gets all shader engines, which are used by the primitive elements of the mesh. + writeObjectGroups ( mesh, meshNode, numNodeInstances ); + // Write the vertex positions. // Just write the values, they will be referenced from the edges and the faces. writeVertexPositions ( mesh, meshNode ); @@ -181,6 +187,72 @@ } // -------------------------------------------- + void GeometryImporter::writeObjectGroups ( + const COLLADAFW::Mesh* mesh, + MayaDM::Mesh &meshNode, + size_t numNodeInstances ) + { + // Create the object group instances and the object groups and write it into the maya file. + + // setAttr -size 2 ".instObjGroups"; // for every instance + // setAttr -size 2 ".instObjGroups[0].objectGroups"; // for every mesh primitive + // setAttr ".instObjGroups[0].objectGroups[0].objectGrpCompList" -type "componentList" 1 "f[0:5]"; + // setAttr ".instObjGroups[0].objectGroups[1].objectGrpCompList" -type "componentList" 1 "f[6:11]"; + + // We have to go through every mesh primitive. + const COLLADAFW::MeshPrimitiveArray& meshPrimitives = mesh->getMeshPrimitives (); + size_t meshPrimitivesCount = meshPrimitives.getCount (); + + // Iterate over the object instances. + for ( size_t j=0; j<numNodeInstances; ++j ) + { + size_t initialFaceIndex = 0; + + // Iterate over the mesh primitives + for ( size_t i=0; i<meshPrimitivesCount; ++i ) + { + // Get the number of faces of the current primitive element. + const COLLADAFW::MeshPrimitive* meshPrimitive = meshPrimitives [ i ]; + // TODO Is this also with trifans, etc. the right number??? + size_t numFaces = meshPrimitive->getGroupedVertexElementsCount (); +// COLLADAFW::Trifans* trifans = (COLLADAFW::Trifans*) primitiveElement; +// COLLADAFW::Trifans::VertexCountArray& vertexCountArray = +// trifans->getGroupedVerticesVertexCountArray (); +// meshPrimitive->getFaceCount (); +// meshPrimitive->getGroupedVerticesVertexCount (); + + // Create the string with the face informations for the component list. + String val = "f[" + COLLADABU::Utils::toString ( initialFaceIndex ) + + ":" + COLLADABU::Utils::toString ( numFaces-1 + initialFaceIndex ) + "]"; + + // Create the component list. + MayaDM::componentList componentList; + componentList.push_back ( val ); + + // Increment the initial face index. + initialFaceIndex += numFaces; + + // Write instance object group component list data into the file. + meshNode.setObjectGrpCompList ( j, i, componentList ); + } + } + + for ( size_t i=0; i<meshPrimitivesCount; ++i ) + { + // Get the current primitive element. + const COLLADAFW::MeshPrimitive* meshPrimitive = meshPrimitives [ i ]; + + // Get the shader engine id. + String shaderEngineName = meshPrimitive->getMaterial (); + COLLADAFW::MaterialId shaderEngineId = meshPrimitive->getMaterialId (); + + + // Look for the + + } + } + + // -------------------------------------------- void GeometryImporter::writeVertexPositions ( const COLLADAFW::Mesh* mesh, MayaDM::Mesh &meshNode ) @@ -1107,6 +1179,26 @@ } // -------------------------------------------- + const MayaDM::Mesh* GeometryImporter::getMayaDMMeshNode ( const COLLADAFW::UniqueId& uniqueId ) const + { + UniqueIdMayaDMMeshMap::const_iterator it = mMayaDMMeshNodesMap.find ( uniqueId ); + if ( it != mMayaDMMeshNodesMap.end () ) + return &(*it).second; + + return NULL; + } + + // -------------------------------------------- + MayaDM::Mesh* GeometryImporter::getMayaDMMeshNode ( const COLLADAFW::UniqueId& uniqueId ) + { + UniqueIdMayaDMMeshMap::iterator it = mMayaDMMeshNodesMap.find ( uniqueId ); + if ( it != mMayaDMMeshNodesMap.end () ) + return &(*it).second; + + return NULL; + } + + // -------------------------------------------- bool GeometryImporter::getEdgeIndex ( const COLLADAFW::Edge& edge, const std::map<COLLADAFW::Edge,size_t>& edgeIndicesMap, Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaMaterialImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaMaterialImporter.cpp 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaMaterialImporter.cpp 2009-02-11 11:00:27 UTC (rev 352) @@ -15,46 +15,40 @@ #include "COLLADAMayaStableHeaders.h" #include "COLLADAMayaMaterialImporter.h" -#include "COLLADAMayaShaderHelper.h" -#include "COLLADAMayaDagHelper.h" -#include "COLLADAMayaSyntax.h" +#include "COLLADAMayaEffectImporter.h" -// #include "COLLADADHReader.h" -// #include "COLLADADHElementIterator.h" -// #include "COLLADADHEffectUtil.h" -// -// #include <dom/domMaterial.h> -// #include <dom/domTypes.h> -#include <maya/MFnLambertShader.h> -#include <maya/MFnPhongShader.h> -#include <maya/MFnBlinnShader.h> - namespace COLLADAMaya { + const String MaterialImporter::MATERIAL_NAME = "Material"; + //------------------------------ MaterialImporter::MaterialImporter ( DocumentImporter* documentImporter ) : BaseImporter ( documentImporter ) {} // -------------------------- - void MaterialImporter::importMaterials() + bool MaterialImporter::importMaterial ( const COLLADAFW::Material* material ) { -// daeDocument* document = getDaeDocument(); -// COLLADADH::Reader reader ( *( document ) ); -// -// COLLADADH::Reader::ElementIterator<domMaterial> materialsIter = reader.getMaterials(); -// while ( materialsIter.more() ) -// { -// domMaterial& material = materialsIter.next(); -// importMaterial ( material ); -// } - } + // Get the material name. + String materialName ( material->getName () ); + if ( COLLADABU::Utils::equals ( materialName, COLLADABU::Utils::EMPTY_STRING ) ) + materialName = MATERIAL_NAME; + materialName = mMaterialIdList.addId ( materialName ); + + const COLLADAFW::UniqueId& materialId = material->getUniqueId (); + mMayaMaterialNamesMap [materialId] = materialName; -// // -------------------------- -// void MaterialImporter::importMaterial ( domMaterial& material ) -// { + // Get the effect + const COLLADAFW::UniqueId& effectId = material->getInstantiatedEffect (); + EffectImporter* effectImporter = getDocumentImporter ()->getEffectImporter (); + + effectImporter->findMayaEffect ( effectId ); + + // + + // daeString elementName = material.getElementName(); // xsNCName materialName = material.getName(); // daeString materialTypeName = material.getTypeName(); @@ -374,8 +368,10 @@ // // } // } -// } -// + + return true; + } + // // -------------------------- // // MObject MaterialImporter::importStandardShader ( // // FCDGeometryInstance* colladaInstance, @@ -433,4 +429,21 @@ // // DaeTextureList textures; // // } + // -------------------------- + MayaDM::DependNode* MaterialImporter::findMayaMaterial ( const COLLADAFW::UniqueId& val ) const + { + UniqueIdMayaMaterialMap::const_iterator it = mMayaMaterialMap.find ( val ); + if ( it != mMayaMaterialMap.end () ) + { + return it->second; + } + return 0; + } + + // -------------------------- + void MaterialImporter::appendMaterial ( const COLLADAFW::UniqueId& id, MayaDM::DependNode* materialNode ) + { + mMayaMaterialMap [id] = materialNode; + } + } \ No newline at end of file Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaVisualSceneImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaVisualSceneImporter.cpp 2009-02-11 10:56:37 UTC (rev 351) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaVisualSceneImporter.cpp 2009-02-11 11:00:27 UTC (rev 352) @@ -19,9 +19,11 @@ #include "COLLADAMayaDagHelper.h" #include "COLLADAMayaSyntax.h" #include "COLLADAMayaGeometryImporter.h" -#include "ColladaMayaException.h" +#include "COLLADAMayaMaterialImporter.h" #include "MayaDMJoint.h" +#include "MayaDMLambert.h" +#include "MayaDMDependNode.h" #include "MayaDMCommands.h" #include "COLLADAFWRotate.h" @@ -41,6 +43,11 @@ namespace COLLADAMaya { + const String VisualSceneImporter::TRANSFORM_NODE_NAME = "Transform"; + const String VisualSceneImporter::SHADING_ENGINE_NAME = "ShadingEngine"; + const String VisualSceneImporter::MATERIAL_INFO_NAME = "MaterialInfo"; + + // ----------------------------------- VisualSceneImporter::VisualSceneImporter ( DocumentImporter* documentImporter ) : BaseImporter ( documentImporter ) @@ -49,8 +56,6 @@ // ----------------------------------- bool VisualSceneImporter::importVisualScene ( const COLLADAFW::VisualScene* visualScene ) { - String visualSceneName = visualScene->getName (); - // Iterate over the root nodes of the current visual scene const COLLADAFW::NodeArray& rootNodes = visualScene->getRootNodes (); size_t count = rootNodes.getCount (); @@ -82,11 +87,7 @@ // Get the unique node name String nodeName = node->getName (); if ( COLLADABU::Utils::equals ( nodeName, "" ) ) - nodeName = node->getSid (); - if ( COLLADABU::Utils::equals ( nodeName, "" ) ) - nodeName = "Transform"; - - // Create a unique name. + nodeName = TRANSFORM_NODE_NAME; nodeName = mTransformNodeIdList.addId ( nodeName ); // Create the node object (joint or node) @@ -164,6 +165,9 @@ // Save for every geometry a list of transform nodes, which refer to it. mGeometryTransformIdsMap [ geometryId ].insert ( nodeId ); + + // Read the shading engines. + readMaterialInstances ( instanceGeometry ); } return true; @@ -733,4 +737,128 @@ return NULL; } + + // ----------------------------------- + void VisualSceneImporter::readMaterialInstances ( const COLLADAFW::InstanceGeometry* instanceGeometry ) + { + // Go through the bound materials + const COLLADAFW::InstanceGeometry::MaterialBindingArray& materialBindingsArray = instanceGeometry->getMaterialBindings (); + size_t numOfBindings = materialBindingsArray.getCount (); + for ( size_t i=0; i<numOfBindings; ++i ) + { + const COLLADAFW::InstanceGeometry::MaterialBinding& materialBinding = materialBindingsArray [i]; + const COLLADAFW::UniqueId& referencedMaterialId = materialBinding.getReferencedMaterial (); + + // Get the material id and the shading engine name. + COLLADAFW::MaterialId materialId = materialBinding.getMaterialId (); + + // Check if already a shading engine with the materialId exist. + MayaDM::ShadingEngine* shadingEngine; + MayaDM::MaterialInfo* materialInfo; + String shadingEngineName; + ShaderData* shaderData = findShaderData ( materialId ); + if ( shaderData == 0 ) + { + // Get the unique shading engine name. + shadingEngineName = materialBinding.getName (); + if ( COLLADABU::Utils::equals ( shadingEngineName, COLLADABU::Utils::EMPTY_STRING )) + shadingEngineName = SHADING_ENGINE_NAME; + shadingEngineName = mShadingEngineIdList.addId ( shadingEngineName ); + + // Create a shading engine, if we not already have one. + FILE* file = getDocumentImporter ()->getFile (); + shadingEngine = new MayaDM::ShadingEngine ( file, shadingEngineName.c_str () ); + + // Create the material info node for the shading engine. + // createNode materialInfo -name "materialInfo2"; + String materialInfoName = MATERIAL_INFO_NAME; + materialInfoName = mMaterialInfoIdList.addId ( materialInfoName ); + MayaDM::MaterialInfo* materialInfo = new MayaDM::MaterialInfo ( file, materialInfoName.c_str () ); + + // Push it in the map of shading engines + appendShaderData ( materialId, shadingEngine, materialInfo ); + + // Connect the message attribute of the shading engine + // with the shading group of the material info. + // connectAttr "blinn1SG.message" "materialInfo2.shadingGroup"; + connectAttr ( file, shadingEngine->getMessage (), materialInfo->getShadingGroup () ); + + MaterialImporter* materialImporter = getDocumentImporter ()->getMaterialImporter (); + MayaDM::DependNode* materialNode = materialImporter->findMayaMaterial ( referencedMaterialId ); + + // If the materials are already imported, we make the + // connection between the shading engine a... [truncated message content] |