greggman / twgl.js

A Tiny WebGL helper Library
http://twgljs.org
MIT License
2.69k stars 261 forks source link

Move the math and primitive parts to separate libraries? #103

Open greggman opened 5 years ago

greggman commented 5 years ago

I've been wondering if I should move the math stuff to a separate library for v5 and just remove it entirely from twgl. Same for the primitives namespace.

They are both in there now just because it was easy but looking at for example three.js, 50% of it or more is external the the main library and no one complains. Either they include 2 to 50 scripts OR they run a build step and pull in what they need.

I've also run into places where i wanted to use the math library separately from twgl. I could make it separate and still have twgl compiled it into itself but at the moment I'm leaning toward separating them.

thoughts?

munrocket commented 5 years ago

idk, since we will have all libraries from one maintainer without code duplication.

greggman commented 5 years ago

maybe I can separate them into separate repos but still have twgl-full include the math and the primitives.

The math stuff doesn't require anything so there would be no code duplication to separate out the math.

The primitives do use both the math and twgl so it's unclear how to separate them.

Maybe pass in twgl and math something like

import * as twgl from 'path/to/twgl.min.js';
import {m4, v3} from 'path/to/mathstuff.min.js';
import * as primitives from 'path/to/primitives.min.js';

primitives.setup({twgl, m4, v3});
zorro-fr24 commented 5 years ago

You could pull them into the main repo as git sub modules perhaps - then your twgl releases can be built and tested against a specific maths or primitives commit ref example: https://github.com/uNetworking/uWebSockets -> uSockets @ 2b34391 or https://github.com/stackgl/headless-gl -> angle @ 9216e68

kdziamura commented 4 years ago

Separate math and primitives is a really good idea. Along with your point on separating math to use it in not-twgl projects - it would be great to be able to use some external math library (like http://glmatrix.net) without pulling extra logic from twgl. My suggestion is to use monorepo approach (with lerna for example) - it's really handy for maintain separated libraries (especially if they depend on each other)

greggman commented 4 years ago

Thanks for the suggestion.

Just fyi, first off there's twgl.js vs twgl-full.js in the dist folder. twgl.js doesn't include the math and primitives.

In npm there's 2 different libraries, twgl.js, and twgl-base.js which doesn't include the math or the primitives.

And finally the module version is tree-shaking friendly so if you don't use something it won't get included.

That's the biggest reason I haven't bothered is that there are already solutions.

munrocket commented 3 years ago

Looks like twgl.js in npm with ES6 modules still have full version. Of cause I am tree-shaked it, but looks little bit weird.

import * as twgl from 'twgl.js';

P.S. The thing that you moved math and primitives to another library it's really good. I understand this only now.