big scene example blend.

Quite a few people have been asking about having larger levels in blender so I thought Id try make an example. - Though maybe other people have done this before?

This could be easily re-used for different levels and the code is fairly simple and it wont conflict with other objects directly in the scene.

  • A text file stores objects name/location/rotation - can be 1000’s, in this example 7200, but Id like to try 100,000+
  • Included is a script that generates the “level.py” file from a blender scene so you can keep a complex level that is used to make this file.
  • While the game runs the logic objects location is used to add/remove objects from the big list based on how close they are.
  • In the demo the script runs on every logic tick to show its quite fast, but can probably run less often (10-30 tics depending on camera movement speed).
  • In the demo the radius is set to 100.0 so you can see popping, set to a higher value for smoother results.
  • This should scale well to a large set of objects because it uses a KD-Tree for lookups.
  • This is limited to managing objects in background layers, its not doing anything tricky like streaming in data from a server which would need some serious C++ :slight_smile:

Edit, I think this script is ideal for placing many small objects in a level. like debris/grass/trees, the way it works means that its limited to static objects.
Id need to do some more tests but it can handle more objects then blender does, easy over 1000 assuming your not having to display all those at once.
If this script proves to be a speed hit can also rewrite in C in the Geometry module.

Edit tested to work quite well with 10million objects, still giving high framerates on a debug blender build with no optimizations.

Hello
very impressive,even if you forgot to pack the texture! :wink:
It runs at 80FPS on my “old” machine ( gfx 75OO)
Thank you for sharing!
Bye

Yeah great!

The logic consumption is very small oO (0.3 ms with tickrate 1). Building it directly in C would also be nice!

150 fps on GF 7600GT in 1680x1050! Thanks for sharing it!

Wow… I will be using this. Thanks!

Does this not include the textures when you put the objects in the text file? None of the trees have textures.

thanks for the great resource!

I get an error, on the import of GameLogic when I press ALT-P in the code window using 2.48.1 and the latest 2.49. On Windows XP.

How are you guys viewing this scene?

great! 57 fps
Blender-2.49 -msvc- Py 2.6.2 SSE2 LAA
Intel core 2 Duo processor T8300 2.4GHz - 4GB DDR2 GeForce 9500M GS TurboCache - OS Windows hasta la vista

But trying with UV-textured objects they are added without texture.
And if I use grouped objects they are not added at all.
Is a bug in this 2.49 or what?

  • 2.49 only.

  • No textures was intentional, (You people focus on looks way too much!), I removed all textures to keep the file size down. Before this GLSL textures worked fine with the test.

As it was, setting up the level took me longer then writing the script.
If the script is slow, running every 30 tics should be more then enough (twice a second). if you get popping you can keep the tic rate down but increase the radius a bit.
Even 10 should be ok for fairly fast moving cameras.

There is no limits to the number of different kinds of objects you can have - I did 2 types of tree’s so it looks like its only for trees but you could do buildings, trees grass fences etc.

Blender (not the BGE but just editing objects copy/moving about) chokes at around 10’000 objects for me so Ill need to procedurally generate for the 100’000+ tests.

The Script will make the “level.py” file form every Object which is in the scene right?
So at first you have to build a complete scene with all trees, plants, buildings and so on, then run the build script. After that you can delete all objects, except the ones one the other layer?

@moerdn, pretty much.
for this I found it best to have all the objects in another scene, this way it wont interfere with the load speed of your game by converting 1000s of objects on unseen layers,
removing them (like I did in my example), isnt good if you want to edit the objects again… I only did it for download size.

Someone could write a script to load the text file back as objects, but keeping in a backup scene is not so hard.

To begin the game, press P over the 3D viewport, or start the game from the Game menu in the infobar.

Interesting script, it works very nicely, no framerate drop when I crank the radius up to 300.

How are you placing the trees? I see that each one has a position (x,y,z) in the level.py script. Im assuming you didnt do them all by hand? How do you mass produce all the positions? (especially on such a randomly leveled terrain)

Also a more concerning issue for me is the max viewport issue (limited to 10,000km in the 3D window, and 5,000km in the camera view)
Making decent sized scenes in blender for games is next to impossible with this restriction, unless everything is scaled down heaps, which ruins the physics, as one blender unit = 1m in game. A 20m long object takes up 1/3 of the 3D grid.

Are u guys planning to do anything with this? Im planning to do a large space game, so having realistically sized planets is very hard, most of the planet is clipped out of view when you move a small distance away, I’m trying not to even think about stars at the moment. LOD stuff will help, and thats no problem, I have all that planned out, its just fitting the stuff in the BGE view distance which sucks.

@AD-Edge

  • level_write.py is a script included that writes objects in a scene into level.py, it runs in blender (Alt+P in the text view). Of course this file could be generated some other way too. - as mentioned before you can keep these objects in a separate scene so you can keep editing the objects and dumping their locations when your done.

  • as for floating point limits - if you have a 20m ship best scale by 0.1 and make it 2m. Real camera limit is 500,000 (set the grid size in the 3D view to 100.0). But these are not ideal solutions I think a proper solution could store a much bigger world in a database and load in parts to an area closer to 0,0,0. This isn’t a problem Im interested in solving right now.

  • Planning on doing anything with it?.. just wrote as an example so no real plans… but there are some possible improvements if people find this useful I can look into them.
    ** Support for multiple viewports - trivial.
    ** Radius/Bounding-box - so large objects are not clipped only by their center points - tricky.
    ** Optimization to re-use objects instead of adding/removing the same object - easy, but might not be faster.
    ** KD-Tree support for adding and removing elements at runtime, and moving objects about, allowing for AI characters to move about within the KD-Tree for instance. - tricky.
    ** backup/restore object properties so an object thats added in can have the same props as when it was last removed. - trivial.

Thanks for the feedback and tips, they should be very helpful.

Thats ok :wink:
Its my game, so my problem, I was just wondering if anyone is working on it. I have a few ideas I’m in the process of testing out, so we’ll see.

Handy script tho, I’ve bookmarked for later use, I can see myself using this.

@ideasman
I am tryng to understand your script
In function makeChildren() at line 82 you have an if statment without condition.
Is made intetionally or you have made this for debug and you have to restore the condition?

i’m doing this with a space game i am currently working on and it works quite nicely :).

SOLVED: You said something like “only works for objects in background layer”. Now it works fine :slight_smile: Thanks!

Original Problem:

I build a small test-scene, where I just copied the cube 100 times and then randomized their location. Then I start “level_write.py”, it works well.
Then I start my GE and I get an error in level.py:

Python module not found - controller “cont2#CONTR#3”:
Traceback (most recent call last):
File “level_manager.py”, line 190, in <module>
File “level.py”, line 19, in <module>
File “level.py”, line 13, in init
KeyError: ‘Cube.095’

I attached my file. Can you please have a look? Would be nice, if I can use this script!

Attachments

level_managing_prob.blend (450 KB)

I think I actually prefer the vertex painted trees without textures, could just be me :stuck_out_tongue:

its nice to see that your exporting the objects to a python script in the form of an array.
there are many ways that you can actually export textures as well ,either write the textures as code to a python script as well .

funny thing it gave me roughly 3fps must be my ati card though it doesnt happen with normal scenes