A chunk of three?

I would like to use some Maths from three.js to compute some 3D calculations for regular web pages.
Since CSS3 allow 3D transformations, i need to calculate some local / global coordinates (Vector3 * Matrix4, Matrix4 inversion), as well as i need to perform some kind of vector comparison (Vector3.dot() for instance to determine if a transformed div is facing or not the camera (still talking about CSS, where there is no camera keyword, but instead a perspective property).

I was brave enough (or stupid enough ?) i could reinvent the wheel, and rewrite all of thoses long lines of 3D calculations.
But i like ThreeJS, i like open source collaboration, i like learning math from reading source code, so…
Is there a way of using a chunk of threejs ? The math objects (Vector, Matrix, Quaternion, Plane etc) without the whole project ?

Maybe i’m going the wrong way, since a chunk of three is only about saving some kilooctet from the web ! (instinctively i can’t approve to download and parse 500Ko of JS for some additions & multiplication).
Though, extracting math from threejs could be perceived as a learning, educational initiative.

Relative question :
How is threejs built from the source ?
To whom thoses lines are adressed ?
import { Vector3 } from './Vector3';
Bower ?

You can find all the math related files in this directory - so import { Vector3 } from './Vector3'; is an ES6 import statement and loads the file Vector3.js from that directory.

The objects and functions in the math directory are quite separate from the rest of the library, so you certainly can and should just use them rather than whole library if that’s all you need, either by copy and pasting or learning how to use import statements.

If you do decide to go the later root, there are lots of options, but the tool three.js itself uses is called rollup.js and is one of the easiest to use.

3 Likes

ES6, rollup, i got it, thx !