示例#1
0
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);

}
示例#2
0
std::string AssetsManager::materialAsText(Ogre::MaterialPtr material)
{
	if (material.isNull()) {
		return "";
	}
	Ogre::MaterialSerializer serializer;
	serializer.queueForExport(material, true, false);
	return serializer.getQueuedAsString();
}
示例#3
0
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());
}
//-----------------------------------------------------------------------
void MaterialTab::OnSaveMaterial(wxCommandEvent& event)
{
#ifdef PU_FULL_VERSION
	if (mMaterialListBox)
	{
		wxString filename = mMaterialListBox->GetStringSelection();
		wxFileDialog saveDialog(this, 
			_("Save the material"), 
			wxT(""), 
			filename,
			_("material scripts (*.material;*.osm)|*.material;*.osm"),
			wxFD_SAVE | wxFD_OVERWRITE_PROMPT, 
			wxDefaultPosition, 
			wxDefaultSize, _("Save"));
		if (saveDialog.ShowModal() == wxID_OK)
		{
			SetCursor(*wxHOURGLASS_CURSOR);

			wxString materialName = mMaterialListBox->GetStringSelection();
			Ogre::String name = wx2ogre(materialName);
			Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(name);
			if (!material.isNull())
			{
				// User has pressed ok, so save the material
				Ogre::MaterialSerializer ms;
				Ogre::String path = wx2ogre(saveDialog.GetPath());
				Ogre::String baseName;
				Ogre::String extension;
				Ogre::String dir;
				Ogre::StringUtil::splitFullFilename(path, baseName, extension, dir);
				ms.exportMaterial(material, path);
				
				// Save the selected material + resource locations of material and texture
				ParticleUniverseEditorFrame* frame = static_cast<ParticleUniverseEditorFrame*>(mRootParent);
				mResourceLocationMaterial = ogre2wx(dir);
				frame->addResourcePathToConfig(mResourceLocationMaterial);
				frame->addResourcePathToConfig(mResourceLocationTexture);
			}
			
			SetCursor(wxNullCursor);
		}
	}
#endif // PU_FULL_VERSION
}
示例#5
0
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 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();
	}
}
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);
}
示例#8
0
void saveAsDotScene(const QString& path, QFile& file, Ogre::SceneManager* sceneManager)
{
    Ogre::MeshSerializer* mMeshSerializer = new Ogre::MeshSerializer();
    Ogre::MaterialSerializer* mMaterialSerializer = new Ogre::MaterialSerializer();

    int idCounter = 3;
    if (!file.open(QIODevice::WriteOnly))
    {
        /* show wrror message if not able to open file */
        QMessageBox::warning(0, "Read only", "The file is in read only mode");
    }
    else
    {
        Ogre::SceneManager::MovableObjectIterator iterator = sceneManager->getMovableObjectIterator("Entity");
        QXmlStreamWriter* xmlWriter = new QXmlStreamWriter();
        xmlWriter->setAutoFormatting(true);
        xmlWriter->setDevice(&file);
        xmlWriter->writeStartElement("scene");
        xmlWriter->writeAttribute("formatVersion","");

        xmlWriter->writeStartElement("nodes");
        while(iterator.hasMoreElements())
        {
            Ogre::Entity* e = static_cast<Ogre::Entity*>(iterator.getNext());
            Ogre::Any any = e->getParentNode()->getUserAny();
            Ogre::String widgetType("");
            if(!any.isEmpty()){
                widgetType = any_cast<Ogre::String>(any);
            }
            Ogre::String tmp(widgetType + ":" + e->getParentNode()->getName());
            QString nodeName(tmp.c_str());
            xmlWriter->writeStartElement("node");
            xmlWriter->writeAttribute("name", nodeName);
            xmlWriter->writeAttribute("id", QString::number(idCounter++));


            xmlWriter->writeStartElement("position");
            xmlWriter->writeAttribute("x", QString::number(e->getParentNode()->getPosition().x));
            xmlWriter->writeAttribute("y", QString::number(e->getParentNode()->getPosition().y));
            xmlWriter->writeAttribute("z", QString::number(e->getParentNode()->getPosition().z));
            xmlWriter->writeEndElement();

            xmlWriter->writeStartElement("scale");
            xmlWriter->writeAttribute("x", QString::number(e->getParentNode()->getScale().x));
            xmlWriter->writeAttribute("y", QString::number(e->getParentNode()->getScale().y));
            xmlWriter->writeAttribute("z", QString::number(e->getParentNode()->getScale().z));
            xmlWriter->writeEndElement();

            xmlWriter->writeStartElement("entity");
            xmlWriter->writeAttribute("name", nodeName);
            xmlWriter->writeAttribute("meshFile", nodeName.toLower() + QString(".mesh") );
            xmlWriter->writeAttribute("static", QString("false"));
            xmlWriter->writeEndElement();

            const Mesh* mesh = e->getMesh().getPointer();


            mMeshSerializer->exportMesh(mesh,String(path.toStdString() +
                                                    nodeName.toLower().toStdString() +
                                                    ".mesh" ));


            std::cout << "numeber" <<  mesh->getNumSubMeshes() << std::endl;


            for(int i = 0; i < e->getNumSubEntities(); i++){


                Ogre::Material *mat = static_cast<Ogre::Material*>
                        (Ogre::MaterialManager::getSingletonPtr()->getByName(e->getSubEntity(i)->getMaterialName()).getPointer());

                //e->getMesh().get()->getSubMesh()
                if(mat->getTechnique(0)->getPass(0)->getNumTextureUnitStates() !=0){
                Ogre::String str = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();

            Ogre::MaterialPtr mMatPtr =e->getSubEntity(i)->getMaterial()    ;

            mMaterialSerializer->exportMaterial(mMatPtr ,
                                                String(path.toStdString() +
                                                       nodeName.toLower().toStdString() +
                                                       QString::number(i).toStdString() + ".material" ));
            Ogre::TexturePtr* mTexPtr = new Ogre::TexturePtr(Ogre::TextureManager::getSingletonPtr()->getByName(str));
            Ogre::Texture* mTex = mTexPtr->getPointer();
            Ogre::PixelFormat pxf = mTex->getFormat();
            Ogre::Image mImage;
            mTex->convertToImage(mImage);
            std::cout << str << std::endl;
            mImage.save(String(path.toStdString() +
                                 str));
                }
}
            //material file merge

            for(int i = 0; i < e->getNumSubEntities(); i++){
                Ogre::Material *mat = static_cast<Ogre::Material*>
                        (Ogre::MaterialManager::getSingletonPtr()->getByName(e->getSubEntity(i)->getMaterialName()).getPointer());


                QString mMatFilePath = QString((path.toStdString() +
                                               nodeName.toLower().toStdString() +
                                                ".material").c_str()) ;


                 QFile mFile(mMatFilePath);
                 if (!mFile.open(QIODevice::Append))
                 {
                     /* show wrror message if not able to open file */
                     QMessageBox::warning(0, "Read only", "The file is in read only mode");
                 }
                 else{
                     QTextStream out(&mFile);

                     QString mTempMatPath = QString((path + nodeName.toLower() + QString::number(i) + ".material"));

                     QFile mTempMatFile(mTempMatPath);
                     mTempMatFile.open(QIODevice::ReadOnly);

                     QTextStream src(&mTempMatFile);

                     mFile.write(src.readAll().toStdString().c_str());
                     mTempMatFile.remove();

                 }



            }


            xmlWriter->writeEndElement();


        }

        xmlWriter->writeEndElement();
        xmlWriter->writeEndDocument();
        delete xmlWriter;
    }

    delete mMeshSerializer;
    delete mMaterialSerializer;
}