From: <jud...@us...> - 2009-02-18 12:43:57
|
Revision: 367 http://colladamaya.svn.sourceforge.net/colladamaya/?rev=367&view=rev Author: judithschenk Date: 2009-02-18 12:43:48 +0000 (Wed, 18 Feb 2009) Log Message: ----------- enhancement on unit handling and conversion; light import; node instances; image import; Modified Paths: -------------- branches/nextgen/COLLADAFramework/include/COLLADAFWFileInfo.h branches/nextgen/COLLADAFramework/src/COLLADAFWFileInfo.cpp branches/nextgen/COLLADAMaya/include/COLLADAMayaBaseImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaDocumentImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaLightImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaMaterialImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaVisualSceneImporter.h branches/nextgen/COLLADAMaya/scripts/COLLADAMaya.vcproj branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaLightImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaMaterialImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaVisualSceneImporter.cpp branches/nextgen/COLLADASaxFrameworkLoader/include/COLLADASaxFWLAssetLoader.h Added Paths: ----------- branches/nextgen/COLLADAMaya/include/COLLADAMayaImageImporter.h branches/nextgen/COLLADAMaya/src/COLLADAMayaImageImporter.cpp Modified: branches/nextgen/COLLADAFramework/include/COLLADAFWFileInfo.h =================================================================== --- branches/nextgen/COLLADAFramework/include/COLLADAFWFileInfo.h 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAFramework/include/COLLADAFWFileInfo.h 2009-02-18 12:43:48 UTC (rev 367) @@ -35,14 +35,72 @@ public: /** Descriptive information about unit of measure. Its optional attributes are:*/ - struct Unit + class Unit { + public: + static const double LINEAR_UNIT_KILOMETER; + static const double LINEAR_UNIT_METER; + static const double LINEAR_UNIT_DECIMETER; + static const double LINEAR_UNIT_CENTIMETER; + static const double LINEAR_UNIT_MILLIMETER; + static const double LINEAR_UNIT_FOOT; + static const double LINEAR_UNIT_INCH; + static const double LINEAR_UNIT_YARD; + + static const String LINEAR_UNIT_KILOMETER_NAME; + static const String LINEAR_UNIT_METER_NAME; + static const String LINEAR_UNIT_DECIMETER_NAME; + static const String LINEAR_UNIT_CENTIMETER_NAME; + static const String LINEAR_UNIT_MILLIMETER_NAME; + static const String LINEAR_UNIT_FOOT_NAME; + static const String LINEAR_UNIT_INCH_NAME; + static const String LINEAR_UNIT_YARD_NAME; + + static const String ANGULAR_UNIT_DEGREES_NAME; + static const String ANGULAR_UNIT_RADIANS_NAME; + + static const String TIME_UNIT_FILM_NAME; + + + enum LinearUnit + { + KILOMETER, + METER, + DECIMETER, + CENTIMETER, + MILLIMETER, + FOOT, + INCH, + YARD, + UNKNOWN_LINEAR_UNIT + }; + + enum AngularUnit + { + DEGREES, + RADIANS, + UNKNOWN_ANGULAR_UNIT + }; + + enum TimeUnit + { + FILM, + UNKNOWN_TIME_UNIT + }; + + private: + + /** + * The enum value for the linear unit. + */ + LinearUnit mLinearUnitUnit; + /** * The name of the distance unit to use in the scene. For example, * "meter", "centimeter", "inches", or "parsec". This can be the * real name of a measurement, or an imaginary name. */ - String mLinearUnit; + String mLinearUnitName; /** * How many real-world meters in one distance unit as a floating-point number. @@ -54,15 +112,96 @@ /** * The angular unit; */ - String mAngularUnit; + String mAngularUnitName; + AngularUnit mAngularUnitUnit; /** * The time unit. */ - String mTimeUnit; + String mTimeUnitName; + TimeUnit mTimeUnitUnit; + public: + + Unit () + : mLinearUnitName ( LINEAR_UNIT_METER_NAME ) + , mLinearUnitUnit ( METER ) + , mLinearUnitMeter ( LINEAR_UNIT_METER ) + , mAngularUnitName ( ANGULAR_UNIT_DEGREES_NAME ) + , mAngularUnitUnit ( DEGREES ) + , mTimeUnitName ( TIME_UNIT_FILM_NAME ) + , mTimeUnitUnit ( FILM ) + {} + + Unit ( String linearUnitName, double linearUnitMeter, + String angularUnitName, String timeUnitName = TIME_UNIT_FILM_NAME ) + : mLinearUnitName ( linearUnitName ) + , mLinearUnitMeter ( linearUnitMeter ) + , mAngularUnitName ( angularUnitName ) + , mTimeUnitName ( timeUnitName ) + { + initializeLinearUnitUnitByName ( mLinearUnitName ); + initializeAngularUnitUnitByName ( mAngularUnitName ); + initializeTimeUnitUnitByName ( mTimeUnitName ); + } + + virtual ~Unit () {} + + /** + * The enum value for the linear unit. + */ + const LinearUnit& getLinearUnitUnit () const { return mLinearUnitUnit; } + void setLinearUnitUnit ( const LinearUnit& val ) { mLinearUnitUnit = val; } + + /** + * The name of the distance unit to use in the scene. For example, + * "meter", "centimeter", "inches", or "parsec". This can be the + * real name of a measurement, or an imaginary name. + */ + const String& getLinearUnit () const { return mLinearUnitName; } + void setLinearUnit ( const String& val ); + + /** + * Initializes the linear unit unit with the specified enum value + * in depend of the given name. + */ + void initializeLinearUnitUnitByName ( const String& val ); + + /** + * How many real-world meters in one distance unit as a floating-point number. + * For example, 1.0 for the name "meter"; 1000 for the name "kilometer"; + * 0.3048 for the name "foot". + */ + const double getLinearUnitMeter () const { return mLinearUnitMeter; } + void setLinearUnitMeter ( const double val ) { mLinearUnitMeter = val; } + + /** + * The angular unit; + */ + const String& getAngularUnitName () const { return mAngularUnitName; } + void setAngularUnitName ( const String& val ); + + /** + * Initializes the angular unit unit with the specified enum value + * in depend of the given name. + */ + void initializeAngularUnitUnitByName ( const String& angularUnitName ); + + /** + * The time unit. + */ + const String& getTimeUnitName () const { return mTimeUnitName; } + void setTimeUnitName ( const String& val ); + + /** + * Initializes the time unit unit with the specified enum value + * in depend of the given name. + */ + void initializeTimeUnitUnitByName ( const String& timeUnitName ); + }; + /*Descriptive information about the coordinate system of the geometric data. All coordinates are right handed by definition. Valid values are X_UP, Y_UP, @@ -126,7 +265,7 @@ */ void setLinearUnit ( const String& linearUnit ) { - mUnit.mLinearUnit = linearUnit; + mUnit.setLinearUnit ( linearUnit ); } /** @@ -134,7 +273,7 @@ */ void setLinearUnitMeter ( const double linearUnitMeter ) { - mUnit.mLinearUnitMeter = linearUnitMeter; + mUnit.setLinearUnitMeter ( linearUnitMeter ); } /** Returns the unit. */ Modified: branches/nextgen/COLLADAFramework/src/COLLADAFWFileInfo.cpp =================================================================== --- branches/nextgen/COLLADAFramework/src/COLLADAFWFileInfo.cpp 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAFramework/src/COLLADAFWFileInfo.cpp 2009-02-18 12:43:48 UTC (rev 367) @@ -21,14 +21,35 @@ const String FileInfo::Y_UP_STRING = "Y_UP"; const String FileInfo::Z_UP_STRING = "Z_UP"; + const double FileInfo::Unit::LINEAR_UNIT_KILOMETER = 1000; + const double FileInfo::Unit::LINEAR_UNIT_METER = 1; + const double FileInfo::Unit::LINEAR_UNIT_DECIMETER = 0.01; + const double FileInfo::Unit::LINEAR_UNIT_CENTIMETER = 0.01; + const double FileInfo::Unit::LINEAR_UNIT_MILLIMETER = 0.001; + const double FileInfo::Unit::LINEAR_UNIT_FOOT = 0.3048; + const double FileInfo::Unit::LINEAR_UNIT_INCH = 0.0254; + const double FileInfo::Unit::LINEAR_UNIT_YARD = 0.9144; + + const String FileInfo::Unit::LINEAR_UNIT_KILOMETER_NAME = "kilometer"; + const String FileInfo::Unit::LINEAR_UNIT_METER_NAME = "meter"; + const String FileInfo::Unit::LINEAR_UNIT_DECIMETER_NAME = "decimeter"; + const String FileInfo::Unit::LINEAR_UNIT_CENTIMETER_NAME = "centimeter"; + const String FileInfo::Unit::LINEAR_UNIT_MILLIMETER_NAME = "millimeter"; + const String FileInfo::Unit::LINEAR_UNIT_FOOT_NAME = "foot"; + const String FileInfo::Unit::LINEAR_UNIT_INCH_NAME = "inch"; + const String FileInfo::Unit::LINEAR_UNIT_YARD_NAME = "yard"; + + const String FileInfo::Unit::ANGULAR_UNIT_DEGREES_NAME = "degree"; + const String FileInfo::Unit::ANGULAR_UNIT_RADIANS_NAME = "radian"; + + const String FileInfo::Unit::TIME_UNIT_FILM_NAME = "film"; + + //------------------------------ FileInfo::FileInfo() : mUpAxisType ( Y_UP ) , mValuePairArray ( ValuePairArray::OWNER ) { - mUnit.mLinearUnit = "centimeter"; - mUnit.mAngularUnit = "degree"; - mUnit.mTimeUnit = "film"; } //------------------------------ @@ -60,4 +81,71 @@ { mValuePairArray.append ( new ValuePair ( value1, value2 ) ); } + + //------------------------------ + void FileInfo::Unit::setAngularUnitName ( const String& val ) + { + mAngularUnitName = val; + + initializeAngularUnitUnitByName ( mAngularUnitName ); + } + + //------------------------------ + void FileInfo::Unit::setLinearUnit ( const String& val ) + { + mLinearUnitName = val; + + initializeLinearUnitUnitByName ( mLinearUnitName ); + } + + //------------------------------ + void FileInfo::Unit::setTimeUnitName ( const String& val ) + { + mTimeUnitName = val; + + initializeTimeUnitUnitByName ( mTimeUnitName ); + } + + //------------------------------ + void FileInfo::Unit::initializeLinearUnitUnitByName ( const String& linearUnitName ) + { + if ( COLLADABU::Utils::equalsIgnoreCase ( linearUnitName, LINEAR_UNIT_KILOMETER_NAME ) ) + mLinearUnitUnit = KILOMETER; + else if ( COLLADABU::Utils::equalsIgnoreCase ( linearUnitName, LINEAR_UNIT_METER_NAME ) ) + mLinearUnitUnit = METER; + else if ( COLLADABU::Utils::equalsIgnoreCase ( linearUnitName, LINEAR_UNIT_METER_NAME ) ) + mLinearUnitUnit = METER; + else if ( COLLADABU::Utils::equalsIgnoreCase ( linearUnitName, LINEAR_UNIT_DECIMETER_NAME ) ) + mLinearUnitUnit = DECIMETER; + else if ( COLLADABU::Utils::equalsIgnoreCase ( linearUnitName, LINEAR_UNIT_CENTIMETER_NAME ) ) + mLinearUnitUnit = CENTIMETER; + else if ( COLLADABU::Utils::equalsIgnoreCase ( linearUnitName, LINEAR_UNIT_MILLIMETER_NAME ) ) + mLinearUnitUnit = MILLIMETER; + else if ( COLLADABU::Utils::equalsIgnoreCase ( linearUnitName, LINEAR_UNIT_FOOT_NAME ) ) + mLinearUnitUnit = FOOT; + else if ( COLLADABU::Utils::equalsIgnoreCase ( linearUnitName, LINEAR_UNIT_INCH_NAME ) ) + mLinearUnitUnit = INCH; + else if ( COLLADABU::Utils::equalsIgnoreCase ( linearUnitName, LINEAR_UNIT_METER_NAME ) ) + mLinearUnitUnit = YARD; + else mLinearUnitUnit = UNKNOWN_LINEAR_UNIT; + } + + //------------------------------ + void FileInfo::Unit::initializeAngularUnitUnitByName ( const String& angularUnitName ) + { + if ( COLLADABU::Utils::equalsIgnoreCase ( angularUnitName, ANGULAR_UNIT_DEGREES_NAME ) ) + mAngularUnitUnit = DEGREES; + else if ( COLLADABU::Utils::equalsIgnoreCase ( angularUnitName, ANGULAR_UNIT_RADIANS_NAME ) ) + mAngularUnitUnit = RADIANS; + else mAngularUnitUnit = UNKNOWN_ANGULAR_UNIT; + } + + //------------------------------ + void FileInfo::Unit::initializeTimeUnitUnitByName ( const String& timeUnitName ) + { + if ( COLLADABU::Utils::equalsIgnoreCase ( timeUnitName, TIME_UNIT_FILM_NAME ) ) + mTimeUnitUnit = FILM; + else mTimeUnitUnit = UNKNOWN_TIME_UNIT; + } + } // namespace COLLADAFW Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaBaseImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaBaseImporter.h 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaBaseImporter.h 2009-02-18 12:43:48 UTC (rev 367) @@ -44,6 +44,8 @@ typedef std::map<COLLADAFW::UniqueId, MayaNode> UniqueIdMayaNodesMap; typedef std::map<COLLADAFW::UniqueId, MayaDM::Mesh> UniqueIdMayaDMMeshMap; + typedef std::map<COLLADAFW::UniqueId, MayaDM::DependNode*> UniqueIdDependNodeMap; + typedef std::pair<COLLADAFW::UniqueId,COLLADAFW::MaterialId> CombinedId; typedef std::vector<size_t> IndicesVector; typedef std::map<CombinedId, IndicesVector> CombinedIdIndicesMap; Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaDocumentImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaDocumentImporter.h 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaDocumentImporter.h 2009-02-18 12:43:48 UTC (rev 367) @@ -41,6 +41,7 @@ class EffectImporter; class CameraImporter; class LightImporter; + class ImageImporter; /** The main importer class. This class imports all data of the scene. */ @@ -79,6 +80,7 @@ bool mGeometryRead; bool mCameraRead; bool mLightRead; + bool mImageRead; /** Pointer to the visual scene importer. */ VisualSceneImporter* mVisualSceneImporter; @@ -98,6 +100,9 @@ /** Pointer to the light importer. */ LightImporter* mLightImporter; + /** Pointer to the image importer. */ + ImageImporter* mImageImporter; + /** The variable tells, how many times the document is read. */ size_t mNumDocumentParses; @@ -223,6 +228,10 @@ @return The writer should return true, if writing succeeded, false otherwise.*/ virtual bool writeLight( const COLLADAFW::Light* camera ); + /** When this method is called, the writer must write the image. + @return The writer should return true, if writing succeeded, false otherwise.*/ + virtual bool writeImage( const COLLADAFW::Image* image ); + /** * Replace offending characters by some that are supported within maya. */ Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h 2009-02-18 12:43:48 UTC (rev 367) @@ -25,10 +25,6 @@ /** TODO Documentation */ class EffectImporter : public BaseImporter { - public: - - typedef std::map<COLLADAFW::UniqueId, MayaDM::DependNode*> UniqueIdDependNodeMap; - private: /** The standard name for a effect without name. */ @@ -47,7 +43,7 @@ UniqueIdNamesMap mMayaEffectNamesMap; /** - * The map holds the maya effect objects. + * The map holds the maya effect objects for the connections. */ UniqueIdDependNodeMap mMayaEffectMap; Added: branches/nextgen/COLLADAMaya/include/COLLADAMayaImageImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaImageImporter.h (rev 0) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaImageImporter.h 2009-02-18 12:43:48 UTC (rev 367) @@ -0,0 +1,65 @@ +/* + 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_IMAGEIMPORTER_H__ +#define __COLLADAMAYA_IMAGEIMPORTER_H__ + +#include "COLLADAMayaPrerequisites.h" +#include "COLLADAMayaBaseImporter.h" + +#include "COLLADABUIDList.h" + +#include "COLLADAFWImage.h" + + +namespace COLLADAMaya +{ + + /** TODO Documentation */ + class ImageImporter : BaseImporter + { + private: + + /** The standard name for image without name. */ + static const String IMAGE_NAME; + + private: + + /** + * The list of the unique maya image names. + */ + COLLADABU::IDList mImageIdList; + + public: + + /** Constructor. */ + ImageImporter ( DocumentImporter* documentImporter ); + + /** Destructor. */ + virtual ~ImageImporter(); + + /** + * Imports the data of the current light. + */ + void importImage ( const COLLADAFW::Image* image ); + + private: + + /** Disable default copy ctor. */ + ImageImporter( const ImageImporter& pre ); + + /** Disable default assignment operator. */ + const ImageImporter& operator= ( const ImageImporter& pre ); + + }; + +} // namespace COLLADAMAYA + +#endif // __COLLADAMAYA_IMAGEIMPORTER_H__ Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaLightImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaLightImporter.h 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaLightImporter.h 2009-02-18 12:43:48 UTC (rev 367) @@ -28,6 +28,16 @@ { private: + /** The name of maya's default light list. */ + static const String INITIAL_LIGHT_LIST; + static const String DEFAULT_LIGHT_SET; + + private: + + typedef std::map<COLLADAFW::UniqueId, MayaDM::Light*> UniqueIdLightNodeMap; + + private: + /** The standard name for camera without name. */ static const String LIGHT_NAME; @@ -40,9 +50,15 @@ /** * The map holds the unique ids of the light nodes to the maya specific nodes. + * Need for the instances. */ UniqueIdMayaNodesMap mMayaLightNodesMap; + /** + * The map holds the maya light objects for the connections. + */ + UniqueIdLightNodeMap mMayaLightMap; + public: /** Constructor. */ @@ -56,6 +72,11 @@ */ void importLight ( const COLLADAFW::Light* light ); + /** + * Writes the connection attributes into the maya ascii file. + */ + void writeConnections (); + private: /** @@ -77,8 +98,22 @@ const COLLADAFW::Light* light, MayaDM::Light* mayaLight ); + /** + * The map holds the unique ids of the light nodes to the maya specific nodes. + * Need for the instances. + */ MayaNode* findMayaLightNode ( const COLLADAFW::UniqueId& lightId ); + /** + * The map holds the maya material objects. + */ + MayaDM::Light* findMayaLight ( const COLLADAFW::UniqueId& val ) const; + + /** + * The map holds the maya light objects. + */ + void appendLight ( const COLLADAFW::UniqueId& id, MayaDM::Light* lightNode ); + }; } // namespace COLLADAMAYA Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaMaterialImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaMaterialImporter.h 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaMaterialImporter.h 2009-02-18 12:43:48 UTC (rev 367) @@ -49,7 +49,7 @@ /** The name of maya's default shader list. */ static const String DEFAULT_SHADER_LIST; - static const String DEFAULT_SHADING_ENGINE; + static const String INITIAL_SHADING_ENGINE; static const String ATTR_SHADERS; public: @@ -166,7 +166,9 @@ const COLLADAFW::UniqueId& transformNodeId, const COLLADAFW::InstanceGeometry* instanceGeometry ); - /** Writes the connection attributes into the maya ascii file. */ + /** + * Writes the connection attributes into the maya ascii file. + */ void writeConnections (); /** Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaVisualSceneImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaVisualSceneImporter.h 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaVisualSceneImporter.h 2009-02-18 12:43:48 UTC (rev 367) @@ -49,37 +49,9 @@ private: - /** - * The list of the unique maya transform node names. - */ - COLLADABU::IDList mTransformNodeIdList; - /* - * The map holds for every unique id of a geometry a list of transform node unique ids. - * We need it for the creation of the geometry, to set the parent transform nodes. - */ - UniqueIdUniqueIdsMap mGeometryTransformIdsMap; - - /* - * The map holds for every unique id of a camera a list of transform node unique ids. - * We need it for the creation of the camera, to set the parent transform nodes. + * Helper class, to handle the transformations. */ - UniqueIdUniqueIdsMap mCameraTransformIdsMap; - - /* - * The map holds for every unique id of a light a list of transform node unique ids. - * We need it for the creation of the light, to set the parent transform nodes. - */ - UniqueIdUniqueIdsMap mLightTransformIdsMap; - - /** - * The map holds the unique ids of the nodes to the full node pathes (contains the name). - */ - UniqueIdMayaNodesMap mMayaTransformNodesMap; - - /* - * Helper class, to handle the transformations. - */ class MayaTransformation { public: @@ -121,12 +93,48 @@ MVector translate3; // = 0,0,0 std::vector<MVector> translate3Vec; size_t numTranslate3; - + // 5 phases size_t phase; }; + private: + + /** + * The list of the unique maya transform node names. + */ + COLLADABU::IDList mTransformNodeIdList; + + /** + * The map holds the unique ids of the nodes to the full node pathes (contains the name). + */ + UniqueIdMayaNodesMap mMayaTransformNodesMap; + + /** + * The map holds for every transform node a list of all existing parent transform nodes + * (this are the nodes, which hold an instance of the current transform node). + */ + UniqueIdUniqueIdsMap mTransformInstancesMap; + + /* + * The map holds for every unique id of a geometry a list of transform node unique ids. + * We need it for the creation of the geometry, to set the parent transform nodes. + */ + UniqueIdUniqueIdsMap mGeometryTransformIdsMap; + + /* + * The map holds for every unique id of a camera a list of transform node unique ids. + * We need it for the creation of the camera, to set the parent transform nodes. + */ + UniqueIdUniqueIdsMap mCameraTransformIdsMap; + + /* + * The map holds for every unique id of a light a list of transform node unique ids. + * We need it for the creation of the light, to set the parent transform nodes. + */ + UniqueIdUniqueIdsMap mLightTransformIdsMap; + public: /** Constructor. */ @@ -150,6 +158,12 @@ */ MayaNode* findMayaTransformNode ( const COLLADAFW::UniqueId& uniqueId ); + /** + * The map holds for every transform node a list of all existing parent transform nodes + * (this are the nodes, which hold an instance of the current transform node). + */ + const UniqueIdVec* findTransformInstances ( const COLLADAFW::UniqueId& transformId ) const; + /* * The map holdes for every geometry (identified by it's unique id ) a list of all * transform nodes (identified by their names, which are unique!). @@ -207,6 +221,11 @@ */ bool readNodeInstances ( const COLLADAFW::Node* node ); + /** + * Write the parenting informations about node instances into the maya ascii file. + */ + void writeNodeInstances (); + /* * Transform the input matrix and convert it in a double[4][4] matrix. */ Modified: branches/nextgen/COLLADAMaya/scripts/COLLADAMaya.vcproj =================================================================== --- branches/nextgen/COLLADAMaya/scripts/COLLADAMaya.vcproj 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/scripts/COLLADAMaya.vcproj 2009-02-18 12:43:48 UTC (rev 367) @@ -2691,6 +2691,10 @@ > </File> <File + RelativePath="..\src\COLLADAMayaImageImporter.cpp" + > + </File> + <File RelativePath="..\src\COLLADAMayaLightImporter.cpp" > </File> @@ -3724,6 +3728,10 @@ </FileConfiguration> </File> <File + RelativePath="..\include\COLLADAMayaImageImporter.h" + > + </File> + <File RelativePath="..\include\COLLADAMayaLightImporter.h" > </File> Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp 2009-02-18 12:43:48 UTC (rev 367) @@ -22,6 +22,7 @@ #include "COLLADAMayaGeometryImporter.h" #include "COLLADAMayaCameraImporter.h" #include "COLLADAMayaLightImporter.h" +#include "COLLADAMayaImageImporter.h" #include "COLLADAMayaVisualSceneImporter.h" #include "COLLADAMayaVisualSceneImporter.h" @@ -50,12 +51,14 @@ , mEffectImporter (0) , mCameraImporter (0) , mLightImporter (0) + , mImageImporter (0) , mSceneGraphWritten (false) , mAssetWritten (false) , mSceneGraphRead (false) , mGeometryRead (false) , mCameraRead (false) , mLightRead (false) + , mImageRead (false) , mLinearUnitMeter (1) , mNumDocumentParses (0) { @@ -82,6 +85,7 @@ mEffectImporter = new EffectImporter ( this ); mCameraImporter = new CameraImporter ( this ); mLightImporter = new LightImporter ( this ); + mImageImporter = new ImageImporter (this); // Get the sceneID (assign a name to the scene) MString sceneName = MFileIO::currentFile (); @@ -100,6 +104,7 @@ delete mEffectImporter; delete mCameraImporter; delete mLightImporter; + delete mImageImporter; } //----------------------------- @@ -186,6 +191,7 @@ // TODO After the complete read of the collada document, // the connections can be written into the maya file. mMaterialImporter->writeConnections (); + mLightImporter->writeConnections (); // Close the file closeMayaAsciiFile (); @@ -305,12 +311,85 @@ fprintf_s ( mFile, "requires maya \"%s\";\n", mayaVersion.c_str () ); - // TODO Default values for the units! + // Get the unit informations. const COLLADAFW::FileInfo::Unit& unit = asset->getUnit (); - fprintf_s ( mFile, "currentUnit -l %s -a %s -t %s;\n", unit.mLinearUnit.c_str (), unit.mAngularUnit.c_str (), unit.mTimeUnit.c_str () ); - // Set the linear unit in meters - mLinearUnitMeter = unit.mLinearUnitMeter; + // TODO Default values for the units! + String linearUnitName = unit.getLinearUnit (); + double linearUnitMeter = unit.getLinearUnitMeter (); + + // Set the linear unit in meters. + // Maya knows: millimeter, centimeter, meter, foot, inch and yard. + switch ( unit.getLinearUnitUnit () ) + { + case COLLADAFW::FileInfo::Unit::KILOMETER: + { + // Convert to meters + linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER_NAME; + linearUnitMeter = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_KILOMETER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER;; + break; + } + case COLLADAFW::FileInfo::Unit::METER: + { + linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER_NAME; + linearUnitMeter = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER; + break; + } + case COLLADAFW::FileInfo::Unit::DECIMETER: + { + // Convert to meters + linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER_NAME; + linearUnitMeter = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_DECIMETER; + break; + } + case COLLADAFW::FileInfo::Unit::CENTIMETER: + { + // Don't convert + linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER_NAME; + linearUnitMeter = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; + break; + } + case COLLADAFW::FileInfo::Unit::MILLIMETER: + { + // Convert to centimeters + linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER_NAME; + linearUnitMeter = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_MILLIMETER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; + break; + } + case COLLADAFW::FileInfo::Unit::FOOT: + { + // Don't convert + linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_FOOT_NAME; + linearUnitMeter = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_FOOT / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_FOOT; + break; + } + case COLLADAFW::FileInfo::Unit::INCH: + { + // Don't convert + linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_INCH_NAME; + linearUnitMeter = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_INCH / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_INCH; + break; + } + case COLLADAFW::FileInfo::Unit::YARD: + { + // Don't convert + linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_YARD_NAME; + linearUnitMeter = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_YARD / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_YARD; + break; + } + default: + { + // Set to meters + linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER_NAME; + linearUnitMeter = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER; + break; + } + } + + fprintf_s ( mFile, "currentUnit -l %s -a %s -t %s;\n", + linearUnitName.c_str (), unit.getAngularUnitName ().c_str (), unit.getTimeUnitName ().c_str () ); + + mLinearUnitMeter = linearUnitMeter; mUpAxisType = asset->getUpAxisType (); // String application ( MGlobal::executeCommandStringResult ( "about -application" ).asChar () ); @@ -325,12 +404,13 @@ mAssetWritten = true; - if ( mSceneGraphRead || mGeometryRead || mCameraRead || mLightRead ) + if ( mSceneGraphRead || mGeometryRead || mCameraRead || mLightRead || mImageRead ) { mSceneGraphRead = false; mGeometryRead = false; mCameraRead = false; mLightRead = false; + mImageRead = false; readColladaDocument (); } @@ -355,11 +435,12 @@ mVisualSceneImporter->importVisualScene ( visualScene ); mSceneGraphWritten = true; - if ( mGeometryRead || mCameraRead || mLightRead ) + if ( mGeometryRead || mCameraRead || mLightRead || mImageRead ) { mGeometryRead = false; mCameraRead = false; mLightRead = false; + mImageRead = false; readColladaDocument (); } @@ -436,7 +517,7 @@ } //----------------------------- - bool DocumentImporter::writeLight ( const COLLADAFW::Light* camera ) + bool DocumentImporter::writeLight ( const COLLADAFW::Light* light ) { // Order: asset, scene graph, others if ( !mAssetWritten || !mSceneGraphWritten ) @@ -449,9 +530,27 @@ if ( mFile == 0 ) start(); // Import the data. - mLightImporter->importLight ( camera ); + mLightImporter->importLight ( light ); return true; } + //----------------------------- + bool DocumentImporter::writeImage ( const COLLADAFW::Image* image ) + { + // Order: asset, scene graph, others + if ( !mAssetWritten || !mSceneGraphWritten ) + { + mImageRead = true; + return true; + } + + // Create the file, if not already done. + if ( mFile == 0 ) start(); + + // Import the data. + mImageImporter->importImage ( image ); + + return true; + } } \ No newline at end of file Added: branches/nextgen/COLLADAMaya/src/COLLADAMayaImageImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaImageImporter.cpp (rev 0) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaImageImporter.cpp 2009-02-18 12:43:48 UTC (rev 367) @@ -0,0 +1,49 @@ +/* + 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 "COLLADAMayaImageImporter.h" + + +namespace COLLADAMaya +{ + + const String ImageImporter::IMAGE_NAME = "Image"; + + + //------------------------------ + ImageImporter::ImageImporter ( DocumentImporter* documentImporter ) + : BaseImporter ( documentImporter ) + { + } + + //------------------------------ + ImageImporter::~ImageImporter() + { + } + + //------------------------------ + void ImageImporter::importImage ( const COLLADAFW::Image* image ) + { + // Check if the light is already imported. + const COLLADAFW::UniqueId& imageId = image->getUniqueId (); +// if ( findMayaLightNode ( imageId ) != 0 ) return; + + // Create a unique name. + String imageName = image->getName (); + if ( COLLADABU::Utils::equals ( imageName, "" ) ) + imageName = IMAGE_NAME; + imageName = mImageIdList.addId ( imageName ); + + + + + } +} // namespace COLLADAMaya Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaLightImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaLightImporter.cpp 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaLightImporter.cpp 2009-02-18 12:43:48 UTC (rev 367) @@ -20,12 +20,16 @@ #include <MayaDMLight.h> #include <MayaDMAmbientLight.h> #include <MayaDMDirectionalLight.h> +#include <MayaDMLightList.h> +#include <MayaDMObjectSet.h> namespace COLLADAMaya { const String LightImporter::LIGHT_NAME = "Light"; + const String LightImporter::INITIAL_LIGHT_LIST = ":lightList1"; + const String LightImporter::DEFAULT_LIGHT_SET = ":defaultLightSet"; //------------------------------ @@ -37,22 +41,29 @@ //------------------------------ LightImporter::~LightImporter() { + UniqueIdLightNodeMap::const_iterator it = mMayaLightMap.begin (); + if ( it != mMayaLightMap.end () ) + { + MayaDM::Light* light = it->second; + delete light; + } } //------------------------------ void LightImporter::importLight ( const COLLADAFW::Light* light ) { - // Check if the camera is already imported. + // Check if the light is already imported. const COLLADAFW::UniqueId& lightId = light->getUniqueId (); if ( findMayaLightNode ( lightId ) != 0 ) return; - // Get the transform nodes, which work with this camera instance. + // Get the transform nodes, which work with this light instance. VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter (); - const UniqueIdVec* transformNodes = visualSceneImporter->findCameraTransformIds ( lightId ); + const UniqueIdVec* transformNodes = visualSceneImporter->findLightTransformIds ( lightId ); if ( transformNodes == 0 ) { - MGlobal::displayError ( "No camera node which implements this camera!" ); - std::cerr << "No camera node which implements this camera!" << endl; + MGlobal::displayError ( "No transform node which implements this light!" ); + std::cerr << "No transform node which implements this light!" << endl; + return; } UniqueIdVec::const_iterator nodesIter = transformNodes->begin (); @@ -74,7 +85,7 @@ } else { - // Get the path to the mesh. + // Get the path to the node. MayaNode* mayaLightNode = findMayaLightNode ( lightId ); String lightNodePath = mayaLightNode->getNodePath (); @@ -143,7 +154,7 @@ COLLADAFW::Color color = light->getColor (); mayaLight->setColor ( MayaDM::float3 ( (float)color.getRed (), (float)color.getGreen (), (float)color.getBlue () ) ); - delete mayaLight; + appendLight ( lightId, mayaLight ); } // -------------------------------------------- @@ -203,11 +214,94 @@ // Cone and Penumbra Angles double fallOffAngle = light->getFallOffAngle (); - spotLight->setConeAngle ( COLLADABU::Math::Utils::degToRad ( fallOffAngle ) ); + spotLight->setConeAngle ( fallOffAngle ); // double penumbraAngle = ( light->getOuterAngle() - light->getFallOffAngle() ) / 2.0f; // spotLight->setPenumbraAngle ( COLLADABU::Math::Utils::degToRad ( penumbraAngle )); } + // -------------------------- + MayaDM::Light* LightImporter::findMayaLight ( const COLLADAFW::UniqueId& val ) const + { + UniqueIdLightNodeMap::const_iterator it = mMayaLightMap.find ( val ); + if ( it != mMayaLightMap.end () ) + { + return it->second; + } + return 0; + } + + // -------------------------- + void LightImporter::appendLight ( const COLLADAFW::UniqueId& id, MayaDM::Light* lightNode ) + { + mMayaLightMap [id] = lightNode; + } + + // -------------------------------------------- + void LightImporter::writeConnections () + { + FILE* file = getDocumentImporter ()->getFile (); + + // Create a dummy object for the light list. + MayaDM::LightList lightList ( file, INITIAL_LIGHT_LIST, "", false ); + + size_t lightIndex = 0; + size_t lightSetIndex = 0; + UniqueIdMayaNodesMap::iterator it = mMayaLightNodesMap.begin (); + while ( it != mMayaLightNodesMap.end () ) + { + const COLLADAFW::UniqueId& lightId = it->first; + MayaNode& mayaNode = it->second; + + MayaDM::DependNode* dependNode = findMayaLight ( lightId ); + MayaDM::Light* lightNode = ( MayaDM::Light* ) dependNode; + dependNode->setName ( mayaNode.getNodePath () ); + + // Connect the light data of the lights (just real ones, no instances), with the light list. + //connectAttr "|spotLight1|spotLightShape1.lightData" ":lightList1.lights" -nextAvailable; + //connectAttr "spotLightShape2.lightData" ":lightList1.lights" -nextAvailable; + connectAttr ( file, lightNode->getLightData (), lightList.getLights ( lightIndex ) ); + ++lightIndex; + + // Get the transform nodes, which work with this light instance. + VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter (); + const UniqueIdVec* transformNodes = visualSceneImporter->findLightTransformIds ( lightId ); + if ( transformNodes == 0 ) + { + MGlobal::displayError ( "No transform node which implements this light!" ); + std::cerr << "No transform node which implements this light!" << endl; + return; + } + + size_t nodeIndex = 0; + UniqueIdVec::const_iterator nodesIter = transformNodes->begin (); + while ( nodesIter != transformNodes->end () ) + { + // Get the transform node. + const COLLADAFW::UniqueId& transformNodeId = *nodesIter; + MayaNode* mayaTransformNode = visualSceneImporter->findMayaTransformNode ( transformNodeId ); + String transformNodeName = mayaTransformNode->getName (); + String transformNodePath = mayaTransformNode->getNodePath (); + MayaDM::Transform transformNode ( file, transformNodePath, "", false ); + + // Get the default light set to add the light transform nodes. + MayaDM::ObjectSet lightSet ( file, DEFAULT_LIGHT_SET, "", false ); + + // Connect the light transforms instance object groups with the default light set. + //connectAttr "spotLight1.instObjGroups" ":defaultLightSet.dagSetMembers" -nextAvailable; + //connectAttr "|spotLight2.instObjGroups" ":defaultLightSet.dagSetMembers" -nextAvailable; + //connectAttr "spotLight3.instObjGroups" ":defaultLightSet.dagSetMembers" -nextAvailable; + connectAttr ( file, transformNode.getInstObjGroups (0), lightSet.getDagSetMembers (lightSetIndex) ); + ++lightSetIndex; + + ++nodesIter; + } + + ++it; + } + + + } + } // namespace COLLADAMaya Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaMaterialImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaMaterialImporter.cpp 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaMaterialImporter.cpp 2009-02-18 12:43:48 UTC (rev 367) @@ -34,8 +34,8 @@ const String MaterialImporter::MATERIAL_NAME = "Material"; const String MaterialImporter::SHADING_ENGINE_NAME = "ShadingEngine"; const String MaterialImporter::MATERIAL_INFO_NAME = "MaterialInfo"; - const String MaterialImporter::DEFAULT_SHADER_LIST = "defaultShaderList1"; - const String MaterialImporter::DEFAULT_SHADING_ENGINE = "initialShadingGroup"; + const String MaterialImporter::DEFAULT_SHADER_LIST = ":defaultShaderList1"; + const String MaterialImporter::INITIAL_SHADING_ENGINE = ":initialShadingGroup"; const String MaterialImporter::ATTR_SHADERS = "shaders"; @@ -201,18 +201,39 @@ mShadingEngineBindingMap [shadingEngineId].insert ( shadingBinding ); } + // -------------------------- + size_t MaterialImporter::getGeometryInstanceIndex ( + const COLLADAFW::UniqueId& geometryId, + const COLLADAFW::UniqueId& transformNodeId ) + { + size_t meshInstanceIndex = 0; + + // Get all visual scene nodes, which use this geometry and make the parent connections. + VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter (); + const UniqueIdVec* transformNodes = visualSceneImporter->findGeometryTransformIds ( geometryId ); + size_t numNodeInstances = transformNodes->size (); + + bool found = false; + for ( size_t index=0; index<numNodeInstances && !found; ++index ) + { + const COLLADAFW::UniqueId& nodeId = (*transformNodes) [index]; + if ( nodeId == transformNodeId ) + { + meshInstanceIndex = index; + found = true; + } + } + return meshInstanceIndex; + } + // -------------------------- void MaterialImporter::writeConnections () { - // TODO // select -noExpand :defaultShaderList1; - // setAttr -size 4 ".shaders"; // select -noExpand :initialShadingGroup; FILE* file = getDocumentImporter ()->getFile (); - String defaultShaderName = ":" + DEFAULT_SHADER_LIST; - mayaSelect ( file, defaultShaderName, true ); - String defaultShadingEngineName = ":" + DEFAULT_SHADING_ENGINE; - mayaSelect ( file, defaultShadingEngineName, true ); + mayaSelect ( file, DEFAULT_SHADER_LIST, true ); + mayaSelect ( file, INITIAL_SHADING_ENGINE, true ); // If there are some object groups, we have to connect them with the geometries. connectGeometryGroups(); @@ -228,31 +249,6 @@ } // -------------------------- - size_t MaterialImporter::getGeometryInstanceIndex ( - const COLLADAFW::UniqueId& geometryId, - const COLLADAFW::UniqueId& transformNodeId ) - { - size_t meshInstanceIndex = 0; - - // Get all visual scene nodes, which use this geometry and make the parent connections. - VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter (); - const UniqueIdVec* transformNodes = visualSceneImporter->findGeometryTransformIds ( geometryId ); - size_t numNodeInstances = transformNodes->size (); - - bool found = false; - for ( size_t index=0; index<numNodeInstances && !found; ++index ) - { - const COLLADAFW::UniqueId& nodeId = (*transformNodes) [index]; - if ( nodeId == transformNodeId ) - { - meshInstanceIndex = index; - found = true; - } - } - return meshInstanceIndex; - } - - // -------------------------- void MaterialImporter::connectShadingEngines () { ShadingDataMap::iterator shaderDataIter = mShaderDataMap.begin(); @@ -401,15 +397,12 @@ const EffectImporter::UniqueIdDependNodeMap& effectMap = effectImporter->getMayaEffectMap (); EffectImporter::UniqueIdDependNodeMap::const_iterator it = effectMap.begin (); - String defaultShaderName = ":" + DEFAULT_SHADER_LIST; - MayaDM::DefaultShaderList defaultShaderList ( file, defaultShaderName, "", false ); - //MayaDM::ShadingEngine defaultShadingEngine ( file, defaultShadingEngineName, "", false ); + MayaDM::DefaultShaderList defaultShaderList ( file, DEFAULT_SHADER_LIST, "", false ); size_t shaderIndex = 0; while ( it != effectMap.end () ) { MayaDM::DependNode* dependNode = it->second; - String destination = ":" + DEFAULT_SHADER_LIST + "." + ATTR_SHADERS; connectAttr ( file, dependNode->getMessage (), defaultShaderList.getShaders (shaderIndex) ); ++shaderIndex; ++it; Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaVisualSceneImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaVisualSceneImporter.cpp 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaVisualSceneImporter.cpp 2009-02-18 12:43:48 UTC (rev 367) @@ -61,6 +61,9 @@ importNode ( rootNode ); } + // Write all the node instances + writeNodeInstances (); + return true; } @@ -99,8 +102,8 @@ importTransformations ( node, transformNode ); // Import the instances. + readNodeInstances ( node ); readGeometryInstances ( node ); - readNodeInstances ( node ); readCameraInstances ( node ); readLightInstances ( node ); @@ -670,6 +673,18 @@ } // ----------------------------------- + const BaseImporter::UniqueIdVec* VisualSceneImporter::findTransformInstances ( + const COLLADAFW::UniqueId& transformId ) const + { + UniqueIdUniqueIdsMap::const_iterator it = mTransformInstancesMap.find ( transformId ); + + if ( it != mTransformInstancesMap.end () ) + return &(*it).second; + + return 0; + } + + // ----------------------------------- const BaseImporter::UniqueIdVec* VisualSceneImporter::findGeometryTransformIds ( const COLLADAFW::UniqueId& geometryId ) const { @@ -706,34 +721,65 @@ } // ----------------------------------- - bool VisualSceneImporter::readNodeInstances ( const COLLADAFW::Node* node ) + bool VisualSceneImporter::readNodeInstances ( const COLLADAFW::Node* parentNode ) { - const COLLADAFW::InstanceNodeArray& nodeInstances = node->getInstanceNodes (); + const COLLADAFW::UniqueId& parentNodeId = parentNode->getUniqueId (); + + const COLLADAFW::InstanceNodeArray& nodeInstances = parentNode->getInstanceNodes (); size_t numInstances = nodeInstances.getCount (); for ( size_t i=0; i<numInstances; ++i ) { - const COLLADAFW::InstanceNode* nodeInstance = nodeInstances [i]; - const COLLADAFW::UniqueId& childInstanceId = nodeInstance->getInstanciatedObjectId (); + // Hold the information to create this instance. + const COLLADAFW::InstanceNode* instanceNode = nodeInstances [i]; + const COLLADAFW::UniqueId& instanceNodeId = instanceNode->getInstanciatedObjectId (); - // Check if the original node is already generated! - MayaNode* mayaChildNode = findMayaTransformNode ( childInstanceId ); - String childNodeName = mayaChildNode->getName (); - - // Get the pathes. - const COLLADAFW::UniqueId& nodeId = node->getUniqueId (); - MayaNode* mayaNode = findMayaTransformNode ( nodeId ); - String parentNodePath = mayaNode->getNodePath (); - String childNodePath = mayaChildNode->getNodePath (); - - // parent -shape -noConnections -relative -addObject "|node1|node2" "|rootNode"; - FILE* file = getDocumentImporter ()->getFile (); - MayaDM::parentShape ( file, childNodePath, parentNodePath, false, true, true, true ); + // Push the parent node of the instanciated node in the list of instance node parents. + // The map holds for every transform node a list of all existing parent transform nodes + // (this are the nodes, which hold an instance of the current transform node). + mTransformInstancesMap [ instanceNodeId ].push_back ( parentNodeId ); } return true; } // ----------------------------------- + void VisualSceneImporter::writeNodeInstances () + { + UniqueIdUniqueIdsMap::iterator it = mTransformInstancesMap.begin (); + while ( it != mTransformInstancesMap.end() ) + { + const COLLADAFW::UniqueId& instanceNodeId = it->first; + + BaseImporter::UniqueIdVec& parentNodes = it->second; + size_t numInstances = parentNodes.size (); + for ( size_t i=0; i<numInstances; ++i ) + { + const COLLADAFW::UniqueId& parentNodeId = parentNodes [i]; + + // TODO Check if the original node is already generated! + MayaNode* mayaChildNode = findMayaTransformNode ( instanceNodeId ); + if ( mayaChildNode == 0 ) + { + MGlobal::displayError ( "The referenced transform node doesn't exist!" ); + std::cerr << "The referenced transform node doesn't exist!" << endl; + } + String childNodeName = mayaChildNode->getName (); + String childNodePath = mayaChildNode->getNodePath (); + + // Get the pathes. + MayaNode* mayaParentNode = findMayaTransformNode ( parentNodeId ); + String parentNodePath = mayaParentNode->getNodePath (); + + // parent -shape -noConnections -relative -addObject "|node1|node2" "|rootNode"; + FILE* file = getDocumentImporter ()->getFile (); + MayaDM::parentShape ( file, childNodePath, parentNodePath, false, true, true, true ); + } + + ++it; + } + } + + // ----------------------------------- bool VisualSceneImporter::readGeometryInstances ( const COLLADAFW::Node* node ) { // Get the unique id of the current node. Modified: branches/nextgen/COLLADASaxFrameworkLoader/include/COLLADASaxFWLAssetLoader.h =================================================================== --- branches/nextgen/COLLADASaxFrameworkLoader/include/COLLADASaxFWLAssetLoader.h 2009-02-17 11:37:48 UTC (rev 366) +++ branches/nextgen/COLLADASaxFrameworkLoader/include/COLLADASaxFWLAssetLoader.h 2009-02-18 12:43:48 UTC (rev 367) @@ -139,8 +139,8 @@ virtual bool begin__unit( const unit__AttributeData& attributeData ) { - mAsset->getUnit().mLinearUnit = String ( (char*) attributeData.name ); - mAsset->getUnit().mLinearUnitMeter = attributeData.meter; + mAsset->getUnit().setLinearUnit ( String ( (char*) attributeData.name ) ); + mAsset->getUnit().setLinearUnitMeter ( attributeData.meter ); return true; } virtual bool end__unit(){return true;} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |