Challenges with the WebVR Boilerplate - Issues include the manager not displaying in VR mode, the camera being stuck looking straight down, and fullscreen mode only

I've been working on incorporating WebVR into a project that I created using Three.js, but I'm running into some issues with getting it to work properly.

Several problems crop up when I try to view the scene:

  1. When VRMode is set to false, my scene renders as expected. However, when I switch to VR Mode, the scene stops rendering altogether. I can see the two stereoscopic windows, but nothing else shows up.

  2. On desktop, the camera points straight down when loading the scene. But on mobile devices, the scene appears upside down. I've tried adjusting the camera to look at the center of my image, but it doesn't seem to have any effect. This issue started after I made changes to support the WebVR manager and VRControls.

        camera.position.set(-300, -800, 200);
        camera.up = new THREE.Vector3(0, 0, 1);
        camera.lookAt(new THREE.Vector3(0, 0, 0));
    

I'm able to set the position without any problems.

  1. When I click the fullscreen button on the GUI, the screen splits into two halves. The top half remains black (my body background and clearfix color are blue), while the bottom half displays my scene. My event listener works fine when manually resizing the window, so this seems to be related to the VR manager.

Any thoughts on what might be causing these errors?

This is how I define my renderer:

var width = window.innerWidth,
    height = window.innerHeight;

var renderer = new THREE.WebGLRenderer({
        antialias: true
});

renderer.setSize(width, height);
renderer.setClearColor(0x1D76BB, 1);

// Effect and Controls for VR
effect = new THREE.VREffect(renderer);
controls = new THREE.VRControls(camera);
effect.setSize(width, height);


var manager = new WebVRManager(renderer, effect);

And here's my animate function:

function animate() {

        requestAnimationFrame(animate);

        if (controls) {
            controls.update();
        }

        if (manager.isVRMode()) {
            renderer.setRenderTarget(null); // add this line
            manager.render(scene, camera);
        } else {
            renderer.render(scene, camera);
        }

    }

I downloaded all my libraries from bower this morning, so I believe they are all up-to-date.

Answer №1

Without examining the entirety of your code, it's challenging to determine what exactly is happening.

While not directly related, the updated WebVRManager class now handles switching between VR and non-VR modes seamlessly, automatically reverting to a standard renderer in 2D mode. This means you no longer need to check for isVRMode or manually call renderer.render. Simply utilize

manager.render</code, as it will manage this process for you. Additionally, the manager has been enhanced to handle resizing tasks, removing the need for manual adjustments on your end. Assuming you are correctly utilizing the manager otherwise.</p>

<p>If you're using VRControls (alongside webvr-polyfill), note that it overrides camera position and orientation settings. Any attempts to set these values manually will be ineffective unless done post <code>controls.update
. To establish a base camera transform, attach the camera to a "dolly" object and manipulate the dolly's transformation instead:

// Example code snippet
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 10000);
var dolly = new THREE.Object3D();
// Additional setup steps here...
scene.add(dolly);

function animate(timestamp) {
    // Animation logic here...
    controls.update();
    manager.render(scene, camera, timestamp);
    requestAnimationFrame(animate);
}

Remember to include the dolly in the scene and rotate it along its Y axis after setting the lookAt direction due to default camera viewing angles pointing towards the negative Z-axis.

For improved debugging clarity, consider adding an AxisHelper to visualize spatial orientations while troubleshooting:

// Adding AxisHelper example
var axisHelper = new THREE.AxisHelper(200);
axisHelper.position.z = 100;
scene.add(axisHelper);

Lastly, if employing webvr-polyfill, be aware that certain devices may apply their barrel distortion shader pass. In cases where shaders conflict or hinder proper scene rendering in VR mode, rendering your shaders before invoking manager.render can potentially resolve such issues. For more insights on this matter, refer to:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leaflet Alert: The number of child elements is not the same as the total number of markers

Encountering a problem with Leaflet clustering using v-marker-cluster. Within the icon createFunction of the cluster, the className of children is used to determine the cluster style. Here is a snippet of this function : const childCount = marker_cluster._ ...

tips for correctly importing source files into jasmine-node testing framework

Currently, I am utilizing the jasmine spec library in combination with the jasmine-node runner for node.js. My main query revolves around the correct method to execute tests using a command in the CLI that encompasses both source files and spec files. Wit ...

Is it possible to display the bounding box of an object in Threejs?

Originating from Ogre and C++, I have now transitioned to developing with Threejs. When working with Ogre, for debugging purposes, I frequently utilize the following method: Ogre::SceneNode* n = ... n->showBoundingBox(true); This method is simply use ...

Storing information in memory through the use of Javascript

i am interested in keeping this type of data consistently in memory. app_id admin_id url status 123 1 xyz.com 1 123 2 xyz.com 0 539 3 exmaple.com 1 876 4 new.com ...

Tips on transforming a JavaScript function constructor into TypeScript

Transitioning from JavaScript to TypeScript has presented me with some challenges. One of the tasks I need to accomplish is converting a constructor function into its TypeScript equivalent. The original JavaScript function looks like this: export default ...

What is the method for spinning a texture within a plane?

Having trouble with rotating textures. I came across this post on Stack Overflow about rotating textures in Three.js (Three.js Rotate Texture). Some users suggested rotating in canvas, which works well for rectangles. However, I am facing issues with pol ...

Mapping API for JavaScript, converting coordinates into precise locations

I have two coordinates: 54.674705589 and 25.289369548. I want to place these coordinates on a map when the button is clicked, similar to this example. However, the example provided is for addresses, not coordinates. Is it possible to modify this example t ...

Is it best practice to initialize loaded scripts before the JQuery .load callback is called or should it be done after the .ready callback in the loaded script?

When I click a button in my main document, I load the content of a specific div using jQuery: $("#my_div").load(function() { alert("Content Loaded"); }); The loaded content contains a script: <script> alert("Initial Alert from External Script" ...

Is there a way to prevent the ENTER key on the keyboard from interacting with

When visiting http://api.jqueryui.com/datepicker/, I came across the following information: Keyboard interaction While using the datepicker, various key commands are available: PAGE UP: Move to the previous month. PAGE DOWN: Move to the next month. CTRL ...

Tips for changing the size of a background image using JavaScript on the fly

I am a beginner in the world of programming and currently working on my very first mini-project - a word definition game. One of the challenges I am facing is related to an event listener on an input field, where I aim to change the background image every ...

Keep an eye on the syncing progress of pouchdb replication

What is the best way to alert the user if there is a loss of Internet connection or if the server goes offline, causing live sync to stop? var localdb = new PouchDB('localdb'); var remotedb = new PouchDB('http://localhost:5984/xyz&a ...

What methods does Angular use to display custom HTML tags in IE9/10 without causing any issues for the browser?

Exploring web components and utilizing customElements.define tends to cause issues in IE9/10. I've noticed that Angular is compatible with IE9/10, and upon inspecting the DOM tree, it seems like Angular successfully displays the custom element tags. ...

In my Google Sheets script, I am looking to introduce a 2-minute delay within the forEach loop for sending emails. Unfortunately, I have not had success

I am looking to introduce a 2-minute delay after each iteration of the loop. Specifically, I want to add a delay in the process of sending emails. You can find the complete code at this link. obj.forEach(function(row, rowIdx){ sleep(1200000); / ...

Issues with implementing asynchronous calls within streams utilizing node.js

I've encountered an issue with async calls in my streams. It seems that when the middle stream makes an asynchronous call, the final stream does not receive the 'end' event. I was able to replicate this behavior using simple through streams ...

Exploring the power of AngularJS with JavaScript and utilizing the $scope

After spending the entire day trying to solve this issue, it seems like I might be missing something simple. Here's the problem at hand: I have a well-structured Nodejs/AngularJS application that utilizes Jade for templating. The server performs certa ...

Assigning path handlers to external modules in NodeJS using Express

I've been trying to minimize the complexity in my routes.js file. Check it out: module.exports = function(app, db) { app.get('/', function(req, res) { res.render('index') }); app.get('/contact-us', function(req, re ...

personalizing material-ui component styles – set select component color to be pure white

I am looking to implement a dropdown menu using material-ui components (refer to https://material-ui.com/components/selects/). To do so, I have extracted the specific component from the example: Component return <div> <FormControl variant="outli ...

Why is it that useEffect is functioning correctly only on the first occasion?

Recently, I've been facing significant challenges with React's useEffect and States. The issue arises when I redirect to the main page of my app and then attempt to use them again. In the following component, everything seems to function correct ...

JavaScript button is not functioning properly to increase or decrease the value in the input field

I'm facing an issue with the javascript increase/decrease buttons on my website. When I assign my JS variable as the class name of the input field, pressing the button results in all input fields being affected simultaneously: https://i.stack.imgur.c ...

Retrieving a file using a Node.js Express application as the response

I am encountering an issue with my Express app. I am using multer to upload a file, and then using res.download to send the file back to the client. Surprisingly, this method works well for text files, but not for images. Strangely, when the file is sent t ...