Could the sluggish WebGl rendering speed be attributed to the size of the JSON file?

Attempting to display a highly complex model using a JSON file, which is quite large at 40MB. Despite being able to render the model on canvas, encountering severe sluggishness during the process.

The issue arises when trying to manipulate the model by rotating or zooming in, causing the entire browser to hang due to the slow performance. Being new to WebGL, unsure of the root cause for this problem and couldn't find any helpful solutions so far.

Could the size of the JSON file be impacting the rendering speed? How can the performance be optimized? It's important to note that the graphic card itself is not the bottleneck as other aspects like browsing are swift.

Utilizing three.js Jason Loader for loading the file:

loader = new THREE.JSONLoader();
loader.load( 'file.js', function ( geometry ) {
    geometry.computeVertexNormals();
    mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( ) );
    scene.add( mesh );
} );

Within the initialization process, configuring the renderer:

renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );

The render operation is called within the animate() function:

function animate() {
    requestAnimationFrame( animate );
    render();
    stats.update();
}

Manipulating the rotation of the mesh in the render function:

function render() {
    mesh.rotation.x += ( targetXRotation - mesh.rotation.x ) * 0.05;
    mesh.rotation.y += ( targetYRotation - mesh.rotation.y ) * 0.05;
    renderer.render( scene, camera );
}

Answer №1

Since you labeled this inquiry under "webgl," it appears that you are interested in utilizing the WebGL renderer:

renderer = new THREE.WebGLRenderer();

as opposed to the canvas option:

renderer = new THREE.CanvasRenderer();

Answer №2

The speed at which your 40-meg file processes may vary depending on its structure. If the file contains multiple individual models, it is likely to run slower. But what exactly do we mean by "models?"

Imagine creating two spheres in a modeling package - you essentially have created two models. Now, if you were to create 1000 spheres, each consisting of 1000 polygons, exporting them may result in slower performance. However, consolidating those 1000 sphere models into a single model comprising all 1000 spheres before the export process could potentially boost the file's processing speed.

Remember, rendering one large object is generally quicker than rendering a multitude of smaller objects.

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

Issue with EJS template displaying no information

I am encountering an issue with ejs templates. While I have successfully used it in a previous project, in my current one, it's not working as intended. Instead of rendering the cards with the passed data, all I see is a blank page. Here is my code fo ...

Encountering an unhandled promise rejection issue with Knex's batchInsert function when attempting to insert arrays larger than 3 elements

I am currently working on an express app and utilizing Knex as the query string builder. During batch insert operations with an array of 1000+ objects, I encountered an error when the array exceeded a certain length. The specific error message is provided ...

What are the reasons for not accessing elements in a more "direct" way like elemId.innerHTML?

Recently, I came across a piece of JavaScript code that accesses HTML elements using the shorthand elementID.innerHTML. Surprisingly, it worked perfectly fine, but interestingly, most tutorials opt for the traditional method of using document.getElementByI ...

Retrieving HTML content from Wikipedia's API using JavaScript

I am encountering an issue where every time I attempt to log data to my console, an error occurs. Could someone kindly point out what may be the problem with the code? My objective is to actually showcase the html content on a webpage. Below is the code ...

The Div element seems to have a mind of its own, refusing

Check out my code on this link: http://jsfiddle.net/Pd7nm/ I'm trying to make the sidebar stop scrolling with the page once it reaches a certain point, but it just won't cooperate. I've attempted various solutions, but none seem to be effec ...

JavaScript countdown timers should maintain their progress even after the page is reloaded

I am encountering an issue with a timer on my checkout page. We have a 2-step checkout process, and after completing step 1, the webpage reloads to step 2, causing the timer to restart. I need the timer to continue counting without resetting. Below is the ...

using javascript to animate multiple div elements

In my current project, I am harnessing the power of Javascript to incorporate some eye-catching animation effects on a rectangle. Once the animation is complete, I have set the box to disappear from view. Check out the code snippet below for more details: ...

The page reloads automatically following the completion of an ajax request

Hey there, I have a basic form with just a text field. When we submit the form, the data entered in the text field gets stored in the database through ajax. Although the ajax function is working properly and the data is being submitted, the page automatica ...

Unable to execute controller due to service call testing failure

I'm currently working on writing a code to test the service call in my controller. The goal is to unit test a specific function within the controller that makes the service call and retrieves data. While I am using local JSON for testing purposes, the ...

Next.js v13 and Firebase are encountering a CORS policy error which is blocking access to the site.webmanifest file

Background: I am currently developing a website using Next.js version 13 in combination with Firebase, and I have successfully deployed it on Vercel. Upon inspecting the console, I came across two CORS policy errors specifically related to my site.webmani ...

What is the rationale behind allowing any type in TypeScript, even though it can make it more challenging to detect errors during compile time?

Why is it that all types are allowed in TypeScript? This can lead to potential bugs at runtime, as the use of type "any" makes it harder to detect errors during compilation. Example: const someValue: string = "Some string"; someValue.toExponentia ...

Show a variety of months using a datepicker arranged neatly in rows and columns

I need to display 13 months using multidatespicker. I achieved this with the following code: $(document).ready(function(){ $('#my_calendar').multiDatesPicker({ numberOfMonths: [4, 4], dateFormat: 'dd-mm-yy&a ...

What could be causing the JSON content to not display in an AJAX request?

I am facing an issue while trying to retrieve JSON data from one page to another. js_page.php <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> ...

Retrieve an HTML page rendering using C#

Is there a way to retrieve the exact HTML code from my website just as it appears in the browser? Initially, I attempted to use a web client like this: using (var client = new WebClient()) { var content = client.DownloadString("my_site_address"); } ...

Pressing a key in an HTML form

I currently have a button with the HTML code <input type="button" name="button">. When I click on this button, it triggers a JavaScript function that takes a value from another input text field <input type="text" name="btxt"> and performs some ...

What is the appropriate command for "building" a fresh NPM project?

I'm currently working on a JS website with Three.js. I kicked off my project like this: $ npm init $ npm install three Can anyone guide me on where to place my code utilizing Three.js, and which npm command should I use to "compile" my script for dep ...

Tips for finishing Vuetify's circular progress bar using a center percentage value

I've been exploring the features of Vuetify's progress circular component lately. This component allows you to specify a value prop, which represents the current progress percentage. The circle completes when the value reaches 100. In my scenar ...

When comparing two state arrays in React, it is important to note that they will not be considered equal and return a boolean (True

As I attempt to compare two arrays stored in my state, my goal is to set a boolean variable to "true" if they match. However, my current if statement fails to detect equality between the arrays. I'm performing this comparison within a setInterval() f ...

Display alert only when focus is lost (on blur) and a dropdown selection was not made

Utilizing Google Maps Places for autocompletion of my input, I am aiming to nudge the user towards selecting an address from the provided dropdowns in order to work with the chosen place. A challenge arises when considering enabling users to input address ...

The concept of a callback function is not applicable within the context of MongoDB in Node.js

I am encountering an issue while validating the existence of an email or username in my MongoDB users collection within Node.js using my User Model. Whenever I attempt to perform this validation, I receive an error stating callback is not a function. This ...