Experiencing performance issues with multiple tweens in Three.js and Tween.js causing delays

Greetings to all, I am new to the world of Three.js and Tween.js and I have a question regarding the possibility of simultaneously tweening 200k vertices from one position to another using Three.js. Apologies in advance if I use the terms pixels and vertices interchangeably.

My goal is to showcase 200k pixels arranged in a grid that can be sorted by the user in various ways, causing them to rearrange accordingly. I want all these pixels to smoothly transition from their initial positions to the final ones simultaneously. Currently, I'm facing performance issues as the animation nears completion despite having the vertices moving with tweens. Any assistance would be greatly appreciated!


For every vertex among those 200k, I have associated a tween object which resides in a list created after drawing the vertices on the scene,

var scPartVerts = scene.children[0].geometry.vertices;
var dataSetLen = 200000;
tweenList = []
for (i=0; i<dataSetLen; i ++){
    tweenList.push(new TWEEN.Tween(scPartVerts[i]))
}

Using D3 for handling click events (simply because it's what I was familiar with), I assign each tween a new XY position to move towards,

d3.select("#key").on("click", function() {
    for (i = 0; i < dataSetLen; i ++){
        var newX = desiredXPostionList[i];      //get new X from a presorted list
        var newY = desiredYPositionList[i];     //get new Y from a presorted list
        tweenList[i].to( {
                x: newX,
                y: newY
            }, 2500)
            .start();
    }

The tweens are then updated during rendering,

function render() {
    scene.children[0].geometry.verticesNeedUpdate = true;
    TWEEN.update();
    renderer.render( scene, camera );
}

The animation runs smoothly up until about 75% completion, at which point it slows down significantly, almost freezing for around 30 seconds when the vertices are close to their final positions. Upon inspecting the animation timeline, it seems that most of the time is spent updating the tweens. Could I potentially be triggering unnecessary tween updates through my d3.select method? (Is JavaScript registering one click as multiple updates?) Or is it simply too challenging for tween.js to handle 200k simultaneous tweens? Thank you in advance for any guidance!

Answer №1

In my unique approach, I start from the very beginning by utilizing loops for handling vertices. It's important to note that while my solution may not be considered the absolute truth, it serves its purpose.

Here's the strategy: establish the duration and current time of the animation,

let duration = 10; // seconds
let currentTime = 10;
let clock = new THREE.Clock();

keep track of the final position of a vertex, assign a random initial position to it, calculate the vector between these positions (direction),

fieldGeom = new THREE.PlaneGeometry(500, 500, 500, 500);
fieldGeom.vertices.forEach(function(vertex){
    vertex.startPosition = new THREE.Vector3(THREE.Math.randInt(-500,500),THREE.Math.randInt(-500,500),THREE.Math.randInt(-500,500));
    vertex.endPosition = vertex.clone();
    vertex.direction = vertex.startPosition.clone().sub(vertex.endPosition);
    vertex.copy(vertex.startPosition);
}); 

then, within the animation loop, incorporate the resulting vector by scaling it with the ratio of currentTime / duration

let delta = clock.getDelta();
currentTime -= delta;
if (currentTime < 0) currentTime = 0;

fieldGeom.vertices.forEach(function(vertex){
    vertex.addVectors(vertex.endPosition,vertex.direction.clone().multiplyScalar(currentTime / duration));
});
fieldGeom.verticesNeedUpdate = true;

Check out this jsfiddle example showcasing 250K points.

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 is the process behind Stackoverflow's "Congratulations, you've earned a new badge" popup window?

Possible Duplicates: Custom notify box similar to StackOverflow Creating popup message like StackOverflow How does StackOverflow implement the "You earned a new badge" window? (the orange one that pops up at the top of the screen, I believe it&ap ...

Node.js server experiencing delays handling multiple requests causing timeouts

As someone who is not very experienced with node, I appreciate your patience. I have a node.js server with 2 routes. Throughout the day, both routes receive requests simultaneously. Route 1 runs smoothly, while route 2 is a long-running process that invol ...

Combine the common id field from two distinct arrays in AngularJS

I have two distinct arrays of data objects, each containing multiple fields: https://i.stack.imgur.com/tMM4l.png https://i.stack.imgur.com/ScgPh.png Here is an example of the data object array with the inclusion of the eventId field. https://i.stack.imgur ...

Having trouble with the JSON response while implementing AngularJS

Recently, I've started working with angularjs and ran into an issue where the data is not loading on the page when pulling JSON from a Joomla component. Strangely enough, everything works perfectly fine when I retrieve the data from a getcustomers.ph ...

The mui-datatables demo fails to display the code snippet as intended

Just diving into React and attempting to grasp MUI-datatables. The code snippet from the Codebox provided on the library's page isn't displaying in my browser, resulting in an empty page. Surprisingly, the console isn't showing any errors. ...

React Three Fiber encountered an unexpected JSON token 'c' at position 3

I am encountering an issue while trying to load a .glb file using react-three-fiber. The error I'm receiving is as follows: Error Unexpected token c in JSON at position 3 I can't seem to figure out what mistake I am making - it seems that the co ...

Tips for troubleshooting when document.queryselector isn't functioning properly in NextJS for server-side rendering (SSR)

I encountered an issue with my circular progress bar code on a Next.js page. Whenever I try to update the "progressEndValue" variable to 67, it triggers a page refresh but doesn't reflect the new value on the progress bar. Instead, I receive the follo ...

My CSS seems to be causing an issue and preventing the function from running correctly. Now I just need to

I'm currently working on a project and following a tutorial to help me create a navigation bar. The tutorial I am using can be found here: https://www.youtube.com/watch?v=gXkqy0b4M5g. So far, I have only reached the 22:05 mark in the video. I have su ...

Having trouble getting the Facebook like button to display on my website using an iframe in the markup

I gave it my all to try and get it to work, but unfortunately, I was unsuccessful. This is the approach I took. First, I followed the instructions provided on https://developers.facebook.com/docs/plugins/like-button. Next, I copied and pasted the iframe ...

Deliver an assured result to a variable within the angular.extend() function

Can someone provide guidance on how to set myVar to a value returned from an asynchronous service method in the following example? angular.extend(this, { myVar: (function() { getVal(); })() }); function getVal() { var d = $q.defer(); ...

Ordering data in a dynamic table using JavaScript

After receiving an array of objects in the form of a JSON file and using AJAX to display specific key-value pairs in a table, I am now faced with the task of sorting the rendered table. However, I am uncertain about the steps to take next. <div id=" ...

Enhancing HTML Vue JS by Dynamically Adding Rows Based on Multiple Selections

<div id="addForm"> <div class="row"> <div class="col-md-4"> <div class="form-group label-floating"> <label class="control-label">Case Type</label> <select class="form-control" v-mo ...

Angular 4 showcases the information stored within this dataset

The data returned from an API to my Angular 4 application is not to my liking. Here is an example of the JSON, where I am only interested in the coin and its price: Goal is to display this data on the page: Coin Price BTC $4,281.28 ETH $294.62 ...

Utilizing $index in AngularJS while iterating through ng-repeat items

Here is an example of an unordered list: <ul class="dropdown-menu inner" role="menu"> <li ng-repeat="availableAlphaName in availableAlphaNames" data-original-index="0" data-optgroup="1" class=""> <a tabindex="0" class="opt " st ...

What is the best way to implement validation for individual elements within an array that are being displayed on a webpage using a for loop?

Currently, I am utilizing Vue JS within the Vuetify framework to build a dynamic form: <v-text-field v-for="items in itemsArray" :key="items.id" v-model="items.data" :label="items.name" ></v-text-field> ...

What is the best approach to transform an HTML textarea value into JSON format?

Client .. inserting some content into a form <textarea name="data"></textarea> After typing the following data into the textarea: {title: 'Hello one!', author: 'someone'} {title: 'Hello two!', author: 'mygf ...

Create a new chart using completely unique information

I am currently working on implementing the example found at http://bl.ocks.org/mbostock/1093130. The goal is to have the "update" function redraw the graph with a completely different dataset each time a button on the DOM is pressed. I have made some modif ...

Is there a way to execute browser.get just once in a script?

I'm completely new to protractor, and I've been setting up the browser.get(URL) command within my first 'it' statement. Then, in my afterEach statement, I navigate back to the homepage. I'm curious if there is a more efficient pla ...

When the time comes, ReactDOM will render your element into the designated container,

What does the [,callback] parameter represent in the ReactDOM.render(element, container) method? ...

Success function in AJAX triggered when no JSON data is returned

Despite its simplicity, I'm having trouble getting this right. I'm utilizing jQuery/AJAX to fetch data (in the form of JSON) from my database. Upon successful retrieval, I have a function to display the data. While this works as expected, I now a ...