Custom Wireframes

  • Original Author - Dev



    1. Create a model in MS3D that will become the wireframe image of your ship. Typically wireframes are simpler than the actual ship model, though this is not necessary; if you have created a custom .sur file for your ship, you may just want to re-use that. Regardless of how you come up with your model, it must be composed of just one mesh (group); if your model has multiple meshes (groups), select them all and regroup them into a single mesh (group). Furthermore, the .cmp exporter generally requires that all meshes have some texture; however, the texture will not matter at all for a wireframe, so just fabricate some texture and attach it to the mesh. Give the mesh a name; we'll go with my_ship_wireframe for this example. Lastly, export the model as a .cmp file, say my_ship_wireframe.cmp.



    2. Open up the command prompt (typically from the start menu) and go to the directory where you extracted the make_wire utility. Alternately, just put the program into the folder where your custom ship is; it's pretty small, so it's not going to hurt if you have a few copies lying around. Anyway, change the current directory to that directory, using the cd command (cd <directory_name>; use dir, which will show everything in the current directory, if you get lost).



    3. Using utf edit, open up the .cmp file you created in step 1. At the top of the file will be something like this:


    -VMeshLibrary
    -my_ship_wireframe.lod0.vms
    -VMeshData ---> export this


    Export the VMeshData to a file; the name will have no effect on anything, so call it something obvious because you're going to use it in a minute. For this example, let's call it vmeshdata.dat.



    4. Move vmeshdata.dat to the directory where make_wire is, if necessary. You don't absolutely have to, but it will make for less typing. Now, run make_wire. The arguments to make_wire are as follows:


    make_wire input_vmeshdata_file name_of_input_vmeshdata output_vmeshwire_file


    The input_vmeshdata_file is vmeshdata.dat in this example. The name_of_input_vmeshdata is my_ship_wireframe.lod0.vms, as taken from the .cmp file in step 3 (be sure that it matches exactly). The output_vmeshwire_file is anything you want; let's go with vwiredata.dat. This gives us the following command line:


    make_wire vmeshdata.dat my_ship_wireframe.lod0.vms vwiredata.dat


    When you run this, you will get the following output:


    total number of triangles in mesh = <number>
    total number of lines in mesh = <number>
    Successfully wrote vmeshwire


    and the file vwiredata.dat will be created/overwritten.



    5. Move vwiredata.dat to the folder where your original ship model is located (not the wireframe model, but the model you are adding the wireframe to). Let's call it my_ship.cmp for reference. Open my_ship.cmp in utf edit. At the top will be something like this:


    -VMeshLibrary
    -my_ship.lod0.vms
    -VMeshData


    We now will add the VMeshData from my_ship_wireframe.cmp to my_ship.cmp. First add two nodes to my_ship.cmp, like so:


    -VMeshLibrary
    -my_ship.lod0.vms
    -VMeshData
    -my_ship_wireframe.lod0.vms <--- use the same name as was used on the command line
    -VMeshData <--- import vmeshdata.dat into here


    and then import vmeshdata.dat, which you extracted from my_ship_wireframe.cmp and used with make_wire, into the lower VMeshData node.



    6. In my_ship.cmp, there will be something else that looks like this:


    - my_ship.3db
    -Multilevel
    -Hardpoints


    Add two more nodes, like so:


    - my_ship.3db
    -Multilevel
    -Hardpoints
    -VMeshWire
    -VWireData <--- import vwiredata.dat into here


    Import vwiredata.dat, created by make_wire in step 4, into the VWireData node.



    7. Lastly, we will set the selection radius of the ship. It isn't terribly important for ships, but for things like weapons and other attached equipment it matters. Export the vmeshref of my_ship.3db:


    - my_ship.3db
    -Multilevel
    -Level0
    -VMeshRef ---> export this
    -Hardpoints
    -VMeshWire


    Let's call the exported file vmeshref.dat. It will always be 60 bytes long, and the last 4 bytes are the radius of the object (in this case my_ship). The radius ALSO controls how far off-screen the object will be drawn, as measured from the center of the object, so don't make the radius too small. Open vmeshref.dat in a hex editor (for example, XVI32, a simple editor I use) and overwrite the last four bytes with your desired radius value, encoded as a 4-byte (32-bit) single-precision floating point value. For example, let's say we want the ship to have a radius of ten meters; we would put 00 00 20 41 in the last four bytes of vmeshref.dat (bear in mind that the encoding is actually 41 20 00 00, but on x86 and similar processors the byte order is reversed). Your hex editor should do the encoding for you, so don't worry about that part.


    You can also use FLModelTool to automatically set radius values of .3db files; just open the .cmp/.3db file and save. However, if you need more control over the exact radii, you can always use the manual method described above.



    8. You are done. Save my_ship.cmp and test things out in-game.




    And that is that. You can add a wireframe to any .3db file, so if you want separate wireframes for different components on a multi-component ship, that's fine; you can also re-use the same wireframe multiple times within a given .cmp file.


    If someone wants to use what little source code there is in some other programming project, by all means go ahead; it's not like I'm particularly attached to it. Still, it would make me happy if I got a bit of credit.


    Speaking of credit, thanks to Colin Sandby for the crc generating code.