I’ve been trying and failing to import the OrbitControls for Three.js into Pyscript. When I run the following snippet of code:
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<p>Using OrbitControls with Three.js and Pyscript</p>
from pyodide import create_proxy, to_js
from js import Object
from js import window
from js import THREE
from js import OrbitControls
I then get the following error:
JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/site-packages/_pyodide/_base.py", line 429, in eval_code .run(globals, locals) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 300, in run coroutine = eval(self.code, globals, locals) File "", line 6, in ImportError: cannot import name 'OrbitControls' from 'js' (unknown location) )
I’ve also been working on some beginner Pyscript/Three.js examples which might be useful if you are just starting out like me and getting to grips with Pyscript (awesome!) and Three.js. I’ve temporarily put the examples in an S3 bucket: https://kersnazzle.s3.eu-west-2.amazonaws.com/index.html
Thanks very much for the response John. I’ve had a quick look at the link and it looks like the pythreejs project is an attempt to bridge Python/Three.js for Jupyter Widgets. I was hoping to be able to use the Pyodide/Pyscript magic to be able to access the OrbitControls.js provided by Three.
I want to thank you for all of your blog articles as they are a fantastic resource for learning Pyscript and have really helped me get going. Keep posting!
Pyscript/pyodide then seems happy to import it from /js/controls/OrbitControls.js. If you use /jsm/controls/OrbitControls.js as I first did then it has a huff (technical term) about the import statement at the top of the OrbitControls.js file.