2
* $Id: LightExporter.cpp 32468 2010-10-14 09:40:56Z jesterking $
4
* ***** BEGIN GPL LICENSE BLOCK *****
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed,
23
* ***** END GPL LICENSE BLOCK *****
28
#include "COLLADASWColor.h"
29
#include "COLLADASWLight.h"
31
#include "DNA_lamp_types.h"
35
#include "LightExporter.h"
36
#include "collada_internal.h"
38
template<class Functor>
39
void forEachLampObjectInScene(Scene *sce, Functor &f)
41
Base *base= (Base*) sce->base.first;
43
Object *ob = base->object;
45
if (ob->type == OB_LAMP && ob->data) {
52
LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryLights(sw){}
54
void LightsExporter::exportLights(Scene *sce)
58
forEachLampObjectInScene(sce, *this);
62
void LightsExporter::operator()(Object *ob)
64
Lamp *la = (Lamp*)ob->data;
65
std::string la_id(get_light_id(ob));
66
std::string la_name(id_name(la));
67
COLLADASW::Color col(la->r, la->g, la->b);
69
float e, d, constatt, linatt, quadatt;
72
if(la->falloff_type==LA_FALLOFF_INVLINEAR) {
76
else if(la->falloff_type==LA_FALLOFF_INVSQUARE) {
80
else if(la->falloff_type==LA_FALLOFF_SLIDERS) {
88
constatt = linatt = quadatt = MAXFLOAT;
92
quadatt = att2/(d*d*(e*2));
96
if (la->type == LA_SUN) {
97
COLLADASW::DirectionalLight cla(mSW, la_id, la_name, e);
99
cla.setConstantAttenuation(constatt);
103
else if (la->type == LA_HEMI) {
104
COLLADASW::AmbientLight cla(mSW, la_id, la_name, e);
106
cla.setConstantAttenuation(constatt);
110
else if (la->type == LA_SPOT) {
111
COLLADASW::SpotLight cla(mSW, la_id, la_name, e);
113
cla.setFallOffAngle(la->spotsize);
114
cla.setFallOffExponent(la->spotblend);
115
cla.setConstantAttenuation(constatt);
116
cla.setLinearAttenuation(linatt);
117
cla.setQuadraticAttenuation(quadatt);
121
else if (la->type == LA_LOCAL) {
122
COLLADASW::PointLight cla(mSW, la_id, la_name, e);
124
cla.setConstantAttenuation(constatt);
125
cla.setLinearAttenuation(linatt);
126
cla.setQuadraticAttenuation(quadatt);
129
// area lamp is not supported
130
// it will be exported as a local lamp
132
COLLADASW::PointLight cla(mSW, la_id, la_name, e);
134
cla.setConstantAttenuation(constatt);
135
cla.setLinearAttenuation(linatt);
136
cla.setQuadraticAttenuation(quadatt);