embedding three.js in Colab

Viewed 648
1 Answers

Here's the main part that I change

import * as THREE from 'https://unpkg.com/three?module';
//import Stats from './jsm/libs/stats.module.js';

I import THREE from unpkg, and remove the Stats part.

Here's a working notebook.

JS calling Python

If you need to get data in THREE from Python, there are 2 difficult ways.

  1. invokeFunction: see these 3 examples. The limitation is that you can pass only JSON data.

  2. proxyPort API: see this solution by @blois and my simplification. You need to start a web server. You can serve binary data by giving a content-length header, as discussed here. Use fetch and arrayBuffer on the receiving end. Currently, this solution seems to not work with Firefox, but it works with Chrome.

Related