Ejemplo n.º 1
0
void MaterialSelector::OnMaterialRightClicked(wxListEvent& event)
{
	long item = mMaterialList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
	if(item >= 0)
	{
		wxString name = mMaterialList->GetItemText(item);
		Ogre::MaterialPtr pMaterial = Ogre::MaterialManager::getSingleton().getByName(name.c_str());
		if (!pMaterial.isNull())
		{
			
			int iSelectedPage = m_Frame->GetEditorNotebook()->GetSelection();

			if(iSelectedPage == 0)
			{
				Fairy::EffectElement* pEffectElement = dynamic_cast<Fairy::EffectElement*>(m_Frame->GetEffectObjectEditor()->GetSelectedObject());
				if(pEffectElement)
				{
					Ogre::String elementType = pEffectElement->getType();
					if(elementType == "Mesh" || elementType == "BillboardSet" || 
						elementType == "Projector" || elementType == "Beam")
					{
						wxPoint pt = event.GetPoint();
						wxMenu menu;
						wxString menuText = wxT("效果:");
						menuText.Append(elementType.c_str());
						menu.Append(feID_SET_EFFECT_MATERIAL,menuText);
						wxPoint clientpt = event.GetPoint();
						PopupMenu(&menu, pt);

					}
					
				}
				Ogre::ParticleSystem* pParticleSystem = dynamic_cast<Ogre::ParticleSystem*>(m_Frame->GetEffectObjectEditor()->GetSelectedObject());
				if(pParticleSystem)
				{
					wxPoint pt = event.GetPoint();
					wxMenu menu;
					wxString menuText = wxT("粒子:");
					menuText.Append(pParticleSystem->getName().c_str());
					menu.Append(feID_SET_EFFECT_MATERIAL,menuText);
					wxPoint clientpt = event.GetPoint();
					PopupMenu(&menu, pt);

				}
			}
			else if(iSelectedPage == 1)
			{
				Ogre::StringInterface* pElement = m_Frame->GetSkillObjectEidtor()->GetSelectedSkllElement();
				if(!pElement)
					return;
				Fairy::AnimationRibbon* pRibbon = dynamic_cast<Fairy::AnimationRibbon*>(pElement);
				if(pRibbon)
				{
					wxPoint pt = event.GetPoint();
					wxMenu menu;
					wxString menuText = wxT("技能:Ribbon ");
					menu.Append(feID_SET_SKILL_MATERIAL,menuText);
					wxPoint clientpt = event.GetPoint();
					PopupMenu(&menu, pt);
				}
			}

			//#if wxUSE_MENUS
			//	wxMenu menu(title);
			//	menu.Append(TreeTest_About, wxT("&About..."));
			//	menu.AppendSeparator();
			//	menu.Append(TreeTest_Highlight, wxT("&Highlight item"));
			//	menu.Append(TreeTest_Dump, wxT("&Dump"));
			//
			//	PopupMenu(&menu, pt);
			//#endif // wxUSE_MENUS
		}
	}
}
Ejemplo n.º 2
0
void MaterialEditorDialog::InitDialog( Fairy::SceneManipulator *manipulator )
{
	assert (manipulator);
	mSceneManipulator = manipulator;

	//InitMaterialCombo();

	// 根据当前所编辑的东西自动地选择或创建材质

	// 如果当前选择了粒子系统,就编辑该粒子系统的材质
	CurrentEditEffectType currentEditItem = gEffectSettingGlobalData.mCurrentEditEffectType;

	switch (currentEditItem)
	{
	case CEFT_PARTICLE:
		{
			Ogre::ParticleSystem *currentSystem = gEffectSettingGlobalData.mCurrentParticleSystem;
			Ogre::String currentTemplateName = gEffectSettingGlobalData.mCurrentParticleTemplateName;

			assert (currentSystem);

			if (currentSystem->getMaterialName() != currentSystem->getName())
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(currentSystem->getName());

				if (mCurrentMaterial.isNull())
				{
					mCurrentMaterial = Ogre::MaterialManager::getSingleton().create(currentSystem->getName(),"General");
				}

				Fairy::Scene::ObjectsByTypeRange particles =
					mSceneManipulator->getSceneInfo()->findObjectsByType(Fairy::ParticleSystemObject::msType);

				for (Fairy::Scene::ObjectsByTypeIterator it = particles.first; it != particles.second; ++it)
				{
					const Fairy::ObjectPtr& object = *it;
					Fairy::ParticleSystemObject* particleObject = static_cast<Fairy::ParticleSystemObject *>(object.get());

					Ogre::ParticleSystem *system = particleObject->getParticleSystem();
					Ogre::String templateName = particleObject->getPropertyAsString("particle system name");

					// 现在做的是直接对模板的修改,所以要修改全部的同个模板的特效
					if ( system && templateName == currentTemplateName )
					{
						system->setMaterialName(mCurrentMaterial->getName());
					}
				}

				// 已经创建的effect中的粒子也要相应修改
				Fairy::Scene::ObjectsByTypeRange effects =
					mSceneManipulator->getSceneInfo()->findObjectsByType(Fairy::EffectObject::msType);

				for (Fairy::Scene::ObjectsByTypeIterator it = effects.first; it != effects.second; ++it)
				{
					const Fairy::ObjectPtr& object = *it;
					const Fairy::EffectObject* effectObject = static_cast<Fairy::EffectObject *>(object.get());

					Fairy::Effect *effect = effectObject->getEffect();

					assert (effect);

					for ( size_t i=0; i<effect->getNumElements(); ++i )
					{
						Fairy::EffectElement *element = effect->getElement(i);

						if ( element->getType() == "Particle" )
						{
							Ogre::String name = static_cast<Fairy::ParticleElement *>(element)->getParticleSystemName();
							if (name == currentTemplateName)
							{
								Ogre::ParticleSystem *system = static_cast<Fairy::ParticleElement *>(element)->getParticleSystem();

								system->setMaterialName(mCurrentMaterial->getName());
							}
						}
					}		
				}

				currentSystem->setMaterialName(mCurrentMaterial->getName());	
			}
			else
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(currentSystem->getName());

				assert ( false == mCurrentMaterial.isNull() );
			}
			InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );

			break;
		}

	case CEFT_RIBBON:
		{
			unsigned short currentRibbonIndex = gEffectSettingGlobalData.mCurrentRibbonIndex;

			Fairy::AnimationRibbon *ribbon = gEffectSettingGlobalData.mCurrentSkill->getAnimationRibbon(currentRibbonIndex);

			assert (ribbon);

			Ogre::String currRibbonMatName = ribbon->getMaterialName();

			// ribbon该有的名称
			Ogre::String ribbonMatName = gEffectSettingGlobalData.mCurrentSkill->getSkillName() +
				"ribbon" + Ogre::StringConverter::toString(currentRibbonIndex);

			if ( currRibbonMatName != ribbonMatName )
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(ribbonMatName);

				if (mCurrentMaterial.isNull())
				{
					mCurrentMaterial = Ogre::MaterialManager::getSingleton().create(ribbonMatName,"General");
				}

				ribbon->setMaterial(ribbonMatName);
			}
			else
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(ribbonMatName);

				assert ( false == mCurrentMaterial.isNull() );
			}

			InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );

			break;
		}

	case CEFT_EFFECT_BEAM:
		{
			Fairy::BeamElement *beam = static_cast<Fairy::BeamElement *>
				( gEffectSettingGlobalData.mCurrentEffect->getElement(gEffectSettingGlobalData.mCurrentEffectElementIndex) );

			assert (beam);

			Ogre::String currBeamMatName = beam->getMaterialName();

			// ribbon该有的名称
			Ogre::String beamMatName = gEffectSettingGlobalData.mCurrentEffect->getTemplateName() +
				"beam" + Ogre::StringConverter::toString(gEffectSettingGlobalData.mCurrentEffectElementIndex);

			if ( currBeamMatName != beamMatName )
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(beamMatName);

				if (mCurrentMaterial.isNull())
				{
					mCurrentMaterial = Ogre::MaterialManager::getSingleton().create(beamMatName,"General");
				}

				beam->setMaterialName(beamMatName);
			}
			else
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(beamMatName);

				assert ( false == mCurrentMaterial.isNull() );
			}

			InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );

			break;
		}

	case CEFT_EFFECT_PROJECTOR:
		{
			Fairy::ProjectorElement *projectorElement = static_cast<Fairy::ProjectorElement *>
				( gEffectSettingGlobalData.mCurrentEffect->getElement(gEffectSettingGlobalData.mCurrentEffectElementIndex) );

			assert (projectorElement);

			gEffectSettingGlobalData.mOriginProjectorMaterial = projectorElement->getMaterialName();

			mCurrentMaterial = projectorElement->getProjector()->_getPatchMaterial();

			if ( false == mCurrentMaterial.isNull() )
				InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );
			else
			{
				wxMessageBox(_("Please select the material in effect editor first!"));
			}
		}

    case CEFT_EFFECT_BILLBOARDSET:
        {
            Fairy::BillboardSetElement *billboardSet = static_cast<Fairy::BillboardSetElement *>
                ( gEffectSettingGlobalData.mCurrentEffect->getElement(gEffectSettingGlobalData.mCurrentEffectElementIndex) );

            assert (billboardSet);

            Ogre::String currBillboardMatName = billboardSet->getBillboardMaterial();

            // ribbon该有的名称
            Ogre::String billboardMatName = gEffectSettingGlobalData.mCurrentEffect->getTemplateName() +
                "billboardset" + Ogre::StringConverter::toString(gEffectSettingGlobalData.mCurrentEffectElementIndex);

            if ( currBillboardMatName != billboardMatName )
            {
                mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(billboardMatName);

                if (mCurrentMaterial.isNull())
                {
                    mCurrentMaterial = Ogre::MaterialManager::getSingleton().create(billboardMatName,"General");
                }

                billboardSet->setBillboardMaterial(billboardMatName);
            }
            else
            {
                mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(billboardMatName);

                assert ( false == mCurrentMaterial.isNull() );
            }

            InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );

            break;
        }

	}
}