-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add build-examples script #21584
Add build-examples script #21584
Conversation
Let's take class FlakesTexture {
constructor( width = 512, height = 512 ) {
const canvas = document.createElement( 'canvas' );
canvas.width = width;
canvas.height = height;
const context = canvas.getContext( '2d' );
context.fillStyle = 'rgb(127,127,255)';
context.fillRect( 0, 0, width, height );
for ( let i = 0; i < 4000; i ++ ) {
const x = Math.random() * width;
const y = Math.random() * height;
const r = Math.random() * 3 + 3;
let nx = Math.random() * 2 - 1;
let ny = Math.random() * 2 - 1;
let nz = 1.5;
const l = Math.sqrt( nx * nx + ny * ny + nz * nz );
nx /= l;
ny /= l;
nz /= l;
context.fillStyle = 'rgb(' + ( nx * 127 + 127 ) + ',' + ( ny * 127 + 127 ) + ',' + nz * 255 + ')';
context.beginPath();
context.arc( x, y, r, 0, Math.PI * 2 );
context.fill();
}
return canvas;
}
}
THREE.FlakesTexture = FlakesTexture; Meaning the global namespace is polluted with class THREE.FlakesTexture { |
That doesn't seem possible without some magic from the likes of Babel. This would be similar to: const THREE.someConstant = value |
@Mugen87 I think you meant THREE.FlakesTexture = class FlakesTexture { It is definitely possible with some regex magic but currently it's really hard because of files such as CCDIKSolver.js which creates an unnecessary wrapper and makes the regex stuff difficult. It's safer to wait for the classes conversion of |
That sounds good to me. |
💪💪💪 |
Thanks! |
Great! Should we remove now |
I think so! @marcofugaro are you taking care of that? |
Okay! I'll do a big PR with the new |
BTW: I've tested various loader and post-processing examples with the generated files and all worked (of course after updating the imports^^). |
@Mugen87 I think we should add @gkjohnson for this item in the change log 👍 |
Noted! |
It should also be noted in the migration guide that |
It seems the new script handles this use case, see: three.js/examples/js/postprocessing/EffectComposer.js Lines 268 to 269 in 5069d47
I've tested post-processing examples without including |
Oh I see, you're right -- I was confused because it's also specified as a separate file now. Looks good! |
Related issue: #19986 (comment) #20527
Description
Add the
build-examples
script that allows to convert esmodule files to non-esmodule files and optionally transpile them for older browsers.It works like this:
Here is an example:
Input
Output
Currently I left out the nodes files, it's a bit more tricky because of the Nodes namespace, but will do it in a future PR.
I also left out some other files (such as the
webxr
ones) because the library they're using doesn't currently provide a non-module version. See the ignore list for details.