Team Fortress Wiki:3D Models

From Team Fortress Wiki
Revision as of 14:17, 4 September 2011 by Moussekateer (talk | contribs)
Jump to: navigation, search

Requirements

Initial setup

  • Install Python 2.6 and the required libraries (SendKeys, PIL and pywin32).
  • Navigate to \Python26\Lib\site-packages and replace SendKeys.py with the modified version linked above.
  • Download and save the automaton scripts to an easily accessible folder.
  • Set up HLMV to produce the highest quality images possible by following the guide found here.

Setting up automate.py

File:3D Tutorial HLMV Coordinates.png
HLMV screen where 1 is the location of fileButtonCoordindates, 2 is the location of optionsButtonCoodinates and 3 is the boundary for imgCropBoundaries
  • Open up HLMV and maximise it.
  • Take a screenshot and paste it into an image viewer such as paint.NET or Photoshop.
  • Take note of the following pixel coordinates for your screen size.
    • SDKLauncherStartingPoint is a tuple of the x,y coordindates where the SDK Launcher will roughly be so the script can click on it. This can be a very rough estimate.
    • monitorResolution is simply a tuple of your screen resolution.
    • imgCropBoundaries is the boundary of the window the model in HLMV is contained within. The format is;
      • [pixel distance of left boundary from left of screen, pixel distance of top boundary from top of screen, pixel distance of right boundary from left of screen, pixel distance of bottom boundary from top of screen]
      • You should leave a few pixels gap from the window edge.
  • fileButtonCoordindates is a tuple of the x,y coordinates for the File menu button in HLMV.
  • optionsButtonCoodinates is a tuple of the x,y coordinates for the Options menu button in HLMV.
  • Close any programs that may interrupt or interfere with the process.
  • You're now set to take the images.

Workflow

  • Open up a weapon model in HLMV, make sure the 'Normal Mapping' checkbox is ticked, and centre the model.
  • Zoom the model out so that it is as large as possible but will not clip outside the viewer window when rotated or tilted.
  • Open regedit, navigate to \HKEY_CURRENT_USER\Software\Valve\hlmv and locate the registry key entry for the model. This will be in the form of models.weapons.c_models.c_wrench.c_wrench.mdl.
  • Copy and paste this key name into automate.py in the model = HLMVModelRegistryKey() entry.
  • Copy the Trans key entry for the model into automateDis as the intialTranslation argument (Don't forget to add the commas to separate the values).
  • Rotate the model by dragging near the centre of the viewer.
  • There will be three possible outcomes here.
    • The model will rotate around the bottom corner of the model. If so you will need to make use of rotationOffset.
      • Rotate the model so that it is facing left. Hold down the shift key and move the model sideways so that it is centered in the circle that appears.
      • Press F5 in HLMV and then in regedit. Note the new y Trans value. The difference between the current value and the initial value is the rotationOffset value.
    • The model will rotate around the wrong plane or the model does not rotate around the vertical or horizontal centre. If so the model will need to be recompiled. See the section on recompiling models.
    • The model will rotate around the vertical and horizontal centre of the model. If so, you're good to go.
  • Intially HLMV is open and maximixed. The script is started as so. From the commandline navigate to the folder containing the scripts and type python automate.py.
  • You then have 3 seconds (by default) to do the following. Click on the SDK launcher and highlight the 'Model Viewer' entry. Then click on HLMV to bring it back into focus.
  • The script will now automate taking the required images.

Team coloured models

  • By default you will capture the images for the RED coloured weapon. You will need to retake the images for the BLU variant.
  • Open up 'tf\materials\model\weapons' in GCFScape and extract the vmts for the model into \Steam\steamapps\<username>\team fortress 2\tf\materials\models\weapons.
  • Open the vmts in a text editor and copy over the '"$baseTexture" "models\weapons\<weaponame>"' line from the BLU vmt and overwrite the corresponding line in the RED vmt.
  • The model will now have BLU coloured and you can repeat as before to take the images.

Recompiling models

  • Open the model in HLMV.
  • Launch GCFScape and load 'team fortress 2 materials.gcf'.
  • Navigate to tf\models\weapons and extract the relevant weapon folder to \Steam\steamapps\<username>\team fortress 2\tf\models\weapons.
  • Launch MDL Decompiler, tick "do not fix rotations on animations", set your output directory to the same folder where the model was extracted and extract.
  • Unfortunately you're not done. The animation sequences you have just decompiled are all horribly borked. Launch StudioCompiler, go to the Model Decompile tab, decompile the same model (this time leaving do not fix rotations unticked). The decompiler will throw you an error, that's fine, click okay and it will finish extracting. Make sure you output to the SAME directory as the previous step so the files will be overwritten.
  • Open up the outputted "mdldecompiler.qc" and change the $model line's value for the .dmx.smd file to not include a directory. I.e. change "parts/dmx/c_wrench.dmx.smd" to "c_wrench.dmx.smd".
  • Open up idle.smd in a text editor. You will find an entry/entries that start with time 0/1/etc. The 2nd/3rd/4th numbers in the entry correspond to back/forth, side to side and up/down translations respectively. The 5th/6th/7th numbers in the entry correspond to x, y and z rotations respectively. Correct these values for all lines and save.
  • Go back to StudioCompiler, go to the Model Compile tab, go to the "Compile w/Existing QC" section, select your "mdldecompiler.qc" which you just edited and press compile. Note: If you get a compiler error about write access, it's probably because the directory the compiler wants to output to as specified in the .qc doesn't exist. Create it.
  • Press F5 in HLMV to refresh the model state. If the model still does not rotate in the correct plane/centre of the model then change the values again and recompile. This may require a lot of trial and error.
  • After successfully recentering the model copy the recompiled .mdl, .vtx, .phy and .vvd files into a zipped folder and upload to a file sharing site (preferably MediaFire) to post on the project page.

Uploading your image

  • After the script has finished it will generate a stitched image and a .txt file with the offset map.
  • Upload the image to the wiki under the name 'User <wikiusername> <weapon> <teamcolour (if applicable) 3D.jpg>' and copy and paste the offset map text into the summary box.

Tips and debugging

  • If your HLMV is opening too slowly then adjust the time in the mouse.sleep(time in seconds) entry that follows opening HLMV.
  • Stick the SDK launcher near the top left of your screen to speed up the step, as the script will start looking for the button there by default (this can be changed).
  • If something interrupts the image taking process, you can continue where you left off by setting the n arguement in the automatedDis method.
    • You can also use this to check the images are coming out right by interrupting the script and checking the images. If the rotation looks okay continue where you left off.