bool MayaObject::shadowMapCastingLight() { if(!this->mobject.hasFn(MFn::kLight)) return false; MFnDependencyNode lightFn(this->mobject); bool useDepthMapShadows = false; if(!getBool(MString("useDepthMapShadows"), lightFn, useDepthMapShadows)) return false; if(!useDepthMapShadows) return false; return true; }
// ------------------------------------ bool LightExporter::exportLight ( const MDagPath& dagPath ) { if ( !ExportOptions::exportLights() ) return false; MObject lightNode = dagPath.node(); // Retrieve the Maya light object MStatus status; MFnLight lightFn(lightNode, &status); CHECK_STAT(status); if (status != MStatus::kSuccess) return false; // Get the maya light id. String mayaLightId = mDocumentExporter->dagPathToColladaId ( dagPath ); // Generate a COLLADA id for the new object String colladaLightId; // Check if there is an extra attribute "colladaId" and use this as export id. MString attributeValue; DagHelper::getPlugValue ( lightNode, COLLADA_ID_ATTRIBUTE_NAME, attributeValue ); if ( attributeValue != EMPTY_CSTRING ) { // Generate a valid collada name, if necessary. colladaLightId = mDocumentExporter->mayaNameToColladaName ( attributeValue, false ); } else { // Generate a COLLADA id for the new object colladaLightId = mDocumentExporter->dagPathToColladaId ( dagPath ); } // Make the id unique and store it in a map. colladaLightId = mLightIdList.addId ( colladaLightId ); mMayaIdColladaIdMap [ mayaLightId ] = colladaLightId; // Get a pointer to the stream writer. COLLADASW::StreamWriter* streamWriter = mDocumentExporter->getStreamWriter(); // The light name String lightName = mDocumentExporter->dagPathToColladaName ( dagPath ); // Figure out the type of light and create it COLLADASW::Light* light = NULL; MFn::Type type = lightNode.apiType(); switch (type) { case MFn::kAmbientLight: light = new COLLADASW::AmbientLight( streamWriter, colladaLightId, lightName ); break; case MFn::kDirectionalLight: light = new COLLADASW::DirectionalLight( streamWriter, colladaLightId, lightName ); break; case MFn::kSpotLight: light = new COLLADASW::SpotLight( streamWriter, colladaLightId, lightName ); break; case MFn::kPointLight: // Intentional pass-through default: light = new COLLADASW::PointLight( streamWriter, colladaLightId, lightName ); break; } // Export the original maya name. light->addExtraTechniqueParameter ( PROFILE_MAYA, PARAMETER_MAYA_ID, mayaLightId ); // Get a pointer to the animation exporter. AnimationExporter* anim = mDocumentExporter->getAnimationExporter(); bool animated = false; // Color/Intensity are the common attributes of all lights MColor mayaColor = lightFn.color ( &status ); CHECK_STAT(status); COLLADASW::Color lightColor ( mayaColor.r, mayaColor.g, mayaColor.b, mayaColor.a ); animated = anim->addNodeAnimation ( lightNode, ATTR_COLOR, kColour, RGBA_PARAMETERS ); light->setColor( lightColor, animated ); float intensity = lightFn.intensity ( &status ); CHECK_STAT(status); animated = anim->addNodeAnimation ( lightNode, ATTR_INTENSITY, kSingle ); light->setIntensity( intensity, animated ); // Export light intensity light->addExtraTechniqueParameter(PROFILE_MAYA, ATTR_INTENSITY, intensity); // Add the type specific attributes if (lightNode.hasFn(MFn::kNonAmbientLight)) { // Needed Point and Spot light types parameters: Attenuation and Attenuation_Scale // Attenuation in COLLADA is equal to Decay in Maya. MFnNonAmbientLight naLightFn(lightNode); int decayRate = naLightFn.decayRate(&status); CHECK_STAT(status); decayRate = std::min ( decayRate, 2 ); decayRate = std::max ( decayRate, 0 ); light->setConstantAttenuation ( ( decayRate == 0 ) ? 1.0f : 0.0f); light->setLinearAttenuation ( ( decayRate == 1 ) ? 1.0f : 0.0f); light->setQuadraticAttenuation ( ( decayRate == 2 ) ? 1.0f : 0.0f); } else if (lightNode.hasFn(MFn::kAmbientLight)) { MFnAmbientLight ambientLightFn ( lightNode ); float ambientShade = ambientLightFn.ambientShade(); String paramSid = EMPTY_STRING; animated = anim->addNodeAnimation ( lightNode, ATTR_AMBIENT_SHADE, kSingle ); if ( animated ) paramSid = ATTR_AMBIENT_SHADE; light->addExtraTechniqueParameter ( PROFILE_MAYA, MAYA_AMBIENTSHADE_LIGHT_PARAMETER, ambientShade, paramSid ); } if (lightNode.hasFn(MFn::kSpotLight)) { // Put in the needed spot light type attributes : Falloff, Falloff_Scale and Angle MFnSpotLight spotFn(lightNode); float fallOffAngle = COLLADABU::Math::Utils::radToDegF ( (float)spotFn.coneAngle( &status ) ); CHECK_STAT(status); animated = anim->addNodeAnimation ( lightNode, ATTR_CONE_ANGLE, ( SampleType ) ( kSingle | kAngle ) ); light->setFallOffAngle ( fallOffAngle, animated ); light->setFallOffExponent ( 1.0f ); float penumbraValue = COLLADABU::Math::Utils::radToDegF ( (float)spotFn.penumbraAngle( &status ) ); CHECK_STAT(status); animated = anim->addNodeAnimation ( lightNode, ATTR_PENUMBRA_ANGLE, ( SampleType ) ( kSingle | kAngle ) ); // Export spot setting float dropOff = (float)spotFn.dropOff(&status); CHECK_STAT(status); light->addExtraTechniqueParameter(PROFILE_MAYA, MAYA_PENUMBRA_LIGHT_PARAMETER, penumbraValue); light->addExtraTechniqueParameter(PROFILE_MAYA, MAYA_DROPOFF_LIGHT_PARAMETER, dropOff); // TODO // FCDLightTools::LoadPenumbra(light, penumbraValue, colladaLight->GetOuterAngle().GetAnimated()); // TODO // animated = anim->addNodeAnimation ( lightNode, ATTR_DROP_OFF, kSingle ); // light->setDropOff ( (float) spotFn.dropOff ( &status ), animated ); CHECK_MSTATUS(status); } SceneElement* sceneElement = NULL; SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph(); sceneElement = sceneGraph->findElement(dagPath); exportExtraAttributes(sceneElement, light); addLight ( *light ); delete light; return true; }