Only when the canvas Div becomes visible, WebGL Three.js will start loading

In my HTML5 application, I am utilizing three canvases. Two of these canvases hold a WebGL 3D scene that is rendered using Three.js.

These canvases are contained within a custom slider that displays only one canvas at a time in full window size. The issue I am facing is that even though I load all three views during initialization, there is something that is not loaded in the non-visible WebGL canvas until I slide to it. Once I slide to the canvas, it is then loaded and displayed. By "loaded," I mean that something in the render is not occurring until it becomes visible, even though the scene and methods are functioning correctly from the beginning.

I noticed this issue when sliding to the div for the first time, it takes some time to load and the controls freeze during this period. The user is unsure if they clicked properly because the "slide next" button's active state is not activated until the end of this unknown loading time. The slide animations are also skipped, presumably because the loading process takes longer than the sliding animation. Once the canvas has been displayed once, the behavior is correct and slides quickly from one view to the next.

Is there an option in the render or possibly the browser to force this loading to occur even when the canvas is off-screen? Ideally, I would like this loading to only happen during initialization because I do not want the GPU to render things that are not displayed, just preload them.

Answer №1

When setting up your website to handle blocking flags for scene updates and renders, it is important to ensure that each renderer has at least one requestAnimationFrame cycle allowed during initialization. This initial cycle is crucial for completing time-consuming initializations before rendering the scene for the first time. If these initializations are delayed until they are needed, it can negatively impact the responsiveness of your site:

For example, consider a slider with 3 scenes where only one is displayed at a time. If a blocking system is used to update only the currently displayed scene, not allowing all three scenes to initialize during site loading means that only the initially displayed scene will be ready. This results in delays when transitioning to other scenes as they need to initialize at the same time as the sliding animation is triggered. Since initialization takes longer than the animation, the sliding effect is disrupted and a flicker occurs when displaying the new scene for the first time. However, once initialized, the behavior will return to normal for that scene.

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

Allowing unauthorized cross-origin requests to reach the SailsJS controller despite implementing CORS restrictions

My cors.js file has the following configuration: module.exports.cors = { allRoutes: true, origin: require('./local.js').hosts, // which is 'http://localhost' } I decided to test it by making a request from a random site, Here is ...

Group records in MongoDB by either (id1, id2) or (id2, id1)

Creating a messaging system with MongoDB, I have designed the message schema as follows: Message Schema: { senderId: ObjectId, receiverId: ObjectId createdAt: Date } My goal is to showcase all message exchanges between a user and other users ...

Issues with npm installation on Ubuntu 16.04

Encountering issues while attempting to install npm on Ubuntu 16.04 using the command sudo apt-get install npm. The errors received are as follows: The following packages have unmet dependencies: npm : Depends: nodejs but it is not going to be installed ...

Creating a Breeze js entity using a JSON string and importing it into the breeze cache: A step-by-step guide

Currently, I am developing a mobile single page website that utilizes technologies like breeze js, angular js, web API, and entity framework. To enhance the performance of the site, I have decided to include the breeze metadata in a bundled JavaScript fil ...

What is the reason behind fullstack-angular generator utilizing Lo-Dash's merge rather than document.set?

This is the original code snippet used for updating: exports.update = function(req, res) { if(req.body._id) { delete req.body._id; } Thing.findById(req.params.id, function (err, thing) { if (err) { return handleError(res, err); } if(!thing) { ...

Tips for updating server-side variables from the client-side in Next.js

There is a code snippet in api/scraper.js file that I need help with. const request = require("request-promise"); const cheerio = require("cheerio"); let url = "https://crese.org/distintivo-azul/"; let result; request(url, ...

What causes the datepicker to flicker in React when an input field is in focus?

Can someone explain why the datepicker is flickering in React when focusing on the input field? I have integrated the following date picker in my demonstration: https://www.npmjs.com/package/semantic-ui-calendar-react However, it is flickering on focus, ...

The challenge of maintaining coherence in AngularJS scopes

It's driving me crazy. Our integration with some ATSs involves sending queries and setting variables in the scope upon receiving responses. I always make sure to set the variables within a $scope.$apply() to ensure proper updating. Everything was work ...

Using AngularJS's $watchCollection in combination with ng-repeat

Encountering difficulties receiving notifications for changes in a list when utilizing an input field within ng-repeat directly. However, I am able to modify values and receive notifications from $watchCollection. To illustrate: <!DOCTYPE html> < ...

Ways to handle Sessions in Node.js

I'm attempting to utilize a website within node.js. However, the site is prompting me to enable the storage of session cookies. I attempted to set up a cookie-jar, but I couldn't get it to work. Here is a simplified version of the code that is c ...

Analyzing input from the user for string comparison

I am trying to create a code that activates when the user inputs a specific symbol or string. The issue is that it seems to be disregarding the if statements I have implemented. Here is the challenge at hand: Develop a program that can determine the colo ...

Having trouble with my bootstrap carousel not functioning properly - issue with jQuery line causing the rest of the code to disable

I've been facing some challenges with this Bootstrap slider for quite some time now. Despite my best efforts and thorough research on the forum, I just can't seem to make it function properly. Here's the code snippet in question: <!DOCTY ...

What is the best way to incorporate a string value from an external file into a variable in TypeScript without compromising the integrity of special characters?

I am encountering an issue with importing a variable from a separate file .ts that contains special characters, such as accents used in languages like French and Spanish. The problem I am facing is that when I require the file, the special characters are ...

"After the document is fully loaded, the Ajax post function is failing to work

I am looking to trigger an Ajax call once my document has finished loading. Here is the code I currently have: <script> $(window).bind("load", function () { getCategories(); }); </script> <script> ...

Using Rails 5 and Ajax: Comments will only be appended if a comment already exists

I have been working on a new feature that allows users to add comments to articles using Ajax. However, I have encountered an issue where the comment only gets rendered successfully through Ajax if there is already one existing comment. The database commit ...

How many files are being monitored by Grunt?

Recently, I received a new project using Angular + Node from a client and successfully set it up on my local machine. However, one major issue arose when running the grunt command - my CPU spiked to 100% causing my system to hang. Strangely, the same proje ...

Utilize the $slots property when working with v-slot in your Vue application

When dealing with a specific use-case, it becomes necessary to retrieve the rendered width and height of a DOM element inside a slot. Typically, this can be achieved by accessing this.$slots.default[0].elm. However, complications arise when introducing sc ...

Extracting and retrieving data using JavaScript from a URL

After reviewing some code, I am interested in implementing a similar structure. The original code snippet looks like this: htmlItems += '<li><a href="show-feed.html?url=' + items[i].url + '">' + items[i].name + '& ...

What is the process for attaching an event handler to an element that is displayed after a button click?

I need some assistance with my JavaScript code. I have a page with two links, and when the second link is clicked, certain fields are displayed. I am trying to write an onkeyup() event handler for one of these fields, but seem to be missing something. Here ...

A simple guide to running Express Js and MongoDB from the command line and gracefully closing the terminal

Is there a way to run an Express project without the terminal being visible or easily closed? I need my server to stay running, but I don't want the user on the local PC to be able to see or close the terminal. Any suggestions on how to achieve this ...