Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LightExporter.cpp « collada « io « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 33c041e790f856f7a17e726189e6533695809f37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup collada
 */

#include <string>

#include "COLLADASWColor.h"
#include "COLLADASWLight.h"

#include "BLI_math.h"

#include "LightExporter.h"
#include "collada_internal.h"

template<class Functor>
void forEachLightObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
{
  LinkNode *node;
  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)
    : COLLADASW::LibraryLights(sw), export_settings(export_settings)
{
}

void LightsExporter::exportLights(Scene *sce)
{
  openLibrary();

  forEachLightObjectInExportSet(sce, *this, this->export_settings.get_export_set());

  closeLibrary();
}

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));
  COLLADASW::Color col(la->r * la->energy, la->g * la->energy, la->b * la->energy);
  float d, constatt, linatt, quadatt;

  d = la->dist;

  constatt = 1.0f;

  if (la->falloff_type == LA_FALLOFF_INVLINEAR) {
    linatt = 1.0f / d;
    quadatt = 0.0f;
  }
  else {
    linatt = 0.0f;
    quadatt = 1.0f / (d * d);
  }

  /* sun */
  if (la->type == LA_SUN) {
    COLLADASW::DirectionalLight cla(mSW, la_id, la_name);
    cla.setColor(col, false, "color");
    cla.setConstantAttenuation(constatt);
    exportBlenderProfile(cla, la);
    addLight(cla);
  }

  /* spot */
  else if (la->type == LA_SPOT) {
    COLLADASW::SpotLight cla(mSW, la_id, la_name);
    cla.setColor(col, false, "color");
    cla.setFallOffAngle(RAD2DEGF(la->spotsize), false, "fall_off_angle");
    cla.setFallOffExponent(la->spotblend, false, "fall_off_exponent");
    cla.setConstantAttenuation(constatt);
    cla.setLinearAttenuation(linatt);
    cla.setQuadraticAttenuation(quadatt);
    exportBlenderProfile(cla, la);
    addLight(cla);
  }
  /* lamp */
  else if (la->type == LA_LOCAL) {
    COLLADASW::PointLight cla(mSW, la_id, la_name);
    cla.setColor(col, false, "color");
    cla.setConstantAttenuation(constatt);
    cla.setLinearAttenuation(linatt);
    cla.setQuadraticAttenuation(quadatt);
    exportBlenderProfile(cla, la);
    addLight(cla);
  }
  /* area light is not supported
   * it will be exported as a local lamp */
  else {
    COLLADASW::PointLight cla(mSW, la_id, la_name);
    cla.setColor(col, false, "color");
    cla.setConstantAttenuation(constatt);
    cla.setLinearAttenuation(linatt);
    cla.setQuadraticAttenuation(quadatt);
    exportBlenderProfile(cla, la);
    addLight(cla);
  }
}

bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Light *la)
{
  cla.addExtraTechniqueParameter("blender", "type", la->type);
  cla.addExtraTechniqueParameter("blender", "flag", la->flag);
  cla.addExtraTechniqueParameter("blender", "mode", la->mode);
  cla.addExtraTechniqueParameter("blender", "gamma", la->k, "blender_gamma");
  cla.addExtraTechniqueParameter("blender", "red", la->r);
  cla.addExtraTechniqueParameter("blender", "green", la->g);
  cla.addExtraTechniqueParameter("blender", "blue", la->b);
  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");
  cla.addExtraTechniqueParameter("blender", "spotsize", RAD2DEGF(la->spotsize));
  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);
  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);

  return true;
}