SteveS Posted September 26, 2017 Share Posted September 26, 2017 Is it possible to get the position and rotation of an attached HP mixed reality headset after using the scene.createDefaultVRExperience() call? I've been unable to get the content using scene.activeCamera. Also is it possible to use a different webCam - the default is the front looking camera on my laptop. I'd like to use a USB webcam instead. Love babylon.js Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 26, 2017 Share Posted September 26, 2017 The device's rotation and position can be retrieved using the current (active) camera: devicePosition (http://doc.babylonjs.com/classes/3.0/webvrfreecamera#deviceposition-vector3-classes-3-0-vector3-) deviceRotationQuaternion (http://doc.babylonjs.com/classes/3.0/webvrfreecamera#devicerotationquaternion-any) About the webcam - you can provide a device ID in the constraints when initializing the video texture - http://doc.babylonjs.com/classes/3.0/videotexture#static-createfromwebcam-scene-onready-constraints-rarr-void I hope this helps! Quote Link to comment Share on other sites More sharing options...
SteveS Posted September 26, 2017 Author Share Posted September 26, 2017 Thanks for the quick response. Let me elaborate a bit more about the issue. Before the scene.createDefaultVRExperience() call (which I believe was created in early August) one would use the webvrfreecamera call and a few other calls to setup the VR device connection. What is nice about the createDefaultVRExperience call is that all the VR configuration setup is done for you by that single call. It also creates a button in the lower right corner that when pressed immerses you if a compatible headset is attached. We received our HP mixed reality headset in early August and set about creating a number of apps using babylonjs and they work with that single call - when the button is pressed you immerse in the headset. Now this only works in the Edge browser not released versions of Firefox, Opera and Chrome. One of the apps we created displays a 360 picture on the inside and outside of a sphere of diameter 6. The HP headset has inside out tracking and provides continuous position and rotation information with position in metric units just like the Hololens. When immersed you can walk around the sphere and even go inside the sphere and look around. The app has a text panel displaying the position and rotation of the parameters scene.activeCamera.position and scene.activeCamera.rotation. scene.activeCamera.position never changes but scene.activeCamera.rotation does change based on mouse movement before immersion but doesn't change while immersed. I think what is happening is the createDefaultVRExperience call is creating a private scene camera but only partially updating it's public parameters in activeCamera under certain conditions. I've only briefly looked at the code for that function and not being a javascript expert haven't been able to see what might be missing. Possibly the author of the function could shine some light on this. I'll look into the webCam device ID and see if I can change the CAM selection. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 26, 2017 Share Posted September 26, 2017 The createDefaultVRExperience should work flawlessly on chrome or firefox with Oculus or HTC vive. HP device is only supported by Edge (not a limitation of babylon.js per se) It does not create a private camera but instead replace the scene.activeCamera. The WebVRCamera does not update its position / rotation but instead keeps the deviceOrientation and devicePosition updated. The camera.position and camera.rotation only specify offsets from the deviceOrientation and devicePosition values. Quote Link to comment Share on other sites More sharing options...
SteveS Posted September 26, 2017 Author Share Posted September 26, 2017 Thanks for responding. The createDefaultVRExperience works beautifully with the HP headset. My problem is I don't know how to reference the headset orientation and position. I want to use the deviceOrientation and devicePosition information to control other functions inside the render loop - I just don't know how to get that information. I've tried scene.activeCamera.devicePosition.x, scene.devicePosition.x, etc. Everything I've tried doesn't work. A code example would be terrific. Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 27, 2017 Share Posted September 27, 2017 The enterVR() function of the VRHelper (that is being initialized when calling createDefaultVRExperience() sets the active camera to be the webvr camera. Are you calling this function? Can you check the name of the camera's class (scene.activeCamera.getClassName() ) ? The following interface is exposed on the WebVRCamera objcet: export interface PoseControlled { position: Vector3; rotationQuaternion: Quaternion; devicePosition?: Vector3; deviceRotationQuaternion: Quaternion; rawPose: DevicePose; deviceScaleFactor: number; } rawPose, and both device*** are the variables you can use to get the device'S position. The rest is to set a "world offset" for your scene. Quote Link to comment Share on other sites More sharing options...
SteveS Posted September 27, 2017 Author Share Posted September 27, 2017 Some progress. scene.activeCamera.getClassName() pre-immersion returns DeviceOrientationCamera. post immersion (after pressing the lower right hand side googles - which I assume executes the enterVR() function) returns WebVRFreeCamera. I added a delay before attempting to access the headset data after immersion but still no success. I tried scene.activeCamera.WebVRFreeCamera.devicePosition.x scene.WebVRFreeCamera.devicePosition.x scene.WebVRFreeCamera.rawPose.position.x and a bunch of other permutations. In all cases the render loop still halts. Clearly I'm not be using the correct reference syntax. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 27, 2017 Share Posted September 27, 2017 after immersion, you just need to use: scene.activeCamera.devicePosition.x Quote Link to comment Share on other sites More sharing options...
SteveS Posted September 27, 2017 Author Share Posted September 27, 2017 That works! Thanks alot I actually tried that before immersion and, of course, it failed. One last question. Is there a bool I can test indicating immersion? Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 28, 2017 Share Posted September 28, 2017 you can use the (protected/public) _vrDisplay variable on the WebVRCamera, which is the native VRDisplay object from your browser. It has a flag called 'isPresenting' which is a boolean: if (camera._vrDevice && camera._vrDevice.isPresenting) { doThisAmazingThingThatNeedsToBeDone(); } Quote Link to comment Share on other sites More sharing options...
SteveS Posted September 28, 2017 Author Share Posted September 28, 2017 Tried scene.activeCamera.isPresenting but no success. Used if(scene.activeCamera.getClassName()=="WebVRFreeCamera") { dosomestuff(); } and it works. Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 28, 2017 Share Posted September 28, 2017 Hi Steve, this works too, but I did give you a code sample on how to get the flag's value isPresenting is not a property of the camera, but of the VRDevice object. It is also on only when the device is connected and presenting, making it a better candidate for many use cases. Quote Link to comment Share on other sites More sharing options...
SteveS Posted September 28, 2017 Author Share Posted September 28, 2017 I can't use camera._vrDevice as I don't declare a camera object in my code - I use the camera created by the scene.createDefaultVRExperience() call. From there (courtesy of Deltakosh's post) I reference properties of the camera by using scene.activeCamera.devicePosition So it's not clear to me how to reference _vrDevice.isPresenting in my code as "if(camera._vrDevice&&camera._vrDevice.isPresenting)" fails. I would prefer to use .isPresenting I just don't how to reference it. Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 29, 2017 Share Posted September 29, 2017 the camera object is scene.activeCamera, after calling the vr experience function. so, whenever I say "camera" I actually mean the active camera. Here is the modified code: if (scene.activeCamera._vrDevice && scene.activeCamera._vrDevice.isPresenting) { walkLikeAnEgyptian(); } Quote Link to comment Share on other sites More sharing options...
SteveS Posted September 29, 2017 Author Share Posted September 29, 2017 That worked! Thank you. 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.