Anim in Code and XML
by Sean T. Boyette · in Torque X 2D · 08/14/2008 (10:03 pm) · 9 replies
Hey guys,
I am learning up on tx a bit - still wondering about the Skinned models (if anyone knows)
but anyways..
can someone give me a bit more guidance on how to load a anim on a model..
the following was provided by John for loading the robot model in code, he also provided the xml as well:
Thanks guys!
Sean
I am learning up on tx a bit - still wondering about the Skinned models (if anyone knows)
but anyways..
can someone give me a bit more guidance on how to load a anim on a model..
the following was provided by John for loading the robot model in code, he also provided the xml as well:
//create the simple torque object
TorqueObject objPlayer = new TorqueObject();
objPlayer.Name = "CurrentPlayer";
//create the render component
T3DTSRenderComponent componentRender = new T3DTSRenderComponent();
componentRender.ShapeName = @"data\Models\robot\blue_player.dts";
//create the scene component
T3DSceneComponent componentScene = new T3DSceneComponent();
componentScene.Position = new Vector3(1024, 1024, 295);
//add both of the components
objPlayer.Components.AddComponent(componentRender);
objPlayer.Components.AddComponent(componentScene);
//register the object
TorqueObjectDatabase.Instance.Register(objPlayer);
[code]
I want to play just the idle animation and have written this portion in code -
what am I missing -if anyone has the xml for just the idle that would be good as well!
[code]
//Animation
TSAnimation idleAnim = new TSAnimation();
idleAnim.ThreadName = "ActionThread";
idleAnim.SequenceName = "root";
idleAnim.Name = "Idle";
AnimationFSM anims = new AnimationFSM();
anims.StartState = "Idle";
T3DAnimationComponent componentAnimation = new T3DAnimationComponent();
componentAnimation.SceneGroupName = "CurrentPlayer";
componentAnimation.AddAnimation(anims);
objPlayer.Components.AddComponent(componentAnimation);Thanks guys!
Sean
About the author
#2
I have not gotten it to work yet though. Here is his whole post:
Jeff,
Yes. I've thoroughly tested all the skinned DTS models that comes with the TGE demo and they all display fine. If you are planning on using actual skinned meshes and not just separate meshes linked directly to a bones or biped hierarchy then you will need to edit the code I've listed above and add that one line to check for the NodeIndex being -1. Also, getting the model to display isn't a problem, but getting the animation stuff to play has caused me some consternation.
I have been unable to load up the animation in direct code and get it to play (despite the code compiling and tracing through fine). Currently it seems that loading models with animation only work via entering xml into your txscene, as the deserializer seems to have some mystery init code that I have been unable to locate to perform manually in code. For sanity sake, just go to the FPS demo's level's and grab the player object section. To display the model and have a test animation work, you can use the following xml (I put mine in the objects section right after the terrain object that the 3d startergame puts in by default:
Obviously you will want to change the dts model name to you model name, and put the proper sequence name of your test animation in the SequenceName section (if you like me embedded the the sequence into the DTS model). If you exported your sequence into a separate DSQ file, you will omit the SequenceName section and instead use the SequenceFilename section to point to your DSQ, (it needs to be in the same directory as your DTS and you'll need to use the standard Torque file stuff to point to it: @"data\shapes\TestModel.dsq")
Hope that helps you.
08/29/2008 (6:32 am)
I saw a thread in the torque private forums, where Patrick Chambers said the below xml structure will work, without a FSM :<AnimationComponent type="GarageGames.Torque.T3D.T3DAnimationComponent">
<SceneGroupName>PlayerMesh</SceneGroupName>
<Animations>
<Animation type="GarageGames.Torque.T3D.TSAnimation">
<ThreadName>ActionThread</ThreadName>
<SequenceFilename>data\Skeleton\testanim.dsq</SequenceFilename>
<Name>Rotate</Name>
<TimeScale>1.0</TimeScale>
</Animation>
</Animations>
</AnimationComponent>I have not gotten it to work yet though. Here is his whole post:
Jeff,
Yes. I've thoroughly tested all the skinned DTS models that comes with the TGE demo and they all display fine. If you are planning on using actual skinned meshes and not just separate meshes linked directly to a bones or biped hierarchy then you will need to edit the code I've listed above and add that one line to check for the NodeIndex being -1. Also, getting the model to display isn't a problem, but getting the animation stuff to play has caused me some consternation.
I have been unable to load up the animation in direct code and get it to play (despite the code compiling and tracing through fine). Currently it seems that loading models with animation only work via entering xml into your txscene, as the deserializer seems to have some mystery init code that I have been unable to locate to perform manually in code. For sanity sake, just go to the FPS demo's level's and grab the player object section. To display the model and have a test animation work, you can use the following xml (I put mine in the objects section right after the terrain object that the 3d startergame puts in by default:
<Player type="GarageGames.Torque.Core.TorqueObject" name="Player">
<Components>
<AnimationComponent type="GarageGames.Torque.T3D.T3DAnimationComponent">
<SceneGroupName>PlayerMesh</SceneGroupName>
<Animations>
<Animation type="GarageGames.Torque.T3D.TSAnimation">
<ThreadName>ActionThread</ThreadName>
<SequenceName>test</SequenceName>
<Name>TestAnimation</Name>
</Animation>
</Animations>
</AnimationComponent>
<RenderComponent type="GarageGames.Torque.T3D.T3DTSRenderComponent">
<SceneGroupName>PlayerMesh</SceneGroupName>
<ShapeName>data\shapes\TestModel.dts</ShapeName>
</RenderComponent>
<SceneComponent type="GarageGames.Torque.T3D.T3DSceneComponent">
<SceneGroup>PlayerMesh</SceneGroup>
<Position>
<X>1024</X>
<Y>1024</Y>
<Z>300</Z>
</Position>
</SceneComponent>
</Components>
</Player>Obviously you will want to change the dts model name to you model name, and put the proper sequence name of your test animation in the SequenceName section (if you like me embedded the the sequence into the DTS model). If you exported your sequence into a separate DSQ file, you will omit the SequenceName section and instead use the SequenceFilename section to point to your DSQ, (it needs to be in the same directory as your DTS and you'll need to use the standard Torque file stuff to point to it: @"data\shapes\TestModel.dsq")
Hope that helps you.
#3
This seems to advance the animation. Originally, it was just showing the first frame, and that was it. I found this out when I tested the boombot dts, and was testing the run animation. So it would appear that the T3DTSRenderComponent has to have an updateanimation call in order for the animation to play through fully. I had this in my xml to load the animation:
09/01/2008 (8:05 pm)
Ok, I figured it out. I had to add this to my player component:public void ProcessTick(Move move, float dt)
{
if (move != null)
{
_renderComponent.UpdateAnimation(dt);
}
}This seems to advance the animation. Originally, it was just showing the first frame, and that was it. I found this out when I tested the boombot dts, and was testing the run animation. So it would appear that the T3DTSRenderComponent has to have an updateanimation call in order for the animation to play through fully. I had this in my xml to load the animation:
<AnimationComponent type="GarageGames.Torque.T3D.T3DAnimationComponent">
<SceneGroupName>PlayerMesh</SceneGroupName>
<Animations>
<Animation type="GarageGames.Torque.T3D.TSAnimation">
<ThreadName>ActionThread</ThreadName>
<SequenceFilename>data\Skeleton\test1.dsq</SequenceFilename>
<Name>Rotate</Name>
</Animation>
</Animations>
</AnimationComponent>
#5
Would it be possible for you to post your player component?
I am trying to get an animation to play, and am getting lost:
for simplistic sake, I currently have the following being called from StartGame - and it does appear as though it just plays the first frame.
11/01/2008 (9:48 pm)
David - Would it be possible for you to post your player component?
I am trying to get an animation to play, and am getting lost:
for simplistic sake, I currently have the following being called from StartGame - and it does appear as though it just plays the first frame.
//find the physics resolver
RigidCollisionManager rigidManager = TorqueObjectDatabase.
Instance.FindObject<RigidCollisionManager>("RigidManager");
//get the Player object type
TorqueObject DTSPlayer = new TorqueObject();
DTSPlayer.Name = "newDTS";
//add the scene component
T3DSceneComponent componentScene = new T3DSceneComponent();
componentScene.SceneGroup = "newDTS";
componentScene.Position = new Vector3(1034, 1036, 257);
DTSPlayer.Components.AddComponent(componentScene);
//AddDTS the RenderComponent
T3DTSRenderComponent componentRender = new T3DTSRenderComponent();
componentRender.ShapeName = @"data\shapes\Robot_Black\Robot_black.dts";
componentRender.SceneGroupName = "newDTS";
DTSPlayer.Components.AddComponent(componentRender);
//add the animation component
T3DAnimationComponent componentAnimation = new T3DAnimationComponent();
componentAnimation.SceneGroupName = "newDTS";
DTSPlayer.Components.AddComponent(componentAnimation);
TorqueObjectDatabase.Instance.Register(DTSPlayer);
//add the animations
DTSPlayer = TorqueObjectDatabase.Instance.FindObject<TorqueObject>("newDTS");
componentAnimation = DTSPlayer.Components.FindComponent<T3DAnimationComponent>();
TSAnimation animationIdle = new TSAnimation();
animationIdle.ThreadName = "ActionThread";
animationIdle.SequenceName = "idle";
animationIdle.SequenceFilename = @"data\shapes\Animations\Robot_Idle.dsq";
animationIdle.Name = "Idle";
componentAnimation.AddAnimation(animationIdle);
animationIdle.Play();
#6
I used an actual class, defined as such, some parts are left out:
If you are creating your player on the fly without a defined class (it looks like you are), I am thinking you could add in the draw function in the game.cs an update to the players rendercomponents UpdateAnimation call. I just created a player class that inherits from TorqueObject and implements IprocessTick. That way I can manage my player object, but still hook into the process tick peice.
11/07/2008 (9:52 pm)
Hi Sean, I used an actual class, defined as such, some parts are left out:
namespace StarterGame3D
{
public class PlayerComponent : TorqueObject, ITickObject
{
private T3DTSRenderComponent _renderComponent;
public override bool OnRegister()
{
if (!base.OnRegister())
return false;
_renderComponent = this.Components.FindComponent<T3DTSRenderComponent>();
_rigidComponent.CollidesWith = TorqueObjectDatabase.Instance.GetObjectType("Terrain");
ProcessList.Instance.AddTickCallback(this);
return true;
}
public void ProcessTick(Move move, float dt)
{
_isometricCameraComponent.Update();
if (move != null)
{
Vector3 velocity = _rigidComponent.Velocity;
// set our test object's Velocity based on stick/keyboard input
velocity.X = move.Sticks[0].X * 40.0f;
velocity.Y = move.Sticks[0].Y * 40.0f;
_rigidComponent.Velocity = velocity;
_renderComponent.UpdateAnimation(dt);
}
}
.....If you are creating your player on the fly without a defined class (it looks like you are), I am thinking you could add in the draw function in the game.cs an update to the players rendercomponents UpdateAnimation call. I just created a player class that inherits from TorqueObject and implements IprocessTick. That way I can manage my player object, but still hook into the process tick peice.
#8
11/16/2008 (12:29 pm)
Hehe, yah, your right, ITickObject :P Darn those tangents of thought :)
#9
Email me or post back with a link if you could james@teamelitetopeka.org
11/05/2009 (11:29 pm)
Does anyone have a working project of how to get an animation to render? Please i've been trying to get this to work now for some time.Email me or post back with a link if you could james@teamelitetopeka.org
Torque Owner David Everhart
<AnimationComponent type="GarageGames.Torque.T3D.T3DAnimationComponent"> <SceneGroupName>PlayerMesh</SceneGroupName> <Animations> <Animation type="GarageGames.Torque.T3D.AnimationFSM"> <StartState>Rotate</StartState> <Name>test</Name> <AnimationStates> <AnimationState> <StateType>StarterGame3D.RotateAnimationState</StateType> <Animation type="GarageGames.Torque.T3D.TSAnimation"> <ThreadName>ActionThread</ThreadName> <SequenceFilename>data\Skeleton\testanim.dsq</SequenceFilename> <SequenceName>test</SequenceName> <Name>Rotate</Name> </Animation> </AnimationState> </AnimationStates> </Animation> </Animations> </AnimationComponent>I then tried this in begin run:
T3DAnimationComponent test = player.Components.FindComponent<T3DAnimationComponent>(); Animation animation = test.GetAnimation("test"); animation.Play();No go so far. :(