MayaValveExport
From DigitalBlacksmith
Contents
|
[edit] Exporting from Maya 8.0 to Valve (Prall's Exporter)
This tutorial covers how to export 3D models from Maya 8.0 to Valve Source SDK.
I've recently created my own modification to Prall's script. These modifications help with larger models. However, if you are just getting started I recommend you stay with Prall's original exporter (e.g., this page) for now...
[edit] Acknowledgments
This tutorial has been adapted from:
Free Tutorial from Noesis Interactive
- This free tutorial video, from the folks at Noesis Interactive, shows exactly what you need to do to export models from Maya to Valve Source. You will need to click on the video as it starts, as it is only a preview, but contains a hyperlink to a full video that shows everything. The link above only shows the first few minutes..
- Also, check out these great Maya/Valve DVDs from Noesis Interactive. I ordered the two Maya DVDs [1] [2] today plus the Advanced Level Design DVD [3].
No, this is not a paid advertisement..the tutorials are that good! I highly recommend you watch the video provided above.
My tutorial borrows from the video, but is designed to create and compile models in your MOD root. This is a little tricker than the video, which compiles everything in the HL2 game tree.
[edit] Tutorial
[edit] Setting up the Exporter
1. Grabbed the zip file hl2export2.5.zip by Prall. Link
2. Copied the contents of the zip file to my Maya User Profile directory:
C:\Documents and Settings\windows_login_name\My Documents\maya\8.0
Note: Because I already had a scripts and prefs directory, I manually dragged and dropped the files from the zip file to the currently existing directories. Also, if there were file conflicts between the Prall tool and the Valve bundled tool, I overwrote them.
Note: The scripts in the user profile directory are automatically loaded at startup. I don't recommend trying to alter the contents of Maya's program scripts directory.
3. If all goes well, when you open Maya, and look at the File menu you should see some new options:
- Export SMD...
- Export VTA
- Import SMD..
- Import SMD Animation
- Import from hammer
- Compile QC
You will also see a new shelf called HL2Export, that has 4 icons - Export, ADD, NEW, Layer:
[edit] Setting up the Valve Directories and Maya Project
First, some background...
My MOD title: ARMAR
My MOD directory, herein abbrevieated as <MODDIR> was created using the Valve Source SDK Create Mod Tool, and is located here:
C:\Steam\steamapps\SourceMods\ARMAR
1. Create the following directory structure in your MOD tree:
Note: As a minimum, ensure you have the following directories..If you have more that's OK...
<MODDIR> materialsrc\ materialsrc\testimage.tga materialsrc\mayabox\ modelsrc\ modelsrc\mayabox\ materials\ models\
Notes:
- Here we created, or ensured the creation of 4 'level 1' directories
- materialsrc
- modelsrc
- materials
- models.
- We also created a mayabox subdirectory in materialsrc and modelsrc.
- mayabox is just a name for my model.
- testimage.tga is the example texture I use in this tutorial. You can replace it with your own POWER OF 2 TGA, or download mine here.
- The other subdirectories - modelsrc, materials, models can all be empty, or contain other files..
2. Open up Maya
3. Click on File, Project, Set'
4. Navigate to the mayabox sub directory in the MOD:
C:\Steam\steamapps\SourceMods\ARMAR\modelsrc\mayabox
5. Click OK
[edit] Creating a Test Mesh and Texture
We will now create some test geometry to texture and export..
1. Create a Polygon cube in Maya.
- Create Menu, Polygon Primitives, Polygon Cube
2. Hit the 5 key to shade it..It should be some default color
3. Right click on the cube. Mouse down to the Assign new material...' menu, then select Phong. (not Phong E)
4. The shader panel should come up on the right. Select the color map icon (black and white checker board to the right of color)
5. The Create Render Node popup dialog will appear - Select File
6. The panel on the right will show a new panel for specifying the texture file. ABout half way down you will see 'Image Name with a text box and a folder icon. press the folder icon and navigate to our TGA texture:
C:\Steam\steamapps\SourceMods\ARMAR\materialsrc\mayabox\testimage.tga
Note: You don't need to hit OK or anything
7. Press the 6 key to hardware shade your model. You should then see the model with a colored test pattern:
[edit] Setting up the Export Layers and Compiling the SDL files
The Prall exporter uses Maya Layers to handle exporting of the Maya model to the SDL intermediate models. The export scripts will look on the reference layer and also the physics layer to find the models to export. So we have to create these, then add the model to it. We will first create the reference layer, then use a slick trick from our friends at Noesis to make the other layer.
[edit] Creating and Exporting the reference layer
1. Select the right most channel selector icon in Maya at the top right hand side of the toolbar:
2. This will bring up an embedded layer panel at the bottom of the channel:
3. Hit the 'Layers Menu (next to Options, and Help) inside this control, then Create Empty Layer
4. This will add a layer. Double click the layer and rename it 'reference' Note: it must be named reference exactly.
5. Now we add the model to the reference layer:
- Click on the model in Maya - The wireframe should show the active selection
- Add it to the layer by right clicking on the reference layer, holding down the right mouse button, select Add Selected Object
6. Check the add by selecting the little V icon next to reference, which toggles visibility. The model visibility should toggle with the layer.
We now need to add the shape information for our Maya model to the reference layer. By default, Maya 8 ignores the important shape node.
7. Right click on the reference layer, and hit Membership This brings up the Relationship Editor You will see the layers on the left, and all the parts of the Maya model on the right. Expand the reference layer on the left, and expand the pCube1 shape on the right. When everything is set you should see:
8. To add the Shape node (pCubeShape1) to the reference layer, left click on the reference layer icon on the left, then left click the pCubeShape1 node on the right. This adds the shape node to the layer:
9. You need to ensure your model is "normalized" prior to export. All translations should be zeroed out (TranslateX, TranslateY, and TranslateZ =0) and the scales should be set to 1. If they aren't hit Modify Menu, Reset Transformations. Once this is done, freeze the model's transformations - Modify Menu, Freeze Transformations.
NOTE: I haven't had to mess with this in this toy example, as a created the mesh on the grid and didn't transform it. This could be a HUGE issue with bigger models.
10. Now save the Maya file. File, Save As, (note we are in the mayabox subfolder of our modelsrc directory inside our MODDIR) and call it mayabox. Save it as file type .mb
11. Select the HL2Export Shelf. Bring up the SMD Export options window by clicking on the Export icon on the HL2Export Shelf. Hit the Path Settings tab. Select the default button to map all the smd/qc and other paths to our project:
This sets the exporter to export files to the correct location.
12. Prepare the export. Hit the export tab on the SMD Export Options window. For this first phase, we are only going to export the reference layer and an idle layer. Set the exporter up as shown below - mainly select Export Reference smd from Layer reference and export 1 frame Idle smd and Compile. Uncheck generate QC and Export physics....
13. When everything is set, hit the Full Compile button.
14. You should see a progress bar tick by...You may get a warning in the Maya status bar.
15. To verify you got the SMDs, check out the modelsrc\mayabox directory:
C:\Steam\steamapps\SourceMods\ARMAR\modelsrc\mayabox
You should see two new files - mayabox.smd and mayabox_idle.smd.
16. Save the Maya file again
[edit] Creating and Exporting the physics layer
Now we will repeat the process again, this time for the physics layer.
1. Go to the Maya file menu and reopen the same file you've been working in - mayabox.mb
2. With the model open, double click on the reference layer in the layer control, and rename the layer physics
3. Hit the Export icon in the HL2Export shelf.
4. Reconfigure the export settings to only export the Physics layer:
5. Do another Full Compile
6. You should now have a third SMD file in
C:\Steam\steamapps\SourceMods\ARMAR\modelsrc\mayabox
This new file - mayabox_phy.smd is the physics smd.
To recap, we should now have three SMD files:
mayabox.smd mayabox_idle.smd mayabox_phy.smd
[edit] Prepping the QC file
The QC file serves as a manifest of sorts for creating the actual Valve MDL file from the three SDL files and the texture file (color pattern) we used earlier.
1. Create a new text file named mayabox.qc in the following directory:
C:\Steam\steamapps\SourceMods\ARMAR\modelsrc\mayabox
The file should look like this:
//Static prop qc
$modelname mayabox\mayabox.mdl
$cdmaterials models\mayabox
//Note - replace this with any surface prop type -- look at sdk documentation
$surfaceprop "rock"
$staticprop
$scale 1
//SMD files
$body studio "mayabox.smd"
$sequence idle "mayabox_idle" fps 1
//Note - prall export uses phy not phys
$collisionmodel "mayabox_phy.smd" {
//Mass in kilograms
$concave
$mass 2.0
}
$upaxis Y
Pay close attention to the file names.
2. Open Valve Source SDK via your desktop icon. Ensure your Mod (e.g. ARMAR) is the Current Game. if its not, select it, close Valve Source SDK, then restart it. Leave it open. This will prime the Valve studiomdl.exe tool to compile our MDL file and place it in the right place.
3. Create a batch file to call studiomdl.exe. Create a text file named mayabox.bat in the following directory:
C:\Steam\steamapps\SourceMods\ARMAR\modelsrc\mayabox
Fill the file with these commands:
"C:\Steam\steamapps\steam_userid\sourcesdk\bin\ep1\bin\studiomdl.exe" "C:\Steam\steamapps\SourceMods\ARMAR\modelsrc\mayabox\mayabox.qc" pause
Note: The first line contains the full path to the studiomdl.exe tool, followed by the full path to the qc file. Edit these to match you configuration. The second line pausing so we can see the debug info.
4. Save the batch file
[edit] Compiling the MDL file
PREP STEP: In order to ensure a good compile, the Source SDK must be set to your MOD as the current game. Open the Source SDK from Steam, and set your game, then close. Sometimes, I have to restart steam to get this to 'take' Finally, if you are working in a Windows command line shell, you will need to restart the windows cmd shell after you do this.
Now its time to turn the SMD files into a no-kidding Valve MDL file.
1. Double click on the mayabox.bat file. leave the console window open, just in case.
2. Check the following folder, which should now contain our compile MDL file (and some supporting stuff):
C:\Steam\steamapps\SourceMods\ARMAR\models\mayabox
3. Also, open the Valve source model viewer (hlmv.exe or get it through the Valve Source SDK menu), and look for the mayabox folder. Try opening the mayabox.mdl file. You should see a box with the purple and black checkerboard pattern.
Note: If you can't seem to find your model in the viewer, drag and drop mayabox.mdl ontop of the hmlv.exe icon (find it way down inside the valve SDK bin (e.g. C:\Steam\steamapps\steam_userid\sourcesdk\bin\ep1\bin\hlmv.exe)
4. If you don't see anything in the models\mayabox directory, and/or you can't view your model with the viewer, check the output from the batch file. If you see some errors - try some of these fixes. I had to open up the model viewer to get mine to work the first time.
[edit] Creating the VTF and VMT texture files
We will now work on getting the textures compiled....
This step involves converting our texture files used to texture the Maya model into Valve's proprietary texture file format. This is a powerful format that allows textures to take on the values of materials, and thus have physical properties. This will allow you texture to do things like produce wood or glass fragments when they are shot in a game, or produce sounds effects, etc.
Of course this means that texturing in valve is extra complicated. If you want more info into what is happening in the following steps, check out:
Valve Matertial (VMT) Documentation
[edit] Creating the VTF file for the texture.
We have to convert the TGA file (testimage.tga) we used to texture the Maya model into a VTF file. This is a Valve standard format for all 2D graphics.
1. Open up the following directory, where we stashed the TGA file for the maya model:
C:\Steam\steamapps\SourceMods\ARMAR\materialsrc
2. Verify that the testimage.tga file is still there
3. Find the vtex.exe tool provided by Valve. Open the directory where the tool is stored. Mine is here:
C:\Steam\steamapps\steam_userid\sourcesdk\bin\ep1\bin\
4. Ensure the Source SDK window is still open, and that your MOD is still the 'Current Game.'
5. Drag and drop the testimage.tga in the materialsrc directory and drop it on the vtex.exe in the bin directory. This will automatically create a VTF file from the TGA and drop it in the correct location in your MOD directory structure.
6. Verify the testimage.vtf file is in the following directoy:
C:\Steam\steamapps\SourceMods\ARMAR\materials
Notes: For those that prefer a GUI, you can also use Nem's Excellent VTFEdit Tool to create and edit VTFs. This is also a handy tool for viewing VTF's.
[edit] Creating the VMT file for the texture.
A VMT file is a manifest/header for the VTMF file. It tells Valve how to render the VMF file.
1. Create a blank text file called testimage.vmt in the following directory:
C:\Steam\steamapps\SourceMods\ARMAR\materials\models\mayabox
2. Paste the following in the file and save it:
"VertexLitGeneric"
{
"$basetexture" "testimage"
"model" 1
}
3. Reopen the model in the HL2 Model Viewer. The model should now appear textured:
If texturing still won't work:
- Check the placement of the VTF and VMT files:
Full VTF file path: C:\Steam\steamapps\SourceMods\ARMAR\materials\testimage.vtf
Full VMF file path: C:\Steam\steamapps\SourceMods\ARMAR\materials\models\mayabox\testimage.vtf
- Check the file names. You have to use the same file name you used when you did the original Phong shading in Maya
- Check the syntax of the VMT file.
[edit] TO DOs
Here are some things I need to try now:
1. Exporting models with vertex color-based textures. These don't have any associated texture files to convert. Most of the LAV-25 Modeling to date uses this type of texturing.
2. Try some more sophisticated textures, where we have multiple TGA files.
- See this.
3. Try sidestepping TGA's, and use VTFEdit to crank VTF's from BMPs and JPGs.
4. Can a Python or PERL script be used to automate some of the compilation? Things like making VTFs, VMFs, running studiomdl, etc..
[edit] Maya to Valve References
Here are some other references on Maya export to Valve:
