A blender addon for babylonjs scene viewing

just download this repo as zip and that can be used as the addon.

demo:

for this to work, your ports 8000 and 8001 should be free.
Just start the serve and go to localhost:8001

How this works?
Exports and Imports the scene as gltf lol


I made this w/ a websocket 2-way communication system for future plans for this.

Right now it just exports glb cuz idk what yall’re gonna do in your blender scene.
but world matrix changes for example can be transmitted real time.

and this can maybe have an editor like interface and you can make changes to your blender scene from your babylon view etc etc

the websocket comes in handy.

It might glitch out here and there. consider this v0. a PoC.

it’ll get better eventually.


Literally my first time making a blender addon and I crammed everything into 1 file cuz file import didn’t work only inside blender for some reason. idk.

Have fun : )

7 Likes

We discussed this feature just yesterday :smiley: . I did a quick python test some time ago and it was ok-ish. GitHub - CedricGuillemet/BlenderLiveUpdate: Live HTTP/GLTF2 link between Blender and any tool that can stream assets like Babylon.js Playground Your solution looks much much better.

I was wondering if, instead of using the network, having a python layer between Blender and Babylon (native) was possible. It think it’s possible to have an API to control BabylonNative (init window, load gltf stream,…)

Let me know if you’d be interested in a collab: I can handle BabylonNative python glue.

cc @PirateJC

EDIT: looking at your video, I’m wondering if a bi directional comunication is possible. Like tweaking a material in Inspector, generating a mesh proceduraly, etc

2 Likes

GitHub - CedricGuillemet/BlenderLiveUpdate: Live HTTP/GLTF2 link between Blender and any tool that can stream assets like Babylon.js Playground

Looks sheesh! and it’s right in the playground as well : O

I was wondering if, instead of using the network, having a python layer between Blender and Babylon (native) was possible. It think it’s possible to have an API to control BabylonNative (init window, load gltf stream,…)

sure we could do that! : D, but… y tho?
it’s not like passing messages is an overhead, even if it is, the larger overhead of export/import is heavier : O

looking at your video, I’m wondering if a bi directional comunication is possible. Like tweaking a material in Inspector, generating a mesh proceduraly, etc

That’s precisely I chose websocket comm to begin w/!

The plan is to not only get some realtime sync (clicking buttons eveytime for update is tedious), but also get a back sync!

an editor like interface on babylon side and you have the option translate your babylon changes back to blender : ))

Let me know if you’d be interested in a collab: I can handle BabylonNative python glue.

I haven’t been introduced to babylon native yet I don’t think : P

so I don’t exactly get the vision : O

To make it (very, very) short, BabylonNative is like a Webbrowser, without DOM, but with much more control and the ability to add custom native components.
So, the Python component could be used by any Python client, not just Blender but potentialy other apps using Python like Maya or Substance.

1 Like

without DOM

oh is it like a “write once, run anywhere” @ native speeds thing? I took a look at the examples and going over the docs

So, the Python component could be used by any Python client, not just Blender but potentialy other apps using Python like Maya or Substance.

and this does sound useful : O

Let me know if you’d be interested in a collab

but rn I’m too in the dark about how all this works to meaningfully contribute to anything involving this : P

I do think this is an amazing idea tho, writing it once and having it be an addon-bridge for every 3D program at once : O

Hey ! Nice project :slight_smile:

I had done the exact same from Blender to Houdini (the export being used as a base for some procedural modeling in Houdini).

Something nice would be to add some “realtime” option, where you basically listen for any modification in Blender (Going from Edit to Object Mode, mesh move, new mesh, etc…). Eventually you would limit the update rate in order not to bullshit the network :face_with_tongue:

1 Like

maybe, optional, negotiable xD

I had done the exact same from Blender to Houdini

Never used Houdini but I’ve heard good things : O

1 Like

I have not coded any blender python in a while but I remember finding some solution to imports of other scripts involved adding the path to the target import directory to the sys.path , eg :

here , I had my other scripts in the parent directries ‘script’ folder , like the script pipeline_process

import bpy
import os
import sys

# Get the directory of the current Blender file
blend_dir = os.path.dirname(bpy.data.filepath)

# Get the parent directory of the blend_dir
parent_dir = os.path.dirname(blend_dir)

# Get the path to the "parent scripts" directory
scripts_dir = os.path.join(parent_dir, "scripts")

# Add the "scripts" directory to sys.path
sys.path.append(scripts_dir)

import pipeline_process
from importlib import reload
reload(pipeline_process)

not sure if this info will help or work for you but thought i might share anyway incase it does.

Another gotcha of separate files and script importing , when still developing you phython code only changes to the main file blender is handling are picked up, unless you have what you see in the last line in my example

reload(pipeline_process)

I guess imports are doing some internal caching.

also , sys.path.append is global to the session , meaning inside pipeline_process script , i can import any other scripts in the same directory as it exists in itself without having to do the path set up again eg : pipeline_process.py does this :

import time
import bpy
import os
import json
from PIL import Image

# THIS SCRIPT IS RUN FROM THE SPECIFIC ROOM PIPELINE SCRIPT
#THAT SCRIPT WILL IMPORT THE REQUIRED BAKING DATA AND PASS IT TO THIS SCRIPT

#IMPORTANT , these scripts require setup of a custom import path , handled by the SPECIFIC ROOM PIPELINE SCRIPT that will import this script

import util_directories_and_paths
import util_collections_and_objects
import pipeline_preprocess_uv
import pipeline_preprocess_collections
import util_images
from importlib import reload
reload(util_directories_and_paths)
reload(util_collections_and_objects)
reload(pipeline_preprocess_uv)
reload(pipeline_preprocess_collections)
reload(util_images)
1 Like

solved! thank you so much : D
the files are nice and organised now, much easier to work with! : )

1 Like

Also,
Update: Added Inspector : )

1 Like

I’m trying the other way around :smiley:
Babylon as a Python module:

I need to install the same Python version as Blender.

2 Likes

Sorry I had missed this part where you struggle with Python imports.
I have spent quite some time already working with Blender Addons (example), including networking, custom OpenGL directly inside Blender, automatic addon update from remote server on Blender launch, etc..

Don’t hesitate to ask if you need more help :slight_smile:


No way, what is this :grin:

2 Likes

gawd Pybylon is gonna go crazy :open_mouth:

so is this gon be, you can write babylon apps in python now, just pip install pybylon? :smiley:

are you DMing assets xD

That’s a lot! I’m still in the basics of all the blender hooks and stuff lol

I’ll keep that in mind, ty :smiley:

Yes, it could be a thing :slight_smile:

1 Like

Update: Realtime sync : D

It’s buggy and glitchy rn and works for only a select few cases. But it’s a start! : )

I also made an ambient light postprocess, since blender world color doesn’t use the clear color, but seems to have an addition blend effect w/ the whole render.

you get the option to turn it off and just use clear color by typing
app.useClearColorFromPost = false in the console.

I imagine I’ll integrate this among other things in a settings menu at some point.

3 Likes

Update:

  • fixed some websocket issues
  • fixed the blinking thing that happens on refresh / sync

added AgX tonemapping by default, cuz blender has that on by default

yoinked it from three.js, three.js/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js at dev · mrdoob/three.js · GitHub

now it looks pretty close,

w/o agx it looks like,

which is like, fine, it looks exactly like the Standard tonemapping in blender.

so there’s an option to disable it,
app.useAGXTonemapping = false