Changeset View
Changeset View
Standalone View
Standalone View
source/blender/collada/EffectExporter.cpp
| Context not available. | |||||
| int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); | int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); | ||||
| if (num_layers) | if (num_layers) | ||||
| return std::string(bc_CustomData_get_active_layer_name(&me->fdata, CD_MTFACE)); | return std::string(bc_CustomData_get_active_layer_name(&me->fdata, CD_MTFACE)); | ||||
| return ""; | return ""; | ||||
| } | } | ||||
| Context not available. | |||||
| bool EffectsExporter::hasEffects(Scene *sce) | bool EffectsExporter::hasEffects(Scene *sce) | ||||
| { | { | ||||
| Base *base = (Base *)sce->base.first; | Base *base = (Base *)sce->base.first; | ||||
| while (base) { | while (base) { | ||||
| Object *ob = base->object; | Object *ob = base->object; | ||||
| int a; | int a; | ||||
| Context not available. | |||||
| void EffectsExporter::writeTextures(COLLADASW::EffectProfile &ep, | void EffectsExporter::writeTextures(COLLADASW::EffectProfile &ep, | ||||
| std::string &key, | std::string &key, | ||||
| COLLADASW::Sampler *sampler, | COLLADASW::Sampler *sampler, | ||||
| MTex *t, Image *ima, | MTex *t, Image *ima, | ||||
| std::string &uvname ) { | std::string &uvname ) { | ||||
| // Image not set for texture | // Image not set for texture | ||||
| if (!ima) return; | if (!ima) return; | ||||
| // color | // color | ||||
| if (t->mapto & (MAP_COL | MAP_COLSPEC)) { | if (t->mapto & (MAP_COL | MAP_REF)) { | ||||
| ep.setDiffuse(createTexture(ima, uvname, sampler), false, "diffuse"); | ep.setDiffuse(createTexture(ima, uvname, sampler), false, "diffuse"); | ||||
| } | } | ||||
| // ambient | // ambient | ||||
| Context not available. | |||||
| ep.setAmbient(createTexture(ima, uvname, sampler), false, "ambient"); | ep.setAmbient(createTexture(ima, uvname, sampler), false, "ambient"); | ||||
| } | } | ||||
| // specular | // specular | ||||
| if (t->mapto & MAP_SPEC) { | if (t->mapto & (MAP_SPEC | MAP_COLSPEC)) { | ||||
| ep.setSpecular(createTexture(ima, uvname, sampler), false, "specular"); | ep.setSpecular(createTexture(ima, uvname, sampler), false, "specular"); | ||||
| } | } | ||||
| // emission | // emission | ||||
| Context not available. | |||||
| ep.setEmission(createTexture(ima, uvname, sampler), false, "emission"); | ep.setEmission(createTexture(ima, uvname, sampler), false, "emission"); | ||||
| } | } | ||||
| // reflective | // reflective | ||||
| if (t->mapto & MAP_REF) { | if (t->mapto & (MAP_COLMIR | MAP_RAYMIRR)) { | ||||
| ep.setReflective(createTexture(ima, uvname, sampler)); | ep.setReflective(createTexture(ima, uvname, sampler)); | ||||
| } | } | ||||
| // alpha | // alpha | ||||
| Context not available. | |||||
| ep.setTransparent(createTexture(ima, uvname, sampler)); | ep.setTransparent(createTexture(ima, uvname, sampler)); | ||||
| } | } | ||||
| // extension: | // extension: | ||||
| // Normal map --> Must be stored with <extra> tag as different technique, | // Normal map --> Must be stored with <extra> tag as different technique, | ||||
| // since COLLADA doesn't support normal maps, even in current COLLADA 1.5. | // since COLLADA doesn't support normal maps, even in current COLLADA 1.5. | ||||
| if (t->mapto & MAP_NORM) { | if (t->mapto & MAP_NORM) { | ||||
| COLLADASW::Texture texture(key); | COLLADASW::Texture texture(key); | ||||
| Context not available. | |||||
| 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(); | ||||
| Context not available. | |||||
| writePhong(ep, ma); | writePhong(ep, ma); | ||||
| } | } | ||||
| } | } | ||||
| // 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"); | ||||
| Context not available. | |||||
| //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][1]; | void *samp_surf[MAX_MTEX][1]; | ||||
| // image to index to samp_surf map | // image to index to samp_surf map | ||||
| // samp_surf[index] stores 2 pointers, sampler and surface | // samp_surf[index] stores 2 pointers, sampler and surface | ||||
| std::map<std::string, int> im_samp_map; | std::map<std::string, int> im_samp_map; | ||||
| Context not available. | |||||
| for (a = 0, b = 0; a < tex_indices.size(); a++) { | for (a = 0, b = 0; a < tex_indices.size(); a++) { | ||||
| MTex *t = ma->mtex[tex_indices[a]]; | MTex *t = ma->mtex[tex_indices[a]]; | ||||
| Image *ima = t->tex->ima; | Image *ima = t->tex->ima; | ||||
| // Image not set for texture | // Image not set for texture | ||||
| if (!ima) continue; | if (!ima) continue; | ||||
| std::string key(id_name(ima)); | std::string key(id_name(ima)); | ||||
| key = translate_id(key); | key = translate_id(key); | ||||
| Context not available. | |||||
| // COLLADASW::NewParamSurface surface(mSW); | // COLLADASW::NewParamSurface surface(mSW); | ||||
| // surface->setParamType(COLLADASW::CSW_SURFACE_TYPE_2D); | // surface->setParamType(COLLADASW::CSW_SURFACE_TYPE_2D); | ||||
| //<newparam> <sampler> <source> | //<newparam> <sampler> <source> | ||||
| COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D, | COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D, | ||||
| key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX, | key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX, | ||||
| Context not available. | |||||
| // copy values to arrays since they will live longer | // copy values to arrays since they will live longer | ||||
| samplers[a] = sampler; | samplers[a] = sampler; | ||||
| //surfaces[a] = surface; | //surfaces[a] = surface; | ||||
| // store pointers so they can be used later when we create <texture>s | // store pointers so they can be used later when we create <texture>s | ||||
| samp_surf[b][0] = &samplers[a]; | samp_surf[b][0] = &samplers[a]; | ||||
| //samp_surf[b][1] = &surfaces[a]; | //samp_surf[b][1] = &surfaces[a]; | ||||
| im_samp_map[key] = b; | im_samp_map[key] = b; | ||||
| b++; | b++; | ||||
| } | } | ||||
| Context not available. | |||||
| for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) { | for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) { | ||||
| Material *mat = give_current_material(ob, mpoly->mat_nr + 1); | Material *mat = give_current_material(ob, mpoly->mat_nr + 1); | ||||
| if (mat != ma) | if (mat != ma) | ||||
| continue; | continue; | ||||
| Image *ima = txface->tpage; | Image *ima = txface->tpage; | ||||
| Context not available. | |||||
| COLLADASW::Sampler *sampler | COLLADASW::Sampler *sampler | ||||
| /*COLLADASW::Surface *surface*/) | /*COLLADASW::Surface *surface*/) | ||||
| { | { | ||||
| COLLADASW::Texture texture(translate_id(id_name(ima))); | COLLADASW::Texture texture(translate_id(id_name(ima))); | ||||
| texture.setTexcoord(uv_layer_name); | texture.setTexcoord(uv_layer_name); | ||||
| //texture.setSurface(*surface); | //texture.setSurface(*surface); | ||||
| texture.setSampler(*sampler); | texture.setSampler(*sampler); | ||||
| COLLADASW::ColorOrTexture cot(texture); | COLLADASW::ColorOrTexture cot(texture); | ||||
| return cot; | return cot; | ||||
| } | } | ||||
| Context not available. | |||||
| return cot; | return cot; | ||||
| } | } | ||||
| //returns the array of mtex indices which have image | //returns the array of mtex indices which have image | ||||
| //need this for exporting textures | //need this for exporting textures | ||||
| void EffectsExporter::createTextureIndices(Material *ma, std::vector<int> &indices) | void EffectsExporter::createTextureIndices(Material *ma, std::vector<int> &indices) | ||||
| { | { | ||||
| Context not available. | |||||