2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2010-10-06 07:13:42 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup collada
|
2011-02-27 20:30:35 +00:00
|
|
|
*/
|
|
|
|
|
2010-10-06 07:13:42 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "COLLADASWColor.h"
|
|
|
|
#include "COLLADASWLight.h"
|
|
|
|
|
2010-10-14 09:40:56 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
2010-10-06 07:13:42 +00:00
|
|
|
#include "LightExporter.h"
|
|
|
|
#include "collada_internal.h"
|
|
|
|
|
|
|
|
template<class Functor>
|
2019-02-27 12:02:02 +11:00
|
|
|
void forEachLightObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
|
2010-10-06 07:13:42 +00:00
|
|
|
{
|
2012-06-12 21:25:29 +00:00
|
|
|
LinkNode *node;
|
2012-06-12 22:05:33 +00:00
|
|
|
for (node = export_set; node; node = node->next) {
|
2012-06-12 21:25:29 +00:00
|
|
|
Object *ob = (Object *)node->link;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 21:25:29 +00:00
|
|
|
if (ob->type == OB_LAMP && ob->data) {
|
2010-10-06 07:13:42 +00:00
|
|
|
f(ob);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 12:17:17 +02:00
|
|
|
LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
|
2012-06-12 22:05:33 +00:00
|
|
|
: COLLADASW::LibraryLights(sw), export_settings(export_settings)
|
|
|
|
{
|
|
|
|
}
|
2010-10-14 09:40:56 +00:00
|
|
|
|
2011-09-07 18:23:30 +00:00
|
|
|
void LightsExporter::exportLights(Scene *sce)
|
2010-10-06 07:13:42 +00:00
|
|
|
{
|
|
|
|
openLibrary();
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2019-05-23 12:17:17 +02:00
|
|
|
forEachLightObjectInExportSet(sce, *this, this->export_settings.get_export_set());
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-06 07:13:42 +00:00
|
|
|
closeLibrary();
|
|
|
|
}
|
2011-07-02 05:05:03 +00:00
|
|
|
|
2010-10-06 07:13:42 +00:00
|
|
|
void LightsExporter::operator()(Object *ob)
|
|
|
|
{
|
2019-02-27 10:46:48 +11:00
|
|
|
Light *la = (Light *)ob->data;
|
2010-10-06 07:13:42 +00:00
|
|
|
std::string la_id(get_light_id(ob));
|
|
|
|
std::string la_name(id_name(la));
|
2011-03-30 10:51:01 +00:00
|
|
|
COLLADASW::Color col(la->r * la->energy, la->g * la->energy, la->b * la->energy);
|
2011-06-20 10:22:39 +00:00
|
|
|
float d, constatt, linatt, quadatt;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-14 09:40:56 +00:00
|
|
|
d = la->dist;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-03-30 10:51:01 +00:00
|
|
|
constatt = 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
if (la->falloff_type == LA_FALLOFF_INVLINEAR) {
|
2011-06-13 15:07:36 +00:00
|
|
|
linatt = 1.0f / d;
|
2011-03-30 10:51:01 +00:00
|
|
|
quadatt = 0.0f;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
linatt = 0.0f;
|
2011-06-13 15:07:36 +00:00
|
|
|
quadatt = 1.0f / (d * d);
|
2010-10-14 09:40:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-06 07:13:42 +00:00
|
|
|
/* sun */
|
|
|
|
if (la->type == LA_SUN) {
|
2011-06-20 10:22:39 +00:00
|
|
|
COLLADASW::DirectionalLight cla(mSW, la_id, la_name);
|
2012-04-29 15:47:02 +00:00
|
|
|
cla.setColor(col, false, "color");
|
2010-10-14 09:40:56 +00:00
|
|
|
cla.setConstantAttenuation(constatt);
|
2011-03-27 09:46:20 +00:00
|
|
|
exportBlenderProfile(cla, la);
|
2010-10-06 07:13:42 +00:00
|
|
|
addLight(cla);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-06 07:13:42 +00:00
|
|
|
/* spot */
|
|
|
|
else if (la->type == LA_SPOT) {
|
2011-06-20 10:22:39 +00:00
|
|
|
COLLADASW::SpotLight cla(mSW, la_id, la_name);
|
2012-04-29 15:47:02 +00:00
|
|
|
cla.setColor(col, false, "color");
|
Cleanup: Internal degrees removal.
This patch changes most of the reamining degrees usage in internal code into radians.
I let a few which I know off asside, for reasons explained below - and I'm not sure to have found out all of them.
WARNING: this introduces forward incompatibility, which means files saved from this version won't open 100% correctly
in previous versions (a few angle properties would use radians values as degrees...).
Details:
- Data:
-- Lamp.spotsize: Game engine exposed this setting in degrees, to not break the API here I kept it as such
(using getter/setter functions), still using radians internally.
-- Mesh.smoothresh: Didn't touch to this one, as we will hopefully replace it completely by loop normals currently in dev.
- Modifiers:
-- EdgeSplitModifierData.split_angle, BevelModifierData.bevel_angle: Done.
- Postprocessing:
-- WipeVars.angle (sequencer's effect), NodeBokehImage.angle, NodeBoxMask.rotation, NodeEllipseMask.rotation: Done.
- BGE:
-- bConstraintActuator: Orientation type done (the minloc[0] & maxloc[0] cases). Did not touch to 'limit location' type,
it can also limit rotation, but it exposes through RNA the same limit_min/limit_max, which hence
can be either distance or angle values, depending on the mode. Will leave this to BGE team.
-- bSoundActuator.cone_outer_angle_3d, bSoundActuator.cone_inner_angle_3d: Done (note I kept degrees in BGE itself,
as it seems this is the expected value here...).
-- bRadarSensor.angle: Done.
Reviewers: brecht, campbellbarton, sergey, gaiaclary, dfelinto, moguri, jbakker, lukastoenne, howardt
Reviewed By: brecht, campbellbarton, sergey, gaiaclary, moguri, jbakker, lukastoenne, howardt
Thanks to all!
Differential Revision: http://developer.blender.org/D59
2013-12-03 20:09:25 +01:00
|
|
|
cla.setFallOffAngle(RAD2DEGF(la->spotsize), false, "fall_off_angle");
|
2012-04-29 15:47:02 +00:00
|
|
|
cla.setFallOffExponent(la->spotblend, false, "fall_off_exponent");
|
2010-10-14 09:40:56 +00:00
|
|
|
cla.setConstantAttenuation(constatt);
|
|
|
|
cla.setLinearAttenuation(linatt);
|
|
|
|
cla.setQuadraticAttenuation(quadatt);
|
2011-03-27 09:46:20 +00:00
|
|
|
exportBlenderProfile(cla, la);
|
2010-10-06 07:13:42 +00:00
|
|
|
addLight(cla);
|
|
|
|
}
|
|
|
|
/* lamp */
|
|
|
|
else if (la->type == LA_LOCAL) {
|
2011-06-20 10:22:39 +00:00
|
|
|
COLLADASW::PointLight cla(mSW, la_id, la_name);
|
2012-04-29 15:47:02 +00:00
|
|
|
cla.setColor(col, false, "color");
|
2010-10-14 09:40:56 +00:00
|
|
|
cla.setConstantAttenuation(constatt);
|
|
|
|
cla.setLinearAttenuation(linatt);
|
|
|
|
cla.setQuadraticAttenuation(quadatt);
|
2011-03-27 09:46:20 +00:00
|
|
|
exportBlenderProfile(cla, la);
|
2010-10-06 07:13:42 +00:00
|
|
|
addLight(cla);
|
|
|
|
}
|
2019-02-27 12:02:02 +11:00
|
|
|
/* area light is not supported
|
2010-10-06 07:13:42 +00:00
|
|
|
* it will be exported as a local lamp */
|
|
|
|
else {
|
2011-06-20 10:22:39 +00:00
|
|
|
COLLADASW::PointLight cla(mSW, la_id, la_name);
|
2012-04-29 15:47:02 +00:00
|
|
|
cla.setColor(col, false, "color");
|
2010-10-14 09:40:56 +00:00
|
|
|
cla.setConstantAttenuation(constatt);
|
|
|
|
cla.setLinearAttenuation(linatt);
|
|
|
|
cla.setQuadraticAttenuation(quadatt);
|
2011-03-27 09:46:20 +00:00
|
|
|
exportBlenderProfile(cla, la);
|
2010-10-06 07:13:42 +00:00
|
|
|
addLight(cla);
|
|
|
|
}
|
2011-03-27 09:46:20 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 10:46:48 +11:00
|
|
|
bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Light *la)
|
2011-03-27 09:46:20 +00:00
|
|
|
{
|
|
|
|
cla.addExtraTechniqueParameter("blender", "type", la->type);
|
|
|
|
cla.addExtraTechniqueParameter("blender", "flag", la->flag);
|
|
|
|
cla.addExtraTechniqueParameter("blender", "mode", la->mode);
|
2011-08-13 16:20:28 +00:00
|
|
|
cla.addExtraTechniqueParameter("blender", "gamma", la->k, "blender_gamma");
|
2011-03-30 10:51:01 +00:00
|
|
|
cla.addExtraTechniqueParameter("blender", "red", la->r);
|
|
|
|
cla.addExtraTechniqueParameter("blender", "green", la->g);
|
|
|
|
cla.addExtraTechniqueParameter("blender", "blue", la->b);
|
2011-08-13 16:20:28 +00:00
|
|
|
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");
|
Cleanup: Internal degrees removal.
This patch changes most of the reamining degrees usage in internal code into radians.
I let a few which I know off asside, for reasons explained below - and I'm not sure to have found out all of them.
WARNING: this introduces forward incompatibility, which means files saved from this version won't open 100% correctly
in previous versions (a few angle properties would use radians values as degrees...).
Details:
- Data:
-- Lamp.spotsize: Game engine exposed this setting in degrees, to not break the API here I kept it as such
(using getter/setter functions), still using radians internally.
-- Mesh.smoothresh: Didn't touch to this one, as we will hopefully replace it completely by loop normals currently in dev.
- Modifiers:
-- EdgeSplitModifierData.split_angle, BevelModifierData.bevel_angle: Done.
- Postprocessing:
-- WipeVars.angle (sequencer's effect), NodeBokehImage.angle, NodeBoxMask.rotation, NodeEllipseMask.rotation: Done.
- BGE:
-- bConstraintActuator: Orientation type done (the minloc[0] & maxloc[0] cases). Did not touch to 'limit location' type,
it can also limit rotation, but it exposes through RNA the same limit_min/limit_max, which hence
can be either distance or angle values, depending on the mode. Will leave this to BGE team.
-- bSoundActuator.cone_outer_angle_3d, bSoundActuator.cone_inner_angle_3d: Done (note I kept degrees in BGE itself,
as it seems this is the expected value here...).
-- bRadarSensor.angle: Done.
Reviewers: brecht, campbellbarton, sergey, gaiaclary, dfelinto, moguri, jbakker, lukastoenne, howardt
Reviewed By: brecht, campbellbarton, sergey, gaiaclary, moguri, jbakker, lukastoenne, howardt
Thanks to all!
Differential Revision: http://developer.blender.org/D59
2013-12-03 20:09:25 +01:00
|
|
|
cla.addExtraTechniqueParameter("blender", "spotsize", RAD2DEGF(la->spotsize));
|
2011-03-27 09:46:20 +00:00
|
|
|
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);
|
2011-03-27 17:57:14 +00:00
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-03-27 09:46:20 +00:00
|
|
|
return true;
|
2010-10-06 07:13:42 +00:00
|
|
|
}
|