Ogre : How to actually get morph animations to work in the engine
2017-05-12 18:27
525 查看
Introduction
Ogre features both Morph animation and Pose animation. The difference between these two techniques is explained in themanual
. However,
what is not explained there, is how to actually get morph animations to work in the engine. This article provides explanation of this.
Code in the engine
Morph animation works like skeletal animation from the in-engine point of view. If there is a morph animation in the mesh, then you can get it to animate like this:
Morph AnimationState usage
//get the animation Ogre::AnimationState* state = entity->getAnimationState("morph"); state->setEnabled(true); //do this every frame to play the animation float time = 0.1f; state->addTime(time);
An example shader
You can let OGRE do software blending of the morph animation, but you can also do it in hardware. The shader will only get morph data from the engine if its AnimationState is enabled, so the code above is needed.
Morph.material
vertex_program Cg_Morph_VP cg { source Morph.cg entry_point Morph_VP profiles vs_1_1 includes_morph_animation true default_params { param_named_auto worldViewProjMatrix worldviewproj_matrix param_named_auto animationPhase animation_parametric } } material Morph { technique { pass { vertex_program_ref Cg_Morph_VP { } } } }
Morph.cg
Note that the second position is put in the first free texture coordinate.void Morph_VP ( float3 position1 : POSITION, float2 uv : TEXCOORD0, float3 position2 : TEXCOORD1, out float4 oPosition : POSITION, uniform float4x4 worldViewProjMatrix, uniform float animationPhase ) { float3 blendedPosition = lerp(position1, position2, animationPhase); oPosition = mul(worldViewProjMatrix, float4(blendedPosition, 1)); }
注意事项:
position2是放到TEXCOORD1的位置,如果你自己本身有N个纹理坐标,那么position的位置会被放到末尾,即TEXCOORDN+1
原文链接:http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Morph+animation
相关文章推荐
- how to get the space size of some tables in one database?
- How to get files to show up in the Process Monitor/Report Repository
- How to Get the Function Code in R
- How to get the handle in windows using python
- 在Bean(java类)中如何取到jspx中Bindings的数据?How to get the ADF BindingContainer in a managed bean?
- How to get the mapping relationship between two columns in a table
- How to get and set the system socket buffer in AIX?
- flex/in the datagrid,how to get the new value of cell in the datagrid after edit
- string - How to get the filename without the extension from a path in Python? - Stack Overflow
- [RxJS] How To get the results of two HTTP requests made in sequence
- [eZ publish] When a ezxml embed an video, how to get the ezxml object in the video embed template?
- How to get the number of pages in a Word Document
- How to get the date N days ago in Python
- How to Get the Length of File in C
- I was eager to get my paddles wet and see how this kayak performed in the water.
- How to get a type in C++ when its template argument is the argument
- How to get IOleSite interface of the WebBrowser in an ActiveX control
- How to change the Push and Pop animations in a navigation based app
- How to get the url of a page in OpenERP?
- iOS Programming 101: How To Get the User Location in iPhone App