Initialising meshes from another .blend

To improve FPS aswell as load speed in my game Worn Tires I want to load different car meshes(different tuning/models aswell as paints) from another .blend with all theese(later) hundreds or even thousands of meshes. How can I do it?

http://www.blender.org/api/blender_python_api_2_75_release/bge.logic.html#bge.logic.LibLoad

And… Is it


carMesh = bge.logic.LibLoad("..//Assets/Meshes/Meshes.blend", "Mesh", ...)
own.replaceMesh(carMesh)

? With what in the next?
The game is in folder Game/Blends while meshes will be in Game/Assets/Meshes. I don’t know how to write this relative path correctly.


path = logic.expandPath('//')+"map/result_{}_{}.blend".format(x,y)

That is what I use.

And libload does not return that kind of variable…

So, will this:


path = logic.expandPath("//") + "Assets/Meshes/Meshes.blend"

Will bring me a folder at Assets//Meshes/Meshes.blend? Noting that the .blend is placed in a folder that is in the same folder as Assets folder. And how do I get desired mesh from that scene with LibLoad(just one mesh with exact name).

There is also this handy function called print() :yes:

(actually, I don’t know how it works on linux )

Short version.

First you create all the models you want in your separate .blend file. Then you place those models in an inactive layer or you select a layer that contains nothing and you save that .blend file.
And you’re ready to go.

relative_blend_file_path = “some path relative to the main blender file”
absolute_blend_file_path = bge.logic.expandPath("//" + relative_blend_file_path)
bge.logic.LibLoad(absolute_blend_file_path, load_actions=True)

Now the active scene in that relative blend file has been merged with the active scene of the running game. All objects of that merged scene that were in an inactive layer are available as inactive objects of the current scene, and you can say:

game_object = bge.logic.getCurrentScene().addObject(“the name of the object”)#2.75

So the key thing is that the objects you want to load from an external blender file should be in an inactive layer of the current scene in that blender file.

I still don’t get it. My question is:
How do I access this folder:


~/GameFolder/Assets/Meshes/Meshes.blend

realtively executing script in this .blend:


~/GameFolder/Blends/Game1.blend

?

bge.logic.expandPath("//" + “…/Assets/Meshes/Meshes.blend”)

In “expandPath” logic, “//” is “~/GameFolder/Blends”, and that is the base path.

“…” stands for “the parent directory of”

oh… OK! Now I get it! Next - can I LibLoad a single mesh with exact name from the .blend?

There is no built-in function to do exactly that but you can do it in a two stage process - and a suitable blend file.
First you load the file with LibLoad, then you add the KX_GameObject with scene.addObject(“the name”).
For this to work:

  1. the object you want to add must be in an inactive layer of the current scene of the loaded blend file
  2. “the name” must be unique in the context of the game

Could you make an example .zip for me?

Here you go:

http://www.tukano.it/blender/load_asset_test.zip

The blend file in the main subfolder is the one that loads the blend file in the asset subfolder.

Thanks! I’ll try to implement it in my game…