View Thread
Point Defense Systems » Support for our Releases » Coding / Scripting Support
 Print Thread
Hodding tutorial with turrets
Sun Tzu
How to put a subsystem turret directly into the ship's HOD?

This is a step-by-step tutorial. We will deal with the upper turret on the Hydra IV frigate (hgn_mvtatorpedofrigate). You need 4E534B's Cold Fusion Hod Edit, PDS files, and HW2 files (in fact only the ship.st shader will be enough).

0) Back-up

Make a backup of hgn_mvtatorpedofrigate.ship and hgn_mvtatorpedofrigate.hod. That can be useful if you mess up with anything during the process.

1) Identify the hardpoint and the subsystem

Open the .ship file with a text editor. See the StartShipHardPointConfig function, that sets subsystem weapons. Ours is: StartShipHardPointConfig(NewShipType,"Weapon Back Gun","HardpointWeaponBack","Weapon","Generic","Damageable","hgn_FF_BK","hgn_FF_BK"). The joint name is the 3rd argument HardpointWeaponBack and the sub name is the last argument: hgn_FF_BK.

2) Get the turret meshes and textures

In the subsystem folder, you find a hgn_FF_BK folder with a hgn_FF_BK.hod file. Open it with CFHodEd. First have a look at how it looks: Hierarchy tab, click on any joint to select it and click on the position button.
Surprise, it is a whole platform! This shows Tel' and former PDS team's cleverness: when there was no alternative to Maya and they used ships as subsystems.

Click on the Geometry tab. You can see the list of meshes in the Hod file. The turret meshes are Weapon_Top_Position_mesh, Weapon_TopSlave_Muzzle_mesh and Weapon_Top_Muzzle_mesh. Select them and export them by hitting the Export button (accept to reverse UVs).

Also export the battle scar meshes. In the BSRM tab, select the same three meshes and export them.

Last, we need to export the textures. In the Textures tab, select the files that correspond to the top turret; usually the names are self explanatory. For us, it will be Hgn_FrigateTurret_EXPORT[1] and Hgn_FrigateTurret_EXPORT[3].

Normally, all exported files should be in the data:subsystem/hgn_FF_BK/ folder. There is a bug in the 2.66 version of CFHodEdit that sends all to the root of the volume (normally C:\); in prior version, all files are exported in the folder where the application is located. Anyway, put everything in the same directory.

You'll notice that Hgn_FrigateTurret_EXPORT[1] lost its tag and became Hgn_FrigateTurret_EXPORT. As you can check with any program that reads dds file, it is the diffuse texture. So rename it Hgn_FrigateTurret_EXPORT[1]. Also Hgn_FrigateTurret_EXPORT[3] became Hgn_FrigateTurret_EXPORT[2]. We can leave it that way, because it is the glow texture.

3) Import the turret meshes and textures

Don't close the CFHodEdit instance with hgn_FF_BK.hod. Open another one with hgn_mvtatorpedofrigate.hod.

Start with the Textures tab. Click on the Add button. Select the newly created new texture 13, click on the Replace button and select Hgn_FrigateTurret_EXPORT[1]. Follow the same process to import Hgn_FrigateTurret_EXPORT[2].

Now that you have both textures it might be a good idea to save. At this stage Save As is the only option; as we made a backup, you can proceed and save as hgn_mvtatorpedofrigate.hod.

Time to combine the textures into the material that will be applied to the mesh. In the Materials tab, add a new material. Select the newly created Material_7 and rename it Turret. With Turret selected, select a shader by hitting the Browse button. You should pick up ship.st, which is in the HW2 data:shaders directory. Then the shader window should display "ship" and you should see "$diffuse" and "$glow" in the parameters window. Click on $diffuse and select Hgn_FrigateTurret_EXPORT[1]. Assign Hgn_FrigateTurret_EXPORT[2] to $glow in the same way. Save. Now you have materials ready to apply to the meshes.

In the Geometry tab, click on the Add button on the top left of the panel. Select the newly created NewObject3, rename it Weapon_Top_Position_mesh add a LOD by clicking on the Add button at centre bottom of the panel; the LOD window should display "LOD:0". Select this and hit Replace, then select the Weapon_Top_Position_mesh_LOD0 we exported from the subsystem. You should refuse to merge vertices (unless you know what you're doing), accept to reverse UVs and select Turret as a replacement for turret material. Now you have the mesh for the turret base into the hod. Repeat the process with LOD1 and LOD2 and then with Weapon_TopSlave_Muzzle_mesh and Weapon_Top_Muzzle_mesh.

Last, go to the BSRM tab. Select Weapon_Top_Position and hit Replace. Select the Weapon_Top_Position_BSRM that we exported from the subsystem. Again refuse to merge vertices. Repeat the process for muzzle and slave muzzle.
Now you can save again your work.

4) Put the meshes on the proper joints

Let's have a look back at the subsystem HOD. In the Geometry tab, select Weapon_Top_Position_mesh and have a look at the parent window. It displays the name of the joint where the mesh is put (Weapon_Top_Position). In the hierarchy table, you see the coordinates of that joint, with children "latitude", "muzzle", "direction" and "rest".

We will have to create them on our frigate HOD. Fortunately Relic and PDS teams made 95% of the job, so we just need to exploit it.

First in the hierarchy tab, select root [that's important!!] and click on the Add Hardpoint button. Select Animated Turret and type in the name: TurretTop. Then at the end of the joint list you have a Weapon_TurretTop_Position joint with Rest, Direction, Latitude and Muzzle children.

Second, find out the coordinates of the joint where the subsystem that we are removing was mounted. You remember it was named HardpointWeaponBack, so you'll find a HardpointWeaponBack_Position in the Hierarchy tab. Note down the position (ie X Y and Z values of the first row). Then have a look into the hierarchy of the subsystem HOD and note down the position of Weapon_Top. Add both coordinates. Fill in the Weapon_TurretTop_Position with the result, which should be 0, 7.817 and -36.761. Keep the default values for Direction and Rest, we will see later if we need to change them.

Third, find out the coordinates of latitude and muzzle of Weapon_Top in the subsystem HOD. Fill the Weapon_TurretTop_Latitude and Weapon_TurretTop_Muzzle coordinates with those values.

Fourth, now that we have placed joints, go back to the geometry tab. Assign Weapon_Top_Position_mesh to Weapon_TurretTop_Position and Weapon_TurretTop_Muzzle_mesh to Weapon_TurretTop_Muzzle.

Godd time to save again.

Repeat the process to create Weapon_TurretTopSlave hardpoints and assign Weapon_TopSlave_Muzzle_mesh to Weapon_TurretTopSlave_Muzzle.

5) Edit the .ship file

By the way do we know which weapon was mounted on that turret? oops, let's open hgn_FF_BK.subs again. In the tartSubSystemWeaponConfig function, you see that the weapon's name is "hgn_FFBK" and that there is no fire effect associated. But since we are curious guys, we'll have a look at hgn_ff_bk.events file, where we can see that there are some weapon fire effect there. We can import them to our frigate later on if we want.

Going back to hgn_mvtatorpedofrigate.ship, we delete the line
StartShipHardPointConfig(NewShipType,"Weapon Back Gun","HardpointWeaponBack","Weapon","Generic","Damageable","hgn_FF_BK","hgn_FF_BK")
which created the subsytem and a new line:
StartShipWeaponConfig(NewShipType, "hgn_FFBK", "Weapon_TurretTop", "")
which simply creates the same weapon on the turret joint that we created. For the moment, we will not add a fire effect.

Save the hgn_mvtatorpedofrigate.ship file. Time to test it in game! No more lag!!

6) Fine tuning

In game you have seen that the turret when inactive was oriented towards the front of the ship, while it was pointed to the rear. To solve that, we can reverse the orientation of the joints by adding a 180 Y rotation in Weapon_TurretTop_Position and Weapon_TurretTop_Slave_Position.

Also the turret is set to deep in the hull. To move it up, you just need to increase the Y value of Weapon_TurretTop_Position and Weapon_TurretTop_Slave_Position. Here you can safely add 0.5 to both.

Conclusion: it does not take much to hod a new ship. Except that the setting or the turret (position on the hull and orientation) as well as the weapon settings (including the rotation speed and tracking angle of the turret) had already been done, which made the task rather easy.
Edited by Sun Tzu on 13-01-2007 23:14
 
Inert
You replaced an existing .hod with your own components? That's pretty ingenious of you. Smile

I probably should've reached that conclusion; if you try to recreate a .hod from scratch, you get all kinds of a mess.
 
Jump to Forum