From: <jud...@us...> - 2009-02-16 17:27:36
|
Revision: 363 http://colladamaya.svn.sourceforge.net/colladamaya/?rev=363&view=rev Author: judithschenk Date: 2009-02-16 17:27:30 +0000 (Mon, 16 Feb 2009) Log Message: ----------- import cameras, import lights Modified Paths: -------------- branches/nextgen/COLLADAFramework/include/COLLADAFWCamera.h branches/nextgen/COLLADAFramework/src/COLLADAFWCamera.cpp branches/nextgen/COLLADAMaya/include/COLLADAMayaCameraImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h branches/nextgen/COLLADAMaya/include/COLLADAMayaLightImporter.h branches/nextgen/COLLADAMaya/src/COLLADAMayaCameraImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaGeometryImporter.cpp branches/nextgen/COLLADAMaya/src/COLLADAMayaLightImporter.cpp Modified: branches/nextgen/COLLADAFramework/include/COLLADAFWCamera.h =================================================================== --- branches/nextgen/COLLADAFramework/include/COLLADAFWCamera.h 2009-02-16 15:14:35 UTC (rev 362) +++ branches/nextgen/COLLADAFramework/include/COLLADAFWCamera.h 2009-02-16 17:27:30 UTC (rev 363) @@ -43,10 +43,9 @@ ASPECTRATIO_AND_X, //!< aspect ratio and xfov or xmag, respectively describe the camera ASPECTRATIO_AND_Y, //!< aspect ratio and yfov or <mag, respectivelydescribe the camera }; - - private: + /** The name of the camera*/ String mName; @@ -58,15 +57,12 @@ /** The horizontal field of view or magnification of the view.*/ double mXFovOrXMag; - bool mHasXFovOrXMag; /** The vertical field of view or magnification of the view.*/ double mYFovOrYMag; - bool mHasYFovOrYMag; /** The aspect ratio.*/ double mAspectRatio; - bool mHasAspectRatio; /** The near clipping plane.*/ double mNearClippingPlane; @@ -102,41 +98,32 @@ double getXFov() const { return mXFovOrXMag; } /** Sets the horizontal field of view. Use only for perspective cameras.*/ - void setXFov(double xFov) { mXFovOrXMag = xFov; mHasXFovOrXMag = true; } + void setXFov(double xFov) { mXFovOrXMag = xFov; } /** Returns the horizontal magnification of the view. Use only for orthographic cameras.*/ double getXMag() const { return mXFovOrXMag; } /** Sets the horizontal magnification of the view. Use only for orthographic cameras.*/ - void setXMag(double xMag) { mXFovOrXMag = xMag; mHasXFovOrXMag = true; } + void setXMag(double xMag) { mXFovOrXMag = xMag; } /** Returns the vertical field of view. Use only for perspective cameras.*/ double getYFov() const { return mYFovOrYMag; } /** Sets the vertical field of view. Use only for perspective cameras.*/ - void setYFov(double yFov) { mYFovOrYMag = yFov; mHasYFovOrYMag = true; } + void setYFov(double yFov) { mYFovOrYMag = yFov; } /** Returns the vertical magnification of the view. Use only for orthographic cameras.*/ double getYMag() const { return mYFovOrYMag; } /** Sets the vertical magnification of the view. Use only for orthographic cameras.*/ - void setYMag(double yMag) { mYFovOrYMag = yMag; mHasYFovOrYMag = true; } + void setYMag(double yMag) { mYFovOrYMag = yMag; } - /** The horizontal field of view or magnification of the view.*/ - const bool& getHasXFovOrXMag () const { return mHasXFovOrXMag; } - - /** The vertical field of view or magnification of the view.*/ - const bool& getHasYFovOrYMag () const { return mHasYFovOrYMag; } - /** Returns the aspect ratio.*/ double getAspectRatio() const { return mAspectRatio; } /** Sets the aspect ratio.*/ - void setAspectRatio(double aspectRatio) { mAspectRatio = aspectRatio; mHasAspectRatio = true; } + void setAspectRatio(double aspectRatio) { mAspectRatio = aspectRatio; } - /** The aspect ratio.*/ - const bool& getHasAspectRatio () const { return mHasAspectRatio; } - /** Returns the near clipping plane.*/ double getNearClippingPlane() const { return mNearClippingPlane; } Modified: branches/nextgen/COLLADAFramework/src/COLLADAFWCamera.cpp =================================================================== --- branches/nextgen/COLLADAFramework/src/COLLADAFWCamera.cpp 2009-02-16 15:14:35 UTC (rev 362) +++ branches/nextgen/COLLADAFramework/src/COLLADAFWCamera.cpp 2009-02-16 17:27:30 UTC (rev 363) @@ -21,11 +21,8 @@ , mCameraType(UNDEFINED_CAMERATYPE) , mDescriptionType( UNDEFINED ) , mXFovOrXMag(0) - , mHasXFovOrXMag (false) , mYFovOrYMag(0) - , mHasYFovOrYMag (false) , mAspectRatio(0) - , mHasAspectRatio (false) , mNearClippingPlane(0) , mFarClippingPlane(0) { Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaCameraImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaCameraImporter.h 2009-02-16 15:14:35 UTC (rev 362) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaCameraImporter.h 2009-02-16 17:27:30 UTC (rev 363) @@ -65,8 +65,7 @@ */ void createCamera ( const COLLADAFW::Camera* camera, - MayaNode* mayaTransformNode, - size_t numNodeInstances ); + MayaNode* mayaTransformNode ); void setPerspectiveCameraAttributes ( const COLLADAFW::Camera* camera, Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h 2009-02-16 15:14:35 UTC (rev 362) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaEffectImporter.h 2009-02-16 17:27:30 UTC (rev 363) @@ -113,7 +113,7 @@ const COLLADAFW::Color& standardColor = effect->getStandardColor (); if ( standardColor.isValid () ) - lambert->setColor ( MayaDM::float3 (standardColor.getRed (), standardColor.getGreen (), standardColor.getBlue ()) ); + lambert->setColor ( MayaDM::float3 ( (float)standardColor.getRed (), (float)standardColor.getGreen (), (float)standardColor.getBlue ()) ); const COLLADAFW::ColorOrTexture& diffuse = commonEffect->getDiffuse (); @@ -121,7 +121,7 @@ { const COLLADAFW::Color& color = diffuse.getColor (); if ( color.isValid () ) - lambert->setColor ( MayaDM::float3 (color.getRed (), color.getGreen (), color.getBlue ()) ); + lambert->setColor ( MayaDM::float3 ( (float)color.getRed (), (float)color.getGreen (), (float)color.getBlue ()) ); } else { @@ -134,7 +134,7 @@ { const COLLADAFW::Color& color = emission.getColor (); if ( color.isValid () ) - lambert->setIncandescence ( MayaDM::float3 (color.getRed (), color.getGreen (), color.getBlue ()) ); + lambert->setIncandescence ( MayaDM::float3 ( (float)color.getRed (), (float)color.getGreen (), (float)color.getBlue ()) ); } // TODO @@ -166,7 +166,7 @@ { const COLLADAFW::Color& color = transparent.getColor (); if ( color.isValid () ) - lambert->setTransparency ( MayaDM::float3 (color.getRed (), color.getGreen (), color.getBlue ()) ); + lambert->setTransparency ( MayaDM::float3 ( (float)color.getRed (), (float)color.getGreen (), (float)color.getBlue ()) ); } } Modified: branches/nextgen/COLLADAMaya/include/COLLADAMayaLightImporter.h =================================================================== --- branches/nextgen/COLLADAMaya/include/COLLADAMayaLightImporter.h 2009-02-16 15:14:35 UTC (rev 362) +++ branches/nextgen/COLLADAMaya/include/COLLADAMayaLightImporter.h 2009-02-16 17:27:30 UTC (rev 363) @@ -14,15 +14,35 @@ #include "COLLADAMayaPrerequisites.h" #include "COLLADAMayaBaseImporter.h" +#include "COLLADABUIDList.h" +#include <MayaDMSpotLight.h> +#include <MayaDMPointLight.h> + + namespace COLLADAMaya { /** TODO Documentation */ class LightImporter : BaseImporter { + private: + + /** The standard name for camera without name. */ + static const String LIGHT_NAME; + private: + /** + * The list of the unique maya light names. + */ + COLLADABU::IDList mLightIdList; + + /** + * The map holds the unique ids of the light nodes to the maya specific nodes. + */ + UniqueIdMayaNodesMap mMayaLightNodesMap; + public: /** Constructor. */ @@ -34,8 +54,31 @@ /** * Imports the data of the current light. */ - void importLight ( const COLLADAFW::Light* camera ); + void importLight ( const COLLADAFW::Light* light ); + private: + + /** + * Creates a light. + */ + void createLight ( const COLLADAFW::Light* light, MayaNode* mayaTransformNode ); + + /** + * Sets the spot light specific attributes. + */ + void setSpotLightAttributes ( + const COLLADAFW::Light* light, + MayaDM::Light* mayaLight ); + + /** + * Sets the point light specific attributes. + */ + void setPointLightAttributes ( + const COLLADAFW::Light* light, + MayaDM::Light* mayaLight ); + + MayaNode* findMayaLightNode ( const COLLADAFW::UniqueId& lightId ); + }; } // namespace COLLADAMAYA Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaCameraImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaCameraImporter.cpp 2009-02-16 15:14:35 UTC (rev 362) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaCameraImporter.cpp 2009-02-16 17:27:30 UTC (rev 363) @@ -37,25 +37,19 @@ //------------------------------ void CameraImporter::importCamera ( const COLLADAFW::Camera* camera ) { - // Get the parent transform node, which reference this camera. + // Check if the camera is already imported. const COLLADAFW::UniqueId& cameraId = camera->getUniqueId (); - VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter (); - - // Check if the camera is already imported. if ( findMayaCameraNode ( cameraId ) != 0 ) return; // Get the transform nodes, which work with this camera instance. + VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter (); const UniqueIdVec* transformNodes = visualSceneImporter->findCameraTransformIds ( cameraId ); if ( transformNodes == 0 ) { MGlobal::displayError ( "No camera node which implements this camera!" ); std::cerr << "No camera node which implements this camera!" << endl; } - size_t numNodeInstances = transformNodes->size (); - // The index value of the current geometry instance. - size_t geometryInstanceIndex = 0; - UniqueIdVec::const_iterator nodesIter = transformNodes->begin (); while ( nodesIter != transformNodes->end () ) { @@ -71,7 +65,7 @@ if ( nodesIter == transformNodes->begin() ) { // Create the current mesh node. - createCamera ( camera, mayaTransformNode, numNodeInstances ); + createCamera ( camera, mayaTransformNode ); } else { @@ -91,8 +85,7 @@ //------------------------------ void CameraImporter::createCamera ( const COLLADAFW::Camera* camera, - MayaNode* mayaTransformNode, - size_t numNodeInstances ) + MayaNode* mayaTransformNode ) { // Create a unique name. String cameraName = camera->getName (); @@ -143,28 +136,57 @@ FILE* file = getDocumentImporter ()->getFile (); - if ( camera->getHasAspectRatio () ) + const COLLADAFW::Camera::DescriptionType& description = camera->getDescriptionType (); + switch ( description ) { - double aspectRatio = camera->getAspectRatio (); - MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); - } - else - { - double aspectRatio = camera->getXFov () / camera->getYFov (); - MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); - } + case COLLADAFW::Camera::ASPECTRATIO_AND_X: + { + double aspectRatio = camera->getAspectRatio (); + MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); - if ( camera->getHasYFovOrYMag () ) - { - double verticalFieldOfView = camera->getYFov (); - MayaDM::editCameraVerticalFieldOfView ( file, mayaCamera.getName (), verticalFieldOfView ); + double horizontalFieldOfView = camera->getXFov (); + MayaDM::editCameraHorizontalFieldOfView ( file, mayaCamera.getName (), horizontalFieldOfView ); + } + break; + case COLLADAFW::Camera::ASPECTRATIO_AND_Y: + { + double aspectRatio = camera->getAspectRatio (); + MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); + + double verticalFieldOfView = camera->getYFov (); + MayaDM::editCameraVerticalFieldOfView ( file, mayaCamera.getName (), verticalFieldOfView ); + } + break; + case COLLADAFW::Camera::SINGLE_X: + { + double horizontalFieldOfView = camera->getXFov (); + MayaDM::editCameraHorizontalFieldOfView ( file, mayaCamera.getName (), horizontalFieldOfView ); + } + break; + case COLLADAFW::Camera::SINGLE_Y: + { + double verticalFieldOfView = camera->getYFov (); + MayaDM::editCameraVerticalFieldOfView ( file, mayaCamera.getName (), verticalFieldOfView ); + } + break; + case COLLADAFW::Camera::X_AND_Y: + { + double aspectRatio = camera->getXFov () / camera->getYFov (); + MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); + + double horizontalFieldOfView = camera->getXFov (); + MayaDM::editCameraHorizontalFieldOfView ( file, mayaCamera.getName (), horizontalFieldOfView ); + + double verticalFieldOfView = camera->getYFov (); + MayaDM::editCameraVerticalFieldOfView ( file, mayaCamera.getName (), verticalFieldOfView ); + } + break; + default: + MGlobal::displayError ( "Unknown description type!" ); + std::cerr << "Unknown description type!" << endl; + break; } - if ( camera->getHasXFovOrXMag () ) - { - double horizontalFieldOfView = camera->getXFov (); - MayaDM::editCameraHorizontalFieldOfView ( file, mayaCamera.getName (), horizontalFieldOfView ); - } } //------------------------------ @@ -184,28 +206,51 @@ FILE* file = getDocumentImporter ()->getFile (); - if ( camera->getHasAspectRatio () ) + COLLADAFW::Camera::DescriptionType description = camera->getDescriptionType (); + switch ( description ) { - double aspectRatio = camera->getAspectRatio (); - MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); - } - else - { - double aspectRatio = camera->getXMag () / camera->getYMag (); - MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); - } + case COLLADAFW::Camera::ASPECTRATIO_AND_X: + { + double aspectRatio = camera->getAspectRatio (); + MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); - if ( camera->getHasYFovOrYMag () ) - { - double orthographicHeight = camera->getYMag () / 2; - MayaDM::editCameraOrthographicHeight ( file, mayaCamera.getName (), orthographicHeight ); + double orthographicWidth = camera->getXMag () / 2; + MayaDM::editCameraOrthographicWidth ( file, mayaCamera.getName (), orthographicWidth ); + } + break; + case COLLADAFW::Camera::ASPECTRATIO_AND_Y: + { + double aspectRatio = camera->getAspectRatio (); + MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); + + double orthographicHeight = camera->getYMag () / 2; + MayaDM::editCameraOrthographicHeight ( file, mayaCamera.getName (), orthographicHeight ); + } + break; + case COLLADAFW::Camera::SINGLE_X: + { + double orthographicWidth = camera->getXMag () / 2; + MayaDM::editCameraOrthographicWidth ( file, mayaCamera.getName (), orthographicWidth ); + } + break; + case COLLADAFW::Camera::SINGLE_Y: + { + double orthographicHeight = camera->getYMag () / 2; + MayaDM::editCameraOrthographicHeight ( file, mayaCamera.getName (), orthographicHeight ); + } + break; + case COLLADAFW::Camera::X_AND_Y: + { + double aspectRatio = camera->getXMag () / camera->getYMag (); + MayaDM::editCameraAspectRatio ( file, mayaCamera.getName (), aspectRatio ); + } + break; + default: + MGlobal::displayError ( "Unknown description type!" ); + std::cerr << "Unknown description type!" << endl; + break; } - if ( camera->getHasXFovOrXMag () ) - { - double orthographicWidth = camera->getXMag () / 2; - MayaDM::editCameraOrthographicWidth ( file, mayaCamera.getName (), orthographicWidth ); - } } // -------------------------------------------- @@ -215,7 +260,7 @@ if ( it != mMayaCameraNodesMap.end () ) return &(*it).second; - return NULL; + return 0; } } // namespace COLLADAMaya Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp 2009-02-16 15:14:35 UTC (rev 362) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaDocumentImporter.cpp 2009-02-16 17:27:30 UTC (rev 363) @@ -266,10 +266,10 @@ // ':', '|', '-', '!' are replaced by '_'. const char* c = name.c_str (); - int length = name.length(); + size_t length = name.length(); char* tmp = new char[length + 1]; - for ( int i = 0; i <= length; i++ ) + for ( size_t i = 0; i <= length; i++ ) { char d = c[i]; if ( d == '.' || d == '-' || d == '|' || d == ':' || d == '/' || d == '\\' || d == '(' || d == ')' || d == '[' || d == ']' ) Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaGeometryImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaGeometryImporter.cpp 2009-02-16 15:14:35 UTC (rev 362) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaGeometryImporter.cpp 2009-02-16 17:27:30 UTC (rev 363) @@ -336,9 +336,9 @@ { COLLADABU::Math::Vector3 converted; toLinearUnit ( (*values)[i], (*values)[i+1], (*values)[i+2], converted ); - meshNode.appendVrts ( converted[0] ); - meshNode.appendVrts ( converted[1] ); - meshNode.appendVrts ( converted[2] ); + meshNode.appendVrts ( (float)converted[0] ); + meshNode.appendVrts ( (float)converted[1] ); + meshNode.appendVrts ( (float)converted[2] ); } meshNode.endVrts (); } @@ -352,9 +352,9 @@ { COLLADABU::Math::Vector3 converted; toLinearUnit ( (*values)[i], (*values)[i+1], (*values)[i+2], converted ); - meshNode.appendVrts ( converted[0] ); - meshNode.appendVrts ( converted[1] ); - meshNode.appendVrts ( converted[2] ); + meshNode.appendVrts ( (float)converted[0] ); + meshNode.appendVrts ( (float)converted[1] ); + meshNode.appendVrts ( (float)converted[2] ); } meshNode.endVrts (); } Modified: branches/nextgen/COLLADAMaya/src/COLLADAMayaLightImporter.cpp =================================================================== --- branches/nextgen/COLLADAMaya/src/COLLADAMayaLightImporter.cpp 2009-02-16 15:14:35 UTC (rev 362) +++ branches/nextgen/COLLADAMaya/src/COLLADAMayaLightImporter.cpp 2009-02-16 17:27:30 UTC (rev 363) @@ -10,11 +10,24 @@ #include "COLLADAMayaStableHeaders.h" #include "COLLADAMayaLightImporter.h" +#include "COLLADAMayaVisualSceneImporter.h" +#include "math\COLLADABUMathUtils.h" +#include "COLLADAFWLight.h" + +#include <MayaDMCommands.h> +#include <MayaDMLight.h> +#include <MayaDMAmbientLight.h> +#include <MayaDMDirectionalLight.h> + + namespace COLLADAMaya { + const String LightImporter::LIGHT_NAME = "Light"; + + //------------------------------ LightImporter::LightImporter ( DocumentImporter* documentImporter ) : BaseImporter ( documentImporter ) @@ -27,9 +40,174 @@ } //------------------------------ - void LightImporter::importLight ( const COLLADAFW::Light* camera ) + void LightImporter::importLight ( const COLLADAFW::Light* light ) { + // Check if the camera is already imported. + const COLLADAFW::UniqueId& lightId = light->getUniqueId (); + if ( findMayaLightNode ( lightId ) != 0 ) return; + // Get the transform nodes, which work with this camera instance. + VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter (); + const UniqueIdVec* transformNodes = visualSceneImporter->findCameraTransformIds ( lightId ); + if ( transformNodes == 0 ) + { + MGlobal::displayError ( "No camera node which implements this camera!" ); + std::cerr << "No camera node which implements this camera!" << endl; + } + + UniqueIdVec::const_iterator nodesIter = transformNodes->begin (); + while ( nodesIter != transformNodes->end () ) + { + // Get the maya node of the current transform node. + const COLLADAFW::UniqueId& transformNodeId = *nodesIter; + MayaNode* mayaTransformNode = visualSceneImporter->findMayaTransformNode ( transformNodeId ); + String transformNodeName = mayaTransformNode->getName (); + + // Get the path to the parent transform node. + String transformNodePath = mayaTransformNode->getNodePath (); + + // The first reference is a direct one, the others are instances. + if ( nodesIter == transformNodes->begin() ) + { + // Create the current mesh node. + createLight ( light, mayaTransformNode ); + } + else + { + // Get the path to the mesh. + MayaNode* mayaLightNode = findMayaLightNode ( lightId ); + String lightNodePath = mayaLightNode->getNodePath (); + + // parent -shape -noConnections -relative -addObject "|pCube1|pCubeShape1" "pCube2"; + FILE* file = getDocumentImporter ()->getFile (); + MayaDM::parentShape ( file, lightNodePath, transformNodePath, false, true, true, true ); + } + + ++nodesIter; + } } + // -------------------------------------------- + void LightImporter::createLight ( + const COLLADAFW::Light* light, + MayaNode* mayaTransformNode ) + { + // Check if the camera is already imported. + const COLLADAFW::UniqueId& lightId = light->getUniqueId (); + + // Create a unique name. + String lightName = light->getName (); + if ( COLLADABU::Utils::equals ( lightName, "" ) ) + lightName = LIGHT_NAME; + lightName = mLightIdList.addId ( lightName ); + + // Create a maya node object of the current node and push it into the map. + MayaNode mayaMeshNode ( lightId, lightName, mayaTransformNode ); + mMayaLightNodesMap [ lightId ] = mayaMeshNode; + + FILE* file = getDocumentImporter ()->getFile (); + + MayaDM::Light* mayaLight = 0; + COLLADAFW::Light::LightType lightType = light->getLightType (); + switch ( lightType ) + { + case COLLADAFW::Light::AMBIENT_LIGHT: + { + mayaLight = new MayaDM::AmbientLight ( file, lightName, mayaTransformNode->getNodePath () ); + } + break; + case COLLADAFW::Light::DIRECTIONAL_LIGHT: + { + mayaLight = new MayaDM::DirectionalLight ( file, lightName, mayaTransformNode->getNodePath () ); + } + break; + case COLLADAFW::Light::POINT_LIGHT: + { + mayaLight = new MayaDM::PointLight ( file, lightName, mayaTransformNode->getNodePath () ); + setPointLightAttributes ( light, mayaLight ); + } + break; + case COLLADAFW::Light::SPOT_LIGHT: + { + mayaLight = new MayaDM::SpotLight ( file, lightName, mayaTransformNode->getNodePath () ); + setSpotLightAttributes ( light, mayaLight ); + } + break; + default: + MGlobal::displayError ( "Unknown light type!" ); + std::cerr << "Unknown light type!" << endl; + return; + break; + } + + COLLADAFW::Color color = light->getColor (); + mayaLight->setColor ( MayaDM::float3 ( (float)color.getRed (), (float)color.getGreen (), (float)color.getBlue () ) ); + + delete mayaLight; + } + + // -------------------------------------------- + MayaNode* LightImporter::findMayaLightNode ( const COLLADAFW::UniqueId& lightId ) + { + UniqueIdMayaNodesMap::iterator it = mMayaLightNodesMap.find ( lightId ); + if ( it != mMayaLightNodesMap.end () ) + return &(*it).second; + + return 0; + } + + // -------------------------------------------- + void LightImporter::setPointLightAttributes ( + const COLLADAFW::Light* light, + MayaDM::Light* mayaLight ) + { + MayaDM::PointLight* pointLight = (MayaDM::PointLight*)mayaLight; + + // Attenuation in COLLADA is equal to Decay in Maya. + double constant = light->getConstantAttenuation (); + double linear = light->getLinearAttenuation (); + double quadratic = light->getQuadraticAttenuation (); + + // TODO If light is animated, the values have to change! + if ( quadratic > linear && quadratic > constant ) + pointLight->setDecayRate ( 2 ); + else if ( linear > constant ) + pointLight->setDecayRate ( 1 ); + else pointLight->setDecayRate ( 0 ); + } + + // -------------------------------------------- + void LightImporter::setSpotLightAttributes ( + const COLLADAFW::Light* light, + MayaDM::Light* mayaLight ) + { + MayaDM::SpotLight* spotLight = (MayaDM::SpotLight*)mayaLight; + + // Attenuation in COLLADA is equal to Decay in Maya. + double constant = light->getConstantAttenuation (); + double linear = light->getLinearAttenuation (); + double quadratic = light->getQuadraticAttenuation (); + + // TODO If light is animated, the values have to change! + if ( quadratic > linear && quadratic > constant ) + spotLight->setDecayRate ( 2 ); + else if ( linear > constant ) + spotLight->setDecayRate ( 1 ); + else spotLight->setDecayRate ( 0 ); + + // Drop-off + double dropOff; + if ( COLLADABU::Math::Utils::equals ( light->getFallOffExponent (), 0.0 ) ) dropOff = 0.0; + else dropOff = 1.0; // COLLADA 1.4 took out the fallOffScale, for some reason. + spotLight->setDropoff ( dropOff ); + + // Cone and Penumbra Angles + double fallOffAngle = light->getFallOffAngle (); + spotLight->setConeAngle ( COLLADABU::Math::Utils::degToRad ( fallOffAngle ) ); + +// double penumbraAngle = ( light->getOuterAngle() - light->getFallOffAngle() ) / 2.0f; +// spotLight->setPenumbraAngle ( COLLADABU::Math::Utils::degToRad ( penumbraAngle )); + + } + } // namespace COLLADAMaya This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |