DTS/Blender/Creating a Simple Wheeled Vehicle

From TDN

You can get a working example of a wheeled vehicle in Blender, by Scott Coursey, here:

http://www.blendedpixels.com/torque/index.html

Links:
Brake Lights: http://tdn.garagegames.com/wiki/DTS/Blender/Creating_a_Simple_Wheeled_Vehicle/BrakeLights
Another example car: http://tdn.garagegames.com/wiki/Image:AnimCar.zip

[edit] Following by Duncan Gray.
An example vehicle wheel with LOD's http://tdn.garagegames.com/wiki/Image:TGE_viperWheel.blend

With Blender it's also possible to create break lights which work with the default engine code. Indicator animations are possible but may requires minor wheeledvehicle class changes.

Image:Driving_normal.jpg Image:Driving_braking.jpg Image:Driving_indicating.jpg

A quick explanation of the basic vehicle. You need to add an armature and some bones, named according to the nodes required by your vehicle.

IMPORTANT: Always be in TOP view when adding an armature or the orientation of your nodes will be incorrect when exported to TGE. It's most noticeable when going into 1st person view. If the camera is sideways or upside down then the above is the most likely cause.

Image:DV1.jpg

The picture above shows the bones laid out in a logical manner for the vehicle. I have not added a mass node as it is not essential. The engine will use the center of the bounds box in the absence of a mass node.

[edit] By Cory Anderson:
Be sure that your mesh and armatures are centered around the Blender environment, or their origins will be exported wrong. If your wheels seem misaligned, or orbit around the axis rather than rotate around it, this is probably the case.

The bones required are:

hub0,hub1,hub2,hub3 etc to suite the amount of wheels on your vehicle.
eye, cam are the node used by the 1st and 3rd person camera.

The next picture shows the Blender Outliner with the setup I used for this vehicle. (Click the "View Outliner" option).

Image:DV2.jpg

The exporter ignores ALL items which are not a child of the Shape empty, with the one exception being the Bounds object which must not be placed within the Shape tree.

This means that the camera and all the other empty's I added will safely be ignored by the exporter. I added EmptyCenter in the center of the mesh as it is sometimes usefull to refer to a fixed location when mirroring mesh parts etc. The center of the object data is a moving target because it chanages as your mesh changes.

I also added, for my own sanity, emptys at the locations of the wheel hubs. When editing bones you can sometimes make mistakes and shift them by accident. It is then usefull to have those empties so that you can select them, snap the 3d cursor to it's location, select the offending bone and snap it to the 3d cursor location, thereby restoring its position.

Ok, so all the exporter requires is the data in the Shape tree. Fot this tutorial I only added one Detail level named Detail32. (They don't need to be a power of two) The detail number corresponds to the verticle pixel size at which the engine will jump to the next level of detail in your model. You can make the detail numbers anything you want as long as you understand how they affect the LOD selection process.

Within the Detail32 tree, you will see that I have two armatures and a mesh. I have expanded the second armature so that you can see the bones it contains. Those bones do not deform any mesh vertex groups therefore it was not necessary to make the mesh a child of this armature.

Next lets look at doing a spring animation.

Image:DV3.jpg

The above picture shows the armature in Pose mode with the hub0 bone selected (shown in blue)
The hub is positioned at the location of "TOP of spring travel" or put another way, the place where the center of the wheel will be when the spring is full compressed.

Create a key in frame one for this bone. (have the cursor in the top window, press i then select the location option)

Image:DV4.jpg

Next move the frame counter to position 2. Move the bone down (press gz) to the position of "BOTTOM of spring travel. Also known as spring fully extended. Now create a key for this bone as above.

Name the action spring0. Compare the above two pictures and note the differences

Do the same for the other hubs and name those actions spring1, spring2 etc

This vehicle does not need a steering sequence. The game-engine will automatically steer the wheels at the hub location. You specify which wheels to steer in the onADD method of the vehicle. (Done in script) Check the script for the buggy in the starter.racing example.

Some vehicles, such as motorcycles, will have moving parts (handle bars) which need to be animated to show the vehicle steering. To create a steering action you will need to add bones (names don't matter) and make the corresponding mesh a child of the armature so that it's vertices get affected by the bone movements.

When ready, create a new action named steering and create keys in 3 frames so that:
frame 1 shows the mesh in "full right" position.
frame 2 shows the mesh in "straight" position.
frame 3 shows the mesh in "full left" position.


Image:DV5.jpg

The above vehicle was a lot more complex as the it required mesh movement for both steering and spring animations. Depending on your game requirements, it's not always necessary to animate mesh in this manner.

Brake Lights

I made a 4 polly mesh which covers each of the brake lights. This mesh is animated so that it is hidden in the vehicle mesh on frame 1 and is popped out over the brake lights on frame 2. Name this animation brakelight and it will work with the default game-engine code.
The material of the cover mesh was given some self illumination for the glow effect.

Indicators

Again this is just an animation of a cover meash which hides and unhides the relevant indicator. There is no default engine code for this so you will need to create some code changes or use script commands to activate the animations.

http://tdn.garagegames.com/wiki/BlendPlayerMesh.zip