Skip to content
TiberiumFusion edited this page Sep 1, 2024 · 22 revisions

Basics

Converting SMD files

Find an SMD file, feed it to Smd2Pac, and you will get a text file containing PAC3 animation data. You can simply drag and drop your SMD file onto the Smd2Pac executable. From the command line, the path to the SMD file can be either the very first or very last parameter. Or, you can use the --smd argument to put it anywhere in your argument sequence. Get used to using the command line, though, because you'll need it for...

Animation subtraction

Virtually every animation you convert will need to be subtracted!

SMD animations are a kind of "baked" animation. They include a composition of the model's bind pose + the distinct animation itself. This is normally fine, since the Source engine transforms all bones relative to 0,0,0. In PAC3, however, all animations are relative to the current, realtime pose of your model. If you load up an SMD animation into pac without first subtracting it, your model is going to distort horribly, since the resulting animation has effectively been doubled.

The solution is to "subtract" the model's bind pose from your SMD animation, thus creating an "additive" animation that PAC3 will combine with the realtime engine pose to produce the intended final pose. Smd2Pac will do the subtraction and all of the complex math for you via a single argument. You could use studiomdl and Crowbar instead, but Smd2Pac usually does a better job of avoiding singularities and precision loss that would otherwise require you to manually create some fixup rotations.

Animation subtraction requires two SMD files. The destination SMD contains the animation you want to see with pac in gmod. The source SMD contains the base pose for your model (ideally, the bind pose that was used in the destination SMD). If your model doesn't have an SMD animation that contains its bind pose, you should pick an SMD that contains the most neutral, motionless pose available, such as the idle standing animation.

Only one frame from the source SMD will be used for subtraction on all frames of your destination SMD, so choose wisely. The very first frame (time 0) will suffice for most situations.

When you have chosen the best source SMD and frame to subtract from your destination SMD, use the arguments --make-additive-from and --additive-base-frame to feed them to Smd2Pac. See the arguments table and examples section for more info.

You can also use Smd2Pac strictly as an SMD animation subtractor. Add the argument --dump-additive-smd and Smd2Pac will write the subtracted (and thus now additive) destination SMD to a file, which you can then import into 3D software, compile into an MDL with studiomdl, etc.

How to get the output animation data into your PAC3 outfit

The custom animation part in PAC3 creates and accepts animation data in a JSON format. Smd2Pac outputs a simple txt file containing the processed animation data as an escaped JSON string. In the PAC3 editor, you can copy and paste this string directly into the data property of the custom animation part, but gmod/pac/vgui may choke on it if the string is too long and it will not paste. To work around this, open up your pac outfit's file (in garrysmod/data/pac3) with a text editor, look for the custom animation element, and copy & paste the entire JSON data string created by Smd2Pac into the data property.

Where to paste larger

Save your changes in the text editor, then switch back into gmod and re-load your pac from the outfit file. If the custom animation part still has empty animation data, you probably didn't paste it into the outfit file correctly.

Alternatively, you can upload your animation data to a direct web link, like a pastebin paste, and set the custom animation part's url property to the URL of the paste.

Once you have the animation data loaded up in pac, the last thing you need to do is set the custom animation part's rate property to the framerate of your SMD animation. For example, if you set rate to 30, your animation will play back at 30 frames per second. If you got your SMD file from an MDL, then the frame rate will be specified by the fps param somewhere in the SMD's $sequence block in the QC file.


Arguments

The only required argument is the path to your SMD file.

All named arguments are optional, unless --ignore-bones is present, in which case --smd must be used.

Argument Description Example
‑‑smd Path to the SMD file you want to convert. Can also be a folder for batch conversions. If the first or last argument is your SMD file, you don't have to use ‑‑smd. ‑‑smd "path\to\my cool anim.smd"
‑‑deep If ‑‑smd is a folder, ‑‑deep will also search subfolders for SMD files to convert. --deep
‑‑output Output filename for the PAC3 animation data. ‑‑output "path\to\my pac3 anim data.txt"
‑‑make‑additive‑from Path to an SMD file to use as the source SMD for animation subtraction. Enables animation subtraction. ‑‑make‑additive‑from "path\to\bind pose.smd"
‑‑additive‑base‑frame Frame from the source SMD to use for animation subtraction. Must correspond to a valid time block in the SMD. Default is 0. ‑‑additive‑base‑frame 0
‑‑dump‑additive‑smd Writes the subtracted destination SMD to a new SMD file in a subfolder. ‑‑dump‑additive‑smd
‑‑optimize Specify an optimization level. The default is 1. ‑‑optimize 0
‑‑ignore‑bones A list of bones to ignore, separated by spaces. These bones won't be included in the output PAC3 animation data. If you use ‑‑ignore‑bones, you must also use ‑‑smd. ‑‑ignore‑bones ValveBiped.Bip01_L_Thigh ValveBiped.Bip01_L_Calf
‑‑bone‑fixup Can be used multiple times. Specifies a fixup translation + rotation (in SMD coordinate space) for a specific bone. Syntax: bone name TX TY TZ RX RY RZ ‑‑bone‑fixup ValveBiped.Bip01_Pelvis 0 0 0 0 0 90
‑‑dont‑escape‑output By default, Smd2Pac escapes the output json text, which is necessary for importing into PAC3. This argument disables that. ‑‑dont‑escape‑output
‑‑hide‑warnings Hides all warning messages. ‑‑hide-warnings
‑‑parse-with-system-locale Read SMD files using your system's locale, instead of the expected locale for SMD files. Useful if your culture uses 1234,56-style decimals and your other tools create SMD files with that decimal marker format. ‑‑parse-with-system-locale
‑‑write-with-system-locale Writes SMD files using your system's locale, instead of the expected locale for SMD files. Useful if your culture uses 1234,56-style decimals and your other tools expect SMD files with that decimal marker format. ‑‑write-with-system-locale

Advanced options

Bone fixups

You can specify a constant translation + rotation that will be applied to a chosen bone on every frame of the entire animation. This is useful for undoing errors in additive SMD files that were subtracted by studiomdl and decompiled with Crowbar.

For example, if your subtracted SMD animation has an erroneous -90 Z rotation on the root bone, you can tell Smd2Pac to apply a +90 Z rotation fixup to cancel out the error. If your model is a valve biped, that might look like this: --bone-fixup ValveBiped.Bip01_Pelvis 0 0 0 0 0 90. The --bone-fixup argument can be used multiple times to create fixups for more than one bone.

Bone fixups are in SMD coordinate space and are applied after everything else!
Also, SMD files and the Source engine itself have different coordinate spaces! Thanks, Valve!
Also also, PAC3 uses yet another different coordinate space that deviates from the engine! Thanks, CapsAdmin!

● In SMD, +X (foward) is north on the compass, +Y (right) is east on the compass, and +Z is up.
● In the Source engine, +X (foward) is east on the compass, +Y (right) is north on the compass, and +Z is up.
● In PAC3, +X (forward) is east on the compass, +Y (right) is south on the compass, and +Z is up.
If your bone fixup includes a translation but moves the bone in the wrong direction, try swapping both your X and Y translations, then negating either the new X value or both values.

Optimization

Smd2Pac can optimize the output PAC3 animation data to some extent. Use the --optimize argument to set the optimization level.

  • --optimize 0 No optimization. (Default)
  • --optimize 1 Bones that have no perceptible movement for the entire animation are ignored. Affects subtracted SMDs only. Non-subtracted SMDs will not be optimized.

Dumping subtracted SMDs

With the --dump-additive-smd argument, Smd2Pac will write the subtracted SMD animations it calculated to a subfolder. You can import these SMDs into other software, compile them into MDLs, compare them with studiomdl/Crowbar's calculations, etc.


Examples

Smd2Pac.exe taunt_muscle.smd
Converts taunt_muscle.smd into PAC3 animation data and writes it to output\taunt_muscle_pac3animdata.txt. In this case, taunt_muscle.smd is already an additive animation and does not need to be subtracted.
Smd2Pac.exe taunt_muscle_base.smd --make-additive-from idle_all_01.smd
Converts taunt_muscle_base.smd into PAC3 animation data and writes it to output\taunt_muscle_base_pac3animdata.txt. Before the conversion, taunt_muscle_base.smd is subtracted from frame 0 of idle_all_01.smd in order to turn it into an additive animation.
Smd2Pac.exe taunt_muscle_base.smd --make-additive-from idle_all_01.smd --output "pac3 data.txt"
Converts taunt_muscle_base.smd into PAC3 animation data and writes it to pac3 data.txt. Before the conversion, taunt_muscle_base.smd is subtracted from frame 0 of idle_all_01.smd in order to turn it into an additive animation.
Smd2Pac.exe --smd taunt_muscle_base.smd --make-additive-from idle_all_01.smd --ignore-bones ValveBiped.Bip01_L_Hand ValveBiped.Bip01_R_Hand
Converts taunt_muscle_base.smd into PAC3 animation data and writes it to output\taunt_muscle_base_pac3animdata.txt. Before the conversion, taunt_muscle_base.smd is subtracted from frame 0 of idle_all_01.smd in order to turn it into an additive animation. Additionally, the left and right hand bones are omitted from the output animation.
Smd2Pac.exe "bad animation.smd" --make-additive-from "bad bind pose.smd" --additive-base-frame 3 --bone-fixup BadRig_Pelvis 0 0 0 90 0 0
Converts bad animation.smd into PAC3 animation data and writes it to output\bad animation_pac3animdata.txt. Before the conversion, bad animation.smd is subtracted from frame 3 of bad bind pose.smd in order to turn it into an additive animation. Additionally, a 90,0,0 fixup rotation is applied to the BadRig_Pelvis bone.
Smd2Pac.exe "path\to\some smds" --make-additive-from idle_all_01.smd
Converts all *.smd files in the folder path\to\some smds into PAC3 animation data and writes them to path\to\some smds\output\*_pac3animdata.txt. Before the conversion, each SMD is subtracted from frame 0 of idle_all_01.smd in order to turn them into additive animations.
Smd2Pac.exe . --deep --make-additive-from idle_all_01.smd --dump-additive-smd
Converts all *.smd files in the working directory and all subfolders into PAC3 animation data and writes them to *\*\...\*_pac3animdata.txt. Before the conversion, each SMD is subtracted from frame 0 of idle_all_01.smd in order to turn them into additive animations. Additionally, the subtracted SMD animations will be written to *\*\...\*_subtracted.smd.