Using 3D shape animations in T2D
by Ben Shive · in Torque Game Builder · 03/10/2006 (11:51 am) · 6 replies
I've been following the TDN article (http://tdn.garagegames.com/wiki/Torque_2D/T2D_3DShapes) on using 3D models in T2D, but I've been having problems. I can get the models loaded just fine exporting the objects from Blender, but I've been having problems with the animation. Either the article is missing something simple and important, or I am!
Running the game when calling the following code makes all the animations play. I can't selectively execute one of them. Even without the playAnimation line, they all play as if they were the idle animation. Nothing I've done so far has changed that. Hopefully someone can spot what I'm doing wrong here.
datablock TSShapeConstructor(testDTS)
{
baseShape = "./../data/models/3action.dts";
sequence0 = "./../data/models/IdleShape.dsq idle";
sequence1 = "./../data/models/CubeMove.dsq cube";
sequence2 = "./../data/models/TriMove.dsq triangle";
sequence3 = "./../data/models/CylMove.dsq circle";
};
function displayDTS() {
%shape = new t2dShape3D() { scenegraph = t2dScene; };
%shape.setShape("./../data/models/3action.dts");
%shape.setPosition( "5 5" );
%shape.setShapeRotation( "45 45 0" );
%shape.setSize( 50 );
%shape.setShapeScale( 0.3 );
%shape.playAnimation( cube );
}
Running the game when calling the following code makes all the animations play. I can't selectively execute one of them. Even without the playAnimation line, they all play as if they were the idle animation. Nothing I've done so far has changed that. Hopefully someone can spot what I'm doing wrong here.
datablock TSShapeConstructor(testDTS)
{
baseShape = "./../data/models/3action.dts";
sequence0 = "./../data/models/IdleShape.dsq idle";
sequence1 = "./../data/models/CubeMove.dsq cube";
sequence2 = "./../data/models/TriMove.dsq triangle";
sequence3 = "./../data/models/CylMove.dsq circle";
};
function displayDTS() {
%shape = new t2dShape3D() { scenegraph = t2dScene; };
%shape.setShape("./../data/models/3action.dts");
%shape.setPosition( "5 5" );
%shape.setShapeRotation( "45 45 0" );
%shape.setSize( 50 );
%shape.setShapeScale( 0.3 );
%shape.playAnimation( cube );
}
#2
1) Yes, they're all exported as DSQ's. I did have this wrong at first and then exported all of them.
2) They are in the same directory, and I'm not getting any warnings.
3) All of the animations are playing at the same time. To test the process I had made a simple block with 3 shapes, each with an individual animation to move the shape up and down. All three shapes move when the model is loaded.
I'm glad it is that easy! I'm pretty sure there's just something simple being missed here since I was able to get the model in without any problems. Do you have a complete sample code fragment that shows the datablock and code used to execute the model animation?
03/11/2006 (5:28 pm)
From the article, I want to trigger animations from Torque Script so I do need separate DSQ's.1) Yes, they're all exported as DSQ's. I did have this wrong at first and then exported all of them.
2) They are in the same directory, and I'm not getting any warnings.
3) All of the animations are playing at the same time. To test the process I had made a simple block with 3 shapes, each with an individual animation to move the shape up and down. All three shapes move when the model is loaded.
I'm glad it is that easy! I'm pretty sure there's just something simple being missed here since I was able to get the model in without any problems. Do you have a complete sample code fragment that shows the datablock and code used to execute the model animation?
#3
Which gets called by:
spawnEnemy(Alien, "-55, 230", Alien1);
to spawn the enemy alien.
03/12/2006 (1:54 am)
new t2dShape3D(Alien)
{
collisionCallback = "1";
collisionPolyList = "-1.00 -1.00 1.00 -1.00 1.00 1.00 -1.00 1.00";
collisionCircleScale = "1";
collisionPolyScale = "1 1";
collisionCircleSuperscribed = "1";
shapeFileName = "~/data/images/3dalien/alien.dts";
skinName = "player";
// skinName = "0";
};function spawnEnemy(%type, %pos, %name)
{
%obj = new t2dShape3D(%name)
{
sceneGraph = t2dScene;
};
echo("ShapeFile should be: (" @ %type.shapeFileName @ ")");
%obj.setShape(%type.shapeFileName);
%obj.setShapeScale( 1,1.2,1 );
%obj.setSize( 20,40 );
%obj.setCollisionActive(true, true);
%obj.setCollisionPhysics(true, true);
%obj.setCollisionDetection(POLYGON);
%obj.setCollisionResponse(CLAMP);
%obj.setCollisionGroups( $playerGroup SPC $playerProjectileGroup );
%obj.setCollisionCallback(true);
%obj.setCollisionMaxIterations(2);
%obj.setLayer($enemyLayer);
%obj.setGraphGroup($enemyGroup);
%obj.setPosition(%pos);
%obj.PlayAnimation( root );
%obj.setShapeRotation("0 180 0");
// %obj.setShapeAngularVelocity("0 90 0");
%obj.setDetailLevel(0);
%obj.setDebugOn(5);
}Which gets called by:
spawnEnemy(Alien, "-55, 230", Alien1);
to spawn the enemy alien.
#4
03/21/2006 (7:17 am)
Thanks Steven, I got back to this after getting swamped at my 'other' job. I'm looking at the source and I don't see where you refer to the DSQ's? For example, I can see that %obj.PlayAnimation( root ); will play the DSQ associated with 'root', but I don't see where that's defined.
#5
03/23/2006 (1:33 pm)
I tested this today using the pre-made model:function gameArms::createModel (%this)
{
if (! isObject (mdlSoldier)) datablock TSShapeConstructor (mdlSoldier)
{
baseShape = "./models/soldier/reinstatedsoldier.dts";
sequence0 = "./models/soldier/reinstatedsoldier-idle.dsq idle";
sequence1 = "./models/soldier/reinstatedsoldier-move.dsq move";
sequence2 = "./models/soldier/reinstatedsoldier-attack.dsq attack";
sequence3 = "./models/soldier/reinstatedsoldier-react.dsq react";
sequence4 = "./models/soldier/reinstatedsoldier-death.dsq death";
};
%this.model = new t2dShape3D () { scenegraph = t2dSceneGame; };
%this.model.setShape ("./models/soldier/reinstatedsoldier.dts");
%this.model.playAnimation ("move");
%this.model.setPosition ($ge_player.getPositionX () + 25, $ge_player.getPositionY () - 25);
}this code spawns a 3D model near my player [$ge_player]
#6
03/24/2006 (3:14 am)
Thanks everyone, got this all worked out finally! Just need to figure out what I did wrong with my initial model export.
Torque 3D Owner Stephen Zepp
Can you confirm a couple of things:
1) You did in fact export the animations separately, and there are no animations exported directly into the .dts shape from Blender? ( I think this is the default way the exporter works by the way, hence the reason I'm asking).
2) Do you have the .dsq files in the same directory as your base shape, and are they loading successfully (check console.log for warnings).
3) Could you describe a bit more in detail what you see on screen--are all of the animations playing simultaneously, one after the other, or something different?
I know that properly executed (not meant as an insult!), animation loading and playing does work for t2dShape3d---for the recent TGB Boot Camp I brought over the "blue guy" from TGE's tutorial.base intact, and was able to selectively play any of the animations...I even grabbed a couple of Fluffy's (the Torque Orc) animations and added them in with no issues.