Ogre动画加载之节点动画、mesh动画及骨骼动画加载方法

来源:互联网 发布:重复歌曲删除软件 编辑:程序博客网 时间:2024/06/07 22:48

转自:http://blog.csdn.net/y601500359/article/details/48023961


在Max中,动画分为两种动画,即Node Animations动画及Mesh Animations动画:


导出文件之后,Node Animations动画是在xx.scene文件中,

[css] view plaincopy
  1. <node name="huosaixinganzuzhong_qinang_Catheterization">  
  2.             <position x="-14.3185" y="84.3693" z="39.3585"/>  
  3.             <scale x="0.641439" y="0.64144" z="0.64144"/>  
  4.             <rotation qx="-0.00690901" qy="-0.338498" qz="-0.205336" qw="0.918264"/>  
  5.             <animations>  
  6.                 <animation name="huosaixinganzuzhong_qinang_Catheterization_Anhuosaixinganzu_qinang_Catheterization" enable="false" loop="false" interpolationMode="linear" rotationInterpolationMode="linear" length="10">  
  7.                     <keyframe time="0">  
  8.                         <translation x="-14.3185" y="84.3693" z="39.3585"/>  
  9.                         <rotation qx="-0.00690901" qy="-0.338498" qz="-0.205336" qw="0.918264"/>  
  10.                         <scale x="0.641439" y="0.64144" z="0.64144"/>  
  11.                     </keyframe>  
  12.                     <keyframe time="0.25">  
  13.                         <translation x="-14.3185" y="84.3693" z="39.3585"/>  
  14.                         <rotation qx="-0.00690901" qy="-0.338498" qz="-0.205336" qw="0.918264"/>  
  15.                         <scale x="0.641439" y="0.64144" z="0.64144"/>  
  16.                     </keyframe>  
  17.                     <keyframe time="0.5">  
  18.                         <translation x="-14.3185" y="84.3693" z="39.3585"/>  
  19.                         <rotation qx="-0.00690901" qy="-0.338498" qz="-0.205336" qw="0.918264"/>  
  20.                         <scale x="0.641439" y="0.64144" z="0.64144"/>  
  21.                     </keyframe>  
  22.                  <span style="white-space:pre">   </span>......................  
  23.                     <keyframe time="10">  
  24.                         <translation x="-14.3185" y="84.3693" z="39.3585"/>  
  25.                         <rotation qx="-0.00690901" qy="-0.338498" qz="-0.205336" qw="0.918264"/>  
  26.                         <scale x="0.641439" y="0.64144" z="0.64144"/>  
  27.                     </keyframe>  
  28.                 </animation>  
  29.             </animations>  
  30.             <node name="huosaixinganzhong_qinang_Catheterization">  
  31.                 <position x="1.80421" y="-1.25923" z="-3.50464"/>  
  32.                 <scale x="0.81164" y="1.09026" z="0.811641"/>  
  33.                 <rotation qx="-0.680035" qy="-0.241997" qz="-0.317626" qw="0.614901"/>  
  34.                 <entity name="huosaixinganzhong_qinang_Catheterization" castShadows="true" receiveShadows="true" meshFile="huosaixinganzhong_qinang_Catheterization.mesh">  
  35.                     <subentities>  
  36.                         <subentity index="0" materialName="12-Default_qinang_Catheterization"/>  
  37.                     </subentities>  
  38.                 </entity>  
  39.                 <animations>  
  40.                     <animation name="huosaixinganzhong_qinang_Catheterization_Anhuosaixinganzu_qinang_Catheterization" enable="false" loop="false" interpolationMode="linear" rotationInterpolationMode="linear" length="10">  
  41.                         <keyframe time="0">  
  42.                             <translation x="1.80421" y="-1.25923" z="-3.50464"/>  
  43.                             <rotation qx="-0.680035" qy="-0.241997" qz="-0.317626" qw="0.614901"/>  
  44.                             <scale x="0.81164" y="1.09026" z="0.811641"/>  
  45.                         </keyframe>  
  46.                         <keyframe time="0.25">  
  47.                             <translation x="2.00894" y="-1.29527" z="-3.69881"/>  
  48.                             <rotation qx="-0.680035" qy="-0.241997" qz="-0.317626" qw="0.614901"/>  
  49.                             <scale x="0.81164" y="1.09026" z="0.811641"/>  
  50.                         </keyframe>  
  51.                         <keyframe time="0.5">  
  52.                             <translation x="2.21368" y="-1.33129" z="-3.89296"/>  
  53.                             <rotation qx="-0.680035" qy="-0.241997" qz="-0.317626" qw="0.614901"/>  
  54.                             <scale x="0.81164" y="1.09026" z="0.811641"/>  
  55.                         </keyframe>  
  56.                         <keyframe time="0.75">  
  57.                             <translation x="2.41842" y="-1.36732" z="-4.08713"/>  
  58.                             <rotation qx="-0.680035" qy="-0.241997" qz="-0.317626" qw="0.614901"/>  
  59.                             <scale x="0.81164" y="1.09026" z="0.81164"/>  
  60.                         </keyframe>  
  61.                         <keyframe time="1">  
  62.                             <translation x="2.62315" y="-1.40336" z="-4.2813"/>  
  63.                             <rotation qx="-0.680035" qy="-0.241997" qz="-0.317626" qw="0.614901"/>  
  64.                             <scale x="0.81164" y="1.09026" z="0.811641"/>  
  65.                         </keyframe>  
  66.                         <keyframe time="1.25">  
  67.                             <translation x="2.82789" y="-1.43939" z="-4.47546"/>  
  68.                             <rotation qx="-0.680035" qy="-0.241997" qz="-0.317626" qw="0.614901"/>  
  69.                             <scale x="0.81164" y="1.09026" z="0.811641"/>  
  70.                         </keyframe>  
  71.                         ...................  
  72.                         </animation>  
  73.                     </animations>  
  74.                 </node>  
  75.             </node>  
  76.         </node>  

其中,动画为组动画,上例代码中大组为:huosaixinganzuzhong_qinang_Catheterization,其中包含一个实体:huosaixinganzhong_qinang_Catheterization及一个小组youshouzuzhong_qinang_Catheterization,而小组youshouzuzhong_qinang_Catheterization中又包含一个实体youshouzhong。

上述代码为Node Animations动画,其中含有骨骼动画,在组动画中,在设置动画名称时,如果设置的是组(不管是大组,还是大组中的小组),一经设置,该组中的所有实体都具有相同设置,如果不想具有统一设置,需设置到具体的实体。

而Mesh Animations动画设置后,相关动画信息是保存于实体mesh文件中,通过OgreXMLConverter.exe程序打开mesh文件,我们可以发现文件中的动画信息如下:

[css] view plaincopy
  1. <animations>  
  2.         <animation name="Anqinang_qinang_Catheterization" length="3.33333">  
  3.             <tracks>  
  4.                 <track target="submesh" index="0" type="morph">  
  5.                     <keyframes>  
  6.                         <keyframe time="0">  
  7.                             <position x="-1.58943" y="1.58688" z="4.40104" />  
  8.                             <position x="-1.58157" y="1.54572" z="4.36043" />  
  9.                             <position x="-1.53318" y="1.50714" z="4.41092" />  
  10.                             <position x="-1.53318" y="1.50714" z="4.41092" />  
  11.                             <position x="-1.54067" y="1.54639" z="4.44964" />  
  12.                             <position x="-1.58943" y="1.58688" z="4.40104" />  
  13.                             <position x="-1.57888" y="1.63509" z="4.43217" />  
  14. <span style="white-space:pre">            </span>    ............  
  15.                             <position x="-1.4892" y="1.46244" z="4.46453" />  
  16.                             <position x="-1.49738" y="1.46591" z="4.45844" />  
  17.                             <position x="-1.49738" y="1.46591" z="4.45844" />  
  18.                             <position x="-1.47142" y="1.43938" z="4.41488" />  
  19.                             <position x="-1.46384" y="1.43652" z="4.42197" />  
  20.                             <position x="-1.42566" y="1.42693" z="4.38227" />  
  21.                             <position x="-1.46384" y="1.43652" z="4.42197" />  
  22.                             <position x="-1.47142" y="1.43938" z="4.41488" />  
  23.                             <position x="-1.47142" y="1.43938" z="4.41488" />  
  24.                             <position x="-1.43234" y="1.42957" z="4.37424" />  
  25.                             <position x="-1.42566" y="1.42693" z="4.38227" />  
  26.                         </keyframe>  
  27.                     </keyframes>  
  28.                 </track>  
  29.             </tracks>  
  30.         </animation>  
  31.     </animations>  
现在分别介绍三种动画:骨骼动画、节点动画(Node Animations)和实体动画(Mesh Animations)的加载方法。

1、骨骼动画:一旦含有骨骼的实体,如果想要展现max中该有的动作,仅仅加载实体是不够的,必须将相应的动画加载进去,而骨骼动画实质上归属于实体动画,设置方式和实体动画一样,只是不需要设置动画时间。

加载方式如下:

[cpp] view plaincopy
  1. Ogre::SceneManager* m_pSceneManager;  
  2.     Ogre::SceneNode *scenenode;  
  3.     Ogre::Entity *ent;  
  4.     Ogre::Node *node;  
  5.     Ogre::AnimationState *m_anXiaoduguan_Zuoshou;  
  6.     if((m_pSceneManager->hasSceneNode("zuoshou_qinang_Catheterization")))  
  7.     {  
  8.         ent = m_pSceneManager->getEntity("zuoshou_qinang_Catheterization");//获取实体  
  9.         m_anXiaoduguan_Zuoshou = ent->getAnimationState("Anzuoshou");//获取动画,动画名称为Anzuoshou  
  10.         m_anXiaoduguan_Zuoshou->setLoop(true);//设置动画循环播放  
  11.         m_anXiaoduguan_Zuoshou->setEnabled(true);//设置动画使能,使动画能够被播放  
  12.     }  
注:实体动画,必须通过获取实体。

2、节点动画:

由于节点动画信息是保存在scene文件中,所以需要从scene文件中加载,加载方式如下:

先初始化:

[cpp] view plaincopy
  1. Ogre::SceneManager* m_pSceneManager;  
  2.     Ogre::SceneNode *scenenode;  
  3.     Ogre::Entity *ent;  
  4.     Ogre::Node *node;  
  5.     Ogre::AnimationState *m_anXiaoduguan_Zuoshou;  
  6.     if (m_pSceneManager->getSceneNode("huosaixinganzuzhong_qinang_Catheterization"))  
  7.     {  
  8.         m_anXiaoduguan_Huisaixinganzu = m_pSceneManager->getAnimationState("huosaixinganzhong_qinang_Catheterization_Anhuosaixinganzu_qinang_Catheterization");  
  9.         m_anXiaoduguan_Huisaixinganzu->setEnabled(true);  
  10.         m_anXiaoduguan_Huisaixinganzu->setLoop(false);  
  11.   
  12.         m_anXiaoduguan_Youshouzu = m_pSceneManager->getAnimationState("youshouzhong_Anhuosaixinganzu_qinang_Catheterization");  
  13.         m_anXiaoduguan_Youshouzu->setEnabled(true);  
  14.         m_anXiaoduguan_Youshouzu->setLoop(false);  
  15.     }  

在设置动画时间,如我们如通过slider来控制我们的动画,slider传来的值为n。那么时间加载如下:
[cpp] view plaincopy
  1. double dTimeNode = 3.33f/100*n;//3.33f为动画的总时间,如果需要动画加载快或者慢,通过在max中控制动画的帧数来控制  
  2. m_anXiaoduguan_Huisaixinganzu->setTimePosition(dTimeNode);  

3、实体动画:

实体动画的初始化方式和骨骼动画一致,不再赘述。

而时间加载一般通过

[cpp] view plaincopy
  1. bool frameRenderingQueued(const Ogre::FrameEvent& evt);  
函数控制,也可以自己设定时间,如果通过上述函数控制,控制方式一般如下:
[cpp] view plaincopy
  1. _aniStateXishou->addTime(evt.timeSinceLastFrame);  
  2. m_time += evt.timeSinceLastFrame;  
实体动画时间加载方式多变,需根据自我需求,自我设定。
0 0
原创粉丝点击