示例#1
0
bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Lamp *la)
{
	cla.addExtraTechniqueParameter("blender", "type", la->type);
	cla.addExtraTechniqueParameter("blender", "flag", la->flag);
	cla.addExtraTechniqueParameter("blender", "mode", la->mode);
	cla.addExtraTechniqueParameter("blender", "gamma", la->k, "blender_gamma");
	cla.addExtraTechniqueParameter("blender", "red", la->r);
	cla.addExtraTechniqueParameter("blender", "green", la->g);
	cla.addExtraTechniqueParameter("blender", "blue", la->b);
	cla.addExtraTechniqueParameter("blender", "shadow_r", la->shdwr, "blender_shadow_r");
	cla.addExtraTechniqueParameter("blender", "shadow_g", la->shdwg, "blender_shadow_g");
	cla.addExtraTechniqueParameter("blender", "shadow_b", la->shdwb, "blender_shadow_b");
	cla.addExtraTechniqueParameter("blender", "energy", la->energy, "blender_energy");
	cla.addExtraTechniqueParameter("blender", "dist", la->dist, "blender_dist");
	cla.addExtraTechniqueParameter("blender", "spotsize", la->spotsize);
	cla.addExtraTechniqueParameter("blender", "spotblend", la->spotblend);
	cla.addExtraTechniqueParameter("blender", "halo_intensity", la->haint, "blnder_halo_intensity");
	cla.addExtraTechniqueParameter("blender", "att1", la->att1);
	cla.addExtraTechniqueParameter("blender", "att2", la->att2);
	// \todo figure out how we can have falloff curve supported here
	cla.addExtraTechniqueParameter("blender", "falloff_type", la->falloff_type);
	cla.addExtraTechniqueParameter("blender", "clipsta", la->clipsta);
	cla.addExtraTechniqueParameter("blender", "clipend", la->clipend);
	cla.addExtraTechniqueParameter("blender", "shadspotsize", la->shadspotsize);
	cla.addExtraTechniqueParameter("blender", "bias", la->bias);
	cla.addExtraTechniqueParameter("blender", "soft", la->soft);
	cla.addExtraTechniqueParameter("blender", "compressthresh", la->compressthresh);
	cla.addExtraTechniqueParameter("blender", "bufsize", la->bufsize);
	cla.addExtraTechniqueParameter("blender", "samp", la->samp);
	cla.addExtraTechniqueParameter("blender", "buffers", la->buffers);
	cla.addExtraTechniqueParameter("blender", "filtertype", la->filtertype);
	cla.addExtraTechniqueParameter("blender", "bufflag", la->bufflag);
	cla.addExtraTechniqueParameter("blender", "buftype", la->buftype);
	cla.addExtraTechniqueParameter("blender", "ray_samp", la->ray_samp);
	cla.addExtraTechniqueParameter("blender", "ray_sampy", la->ray_sampy);
	cla.addExtraTechniqueParameter("blender", "ray_sampz", la->ray_sampz);
	cla.addExtraTechniqueParameter("blender", "ray_samp_type", la->ray_samp_type);
	cla.addExtraTechniqueParameter("blender", "area_shape", la->area_shape);
	cla.addExtraTechniqueParameter("blender", "area_size", la->area_size);
	cla.addExtraTechniqueParameter("blender", "area_sizey", la->area_sizey);
	cla.addExtraTechniqueParameter("blender", "area_sizez", la->area_sizez);
	cla.addExtraTechniqueParameter("blender", "adapt_thresh", la->adapt_thresh);
	cla.addExtraTechniqueParameter("blender", "ray_samp_method", la->ray_samp_method);
	cla.addExtraTechniqueParameter("blender", "shadhalostep", la->shadhalostep);
	cla.addExtraTechniqueParameter("blender", "sun_effect_type", la->shadhalostep);
	cla.addExtraTechniqueParameter("blender", "skyblendtype", la->skyblendtype);
	cla.addExtraTechniqueParameter("blender", "horizon_brightness", la->horizon_brightness);
	cla.addExtraTechniqueParameter("blender", "spread", la->spread);
	cla.addExtraTechniqueParameter("blender", "sun_brightness", la->sun_brightness);
	cla.addExtraTechniqueParameter("blender", "sun_size", la->sun_size);
	cla.addExtraTechniqueParameter("blender", "backscattered_light", la->backscattered_light);
	cla.addExtraTechniqueParameter("blender", "sun_intensity", la->sun_intensity);
	cla.addExtraTechniqueParameter("blender", "atm_turbidity", la->atm_turbidity);
	cla.addExtraTechniqueParameter("blender", "atm_extinction_factor", la->atm_extinction_factor);
	cla.addExtraTechniqueParameter("blender", "atm_distance_factor", la->atm_distance_factor);
	cla.addExtraTechniqueParameter("blender", "skyblendfac", la->skyblendfac);
	cla.addExtraTechniqueParameter("blender", "sky_exposure", la->sky_exposure);
	cla.addExtraTechniqueParameter("blender", "sky_colorspace", la->sky_colorspace);
	
	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;
    }
示例#3
0
bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Light *la)
{
  cla.addExtraTechniqueParameter("blender", "type", la->type);
  cla.addExtraTechniqueParameter("blender", "flag", la->flag);
  cla.addExtraTechniqueParameter("blender", "mode", la->mode);
  cla.addExtraTechniqueParameter("blender", "gamma", la->k, "blender_gamma");
  cla.addExtraTechniqueParameter("blender", "red", la->r);
  cla.addExtraTechniqueParameter("blender", "green", la->g);
  cla.addExtraTechniqueParameter("blender", "blue", la->b);
  cla.addExtraTechniqueParameter("blender", "shadow_r", la->shdwr, "blender_shadow_r");
  cla.addExtraTechniqueParameter("blender", "shadow_g", la->shdwg, "blender_shadow_g");
  cla.addExtraTechniqueParameter("blender", "shadow_b", la->shdwb, "blender_shadow_b");
  cla.addExtraTechniqueParameter("blender", "energy", la->energy, "blender_energy");
  cla.addExtraTechniqueParameter("blender", "dist", la->dist, "blender_dist");
  cla.addExtraTechniqueParameter("blender", "spotsize", RAD2DEGF(la->spotsize));
  cla.addExtraTechniqueParameter("blender", "spotblend", la->spotblend);
  cla.addExtraTechniqueParameter("blender", "att1", la->att1);
  cla.addExtraTechniqueParameter("blender", "att2", la->att2);
  // \todo figure out how we can have falloff curve supported here
  cla.addExtraTechniqueParameter("blender", "falloff_type", la->falloff_type);
  cla.addExtraTechniqueParameter("blender", "clipsta", la->clipsta);
  cla.addExtraTechniqueParameter("blender", "clipend", la->clipend);
  cla.addExtraTechniqueParameter("blender", "bias", la->bias);
  cla.addExtraTechniqueParameter("blender", "soft", la->soft);
  cla.addExtraTechniqueParameter("blender", "bufsize", la->bufsize);
  cla.addExtraTechniqueParameter("blender", "samp", la->samp);
  cla.addExtraTechniqueParameter("blender", "buffers", la->buffers);
  cla.addExtraTechniqueParameter("blender", "area_shape", la->area_shape);
  cla.addExtraTechniqueParameter("blender", "area_size", la->area_size);
  cla.addExtraTechniqueParameter("blender", "area_sizey", la->area_sizey);
  cla.addExtraTechniqueParameter("blender", "area_sizez", la->area_sizez);

  return true;
}