Exporting from blender to torque

If you are using the lab machines they are set up to do exports. If you are using your own machine and you downloaded Blender, you also need to download and install the exporter. You can get it here: Blender To Torque Exporter

Note, if you have not gotten blender yet (It is FREE, you should), it is downloadable from: Blender Download Site

We will first just create a simple cone in blender, export it to a DTS file, and then put it in the right place in the Torque directory structure to be able to include it in a game. Note, this first cone will NOT be textured, so it will just be an ugly grey in the torque game.

Using the exporter to create the DTS file

The following excellent tutorial explains the entire process:

Blender to DTS Tutorial

I can not improve on this tutorial, but I will summarize the steps:

  1. Create the model you want. Make sure it is one mesh.

  2. Scale the model to be about 2.5 units in largest dimension to make it about the size of a blue-guy player object. Scale bigger/smaller if you want it bigger/smaller than the blueguy.

  3. Make sure you are in FRONT VIEW and in Object Mode, then, add three nodes (empties) in a triangle pattern. Name them:
    center top: "Shape"
    left lower: "Detail32"
    right lower: "Collision0"

  4. Add a collision mesh for the shape (so you can detect collisions): Go to front view in wireframe mode. Create a cube and make it just larger than the object so it obscure your object in all three views. It is easiest to keep it a cube, but you can go through the 3 dimensions and more tightly bound the object. If the cube is too big you will get "false collisions".

  5. Link nodes and meshes:

    1. right-click model mesh, then shift-right-click detail32 node. Now hight CTRL+p to link.

    2. right-click detail32 node, then shift-right-click shape node. Now hight CTRL+p to link.

    3. right-click collision mesh, then shift-right-click col0 node. Now hight CTRL+p to link.

    4. right-click col0 node, then shift-right-click shape node. Now hight CTRL+p to link.

  6. Export:

    File->export->Torque Shape

    Go to general, and select the "Write Shape Script" and "Write TSE Materials" buttons. Click export

You should now have a DTS file ready to be put in Torque.

Putting your DTS file into your Torque game

Adding your DTS file to Torque is accomplished as follows. Lets assume the new model is called "cylinder.dts" and you are adding the new model into a game whose code directory is "~/.../GameTestModel". Do the following:
  1. cd ~/.../GameTestModel
  2. cd data/shapes
  3. mkdir cylinder
  4. cp cylinder.dts and cylinder.blend into the directory cylinder. Note, the .blend file is not needed, but it is nice to have for when you decide you want to modify the item.
  5. cd ~/...GameTestModel/server
  6. cp logoitem.cs cylinderitem.cs
  7. Edit cylinderitem.cs as follows: a) change TorqueLogoItem to CylinderItem; and b) change shapeFile path to: ~/data/shapes/cylinder/cylinder.dts
  8. Modify game.cs to add the following line to the onSeverCreate() method:

    exec("./cylinder.cs") ;

Make sure that in the game.cs file just about the ~/...GameTestModel directory that you reset the $defaultGame variable to be "GameTestModel". Now start up torque. You should be able to go into Window->World Editor Creator and then in the bottom right panel open up Shapes/Items and see your ClinderItem and click on it to add. If you want to check out why you created the collision mesh, just add a call to onCollision. For example, to delete the cylinder object when the player runs into them, here is the contents of my cylinder.cs file:

datablock StaticShapeData(CylinderItem)
{
    category = "Items";
    shapeFile = "~/data/shapes/cylinder/cylinder.dts";
};

function CylinderItem::onCollision(%this, %obj, %col)
{
    if(%col.getClassName() $= "Player")
    {
        %obj.delete();
    }
}

Also, rather than place them by hand, you can place them using code with something like the following. The tricky part is getting the Z-coordinate correct!


//-----------------------------------------------------------------------------
// Add dropCylinders and spawnClylinder to the AIManager static functions
//-----------------------------------------------------------------------------

function AIManager::dropCylinders( %this )
{
	echo("\n\nInside AIMangager::dropCylinders\n\n") ;
    for (%i = 0 ; %i < 9 ; %i++) 
        %temp = %this.spawnCylinder( i );

    echo ("\n\n Called AIManager::startBots\n\n") ;
}

function AIManager::spawnCylinder( %this , %name )
// %name is an integer, the number of the NPC
{
	%offset = getRandom(-10,10) SPC getRandom(-10,10) SPC 0 ;
	// %sp1 = pickSpawnPoint() ;
	%sp1 = "25 -410 65 1 0 0 0" ;

	// %theSpawnPoint = VectorAdd(pickSpawnPoint(), %offset) ;
	%theSpawnPoint = VectorAdd(%sp1, %offset) ;

	%cyl = new StaticShape()
	{
		dataBlock = CylinderItem;
		mass = 10 ;
	};

	MissionCleanup.add( %cyl );
	%cyl.setName( %name );
	%cyl.setTransform( %theSpawnPoint );


    return %cyl;
}

Only problem is it is an ugly grey, now cool colors/textures, to get those you need to learn how to texture and export with the texture.

Texturing in blender and exporting to Torque

Blender Texturing

Again, I can not improve on this tutorial, but I will summarize the steps:

  1. Make a texture (512x512, save as png or jpg). A person could spend tons of time creating textures, just to make it easy some simple textures can be found in HERE
  2. Make the model you want, with a collision mesh. Then move the collision mesh aside to focus on the object you want to texture.
  3. Make sure all normals are pointing out (go into the UV Face Select mode and make sure all faces are white).
  4. Mark the seams (inside edit mode, select the edges of a seam, then hit CTRL+E)
  5. Split the screen
  6. In the right screen set mode to UV image mode, in Left UF face select mode
  7. in left, hit A to select all, then U to unwrap
  8. Save the uv layout (uv window: UVs->script->save)
  9. Copy the texture you want into the same directory
  10. Insider the uv window, Image->open and select the image
  11. Save the uv layout again
  12. make sure 3D window is in object mode and the lower window is in button mode.
  13. make sure in shading mode (F5)
  14. in the "links and pipeline" panel click "add new"
  15. now in the links and pipeline panel that pops up, change material to "blueGlass" or whatever the name of your material is, leaving off the .png or .jpg
  16. now bring up the textures panel (f6)
  17. click "add new" under texture
  18. change texture type to "image"
  19. Go back into the 3D view window in object mode. Move the collision cube back over the model. If you did not create a collision mesh and the links with the three "empty" objects in a triangle as before, do so now.
  20. now save the .blend file
  21. Export the file. Note, you will likely have to resize the lower window to find the export button (make the lower window larger by grabbing the top of the window and moving it up).

The export will create a .dts and and .log file. Check out the .log file. The .log file should mention two objects: both the one you textured and the collision cube. Also, a material should be mentioned. Here is a sample log file:

Torque Exporter 0.94 
 Using blender, version 243
 Loaded Preferences.
 Processing Scene...
 Cleaning Preference Keys
 Exporting...
 Writing shape to  '/Users/scottleutenegger/Awork/teach/3821/Blender/simple2\texturedCone.dts'.
 Processing...
 > Shape Details
    > Nodes
      ^^ Bone [Exp-Catch-Root] (parent -1)
    > Objects
     'Cone' : Standard 
     'Cube' : Null Standard 
    > Materials
       yellowGrass
    > Detail Levels
       Detail-1 (size : 32)
       Collision-1 (size : -1)
       Smallest : Detail-1 (size : 32)
    > Internal Sequences
 Writing out DTS...
 Done.
 Finished.
 

You have created the files you need but unless you have "showtool" you can not see the textured model. Again you need to put the file into Torque. This is pretty much the same as before, but this time you also need to put the texture file in the directory as well as the .dts file. Try it, go into world creator, and create some textured objects in your game.