11#include "COLLADASWEffectProfile.h"
39 BCExportSettings &export_settings,
41 : COLLADASW::LibraryEffects(sw), export_settings(export_settings), key_image_map(key_image_map)
45bool EffectsExporter::hasEffects(
Scene *sce)
50 for (a = 0; a < ob->totcol; a++) {
68 if (hasEffects(sce)) {
74 sce, *
this, this->export_settings.get_export_set());
80void EffectsExporter::set_shader_type(COLLADASW::EffectProfile &ep,
Material *ma)
83 ep.setShaderType(COLLADASW::EffectProfile::LAMBERT);
86void EffectsExporter::set_transparency(COLLADASW::EffectProfile &ep,
Material *ma)
91 COLLADASW::ColorOrTexture cot =
bc_get_cot(0, 0, 0, alpha);
92 ep.setTransparent(cot,
false,
"alpha");
93 ep.setOpaque(COLLADASW::EffectProfile::A_ONE);
97void EffectsExporter::set_diffuse_color(COLLADASW::EffectProfile &ep,
Material *ma)
100 ep.setDiffuse(cot,
false,
"diffuse");
103void EffectsExporter::set_ambient(COLLADASW::EffectProfile &ep,
Material *ma)
106 ep.setAmbient(cot,
false,
"ambient");
108void EffectsExporter::set_specular(COLLADASW::EffectProfile &ep,
Material *ma)
111 ep.setSpecular(cot,
false,
"specular");
113void EffectsExporter::set_reflective(COLLADASW::EffectProfile &ep,
Material *ma)
116 ep.setReflective(cot,
false,
"reflective");
119void EffectsExporter::set_reflectivity(COLLADASW::EffectProfile &ep,
Material *ma)
122 if (reflectivity > 0.0) {
123 ep.setReflectivity(reflectivity,
false,
"specular");
127void EffectsExporter::set_emission(COLLADASW::EffectProfile &ep,
Material *ma)
130 ep.setEmission(cot,
false,
"emission");
133void EffectsExporter::set_ior(COLLADASW::EffectProfile &ep,
Material *ma)
136 ep.setIndexOfRefraction(alpha,
false,
"ior");
139void EffectsExporter::set_shininess(COLLADASW::EffectProfile &ep,
Material *ma)
142 ep.setShininess(shininess,
false,
"shininess");
151 MaterialNode material = MaterialNode(mContext, ma, key_image_map);
153 if (image ==
nullptr) {
157 std::string uid(
id_name(image));
160 if (material_image_map.find(key) == material_image_map.end()) {
161 material_image_map[key] = image;
162 key_image_map[key] = image;
166void EffectsExporter::create_image_samplers(COLLADASW::EffectProfile &ep,
168 std::string &active_uv)
170 KeyImageMap::iterator iter;
172 for (iter = material_image_map.begin(); iter != material_image_map.end(); iter++) {
174 Image *image = iter->second;
175 std::string uid(
id_name(image));
178 COLLADASW::Sampler *sampler =
new COLLADASW::Sampler(
179 COLLADASW::Sampler::SAMPLER_TYPE_2D,
180 key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
181 key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
183 sampler->setImageId(key);
185 ep.setDiffuse(
createTexture(image, active_uv, sampler),
false,
"diffuse");
195 COLLADASW::EffectProfile ep(mSW);
196 ep.setProfileType(COLLADASW::EffectProfile::COMMON);
198 set_shader_type(ep, ma);
200 COLLADASW::ColorOrTexture cot;
202 set_diffuse_color(ep, ma);
203 set_emission(ep, ma);
205 set_reflectivity(ep, ma);
206 set_transparency(ep, ma);
210 set_shininess(ep, ma);
212 set_specular(ep, ma);
215 get_images(ma, material_image_map);
217 create_image_samplers(ep, material_image_map, active_uv);
221 for (a = 0,
b = 0; a < tex_indices.size(); a++) {
222 MTex *t = ma->mtex[tex_indices[a]];
234 if (im_samp_map.find(key) == im_samp_map.end()) {
236 COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D,
237 key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
238 key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
239 sampler.setImageId(key);
241 samplers[a] = sampler;
244 samp_surf[
b] = &samplers[a];
247 im_samp_map[key] =
b;
252 for (a = 0; a < tex_indices.size(); a++) {
253 MTex *t = ma->mtex[tex_indices[a]];
262 int i = im_samp_map[key];
263 std::string uvname = strlen(t->
uvname) ? t->
uvname : active_uv;
264 COLLADASW::Sampler *sampler = (COLLADASW::Sampler *)
266 writeTextures(ep, key, sampler, t, ima, uvname);
271 ep.addProfileElements();
272 ep.addExtraTechniques(mSW);
279 std::string &uv_layer_name,
280 COLLADASW::Sampler *sampler
285 texture.setTexcoord(uv_layer_name);
289 COLLADASW::ColorOrTexture cot(
texture);
295 COLLADASW::Color color(r, g,
b, a);
296 COLLADASW::ColorOrTexture cot(color);
#define FOREACH_SCENE_OBJECT_END
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
CustomData interface, see also DNA_customdata_types.h.
int CustomData_number_of_layers(const CustomData *data, eCustomDataType type)
General operations, lookup, etc. for materials.
Material * BKE_object_material_get(Object *ob, short act)
static std::string getActiveUVLayerName(Object *ob)
EffectsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings, KeyImageMap &key_image_map)
COLLADASW::ColorOrTexture createTexture(Image *ima, std::string &uv_layer_name, COLLADASW::Sampler *sampler)
COLLADASW::ColorOrTexture getcol(float r, float g, float b, float a)
void operator()(Material *ma, Object *ob)
void exportEffects(bContext *C, Scene *sce)
Image * get_diffuse_image()
std::string translate_id(const char *idString)
std::string get_effect_id(Material *mat)
std::string id_name(void *id)
COLLADASW::ColorOrTexture bc_get_specular(Material *ma)
COLLADASW::ColorOrTexture bc_get_ambient(Material *ma)
double bc_get_alpha(Material *ma)
COLLADASW::ColorOrTexture bc_get_cot(float r, float g, float b, float a)
COLLADASW::ColorOrTexture bc_get_emission(Material *ma)
COLLADASW::ColorOrTexture bc_get_reflective(Material *ma)
double bc_get_reflectivity(Material *ma)
double bc_get_shininess(Material *ma)
COLLADASW::ColorOrTexture bc_get_base_color(Material *ma)
double bc_get_ior(Material *ma)
const char * bc_CustomData_get_active_layer_name(const CustomData *data, eCustomDataType type)
std::map< std::string, Image * > KeyImageMap
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
void forEachMaterialInExportSet(Scene *sce, Functor &f, LinkNode *export_set)