Another Lod setup written in python

the area is (5km x 5km) and the whole area if filled with grass and trees that is dynamic loaded and unloaded on the fly.

ca 10000 trees
ca 140000+ patches of grass

filesize: 50mb
http://15b.dk/blendfiles/lod-dist-spawn-test.blend

1 Like

With the blend stable 60 fps, However it takes a while to load(on a decent system, open blend and playing the blend), other then that works great.

added a few more plants

“However it takes a while to load”

this is due to the size of the area, all placements of the plants and grass is calculated every time it is started.

I know, just wanted others to let know that it can take a while to load up. Took me roughly 7-10 seconds, but i bet with older pc it can be 30+, should not be a problem anyway, if this getting used in a game it should have a loading screen anyway.( made by the user)

i think its the modifiers on the landscape that takes it so long. the bge doesnt like modifiers.

i don’t see much of a difference in load time after i have applied the modifiers.

is this based on the kde tree concept? I need to check this out…

yes it uses kd-trees and sets to minimize the number of objects it loops over.

yes, I meant kd, not kde…
I checked this out before yes it runs amazingly well…
BUT: almost impossible to work in blender with that many objects…I cannot even make any adjustments to your scene on my computer without waiting 30 seconds between clicking, mouse movement etc…

you could improve it if it also set up the scene dynamically so there is not so much stutter when you are level editing…

this is not to say it’s bad…it’s awesome…I just also find it impossible to work with :slight_smile:

fixed the lagines when editing and it loads faster to, plus the filessize is 14mb smaller.

This a great resource. I am currently using the random assets placer v3 which is very well commented so it’s easy to figure out how it works. But it’s random …
This LOD setup is beyond my scripting levels, any chance of uploading something like a tutorial that will explain how this works?

the principles behind it is pretty simple.

here is an example.

lets say the brown circle is what the player can see when he starts
and the blue circle if what he can see when he move to a new position
so when the player starts out all the objects (the black dots) inside the brown circle are drawn and stored in a set ( https://docs.python.org/3.6/tutorial/datastructures.html#sets )
and when the player move to a new position then all the objects inside the blue circle is stored in a set
so now all the objects in green area needs to removed (outside view distance) and objects in the orange area needs to be added and all the objects in the blue area should be ignored
and to get all the objects inside the green area you have to subtract the second set (objects from blue circle) from the first set (objects from brown circle) and to get all from inside the orange area you do the opposite (subtract first set from second set)
sets

this is the code that does that in the blend

    oldset = own["oldset"]
    
    newset = set([])
    
    treelist = own["kd"].find_range(player.worldPosition, maxdist)  
    
    for itm in treelist:
        co, index, dist = itm
        newset.add(index)
        
    a = newset - oldset
     
    if len(a)>0:
        own["added"]=len(a)
        newplace = scene.objects["newplace"]
        
        for i in a:
            tree = own["treelist"][i]                  
            
            newplace.worldPosition = tree.worldPosition
            obj = scene.addObject("oaktree",newplace,0)
            tree.obj = obj
               
    a = oldset - newset
     
    if len(a)>0:
        own["removed"]=len(a)
        for i in a:
            tree = own["treelist"][i]
            
            if tree.obj != None:
                tree.obj.endObject()
                tree.obj = None

    own["oldset"] = newset

i hope this answered some of your questions.

1 Like

It did, or at least i believe it did!
I guess that you have made a terrain with a particle system (the trees), made the particles real and then you somehow stored each position of the trees in treelist.py, and then deleted all trees.
By calling this list, the tree positions are set and then the lod system shows only trees in range.

I can’t figure out what the idgenerator.py script does and how can i use this lod system to my own project…
I also can’t figure out how grass is generated.

I am using blender 4 years now and i have made this simulator:
https://www.youtube.com/watch?v=s6WgkJXXg5s

It is using the random assets placer to display some of the assets but its random…

I really like BGE but its hard to create something good.
Thanks for your time.

the idgenerator.py script generates random unique strings like this “55d1194e0731d94d6459144740ffeb6a” and i use them as keys or identifiers.

Thanks for your help. One last thing: How treelist.py is made?

easy, my scene started out with all the trees in it, i simply looped over all the trees in the scene and stored there position in a dict and after that was done i simply stored that dict to disk.