Level of Detail script.

Demo of script I made last night. Standalone Level of Details script for Blender Game engine. Not true level of detail as all it does is replace meshes.

However it allows for easier implementation and multiple different levels running at the same time.
At this point all it requires is for the main object to have a property on it and for the replacement objects to have sequential number. E.G. Cube (main object). Cube1,Cube2,Cube3 (replacement objects.)

Example of calling the script:

import bge
import LevelOfDetail as lod

def main():


hasLOD and isLOD are the property names on the cube and shape.

distance are the distances to change levels at from lowest detail to highest detail.

If they had the same property name on them then they would both change levels at the same time. and only one line would be needed to affect both objects.

First off cool!

but couldnt u do this using logic bricks with the replace mesh actuator?

How would you measure the distance between when zooming out with logic bricks though?

It could be done with an inverted near sensor (in theory). So, as long as the object is near the player, the mesh is not replaced- however, I imagine it would be spaghetti hell (plus I would imagine there are more problems to take into account) so I would prefer the Python option.

Thanks for your script jayfelsman!

How would this work for complex meshes, like characters?

The good thing about using scripts here instead of logic bricks is that you can also introduce other actions such as making the mesh invisible beyond a certain range. I’ve used similar scripts in my rojects so far with great results.

I usually use:
high res mesh > low res > very low res / billboard > invisible

heh thanks for the interest. I wasn’t really expecting much response. I was just curious as how simple it would be to do.

I wanted something that didn’t care what it was attached to. For example I attached the script to the camera but it could be on any object in the scene . The objects had no logic bricks or scripts at all. The only thing it had was a property name.

The other thing I wanted was something that would allow different Levels of Detail working at the same time.
And different amount of objects.

To take the example in my first post

You could do this.

import bge
import LevelOfDetail as lod

def main():


The objects with property ‘isLOD’ only has 3 Levels, where ‘hasLOD’ has 4 levels. As well as each having different distances.

I am going to finish off the script and put in some error handling. At the moment it consists of like 6 lines of code haha.
I might turn it into something better. Like adding an option for the final one to be Invisible. :stuck_out_tongue:

Haven’t been able to work on the script since I made it. Was wondering if anyone wanted any features added to it to expand it’s functionality.
Feel free to drop some suggestions here. Hopefully I will find a few minutes to work on it in the next few days.


How about, instead of replacing the mesh, it acts with a subdivision modifier, and lowers the subD?

I thought about trying something like that. However that’s rarely any use as you might add a lot of different parts to it.
Example :
A cube with low res textures could be used for a house in the distance. But up close it would have higher res textures and more poly’s for things like windows doorways etc. Just subdividing would not add the extra shapes required.

I will try and do a more real world example.

Bit more of an example.

Again single code


2 Objects with same property ‘hasLOD’ . I loaded the 2 objects(houses) multiple times in the scene. This also shows that it works with objects dynamically added.