Extending Three.js

Hey all!

So bits and pieces like: https://github.com/mrdoob/three.js/issues/20455
show up from time to time and I myself am becoming more and more interested in reconfiguring parts of the library to suit my own preferences so naturally the question becomes “how do I do that?”

The current way that build/three.js is built is via rollup. I don’t know enough about that just yet but on face value it’s a bunch of regex’s parsing over the source scripts with file i/o form node.js to produce/write out a final script.

But that’s not exactly where I’m wanting to go. I’m playing around with cannon.js and creating new controls, and I feel like I’m in this weird development spot where I kind of want to fork the repo, change a bunch of things but not run it through rollup so I can work with changes I make directly, but then later on, when I might’ve nailed something down enough, I’d like to want to make a personal rollup build…

Did I not look hard enough through the doc’s/other related material?

See I feel like I’m might just be asking the wrong question because of seeing similar-ish question/answers like: Extending PointLight uniforms

There’s nothing wrong with forking the repo :nerd_face:

2 Likes

Are you sure you will need to change anything in the core? Controls and physics can be implemented externally, like in the examples.

3 Likes

Why do not run rollup? This is just a way of grouping everything in one file, but with confidence all dependencies are written in a good order…

You can make your changes and rollup every time a file is written to disk to be able to test! (See the rollup docs there should be a watch option)

If really the time consumed by rollup each time is a problem, you can add additional <script> after the one of /build/three.js to override some parts, but you have to be careful to not use import xxx from xxx in this file but replace it with the global object let xxx = THREE.xxx and then when you rollup, replace those lines with good module imports again…
IMHO this is more work that using rollup…