Subunit
Selections in THREE.js
A small library that gives you D3 style selections in THREE.js. Now you can do awesome stuff in WebGL with a familiar API. Subunit selects into a THREE.js scene graph just like selecting into the DOM with D3.
npm install subunit
The library only has peer dependency on THREE.js. D3 is not required to be loaded on the page.
Example Code
The code below is an excerpt from this simple demo that creates some blue and red bars.
...const barMaterial = color: '#4183c4' ; // blue materialconst bigMaterial = color: '#ff0000' ; // red material const rootNode = Subunit; // select the scenerootNodepositionx = -size0 / 2; // adjust the root node rootNode // select with tags separated by periods e.g 'tag1.tag2.tag3' datadata // specify your data and call enter on the selection // append a mesh // add a tag ; rootNode // use the tags like classes to select items ;...
Live Demos:
Getting started
There is starter repo for loading Subunit in browser with THREE.js.
To run the demos locally...
-
clone the repo
-
cd subunit
-
npm install && npm start
That will fire up a dev server and open your browser to the demos index.