What could be the reason for THREE.ColladaLoader causing a complete suspension of all operations on the website

While attempting to load an animated .dae file, I utilized the 'onProgress' argument to track its loading progress. Surprisingly, the file reaches 74% loaded in just 2 seconds, only to have the entire page freeze for an additional 23 seconds before the model finally loads (and all other activities come to a standstill, including css animations). Even when I tried using setInterval() to display the progress, it too stopped as soon as the loader hit 74%.

var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load('models/swing_dancing.dae', function(collada) {
    dae = collada.scene;
    dae.traverse(function(child) {
        if (child instanceof THREE.SkinnedMesh) {
            var animation = new THREE.Animation(child, child.geometry.animation);
            animation.play();
        }
    });

    dae.scale.x = dae.scale.y = dae.scale.z = 0.002;
    dae.updateMatrix();

    init();
    animate();

}, function(xhr) {
    console.log(('progress ' + xhr.loaded / xhr.total * 100) + '% loaded')
});

Seeking any suggestions or tips on how to resolve this issue. My starting point was the example here and the related documentation here

https://i.sstatic.net/BSx7L.png

Answer №1

JavaScript operates on a single thread, so once a file is loaded and the asynchronous process of parsing and creating elements begins, it blocks other tasks until completion. This results in the UI being frozen or blocked, causing delays in animations. To overcome this issue, the parse and creation task should be divided into smaller tasks that can be executed gradually over multiple animation frames or with timeouts to allow for smoother animation.

For example:

   ms | frame | task
------+-------+------------- 
    0 |   0   | update preload animation
..........................................
    n |   m   | update preload animation + start to process data from server
------------------------------------------
    h | m+1   | processing (parsing *dea, creating objects)
------------------------------------
 h+3s | m+2   | processing done, animation and UI updates continue

Therefore, frame m+1 may take around 3 seconds instead of the ideal 100/6 ms, leading to animation sticking issues.

To display an animation while initialization is ongoing, each frame should include updating the animation and processing subtasks quickly:

frame n    update Animation, process subtask (<-- this must not take too long)
frame n+1 .
frame n+2 .
frame n+3 .

Until all substasks are executed

Answer №2

Philipp's insight is accurate. I would like to expand on his point by suggesting another approach: consider parsing the collada file in a web worker. There are existing libraries available for this purpose, such as https://github.com/jagenjo/collada.js/tree/master

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

What are some techniques for designing a dynamic object that evolves over time in WebGL using Three.js and Tween.js?

Recently, I've started experimenting with Three.js and Tween.js and I'm interested in creating an animation where an object appears to "grow": such as a 3D ball transforming into a tube shape (or being pulled into a tube). Is it possible to achi ...

Looking to incorporate an additional column 'LastName' that can be used for filtering in the Angular data table code. This column will be included if it is present in the data

function applyFilter(filterValue: string) { filterValue = filterValue.toLowerCase(); --- return filtered result return this.dataSet.filter( (item: any) => item.name ? item.name.toLowerCase(). ...

What is the optimal method for displaying an alternative image in case the primary image fails to load in .NET web forms?

-Verify file existence using IO check. -Implement javascript onerror function to handle errors. -Check for 404 response and display default image if not found. From the options provided, which method is most efficient in loading a page quickly? ...

Issues with location forecasts and .getPlace() when utilizing the Google Maps loader for Place Autocomplete in Vue are causing functionality problems

After setting up a Vue 2 app using the vue cli, I noticed that when typing an address, no suggestions were populating from the dropdown. Checking the network tab, I observed the AutocompletionService.GetPredictions call triggering without any errors upon p ...

Host an Angular app with views using Express.js - reloading is disabled

I'm currently working with an expressjs configuration that looks like this: app.use(express.static(path.join(__dirname,"../../site"))); app.use("/src", express.static(path.join(__dirname,"../cms/src"))); app.get('/', function(req, res){ ...

What is the best way to prevent an HTMLCollection from automatically updating?

Is there a way to prevent the HTMLCollection from being live? var cells = someTable.getElementsByTagName('td'); I noticed that it's a live collection, so when I add a new td to the table, the cells length increases by 1. How can I make it ...

Set a variable equal to the output of an external function, but receive an undefined value in

I've been facing an issue where I'm trying to store the value of an external function in a JavaScript variable, but it keeps returning undefined. The external function in question is designed to search for a specific record within a database: f ...

Odd Behavior when altering button attribute using Jquery

After disabling a button with a click handler, I have noticed an interesting behavior where the button does not submit afterwards. The issue seems to vary between different browsers, with Firefox still allowing form submission after the button is disabled, ...

Prevent scale animation for a specific section of the icon using CSS

I need help in preventing the scale animation of the :before part of the icon class from occurring when the button is hovered. The current behavior is causing the arrow to look distorted on hover... Link to the code on Codepen HTML <div class="se ...

The Firestore query for viewing resources is currently not functioning as expected due to issues with

I'm currently working on implementing the "read" Rules from an array, following the guidelines in this blog post var db = firebase.firestore(); db.collection("_users").where("viewers", "array-contains", myUID) .get() .then((querySnapshot ...

Synchronize the completion of multiple promises in ExpressJs before sending a response

My POST API contains some logic that needs to wait for all promises to finish before sending the response. However, I'm facing an issue with making my server wait using await Promise.all(tasks); I've tried various approaches and even used librar ...

Tips for running multiple .js test files simultaneously with npm (pact files)

My background is in Java and Maven, where I am accustomed to running multiple test files together and sequentially using a command like: mvn '-Dtest=com.my.directory.tests.*Test' test In this setup, all my test files are named to end with the w ...

Guidelines for executing child displacement on a 3D entity in Three.js?

Here is a basic demonstration of loading an object with MTLLoader() and OBJLoader() in Three.js. var loader = new THREE.MTLLoader(); loader.load(<?php echo "'".$mPart."'"; ?>, function (materials) { materials.preload(); var objLoad ...

The Art of Receiving Feedback in THREE.js

I have created a feedback loop using backbuffer in my code with the following implementation: function render() { renderer.setRenderTarget(BufferA); renderer.render(BufferAScene, camera); renderer.setRenderTarget(null); rendere ...

Creating a window.variable in a jQuery ajax callback using CoffeeScript

This particular project is built using rails and backbone-on-rails framework. Despite my efforts, I have been facing an issue with setting a global variable in a response callback function. Here's what I have attempted so far: 1) Initialization of t ...

Updating the NPM entry point without relying on an index.js file

After successfully publishing a private module to NPM, which contains shared code used by multiple services, I encountered an issue with the transpilation process. Since the code is written in ES6, it needs to be transpiled using Babel before being publish ...

"Encountering a glitch with the Expo app while trying to set

Whenever I try to run the following code snippet, I encounter an error: const Stack = createStackNavigator(); I have made sure that all the necessary dependencies are installed, but still, I get the following error message: "undefined is not an object (e ...

Can you explain the distinct operational contrast between these two sets of code?

Is there a difference in functionality between these two code snippets? <!--?php include('json-ld.php'); ?--><script type="application/ld+json">// <![CDATA[ <?php echo json_encode($payload); ?> // ]]></script> and ...

function executed when meteor template finishes loading all content

Here is a template structure that I am working with: <template name="mainEvents"> <section class="main-events-list events-list js-content-slider"> {{#each events}} <div class="events-list-item"> &l ...

Can JavaScript be used to adjust the zoom level of a website when the user's display scaling is set above 100%, like at 125% or 150%?

These are the display settings I was referring to... They are always set to 150% on laptops... Is it possible to adjust the website zoom using javascript if the user has display settings scaling above 100%, such as 125% or 150%? ...