Blender 4 Panda

It’s not a ready-for-use product, but anyway you can try to get some results with it, or even improve it :wink:

What you need
Development version of Panda3D (1.9)
Blender version 2.7 (not tested, but possible it will work on 2.6 too )
latest version of YABEE from GIT: github.com/09th/YABEE
Scene Exporter (Blender plugin): github.com/09th/Blender4Panda-plugin
Scene Loader (Python package for P3D): github.com/09th/Blender4Panda-loader

You should have installed and enabled both YABEE and Scene exporter plugins.
Plugins can be installed by dropping they unzipped folders into <blender_path>//scripts/addons directory or from Blender User Preferences (Ctrl+Alt+U) -> Addons -> Install from file (zip file in this case). After installing you can find and enable it by keyword “Panda”.

Usage
When all done, you can found new panel in the tools shelf (hotkey “T”) called SE4P3D and “Export scene” button on it. Press the export button and select a directory for saving scene. Exporter will create <scene_name>.jsd file with the scene description and subfolder called “res”. Created subfolder will contain <scene_name>.egg file with the scene geometry and various files (shaders and images) related to the scene materials.

Now you can try to load exported scene:

from direct.showbase.ShowBase import ShowBase
from SceneLoader import Scene # SceneLoader is folder, with the Blender4Panda-loader content

base = ShowBase()
sc = Scene(render, loader, base) # pass root node for scene, loader and ShowBase object
sc.load('untitled.jsd') # load our .jsd file
sc.switch_camera() # Switch to the first camera if exist. You can comment this line and use default Panda's camera

base.run()

Restrictions and notes:

[]We are talking about “Blender Game” rendering engine[/]
[]All objects should have material[/]
[]At current stage we talking about the static scene with the meshes, materials, lights and cameras[/]
[]Shader materials aka shader nodes also can be used[/]
[]Do not try to use “Assets”, they not work yet[/]
[]Blender has a bug with the spot light: it casts shadow and provide appropriate shaders when “Shadow” checkbox is unchecked. Make sure that checkbox state corresponds to what you see.[/]
[]If you have scene which not exported, or exported incorrectly (considering known limitations), then you can send it to me and I’ll try to improve exporter[/]


About extensions
extensions usage scheme download/file.php?id=324

Simplest extensions:

Blender

order = 25
target = 'scene'
def invoke(all_data, target_data, context, fname, flags=None):
    target_data['my_message'] = 'Hello'

Panda

order = 25
target = 'scene'
def invoke(scene, data, action):
    if action == 'LOAD':
        if 'my_message' in data:
            print data['my_message'], 'from', scene.jsd_file

some scene usable variables

...
        self.root = root
        self.loader = loader
        self.show_base = show_base
        self.path_dict = {'sounds':'res',
                         'meshes':'res',
                         'images':'res',
                         'materials':'res'
                          }
        # Raw data, which should loaded from JSON file
        self.data_dict = {'objects':{},
                         'assets':{},
                         'scene':{},
                         'materials':{}
                          }
        # Data after passing through import extension will be stored in
        # variables below this comment
        self.objects = {}
        self.lights = {}
        self.sounds = {}
        self.cameras = {}
        self.textures = {}
        self.meshes = {}
...

*.jsd structure

{
    "scene": {
        /*various common scene parameters*/
        "parameter_1": value,
        ...
        "parameter_N": value
    },
    "assets": {
        /*
        List of used assets.
        Assets is a complex objects, which can be reused.
        Assets not implemented yet.
        */
        "asset_name_1": {/*asset parameters*/},
        ...
        "asset_name_N": {/*asset parameters*/}
    },
    "objects": {
        /*
        List of used objects, for example meshes, lights, sounds e.t.c.
        Object also can be exemplar of asset.
        */
        "object_name_1": {/*object parameters*/},
        ...
        "object_name_N": {/*object parameters*/}
    },
    "materials": {
        /*
        List of used materials, added mostly in purposes of implementing
        Blender shader.
        */
        "material_name_1": {/*material parameters*/},
        ...
        "material_name_N": {/*material parameters*/}
    }
}

Old first post:

That’s pretty cool! :slight_smile:

Regarding shaders, is there some way of getting Blender to use Panda’s uniforms? If not, (as you may well have already considered) it might be worth attempting to automatically convert some of Blender’s idiosyncractic uniforms to Panda-recognised ones.

Thanks )

I think that I’ll have to overwrite some attributes in the exported shader file to use Panda’s attributes like p3d_MultiTexCoord and p3d_Tangent. As for uniforms, I not sure, but it seems that P3D and Blender uses different spaces. To make shaders workable I should transform matrices, getted from Panda before pass it to the shader.

In any case I try to make system, which include two parts - one for Blender and another - for Panda. In the Panda’s part I hope to make automatic converter for all needed uniforms.

Cool! How does the pipeline work under the hood? Are you adding tags to the .egg files?

Thanks )

No, I use separate JSON file, which describe scene. Shaders also saved to the separate files. Main reason for it - easy read, easy modify for human. It quite easy to get lost in the EGG file with large mesh data, especially if it would contain something else, so I use EGG for the intended purpose - for the models only.

Ah, that’s a great idea. Then the scene description can be modified separately without having to edit a possibly huge .egg file.

I’ve personally been toying around a bit with the concept of creating a live Panda preview of the scene in a Blender viewport. (I’ve gotten a few promising results, but there are a lot of challenges to overcome.) That would go really well hand-in-hand with a good scene export pipeline such as you are building here. I envision that soon, people will be able to use Blender as a full-fledged scene editor for Panda, thanks to your efforts. An exciting thought. :slight_smile:

Wow, you mean integrate something like pview in the Blender viewport, or use Panda as Blender game render? Though last assumption sounds like sci-fi.

Yes, but at first I planned to use separate files for each model, though it not too hard to give choice: use separate files or use single file for whole scene.
As for separate files - I use this approach with target to make something like “asset” used in Unity, which can be an interactive object (chests, doors, e.t.c.) and may be (in the far future) use hardware instancing on some objects like trees. Also, looking back to “assets” I trying to integrate some feature from this awesome plugin youtube.com/watch?v=i8a00XRGgqU
And finally I use modular approach in import/export pipeline with hope that in future users can extend this script for their specific needs.

Yes, something like pview in the Blender viewport. Ideally, it’d be really cool if any changes made in Blender would show immediately in the Panda viewport as well.
Two things I had working in my prototype:
(1) Panda renders a live viewport, ie. you can pan and zoom the camera just as you would in Blender, but it’ll be rendered by Panda and not by Blender Render. Certain settings, like changing the color of the model, would show up immediately in the viewport.
(2) Pressing F12 shows Panda rendering a frame.
It’s still very awkward, though; especially (1), which requires Panda to render into Blender’s OpenGL context, which is a bit glitchy and doesn’t work well with things like buffers. It also required me to build Panda against Python 3. I’m probably going to rethink it from the ground up, though I won’t have time to get to it soon.

Ah, cool. I have been working on some ideas on how to make Panda do HW instancing more automatically (by checking if Geoms occur more than once, and packing per-instance data into a VBO) and will be implementing them sometime after the 1.9 release.
My approach would be useful for both custom shaders and the shader generator.

(Currently, the problem is that you have to do your own culling when you use hardware instancing, and also that you have to pass all the data to the shader yourself. The ideas I’ve been working on will solve both those problems.)

I endorse that. :slight_smile:

That’s cool. I think it should solve issues with “too many nodes”, at least on the modern video cards.

Just want to show off my progress )
Screen below obtained from the exported (in mostly automatically) scene. Model has quite complex material with “Ramp”.

I have a request: if someone has simple examples of scenes, made and customized in Blender, please send it me to test and investigation.
I am not a 3D artist, so I can’t know all techniques used by artists in Blender.

Restrictions and notes:

[]We are talking about “Blender Game” rendering engine, so if you can see something in this mode with method to display: “Material”, then I hope we can get the same thing in Panda[/]
[]All objects should have material[/]
[]At current stage we talking about static scene, which include meshes, lights, even if they not presented in Panda (screen above uses two hemisphere lights), and perhaps sounds[/]
[]Shader materials aka shader nodes also can be used (I especially interested in it)[/]

I’m no Blender Artist, but here’s a suggestion: blendswap is a great source of scenes and models made in Blender. If you search for something like “BGE” you’ll get to see particularly game-ready stuff.

Thanks, didn’t know about this resource.

Ok. Today I have something that I can show up. I more or less finished working with the Blender shaders system and plan to switch on another things, perhaps it will be physics, or may be “assets” which not work yet.

It’s not a ready-for-use product, but anyway you can try to get some results with it, or even improve it :wink:

What you need
Development version of Panda3D (1.9)
Blender version 2.7 (not tested, but possible it will work on 2.6 too )
latest version of YABEE from GIT: github.com/09th/YABEE
Scene Exporter (Blender plugin): github.com/09th/Blender4Panda-plugin
Scene Loader (Python package for P3D): github.com/09th/Blender4Panda-loader

You should have installed and enabled both YABEE and Scene exporter plugins.
Plugins can be installed by dropping they unzipped folders into <blender_path>//scripts/addons directory or from Blender User Preferences (Ctrl+Alt+U) -> Addons -> Install from file (zip file in this case). After installing you can find and enable it by keyword “Panda”.

Usage
When all done, you can found new panel in the tools shelf (hotkey “T”) called SE4P3D and “Export scene” button on it. Press the export button and select a directory for saving scene. Exporter will create <scene_name>.jsd file with the scene description and subfolder called “res”. Created subfolder will contain <scene_name>.egg file with the scene geometry and various files (shaders and images) related to the scene materials.
Now you can try to load exported scene:

from direct.showbase.ShowBase import ShowBase
from SceneLoader import Scene # SceneLoader is folder, with the Blender4Panda-loader content

base = ShowBase()
sc = Scene(render, loader, base) # pass root node for scene, loader and ShowBase object
sc.load('untitled.jsd') # load our .jsd file
sc.switch_camera() # Switch to the first camera if exist. You can comment this line and use default Panda's camera

base.run()

Restrictions and notes (again):

[]We are talking about “Blender Game” rendering engine[/]
[]All objects should have material[/]
[]At current stage we talking about the static scene with the meshes, materials, lights and cameras[/]
[]Shader materials aka shader nodes also can be used[/]
[]Do not try to use “Assets”, they not work yet[/]
[]Blender has a bug with the spot light: it casts shadow and provide appropriate shaders when “Shadow” checkbox is unchecked. Make sure that checkbox state corresponds to what you see.[/]
[]If you have scene which not exported, or exported incorrectly (considering known limitations), then you can send it to me and I’ll try to improve exporter[/]

To be continue… A bit later I’ll try to explain how it works internally and how it can be extended.

About extensions


Simplest extensions:
Blender

order = 25
target = 'scene'
def invoke(all_data, target_data, context, fname, flags=None):
    target_data['my_message'] = 'Hello'

Panda

order = 25
target = 'scene'
def invoke(scene, data, action):
    if action == 'LOAD':
        if 'my_message' in data:
            print data['my_message'], 'from', scene.jsd_file

*.jsd structure

{
    "scene": {
        /*various common scene parameters*/
        "parameter_1": value,
        ...
        "parameter_N": value
    },
    "assets": {
        /*
        List of used assets.
        Assets is a complex objects, which can be reused.
        Assets not implemented yet.
        */
        "asset_name_1": {/*asset parameters*/},
        ...
        "asset_name_N": {/*asset parameters*/}
    },
    "objects": {
        /*
        List of used objects, for example meshes, lights, sounds e.t.c.
        Object also can be exemplar of asset.
        */
        "object_name_1": {/*object parameters*/},
        ...
        "object_name_N": {/*object parameters*/}
    },
    "materials": {
        /*
        List of used materials, added mostly in purposes of implementing
        Blender shader.
        */
        "material_name_1": {/*material parameters*/},
        ...
        "material_name_N": {/*material parameters*/}
    }
}

some scene usable variables

...
        self.root = root
        self.loader = loader
        self.show_base = show_base
        self.path_dict = {'sounds':'res',
                         'meshes':'res',
                         'images':'res',
                         'materials':'res'
                          }
        # Raw data, which should loaded from JSON file
        self.data_dict = {'objects':{},
                         'assets':{},
                         'scene':{},
                         'materials':{}
                          }
        # Data after passing through import extension will be stored in
        # variables below this comment
        self.objects = {}
        self.lights = {}
        self.sounds = {}
        self.cameras = {}
        self.textures = {}
        self.meshes = {}
...

Just a little video with first results of exporting scene with physics (presented all possible rigid body shapes): youtube.com/watch?v=iXVv33bHoW8

That’s so cool! This’ll make it so much easier to use Blender with Panda.

Thanks )
Though, there is still a lot of work before it become more or less usable for the end-user.

Standard Blender Rigid Body constraints example exported to Panda
youtu.be/Ut15UvZstuk

I was surprised when I discovered that BGE can’t use cubemaps by default, especially given the fact that all needed settings already exist for the “Blender render”. Of course, it can be made with writing own shader, but this way breaks all conception of materials. Perhaps, it will be realised in the later versions of BGE, but for the time being I made hack which inject cubemap code in output shader. It uses Blender render cubemap settings and should be more or less close to original material. However it’s still a hack an can be bugged, also at this time it restricted by one cubemap texture per material.

dynamic cubemap in action
youtube.com/watch?v=jp-04DGL4uM