Changeset View
Changeset View
Standalone View
Standalone View
source/blender/collada/EffectExporter.cpp
| Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void EffectsExporter::writeLambert(COLLADASW::EffectProfile &ep, Material *ma) | void EffectsExporter::writeLambert(COLLADASW::EffectProfile &ep, Material *ma) | ||||
| { | { | ||||
| COLLADASW::ColorOrTexture cot; | COLLADASW::ColorOrTexture cot; | ||||
| ep.setShaderType(COLLADASW::EffectProfile::LAMBERT); | ep.setShaderType(COLLADASW::EffectProfile::LAMBERT); | ||||
| } | } | ||||
| void EffectsExporter::writePhong(COLLADASW::EffectProfile &ep, Material *ma) | void EffectsExporter::writePhong(COLLADASW::EffectProfile &ep, Material *ma) | ||||
gaiaclary: i think there is no need to use the parameter is_shadeless here. See below line 195 | |||||
| { | { | ||||
| COLLADASW::ColorOrTexture cot; | COLLADASW::ColorOrTexture cot; | ||||
| ep.setShaderType(COLLADASW::EffectProfile::PHONG); | ep.setShaderType(COLLADASW::EffectProfile::PHONG); | ||||
| // shininess | // shininess | ||||
Not Done Inline ActionsWhy not make one method: void EffectsExporter::writeShader(COLLADASW::EffectProfile &ep, COLLADASW::ShaderType, Material *ma ) This would avoid duplication of code. gaiaclary: Why not make one method:
void EffectsExporter::writeShader(COLLADASW::EffectProfile &ep… | |||||
| ep.setShininess(ma->har, false, "shininess"); | ep.setShininess(ma->har, false, "shininess"); | ||||
| // specular | // specular | ||||
| cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f); | cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f); | ||||
| ep.setSpecular(cot, false, "specular"); | ep.setSpecular(cot, false, "specular"); | ||||
| } | } | ||||
| void EffectsExporter::writeTextures(COLLADASW::EffectProfile &ep, | void EffectsExporter::writeTextures(COLLADASW::EffectProfile &ep, | ||||
| std::string &key, | std::string &key, | ||||
| Show All 40 Lines | if (t->mapto & MAP_NORM) { | ||||
| texture.setProfileName("FCOLLADA"); | texture.setProfileName("FCOLLADA"); | ||||
| texture.setChildElementName("bump"); | texture.setChildElementName("bump"); | ||||
| ep.addExtraTechniqueColorOrTexture(COLLADASW::ColorOrTexture(texture)); | ep.addExtraTechniqueColorOrTexture(COLLADASW::ColorOrTexture(texture)); | ||||
| } | } | ||||
| } | } | ||||
| void EffectsExporter::operator()(Material *ma, Object *ob) | void EffectsExporter::operator()(Material *ma, Object *ob) | ||||
| { | { | ||||
| bool is_shadeless = ma->mode & MA_SHLESS; | |||||
| // create a list of indices to textures of type TEX_IMAGE | // create a list of indices to textures of type TEX_IMAGE | ||||
| std::vector<int> tex_indices; | std::vector<int> tex_indices; | ||||
| if (this->export_settings->include_material_textures) | if (this->export_settings->include_material_textures) | ||||
| createTextureIndices(ma, tex_indices); | createTextureIndices(ma, tex_indices); | ||||
| openEffect(translate_id(id_name(ma)) + "-effect"); | openEffect(translate_id(id_name(ma)) + "-effect"); | ||||
| COLLADASW::EffectProfile ep(mSW); | COLLADASW::EffectProfile ep(mSW); | ||||
| ep.setProfileType(COLLADASW::EffectProfile::COMMON); | ep.setProfileType(COLLADASW::EffectProfile::COMMON); | ||||
| ep.openProfile(); | ep.openProfile(); | ||||
| // set shader type - one of three blinn, phong or lambert | |||||
| /* set shader type */ | |||||
| if (is_shadeless) { | |||||
| ep.setShaderType(COLLADASW::EffectProfile::CONSTANT); | |||||
| } | |||||
Not Done Inline ActionsSeems you're unintentionally modifying material bitflags here. sergey: Seems you're unintentionally modifying material bitflags here. | |||||
| else { | |||||
| if (ma->spec > 0.0f) { | if (ma->spec > 0.0f) { | ||||
| if (ma->spec_shader == MA_SPEC_BLINN) { | if (ma->spec_shader == MA_SPEC_BLINN) { | ||||
Not Done Inline Actionsno need to call this function here. line 195 below already does the trick. gaiaclary: no need to call this function here. line 195 below already does the trick. | |||||
| writeBlinn(ep, ma); | writeBlinn(ep, ma); | ||||
| } | } | ||||
| else { | else { | ||||
| // \todo figure out handling of all spec+diff shader combos blender has, for now write phong | // \todo figure out handling of all spec+diff shader combos blender has, for now write phong | ||||
| // for now set phong in case spec shader is not blinn | // for now set phong in case spec shader is not blinn | ||||
| writePhong(ep, ma); | writePhong(ep, ma); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (ma->diff_shader == MA_DIFF_LAMBERT) { | if (ma->diff_shader == MA_DIFF_LAMBERT) { | ||||
| writeLambert(ep, ma); | writeLambert(ep, ma); | ||||
| } | } | ||||
| else { | else { | ||||
| // \todo figure out handling of all spec+diff shader combos blender has, for now write phong | // \todo figure out handling of all spec+diff shader combos blender has, for now write phong | ||||
| writePhong(ep, ma); | writePhong(ep, ma); | ||||
| } | } | ||||
| } | } | ||||
Not Done Inline Actionssomething wrong with indentation here? gaiaclary: something wrong with indentation here? | |||||
| } | |||||
| // index of refraction | // index of refraction | ||||
| if (ma->mode & MA_RAYTRANSP) { | if (ma->mode & MA_RAYTRANSP) { | ||||
| ep.setIndexOfRefraction(ma->ang, false, "index_of_refraction"); | ep.setIndexOfRefraction(ma->ang, false, "index_of_refraction"); | ||||
| } | } | ||||
| else { | else { | ||||
| ep.setIndexOfRefraction(1.0f, false, "index_of_refraction"); | ep.setIndexOfRefraction(1.0f, false, "index_of_refraction"); | ||||
| } | } | ||||
| COLLADASW::ColorOrTexture cot; | COLLADASW::ColorOrTexture cot; | ||||
| // transparency | // transparency | ||||
| if (ma->mode & MA_TRANSP) { | if (ma->mode & MA_TRANSP) { | ||||
| // Tod: because we are in A_ONE mode transparency is calculated like this: | // Todo: because we are in A_ONE mode transparency is calculated like this: | ||||
| ep.setTransparency(ma->alpha, false, "transparency"); | ep.setTransparency(ma->alpha, false, "transparency"); | ||||
| // cot = getcol(1.0f, 1.0f, 1.0f, 1.0f); | // cot = getcol(1.0f, 1.0f, 1.0f, 1.0f); | ||||
| // ep.setTransparent(cot); | // ep.setTransparent(cot); | ||||
| } | } | ||||
| // emission | // emission | ||||
| if (is_shadeless) { | |||||
| cot = getcol(ma->r, ma->g, ma->b, 1.0f); | |||||
| } | |||||
| else { | |||||
Not Done Inline ActionsSame as above. sergey: Same as above. | |||||
| cot = getcol(ma->emit, ma->emit, ma->emit, 1.0f); | cot = getcol(ma->emit, ma->emit, ma->emit, 1.0f); | ||||
| } | |||||
| ep.setEmission(cot, false, "emission"); | ep.setEmission(cot, false, "emission"); | ||||
Not Done Inline ActionsHaving double negation sounds not right to me. I would rather use: if(is_shadeless) {...} else {...}or maybe: instead of is_shadeless, use boolean has_shade... gaiaclary: Having double negation sounds not right to me. I would rather use:
if(is_shadeless) {...}… | |||||
| // diffuse multiplied by diffuse intensity | // diffuse multiplied by diffuse intensity | ||||
| if (!is_shadeless) { | |||||
| cot = getcol(ma->r * ma->ref, ma->g * ma->ref, ma->b * ma->ref, 1.0f); | cot = getcol(ma->r * ma->ref, ma->g * ma->ref, ma->b * ma->ref, 1.0f); | ||||
| ep.setDiffuse(cot, false, "diffuse"); | ep.setDiffuse(cot, false, "diffuse"); | ||||
| } | |||||
Not Done Inline Actionsyou could move line 241 and line 245 below the if/else block. gaiaclary: you could move line 241 and line 245 below the if/else block. | |||||
| // ambient | // ambient | ||||
| /* ma->ambX is calculated only on render, so lets do it here manually and not rely on ma->ambX. */ | /* ma->ambX is calculated only on render, so lets do it here manually and not rely on ma->ambX. */ | ||||
| if (this->scene->world) | if (is_shadeless) | ||||
| cot = getcol(this->scene->world->ambr * ma->amb, this->scene->world->ambg * ma->amb, this->scene->world->ambb * ma->amb, 1.0f); | |||||
| else | |||||
| cot = getcol(ma->amb, ma->amb, ma->amb, 1.0f); | cot = getcol(ma->amb, ma->amb, ma->amb, 1.0f); | ||||
| else { | |||||
| if (this->scene->world) | |||||
| cot = getcol(this->scene->world->ambr * ma->amb, | |||||
| this->scene->world->ambg * ma->amb, | |||||
| this->scene->world->ambb * ma->amb, 1.0f); | |||||
| ep.setAmbient(cot, false, "ambient"); | ep.setAmbient(cot, false, "ambient"); | ||||
| } | |||||
Not Done Inline Actionsadd a line break and indent here gaiaclary: add a line break and indent here | |||||
| // reflective, reflectivity | // reflective, reflectivity | ||||
| if (ma->mode & MA_RAYMIRROR) { | if (ma->mode & MA_RAYMIRROR) { | ||||
| cot = getcol(ma->mirr, ma->mirg, ma->mirb, 1.0f); | cot = getcol(ma->mirr, ma->mirg, ma->mirb, 1.0f); | ||||
| ep.setReflective(cot); | ep.setReflective(cot); | ||||
| ep.setReflectivity(ma->ray_mirror); | ep.setReflectivity(ma->ray_mirror); | ||||
| } | } | ||||
| // else { | // else { | ||||
| // cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f); | // cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f); | ||||
| // ep.setReflective(cot); | // ep.setReflective(cot); | ||||
| // ep.setReflectivity(ma->spec); | // ep.setReflectivity(ma->spec); | ||||
| // } | // } | ||||
| // specular | // specular | ||||
| if (ep.getShaderType() != COLLADASW::EffectProfile::LAMBERT) { | if (ep.getShaderType() != COLLADASW::EffectProfile::LAMBERT) { | ||||
| if (!is_shadeless) { | |||||
| cot = getcol(ma->specr * ma->spec, ma->specg * ma->spec, ma->specb * ma->spec, 1.0f); | cot = getcol(ma->specr * ma->spec, ma->specg * ma->spec, ma->specb * ma->spec, 1.0f); | ||||
| ep.setSpecular(cot, false, "specular"); | ep.setSpecular(cot, false, "specular"); | ||||
| } | } | ||||
| } | |||||
| // XXX make this more readable if possible | // XXX make this more readable if possible | ||||
| // create <sampler> and <surface> for each image | // create <sampler> and <surface> for each image | ||||
| COLLADASW::Sampler samplers[MAX_MTEX]; | COLLADASW::Sampler samplers[MAX_MTEX]; | ||||
| //COLLADASW::Surface surfaces[MAX_MTEX]; | //COLLADASW::Surface surfaces[MAX_MTEX]; | ||||
| //void *samp_surf[MAX_MTEX][2]; | //void *samp_surf[MAX_MTEX][2]; | ||||
| void *samp_surf[MAX_MTEX]; | void *samp_surf[MAX_MTEX]; | ||||
| ▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines | |||||
i think there is no need to use the parameter is_shadeless here. See below line 195