void MaterialEditor::OnSaveMaterial(wxCommandEvent &e) { if(mMaterial.isNull()) return; if(mSaveFileName == "") { wxFileDialog dialog(this, wxT("保存材质文件"), EFFECT_PATH, wxT(""), "All texture files (*.material)|*.material", wxSAVE); if (dialog.ShowModal() == wxID_OK) { wxArrayString SavePaths; dialog.GetPaths(SavePaths); mSaveFileName = SavePaths[0].c_str(); } else { return; } } Ogre::MaterialSerializer ser; ser.queueForExport(mMaterial); ser.exportQueued(mSaveFileName); }
std::string AssetsManager::materialAsText(Ogre::MaterialPtr material) { if (material.isNull()) { return ""; } Ogre::MaterialSerializer serializer; serializer.queueForExport(material, true, false); return serializer.getQueuedAsString(); }
void MaterialEditorDialog::OnSaveButtonDown(wxCommandEvent &e) { if (mCurrentMaterial.isNull()==false) { Ogre::String matName; switch (gEffectSettingGlobalData.mCurrentEditEffectType) { case CEFT_EFFECT_PROJECTOR: { matName = gEffectSettingGlobalData.mOriginProjectorMaterial; Ogre::MaterialPtr newMat = Ogre::MaterialManager::getSingleton().getByName(matName); mCurrentMaterial->copyDetailsTo(newMat); newMat->setSelfIllumination(0.0f, 0.0f, 0.0f); Ogre::String pathFileName = EFFECT_PATH + matName + ".material"; Ogre::MaterialSerializer ser; ser.queueForExport(newMat); ser.exportQueued(pathFileName); break; } default: { matName = mCurrentMaterial->getName(); Ogre::String pathFileName = EFFECT_PATH + matName + ".material"; Ogre::MaterialSerializer ser; ser.queueForExport(mCurrentMaterial); ser.exportQueued(pathFileName); break; } } wxMessageBox("Success Save!"); Hide(); } }
QString OgreMaterialProperties::ToString() { Ogre::MaterialPtr matPtr = ToOgreMaterial(); if (matPtr.isNull()) return ""; Ogre::MaterialSerializer serializer; serializer.queueForExport(matPtr, true, false); return QString(serializer.getQueuedAsString().c_str()); }
int OgreNodeHandler::endShape() { std::cout << "End Shape\n"; if (!_currentEntity && !_currentManualObject) { std::cout << "No geometry found\n"; return 1; } if (_currentEntity) { _nodeStack.top()->attachObject(_currentEntity); if (_currentMaterial.isNull()) { _currentEntity->getSubEntity(0)->setMaterialName("_X3DNOMATERIAL"); //_currentMaterial = MaterialManager::getSingleton().create("_x3ddefaultmaterial", "X3DRENDERER"); } else { //std::cout << "Setting active Material: " << static_cast<Ogre::Entity*>(obj)->getSubEntity(0)->getMaterialName() << std::endl; _currentEntity->getSubEntity(0)->setMaterialName(_currentMaterial->getName()); Ogre::MaterialSerializer serial; serial.queueForExport(_currentMaterial); std::cout << "Current material:" << std::endl << serial.getQueuedAsString(); serial.clearQueue(); std::cout << "Material source blend factor: " << _currentMaterial->getTechnique(0)->getPass(0)->getSourceBlendFactor(); std::cout << "Material destination blend factor: " << _currentMaterial->getTechnique(0)->getPass(0)->getDestBlendFactor(); std::cout << (_currentMaterial->isTransparent() ? "Material is transparent" : "Material is opaque"); } std::cout << "Setting active Material: " << _currentEntity->getSubEntity(0)->getMaterialName() << std::endl; _currentEntity = NULL; } if (_currentManualObject) { _nodeStack.top()->attachObject(_currentManualObject); _currentManualObject = NULL; } _currentMaterial.setNull(); _shapeName.clear(); return 1; }
void MilkshapePlugin::doExportMaterials(msModel* pModel) { Ogre::LogManager& logMgr = Ogre::LogManager::getSingleton(); Ogre::MaterialManager matMgrSgl; Ogre::String msg; matMgrSgl.initialise(); int numMaterials = msModel_GetMaterialCount(pModel); msg = "Number of materials: " + Ogre::StringConverter::toString(numMaterials); logMgr.logMessage(msg); OPENFILENAME ofn; memset (&ofn, 0, sizeof (OPENFILENAME)); char szFile[MS_MAX_PATH]; char szFileTitle[MS_MAX_PATH]; char szDefExt[32] = "material"; char szFilter[128] = "OGRE .material Files (*.material)\0*.material\0All Files (*.*)\0*.*\0\0"; szFile[0] = '\0'; szFileTitle[0] = '\0'; ofn.lStructSize = sizeof (OPENFILENAME); ofn.lpstrDefExt = szDefExt; ofn.lpstrFilter = szFilter; ofn.lpstrFile = szFile; ofn.nMaxFile = MS_MAX_PATH; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = MS_MAX_PATH; ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST; ofn.lpstrTitle = "Export to OGRE Material"; if (!::GetSaveFileName (&ofn)) return; // Strip off the path Ogre::String matName = szFile; size_t lastSlash = matName.find_last_of("\\"); matName = matName.substr(lastSlash+1); // Set up logMgr.logMessage("Trying to create Material object"); Ogre::MaterialSerializer matSer; for (int i = 0; i < numMaterials; ++i) { msMaterial *mat = msModel_GetMaterialAt(pModel, i); msg = "Creating material " + Ogre::String(mat->szName); logMgr.logMessage(msg); Ogre::MaterialPtr ogremat = matMgrSgl.create(mat->szName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); logMgr.logMessage("Created."); ogremat->setAmbient(msVec4ToColourValue(mat->Ambient)); ogremat->setDiffuse(msVec4ToColourValue(mat->Diffuse)); ogremat->setSpecular(msVec4ToColourValue(mat->Specular)); ogremat->setShininess(mat->fShininess); if (0 < strlen(mat->szDiffuseTexture)) ogremat->getTechnique(0)->getPass(0)->createTextureUnitState(mat->szDiffuseTexture); if (0 < strlen(mat->szAlphaTexture)) ogremat->getTechnique(0)->getPass(0)->createTextureUnitState(mat->szAlphaTexture); matSer.queueForExport(ogremat); } msg = "Exporting materials to " + matName; logMgr.logMessage(msg); matSer.exportQueued(matName); }