This is something I've been meaning to do for quite some time, but I never got to it. Until now that is.
What you've stumbled upon is a tutorial on how to create eye-posing for Source Filmmaker (using flexes and the viewtarget that is), using a step by step approach.
This tutorial assumes you know the basics of working with a 3D modelling program and a 2D editing program, how to compile a model for SFM, how to convert textures to vtf files and how to set up standard vmt files.
- 3D modelling program like 3DSmax
- 2D editing program like Photoshop
Step 1. Creating the eye-textures for use in Source
I take the time-saving approach of copying the textures of a working model and adapting the new textures to their measurements. If you want to do it differently, be my guest.
- Go to the materials folder of a model that has working eye-posing in SFM and find the .vtf file containing the eye texture of that model. Open this file with vtfedit and export it as a .tga file.
- Open this .tga file with a 2D editing program like Photoshop. Now copy the texture you want the eyes to use on top of this .tga file.
- Scale the copied texture so the iris has the same size as the eye texture you exported.
- Now save this file twice as eyeball_l.tga and eyeball_r.tga.
This texture is now ready to be converted, but let's first use these 2 textures to determine the areas of the mesh which will be used for the eyes. This will tell Source where the mesh for the eyes is located.
Step 2. Adding the materials to the 3D model
I will be explaining how to do everything in 3DSmax. If you use something else, you will have to figure out the exact steps on how to do this yourself, but the process should be very similar.
- Start up 3DSmax and load the model you want to add eye-posing to. Select the entire mesh of the model and under Editable Mesh
or Editable Poly
, select Element
- Now select the right eyeball (it'll turn red to show the faces of the eyeball are selected).
- Now go to rendering>material editor>compact material editor
- And select one of the spheres and click the square to the right of diffuse.
- Select Maps>Standard>Bitmap
and press okay.
- Now find the eyeball_r.tga you saved and click open. You are now back in the material editor, click assign material to selection
and then click show shaded material in view
The texture on the eye may look weird now, but that's okay (the uv-map might not be correct, but the source engine will not use the UV-map for the eyes, so no problem)
- Do the same thing as you did for the right eye, but now select the left eye using element selection, use another sphere and use eyeball_l.tga instead of eyeball_r.tga. Once this is done you can close the material editor.
- Now click editable poly
or editable mesh
and then click skin
You should now save the model and export it as an smd (you might want to check if the rigging still work, so before you save see if moving/rotating one of the bones still works fine).
Now keep your model program open, we need to find the coordinates of the eyes to use in the qc file.
Step 3. Finding the coordinates for qc_eyes
- First navigate to your sourcefilmmaker\game\bin folder and find qc_eyes.exe and start it.
- Set the option for the 3d platform
you use (for 3DSMax you use the Z-Axis as up)
- Now go back to your 3DSmax.
- Under editable poly
or editable mesh
and select the vertex in the middle of the right eye.
- Right click anywhere in the perspective view and set the transform to move. If you now look at the bottom of the screen you'll see values for X, Y and Z. Copy the values for X and Z into the boxes for X and Z for the right eye in qc_eyes (make sure to replace the , with a . if necessary)
- For the y value we will need to look at one of the wireframe views in the 3d modelling program (either the top or side view). Find a vertex that looks like it would be in the center of the eyeball from the side (if you can't find a proper one take, the eye value of two verteces it would be inbetween and take the average value of those two) and input that value into qc_eyes for the y position.
in the picture above you can see I selected 2 vertices on the left wireframe where I estimated that the center vertex would lie somewhere between. 3DSmax will automatically calculate the average Y-value of those 2 vertices
- Do the same thing for the left eye and input those in the correct boxes in qc_eyes. Now if the values for eye coordinates
and the 3d Platform
have been filled in, you can press the Create QC Text button. This will generate a bunch of text in the box below. Replace all references to ValveBiped.Bip01_Head1
with the name you have given the bone for the head of the model.
- Now add the lines it generated that I highlighted to your qc file (make sure you put the lines in their correct spot in your qc file).
- Also add these two lines beneath the eyeball lefteye ...
flexcontroller eyes range -45 45 eyes_updown
flexcontroller eyes range -45 45 eyes_rightleft
- You can now close your modelling program and qc_eyes (you don't need to save or export the model as smd, since that has already been done).
- Compile the model for SFM using the qc file you just altered.
The model should now be working fine in SFM with the exception that is has no textures for the eyes. So all that's left to do is convert the textures to vtf files and create vmt files for them.
Step 4. Converting the textures to be source compliant
- Simply convert eyeball_l.tga and eyeball_r.tga to eyeball_l.vtf and eyeball_r.vtf (if they both eyes use the same texture, you could also just convert one to pupil.vtf or something, but for completions sake I'll do it like this) and copy these vtf files to the materials folder for the model.
All that's left now is to create the vmts for the model, you can use https://developer.valvesoftware.com/wiki/EyeRefract to create them yourself or be like me and copy them over from another model with working eye-posing and simply alter the texture path for the $iris.
-To do this go to the materials folder of a model with working eye-posing and find the eyeball_l.vmt and eyeball_r.vmt files. Copy those to the material folder of your model and open them with vtfedit.
- Find the $iris parameter and change the path to the eyeball_r or eyeball_l of your model. Do this for both vmt files.
- There will be one thing missing which is the ambient occlusion texture, that eyerefract uses. You can create one yourself (make a completely white texture with a completely black alpha channel), or copy a vtf from another model.
- Make sure to set the correct path for $AmbientOcclTexture in the eyeball vmts to that texture.
If you load the model in SFM now and if you've done everything correctly, it should be fully working with eye-posing.
One last thing. If you think the irises are too small or she looks cross-eyed (or the opposite) you should have a look at the following values in the qc file:
The blue circled values represent the angle at which the eyes are turned inward and the green circled values represent the radius/size of the eye. Just experiment with those if you feel you're having these issues.
If you have any problems with this tutorial, feel free to ask for help (I won't be able to answer any questions regarding other 3D or 2D programs, but I should be able to help with anything else).