BGE->bpy->BGE

Greetings to all!
There’s something beating the back of my head:
What can be done with bpy? can we open/create new blends, edit and save them?
Is it possible to have and ‘editor’ blend running alongside a bge game?
For example:
The game starts empty, then it send a bpy command to the editor to add a cube, and save. Then in game we libLoad the cube?
Can bge interact with bpy?

You can compile Blender as a module. I’m not sure how much that allows you to achieve, but I imagine quite a lot, because if everything is handled correctly, the UI isn’t needed by the underlying code in order for it to function.

This would make amazingly powerfull GPL games,

Hmm. The file format for .blend is open, right? Does that mean we can write to a bytestring and then libload what we’ve written? I think this would be wasier than trying to use BPY in the game engine, though you’d have to do a lot of the maths yourself.

It would be a rather wasteful time, if you ask me - you have to manually create mesh data, which is the whole purpose of the Blender module. It means maintaining a new API as well, as you’re essentially rewriting all of Blender’s DNA/RNA reading utilities.

Be aware, Blender is a different application. The BGE runs embedded in Blender.

This means:
A) You can use bpy when running embedded only
B) You can use bpy to interact with the current Blender context (which is not the BGE context)
C) You need to reload the scene to get the modified data from Blender context into the BGE context.

Hmm, thank you guys for your inputs.
Yes, I understand that the BGE runs into blender. However, you mention it being a different application, also, the bge file can interact directly with a blend file.
Imagine having the following:
Start game , open assets blend, add a few objects, save blend. Open game file. from new file libLoad objects from the asset blend.
-----------------------------------BPY---------------------------------- | ---------------------------BGE-----------------------------------

It’s like making a game with not a single object premodelled! That’s also why I asked how much can be done using bpy? Can all operations be performed? How can I run a bpy script from the blend, whitout using ALT- P?

AFAIK, you should be able to import and use the standard BPY Python module and commands to do mostly anything. For example, there are scripts that can model certain things for you, so I imagine most of the features of Blender are open through that module, though you need Blender to use the API and the effects happen after exiting the BGE (if I recall). So, it might not be practical unless you can find a way to use it without restarting the game engine. It might still be worth it for certain processes, though.

When you run the BGE embedded in Blender, you can (via Python) access and manipulate the Blender context.

To update the BGE context you can reload the scene. It will reload the scene from the embedded Blender unless you use the game actuator which loads from a file.

What about for in game map editing, apply decals, draw lines that bake into normal dents and bumps etc?

Hit go and they are then baked to textures? Reinit

How do you think does this help with the above questions?

It’s almost in the same line of though!
Like send a command to bake blender textures into a model, then re-import it via scene reloading! Althouhg that can be realtime, with nodes!
I’ve got a feelling this is fleshing up:

AFAIK, you should be able to import and use the standard BPY Python module and commands to do mostly anything. For example, there are scripts that can model certain things for you, so I imagine most of the features of Blender are open through that module

When you run the BGE embedded in Blender, you can (via Python) access and manipulate the Blender context.

To update the BGE context you can reload the scene. It will reload the scene from the embedded Blender unless you use the game actuator which loads from a file.

So, if I can access the “parent” blend via embedded game, can I also access any other blend file through bgeplayer( stand alone game)?
For I want to manipulate a blend through a game and not exactly the one the game is running from. The assets should be accessed through libLoad!
I could start testing if I knew how to tell blender to execute a specific script!

So the question in my mind is: can you open a different blend in blender using bpy while the game engine is running. I can only see nastiness happening…

If you hover your mouse over buttons in the UI you will see the bpy code needed to ‘click’ said button.

You can access another .blend
The BGE can load other .blend files. The BGE can’t manipulate a .blend neither in embedded mode nor with blenderplayer.

As written earlier - Blender can do that. No Blender = no manipulation of .blend files. [Blenderplayer does not contain Blender]

As written earlier - Blender can do that. No Blender = no manipulation of .blend files. [Blenderplayer does not contain Blender]

Understood!
But the BGE can communicate with other programs, it’s just a matter of knowing if blender can be manipulated remotely (port) using bpy!
If that is possible, then there will be a matter of bpy proficiency to UNLIMITED REALTIME EDITTING POWER!

Technically, this is not correct, which Is where my motivation for hypothesising an interaction between BPY and BGE data:
http://wiki.blender.org/index.php/User%3AIdeasman42/BlenderAsPyModule

Argh… first true obstacle, one has to build a custom version of blender…

This is a clean way to do things. You can always load Blender and ask it to do things via a socket.

You can always load Blender and ask it to do things via a socket.

Ah! We’re getting somewhere! That’s what I’m looking for!
Will hit the search button!

Well, my search didn’t give much fruits! So I’ll start asking, maybe a developper?

  1. How do I run blender on the background and tell it to run a bpy script?
  2. If that is trivial, lets say I want to modify an object in the blend, I di not see any “selection” command, except ‘select all’. How will I edit a specific object? The same goes for saving!
  3. Is blender completely manipulable in the background, via, lets say socket?

You can always load Blender and ask it to do things via a socket.

Any tiny little example?