Python script do add objects (from folders)

Hi

As far as i searched, there is no answer to the question i will post now.

As we all know its possible to add object in the bge scene from other layers (ex. shooting bullets)

But what i want to know is:

Is there a way to add an object to specific coordinates using python, an object that is on a determinate folder in the operating system (lets say: mesh.obj in c:\3dmodels\blender\meshes) ?

And of course, to load its material/texture (ex: ‘mesh.mtl’)


An alternative, can we add an object from another blend file (append) using python, this way bringing its characteristics, like softbody, invisible, materials, etc?

You can link objects from other blends. This is a good way to organize the game especially when working in team.

For dynamic loading search for LibLoad.

Monster, in your opinion its better to implement a “only render an object if-n-while a player is in a certain distance” python script?

Or there is another way to improve the renders/fps in bge?

Lets think about it.
A) rendering an object needs processing time
B) not rendering does not need processing time
C) calculating if an object should be rendered or not needs processing time too

The BGE already calculates when an object needs to be rendered (frustum culling). So you do not really need to care about that.
But … as more objects exist within the scene as much more processing time C) needs.

Beside that there is more than rendering that influences the processing time. Logic and Physics need processing time as well. They will not care if camera frustum ;). The BGE can’t help here as there is no way to automatically know if you need physics/logic or not.

A good way to manage the things to use processing time is to suspend/remove everything that is not important to the current processing. This can be done with a LOD or similar.

Keep in mind it is only worth if the processing costs for managing that is much less than the costs saved.

What can you do:

Level 1:
LOD - increase/decrease visible details dependent on the distance to camera.

Level 2:
Physics Culling - suspend/resume physics processing dependent on the current focus. (E.g. it might be unimportant that a ball behind a wall is bouncing along the road … maybe not - you need to decide)

Level 3:
Object culling - remove/add objects that are on the border of the current focus (= last level of LOD)

Level 4:
Object streaming - load/unload game data of objects that is needed/not needed anymore

All over that: ensure you do not destroy the game logic when doing this.
E.g. the player still expects an power plant to produce electric power even when not visible or not even near.
other Example: imagine a large battle field: even if you do not look you expect fighters to win/loose/get wounded/die.

Even the game logic can be “streamed”:

  • You can have one logic when visible (e.g. dependent on the visible objects) = in-sight logic
  • you can have out-of-sight logic (which does not rely on existing game objects but an internal game model [e.g. Python code])

Such things are very important. Imagine you can’t simulate the trajectory of each single bullet within a massive fight. Even if just a minority is rendered.