Unsteady motions in three.js Animation

I am experiencing issues with animation and movement in my three.js scene. Regardless of whether I move the camera by a very small amount or animate an object using Tween.js, the animation appears jerky with the object jumping around its axis of movement, indicating a potential rounding error in positioning.

The problem becomes more pronounced when I move far from the scene center (which is at vertex 0,0,0), for instance to vertex 0,8000000,0.

This issue occurs both when moving the camera and when moving objects.

I am utilizing standard example codes and libraries:

<script src="http://threejs.org/examples/../build/three.min.js"></script>
<script src="js/Detector.js"></script>
<script src="js/TrackballControls.js"></script>
<script src="js/stats.js"></script>
<script src="js/tween.min.js"></script>

I can provide a snippet of code here, although I'm unsure which part may be relevant.

View a video demonstration of the issue here:

Video of screen

EDIT:

Attempting to position the object and camera closer to the center (at XYZ:0,0,1000) results in reduced jitter, but the error is still noticeable: Second video available here

Answer №1

Encountering two issues within a single question.

I managed to tackle them using two different methods.

Firstly, the issue of jerky movements of an object on camera movement. It gives the illusion that the object is sporadically jumping around its position, when in reality, it remains stationary while the camera moves (sometimes jumping during orbit or zoom). This discrepancy is due to a loss of precision as the distance from the center of the scene increases significantly (reaching about 10 million units).

The solution lies in either scaling down the size of the scene significantly or exploring alternative ways to maneuver the camera around the object without sacrificing precision.

To rectify this, simply move the object closer to the center of the scene at Vertex(0,0,0).

Secondly, the problem of erratic object movements during TWEEN transitions from point A to point B. This inconsistency stemmed from the rendering process, which was being triggered after a certain delay following the TWEEN.update() call. Consequently, the smooth transition of the object was not synchronized with the TWEEN calculations, resulting in slight overshooting and subsequent readjustments in each frame.

The remedy involves adjusting the positioning of the TWEEN.update() call within the render() function (which is called by animate()). By ensuring that the update occurs before the rendering, the fluidity of object movements can be preserved without discrepancies.

Previously:

function animate() { 
      render();
      TWEEN.update(); // as suggested by TWEEN.js documentation
      requestAnimationFrame( animate );
}

function render() {      
      renderer.render( scene, camera );         
}

Now:

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

function render() {      
      TWEEN.update(); // implementing this adjustment has proven effective      
      renderer.render( scene, camera );         
}

Though this issue may manifest in various scenes, it's less perceptible over shorter distances.

Answer №2

I have devised another strategy to address the issue of losing precision in a vast scene.

Instead of compromising on precision for camera and object movements across long distances (e.g. coordinates XYS(1000000000,165464464665464464,0)), I opted to tackle the problem differently.

My solution involved creating a parent object that moves in the opposite direction of my ship. While my ship remains fixed at scene position XYZ(0,0,0), all other objects are nested within the parent object, which orbits around my ship in the opposite direction.

When I need to move my ship, rather than directly translating it with ship.translateX(10), I instead translate the parent object with parent.translateX(10*-1).

This approach ensures consistent precision over unlimited distances without the need to manage camera orbiting around the moving ship or adjust the skybox, as my ship always stays within the confines of the scene (preventing it from moving outside the skybox).

However, this solution does shift the challenge from one aspect to another, requiring accurate calculations for positions within the parent box and the relative positions of my ship. For further details, I posted an additional question here:

- not active as of 2021,

Alternatively, you can explore a similar solution discussed in this related query: How to get the global/world position of a child object?

For reference, refer to the documentation provided here: https://threejs.org/docs/#api/en/core/Object3D.getWorldPosition

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

Error encountered while parsing a file: JSON parsing failed due to an unexpected token 'g' at position

https.get('example.com/phpfilethatechoesandimtryingtograbtheecho.php', (res) => { console.log('statusCode:', res.statusCode); onsole.log('headers:', res.headers); res.on('data', (d) => { return ...

"Encountering an issue with undefined request.body in Express after using

Update: The issue has been resolved by incorporating the following code: app.configure(function(){ app.use(express.bodyParser()); }); Original query: I am currently grappling with how to handle a post request using node and express, and I seem to be ...

Generates a dynamic HTML table using JSON data through JavaScript

I need help organizing my json data into a dynamic HTML table with customizable headings. If there is no value for a particular item, the box should remain empty. [ { "name":"value1", "email":"<a hr ...

React application experiencing continuous SpeechRecognition API without stopping

I need assistance with integrating speech recognition into my web application using Web API's speech recognition feature. Below is the React code I am currently working with: import logo from './logo.svg'; import './App.css'; impor ...

Display progress bar dialogue upon submission

I am looking to implement a jQuery popup that displays "Loading..." on every postback. I am unsure of how to achieve this and which technologies to use. My goal is to create the code in a superclass so that it only needs to be coded once. Ideally, when I c ...

Troubleshooting Problem with Facebook Messenger Bot Webhook

I received the following notification: Your Webhooks subscription callback URL is not currently accepting updates. We have observed that your Webhooks subscription for callback URL has been inactive for at least 16 minutes. Please ensure that your cal ...

Tips for designing a pre-selection process

I've been considering the idea of implementing a temporary screen that allows users to choose between different options before proceeding to a specific page. For instance, on the contact page, users would be prompted with a question like "Are you loo ...

Transform a series of items into an array

I have a task where I need to create a function that takes a list as an argument and returns its elements in an array format. For instance, if the input is: {value: 1, rest: {value: 2, rest: null}} Then, the expected output should be: [1, 2] This is my ...

Implementing JavaScript to provide personalized error messages for empty form fields

I am facing an issue with form validation on iPhone / Safari, as they do not recognize the required attribute. I want to display individual error messages below each empty input field using JavaScript. Although my code is functional, the problem is that t ...

"Tips for positioning the center of a map with the help of external latitude and longitude

I have developed a program that extracts an address from a database. To obtain the latitude and longitude of the address, I utilized geocoder (https://www.npmjs.com/package/geocoder). Now, every time I click a button to retrieve the address, I want the map ...

Execute a function once the user has finished typing

I have a textbox that should update search results in real-time as the user types. The typed input will filter down an array of data, showing only items that match the input. Currently, I am using the onBlur event, which updates the results after the user ...

Converting Excel Cell Content to HTML Format

Is there a way in Angular to read formatted cell values as HTML for rendering on a webpage? For example, if I have a cell in Excel with the Name formatted as bold, how can I read it as Name in Angular and display it on the webpage? I have looked into some ...

What is the best way to declare a TypeScript type with a repetitive structure?

My data type is structured in the following format: type Location=`${number},${number};${number},${number};...` I am wondering if there is a utility type similar to Repeat<T> that can simplify this for me. For example, could I achieve the same resul ...

Determining the Visibility of a Control within a Container with Scrollbars

Here is the code snippet that I am working with: <div style="overflow: scroll; width: 75px; background-color: Black; "> <table style="background-color: Red"> <tr> <td> < ...

FileReader and Socket.io uploader: each new upload builds upon the previous uploads

I have been working on integrating a file uploader using html5, js, and node which uploads large files in chunks. Everything works perfectly for a single upload. However, when attempting to upload again on the same page, it gets stuck in an endless loop wh ...

Encountering a parsing error while trying to fetch and parse XML using

I'm looking to retrieve XML data from the following URL using JQuery Ajax When accessing via browser, this is displayed: This XML file does not appear to have any style information associated with it. The document tree is shown below. <puco> ...

Extending the rules and requirements of VInput

Currently, I am utilizing Vue+Vuetify and facing the task of revamping a custom selector component. The existing code structure is as follows: <template> <v-autocomplete :id="id" v-model="internalValue" :clearabl ...

JavaScript .indexOf array method not functioning properly in Internet Explorer versions 7 and 8

I'm curious to know if IE 7 and IE 8 are compatible with the JavaScript .indexOf() method because I keep getting this error message: SCRIPT438: Object doesn't support property or method 'indexOf' This error appears in the IE9 debug co ...

What is the best way to target changing elements displayed by *ngIf?

Trying to access a dynamic element generated by ngIf in the code below has proven to be challenging. I attempted two different methods: Using ElementRef and querySelector Component template: `<div class="test" *ngIf="expr"> <a id="b ...

Error in Dimplejs: Line is not visible when series is empty

I have a dimplejs.org line chart set up. I am trying to colorize the Clicks data points from blue to red (blue for fewer clicks and a gradient from blue to red for more clicks). When I set the series as shown below, it works fine but the tooltip only incl ...