Jump to content

Web workers and Babylon.js


binyan
 Share

Recommended Posts

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 to
web-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?

Link to comment
Share on other sites

Yup, it won't.

Web workers only have access to the following:

  • XMLHttpRequest
  • Application Cache
  • create other web workers
  • navigator object
  • location object
  • setTimeout method
  • clearTimeout method
  • setInterval method
  • clearInterval method
  • importScripts method
  • JSON
  • Worker

Possible 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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 years later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...