Blender  V3.3
LightExporter.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <string>
8 
9 #include "COLLADASWColor.h"
10 #include "COLLADASWLight.h"
11 
12 #include "BLI_math.h"
13 
14 #include "LightExporter.h"
15 #include "collada_internal.h"
16 
17 template<class Functor>
18 void forEachLightObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
19 {
20  LinkNode *node;
21  for (node = export_set; node; node = node->next) {
22  Object *ob = (Object *)node->link;
23 
24  if (ob->type == OB_LAMP && ob->data) {
25  f(ob);
26  }
27  }
28 }
29 
30 LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
31  : COLLADASW::LibraryLights(sw), export_settings(export_settings)
32 {
33 }
34 
36 {
37  openLibrary();
38 
39  forEachLightObjectInExportSet(sce, *this, this->export_settings.get_export_set());
40 
41  closeLibrary();
42 }
43 
45 {
46  Light *la = (Light *)ob->data;
47  std::string la_id(get_light_id(ob));
48  std::string la_name(id_name(la));
49  COLLADASW::Color col(la->r * la->energy, la->g * la->energy, la->b * la->energy);
50  float d, constatt, linatt, quadatt;
51 
52  d = la->dist;
53 
54  constatt = 1.0f;
55 
57  linatt = 1.0f / d;
58  quadatt = 0.0f;
59  }
60  else {
61  linatt = 0.0f;
62  quadatt = 1.0f / (d * d);
63  }
64 
65  /* sun */
66  if (la->type == LA_SUN) {
67  COLLADASW::DirectionalLight cla(mSW, la_id, la_name);
68  cla.setColor(col, false, "color");
69  cla.setConstantAttenuation(constatt);
70  exportBlenderProfile(cla, la);
71  addLight(cla);
72  }
73 
74  /* spot */
75  else if (la->type == LA_SPOT) {
76  COLLADASW::SpotLight cla(mSW, la_id, la_name);
77  cla.setColor(col, false, "color");
78  cla.setFallOffAngle(RAD2DEGF(la->spotsize), false, "fall_off_angle");
79  cla.setFallOffExponent(la->spotblend, false, "fall_off_exponent");
80  cla.setConstantAttenuation(constatt);
81  cla.setLinearAttenuation(linatt);
82  cla.setQuadraticAttenuation(quadatt);
83  exportBlenderProfile(cla, la);
84  addLight(cla);
85  }
86  /* lamp */
87  else if (la->type == LA_LOCAL) {
88  COLLADASW::PointLight cla(mSW, la_id, la_name);
89  cla.setColor(col, false, "color");
90  cla.setConstantAttenuation(constatt);
91  cla.setLinearAttenuation(linatt);
92  cla.setQuadraticAttenuation(quadatt);
93  exportBlenderProfile(cla, la);
94  addLight(cla);
95  }
96  /* area light is not supported
97  * it will be exported as a local lamp */
98  else {
99  COLLADASW::PointLight cla(mSW, la_id, la_name);
100  cla.setColor(col, false, "color");
101  cla.setConstantAttenuation(constatt);
102  cla.setLinearAttenuation(linatt);
103  cla.setQuadraticAttenuation(quadatt);
104  exportBlenderProfile(cla, la);
105  addLight(cla);
106  }
107 }
108 
109 bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Light *la)
110 {
111  cla.addExtraTechniqueParameter("blender", "type", la->type);
112  cla.addExtraTechniqueParameter("blender", "flag", la->flag);
113  cla.addExtraTechniqueParameter("blender", "mode", la->mode);
114  cla.addExtraTechniqueParameter("blender", "gamma", la->k, "blender_gamma");
115  cla.addExtraTechniqueParameter("blender", "red", la->r);
116  cla.addExtraTechniqueParameter("blender", "green", la->g);
117  cla.addExtraTechniqueParameter("blender", "blue", la->b);
118  cla.addExtraTechniqueParameter("blender", "shadow_r", la->shdwr, "blender_shadow_r");
119  cla.addExtraTechniqueParameter("blender", "shadow_g", la->shdwg, "blender_shadow_g");
120  cla.addExtraTechniqueParameter("blender", "shadow_b", la->shdwb, "blender_shadow_b");
121  cla.addExtraTechniqueParameter("blender", "energy", la->energy, "blender_energy");
122  cla.addExtraTechniqueParameter("blender", "dist", la->dist, "blender_dist");
123  cla.addExtraTechniqueParameter("blender", "spotsize", RAD2DEGF(la->spotsize));
124  cla.addExtraTechniqueParameter("blender", "spotblend", la->spotblend);
125  cla.addExtraTechniqueParameter("blender", "att1", la->att1);
126  cla.addExtraTechniqueParameter("blender", "att2", la->att2);
127  /* \todo figure out how we can have falloff curve supported here */
128  cla.addExtraTechniqueParameter("blender", "falloff_type", la->falloff_type);
129  cla.addExtraTechniqueParameter("blender", "clipsta", la->clipsta);
130  cla.addExtraTechniqueParameter("blender", "clipend", la->clipend);
131  cla.addExtraTechniqueParameter("blender", "bias", la->bias);
132  cla.addExtraTechniqueParameter("blender", "soft", la->soft);
133  cla.addExtraTechniqueParameter("blender", "bufsize", la->bufsize);
134  cla.addExtraTechniqueParameter("blender", "samp", la->samp);
135  cla.addExtraTechniqueParameter("blender", "buffers", la->buffers);
136  cla.addExtraTechniqueParameter("blender", "area_shape", la->area_shape);
137  cla.addExtraTechniqueParameter("blender", "area_size", la->area_size);
138  cla.addExtraTechniqueParameter("blender", "area_sizey", la->area_sizey);
139  cla.addExtraTechniqueParameter("blender", "area_sizez", la->area_sizez);
140 
141  return true;
142 }
#define RAD2DEGF(_rad)
struct Light Light
#define LA_SPOT
#define LA_SUN
#define LA_LOCAL
#define LA_FALLOFF_INVLINEAR
@ OB_LAMP
void forEachLightObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its and Z components Generates normals with round corners and may slow down renders Vector Displace the surface along an arbitrary direction White Return a random value or color based on an input seed Float Map an input float to a curve and outputs a float value Separate Color
void exportLights(Scene *sce)
LightsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
void operator()(Object *ob)
std::string get_light_id(Object *ob)
std::string id_name(void *id)
OperationNode * node
uint col
ccl_gpu_kernel_postfix ccl_global float int int int sw
float att2
float r
float energy
short bufsize
float dist
float clipend
float att1
float area_sizez
float soft
float area_sizey
short samp
float shdwg
short area_shape
float clipsta
float spotblend
float g
short falloff_type
float spotsize
float area_size
float k
float shdwr
float b
float shdwb
short type
float bias
short buffers
short flag
void * data