Creating collision models

From FreeAllegiance Wiki
Revision as of 01:54, 16 May 2010 by Compellor (talk | contribs) (Headings)
Jump to navigationJump to search

Collision models for allegiance are stored in CVH files, which can be created with AMT or with the original artwork tools.

The original artwork tools can be downloaded here. You will need 7-Zip.

Tutorial

First, you will need to create a collection of convex hulls which make up your collision model. Try not to use more polygons than necessary, but also consider what the model will be used for. Something as small as a power-up just needs a box, fighters should have a silhouette similar to that of the visible model (erring on the side of invisible walls rather than being able to shoot right through the ship), and bases should only have invisible walls in places where that would prevent a fighter from getting stuck, such as over the entrance to a launch bay. Avoid intersecting meshes, as they have been known to cause problems. Finally, be absolutely sure that all of your meshes are in fact convex hulls.

[1]

I am using trueSpace 7.6, a free program you can download here. Other programs could be used, but I will demonstrate the use of trueSpace in this tutorial. If you want to export from Milkshape to trueSpace, you can do so as DirectX *.x.

Start with this scene file if you want to follow the tutorial directly. You must group all of your meshes as siblings. Before you go any farther, make sure that your mesh is at the same coordinates as the visible mesh in Milkshape: determine the coordinates of a given vertex in Milkshape by selecting it and clicking Tools>Model Information, then select the same vertex in trueSpace. Right-click the "object tool" button in the tool bar to bring up the object info pane, containing the location coordinates. Be sure to backup the object or scene file containing your model.

[2]

It may be necessary (assume it is) to select this group in the scene editor, set the animation frame to 1, set the record options to move, rotate, and scale, then press the record button. trueSpace's animation code is finicky: if you save your model after this, you may find yourself needing to restore from backup and redo the animation, and for some models the animation step isn't even necessary (no way to tell until you're finished converting to CVH). If you later discover that something went wrong with your CVH, this is a step where it could easily go wrong.

Select the group, and Save>Object. Save as type: DirectX *.x, Ascii Text. Press the settings button. You do not need to export textures, but you do need to export animation. The saved *.x file can have any name you like for now; I find it helps to differentiate the file you just saved from files you may be replacing.

In this tutorial I am creating a new collision model for the GT fighter, the file for which is fig405.cvh. If you had a new model you created in Milkshape, then you would create the visible MDL file and the various "joints" as per Creating models for Allegiance and export the CVH as well. You need not bother to make collision meshes in Milkshape, you're just exporting to CVH so that you have the weapon, missile, and cockpit locations for later. Again, be sure you have backups of anything you're working with, the next few steps can get messy.

Open the *.x file you saved from trueSpace in Notepad. You may also want to open an original _bound.x file for reference. Note that some .x file exporters format their text files in a way that Notepad can't read the spacing. trueSpace thankfully does not. Also, don't worry about the templates in the old files, you won't need them. What you'll need to do is copy the frame and mesh names of the _bound file. Some modeling programs might let you export correct headings, but trueSpace sadly does not.

In the example file, "Frame NoName_1-0" becomes "Frame frm-root". It doesn't matter what you put after "frm-" in the root frame, but "root" is simple and descriptive. After that, each frame becomes "Frame frm-bound#", and the mesh contained in that frame becomes "Mesh bound#". Truespace exports texture coordinates, you can delete them if you like but there's no reason to do so. Keep an eye on the curly brackets, you don't want to delete the wrong ones.

When you work your way down to the animation section, all you have to do is delete the "AnimationOptions{}" section and change the frame names to match what you changed above, e.g. "frm-root", "frm-bound1". Now save this file as fig405_bound.x.

Copy fig405_bound.x into the artwork tools folder. If you have a *.x file for the visible mesh, be it exported from Milkshape, or acquired from the original artwork (you can also grab individual files from SVN, you can use that for the next step. This will need to be a mesh that MDLC can read, so if you don't already have a fig405.x, then it might well be easiest to take, say, fig12.x out of the original artwork and rename it "fig405.x". The original GT meshes were made by Orion and have since been lost. You will also need a bmp.mdl file, so in this case fig405bmp.mdl.

Open a command line (run cmd.exe). You may need to run it as an administrator. Change directory to where the original artwork tools are located. Type "makegeo fig405 1 1". You can open makegeo.bat in Notepad if you want to examine what options other than "1 1" do, but they're irrelevant to creating a CVH. If you receive a d3drm.dll error, download it from here and place it in your artwork tools directory. The collision mesh is now a CVH file. If you receive error messages about programs like MDLC and xmunge crashing, ignore them unless a CVH file is not produced.

You can import the new CVH file into Milkshape to check that it processed correctly, although Milkshape is somewhat unreliable so you can't be certain until you test it in Allegiance. There's one thing left to do first though! Your weapon, missile, and cockpit locations are based on the dummy fig405.x file you created by copying fig12.x! In this case, all you need to do is copy the locations from the old CVH file. If you are creating a new model then either copy the locations from the CVH you exported from Milkshape, or your .x file was not a dummy, in which case your weapons should be in the right place. If you are trying to use a good *.x file as a source of weapon locations, and you make changes to the file and want to convert it to CVH again, you'll need to delete the _static.x file because it'll use the _static.x instead of the new *.x.

Troubleshooting

Typical problems you will encounter during testing are that the collision model is off-center, oriented incorrectly, or the wrong scale. The first two problems are best fixed by going back to trueSpace, correcting the error, and doing the whole process over again. If you're still having problems with position and orientation, then it's probably to do with animation.

If you believe you are having a scaling issue, the first entry in the first line of the CVH controls the scale. Note that when importing a CVH into Milkshape, this scale modifier is ignored. However, the artwork tools are fairly reliable (while AMT is not), so you probably won't have to change that. On the other hand, the collision ellipsoid (the next four numbers in the first line) generated by the tools may not be ideal. When testing, you will note that as long as the shields are up, bullets will only collide with objects inside the ellipsoid, and will generate a shield hit animation along the surface of the ellipsoid, but once the shields are down the convex hulls are used. As such, you will want to ensure that little or none of the ship extends outside of the ellipsoid.

You can compare the collision ellipsoid to the model in Milkshape by creating a sphere at the origin, then using the scale tool and Model Information to make the sphere's X, Y, and Z bounds equal to the second, third, and fourth numbers in the first line of the CVH file respectively, each multiplied by the fifth. That is, for the X-bound in fig405.cvh, multiply 4.70 by 1.00. If you want to change the ellipsoid in the CVH file, just change the ellipsoid you created in Milkshape, then copy its X, Y, and Z bounds into the CVH file, and set the scale to 1.00000000.

[3] This is the ellipsoid used by Orion's original CVH. If you shoot the ends of the wings while the shields are up, your bullets won't hit anything.

[4] This is the ellipsoid generated by the original artwork tools. The problem with the wings is worse than Orion's original, and it's much longer than it needs to be, so shield hits to the rear will appear to impact far behind the ship.