The frequent updating of a material's texture map with images at a rapid pace (approximately every 50 milliseconds) results in significant stuttering

Query: What is the most efficient way to swiftly update a sphere's material texture map with images (stored in an HTML5 canvas) at intervals of 50ms to 200ms without causing browser performance issues?

I have a collection of panoramic images that need to be mapped onto a sphere and updated every 50ms to 200ms. While the code appears to be functioning properly, it struggles during execution - resulting in delayed or skipped redraws that take 2s to 3s to display.

Below is the mesh code along with the placeholder texture:

var geometry = new THREE.SphereGeometry(100.0, 64, 64);
var material = new THREE.MeshBasicMaterial({
  map: THREE.ImageUtils.loadTexture(image_path), // placeholder
  side: THREE.DoubleSide,
});

Upon triggering playPanos(0), the intent is to update the material texture map with the image drawn on an HTML5 canvas stored in an array called “loaded_canvas”:

function playPanos(curr_id) {
  if (curr_id >= loaded_canvas.length) return;

  paintPanos(curr_id);

  setTimeout(function() {
    playPanos(curr_id + 1);
  }, 100); // update every 100ms
}

function paintPanos(curr_id) {
  material.map = new THREE.Texture(loaded_canvas[curr_id]);
  material.map.needsUpdate = true;
}

Thank you for your understanding as this code follows a prototype style approach.

Answer №1

Here are some helpful tips:

  • To optimize performance, consider creating the THREE.Texture object only once and using material.map.needsUpdate = true; to update it each time new content is drawn on the canvas.
  • If you store canvases in an array for your animation, consider storing finished textures instead and updating material.map directly.
  • If your canvas resolution is high, try reducing pixel dimensions for better efficiency.
  • Consider using THREE.BackSide instead of side: THREE.DoubleSide if using the sphere for a skybox.

By implementing these optimizations, you can achieve smooth texture updates at 60 frames per second.

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

Achieving form validation in Angular through external data binding techniques

I am facing a challenge with my Angular 4 form as the data is being tracked in an injected service, which is necessary for the project. For each input, the code looks like this... <input name="..." [ngModel]='getVal(...)' (ngModelChange)=&ap ...

Show two choices in a select box next to each other

I've been attempting to display a select box with two options side by side in a list format. Struggling to find any libraries that can achieve this functionality. Here is an example: <select> <option x><option y> <optio ...

Experience the power of VueJS 3 with Pinia, all without the need

I've hit a wall. Despite scouring documentation and countless google searches, I can't seem to find the answer to this straightforward query: how do I install/import PINIA in a VUE application? Let's consider a basic VUE app: <div id=&qu ...

Starting from TypeScript version 5.6, `Buffer` cannot be categorized as either `ArrayBufferView` or `Uint8Array | DataView`

Struggling to make the transition to TypeScript 5.6 Beta, I am encountering these error messages within the node_modules directory. Without making any other modifications, how can I resolve these errors? node_modules/@types/node/buffer.d.ts:632:19 - error ...

"Experience the new Bootstrap 5 feature: Off-Canvas sliding from left to

I encountered the code snippet below on the official bootstrap 5 demo. Despite my efforts, I am struggling to figure out how to relocate the off-canvas menu from Left-to-Right. The divergence between the documentation code referencing offcanvas-start and t ...

Creating a React component that allows for pagination using data fetched from a

I have a Spring Boot endpoint that retrieves and lists items from a database: @RequestMapping(method = RequestMethod.GET, value = "/task", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> processTask(@Valid TaskSearchP ...

Three bizarre phenomena encountered when pushing mesh in JavaScript

Excuse my inexperience, I am quite new to javascript and THREE. In the code snippet below, I am attempting to add meshes to a list of objects: geometry = new THREE.BoxGeometry( 1, 50, 1 ); for ( var i = 0, l = geometry.faces.length; i < l; i ++ ) { ...

Is there a way to access various history.pushState events when using window.popState in JavaScript?

In my code, there are two pushStates that I need to read separately and execute different functions for. However, when the form is not submitted, the related pushState does not trigger and results in this error: Uncaught TypeError: Cannot read property &ap ...

Anyone have any (placeholder) fetch URL parameters that require some time to resolve?

Can anyone share any fetch URL parameters that result in a loading time of roughly 5 seconds or longer for the promise to resolve when using fetch(urlArgument);? I'm eager to experiment and learn more. ...

Tips for adjusting object thickness using threejs for normal-scaling techniques

I am currently exploring methods to extrude a pre-loaded .obj object in order to increase its thickness. My goal is to scale the object based on each polygon's normal, rather than just from its anchor point. For instance, imagine I have a "ring" obje ...

What could be causing the 500 response code when making a request to the NextJS API route within the app directory?

Every time I attempt to access my API route, a 500 Internal Server Error code is returned The origin of the request export const fetchSuggestion = async () => { const response = await fetch('/api/getSuggestion', { cache: 'no-store&ap ...

Unable to import Express in Angular

In my Angular app, there are no syntax errors present. Within a file titled test1.js, I have only one line of code: var express = require('express'); However, I am encountering an error in my log: (Interestingly, commenting out this single l ...

Don't display div if database has certain value - Angular

Is there a way to determine if a specific value exists in a PostgreSQL database? If so, can I then hide an HTML element based on this information? Can CSS and JavaScript be used to hide elements, or is there another method that should be utilized for hidi ...

How do you populate a dropdownlistfor in ASP.NET MVC after a form

My issue is that <form> @Html.DropDownListFor(x => x.City, provinces, "--Select City--", new { @class = "dropdownList" }) @Html.DropDownListFor(x => x.district, Enumerable.Empty<SelectListItem>(), "--Select district--") < ...

What is the process for retrieving the component along with the data?

As I work on compiling a list of div elements that require content from my firebase cloud storage, I find myself unsure about how to effectively run the code that retrieves data from firebase and returns it in the form of MyNotes. Consider the following: ...

Implement authentication verification on all child endpoints within an express router

I have an express router set up and I want only authorized users to access its routes. I am currently using passport middleware. Instead of adding a check for req.user in every endpoint, is there a more efficient way to handle this? router.get("/", asyn ...

What are the benefits of ensuring my Redux store is serializable?

While going through the redux documentation, I came across this important point: Still, you should do your best to keep the state serializable. Don't put anything inside it that you can't easily turn into JSON. This got me thinking, what are t ...

How to disable a specific date in Bootstrap datepicker?

I need to deactivate specific dates using bootstrap <script> $(document).ready(function(){ var date_input=$('input[name="date"]'); var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form') ...

The date picker feature of Jquery Mobile is not appearing on the popup field

I implemented the jtsage jquery mobile date picker, and I am facing an issue where the date picker appears behind the popup instead of in front of it when the text inside the popup is clicked. Here is a snippet of my code: <div data-role="content"> ...

Preventing bubbling and propagation in Ember 2.x

Is there a specific method to prevent event bubbling in Ember 2.18 in this particular situation? I couldn't find a matching example in the official documentation, but I did come across two alternative solutions on other websites. Both of them seem to ...