Jump to content

Move bones while animation


ParaToxic
 Share

Recommended Posts

Hey ya, I would like to ask if it is possible to rotate a bone of a animated mesh white the animation.

I have positioned and rotated my camera to the Head bone of a character and wants to rotate it while the running/idle animation ... but I doesn't work, I can only do that when the character isn't animated ( so without the Animate() function ).

 

Can somebody help me ?

Thanks

Link to comment
Share on other sites

The first thing I would do is make sure FindChild is getting the right bone. Just make a small example program where you aren't animating the entire thing, and just mess around with that bone to make sure you visually see the results.

 

Also, I think there is a tutorial about this. The animating one.

Link to comment
Share on other sites

Look at that.I tried with the soldier mesh and the animation sequences:

#include "engine.h"
#include <iostream>
#include <string>
const int  ScreenWidth = 800;
const int  ScreenHeight = 600;
const char* MediaDir =  "D:/Leadwerks Engine SDK 2.5 V2";
const char* AppTitle = "Anim";
void ErrOut( const std::string& message ) { std::cerr << message << std::endl; }
// -------------------------------
int main( int argn, char* argv[] )
{
// Initialize
if( !Initialize() )
 return 1;	   
SetAppTitle( AppTitle ) ;
RegisterAbstractPath( MediaDir );

// Set graphics mode	   
if( !Graphics(ScreenWidth,ScreenHeight) )
{			   
 ErrOut( "Failed to set graphics mode."  );
 return 1;	   
}

// Create framework object and set it to a global object so other scripts can access it
TFramework fw = CreateFramework();	   
if( fw == NULL )	   
{
 ErrOut( "Failed to initialize engine." );			   
 return 1;	   
}	   

// Set Lua framework object	   
SetGlobalObject( "fw", fw );			   

// Set Lua framework variable	   
BP lua = GetLuaState();	   
lua_pushobject( lua, fw );	   
lua_setglobal( lua, "fw" );	   
lua_pop( lua, 1 );	   

// Get framework main camera	   
TCamera camera = GetLayerCamera( GetFrameworkLayer(0) );	   
PositionEntity( camera, Vec3(0,2,-2) );	   

// Create cube
TMaterial material = LoadMaterial( "abstract::cobblestones.mat" );	   

TEntity mesh = LoadMesh("abstract::soldier.gmf");
int seq = LoadAnimation(mesh,"abstract::animidle.gmf");
TEntity child = FindChild(mesh,"Bip01 Head");
SetBloom(1);
SetHDR(1);
SetSSAO(1);
// Create ground
TMesh ground = CreateCube();	   
ScaleEntity( ground, Vec3(10,1,10) );	   
PositionEntity( ground, Vec3(0,-2,0) );	   
PaintEntity( ground, material );	   

// Add some light
TLight light = CreateDirectionalLight();	   
RotateEntity( light, Vec3(45,45,45) );	   

// Spin cube until user hits Escape
while( !KeyHit() && !AppTerminate() )	   
{			   
 if( !AppSuspended() )
 {

  Animate(mesh,AppTime()/70.0,1.0,seq);
  if(KeyDown(KEY_UP)) TurnEntity(child,Vec3(1,0,0));
  UpdateFramework();			   
  RenderFramework();			

  Flip( 0 );	   
 }
}			   

return Terminate();
}

Link to comment
Share on other sites

Im sorry, i can't send you my project because it has some unnecessary stuff for your problem in it (gamestate, world, some prototype ai management etc).

 

I did the following (pseudo code)

// Loading
LEO::Mesh* dragon = new LEO::Mesh("abstract::dragon.gmf"); // its from 3d foin
LEO::Entity* dragonhead = new LEO::Entity(dragon->findChild("Bip01_Head"));

// Update
dragon->Animate(frame, 1, 0);
dragonhead->SetRotation(Vec3(0, -90, 0));

 

I dont use LoadAnimation, maybe it causes problems ?

Link to comment
Share on other sites

Thanks I git it now :D Well the TurnEntity function doesn't work here, the result is the same as with 'RotateEntity, so the TurnEntity(...Vec3(1,0,0)) causes only a 1 degrees rotation and not 1 degrees per frame.

When I call first the animate function an then the rotateentity function it works well....so thanks :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...