{"action":"created","issue":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/7131","labels_url":"https://api.github.com/repos/mrdoob/three.js/issues/7131/labels{/name}","comments_url":"https://api.github.com/repos/mrdoob/three.js/issues/7131/comments","events_url":"https://api.github.com/repos/mrdoob/three.js/issues/7131/events","html_url":"https://github.com/mrdoob/three.js/pull/7131","id":105298912,"number":7131,"title":"Dev - Full Modularisation","user":{"login":"vanruesc","id":9214917,"avatar_url":"https://avatars.githubusercontent.com/u/9214917?v=3","gravatar_id":"","url":"https://api.github.com/users/vanruesc","html_url":"https://github.com/vanruesc","followers_url":"https://api.github.com/users/vanruesc/followers","following_url":"https://api.github.com/users/vanruesc/following{/other_user}","gists_url":"https://api.github.com/users/vanruesc/gists{/gist_id}","starred_url":"https://api.github.com/users/vanruesc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanruesc/subscriptions","organizations_url":"https://api.github.com/users/vanruesc/orgs","repos_url":"https://api.github.com/users/vanruesc/repos","events_url":"https://api.github.com/users/vanruesc/events{/privacy}","received_events_url":"https://api.github.com/users/vanruesc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-09-08T04:36:58Z","updated_at":"2015-09-10T14:56:59Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mrdoob/three.js/pulls/7131","html_url":"https://github.com/mrdoob/three.js/pull/7131","diff_url":"https://github.com/mrdoob/three.js/pull/7131.diff","patch_url":"https://github.com/mrdoob/three.js/pull/7131.patch"},"body":"_Might be relevant to: #4776, #6241, #3041, #7068 and #4686_\r\n\r\n\r\n## Modular Architecture\r\n\r\nHi,\r\n\r\nwelcome to a funny pull request with way to many changes at once.\r\n\r\nIn this case, however, it wasn't really possible to do it little by litte. I manually converted the whole codebase under src/ to a modular architecture and prepared a new build setup with Grunt.\r\nSome prefer Gulp over Grunt. These tools can coexist so somebody could just add a Gulp configuration later.\r\n\r\n\r\n### Build process\r\n\r\nThe build process, as it is now, uses Grunt and Browserify with the BRFS transform to include all shader files. Glslify did not work, because it broke the shader chunks by adding \"#define GLSLIFY 1\" to every single shader, making the concatination impossible.\r\n\r\nAdditionally, JSHint is now integrated in the build process which helped with removing unnecessary semicolons, unused variables and so on. The unit tests are executed by the Qunit plugin and Uglify generates the minified version.\r\n\r\n- The examples are all working (I double checked all): http://vanruesc.github.io/three.js/examples\r\n- The unit tests don't work directly on the sources yet (those need to be rewritten).\r\n- The math tests work if the normal three bundle is used (instead of \"three-math.js\").\r\n\r\n\r\n### Changes made\r\n\r\nI noticed that there was a mix of single and double quotes and changed everything to double quotes. Furthermore, I added curly brackets to all if-statements and moved variable declarations out of for-loops and if-blocks to prevent redeclarations and other potentially bad things.\r\n\r\n- All constants, backwards compatibility code and polyfills have been moved to seperate files.\r\n- Static fields like THREE.Object3DIdCount had to be changed to Object3D.IdCount, Path.Actions, etc.\r\n- Every change should be backwards compatible, please see src/BackwardsCompatibility for details.\r\n- WebGLShader, WebGLProgram and Math were conflicting with native objects and have been renamed to _WebGLShader, _WebGLProgram and _Math internally.\r\n- Imports are ordered by pathname with the nearest dependencies first.\r\n\r\n\r\n### Difficulties\r\n\r\nWhen I first tried to run the examples with the new bundle, I encountered a problem with cyclic dependencies. Cyclic dependencies are, as already stated in #6241, not a serious problem. The real issue arises when objects are created from classes that aren't declared yet or when a dependency short-circuits an inheritance chain. Such problems occured in Box3, Mesh, SphereGeometry, Path, FontUtils, Shape and some other classes. The issues have been resolved for now, but might need more attention. Shape inherits from Path and Path creates Shapes. The import of the Shape class in Path had to be moved inside a function. That's really bad. Luckily, it only occured in Path.\r\n\r\n---\r\n\r\nI named the package \"@mrdoob/three.js\" and modified the readme file to provide basic instructions on how to use three.js as a module.\r\n\r\n__If you can't or don't want to adopt these changes as they are right now, then that's absolutely fine.__\r\n\r\n_BTW: Since an npm package can only export one library, the editor and the examples are kindof lost in space. My suggestion is to move the editor into a seperate project some day with three.js as its main dependency. The same could and maybe should be done with each single example. I know that this has already been asked before (#4686). Just wanted to bring it up again in the light of this modular architecture._"},"comment":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/comments/139271898","html_url":"https://github.com/mrdoob/three.js/pull/7131#issuecomment-139271898","issue_url":"https://api.github.com/repos/mrdoob/three.js/issues/7131","id":139271898,"user":{"login":"mrdoob","id":97088,"avatar_url":"https://avatars.githubusercontent.com/u/97088?v=3","gravatar_id":"","url":"https://api.github.com/users/mrdoob","html_url":"https://github.com/mrdoob","followers_url":"https://api.github.com/users/mrdoob/followers","following_url":"https://api.github.com/users/mrdoob/following{/other_user}","gists_url":"https://api.github.com/users/mrdoob/gists{/gist_id}","starred_url":"https://api.github.com/users/mrdoob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrdoob/subscriptions","organizations_url":"https://api.github.com/users/mrdoob/orgs","repos_url":"https://api.github.com/users/mrdoob/repos","events_url":"https://api.github.com/users/mrdoob/events{/privacy}","received_events_url":"https://api.github.com/users/mrdoob/received_events","type":"User","site_admin":false},"created_at":"2015-09-10T14:56:59Z","updated_at":"2015-09-10T14:56:59Z","body":"At the moment I'm still trying to design the API (abstraction, performance, intuitiveness,...). Adding these modules in the process would increase the difficulty way too much for me.\r\n\r\nInstead of trying to transform the current code I think a better approach would be for someone to port three to a module approach in a new/different repo  (`three-modular.js` or something).\r\n\r\nWhoever does this will have to keep it up to date though. I have seen a bunch of people doing it and then abandoning it."}}