Exemplo n.º 1
0
void MaterialEditorDialog::setMeshMaterial(void)
{
	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 == gEffectSettingGlobalData.mCurrentParticleTemplateName )
		{
			Ogre::MeshParticleRenderer *renderer = static_cast<Ogre::MeshParticleRenderer *>
				(system->getRenderer());

			assert (renderer->getType() == "mesh");

			renderer->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 == gEffectSettingGlobalData.mCurrentParticleTemplateName)
				{
					Ogre::ParticleSystem *system = static_cast<Fairy::ParticleElement *>(element)->getParticleSystem();

					Ogre::MeshParticleRenderer *renderer = static_cast<Ogre::MeshParticleRenderer *>
						(system->getRenderer());

					assert (renderer->getType() == "mesh");

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

	if (gEffectSettingGlobalData.mCurrentSkill)
	{
		for ( unsigned short i = 0; i < gEffectSettingGlobalData.mCurrentSkill->getNumAnimationEffectInfos(); ++i )
		{
			Fairy::AnimationEffectInfo *effectInfo = gEffectSettingGlobalData.mCurrentSkill->getAnimationEffectInfo(i);
			assert (effectInfo);

			Fairy::Effect *effect = effectInfo->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 == gEffectSettingGlobalData.mCurrentParticleTemplateName)
					{
						Ogre::ParticleSystem *system = static_cast<Fairy::ParticleElement *>(element)->getParticleSystem();

						Ogre::MeshParticleRenderer *renderer = static_cast<Ogre::MeshParticleRenderer *>
							(system->getRenderer());

						assert (renderer->getType() == "mesh");

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

	Ogre::MeshParticleRenderer *renderer = static_cast<Ogre::MeshParticleRenderer *>
		(gEffectSettingGlobalData.mCurrentParticleSystem->getRenderer());

	assert (renderer->getType() == "mesh");

	renderer->setMaterialName(mCurrentMaterial->getName());
}
Exemplo n.º 2
0
void
WXEffectEditDialog::OnPropertyChanged(wxPropertyGridEvent& e)
{
	// Skip parent properties
    if (e.GetPropertyPtr()->GetParentingType() != 0)
        return;
        
	wxPGId id = e.GetPropertyPtr()->GetId();
	wxPGId parentId = mPropertiesViewer->GetPropertyParent(id);

	const wxString &parentLabel = mPropertiesViewer->GetPropertyLabel(parentId);

	unsigned short index = mPropertiesViewer->GetPropertyIndex(parentId);

	Fairy::String propertyName = e.GetPropertyName().c_str();
	Fairy::String propertyValue = e.GetPropertyValueAsString().c_str();

	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);

		// 现在做的是直接对模板的修改,所以要修改全部的同个模板的特效
		if ( effect->getTemplateName() == mEffect->getTemplateName() )
		{
			if (index < effect->getNumElements())
			{
				Fairy::EffectElement *element = effect->getElement(index);
				assert (element);

				element->setParameter(propertyName, propertyValue);
			}
			else
			{
				effect->setParameter(propertyName, propertyValue);
			}
		}
	}

    // 更新当前的skill
    if (gEffectSettingGlobalData.mCurrentSkill)
    {
        for ( unsigned short i = 0; i < gEffectSettingGlobalData.mCurrentSkill->getNumAnimationEffectInfos(); ++i )
        {
            Fairy::AnimationEffectInfo *effectInfo = gEffectSettingGlobalData.mCurrentSkill->getAnimationEffectInfo(i);
            assert (effectInfo);

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

            assert (effect);

            // 现在做的是直接对模板的修改,所以要修改全部的同个模板的特效
            if ( effect->getTemplateName() == mEffect->getTemplateName() )
            {
                if (index < effect->getNumElements())
                {
                    Fairy::EffectElement *element = effect->getElement(index);
                    assert (element);

                    element->setParameter(propertyName, propertyValue);
                }
                else
                {
                    effect->setParameter(propertyName, propertyValue);
                }
            }
        }
    }
}
Exemplo n.º 3
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;
        }

	}
}