Files
test/source/blender/io/collada/LightExporter.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
3.4 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2010-2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup collada
2011-02-27 20:30:35 +00:00
*/
#include <string>
#include "COLLADASWColor.h"
#include "COLLADASWLight.h"
#include "DNA_light_types.h"
#include "LightExporter.h"
#include "collada_internal.h"
#include "BKE_light.h"
template<class Functor>
2019-02-27 12:02:02 +11:00
void forEachLightObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
{
LinkNode *node;
2012-06-12 22:05:33 +00:00
for (node = export_set; node; node = node->next) {
Object *ob = (Object *)node->link;
if (ob->type == OB_LAMP && ob->data) {
f(ob);
}
}
}
LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
2012-06-12 22:05:33 +00:00
: COLLADASW::LibraryLights(sw), export_settings(export_settings)
{
}
void LightsExporter::exportLights(Scene *sce)
{
openLibrary();
forEachLightObjectInExportSet(sce, *this, this->export_settings.get_export_set());
closeLibrary();
}
2011-07-02 05:05:03 +00:00
void LightsExporter::operator()(Object *ob)
{
Light *la = (Light *)ob->data;
std::string la_id(get_light_id(ob));
std::string la_name(id_name(la));
blender::float3 color = BKE_light_power(*la) * BKE_light_color(*la);
if (la->mode & LA_UNNORMALIZED) {
color *= BKE_light_area(*la, ob->runtime->object_to_world);
}
COLLADASW::Color col(color[0], color[1], color[2]);
/* sun */
if (la->type == LA_SUN) {
COLLADASW::DirectionalLight cla(mSW, la_id, la_name);
2012-04-29 15:47:02 +00:00
cla.setColor(col, false, "color");
2011-03-27 09:46:20 +00:00
exportBlenderProfile(cla, la);
addLight(cla);
}
/* spot */
else if (la->type == LA_SPOT) {
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");
2011-03-27 09:46:20 +00:00
exportBlenderProfile(cla, la);
addLight(cla);
}
/* lamp */
else if (la->type == LA_LOCAL) {
COLLADASW::PointLight cla(mSW, la_id, la_name);
2012-04-29 15:47:02 +00:00
cla.setColor(col, false, "color");
2011-03-27 09:46:20 +00:00
exportBlenderProfile(cla, la);
addLight(cla);
}
2019-02-27 12:02:02 +11:00
/* area light is not supported
* it will be exported as a local lamp */
else {
COLLADASW::PointLight cla(mSW, la_id, la_name);
2012-04-29 15:47:02 +00:00
cla.setColor(col, false, "color");
2011-03-27 09:46:20 +00:00
exportBlenderProfile(cla, la);
addLight(cla);
}
2011-03-27 09:46:20 +00: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);
cla.addExtraTechniqueParameter("blender", "red", la->r);
cla.addExtraTechniqueParameter("blender", "green", la->g);
cla.addExtraTechniqueParameter("blender", "blue", la->b);
cla.addExtraTechniqueParameter("blender", "energy", la->energy, "blender_energy");
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", "clipsta", la->clipsta);
cla.addExtraTechniqueParameter("blender", "clipend", la->att_dist);
cla.addExtraTechniqueParameter("blender", "radius", la->radius);
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);
2011-03-27 09:46:20 +00:00
return true;
}