コード例 #1
0
void AssetLoader::createCamera(Ogre::SceneManager* sceneMgr, const aiScene* scene, Ogre::String camName)
{
	for (size_t n = 0; n < scene->mNumCameras; n++)
	{
		// カメラを作成
		Ogre::Camera* cam = sceneMgr->createCamera(scene->mCameras[n]->mName.data);
		std::cout << "Create Camra " << cam->getName() << " " << scene->mCameras[n]->mHorizontalFOV << std::endl;
		cam->setFOVy(Ogre::Radian(scene->mCameras[n]->mHorizontalFOV));
		
		// 視点アニメーション用ノード
		Ogre::SceneNode* camNode = sceneMgr->getRootSceneNode()->createChildSceneNode(cam->getName()+"CamNode");
		camNode->attachObject(cam);

		// アニメーションを走査
		for (size_t na = 0; na < scene->mNumAnimations; na++) {
			aiAnimation* aiani = scene->mAnimations[na];
			for (size_t nc = 0; nc < aiani->mNumChannels; nc++) {
				// カメラと同じ名前のチャネルを取得する
				if (Ogre::String(scene->mCameras[n]->mName.data) == cam->getName()) {
					
					//アニメーションを付けるトラックを作成しておく
					Ogre::Animation* ogani = sceneMgr->createAnimation(cam->getName()+"Animation", aiani->mDuration);
					std::cout << "Animation : " << ogani->getName() << std::endl; 
					Ogre::NodeAnimationTrack* track = ogani->createNodeTrack(0, camNode);
					ogani->setInterpolationMode(Ogre::Animation::IM_LINEAR);

					// アニメーションチャネルからキーフレームアニメーションを取得
					aiNodeAnim* chan = aiani->mChannels[n];
					for (size_t np = 0; np < chan->mNumPositionKeys; np++) {						
						aiVectorKey* vk = &(chan->mPositionKeys[np]);
						Ogre::TransformKeyFrame* key = track->createNodeKeyFrame(vk->mTime);
						key->setTranslate(Ogre::Vector3(vk->mValue[0], vk->mValue[1], vk->mValue[2]));

						aiQuatKey* qk = &(chan->mRotationKeys[np]);
						key->setRotation(Ogre::Quaternion(qk->mValue.w, qk->mValue.x, qk->mValue.y, qk->mValue.z));
					}

					// 管理するアニメーションの名前を付けておく
					Ogre::AnimationState* aniState = sceneMgr->createAnimationState(ogani->getName());
					aniState->setEnabled(true);
					aniState->setLoop(true);
					aniState->setTimePosition(0.0);

					//ループを抜ける
					na = scene->mNumAnimations;
					break;
				}
			}
		}
	}
}
コード例 #2
0
ファイル: CMonster3D.cpp プロジェクト: hjqqq/Forever
void CMonster3D::setupSkeleton(std::string skeletonFile)
{
   Ogre::SkeletonPtr pSkeletonBody = Ogre::SkeletonManager::getSingleton().getByName(m_meshName + ".skeleton");

   Ogre::Skeleton::BoneHandleMap boneHandleMap;
  
   Ogre::SkeletonPtr pNewSkeleton = Ogre::SkeletonManager::getSingleton().load(skeletonFile, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
   Ogre::Animation *pSrcAnimation = pNewSkeleton->getAnimation(0);
   std::string newAnimationName = pSrcAnimation->getName() + "::" + m_pMonsterNode->getName();
   Ogre::Animation *pNewAnimation = pNewSkeleton->createAnimation(newAnimationName, pSrcAnimation->getLength());
   Ogre::Animation *pCloneAnimation = pNewSkeleton->getAnimation(0)->clone(newAnimationName);
   *pNewAnimation = *pCloneAnimation;
   pNewSkeleton->removeAnimation(pSrcAnimation->getName());

   pNewSkeleton->_buildMapBoneByHandle(pNewSkeleton.getPointer(), boneHandleMap);
   pSkeletonBody->_mergeSkeletonAnimations(pNewSkeleton.getPointer(), boneHandleMap);
   Ogre::SkeletonManager::getSingleton().remove(skeletonFile);

   m_pBodyEntity->getSkeleton()->_refreshAnimationState(m_pBodyEntity->getAllAnimationStates());
}
コード例 #3
0
void ActorAnimationSettingEditor::init()
{

	wxGraphDialog* pGraphDialog = m_Frame->GetGraphDialog();
	if(pGraphDialog)
		pGraphDialog->SetLoop(mDObject->getAnimationLoop());

	this->SetTitle(Fairy::VariantCast<Ogre::String>(mObject->getProperty("actor name")));

	//重新设置动画列表框

	mListBoxAnimation->Clear();

	for ( unsigned short i = 0; i < mDObject->getSkeletonAnimationCount(); ++i )
	{
		Ogre::Animation *anim = mDObject->getSkeletonAnimation(i);

		if ( anim )
		{
			wxString nameStr(anim->getName().c_str());
			mListBoxAnimation->InsertItems( 1, &nameStr, 0 );            
		}
	}
	// 加入obj中定义的动作名称
	Fairy::LogicModelManager::AnimationSkeletonLinksIterator asmIt = 
		Fairy::LogicModelManager::getSingleton().getAnimationSkeletonLinksIterator(mDObject->getName());

	while ( asmIt.hasMoreElements() )
	{
		wxString animName(asmIt.peekNextKey().c_str());

		if ( wxNOT_FOUND == mListBoxAnimation->FindString(animName) )
		{
			wxString nameStr(animName.c_str());
			mListBoxAnimation->InsertItems( 1, &nameStr, 0 );
		}

		asmIt.moveNext();
	}

	//重新设置声音
	if ( NULL == Fairy::LogicModel::GetPlaySoundFuncton() )
	{
		Fairy::LogicModel::SetPlaySoundFuncton(wxGetApp().funcPlay);
	}

	if ( NULL == Fairy::LogicModel::GetStopSoundFunction() )
		Fairy::LogicModel::SetStopSoundFunction(wxGetApp().funcStop);


   
}
コード例 #4
0
wxPGConstants * FairySkillEditDialog::PopulateConstants(const Ogre::String& name)
{
	size_t id = reinterpret_cast<size_t>(&name);
	wxPGConstants* constants = wxPropertyGrid::GetConstantsArray(id);

	if (constants)
	{
		for (std::list<wxPGConstants*>::iterator it = mConstantList.begin(); it != mConstantList.end(); ++it)
		{
			if (constants == *it)
			{
				if (constants->UnRef())
					delete constants;

				mConstantList.erase(it);

				break;
			}
		}
	}

//	if (!constants)
//	{
		constants = wxPropertyGrid::CreateConstantsArray(id);

		if ( name == "Animation" )
		{
			// 第一个为空,表示设置这个元素的材质是用原mesh的材质
			for ( unsigned short i = 0; i < mDObject->getSkeletonAnimationCount(); ++i )
			{
				Ogre::Animation *anim = mDObject->getSkeletonAnimation(i);

				if ( anim )
				{
					constants->Add(anim->getName().c_str());
				}
			}			
		}
		else if ( name == "EffectTemplateName" )
		{
			WX::EffectManager::EffectTemplateIterator it = 
				WX::EffectManager::getSingleton().getEffectTemplateIterator();

			while ( it.hasMoreElements() )
			{
				constants->Add(it.peekNextKey().c_str());

				it.moveNext();
			}
		}
		else if ( name == "AttachPoint" )
		{
			for ( unsigned short i=0; i<mDObject->getNumBones(); ++i )
			{
				constants->Add(mDObject->getBoneName(i).c_str());
			}	

			Ogre::StringVector locatorNames;
			mDObject->getLocatorNames(locatorNames);

			for ( size_t i=0; i<locatorNames.size(); ++i )
			{
				constants->Add(locatorNames[i].c_str());
			}			
		}
		else if ( name == "Material" )
		{
			typedef std::list<Ogre::String> MaterialFileNameList;
			MaterialFileNameList materialFileNameList;

			Ogre::FileInfoListPtr fileInfoList =
				Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
				Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
				"*.material");
			for (Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
			{
				if ( it->archive->getName() == MATERIAL_PATH)
				{
					materialFileNameList.push_back(it->filename);
				}
			}

			Ogre::ResourceManager::ResourceMapIterator resourceMapIterator = Ogre::MaterialManager::getSingleton().getResourceIterator();

			while ( resourceMapIterator.hasMoreElements() )
			{				
				Ogre::String matName = resourceMapIterator.peekNextValue()->getName();

				for ( MaterialFileNameList::iterator i = materialFileNameList.begin();
					i != materialFileNameList.end(); ++i )
				{
					if ( *i == resourceMapIterator.peekNextValue()->getOrigin() )
					{
						constants->Add(matName.c_str());
						break;
					}
				}

				resourceMapIterator.moveNext();
			}
		}	
		else if ( name == "SoundName" )
		{
            constants->Add("NULL");
			//-----------------------------------
			//得到所有文件名
            if (wxGetApp().funcEnumSoundFile)
            {
			    int nIndex = 0;
			    do
			    {
				    char szTemp[100];

                    int id;

				    bool bHave = wxGetApp().funcEnumSoundFile(nIndex++, szTemp, 100, id);
				    if(!bHave) break;

				    constants->Add(szTemp);
			    }while(true);
            }
		}

		registerConstants(constants);
	//}

	return constants;
}
コード例 #5
0
void
AddSkillDialog::OnInitDialog(wxInitDialogEvent &e)
{
	wxDialog::OnInitDialog(e);

	wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );

	wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );

	wxStaticText *item2 = new wxStaticText( this, ID_TEXT, /*_("Animation")*/ wxT("动作"), wxDefaultPosition, wxDefaultSize, 0 );
	item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );

	wxString *strs3 = (wxString*) NULL;
	wxComboBox *item3 = new wxComboBox( this, ID_COMBO_ANIMATION, wxT(""), wxDefaultPosition, wxSize(200,-1), 0, strs3, wxCB_DROPDOWN );
	item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );

	wxStaticText *item4 = new wxStaticText( this, ID_TEXT, /*_("Skill Name")*/wxT("技能名称"), wxDefaultPosition, wxDefaultSize, 0 );
	item1->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );

	wxTextCtrl *item5 = new wxTextCtrl( this, ID_TEXTCTRL_SKILL, wxT(""), wxDefaultPosition, wxSize(200,-1), 0 );
	item1->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );

	wxButton *item6 = new wxButton( this, wxID_OK, /*_("OK")*/wxT("确认[&O]"), wxDefaultPosition, wxDefaultSize, 0 );
	item1->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );

	wxButton *item7 = new wxButton( this, wxID_CANCEL, /*_("Cancel")*/wxT("取消[&C]"), wxDefaultPosition, wxDefaultSize, 0 );
	item1->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );

	item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );

	this->SetSizer( item0 );
	item0->SetSizeHints( this );

	ActorAnimationSettingDialog *parentDialog = static_cast<ActorAnimationSettingDialog *>(this->GetParent());
	assert (parentDialog);
	WX::LogicModel *object = parentDialog->GetCurrentObject();
	
	for ( unsigned short i = 0; i < object->getSkeletonAnimationCount(); ++i )
	{
		Ogre::Animation *anim = object->getSkeletonAnimation(i);

		if ( anim )
		{
			wxString nameStr(anim->getName().c_str());
			item3->AppendString(nameStr);
		}
	}

    // 加入obj中定义的动作名称
    WX::LogicModelManager::AnimationSkeletonLinksIterator asmIt = 
        WX::LogicModelManager::getSingleton().getAnimationSkeletonLinksIterator(object->getName());

    while ( asmIt.hasMoreElements() )
    {
        wxString animName(asmIt.peekNextKey().c_str());

        if ( wxNOT_FOUND == item3->FindString(animName) )
        {
            wxString nameStr(animName.c_str());
            item3->AppendString(nameStr);
        }

        asmIt.moveNext();
    }

	item3->SetSelection(0);
	mAnimComboBox = item3;

	mSkillNameTextCtrl = item5;	
}
コード例 #6
0
void ActorAnimationSettingDialog::OnInitDialog(wxInitDialogEvent &e)
{
	wxDialog::OnInitDialog(e);
	wxSizer* sizer = ActorAnimationSetting(this, true, true);

	// 获取各控件的引用
	mListBoxAnimation = wxDynamicCast(this->FindWindow(ID_LISTBOX_ANIMATION),wxListBox);
	mSliderAnimTimePos = wxDynamicCast(this->FindWindow(ID_SLIDER_TIME),wxSlider);
	mSliderAnimRate = wxDynamicCast(this->FindWindow(ID_SLIDER_GLOBAL_ANIM_RATE),wxSlider);
	mSliderAnimFadeOutTime = wxDynamicCast(this->FindWindow(ID_SLIDER_FADE_OUT_TIME),wxSlider);

	mListBoxAllSkill = wxDynamicCast(this->FindWindow(ID_LISTBOX_ALL_SKILL),wxListBox);
	mCheckBoxLoop = wxDynamicCast(this->FindWindow(ID_CHECKBOX_LOOP),wxCheckBox);

	mHairTextCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_HAIR), wxTextCtrl);
	mCapTextCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_CAP), wxTextCtrl);
	mBodyTextCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_BODY), wxTextCtrl);
	mHandTextCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_HAND), wxTextCtrl);
	mFootTextCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_FOOT), wxTextCtrl);

    mHairTextMatCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_HAIR_MAT), wxTextCtrl);
    mCapTextMatCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_CAP_MAT), wxTextCtrl);
    mBodyTextMatCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_BODY_MAT), wxTextCtrl);
    mHandTextMatCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_HAND_MAT), wxTextCtrl);
    mFootTextMatCtrl = wxDynamicCast(this->FindWindow(ID_TEXTCTRL_FOOT_MAT), wxTextCtrl);

    mColourButton = wxDynamicCast(this->FindWindow(ID_BUTTON_COLOUR), wxButton);

	mCheckBoxLoop->SetValue(mDObject->getAnimationLoop());

	for ( unsigned short i = 0; i < mDObject->getSkeletonAnimationCount(); ++i )
	{
		Ogre::Animation *anim = mDObject->getSkeletonAnimation(i);

		if ( anim )
		{
			wxString nameStr(anim->getName().c_str());
			mListBoxAnimation->InsertItems( 1, &nameStr, 0 );            
		}
	}

    // 加入obj中定义的动作名称
    WX::LogicModelManager::AnimationSkeletonLinksIterator asmIt = 
        WX::LogicModelManager::getSingleton().getAnimationSkeletonLinksIterator(mDObject->getName());

    while ( asmIt.hasMoreElements() )
    {
        wxString animName(asmIt.peekNextKey().c_str());

        if ( wxNOT_FOUND == mListBoxAnimation->FindString(animName) )
        {
            wxString nameStr(animName.c_str());
            mListBoxAnimation->InsertItems( 1, &nameStr, 0 );
        }

        asmIt.moveNext();
    }

    if ( NULL == WX::LogicModel::GetPlaySoundFuncton() )
	{
		WX::LogicModel::SetPlaySoundFuncton(wxGetApp().funcPlay);
	}
	
	if ( NULL == WX::LogicModel::GetStopSoundFunction() )
		WX::LogicModel::SetStopSoundFunction(wxGetApp().funcStop);

	FillAllSkillListBox();
}