Performance lag with Three.js on a vertical phone screen

Recently, I transformed my codepen project into a fully functional website. However, I have encountered an issue where the performance is significantly slow when viewed on the Chrome browser of my Nexus 5X phone. Interestingly, the problem resolves itself when I switch to landscape mode or when I view the CodePen directly.

I have experimented by adjusting the width and height settings, attempting to troubleshoot a potential screen or window height issue. Despite reducing the height substantially, the performance remains unchanged.

If there is anyone knowledgeable in the realms of webgl or three.js, could you kindly shed some light on this perplexing situation?

function init() {

    scene = new THREE.Scene();
    height = window.innerHeight;
    width = window.innerWidth;
    aspectRatio = width / height;

  // ...
 }

Answer №1

It is important to incorporate resizing logic in the render loop to account for changes in window size that may occur after loading, such as when the device is rotated. Failing to resize the renderer when the window size changes can result in rendering to a framebuffer size that does not match the actual display, leading to scaling issues.

Additionally, there seems to be a TODO on line 36 of your index.js file that could potentially cause problems. However, everything else appears to be in order.

Resizing logic can be complicated due to the interconnected nature of CSS and renderer size adjustments, which can trigger cascading resizes and layout changes. This can sometimes lead to constant small resizes under specific conditions.

To troubleshoot this issue, try setting your renderer to a fixed square size, like 256x256, during initialization and disabling the window.resize listener. Test this setup on your mobile device to see if performance remains consistent during rotations. I have noticed a similar issue on my Galaxy S5, where horizontal mode performs smoothly but vertical mode seems to be sluggish.

Answer №2

Hey, have you tried utilizing the PMREMGenerator in your code? I've observed that using it to create environment maps causes significant performance issues on mobile devices when in portrait mode.

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

Consolidation of files for Client-Code-Generation with Swagger-Codegen: What is the best way to merge all files into

Just recently started using Swagger and NodeJS, I successfully integrated Swagger into my NodeExpress application and generated typescript-client-code with Swagger-Codegen (specifically Typescript-Angular). However, the issue I am facing is that the gener ...

Accessing data from Execution Contexts in JavaScript

var value = 10; var outer_funct = function(){ var value = 20; var inner_funct = function(){ var value = 30; console.log(value); // displays 30 console.log(window["outer_funct"]["value"]); // I want to log the value 20 her ...

The event was triggered, however, some sections of the code did not run

I am currently working on a project called lan-info on GitHub. Here is the code snippet that I am using: let arpSweepCommand = './arpSweep.sh'; app.get('/arp', (req, res) => { console.log('we have a working signal!'); ...

Utilize Chart.js to showcase vertical axis labels on a line chart

Is there a way to include a Y-axis label for a line graph created using chart.js and angular-chart.js? I am looking to add a y-axis label to my graph. HTML <ion-content ng-controller="AgeController"> <canvas id="line" class="chart chart-line" da ...

Locating the exact position of a DOM node within the source document

Purpose In the process of creating a series of 'extractor' functions to identify components on a page using jsdom and nodejs, I aim to organize these identified 'component' objects based on their original placement within the page. Ch ...

I am unable to retrieve the values from a manually created JavaScript list using querySelectorAll()

const myList = document.createElement("div"); myList.setAttribute('id', 'name'); const list1 = document.createElement("ul"); const item1 = document.createElement("li"); let value1 = document.createTe ...

What is the best way to use JavaScript to fill in missing images with alternative HTML content?

As a provider of a service that helps users find the location of pictures, I face a challenge due to the fact that the pictures are stored on another internal site. Some users may not have access to this site as my service offers additional information. Th ...

Tips for Enhancing JavaScript Performance

Is there a way to enhance my JavaScript code like this: $(window).scroll(function() { if ($('#sec1').isVisible()) { $('.js-nav a.m1').addClass('active'); } else { $('.js-nav a.m1').removeClas ...

Stable header that jumps to the top when scrolled

I have implemented the JavaScript code below to set the header to a fixed position when it reaches the top of the page so that it remains visible while the user scrolls. Everything appears to be functional, but the header movement is abrupt and not smooth. ...

Issue with React-Redux state not updating properly in setInterval()

I am encountering an issue with react-redux / react-toolkit. My state is called todos and it is populated with 3 items correctly, as shown in this image: https://i.sstatic.net/LThi7.png Below is the code of my todo slice: import { createSlice } from &apo ...

The confirmation dialogue is malfunctioning

Need some assistance with my code. I have a table where data can be deleted, but there's an issue with the dialog box that pops up when trying to delete an item. Even if I press cancel, it still deletes the item. Here is the relevant code snippet: ec ...

Looking to retrieve just your Twitter follower count using JavaScript and the Twitter API V1.1?

I am trying to retrieve my Twitter follower count using JavaScript/jQuery in the script.js file and then passing that value to the index.html file for display on a local HTML web page. I will not be hosting these files online. I have spent weeks searching ...

Determine the sibling input value using jQuery in an ASP.NET MVC application

In my Asp.net MVC project in Visual Studio 2015, I have a page where I need to update the user's shopping cart with ajax when the quantity of an item is changed. The challenge I'm facing is retrieving the Article Code from another input field in ...

Having trouble loading this JSON data into my table

So I have a little challenge on my hands: I've got a JSON file with information about various books, each including details like title, author, and year of publication. The goal is to select an option from the list and display the chosen property in ...

Modify the background color of a div by selecting a hex code from a dropdown menu

Is there a way to utilize jQuery in order to alter the background of a <div> by choosing the HEX code from a separate dropdown menu? HTML <select id="target"> <option value="#c2c2c2">Grey</option> <option value="blue">Bl ...

Error: Property 'blogCategory' is unreadable because it is undefined

Having trouble rendering blog posts from a json file in React const BlogPost = (props) => { const [post, setPost] = useState({ id: "", blogCategory:"", blogTitle:"", postedOn:"", ...

What is the best way to align my content alongside my sidebar?

I am facing some challenges with my website layout because I used Bootstrap to integrate a sidebar. The sidebar has caused issues with the positioning of my content, and I'm struggling to align it properly next to the sidebar on the left side. Please ...

Encountering a connection error while running a Node.js Selenium test case on Chrome. The specific error message received is: "Error: ECONNREFUSED - Connection refused to 127.0

When attempting to run a test case on a Selenium Node.js server, an error was encountered: Error: ECONNREFUSED connect ECONNREFUSED. The test case script is as follows: var assert = require('assert'), test = require('selenium-webdriver ...

Tips for executing a Python function from JavaScript, receiving input from an HTML text box

Currently, I am facing an issue with passing input from an HTML text box to a JavaScript variable. Once the input is stored in the JavaScript variable, it needs to be passed to a Python function for execution. Can someone provide assistance with this pro ...

What is the best way to reset Owl Carousel following an ajax request?

I am attempting to reinitialize the owl carousel following a successful ajax call. The ajax call will update the data while retaining the same view. I am encountering an issue where the carousel structure in the view does not reinitialize, and I am unsure ...