示例#1
0
Lamp *rna_Main_lamps_new(Main *UNUSED(bmain), const char *name, int type)
{
	Lamp *lamp= add_lamp(name);
	lamp->type= type;
	id_us_min(&lamp->id);
	return lamp;
}
示例#2
0
/** When this method is called, the writer must write the light.
	@return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeLight( const COLLADAFW::Light* light ) 
{
	if(mImportStage!=General)
		return true;

	Lamp *lamp = NULL;
	std::string la_id, la_name;

	TagsMap::iterator etit;
	ExtraTags *et = 0;
	etit = uid_tags_map.find(light->getUniqueId().toAscii());
	if(etit != uid_tags_map.end())
		et = etit->second;

	la_id = light->getOriginalId();
	la_name = light->getName();
	if (la_name.size()) lamp = (Lamp*)add_lamp((char*)la_name.c_str());
	else lamp = (Lamp*)add_lamp((char*)la_id.c_str());

	if (!lamp) {
		fprintf(stderr, "Cannot create lamp. \n");
		return true;
	}

	// if we find an ExtraTags for this, use that instead.
	if(et && et->isProfile("blender")) {
		et->setData("type", &(lamp->type));
		et->setData("flag", &(lamp->flag));
		et->setData("mode", &(lamp->mode));
		et->setData("gamma", &(lamp->k));
		et->setData("red", &(lamp->r));
		et->setData("green", &(lamp->g));
		et->setData("blue", &(lamp->b));
		et->setData("shadow_r", &(lamp->shdwr));
		et->setData("shadow_g", &(lamp->shdwg));
		et->setData("shadow_b", &(lamp->shdwb));
		et->setData("energy", &(lamp->energy));
		et->setData("dist", &(lamp->dist));
		et->setData("spotsize", &(lamp->spotsize));
		et->setData("spotblend", &(lamp->spotblend));
		et->setData("halo_intensity", &(lamp->haint));
		et->setData("att1", &(lamp->att1));
		et->setData("att2", &(lamp->att2));
		et->setData("falloff_type", &(lamp->falloff_type));
		et->setData("clipsta", &(lamp->clipsta));
		et->setData("clipend", &(lamp->clipend));
		et->setData("shadspotsize", &(lamp->shadspotsize));
		et->setData("bias", &(lamp->bias));
		et->setData("soft", &(lamp->soft));
		et->setData("compressthresh", &(lamp->compressthresh));
		et->setData("bufsize", &(lamp->bufsize));
		et->setData("samp", &(lamp->samp));
		et->setData("buffers", &(lamp->buffers));
		et->setData("filtertype", &(lamp->filtertype));
		et->setData("bufflag", &(lamp->bufflag));
		et->setData("buftype", &(lamp->buftype));
		et->setData("ray_samp", &(lamp->ray_samp));
		et->setData("ray_sampy", &(lamp->ray_sampy));
		et->setData("ray_sampz", &(lamp->ray_sampz));
		et->setData("ray_samp_type", &(lamp->ray_samp_type));
		et->setData("area_shape", &(lamp->area_shape));
		et->setData("area_size", &(lamp->area_size));
		et->setData("area_sizey", &(lamp->area_sizey));
		et->setData("area_sizez", &(lamp->area_sizez));
		et->setData("adapt_thresh", &(lamp->adapt_thresh));
		et->setData("ray_samp_method", &(lamp->ray_samp_method));
		et->setData("shadhalostep", &(lamp->shadhalostep));
		et->setData("sun_effect_type", &(lamp->shadhalostep));
		et->setData("skyblendtype", &(lamp->skyblendtype));
		et->setData("horizon_brightness", &(lamp->horizon_brightness));
		et->setData("spread", &(lamp->spread));
		et->setData("sun_brightness", &(lamp->sun_brightness));
		et->setData("sun_size", &(lamp->sun_size));
		et->setData("backscattered_light", &(lamp->backscattered_light));
		et->setData("sun_intensity", &(lamp->sun_intensity));
		et->setData("atm_turbidity", &(lamp->atm_turbidity));
		et->setData("atm_extinction_factor", &(lamp->atm_extinction_factor));
		et->setData("atm_distance_factor", &(lamp->atm_distance_factor));
		et->setData("skyblendfac", &(lamp->skyblendfac));
		et->setData("sky_exposure", &(lamp->sky_exposure));
		et->setData("sky_colorspace", &(lamp->sky_colorspace));
	}
	else {
		float constatt = light->getConstantAttenuation().getValue();
		float linatt = light->getLinearAttenuation().getValue();
		float quadatt = light->getQuadraticAttenuation().getValue();
		float d = 25.0f;
		float att1 = 0.0f;
		float att2 = 0.0f;
		float e = 1.0f;

		if (light->getColor().isValid()) {
			COLLADAFW::Color col = light->getColor();
			lamp->r = col.getRed();
			lamp->g = col.getGreen();
			lamp->b = col.getBlue();
		}

		if(IS_EQ(linatt, 0.0f) && quadatt > 0.0f) {
			att2 = quadatt;
			d = sqrt(1.0f/quadatt);
		}
		// linear light
		else if(IS_EQ(quadatt, 0.0f) && linatt > 0.0f) {
			att1 = linatt;
			d = (1.0f/linatt);
		} else if (IS_EQ(constatt, 1.0f)) {
			att1 = 1.0f;
		} else {
			// assuming point light (const att = 1.0);
			att1 = 1.0f;
		}
		
		d *= ( 1.0f / unit_converter.getLinearMeter());

		lamp->energy = e;
		lamp->dist = d;

		COLLADAFW::Light::LightType type = light->getLightType();
		switch(type) {
			case COLLADAFW::Light::AMBIENT_LIGHT:
				{
					lamp->type = LA_HEMI;
				}
				break;
			case COLLADAFW::Light::SPOT_LIGHT:
				{
					lamp->type = LA_SPOT;
					lamp->att1 = att1;
					lamp->att2 = att2;
					if(IS_EQ(att1, 0.0f) && att2 > 0)
						lamp->falloff_type = LA_FALLOFF_INVSQUARE;
					if(IS_EQ(att2, 0.0f) && att1 > 0)
						lamp->falloff_type = LA_FALLOFF_INVLINEAR;
					lamp->spotsize = light->getFallOffAngle().getValue();
					lamp->spotblend = light->getFallOffExponent().getValue();
				}
				break;
			case COLLADAFW::Light::DIRECTIONAL_LIGHT:
				{
					/* our sun is very strong, so pick a smaller energy level */
					lamp->type = LA_SUN;
					lamp->mode |= LA_NO_SPEC;
				}
				break;
			case COLLADAFW::Light::POINT_LIGHT:
				{
					lamp->type = LA_LOCAL;
					lamp->att1 = att1;
					lamp->att2 = att2;
					if(IS_EQ(att1, 0.0f) && att2 > 0)
						lamp->falloff_type = LA_FALLOFF_INVSQUARE;
					if(IS_EQ(att2, 0.0f) && att1 > 0)
						lamp->falloff_type = LA_FALLOFF_INVLINEAR;
				}
				break;
			case COLLADAFW::Light::UNDEFINED:
				{
					fprintf(stderr, "Current lamp type is not supported. \n");
					lamp->type = LA_LOCAL;
				}
				break;
		}
	}

	this->uid_lamp_map[light->getUniqueId()] = lamp;
	this->FW_object_map[light->getUniqueId()] = light;
	return true;
}