What is the best way to halt animations for all scenes except for the one currently being displayed?

I have a program with multiple scenes, but only one scene will be visible at a time. How can I stop the animation for all other scenes except the current one to improve performance? Each scene has many objects that are straining the performance.

I believe using cancelAnimationFrame() could help, but I'm not sure how to implement it. Is this the best practice as recommended on Stack Overflow to improve performance?

The scenes are stored in an array, with the current scene determined by the user input numerical value passed to the scenes[] array.

function changeScene() {
    // Set the currentScene to the user selection
        var sceneNumber = list.options[list.selectedIndex].value;
        currentScene = scenes[sceneNumber-1];
    // Hide all scenes by default    
        for (var j=0; j<10; j++) {
        scenes[j].visible = false;
    }   
}

I have set all scenes to be hidden by default, except for the currentScene. However, I need guidance on how to use cancelAnimationFrame() in this scenario. Additionally, I'm curious if using cancelAnimationFrame() will only take effect after all scenes and objects have loaded, or if it can help reduce loading time as well.

Here is a link to my FIDDLE containing the code mentioned above.

Answer №1

Transformation is the adjustment of numerical values over a period of time. In this instance, it involves modifying the rotation angle of the spinningRig within the animate() function. As long as this modification is limited to the current scene, other scenes will not be affected by the animation.

If your concern is related to rendering rather than animation, there is no need to be concerned as Three.JS only renders the scene specified in the renderer.render() function.

Are there any other issues you are referring to? It appears that animation is not a problem in this scenario.

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 best way to retrieve ViewBag data using jQuery?

Greetings, I am currently in the process of developing a web application using MVC5. Within this application, I have implemented a login form that consists of fields for both username and password: @using (Html.BeginForm("ClickAction", "Login", FormMethod ...

What is the best way to incorporate my theme classes into my React component for custom styling?

Struggling to customize my React header buttons as I can't seem to apply my classes function that utilizes useStyles(). The error seems to be coming from: className: {classes.menuButton} within my getMenuButtons function. const useStyles = makeStyles ...

The D3 data format allows for creating interactive sunburst charts that can be easily zoom

My data is structured similarly to flare.json as shown in this example: I'm curious about the function used by the d3 zoomable chart to format the data in this way. The original structure in flare.json looks like this: { name: "stuff", childr ...

Include the referrer header when using the chrome.downloads API

I have been working on developing an extension that replicates the Ctrl+Click to save image functionality from Opera 12. In my extension, I am utilizing chrome.downloads.download() in the background script to trigger downloads, while a content script is re ...

Stop angular schema form's destroyStrategy from deleting any data

After upgrading my Angular app from version 0.8.2 to 0.8.3 of Angular Schema Form (ASF), a significant bug emerged. The application features multi-page forms that utilize prev/next buttons for navigation. A condition is implemented to display only relevan ...

Run the Ionic function only when the app is launched for the first time

I'm facing an issue with a function in Ionic storage that sets an array to default values. I only want this function to run the first time the app is launched on a user's phone, but currently it runs every time the app is opened because it's ...

What is preventing me from using JavaScript to remove this class?

Struggling to implement a skeleton loading screen with CSS classes and JavaScript. The idea is to apply the 'skeleton' class to elements, style them accordingly, then remove the class using a timeout set in JavaScript. However, I'm encounter ...

Vue.js causing issues with jQuery data table

Utilizing jQuery data-table within Vue.js in a laravel project has presented an issue for me. Although the data loads successfully into the data-table, there seems to be a problem with retrieving the data after it has been loaded. Specifically, the first r ...

Prepare fixtures for commands in Cypress before executing the hook

One of my main tasks is to load the fixtures file only once and ensure it is accessible across all project files. To achieve this, I created a fixtures.js file with the following content: let fixturesData; export const loadFixturesData = () => { cy ...

Extracting information from this array using JavaScript

After struggling for a day, I finally managed to get some output from PHP instead of just the word "array". What a relief! (check out this link for the solution) Basically, this is the data returned from an XMLHTTP request to PHP, handled through a JS ca ...

What is the best method to obtain the following id for an image?

Whenever I hover over the li with the number 3, I am getting the wrong number for the next id in the img tag. The first time, I get next id = 4 which is incorrect. But on the second hover, I get next id = 0 which is what I actually need. How can I correctl ...

What is the most effective method for utilizing v-model with a pre-populated form in Vue.js?

Need some help with a form and looping through items in a module to generate textfields. Take a look at the photo for context: Link: https://i.sstatic.net/MPAVq.jpg Currently, I'm using a structure like this... <v-row class=" ...

Modify the tooltip of the selected item in an ng-repeat loop in AngularJS

Upon clicking an element, a function is executed which, upon successful completion, should change the tooltip of that specific element. Within an ngRepeat loop, I have multiple elements displaying the same tooltip. However, I only want to update the toolt ...

Using either Javascript or JQuery to update every cell in a particular column of a table

I need to use a button to add "OK" in the Status column of table tblItem, which is initially empty. How can I achieve this using JavaScript or JQuery? The table has an id of tblItem Id Item Price Status 1 A 15 2 B 20 3 C ...

Database-driven cron scheduling

How can I set up a cron job to send an email notification using node-mailer about 1 or 2 weeks before the expiration date of a product in my database that includes an expired_date field? ...

Discover the magic of Google Charts with the ability to showcase HTML source code within tooltips

I am attempting to show a Pie Chart using Google Charts with HTML in the tooltips, but I am encountering an issue where the HTML source is visible. I have tried setting html:true on the data column and tooltip.isHtml in the options, but I am unsure of what ...

Having trouble loading my app.js in Angular - Seeking help on Coursera!

I've followed the instructions provided thus far and inserted the HTML code accordingly. However, upon attempting to load the page, all I see is: The tabs: The Menu Appetizers Mains Desserts The description: image: dish.name , dish.name , dish.labe ...

Challenges arising with the express search feature

Currently, I am in the process of developing an API for a to-do application. I have successfully implemented the four basic functions required, but I am facing some challenges with integrating a search function. Initially, the search function worked as exp ...

creating a list of checkboxes with v-for in Vue.js

Having a bit of trouble with CheckBox selection. I am looping through a DataTable and adding CheckBox to it, storing them as an Array. My goal is to have the functionality where selecting the left checkbox removes the right one, and vice versa for the ri ...

The error message raised is "b.delegate is not a valid function"

By utilizing the jQuery shake effect, I need to include two jQuery files in my project. Below is the code snippet that allows a div element to shake: var isShaking = false; $(document).ready(function() { setInterval(function() { if (!isShakin ...