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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/collada/EffectExporter.cpp
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/collada/EffectExporter.cpp')
-rw-r--r--source/blender/collada/EffectExporter.cpp347
1 files changed, 175 insertions, 172 deletions
diff --git a/source/blender/collada/EffectExporter.cpp b/source/blender/collada/EffectExporter.cpp
index 94e86af521f..58435c4551f 100644
--- a/source/blender/collada/EffectExporter.cpp
+++ b/source/blender/collada/EffectExporter.cpp
@@ -18,7 +18,6 @@
* \ingroup collada
*/
-
#include <map>
#include <set>
@@ -33,247 +32,251 @@
#include "collada_utils.h"
extern "C" {
- #include "DNA_mesh_types.h"
- #include "DNA_world_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_world_types.h"
- #include "BKE_collection.h"
- #include "BKE_customdata.h"
- #include "BKE_mesh.h"
- #include "BKE_material.h"
+#include "BKE_collection.h"
+#include "BKE_customdata.h"
+#include "BKE_mesh.h"
+#include "BKE_material.h"
}
static std::string getActiveUVLayerName(Object *ob)
{
- Mesh *me = (Mesh *)ob->data;
+ Mesh *me = (Mesh *)ob->data;
- int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
- if (num_layers)
- return std::string(bc_CustomData_get_active_layer_name(&me->ldata, CD_MLOOPUV));
+ int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
+ if (num_layers)
+ return std::string(bc_CustomData_get_active_layer_name(&me->ldata, CD_MLOOPUV));
- return "";
+ return "";
}
-EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings, KeyImageMap &key_image_map) :
- COLLADASW::LibraryEffects(sw),
- export_settings(export_settings),
- key_image_map(key_image_map)
-{}
-
+EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw,
+ const ExportSettings *export_settings,
+ KeyImageMap &key_image_map)
+ : COLLADASW::LibraryEffects(sw), export_settings(export_settings), key_image_map(key_image_map)
+{
+}
bool EffectsExporter::hasEffects(Scene *sce)
{
- FOREACH_SCENE_OBJECT_BEGIN(sce, ob)
- {
- int a;
- for (a = 0; a < ob->totcol; a++) {
- Material *ma = give_current_material(ob, a + 1);
-
- // no material, but check all of the slots
- if (!ma) continue;
-
- return true;
- }
- }
- FOREACH_SCENE_OBJECT_END;
- return false;
+ FOREACH_SCENE_OBJECT_BEGIN (sce, ob) {
+ int a;
+ for (a = 0; a < ob->totcol; a++) {
+ Material *ma = give_current_material(ob, a + 1);
+
+ // no material, but check all of the slots
+ if (!ma)
+ continue;
+
+ return true;
+ }
+ }
+ FOREACH_SCENE_OBJECT_END;
+ return false;
}
void EffectsExporter::exportEffects(bContext *C, Scene *sce)
{
- if (hasEffects(sce)) {
- this->mContext = C;
- this->scene = sce;
- openLibrary();
- MaterialFunctor mf;
- mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set);
-
- closeLibrary();
- }
+ if (hasEffects(sce)) {
+ this->mContext = C;
+ this->scene = sce;
+ openLibrary();
+ MaterialFunctor mf;
+ mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set);
+
+ closeLibrary();
+ }
}
void EffectsExporter::set_shader_type(COLLADASW::EffectProfile &ep, Material *ma)
{
- ep.setShaderType(COLLADASW::EffectProfile::LAMBERT); //XXX check if BLINN and PHONG can be supported as well
+ ep.setShaderType(
+ COLLADASW::EffectProfile::LAMBERT); //XXX check if BLINN and PHONG can be supported as well
}
void EffectsExporter::set_transparency(COLLADASW::EffectProfile &ep, Material *ma)
{
- COLLADASW::ColorOrTexture cot = bc_get_base_color(ma);
- float transparency = cot.getColor().getAlpha();
- if (transparency < 1) {
- // Tod: because we are in A_ONE mode transparency is calculated like this:
- COLLADASW::ColorOrTexture cot = getcol(1.0f, 1.0f, 1.0f, transparency);
- ep.setTransparent(cot);
- ep.setOpaque(COLLADASW::EffectProfile::A_ONE);
- }
+ COLLADASW::ColorOrTexture cot = bc_get_base_color(ma);
+ float transparency = cot.getColor().getAlpha();
+ if (transparency < 1) {
+ // Tod: because we are in A_ONE mode transparency is calculated like this:
+ COLLADASW::ColorOrTexture cot = getcol(1.0f, 1.0f, 1.0f, transparency);
+ ep.setTransparent(cot);
+ ep.setOpaque(COLLADASW::EffectProfile::A_ONE);
+ }
}
void EffectsExporter::set_diffuse_color(COLLADASW::EffectProfile &ep, Material *ma)
{
- // get diffuse color
- COLLADASW::ColorOrTexture cot = bc_get_base_color(ma);
- ep.setDiffuse(cot, false, "diffuse");
+ // get diffuse color
+ COLLADASW::ColorOrTexture cot = bc_get_base_color(ma);
+ ep.setDiffuse(cot, false, "diffuse");
}
void EffectsExporter::set_reflectivity(COLLADASW::EffectProfile &ep, Material *ma)
{
- double reflectivity = bc_get_reflectivity(ma);
- ep.setReflectivity(reflectivity, false, "specular");
+ double reflectivity = bc_get_reflectivity(ma);
+ ep.setReflectivity(reflectivity, false, "specular");
}
void EffectsExporter::set_emission(COLLADASW::EffectProfile &ep, Material *ma)
{
- // not yet supported (needs changes in principled shader
+ // not yet supported (needs changes in principled shader
}
void EffectsExporter::get_images(Material *ma, KeyImageMap &material_image_map)
{
- if (!ma->use_nodes) {
- return;
- }
-
- MaterialNode material = MaterialNode(mContext, ma, key_image_map);
- Image *image = material.get_diffuse_image();
- if (image == nullptr) {
- return;
- }
-
- std::string uid(id_name(image));
- std::string key = translate_id(uid);
-
- if (material_image_map.find(key) == material_image_map.end()) {
- material_image_map[key] = image;
- key_image_map[key] = image;
- }
+ if (!ma->use_nodes) {
+ return;
+ }
+
+ MaterialNode material = MaterialNode(mContext, ma, key_image_map);
+ Image *image = material.get_diffuse_image();
+ if (image == nullptr) {
+ return;
+ }
+
+ std::string uid(id_name(image));
+ std::string key = translate_id(uid);
+
+ if (material_image_map.find(key) == material_image_map.end()) {
+ material_image_map[key] = image;
+ key_image_map[key] = image;
+ }
}
-void EffectsExporter::create_image_samplers(COLLADASW::EffectProfile &ep, KeyImageMap &material_image_map, std::string &active_uv)
+void EffectsExporter::create_image_samplers(COLLADASW::EffectProfile &ep,
+ KeyImageMap &material_image_map,
+ std::string &active_uv)
{
- KeyImageMap::iterator iter;
+ KeyImageMap::iterator iter;
- for (iter = material_image_map.begin(); iter != material_image_map.end(); iter++) {
+ for (iter = material_image_map.begin(); iter != material_image_map.end(); iter++) {
- Image *image = iter->second;
- std::string uid(id_name(image));
- std::string key = translate_id(uid);
+ Image *image = iter->second;
+ std::string uid(id_name(image));
+ std::string key = translate_id(uid);
- COLLADASW::Sampler *sampler = new COLLADASW::Sampler(
- COLLADASW::Sampler::SAMPLER_TYPE_2D,
- key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
- key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
+ COLLADASW::Sampler *sampler = new COLLADASW::Sampler(
+ COLLADASW::Sampler::SAMPLER_TYPE_2D,
+ key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
+ key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
- sampler->setImageId(key);
+ sampler->setImageId(key);
- ep.setDiffuse(createTexture(image, active_uv, sampler), false, "diffuse");
- }
+ ep.setDiffuse(createTexture(image, active_uv, sampler), false, "diffuse");
+ }
}
void EffectsExporter::operator()(Material *ma, Object *ob)
{
- KeyImageMap material_image_map;
+ KeyImageMap material_image_map;
- openEffect(get_effect_id(ma));
+ openEffect(get_effect_id(ma));
- COLLADASW::EffectProfile ep(mSW);
- ep.setProfileType(COLLADASW::EffectProfile::COMMON);
- ep.openProfile();
- set_shader_type(ep, ma);
+ COLLADASW::EffectProfile ep(mSW);
+ ep.setProfileType(COLLADASW::EffectProfile::COMMON);
+ ep.openProfile();
+ set_shader_type(ep, ma);
- COLLADASW::ColorOrTexture cot;
+ COLLADASW::ColorOrTexture cot;
- set_transparency(ep, ma);
- set_diffuse_color(ep, ma);
- set_reflectivity(ep, ma);
- set_emission(ep, ma);
+ set_transparency(ep, ma);
+ set_diffuse_color(ep, ma);
+ set_reflectivity(ep, ma);
+ set_emission(ep, ma);
- get_images(ma, material_image_map);
- std::string active_uv(getActiveUVLayerName(ob));
- create_image_samplers(ep, material_image_map, active_uv);
+ get_images(ma, material_image_map);
+ std::string active_uv(getActiveUVLayerName(ob));
+ create_image_samplers(ep, material_image_map, active_uv);
#if 0
- unsigned int a, b;
- for (a = 0, b = 0; a < tex_indices.size(); a++) {
- MTex *t = ma->mtex[tex_indices[a]];
- Image *ima = t->tex->ima;
-
- // Image not set for texture
- if (!ima) continue;
-
- std::string key(id_name(ima));
- key = translate_id(key);
-
- // create only one <sampler>/<surface> pair for each unique image
- if (im_samp_map.find(key) == im_samp_map.end()) {
- //<newparam> <sampler> <source>
- COLLADASW::Sampler sampler(
- COLLADASW::Sampler::SAMPLER_TYPE_2D,
- key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
- key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
- sampler.setImageId(key);
- // copy values to arrays since they will live longer
- samplers[a] = sampler;
-
- // store pointers so they can be used later when we create <texture>s
- samp_surf[b] = &samplers[a];
- //samp_surf[b][1] = &surfaces[a];
-
- im_samp_map[key] = b;
- b++;
- }
- }
-
- for (a = 0; a < tex_indices.size(); a++) {
- MTex *t = ma->mtex[tex_indices[a]];
- Image *ima = t->tex->ima;
-
- if (!ima) {
- continue;
- }
-
- std::string key(id_name(ima));
- key = translate_id(key);
- int i = im_samp_map[key];
- std::string uvname = strlen(t->uvname) ? t->uvname : active_uv;
- COLLADASW::Sampler *sampler = (COLLADASW::Sampler *)samp_surf[i]; // possibly uninitialised memory ...
- writeTextures(ep, key, sampler, t, ima, uvname);
- }
+ unsigned int a, b;
+ for (a = 0, b = 0; a < tex_indices.size(); a++) {
+ MTex *t = ma->mtex[tex_indices[a]];
+ Image *ima = t->tex->ima;
+
+ // Image not set for texture
+ if (!ima) continue;
+
+ std::string key(id_name(ima));
+ key = translate_id(key);
+
+ // create only one <sampler>/<surface> pair for each unique image
+ if (im_samp_map.find(key) == im_samp_map.end()) {
+ //<newparam> <sampler> <source>
+ COLLADASW::Sampler sampler(
+ COLLADASW::Sampler::SAMPLER_TYPE_2D,
+ key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
+ key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
+ sampler.setImageId(key);
+ // copy values to arrays since they will live longer
+ samplers[a] = sampler;
+
+ // store pointers so they can be used later when we create <texture>s
+ samp_surf[b] = &samplers[a];
+ //samp_surf[b][1] = &surfaces[a];
+
+ im_samp_map[key] = b;
+ b++;
+ }
+ }
+
+ for (a = 0; a < tex_indices.size(); a++) {
+ MTex *t = ma->mtex[tex_indices[a]];
+ Image *ima = t->tex->ima;
+
+ if (!ima) {
+ continue;
+ }
+
+ std::string key(id_name(ima));
+ key = translate_id(key);
+ int i = im_samp_map[key];
+ std::string uvname = strlen(t->uvname) ? t->uvname : active_uv;
+ COLLADASW::Sampler *sampler = (COLLADASW::Sampler *)samp_surf[i]; // possibly uninitialised memory ...
+ writeTextures(ep, key, sampler, t, ima, uvname);
+ }
#endif
- // performs the actual writing
- ep.addProfileElements();
- bool twoSided = false;
- if (ob->type == OB_MESH && ob->data) {
- Mesh *me = (Mesh *)ob->data;
- if (me->flag & ME_TWOSIDED)
- twoSided = true;
- }
- if (twoSided)
- ep.addExtraTechniqueParameter("GOOGLEEARTH", "double_sided", 1);
- ep.addExtraTechniques(mSW);
-
- ep.closeProfile();
- if (twoSided)
- mSW->appendTextBlock("<extra><technique profile=\"MAX3D\"><double_sided>1</double_sided></technique></extra>");
- closeEffect();
+ // performs the actual writing
+ ep.addProfileElements();
+ bool twoSided = false;
+ if (ob->type == OB_MESH && ob->data) {
+ Mesh *me = (Mesh *)ob->data;
+ if (me->flag & ME_TWOSIDED)
+ twoSided = true;
+ }
+ if (twoSided)
+ ep.addExtraTechniqueParameter("GOOGLEEARTH", "double_sided", 1);
+ ep.addExtraTechniques(mSW);
+
+ ep.closeProfile();
+ if (twoSided)
+ mSW->appendTextBlock(
+ "<extra><technique profile=\"MAX3D\"><double_sided>1</double_sided></technique></extra>");
+ closeEffect();
}
COLLADASW::ColorOrTexture EffectsExporter::createTexture(Image *ima,
- std::string& uv_layer_name,
+ std::string &uv_layer_name,
COLLADASW::Sampler *sampler
/*COLLADASW::Surface *surface*/)
{
- COLLADASW::Texture texture(translate_id(id_name(ima)));
- texture.setTexcoord(uv_layer_name);
- //texture.setSurface(*surface);
- texture.setSampler(*sampler);
+ COLLADASW::Texture texture(translate_id(id_name(ima)));
+ texture.setTexcoord(uv_layer_name);
+ //texture.setSurface(*surface);
+ texture.setSampler(*sampler);
- COLLADASW::ColorOrTexture cot(texture);
- return cot;
+ COLLADASW::ColorOrTexture cot(texture);
+ return cot;
}
COLLADASW::ColorOrTexture EffectsExporter::getcol(float r, float g, float b, float a)
{
- COLLADASW::Color color(r, g, b, a);
- COLLADASW::ColorOrTexture cot(color);
- return cot;
+ COLLADASW::Color color(r, g, b, a);
+ COLLADASW::ColorOrTexture cot(color);
+ return cot;
}