Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8982847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:40:54+00:00 2026-06-15T20:40:54+00:00

I am just starting using three.js. I have assembled a test using pieces of

  • 0

I am just starting using three.js. I have assembled a test using pieces of code I’ve found on three.js main website.

I have a bunch of geometries (spheres) representing particles which positions are changed inside a loop, according to an equation I made.
I tried to render each iteration through this kind of code:

function simulate() {
    for (var j = 0 ; j < Nb ; j++ ) {           
        // update the geometries positions
        ...
        render();
    }
}

but the rendering was not done, instead it was performed after going through all the iterations, when entering the animate function, called after simulate

function animate() {
    render();
    requestAnimationFrame( animate );
}

Actually the rendering would happen if I was going step by step in the javascript console of my chrome browser.

So I tried to change my code so that I could use requestAnimationFrame inside my loop, that way:

function simulate() {
    for (var j = 0 ; j < Nb ; j++ ) {           
        this.internalRenderingLoop = function() {
            // update the objects shapes and locations
            ...
            render();
            requestAnimationFrame( this.internalRenderingLoop );
        }
    }
}

but it did not work either. I also apparently have a conflict between both calls of requestAnimationFrame leading to Uncaught Error: TYPE_MISMATCH_ERR: DOM Exception 17

So the question is: is there a way to force the rendering at each iteration in my simulate function or do I need to refactor my code so that each call to update the geometries positions is made in the animate or render function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:40:56+00:00Added an answer on June 15, 2026 at 8:40 pm

    Your last function is nearly there. In your for loop, you are just overwriting the internalrendering loop function without it getting a change to execute. Also if you are using the j variable in your shape update code, you need to increment it a bit differently. How about something like this (untested, but you get the idea):

    var j = 0; // need to be outside function to have proper scope
    function simulate() {
      j++;
      if (j == Nb) { return; } // stop
    
      // update the objects shapes and locations
    
      render();
      requestAnimationFrame(simulate);      
    }
    

    You won’t need animate() function at all because you are already doing the animating in simulate().

    Your simulation speed will also depend on framerate, so to have more control on simulation speed you can replace the last line of function with something like:

    window.setTimeout( function() { requestAnimationFrame(simulate); }, 1000 / 25);
    

    This should run it approximately at 25 FPS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just starting using VS2005 and I wish to have code highlighting in C/C++.
I have just reinstalled LAMPP. When I try starting LAMPP using /opt/lampp/lampp start ,
I'm starting android development from just three days, I have downloaded the SDK and
We're just starting with SVN (were using CVS before :shame:) and I have a
I'm just starting out using Ruby and I've written a bit of code to
I'm just starting Rails dev by using Michael Hartl's walkthrough and have hit a
I'm just starting out using Lua, and I was wondering (because I can't find
I'm just starting out with using Core Data on the iPhone SDK and I'm
Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008. I
I'm just starting to look into using LINQ for my database (and XML, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.