Jump to content

Animated Meshes (Blendshapes / Shapekeys) - KEAM Inside Look


Recommended Posts

This thread will instruct you on how to create Kerbal parts using animated meshes, known in Blender as Shape Keys and known in Unity as Blend Shapes.

 

Disclaimer: This guide assumes you already have a basic understanding of modeling, animation and creating simple Kerbal parts.

 

Why??? The benefit of using animated meshes over regular scaling or rotating of a part allows you to yield complex animations from a single object, regardless of its shape. 

In the Kerbalverse, these parts are most noticeable with inflatable habitats. To my understanding, the only few on the market are those created by myself. With that said, I am hoping this will encourage others to take advantage of our new ability to use Blendshapes in Kerbal thanks to the hard work of @Shadowmage and his Textures Unlimited plugin, which allows for the loading of Asset Bundle-based models. Asset bundle based model loading is currently the only way to accomplish having these parts in Kerbal.

 

For example, it would not be possible to create the egg-shape of the KEAM (BEAM module recreation) if I were to just scale a cylinder. The end resulting animation and shape would not be appropriate.

See wireframe example of the KEAM's expansion using a single object:

NWPQfjB.gif

 

To start, create your model as normal. Create your desired animation with your object using Shape Keys (if Blender) (please Google for simple tutorials on this if you are unsure about animating with Shape Keys. The idea is very similar to animating a regular object. Where you would hit the I key for keyframe over the timeline, you instead do it over a new Shape Key on the side menu).

YIIlxOH.png

If using Blender, it's best to save the .blend file within your Unity project location and work from that file within Unity. If you prefer or require FBX format for any various reason, ensure you have the "Baked Animation" option checked under the Animation tab in your export options. Check "Key All Bones" if using bones for anything.

gPCL2WP.png

Inside Unity, you only need to verify your BlendShapes numbers under the Skinnded Mesh Render component of the animated object match the numbers in Blender. Warning: I noticed some issues above 9 Shape Keys where it seems that Unity only recognizes a total of 10. Avoid going above 9.

wQvUEBd.png

It is very important to note, if you are using a model that contains any sort of part triggers, layers, or tags, like an Airlock or a Ladder, is is MANDATORY that you set up your part tags EXACTLY as shown in the following picture or they WILL NOT WORK when loaded in Kerbal:

GWfut1D.png

The final result on your model must still contain the proper tags and layers, for example with an airlock / hatch:

fsPGX9P.png

To create the prefab ("Asset Bundle object file," as I call it), simply drag the ROOT part of your model FROM the hierarchy into the project folder window below. This action will create a prefab file.

Select this prefab file so that you are viewing the preview of it in preview window. There is an AssetBundle "tag" location on the bottom of this window. Select the dropdown and create a new name for your asset bundle.

Click KSPAssets on the top toolbar of Unity and select Asset Compiler.

3mhCfx0.png

Click "Create" for your asset bundle, followed by Update and then Build. This outputs an assetbundlename.ksp file to your Unity project's "Asset Bundle" folder, one directory up from your Assets folder.

yekrNgj.png

The final step is to rename your finished asset bundle file to have an extension of .smf instead of .ksp

Finally, drop your .smf file into your Kerbal addon folder inside GameData along with its textures and config file and as long as you have Textures Unlimited installed, the .smf file will be loaded like a normal part.

 

I hope this can be of great help to the community or even just one person as I would love to see more complex animations in the Kerbal universe!

Thanks!!!

 

 

 

Edited by bcink
Link to comment
Share on other sites

21 minutes ago, DMagic said:

What's the difference between blend shapes and using an armature animation? Or maybe a better question is what can you do with one that can't do with the other?

My understanding of armatures is such that they work with bones and allow you to "join" multiple objects in an animation to reach a desired rotation / location with the parts as shown here:

of4L0d3.png

In the above example the objects themselves do not change in any fashion, only their location and rotation. The objects are parented to the armatures / bones and perform the rotations based on the joint locations. 

Blend shapes would allow the objects themselves to change. It wouldn't make much sense in the above example to use shape keys. The below example is another demonstration of the shape keys being used on a single shape (from the double-stack hab with inflatable top from new M.A.H. lander pack). Notice the original shape of the expanding top is both a concave and convex single object. With the shape key animations, you are able to morph the actual mesh through animation to reach it's desired final shape. I don't believe something is possible like this with the use of armatures / bones.

vqB5Qfu.png

I hope that helps a bit? Let me know otherwise.

Thanks!

Link to comment
Share on other sites

They are two different ways of achieving the same thing - that is, changing the shape of something. I know that for character rigging, specifically facial rigging, people usually decide whether they want to accomplish it through bones or blend shapes or both.

It's worth noting that for things like engine gimballing, etc where the animation is dynamic then bones are the way to go. Blend shapes are better for things like these inflatables where the shape and deformation don't lend themselves to creating an armature.

Link to comment
Share on other sites

Armatures aren't usually used for separate objects like that landing leg, assuming those are separate meshes (the little extending foot-pad cylinder definitely is, but the others don't necessarily have to be). That example is using an Inverse Kinematics rig (that yellow bone has an IK constraint) to make all of the joints move together in a way that makes sense. Unity doesn't understand those bone constraints, but this type of animation can just be baked (the location, rotation and scale of all the deform bones keyed at each frame) and it will load into Unity and KSP just fine as a SkinnedMeshRenderer.

Normally you would rig a single mesh to an armature, then assign weights at each vertex to determine which bone alters the position of which vertex (this can be mostly done automatically, or in groups of vertices at a time). You can blend together multiple bones at each vertex, but Unity limits it to the four with the highest weights. 

The reason I'm asking is that I think a similar effect might be possible using only bones. It isn't necessary to have bones be linked together as part of a single chain like you see in that leg example. In the bone properties you can uncheck the "Connected" option which will allow a bone to move freely, it will still inherit the parent bone's rotation and scale (you can uncheck those in Blender, too, but Unity doesn't accept that and will always inherit parent bone rotation and scale).

So you might be able to make that inflation animation by (assuming the y axis goes to the right in your example) translating the bones to the right and scaling them up in their x and z axes. Scaling can be tricky to work with in bones, so you might need to make the bones siblings in the hierarchy, rather than a chain of unconnected bones.

That might be more trouble for this example, but for anyone not wanting to rely on outside dependencies it could be helpful.

Link to comment
Share on other sites

3 minutes ago, DMagic said:

That might be more trouble for this example, but for anyone not wanting to rely on outside dependencies it could be helpful.

Great insight. Had no idea about weights (my skills are not very advanced).

True on that example as well. The final release had no bones even and just used constraints in this case as well. :)

Link to comment
Share on other sites

I whipped up a quick example:

rRMhNDp.gif

Each double ring on the cylinder is weighted for the bone that starts at that ring (so the first double ring on the left is weighted to the second bone). Then I uncheck "connected" for each bone in the chain and just translate and scale in the X and Z axes. I also unchecked inherit scale, so this would not strictly work in Unity, but as I said above, there are workarounds. 

Obviously, if you are going to use a dependency anyway then you should use what is easiest. But if you or someone else wants to, you can make similar inflation animations with just bones.

When you select one of the vertices in the cylinder the setup looks like this:

cxhrfHe.png

On the left, in the properties tab, you can see the Vertex Weights category, this vertex is set to Bone.002 with full weight, you can mix other bones with values between 0-1 (if only a single bone is selected then any value > 0 will be full weight).

The Vertex Groups window on the right shows the available weight groups, these can be generated automatically when you parent a mesh to an armature, or you can just add them. The names of the groups match the names of the bones. You can select a group of vertices then use the "Assign" button to assign vertex weights to multiple vertices at the same time. You can also paint on vertex weights by changing the mesh from Edit Mode to Weight Mode.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...