Open cmloegcmluin opened 6 years ago
Yes! Do you want to write the first draft of that? :wink:
Already took care of it, actually! https://www.npmjs.com/package/three-vrcontroller-module
@cmloegcmluin Thanks a lot! How did you do it? Is it possible to automate?
This is the commit that did it: https://github.com/cmloegcmluin/THREE.VRController/commit/ec8c720e4de1bc7dbea2cd2827551cfe3d82f973#diff-8d6f5c826e622ae81907df0290f3fa04
Automation should be possible. The key changes are:
THREE
rather than expecting THREE
to already exist in the global scopeVRController
rather than patching the global THREE.The rest of the changes are not important. In fact, if you were automating this, you'd probably want to simply import * as THREE
. That would have a couple benefits.
VRController
.Good luck and let me know if you have any other questions.
(By the way, a bunch of my VR Three.js stuff stopped working in Chrome this week due to a change in the WebXR API: navigator.xr.requestDevice is not a function
. In fact, all of the WebVR examples at good old https://threejs.org/examples/ are down for this same reason (not surprised since I modeled my code after one of them)).
Also, I noticed that the GitHub URL for my npm package was out of date, and have corrected it. I apologize if you had already gone looking for this information and I didn't make it easy on you!
Cool! Thanks for detailed explanation. I will probably use your fork instead because I really don't get an idea of assuming THREE in global scope. I might open an PR to you repo since I found some functionality missing from the library. https://github.com/stewdio/THREE.VRController/issues/25
Sure thing. Happy to help.
I'll try to explain the whole global vs. module issue. THREE relies on the order you import files, such as with tags in your .html. You need to make sure you import the core THREE library first because that's the JavaScript file that will declare the variable THREE, and declare it scoped not to the file with a var
, let
, or const
, but globally - essentially declaring it to be a property of window or global, as in window.THREE
. The other THREE files, like this VRController one, assume you have already done this, and will not work correctly if you haven't.
It's more popular in the community nowadays to use "dependency injection" style, where each JavaScript file states explicitly what it needs to work correctly in the form of require
or import
statements. It is considered a cleaner and more scalable way to code. It's how package libraries like npm
expect you to serve your code. I won't delve into the rationales here, but I hope this helps clear up my original intention and my process.
I'm not surprised if functionality is missing - the way I did this was super-dumb - the code is just a snapshot of how it was the last time I was here. There may be some tricky way to build something that perpetually serves the latest version of THREE as modules without maintenance, but until then, PR's are no problem.
Yes I understand the Githubissues.
Any interest in making this awesome tool available as an npm package?