From 097a926d943c3b482305c295c60eaff7a85600d8 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Thu, 14 Oct 2010 09:40:56 +0000 Subject: Fix [#24201] COLLADA Exporter: Light source energy incorrect lamp->energy and lamp->distance are now taken in account by calculating the constant, linear and quadratic attenuations based on this. The import tries to do the reverse. Note: this will work only properly for lamps that have att1 and att2 set to 1.0 or 0.0, other lamptypes won't import correctly again. --- source/blender/collada/LightExporter.cpp | 47 +++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'source/blender/collada/LightExporter.cpp') diff --git a/source/blender/collada/LightExporter.cpp b/source/blender/collada/LightExporter.cpp index 7327b309889..5786c682d6a 100644 --- a/source/blender/collada/LightExporter.cpp +++ b/source/blender/collada/LightExporter.cpp @@ -30,6 +30,8 @@ #include "DNA_lamp_types.h" +#include "BLI_math.h" + #include "LightExporter.h" #include "collada_internal.h" @@ -48,6 +50,7 @@ void forEachLampObjectInScene(Scene *sce, Functor &f) } LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryLights(sw){} + void LightsExporter::exportLights(Scene *sce) { openLibrary(); @@ -62,18 +65,45 @@ void LightsExporter::operator()(Object *ob) std::string la_id(get_light_id(ob)); std::string la_name(id_name(la)); COLLADASW::Color col(la->r, la->g, la->b); - float e = la->energy; + float att1, att2; + float e, d, constatt, linatt, quadatt; + att1 = att2 = 0.0f; + + if(la->falloff_type==LA_FALLOFF_INVLINEAR) { + att1 = 1.0f; + att2 = 0.0f; + } + else if(la->falloff_type==LA_FALLOFF_INVSQUARE) { + att1 = 0.0f; + att2 = 1.0f; + } + else if(la->falloff_type==LA_FALLOFF_SLIDERS) { + att1 = la->att1; + att2 = la->att2; + } + + e = la->energy; + d = la->dist; + + constatt = linatt = quadatt = MAXFLOAT; + if(e > 0.0f) { + constatt = 1.0f/e; + linatt = att1/(d*e); + quadatt = att2/(d*d*(e*2)); + } // sun if (la->type == LA_SUN) { COLLADASW::DirectionalLight cla(mSW, la_id, la_name, e); cla.setColor(col); + cla.setConstantAttenuation(constatt); addLight(cla); } // hemi else if (la->type == LA_HEMI) { COLLADASW::AmbientLight cla(mSW, la_id, la_name, e); cla.setColor(col); + cla.setConstantAttenuation(constatt); addLight(cla); } // spot @@ -82,16 +112,18 @@ void LightsExporter::operator()(Object *ob) cla.setColor(col); cla.setFallOffAngle(la->spotsize); cla.setFallOffExponent(la->spotblend); - cla.setLinearAttenuation(la->att1); - cla.setQuadraticAttenuation(la->att2); + cla.setConstantAttenuation(constatt); + cla.setLinearAttenuation(linatt); + cla.setQuadraticAttenuation(quadatt); addLight(cla); } // lamp else if (la->type == LA_LOCAL) { COLLADASW::PointLight cla(mSW, la_id, la_name, e); cla.setColor(col); - cla.setLinearAttenuation(la->att1); - cla.setQuadraticAttenuation(la->att2); + cla.setConstantAttenuation(constatt); + cla.setLinearAttenuation(linatt); + cla.setQuadraticAttenuation(quadatt); addLight(cla); } // area lamp is not supported @@ -99,8 +131,9 @@ void LightsExporter::operator()(Object *ob) else { COLLADASW::PointLight cla(mSW, la_id, la_name, e); cla.setColor(col); - cla.setLinearAttenuation(la->att1); - cla.setQuadraticAttenuation(la->att2); + cla.setConstantAttenuation(constatt); + cla.setLinearAttenuation(linatt); + cla.setQuadraticAttenuation(quadatt); addLight(cla); } } -- cgit v1.2.3