Forum Replies Created
-
AuthorPosts
-
jacksundCustomer
How are you setting up your anaconda environment? My guess is that’s the issue. I named my environment ‘blender_env’ which is why that’s in the folder path above. If you named it something different, then the path won’t be the same. Here’s how you would setup your environment:
conda create -n blender_env python=3.7 conda install -n blender_env -c kitsune.one python-blender conda activate blender_env
Also make sure you have the correct environment active when you’re running python — the ‘conda activate’ step above does this if you’re launching python from the terminal.
Last thing of note is that kitsune’s bpy module isn’t great. A while back, I kept running into issues with it, so I just build my bpy module from source. This is a lot more work but depending on your application it might be worth it.
jacksundCustomerSorry to disappoint, but I don’t have any examples. As far I as I know, I’m the only one trying to script with this method. I have everything working (Verge3D + Blender + Django -> all in python), but I can’t publish it yet as much of the code includes my progress towards a research publication (I’m a chemist). I will say that this full python approach isn’t ideal for non-scientists. In 99% of cases, it’s best to go with javascript, which is probably why I’m the only one doing it.
You can get Verge3d + Blender working in python using the steps I describe above (#20753) – note that if the bpy module doesn’t work, then you have to build it yourself. The tricky part is throwing Django in the mix, which I don’t describe here.
Depending on what you’re trying to accomplish, maybe I could give some guidance…? Otherwise, I can’t point you to a github example until I publish my research. Sorry!
-Jack
jacksundCustomerloadScene() is definitely the route to go! And I now have CORS request working properly.
For apps that I’ve made myself, I’ve also learned to manually set the variable sceneURL in order to indicate the <relative_path> or <url_path> — this would be line 13 in myexampleapp.js file. When using with Django, I found this to be a cleaner approach than adding ?load=<path> to the URL. It makes the urls cleaner and it is easier to script with Django’s templating system.
Thanks again for the help, Alexander and Yuri!
-Jack
jacksundCustomerLooks like this only works if load=<relative_path>, where the file is also on the cdn.soft8soft.com server. Web browsers throw an error when I try load=<url_path>, such as load=https://mywebsite.com/chemical-id/example.gltf. This is blocked because it is a cross-origin request, which looks to be flagged as a security issue.
Here’s the html error:
Access to XMLHttpRequest at ‘http://mywebsite.com/chemical-id/chemical.gltf’ from origin ‘https://cdn.soft8soft.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
There’s also a warning on the webpage:
A cookie associated with a cross-site resource at http://soft8soft.com/ was set without the
SameSite
attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set withSameSite=None
andSecure
.So maybe I just need to set up permissions correctly…? I’m not sure if that opens up security issues for my site though. It is probably better if I don’t combine locally made files with a CDN.
For three.js, loading a gltf looks pretty easy (see below). Is there an analogous command like v3d.GLTFLoader()?
var loader= new THREE.GLTFLoader(); loader.load( 'http://mywebsite.com/chemical-id/chemical.gltf', function(gltf) { scene.add(gltf.scene); }, undefined, function (error) { console.error(error); } );
jacksundCustomerSo 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.jacksundCustomerI’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
jacksundCustomerI’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
jacksundCustomerI 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
-
AuthorPosts