|Tutorial: Custom First Person Weapons
Prepared by KungKrille.
This tutorial assumes that you have some knowledge about how 3D Studio Max works.
A first person gun in Red Faction (RF) is a combination of the weapon and the players arms - actually they are one single mesh. If you are working on a total modification with new characters, you have to model arms that corresponds to those. Others like me who just want to add new guns need Parkers arms. Don't worry, you don't have to model them by yourself. Download RF Weapon Examples, extract the files and you have several .max scenes containing the arms. Open a Rail scene in Max and hide everything except for the model itself ("Mesh" is usually included in the objects name). Be sure that you are on frame "0" (if you don't see frame "0" expand the timeline).
It is where the model is in rest pose. Goto Modifier stack and choose "Edit Patch".
There are hidden geometry you can't delete if you don't. Select all patches except for the arm and delete them. Turn the model back to editable mesh. Unhide all the other objects and delete all bones referring to the gun. Open a new Track View and expand Objects one step.
Right click on Bip01 and select Expand Objects. Right click again and select Expand tracks. Delete all keyframes and close the window. Save the scene and open your gun model or start on a new one now :-)
When you have finished the new gun merge the arm scene. Position the gun so it doesn't mix with the arm and resize it so it fits your concept and the hand. Attach them together to one single mesh and rename it to XXXX-Mesh.
I assume that you have mapped your gun and made some cool textures. RF requires that all textures are collected in one material. First check the material ID:s. For a quick test goto modifier stack, select polygons and scroll down to surface properties. Click on Select by ID and select "1".
The hand polygons should be highlighted. If not change the ID to 1 while the polygons are selected. "2" should be lower arm and "3" upper arm. My gun have just one texture so those polygons can share one ID and I suggest "4". Don't mind if the gun suddenly looks odd with wrong texture - we will fix it in the next step.
Open the Material Editor. Select the first material and turn it to Multi/Sub-Object and choose Discard old material.
Click Set Number and select "4". Browse each texture - hand1st.tga for the hand, envirohand.tga for the lower arm, armnew1.tga for the upper arm and gun_map.tga for my gun. Type in names that make sense for a better overview.
The last step before rigging and skinning is to center the models pivot and put all in the origin of the scene. Select the model and goto Hierarchy and click Affect Pivot Only.
Click Center to Object and Align to World. Now don't forget to reset the model!!! This is one of the most common mistakes. That is for bones as well (but you don't have to reset the existing bones). Goto Utilities and click Reset XForm and Reset Selected.
Collapse the Modifier stack. Bring a pencil and a piece of paper and write down the models position in all three dimensions, then center it to the origin by typing in "0" in all three slots.
The BDBN bones and biped don't follow, so you have to select each root bone and align them to the model manually with help by your notes. Before you do it you have to link the BDBN bones together with the link tool.
Upper arm to root (the little diamond), lower arm to upper arm, hand to lower arm, thumb 03 to hand, thumb 02 to thumb 03 (Volition numbered the fingers from the tip to the hand, very confusing) - continue until all bones are linked. Select the root bone you want to move first and concentrate on the coordinates. Use the previously written figures and add or subtract to get new values and type them in. Do this for both roots and look in the viewports so all are aligned.
Rigging and Skinning
Part 2 - Rigging and Skinning
Even if my gun doesn't have any moving parts you need to add an extra bone for the whole gun. You can build a bone with whatever you want - the important thing is that you convert the bone to editable mesh. Usually I make a copy of the gun and detach parts that will move and use them as bones. I will create a simple box for this tutorial. Activate Affect Pivot Only and move the pivot to one end of the bone, reset the model and collapse the Modifier stack. This is because you want the rotation axes at the right place.
Rename all new bones to BDBN-XXXX - I will call mine BDBN-Gun. Position the bones where you want them (I moved the bone so its pivot is centered at the trigger) on the gun and link them in the right order. Finally link the main gun bone to the root.
We want a muzzle flash and shells that ejects in game. Create two dummies;
Move one in front of the barrel and the other at the end of the barrel above the trigger. The y-axis for the muzzle flash must point into the scene (into the barrel). The shell eject dummy must have its y_axis in the eject direction.
Label them muzzle_1 and shell_eject_1 and link them to the main gun bone.
One more step before skinning. Open the Track View and expand all objects and tracks.All tracks are not needed so click on the icon in the upper left corner and check off everything except Hierarchy, Objects and Transforms. Select all position nodes for all BDBN bones and click on the icon for Assign Controller.
Check Linear Position. Select all rotation nodes and assign Linear Rotation. Create new keys on position and rotation for all BDBN bones at frame "0". If your animations get messed up you can always fall back on this frame, that is ignored by RF game engine.
It's time for skinning which I find very, veryyy boooring! Select the model and apply RF Bone in the Modifier. Click on Add Bones and select all including the dummies in the new window and click Add. You will get a list of all bones in the Modifier. Note: you won't be able to edit anything on the model or the bones after applying RF bone! Save the scene before you do. Expand RF Bone and highlight Vertex.
How you skin is up to you - I usually start from the upper arm and end up at the gun. Select BDBN-UpperArm-L and select vertices it should influence.
Raise the value to a proper wheight.
Note that RF Bone supports smooth skinning, so two or even more bones may influence on the same vertices. This is good at joints like the elbow and between the finger bones.Be sure that the sum of all wheights for every vertex is 100. To make it easier to see what you are doing hide all bones. Save the scene when you finally are done and reopen it - this because of a bug. If you would test how the mesh deform when you rotate the bones nothing happens if you don't do like above. Now test it to see if it looks good and you didn't forget >any vertex. Adjust the wheights where it's needed and save. Goto Modifier and click Export - this must be done before linking to biped. Select both dummies in the pop-up and type in a file name. Now you have the setup for your new gun that RF game engine will refer to. I will export my gun as fp_testgun.vcm.
You who doesn't have Character Studio or like FK can go to next step. We will link the BDBN bones to biped, so we can take advantage of IK and the rotation limits that are already set in biped. Link BDBN-UpperArm-L to Bip01 L upperArm, BDBN-LowerArm-L to Bip01 L Forearm and so on. Of course there are no biped for the gun bones so leave them as they are. Rotate biped bones to check that the setup works and save as a new file.
We will start with a very simple idle animation so we have something to test in game. Set the timeline to 1-60 frames and move the meter to frame "1". Activate the animation button and create a base pose where the arm holds the gun. Don't animate any bones linked to biped! Note that all bones must have a position and rotation key at the first and last frame (except for BDBN bones linked to biped). When you are satisfied with the pose copy all keys to frame "60". The start and end-key must be identical so the loop and swithes to other animations are seemless. When you animate other states like fire and reload, use the same pose.Scrub to frame "30" and move the gun and hand slightly upwards and set keys. This will give the illusion that the player is breathing. Goto Modifier and scroll down to MVF Parameters.
Change Ramp in and out to 5 and leave the framrate at 10. Ramp in/out is how long the transition from/to other animations shall be. You might have to raise the framerate for complex and rapid animations as fire. Click on Export and type in a filename. Mine is exported as fp_testgun_idle.mvf. You can download my animation here.
Reduce and Convert
My suggestion is that you copy Ccrunch and Mvfreduce to your System32 folder, so you have access to them from wherever you want to launch them. Open the Command Prompt (CMD) and type in this command:
fp_testgun.vcm is my name of the setup file and it's directly under C:. If yours is at a different location you have to browse to that folder. Hit your enter key to execute the command and you will get a .v3c file.
Now type in this command:
For some reason I have to include the full path here. -d is the reduction factor for position and -e for rotation. -c is the output flag. Hit enter and a .rfa file is created. Close CMD.
Finally we have to tell RF that we have a brand new gun! Download VPPBuilder, install and launch it. Open tables.vpp from the RedFaction folder. Extract weapons.tbl and fpgun.tbl and open them in Notepad. In weapons.tbl scroll down to the Shotgun and make these changes:
Note that they use old file extensions but they refer to the new ones in reality. 1st Person offset is the models position relative to the eye. Small numbers here indicates a well made setup in Max :-) I replaced all animations with the idle animation, because it's all I got right now. Make this change in fpgun.tbl:
Return to VPPbuilder and create a new file. Add all new files and save in a new folder with the same name as your mod in the modsfolder;
I called my mod testgun.vpp.
Launch RF, click setup and goto Misc. tab. Type this command: -mod XXXX. Click OK and start the game. Choose multiplayer, create game and The Lobby. Locate and pick up the shotgun. Wow, a new gun!!! If you aren't satisfied with the guns position adjust 1st Person offset in weapons.tbl.
You need some more information if you want to add the same effects that some of the original guns have. Heat scanner monitor and ammo counter for example. Sometimes it's a dummy and sometimes a texture. I added the bones as well because of two reasons. It's good to know the BDBN bone names for those who want to add custom animations or want to use the original ones for their own guns. Another reason is that you get a hint how the guns are built by just reading the names.
Below is a list of 1st person guns held by Parker. Vehicle weapons and multiplayer weapons carried by other characters can be found in meshes.tbl (open the v3c's in Notepad and scroll down until you find the info).
Note: the digits are actually an animated texture called assault_digits.vbm
- Setup file:
- link-BDBN-root (dummy or comment?)
- muzzle_1 -root (dummy or comment?)
- BDBN bones:
- aslt-bdbn-clip aslt-bdbn-gun
- Setup file:
- rckt-BDBN-root (dummy or comment?)