Scripting with conda + blender (bpy) + verge3D

Home Forums Programming Scripting with conda + blender (bpy) + verge3D

This topic contains 8 replies, has 2 voices, and was last updated by Alexander Kovelenov Alexander Kovelenov 2 weeks ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #20457
    Avatar
    jacksund
    Licensee

    I hope I’m not asking too much, but I felt that posting here would be better than the general Blender forums! Anyways, I think Verge3D is an awesome opportunity to establish python-backend 3D-model scripting — that is script the creation of *.gltf and *.bin files for online viewing. You could reach out to many developers that stick with python (i.e. all Django users).

    I’m trying to set this up currently, but am struggling to get the Blender+Verge3D code working as an independent python module. The end goal to be able to run the following example script in an anaconda environment:

    Making bpy as a standalone python module has been done before (see here: https://anaconda.org/kitsune.one/python-blender) (and here: https://pypi.org/project/bpy/), but I can’t figure out how to replicate this for Blender 2.80 with Verge3D functionality.

    Does your team have any insight on how to do this? Or is there alternative method to scripting *.blend/*.gltf/*.bin files that you’d suggest?

    Any help is greatly appreciated!!

    -Jack

    #20463

    Hi,
    awesome idea!
    In theory, you can run any python script in Blender environment without GUI (headless mode) using the following command:
    blender -b -P /path/to/my/script/my_script.py
    Let me how it goes.

    Co-founder and CTO at Soft8Soft
    FB | Twitter | VK

    #20475
    Avatar
    jacksund
    Licensee

    I do have scripts successfully running by that method, but that’s actually the reverse of what I’d like to do! With this approach, you always need to run scripts via the ‘blender’ command, which in turn checks for a built-in python. You also can remove the built-in python from blender, and the ‘blender -P’ command will fall back to the system’s default python. That’s a step in the right direction, but it’s not useful for when you want to add bpy functionality to your existing scripts without being forced to use the ‘blender -P’ command instead of ‘py’.

    In my case, I have a conda enviornment with a bunch of high-level modules (django, scipy, plotly, pymatgen, etc.), where I’d add bpy to the server’s functionality — rather than change to running every app/script with the command ‘blender’ instead of ‘py’. If this is possible, then the bpy module becomes much much more accessible to those that have complex environments already built – particularly those that run a django server and those in data science research (like me!).

    The two links that I sent in my original post make the stand-alone python module for blender — I’d like to replicate that with blender 2.80 + Verge3D. So far I’m struggling to do this, but I have since found instructions on building Blender (without Verge3D): https://wiki.blender.org/wiki/Building_Blender/Other/BlenderAsPyModule

    I’m close, but I need help building the module with Verge3D incorporated. Alternatively, we can make a bpy module via the method in the link above and then make a separate Verge3D module that uses bpy as a dependency. I’m not sure which route would be easiest.

    -Jack

    #20492

    Hi,

    thanks for the clarification! I’ve never heard about this BlenderAsPyModule project. So the only thing remains is to import Verge3D addon properly and get access to its features. Have you tried doing something like:

    Replace ‘~/verge3d/addons/verge3d’ to the actual path to Verge3D addon.

    Co-founder and CTO at Soft8Soft
    FB | Twitter | VK

    #20513
    Avatar
    jacksund
    Licensee

    I’ll give this a go! If I get a working build, I’ll upload to anaconda for others to use as well. Thank you!

    -Jack

    #20531
    Avatar
    jacksund
    Licensee

    I’m unfortunately unable to get this to work. bpy looks like it loads all add-ons when it initializes, so verge3D needs to be in that directory when I use ‘import bpy’. I’ve also tried this, but I’m still getting errors.

    Currently bpy (as installed via anaconda : https://anaconda.org/kitsune.one/python-blender) throws an error with all add-ons. Trying to make my own build of bpy is failing at the build stage as well — though this is just because of my inexperience with cmake.

    I’ve even tried adding all of blender’s python path to my external python, but without any luck there. Errors are thrown when the module tries importing binaries (e.g. import _bpy).

    I’ll likely link this discussion to a post in the general blender forums because I need help with the build bpy module.

    -Jack

    #20596

    Yep, you better ask Blender developers for that.

    Verge3D comes with no binaries and no external dependencies so I believe it should be pretty straightforward to import it, once you have more information on how to deal with Blender addons in your setup.

    Co-founder and CTO at Soft8Soft
    FB | Twitter | VK

    #20753
    Avatar
    jacksund
    Licensee

    So I finally got this working! Here are the steps that I followed:

    – Create an anaconda enviornment based on python 3.7
    – Install blender as a python module from https://anaconda.org/kitsune.one/python-blender
    – Download Verge3D (for Blender) from https://www.soft8soft.com/get-verge3d/
    – From the verge3d download, copy the verge3d/addons/verge3d folder into C:/Users/jacks/Anaconda3/envs/blender_env/2.79/scripts/addons
    – Now open up spyder with the blender_env active and run the following:
    import bpy
    import addon_utils
    addon_utils.enable(module_name=”verge3d”)
    NOTE: ‘import bpy’ will throw a bunch of errors/warnings, but this is fine! Error error is associated with blender trying to initiate Blender’s GUI features — which we aren’t using. This will also happen when you enable verge3d. Base functions will still work as intended though.

    #20758

    This is great! Glad you worked it out :good:

    Co-founder and CTO at Soft8Soft
    FB | Twitter | VK

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.