binyan Posted June 1, 2014 Share Posted June 1, 2014 Hi guys,Recently I've tried out the web workers with babylon.js. It's pretty cool, because you can move some heavy computations (like vertex data generation) out of the UI thread.However the minified version of babylon.js cannot be used with web workers, since they only have an access to a very limited scope of DOM objects. Thus, since the minified version of babylon.js contains some calls toweb-workers-non-supported objects (such as window), it throws an error. I think it would be great to divide the minified version into two: babylon.js which would contain "Pure" Javascript (or TypeScript) code, and web_babylon.js which would contain the code which uses a web related stuff (more precisely - calls to the objects which are not supported by Web Workers). What do you think? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 1, 2014 Share Posted June 1, 2014 Could you be more explicit on that? I think that everything related to webgl, canvas and images will not work with workers right? Quote Link to comment Share on other sites More sharing options...
binyan Posted June 1, 2014 Author Share Posted June 1, 2014 Yup, it won't.Web workers only have access to the following:XMLHttpRequestApplication Cachecreate other web workersnavigator objectlocation objectsetTimeout methodclearTimeout methodsetInterval methodclearInterval methodimportScripts methodJSONWorkerPossible implementation maybe dividing the namespace into three layers:1. Logic - all the data and computation classes. 2. Web - all the web related stuff, such as IndexDB, window events, etc.3. WebGL pipe - classes which are responsible for passing the calculated data to WebGL. Of course it is very simplified vision, and I'm sure there is a lot of pitfalls there, but I think it worth to think about some refactoring to support Web Workers in babylon.js. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 1, 2014 Share Posted June 1, 2014 It is also a HUGE amount of work Quote Link to comment Share on other sites More sharing options...
binyan Posted June 2, 2014 Author Share Posted June 2, 2014 You are right These just my thoughts But as a first step you might divide the existing scripts to 2 categories - those who touch Web functionality and those who don't.For example, I think all the functionality of Babylon.Math can be used in Web Worker. Quote Link to comment Share on other sites More sharing options...
kevzettler Posted October 29, 2016 Share Posted October 29, 2016 Sorry for digging up old post but I'd like to add that this modular separation would be good for using Babylonjs in on a multiplayer authroitive server role where you also don't have access to browser objects like window and DOM Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.