Offset UV's or do 'something' in Blender :)

Hi all,

I have a face I wish to animate. By animate I mean change the UV’s so within it’s texture I have a happy/sad/angry face etc. My question is presumably ‘somehow’ I create the texture in Blender and then map the uv’s by code; altering them to suit which expression I want.
I am wondering if this is the best approach for this type of simple animation. Alternatively (of course) I could have a separate texture for the face ; though still I would need to map multiple expressions into 1 texture. Best to do in Unity or ‘somehow’ in Blender???

Thanks

You could use bones to deform the mesh, you’d only need one texture and one UV to accomplish that.

If you use textures though your going to inevitably have kind of a “jerky” appearance (unless you make some 10-30 odd frames for each change of expression). Not sure if thats a problem.

If you wanted to have a single texture though, you could have multiple UV’s and then modify them in code… basically have UV 1 be a happy face and UV 2 be an angry face, then to move between them you just copy both UVs at Start and then lerp from one to the other with a timer in your update function. Since UVs are just Vector2s the lerp part would be easy, just a for loop with some thing like: UVout[n] = Vector2.Lerp(UV1[n], UV2[n]); Although, I don’t know how to have more than 2 uvs in a mesh. If you need more than 2 you’d probably have to export the mesh with 2 uvs in each and import them into unity, then get all of the uvs together. If any one knows a better way that that let me know!

Since you probably would need multiple exports of the mesh though, you could also deform you mesh in blender (make several different expreshions) and then just get copies of those meshes from public variables in your script, and lerp from one to the other (maybe even use an animation curve to get better control over the animation).

Just kinda brian storming here, let me know if your interested in any of these, I could go through them a little further.

Hi Inventor2010,

Thanks for the input. I’m new to Unity and blender so I’m not sure (if I understand you correctly) which method to go for.
I suppose another method would be to have an ‘in game’ model (i.e. no facial animation) and then a separate model with a proper modelled face for close ups - then i can animate properly i.e. keyframe whatever - rather than my simpler solution. It’s an iPhone game so speed/memory/fps were important factors.

Cheers

Well, the Mesh class for unity is right here.

The first thing I suggested is bones, I haven’t dealt with them too much (or at all to be more specific) but they are probably as fast as your going to get. They are what is used in animating a characters arms and limbs and such in Unity. Theres an example here. I’m not very equipped to explain bones, but basically you attach them either in code or in your 3d modeling software to your mesh, and then by moving them the mesh is deformed along with it. (like a real life skeleton) You can attach them in any place you want though, have 2 of them, one attached to each side of the mouth, and then just move them up and down and you could go from smiling to frowning (maybe even attach some to the eyes, and the checks and get some more realistic animations). I’ll try to find some tutorials on that, incase no one else posts.

UV’s might work. What I was suggesting there is having 1 texture (no smaller textures inside it like you said before). Then you would have to get multiple UV’s into your script, but like I said before, and from what you can see on the link I gave you, you can only have 2 UVs. So if you want more your going to have to save 1-2 of your UVs (in blender) with one mesh, then save it again with another 2, and another 2 until you have all the UVs you want. Then import them all into unity, and in script you could then collect all of the UVs, something like this:

var meshes : Mesh[]; // This will let you put all your meshes into this script in the inspector.
private var UVs : Vector2[]; // This will be all your UVs, private cause you don't need to see it in the inspector.
function Start()
{
     UVs = new Vector2[meshes.length]; // Get a variable ready to store all the UVs.
     for(var i=0; i<UVs.Length; ++i)
     {
          UVs[i] = meshes[i].uv;
     }
}

That will get you UVs, it doesn’t utilize the second uv, but just incase you have an odd number of them I just kept it simple. So basiically you’d export your mesh from blender 1 time for each UV, import them into unity, and put them in the meshes variable in the inspector. Then in an Update function you could lerp from one UV to the next. Basically if you have 1 texture applied to the mesh the whole time, then it would go from looking like it did with the first uv, to what it would look like with the second.

The other option I gave would basically be the same thing as the one above except you’d modify the vertices instead of the UVs… You’d still export your mesh multiple times, but not changing the UVs, you’d change the shape instead. and then you could lerp from one mesh to the next, so it would actually change in 3d and not just retexture.

As for knowing which to go for, I wan’t really pointing you in any direction at first, just throwing some ideas out there. But if your worried about speed, all of these would be pretty quick. Bones would probably be the fastest, and UVs would probably be just slightly above vertices. But modifying the vertices would probably be the best looking because you can modify the meshes how ever you see fit right in blender. Bones would probably look pretty good as well, but its not always as clear how they are going to modify the mesh. Then UVs would look the simplest and the flattest.

Those are all the ways I can think of for animating the face, not too sure what you mean though.

Hey thanks.

Altering the mesh and leaping between it sounds simplest to implement and should give good results. I guess I could have LOD; and choose the best model for close-ups and facial animations.
Much appreciate your detailed response, plenty of food for thought :slight_smile:

Cheers