Need animation tutorial

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Need animation tutorial

Post by vanblam »

Does anyone know where to find a really good animation tutorial using the blender plug-in? Like from start to finish lol. I'm so bad with animation right now haha
I do know the other way that Skugg posted, but for me that causes the model to become flat shaded and all the faces are split.

Thanks :)
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Need animation tutorial

Post by minmay »

For rigged animation
I suggest importing an existing rigged model. It doesn't really matter what it is. The reason for this is it's an easy way to get the correct object hierarchy:
SpoilerShow
Image
As usual, there's a game_matrix and a RootNode that you don't want to screw with. The standard animations have an additional node, local_srt, that is a child of RootNode and an eventual parent of every other node. This node isn't required, or really special in any way, but it makes things a lot more convenient - for example, moving/rotating/scaling the entire mesh would be a pain without it.
(Technically I lied about it not being special: GoromorgShieldComponent uses "local_srt" as the parent node for its visual effect. But most of your animations aren't for objects that use that component.)
Feel free to import a standard animation for this model, too, if it helps you think.

The mesh works as normal, just remember that it needs the RigModifier; don't remove or apply it. When you add a new bone, you'll need to add the vertex group for it manually, but that's easy enough. You also need to remember to add the node for it manually; just add another Empty object and name it the same as the bone. Similarly, if you delete a bone, go ahead and delete the corresponding vertex group and node.
The node hierarchy should match the bone hierarchy. In-game, the node will follow the bone - however, Blender won't show that; the Empty object for the node will remain stationary while you play the animation. In the standard assets, the origin of the node always matches the origin of the corresponding bone (including rotation and scale). I recommend following this convention, it makes things easier.

Once you have your bones set up the way you want, go into weight paint mode and paint your weights as normal. Note that Grimrock will provide strange results (different from the results in Blender) if your weights aren't normalized, so I strongly recommend clicking Normalize All before baking your animation(s).

The rest pose will be used ingame until an animation plays. If you have a playOnInit or a MonsterComponent, the player will never see your rest pose, so it's just for your own convenience. (When an animation finishes playing, Grimrock doesn't return the model to its rest pose; it just leaves it in whatever pose the final frame of animation gave it.) But if your model is something like the giant gate in the standard assets, for example, which doesn't play an animation until it opens, then your rest pose matters. Anyway, at this point you can export your model - just remember to check the "Skinning" box in the exporter so your rig and weights actually get exported. (The exporter also lets you choose between exporting in the rest pose and exporting in whatever the current pose is, but since it takes 0.5 seconds in Blender to apply the current pose as the rest pose, this is a triviality.)

If you want to use multiple meshes, that's possible too. Look at assets/models/env/forest_oak.model; it should be pretty self-explanatory.

For the actual animation part, you can animate your bones as normal - just remember to insert keyframes. Don't worry too much about inserting keyframes on unnecessary channels (e.g. the "Whole Character" option) because you can just clean those up in the dope sheet later. Once your keyframes are done, go into Pose Mode and use Pose -> Animation -> Bake Action. Leave frame step at 1, and don't try to use visual keying or clear constraints/parents.
You could export the animation at this point but if you are like me, you want to optimize a bit. You may recall that Grimrock 2's animation format lets channels (location, rotation, scale) for each bone specify a single constant value, instead of repeating the same value every frame like Grimrock 1 animations had to. This really helps with animation filesizes since most bones have constant scale and location, for example.
Unfortunately, if you naively bake the animation and immediately export it, the exporter won't take advantage of this: when you bake a channel with a constant value in Blender, it gets two keyframes in the baked animation, one at the start and one at the end. When the exporter sees this, it sees there's more than one keyframe, so it assumes it can't treat that channel as a constant value, so it repeats the same value every frame in the .animation file, meaning that you get bloated animation files. You can check the dope sheet to confirm this.
You could also use the dope sheet to fix it, by manually deleting the culprit keyframes at the end - but that's obnoxious. There's an easier way: when you bake the animation, bake with an end frame to 1 higher than you actually want. Then delete that final keyframe entirely (select it and Alt+I). Then export. You'll find that the exporter has now taken proper advantage of this feature.

The exporter uses the frame rate specified in the Render panel (the camera icon in Properties; the same place you set antialiasing, aspect ratio, resolution, frame range, etc.). Most Grimrock animations are stored at 30 FPS, but any frame rate is supported, so go wild with that if you want to.

Object animations
These are much simpler, to the point of being almost self-explanatory - just import one of the standard assets' secret buttons and the corresponding animation, and you'll see nearly everything you need to do. There's no complicated object hierarchy, just use the regular hierarchy you'd have for a non-rigged and non-animated model. Indeed, you can make an object animation for any existing .model file without changing the .model itself.
Everything I said about baking rigged animations applies to baking object animations, including the final keyframe problem. Some object animations are so simple that you might prefer to make them frame-by-frame (e.g. pressure plates and most secret buttons).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Need animation tutorial

Post by vanblam »

Awesome , thanks for that. I mess around with it for a while to I get the hang of it :)
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Need animation tutorial

Post by vanblam »

Question: When I start a new model do I just import an existing Grimrock 2 model and delete the stuff inside local_srt? ( When doing an animated model)
Then build my model with-in that?

EDIT:
Another Question: I've been importing different models just to get more of a feel for it, I'm confused about rotations, what rotation does everything need to be in when I
export it? Because the rigging and animation files don't import in the right rotation for me, I have to rotate all kinds of things just to see the animation work properly.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Need animation tutorial

Post by minmay »

Oh, right, I forgot to mention. Use Blender 2.72 for rigged Grimrock models; the plugin has an issue with transforms in later versions for some reason. You shouldn't need to change object rotations/scale if you do that.
vanblam wrote:Question: When I start a new model do I just import an existing Grimrock 2 model and delete the stuff inside local_srt? ( When doing an animated model)
Then build my model with-in that?
I prefer going into edit mode of the mesh and deleting all the vertices, since the mesh already has all the correct transforms and parenting.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Need animation tutorial

Post by akroma222 »

Great reference :D :D
Vanblam - thanks for asking
Minmay - thanks for answering
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Need animation tutorial

Post by vanblam »

Odd when I export the model the normals are backwards... uggg.. I have to invert the normals every time, or when I'm done?

EDIT:
lol sorry, I have another question. How do I get the nodes to be in the right location and rotation? I noticed that it does matter where they are and what rotation there in.
Or does the model "need" to have an animation file for the object to be set right( rest pose) in the game?
I made a door with 6 moving parts, I have all the vertex groups, bones and nodes set and ready. The bones move the right parts from weight paining ( I did normalize all as suggested) and the only thing
left to do is create the animation. But because I don't have an animation set up for it yet, will that cause it to be weird in the game?

EDIT again lol:
Or is there a "specific" version of blender I should be using? I rolled it back to 2.72b.
Sorry for all the newb questions, I just want to learn this, I have so many ideas floating around and its frustrating that I don't know how to animate lol.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Need animation tutorial

Post by Isaac »

vanblam wrote:Odd when I export the model the normals are backwards... uggg.. I have to invert the normals every time, or when I'm done?
I'm not certain of your exact circumstance, but the exporter does offer a transform Normal option that takes the game_matrix into account. Does this fix your issue?
Image
How do I get the nodes to be in the right location and rotation? I noticed that it does matter where they are and what rotation there in.
Or does the model "need" to have an animation file for the object to be set right( rest pose) in the game?
AFAIK the nodes should be centered relative to the zero x/y/z coordinates, unless you don't want the model to appear where the object is placed in the game.
In my case, I didn't, and so I moved them to the starting position of my animation, so that the animation ends where the object is placed.

**Edit: Before you try this yourself, let me get home, and load that animation, to double check the nodes. (In case I'm remembering wrong.)

Image

**The easiest way to isolate the nodes is to hide everything else, and then select all.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Need animation tutorial

Post by minmay »

2.72b is what I use for rigged Grimrock models (again, I'd love to fix that bug in the script but I really can't find the source of it!).
vanblam wrote:Odd when I export the model the normals are backwards... uggg.. I have to invert the normals every time, or when I'm done?
Careful! It may be the entire model that's backwards, not the normals. See the "What to do when this happens" part of this post (I hate to direct you to that same post again but it does deal with this issue).

In 2.72b with the most recent version of the importer, I have never had a model import with the wrong transformation; you shouldn't need to change the rotation/scale/etc. and you definitely shouldn't need to flip the normals.
vanblam wrote:lol sorry, I have another question. How do I get the nodes to be in the right location and rotation? I noticed that it does matter where they are and what rotation there in.
My fault for not elaborating on that...this is the reason I said it's easiest to make the nodes' origins match the corresponding bones' origin. Select the bone in edit mode and copy its origin location, rotation, and scale, then paste them on the node object in object mode.
vanblam wrote:Or does the model "need" to have an animation file for the object to be set right( rest pose) in the game?
No, rigged models work fine without an animation. For example, the giant gate in the standard assets (that appears at the entrance to Twigroot Forest and again at the entrances to the bog and cemetery) doesn't play an animation until it's opened.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Need animation tutorial

Post by vanblam »

minmay wrote:Select the bone in edit mode and copy its origin location, rotation, and scale, then paste them on the node object in object mode.
Ahh I see, the only problem is, you can really only get the exact location. Rotation and scale are hard to match if your bones are in an odd positions. I noticed the location you want to match is the "Head" of the bone, but the roll is the only thing I see for rotation, that's 1 out 3 possible rotations. Scale seems to be judged by the distance between the "head" and the "tail". Is there a different way to copy the complete origin of the bone?
Post Reply