void Mesh::objFileStructure2(const char* mtlfilename){ cout<<mtlfilename<<endl; ifstream mtl(mtlfilename,ios::in); if(!mtl){ cerr<<"File could not be found."<<endl; exit(1); } string materialLine=""; string materialToken=""; while(!mtl.eof()){ if(materialToken!="newmtl"){ getline(mtl, materialLine); std::stringstream os1(materialLine); os1>>materialToken; } if(materialToken =="newmtl"){ std::stringstream os2(materialLine); os2>>materialToken;//new mtl os2>>materialToken;//material string thematerial = materialToken; float red = 0.0776f; float green = 0.2571f; float blue = 0.2041f; do{ if(mtl.eof()){ break; } if(!mtl.eof()){ getline(mtl, materialLine); // cout<<"lines before newmtl ..."<<materialLine<<endl; std::stringstream os3(materialLine); os3>>materialToken; if(materialToken=="Kd"){ os3>>materialToken; //cout<<"red "<<materialToken<<endl; red = atof(materialToken.c_str()); os3>>materialToken; //cout<<"green "<<materialToken<<endl; green = atof(materialToken.c_str()); os3>>materialToken; // cout<<"blue "<<materialToken<<endl; blue = atof(materialToken.c_str()); } }
// Choose one possible residue modification position. Once they're all // chosen, then evaluate. static inline void choose_residue_mod(const search_context &context, match &m, const mass_trace_list *mtlp, double *mass_list, const std::vector<std::vector<spectrum>::size_type> &candidate_spectra, score_stats &stats, std::vector<int> &db_remaining, const unsigned int remaining_positions_to_choose, const unsigned int next_position_to_consider) { assert(remaining_positions_to_choose <= m.peptide_sequence.size() - next_position_to_consider); if (remaining_positions_to_choose == 0) { stats.evaluation_count += 1; evaluate_peptide(context, m, mtlp, mass_list, candidate_spectra, stats); } else { mass_trace_list mtl(mtlp); // consider all of the positions where we could next add a mod for (unsigned int i=next_position_to_consider; i <= m.peptide_sequence.size()-remaining_positions_to_choose; i++) { mtl.item.position = i; const double save_pos_mass=mass_list[i]; const char pos_res = m.peptide_sequence[i]; // consider the possibilities for this position for (std::vector<int>::const_iterator it=context.delta_bag_lookup[pos_res].begin(); it != context.delta_bag_lookup[pos_res].end(); it++) { const int db_index = *it; if (db_remaining[db_index] < 1) continue; db_remaining[db_index] -= 1; mass_list[i] = save_pos_mass + context.delta_bag_delta[db_index]; mtl.item.conjunct_item_index = db_index; choose_residue_mod(context, m, &mtl, mass_list, candidate_spectra, stats, db_remaining, remaining_positions_to_choose-1, i+1); db_remaining[db_index] += 1; } mass_list[i] = save_pos_mass; } } }
bool ccMaterialSet::fromFile_MeOnly(QFile& in, short dataVersion, int flags) { if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags)) return false; //Materials count (dataVersion>=20) uint32_t count = 0;; if (in.read((char*)&count,4) < 0) return ReadError(); if (count == 0) return true; //Load each material { for (uint32_t i=0; i<count; ++i) { ccMaterial::Shared mtl(new ccMaterial); if (!mtl->fromFile(in,dataVersion,flags)) return false; addMaterial(mtl,true); //if we load a file, we can't allow that materials are not in the same order as before! } } if (dataVersion >= 37) { QDataStream inStream(&in); //now load the number of textures (dataVersion>=37) uint32_t texCount = 0; inStream >> texCount; //and load the textures (dataVersion>=37) { for (uint32_t i=0; i<texCount; ++i) { QString filename; inStream >> filename; QImage image; inStream >> image; ccMaterial::AddTexture(image,filename); } } }
bool OBJExporter::exportModel(Model * m, std::string target) { WoWModel * model = dynamic_cast<WoWModel *>(m); if(!model) return false; // prepare obj file QString targetFile = QString::fromStdString(target); QFile file(targetFile); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { LOG_ERROR << "Unable to open" << targetFile; return false; } LOG_INFO << "Exporting" << model->modelname.c_str() << "in" << targetFile; // prepare mtl file QString matFilename = QFileInfo(target.c_str()).completeBaseName(); matFilename += ".mtl"; matFilename = QFileInfo(target.c_str()).absolutePath () + "/" + matFilename; LOG_INFO << "Exporting" << model->modelname.c_str() << "materials in" << matFilename; QFile matFile(matFilename); if (!matFile.open(QIODevice::WriteOnly | QIODevice::Text)) { LOG_ERROR << "Unable to open" << matFilename; return false; } QTextStream obj(&file); QTextStream mtl(&matFile); obj << "# Wavefront OBJ exported by " << QString::fromStdString(GLOBALSETTINGS.appName()) << " " << QString::fromStdString(GLOBALSETTINGS.appVersion()) << "\n"; obj << "\n"; obj << "mtllib " << QFileInfo(matFile).fileName() << "\n"; obj << "\n"; mtl << "#" << "\n"; mtl << "# mtl file for " << QFileInfo(targetFile).fileName() << " obj file" << "\n"; mtl << "#" << "\n"; mtl << "\n"; int counter=1; // export main model if(!exportModelVertices(model, obj, counter)) { LOG_ERROR << "Error during obj export for model" << model->modelname.c_str(); return false; } if(!exportModelMaterials(model, mtl, matFilename)) { LOG_ERROR << "Error during materials export for model" << model->modelname.c_str(); return false; } // export equipped items if(!GLOBALSETTINGS.bInitPoseOnlyExport) { for(WoWModel::iterator it = model->begin(); it != model->end(); ++it) { std::map<POSITION_SLOTS, WoWModel *> itemModels = (*it)->itemModels; if(!itemModels.empty()) { obj << "# " << "\n"; obj << "# " << (*it)->name() << "\n"; obj << "# " << "\n"; for(std::map<POSITION_SLOTS, WoWModel *>::iterator it = itemModels.begin() ; it != itemModels.end(); ++it) { WoWModel * itemModel = it->second; LOG_INFO << "Exporting attached item" << itemModel->modelname.c_str(); // find matrix int l = model->attLookup[it->first]; Matrix m; Vec3D pos; if (l>-1) { m = model->bones[model->atts[l].bone].mat; pos = model->atts[l].pos; } if(!exportModelVertices(itemModel, obj, counter, m, pos)) { LOG_ERROR << "Error during obj export for model" << itemModel->modelname.c_str(); return false; } if(!exportModelMaterials(itemModel, mtl, matFilename)) { LOG_ERROR << "Error during materials export for model" << itemModel->modelname.c_str(); return false; } } } } } file.close(); matFile.close(); return true; }