Scenegraph optimisation

Hi All,

I was wondering if anyone has any tips for scenegraph optimisation? I’m currently at 25% with relatively few assets.

I have 5 rigged characters and about 20 rigged birds. When I remove the birds from the scene I save barely anything, but when I remove the characters I save 15%. Bone count works out about the same for characters and birds.

Could it be that IK’s and constraints are slowing it down (as they’re on characters but not birds)? If so, what’s the best way to resolve it?

Interesting… removing all constraints and IK’s brought scenegraph down from 25% to 3%.

What’s the best way to go about baking this kind of thing?

Posting in a a catchy thread or asking a moderator to post it :slight_smile:

First, it would be helpful to post a blend. This way others can look at it to see if there are any silly mistakes and I can also run it through a profiler to see if the BGE is choking on stuff it really shouldn’t be. Also, you could give iTaSC a try over the legacy solver. I think it’s supposed to be faster.

Hmm, it’s difficult to replicate outside of my 200mb scene.

I removed all IK’s and that eliminates 90% of the problem, so I’m going to try the ‘bake constraints’ script, followed by ‘clean animation curves’. I’ll report back :slight_smile:

As far as I know IK in armatures is an performance eater. Lots of bones are performance eaters. A lot of vertexgroups are performance eaters (especially if the have smooth weights).

You should have a look on the details of your armatures/skin meshes. If you really need all the details, or if you could go for less.

A 200 MB file for one scene is huge. All this data must be processed. You might want to shrink the amount of data as well.
Baking and IPO recording produces an awfull lot of data. You might want to reduce the number of keys in your curves.
Usually you can form the curves with a few Bezier interpolation mode keys. This reduces the filesize dramatically and provides you with better controll over the curves.

I hope it helps

Perhaps you should try optimising your scene a bit.

For example… You say you have 20 birds. If they all have identical meshes and textures then you should be reusing data blocks between them instead of having unique but identical meshes and textures.

I don’t want to teach granny to suck eggs so I’ll just stop there. If you need help optimising a scene for file size then some research or a new thread might be best.

Thanks for the help guys!

I’m not too worried about filesize, we’ve got a lot of high-res reference images, unshortened audio tracks etc. It’s messy but it’s going to be cleaned out in due course. Problems with library linking has caused a fair bit of clutter - constraints not working across linked files, bone parenting impossible on library linked characters etc.

Actually… if I have loaded an image into a scene for reference, and it’s not used on any models as a texture or for anything else, does it use any resources? Also an unused linked group for example?

Edit -> Also, if I’m library linking lots of objects that share a material, what’s the best way to deal with that? I have a new material per file atm, should I just have all the assets in a single .blend so they can share materials?

Mainly using library linking, when that’s impossible I’m using instancing.

Sounds like you’ve got instancing covered. :wink:

An option for reducing the ik overhead is to ‘bake’ the ik actions into regular actions. I’m not sure if anyone’s written a script for this yet, but I came up with the concept awhile ago. If you’re using ik to place limbs at targets in realtime then this won’t help. However, if the ik is there to make the creation of actions faster and easier (and give better results in a shorter development time), then a script could keyframe the bones in an ik chain on the same frames that the ik target is keyframed and the ik would not be needed. If this is relevant and you want me to share my thoughts on this then just say in this thread.

That is EXACTLY what I’d like to be able to do :smiley:

Did a bit of digging to see if this had been implimented yet, but it seems that there is currently nothing available so it will have to be a homebrew solution. Action bake features were removed in 2.46 due to functionality and legacy issues and I can’t find any sign of a recent official or community solution.


Bake features have been removed (including the ‘BAKE’ button on the header). This is because they were not really functional anyway, and should really belong exclusively in the NLA (and/or 3D view). If and when they are reimplemented, they should not be added back to the Action Editor.
Please forgive the verbosity of the rest of my post! It’s a pretty much complete summary of my thinking on this issue and effectively amounts to a script development proposal. :wink:

My proposed workflow would be something like this:

  • Create the ik action as usual
  • Run the script to create a new action that is the same, but now has no ik, only fk.

Here are my rough thoughts on how the script would run:

  • Analyse the armature to find bones that are ik targets and add them to a dictionary as keys with empty lists as values.
  • Find the bones that are controlled by each ik target (possibly by using chain length and bone parenting to identify them) and add them to the list in the dictionary with the ik target as the key.
  • Create a new action with the same name as an existing action but with the prefix of suffix FK (forward kinematics) so the name is unique.
  • For each ik target in the dictionary, scan the action channel for that ik target looking for keyframes.
  • When an ik keyframe is found, set the animation to that frame (to deform the armature using ik).
  • Insert keyframes to the new FK action for all bones in the ik chain (retrieved from the dictionary).
  • Repeat No 5-6 for the whole action.

This should create a new action that is identical, but now has no ik. The armature could be duplicated and the duplicate could have ik targets removed if this is necessary (needs testing).

This is just my thoughts on the subject and there might be some issues with the actual implimentation. I am not much of a rigger or animator which is the main reason that I never got around to writing this script.

Possible issues:

  • It might not be possible to add keyframes to action2 when the armature is already posed by action1. This would require some kind of workaround such as:.

  • Store bone matrices when posed by action1

  • I’m not sure whether it might be possible to ‘lock’ an armature in position so the bone matrices would not need to be stored.

  • Switch to action2.

  • Set bone matrices then keyframe the new position in action2.

  • Switch back to action1 and find the next ik keyframe.

  • If ‘locking’ an armature is possible then it would be ‘unlocked’ after switching back to action1

  • Rinse and repeat.

  • It could be difficult to find out what bones are in an ik chain. This would require some kind of processing that depends on the structure of the armature:

  • Assuming that the ik target head is positioned at the tail of the first bone in the ik chain when the armature is in rest position, this could be used to identify where the ik chain starts.

  • This would depend on the structure of the rig.

  • Appending/prepending “FK” to the name of the action stands a chance of hitting Blender’s 21 character datablock name limit. This would have to be caught and dealt with in a sensible way.
    Hope this is of interest. :slight_smile:

A script/addon such as this is requested and searched for from time to time by people on the forum and would definately be of use to everyone who makes games with bge. However, my free time is pretty much packed out with stuff that I really should be doing and with stuff that I get distracted by so I’m probably not going to get round to coding this any time soon (unless it distracts me ;)). It’s been on my todo list for quite a while, but I keep getting distracted by researching stuff for my projects and by life™.

My ragdoll project has improved my knowledge of accessing data from armatures though so this script/addon is a lot more doable for me than it was previously. However, I have absolutely no knowledge of the animation part of bpy.

After some thought I’ve kinda been inspired to do something about this. A lot of people would benefit and I will probably need it at some point myself.

Could you upload a fully rigged and animated character? I’d be ok with any NDAs that you want to present or maybe you could make public an animated prototype model that demonstrates the rigging that you’d use in your project?

I’m not offering any guarantees, but this might not be as complicated as I first thought. The script proposal in my previous post seems pretty sound and my simple tests indicate that it’s very possible.

If you have a scripter on the case already then then this is excellent and I hope that they share their results. :slight_smile:

Wow FunkyWyrm, thanks for all the great info!

We would code it in-house, but we’re only experienced with the game engine side of things and currently working on a bit of a tight schedule.

Don’t worry about NDA’s, we were going to release all our assets for free at the end of the project anyway.

I set up a basic scene with a rigged dog and some AI and you can see that scenegraph is at 6%. Arrow keys to interact.

Have you looked at the bake constraints script that comes with Blender? It looks like it may do what I’m after, but it just crashes for me :frowning: