"Performance issues with Three.js due to too many textures in 200

I have been experimenting with three.js for a few months now. Recently, I began working on a project involving a 3D webgl product catalogue where we store base64 images in the browser's indexeddb and create the catalogue upon app load. The issue arises due to performance problems, especially when dealing with categories containing hundreds or even thousands of products.

Each category presents models (planes) in a unique way, requiring textures to be generated and pre-loaded before the app starts to provide a smooth user experience. However, this approach causes crashes on hardware with limited RAM and onboard GPUs that share memory with the CPU, such as Chrome crashing.

We attempted loading textures on demand, but it significantly impacts user experience by causing the app to freeze for a few seconds. Currently, materials are created for each product without any textures, while textures are stored separately based on the product ID. When a category loads, we assign the appropriate texture to each model and dispose of unnecessary textures from materials.

The challenge lies in storing 2000 textures which is not memory efficient and leads to crashes on low-budget hardware. On-demand texture loading results in freezes during use, impacting user experience negatively. Furthermore, considering that each model is draggable via touch events complicates the situation.

I do not face any coding issues at the moment, so sharing code would serve no purpose unless requested specifically. My main concern revolves around finding a more effective architectural solution for implementing such an app. I have considered using particle systems, but having a different texture for each particle could yield similar problematic outcomes.

Answer â„–1

You should look into why your loading process is causing the app to freeze for a short period of time, as it seems excessively long.

Memory

Take into account the size of your data - if each of your 512x512 textures are approximately 256kb in size, having 2000 textures means you are attempting to store around 500MB (+ ~33% base64 overhead) of data in indexedDB which has a current limit of 5MB. This suggests that you will need to load the textures on demand regardless.

Texture atlas / Megatextures:

Implementing megatextures or a texture atlas may not be practical in this case. WebGL lacks the necessary features to do this in a memory-efficient manner. You would have to allocate a texture at maximum size (between 8k and 16k) and then divide your textures into tiles within that, while keeping track of which textures are currently in use so you can update parts of the atlas with new textures when needed. Running out of space in the atlas would require allocating a new one at maximum size, potentially leading to performance issues and crashes since GPU memory availability cannot be queried.

Implementing an adaptive loading queue:

var textureQueue = [];
// when object becomes visible
if (loadedTextures[textureID])
    return object.texture = loadedTextures[textureID];

textureQueue.push(textureID);
object.texture = loadingTexture;

// on each update
var
    startLoading = window.performance.now(),
    currentTime = startLoading,
    loadID;
while(
    currentTime - startLoading < 10/*ms*/ &&
    loadID = textureQueue.shift()
) {
    /** load and assign texture here **/
    currentTime = window.performance.now();
}

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

The sharpness of images may diminish when they are created on an HTML5 Canvas within Next JS

I am currently working on a project where users can upload an image onto an HTML5 canvas with fixed dimensions. The uploaded image can be dragged and resized using mouse input while preserving its aspect ratio. Below is the draw function I am using to achi ...

Display the number of rows per page on the pagination system

Looking for a way to add a show per page dropdown button to my existing pagination code from Mui. Here's the snippet: <Pagination style={{ marginLeft: "auto", marginTop: 20, display: "inline-b ...

Retrieve both the key and value from an array of objects

I have been scouring the internet for a solution to this question, but I haven't come across anything that fits my needs. Let's say we have an array of objects like this -- "points":[{"pt":"Point-1","value":"Java, j2ee developer"},{"pt":"Point ...

"Discrepancy in results between JSON stringify and JavaScript object conversion

I need to save this object in a database, but first I have to send it to the backend. Recorder {config: Object, recording: false, callbacks: Object, context: AudioContext, node: ScriptProcessorNode…} However, after using JSON.stringify(recorder) The r ...

When employing the map function in React, the resulting array is always equal to the last element within

Recently delving into the world of React, I encountered an issue while trying to assign unique ids to an array of objects within a Component's state using the map function. Strangely, despite my efforts, all elements in the resulting array ended up be ...

Sending a PHP string formatted as JSON to be processed by jQuery

When attempting to echo a string with a JSON structure, I am encountering issues with the jQuery ajax post not parsing it correctly. My question is whether this string will be recognized as JSON by the jQuery json parse function when echoed in a similar ma ...

Can one jQuery script be used for multiple ajax 'like' buttons?

Hey there! I'm working on an Ajax 'like' button that utilizes jQuery. This button will be utilized multiple times on a single page. I'm looking for a way to streamline the process and avoid including the jQuery script multiple times. Is ...

The alert function in the Ajax web method is malfunctioning

Every time I try to call the Ajax web method, I keep receiving a 'save error' message. However, the data is successfully saved to the database without any issues. I have checked for errors but couldn't find any. How can I display an alert sa ...

Using jQuery to target adjacent elements excluding those that are separated by other text

I have been attempting to locate and combine adjacent em tags within paragraphs, but it has proven to be a more challenging task than I initially anticipated. Let's explore some examples to illustrate this issue: <p><em>Hello</em>&l ...

Navigating string primitives when using AngularJS and $http: Tips and Tricks

A function in ASP.NET Web Api is returning a simple string as JSON data. However, when calling this function from AngularJS, the returned value is surrounded by quotes instead of being a plain string: return $http.post('/api/orders', data).then ...

Unable to display Three.JS OBJ Model

I am facing an issue with loading a .obj model in Three.js. I created the model in Cinema 4D, exported it with a scale of 1 meter, and tried to load it using OBJLoader in Three.js. However, even though there are no errors, the model is not showing up. Wh ...

I attempted to create a test scenario to verify that the length of the tasks array is not negative. However, when trying to test this using 'not.toBe' in the code below, an error was encountered

app.js var todos=[]; todos=['to-do one', 'to-do two']; module.exports=todos; app.test.js const todos=require('./app') test('should have a length of at least 0',()=>{ expect(todos.length).toBeGreaterThanOrEqu ...

Is it possible to import a class from a different project or module in TypeScript?

I am attempting to modify the build task in Typescript within this specific project: https://github.com/Microsoft/app-store-vsts-extension/blob/master/Tasks/app-store-promote/app-store-promote.ts I am looking to incorporate an import similar to the one be ...

An issue is encountered with the JavascriptExecutor while attempting to navigate to a different page using Selenium Webdriver

My goal is to capture user actions such as clicks, keypress, and other DOM events by adding JavaScript event listeners to the WebDriver instance. Everything works fine until I navigate to the next page, where I encounter an exception due to an undefined fu ...

Getting the id of a single object in a MatTable

I'm currently working on an angular 8 application where I've implemented angular material with MatTableDatasource. My goal is to retrieve the id from the selected object in my list: 0: {id: "e38e3a37-eda5-4010-d656-08d81c0f3353", family ...

Looking for assistance with a JavaScript code snippet

I have encountered an issue while iterating through receipts in the given code snippet. The objective is to fetch the receipt number for each receipt and add it to a JSON object. However, I am facing a problem where the same receipt is appearing in two sep ...

Focusing on a text field after reloading a different div with AJAX

I've been spending a lot of time figuring out the following issue and I'm hoping someone can help me find the solution. My web application has an input field (type="text") that is ready to accept user input when the page loads. When the user nav ...

Can someone explain the crazy math used in three.js?

I've recently started learning three.js, and I keep encountering these complex mathematical formulas that seem confusing. Take this example for instance: mouse.set( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeig ...

Jquery: Pressing Enter will cause the input field to lose

Take a look at this fiddle I created: http://jsfiddle.net/7wp9rs2s/. This is the progress I have made on my project so far. In the fiddle above, you can double click on one of the 4 items and a textbox will appear for editing. Instead of clicking out of t ...

What is the best way to extract data from the JSON response obtained from the Facebook Graph API in a Node

I am struggling to parse a JSON file in order to extract specific data, particularly the latest picture. How can I achieve this using Node.js and the Facebook Graph API? Below is the snippet of code I currently have: var params = { hostname: ' ...