Serious Sam 3: BFE

Serious Sam 3: BFE

Not enough ratings
How to add moving eyes to your player model
By NSKuber
With this guide you will be able to add eyes that follow player's looking direction to your multiplayer model, just like in "Life is Strange Character Pack"!
(by "your model" I mean model that you have created, not the one you play with)
I'm assuming that you know how to install and work in SED (you have at least created your own player model, haven't you?), so I won't go into details about the basics.
   
Award
Favorite
Favorited
Unfavorite
Introduction and preparation
Hello!
If you have no idea what I'm talking about talking about, see this mod. Just look at the screenshots.

Ok, now that you understand what we are going to make, first thing you should do is subscribe to that mod. This is important, because it contains world scripts that make it all work, and you will only need to make some additions to your model. Also everyone who wants to see these moving eyes on their end should also subscribe to it!

Second thing you need is spherical (at least half-sphere) eyes for your model. We are going to rotate it, so if eye in your model is just a few polygons connected to the rest of the head, you're not going to succeed. Also eyes in your model should be placed on the head (attached to "Head" bone) and default attachments should be unmodified. If that's not the case, but you still want to make eyes, we can discuss it.

Few illustrations of what I mean (some nearby polygons removed for better view):

If you have subscribed to LiS pack, your model have good eyes (or you created good eyes yourself) and you also have several hours of time and enough patience, we are ready to continue!
Alternative way
As Ryason55 pointed out in the comments, there is anothey way of doing all this eye thing: you can add eye bones to the skeleton, and then edit PoseTransition animations in the Pose Schemes to include eye bones and make eyes look in correct direction for each of the PoseTransition animations.
Pros:
  • It's much more natural, and eyes will be moving smoothly;
Cons:
  • I think it will be even more time consuming, since there are 135 pose animations, and for each of them you need to pose both eyes correctly; though if you are lazy you can only pose Front position precisely, and don't bother much with others;
  • Won't work for moving animations, unless you modify those too; not much of a disadvantage though, since you usually don't see model's eyes when it is moving;
Dunnos:
  • I'm not sure about the precision of eye positions relative to your looking direction, though if I understand correctly how all this pose transition thing work, it should work flawlessly;
From mesh to attachment
In this part we are going to take eyes from our model and make them into attachments.

Go to mesh editor, select one eyeball (I chose the right one) and copy it into a new empty model (tip: to select the whole eyeball at once simply double-click on one of its vertices or polygons).
Now, very important part, you should place your eye in this model so that the center of the world coincides with the center (maybe imaginary center) of the eyeball as a sphere. What I mean is that when you rotate it around the center of the world, it should "stay in place", so that when you will rotate it on the model it will behave like the model is moving its eyes. I hope you get what I mean.
(To rotate around the center of the world go to "Tools" tab, and there change "Origin of action" field from "Center of selection" to "Coordinate system")

Maybe couple screenshots will help:


Note how in the second case after rotating the left part of the eye is much higher than the highest part of the eye before rotation. This shouldn't happen. Imaginary (or real) sphere of the eyeball should stay in place (more or less) when rotating around the center of the world.

Save this model and go back to your player model. Select right eye mesh again and move it somewhere (better move it along one of the axis for some fixed distance, so that you can move it exactly back anytime). Now go to the "Model editor" (from now on we will mostly work in model editor!) save "Children holder" of your model into another file (place it in the directory where your model is, as we are going to change attachments a bit).

After you secured your attachments file, create new attachment and name it "Eye_R_0_0" (if you were copying left eye, "Eye_L_0_0"). Select "Target bone" to "Head" and in "Model instance->Model" choose your created eye model.

At this moment your eye should be somewhere inside of your model, in the neck, as it is attached to the base of the "Head" bone and haven't been moved yet. You're going to find it, select and move to the original position of the right eye. Place it in such way that it is looking forward, both vertically and horizontally. Use left eye (which is still a part of the mesh) as a reference point. Here is what it looked like when you just added attachment and how it should look like after you move it.


Now you can check if you placed mesh in your eye model correctly: rotate this eye in place in different directions to make sure it looks natural.


Looks good to me.
If it doesn't look good to you, e.g. eye protrudes somewhere when you rotate it, go back to your eye model and move mesh around until you are satisfied with the result.

We are going to use the same eye model (of the right eye) for the left eye for simplicity and precision. In most cases they are similar anyway. If eyes of your model look quite different, you can make another model, but be careful with placement later.

Go to the "Mesh editor", move left eyeball somewhere. Return to "Model editor", create another attachment, and copy your "Eye_R_0_0" attachment over it. Rename it to "Eye_L_0_0", go to "Model instance->Stretch" and change "x" stretch from 1 to -1. Then go to "Target offset->v" and change sign of "x" coordinate (e.g. I had x=0.038281192, so I change it to -0.038281192).

If your model is symmetrical and the plane of symmetry of the head coincides with the plane of symmetry of the skeleton (wat), you should now have a perfectly placed left eye. But this is rarely the case, so you'll likely end up with something like on the left picture below. Move the left eye to its correct position. In the end it should look like on the right picture: your model looking forward with its shiny new attachment eyes!


But all of that was just the beginning...
We need more attachments!
This is the "fun" part. Now you will need that patience I mentioned in the intro.

As you may have already guessed, moving eyes work by showing and hiding corresponding eye attachments many times per second. So what we need to do is create attachment for every eye position. This is not hard, but very boring.

But first you need choose few numbers: how much can my model rotate its eyes to the left? to the right? up? down? what will be discrete steps?
If your model is a humanoid with normal head and eyes, then I recommend using the following:

Horizontally eyes can move from -12 to +20 degrees with step of 4 degrees. (-12 means eyes are looking 12 degrees to the right, +20 means 20 degrees to the left).
Vertically eyes can move from -16 to +20 degrees with step of 4 degrees. (-16 means eyes are looking 16 degrees down, +20 means 20 degrees up).

These numbers are not random, but were chosen after testing and cover most of the common positions. If you are brave enough you can make smaller steps to increase precision at the cost of more attachments.

What do these numbers mean anyway? It means that for every position with horizontal looking direction ranging from -12 to 20 with step 4 (i.e. -12, -8, -4, 0, 4, 8, 12, 16, 20) and vertical looking direction ranging from -16 to 20 with step 4 (i.e. -16, -12, -8, -4, 0, 4, 8, 12, 16, 20) you should make an attachment with eye looking in that direction. In my case, that is 9 x 10 = 90 attachments for every eye. Brace yourself.

Ok, how do we do it? Open "Children holder" field of your model, and smash that yellow plus till your finger bleeds 178 times (we already have one eye position for each eye, need 89 more).
(*) Open "Eye_R_0_0" attachment and in "Flags" mark it "Hidden" (this will save you some pain later). Now copy this attachment and paste it in 89 of the newly created ones. To speed up the process in the future, open up all 90 right eye attachments (start from bottom one).

We need to rename them. First number in attachment name corresponds to vertical direction, second - horizontal. We have vertical range from -16 to 20, and step 4, so if we divide, we will get that vertical positions will be numbered from -4 to 5 (that is, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5).
Horizontal positions will be numbered form -3 to 5. So now you change names of all 90 attachments (except for initial "Eye_R_0_0") to "Eye_R_x_y", where x ranges from -4 to 5, and y ranges from -3 to 5. After this you should have something like this (except that all of them should be opened!):


All of these have the same eye model, looking forward.
(some right eye attachments are not on screenshots because they are lower, after L)

Time to rotate! Open "Eye_R_0_1" and remove "Hidden" flag. Bam, we see our initial forward looking eye. But "Eye_R_0_1" should look 1*4 = 4 degrees to the left! So we rotate it 4 degrees. (Tip: by double tapping RMB on rotation circles (while holding Ctrl) you can set discrete rotation angle to number other than default 15 degrees) After you rotated it, set it back to "Hidden".


Now do the same for every attachment: for "Eye_R_x_y" attachment, unhide it, rotate it vertically by 4*x degrees, then horizontally by 4*y degrees and hide it again. Order is important, first do vertical rotation. Some examples: "Eye_R_3_-2" (12 degrees up then 8 degrees to the right) and "Eye_R_-1_5" (4 degrees down then 20 degrees to the left):


Be careful! Though this is a simple and tedious process, one small mistake can spread to many attachments and be hard to find later.

Phew! All done! Well, not quite. Do the same for the left eye, starting from (*) earlier in the text.

After you finished you should have 180 nice eye attachments. You may unhide some pairs of attachments to check if your eyes are looking ok. Don't forget to hide them all in the end.


Congratulations! We are almost done!

Finalizing and testing
We have all eye attachments, but there are still couple of thing that need to be done.

First, remember those numbers we chose (eye rotation ranges and steps)? We need to tell them to the script.
Create yet another attachment (this is the last one, I promise), and name it "EyesParams".
Don't attach it to any bones, don't add any model or flag, just open "Target offset". Let's see, what do we have?
Vertically eye numbers (not angles!) range from -4 to 5, and step is 4 degrees.
Horizontally eye numbers (not angles!) range from -3 to 5, and step is 4 degrees.

Divide all underlined numbers by 10 and plug them into "EyesParams":
Put vertical parameters into "v" (vector) field, in x, y and z correspondingly.
Put horizontal parameters into "q" (quaternion) angle fields.
For example, for my parameters it should look like this. Just copy this if you used same parameters.


Now script will know that your model has eyes and how to rotate them!

Last but not the least: though in the game eye attachments will be shown by the script, they won't be in the model selection menu. At the moment your model should have no eyes (all attachments are hidden), and looks creepy. It will look so creepy in model selection menu and for players that have your player model but don't have LiS playermodels (which contain the script).

How to fix that? Remember how you moved eyes in model's mesh? Well move them back into original place. Now make them slightly smaller or move them slightly deeper into the head or do both, so that they look ok from enough distance, but at the same time they don't intersect with attachment eyes when latter are shown. This eyes will be seen in player selection menu and for players without the script, but should be completely covered by attached eyes when the script is working. In my case it looks like this: no attachments vs "_0_0" attachments


That is all! You made it!
To quickly check if it works at all, start some multiplayer map in the editor, choose your model, enable "Fly" cheat and rotate the camera. If it looks like this:


then congratulations, it's working!
Now test it with someone else (or with yourself using a second copy of Sam and Steam) and update your model!

If after testing you feel that your character is looking a bit to high ar a bit too low in general, or something else is wrong, you don't need to change all attachments - just modify your eye model, rotate it a bit till satisfaction. Also keep in mind that in Sam-sized models eye height is different from the height of the point that you are looking from, that may cause minor inaccuracies (in addition to discrete step).

If you have any questions or corrections, leave them in the comments.
4 Comments
Fallen One 18 Jan, 2017 @ 12:55pm 
that's a sweet mod :steamhappy:
NSKuber  [author] 12 Jan, 2017 @ 9:26pm 
That is indeed a good working way. But I'm not sure what's worse: copypasting and slightly changing 180 attachments, or setting up eyes to look in correct direction for 135 animations (15 poses * 9 directions for each). I'm gonna add this to the introduction.
NSKuber  [author] 12 Jan, 2017 @ 10:04am 
Thanks, I'll give it a look!
Ryason55 12 Jan, 2017 @ 8:21am 
Or, edit the PoseTransition animations in the Pose Schemes to include eye bones.