Hello Everyone,
My name is Zalán (from Hungary).
I would like to introduce a little script to you.
As we know, the main BGE loop runs only on a single thread. This thread manages everything, so it’s not surprising if it’s over exhausted sometimes. The bigger games requires Level of Detail, to keep the scene low poly. It’s easy to make a LOD algorithm, but it could be CPU expensive… especially if every object needs to be replaced in the scene.
Solution?
- Make a separate thread just for the logic.
- Only one, object independent LOD script, which examines and handles all objects in the scene, and make decisions if they needs to be replaced or not.
- Make this LOD script run on the separate thread.
Result:
ZLOD - Multithreaded Level of Detail calculation script
Usage with Object’s game properties:Every Objects in the scene can have:
“2nddist” - distance to switch to the second detailed mesh (not necessary)
“3rddist” - distance to switch to the second detailed mesh (not necessary, won’t work without 2nddist)
“LODdist” - distance to turn the object invisible/visible OR load/unload it when Procedural Loading is turned on.Just for the Owner of this script:
“Procedural Loading” (Boolean) - If it’s true, Every object with the “LODdist” property will be dinamically loaded from an inactive layer. (depending on it’s distance and LODdist)
“Use LOD percentage” (Boolean) - Enables the execution of the Graph_INIT.py which will align all of your object’s LOD distances to the percent you gave (in the config.txt in the same directory, or if it’s not exist, the “userVar” in “Graph_INIT.py”) (Level of Graphic)
RULES of use:
1: Just the base objects needs LOD properties.
2: If you use 2nddist and/or 3rddist, your object’s mesh’s name must end with the number of level it use.
eg.: Sphere.L1 (prop owner active object’s mesh name)
Sphere.L2 (inactive object’s mesh name)
Sphere.L3 (optional inactive object’s mesh name)
3.: If you enable Procedural Loading, please make sure all of your objects with LODdist property are located in an inactive layer (else if they are out of LODdist, they will be completely deleted and can’t load them again)
4.: If you enable LOD percentage (level of graphic) you can adjust ALL of your LOD distances with a single number (percent). By default it will be loaded from the “config.txt” in the same directory. But if the file doesn’t exist, the script will load the value from the “userVal” located in the Graph_INIT script.
5.: Don’t worry… this version is backward compatible, and can be work in the exactly same way as it’s Predecessor worked.
Importing to your scene:
1.: Copy both ZLOD_MT.py and Graph_INIT.py files from my .blend to your.
2.: Create an empty.
3.: Create an always sensor to your empty. Enable pulse mode in it. (TRUE level triggering)
4.: Attach a python module controller to it.
5.: Write into the controller: ZLOD_MT.init
6.: (optional) If you want, create LOD configuration properties for the empty, like: “Procedural Loading” or “Use LOD percentage”
7.: (optional) If you enable “Use LOD percentage”, please make sure you have Graph_INIT.py attached to an always sensor WITHOUT pulse.
8.: Voilà! It’s done. Next time you start the BGE it will automatically starts in a new background thread and begins to look for object with LOD game property. (2nddist,3rddist,LODdist)
The LOD algorithm is based on SolarLune’s BGHelper’s LOD solution.
Please feel free to improve it, and/or give advices and new ideas.
Version 0.3 (Minor improvements)
ZLOD_MT_0.3.blend (3 MB)
Version 0.2.2
10.02.2013
(LINK BROKEN) (2,9 MB)
Version 0.1
29.01.2013
ZLOD_MT.blend (540 KB) (0,5MB)
Version optimised for LibLoad by @iFlowProduction
http://iflowproduction.de/blender_opensource_dl
***Changelog:
0.2.2 - Fixed object’s orientation and scale bug during Procedural Loading
0.2 - Added Procedural Loading, Level of Graphics (LOD percentage), Some bugfixes, Thread optimization
0.1 - First release
***Work in progress:
- Appropriate thread shutdown (if the game killed before the thread, raises an exception)
- Distance templates (So you won’t need to add 3 different prop)
- Object size priorities (So bigger objects will automatically loads at a larger distance than smaller ones)
- Physics LOD
- Object culling
- Bugfixes
- GUI for much more easier use.
***If you will use my script, I would be glad, if you mention my name somewhere