Managing animations in Three.js

I have a Blender animation imported into three.js and I am trying to control the animation using a vertical slider bar with the ID "#roof_angle". As I drag the slider up or down, the animation should go forward or backward. Everything works fine initially, but after some time, the animation starts to lose track of the slider position. How can I fix this issue? What am I missing? The animation consists of 90 frames and the height of my slider bar is 504px.

Here is my code:

function onDocumentMouseDownY( event ) {
   document.addEventListener( 'mousemove', onDocumentMouseMoveY, false );
   last_positionY = event.clientY; 
}
function onDocumentMouseMoveY( event ) {
    delta_mouseY = last_positionY - event.clientY;
    roofAngle = $( "#roof_angle" ).slider( "option", "value")
if(delta_mouseY >= 1){
   if(roofAngle >= 0 && roofAngle < 90 ){
      roofAngle ++;
      animation.update(1/24*(90/504)*delta_mouseY);
   }
}
   else{            
   if(roofAngle > 0){
    animation.update(1/24*(90/504)*delta_mouseY);
    roofAngle --;
   }
   }
  last_positionY = event.clientY;

}

Answer №1

After encountering a problem, I managed to find a solution by implementing some specific conditions related to "animation.currentTime". In my case, the duration of my animation is 3.75 seconds. However, this approach does not provide an explanation as to why there is a floating point delta time in my animation.

function onDocumentMouseMoveY( event ) {
        delta_mouseY = last_positionY - event.clientY;
        roofAngle = $( "#roof_angle" ).slider( "option", "value")
        timeFrameDelta = 1/24*(90/504)*delta_mouseY;

        if(delta_mouseY >= 1){
            if(roofAngle >= 0 && roofAngle < 90 && animation.currentTime+timeFrameDelta < 3.75){
                roofAngle ++;
                animation.update(timeFrameDelta);
            }
        }
        if(delta_mouseY < 0){
            if (animation.currentTime < 0){
                animation.currentTime = 0;
            }
            if(roofAngle > 0){
                animation.update(timeFrameDelta);
                roofAngle --;
            }
        }

        last_positionY = event.clientY;
  }

If anyone has a more efficient method or helpful tips, please share them with me.

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

Send a pair of selected options from dropdown menus to a service using Angular

I have created a component that needs to pass two values from two separate dropdowns to my service on button click. Here is the code for my component: import { Component, Input, OnInit } from '@angular/core'; import { CategoryType } from '. ...

Why does the Mongoose query findOne({params}) return null when it successfully runs in the mongo shell?

Here are the software versions currently being used: mongoose 4.10.8, mongodb 3.4, express 4.13.4, nodejs 6.11.1, npm 3.10.10, When querying in the Mongo shell, I can easily find a user using findOne: > db.users.findOne({"admin":"true"}).pretty() & ...

Modify the appearance of every instance of a specific phrase

Looking to give my site title a unique font separate from the rest of the content every time it appears in a heading. This is all for branding purposes. Let's say my custom font is Courier and my company goes by the name SparklePony. For example, if t ...

Utilizing Vue-cli 3: Incorporating static assets with a specific path

My application is located at: https:/firstpath.com/firstsubfolder/app.html When using relative paths, my static assets are being loaded from: https:/firstpath.com/firstsubfolder/img/image.png Is there a way to specify a specific path for my static asse ...

Sending an Ajax POST request from a Node.js server

I am running a Node.js server with Socket.IO that communicates with a Python server using Django. I am looking to make a POST request from the Node.js server to the Django server on a specific method without utilizing any jQuery functions due to their depe ...

Adjust the Highcharts semi-pie design by eliminating the gap between the pie and the legend

I'm having trouble adjusting the spacing between the bottom of a semi circle donut chart in Highcharts and the legend below it. Despite my efforts, I have not been successful in reducing this gap. Here is the basic chart I am currently working on: h ...

Uploading Files with Vuetify 2 v-file-input and AxiosIn this tutorial, we

After researching extensively on the topic, I reviewed questions such as file-upload-in-vuetify and vuetify-file-uploads, but unfortunately, the solutions provided did not work for me. My current challenge involves utilizing Vuetify 2's <v-file-in ...

avoiding the duplication of effects on an object when new objects are added via ajax

Currently, I am facing a minor issue with an application that I am working on. The problem arises on a particular page where the user can edit a document by dragging modules onto the canvas area. Upon loading the page, JavaScript causes the modules to be ...

Utilizing vue.js router guards with asynchronous user information retrieval

Currently, I am developing a Vue.js application that requires the implementation of router guards to restrict access based on user roles and prevent unauthorized users from accessing the application. The login process involves integrating an external appli ...

React.js, encountering unusual behavior while implementing a timer

I'm currently working on a React project to create a basic timer. The start button should initialize the timer, while the stop button should pause it. However, I've encountered some unexpected behavior. When I click on start for the first time, ...

How can I identify a point that is located a distance X away from a given position and rotation?

Given a point's position and orientation in three-dimensional space, how can I find the endpoint of a line that is located at a specific distance from the origin point and follows the same orientation? Please note that the solution does not necessari ...

Is the && operator being utilized as a conditional statement?

While following a tutorial, I came across this code snippet that uses the 'and' operator in an unusual way. Is this related to React? Can someone provide an explanation or share documentation that clarifies it? {basket?.length > 0 && ...

Preserving Search and Filter Settings in jQuery Data Tables

I've been working with a datatable and I'm trying to figure out how to keep dropdown filters and search parameters saved when the page is reloaded, just like shown in the screenshot below. However, I also want these parameters to be cleared if th ...

Error encountered in WebStorm while using eslint-config-standard configuration

I am currently utilizing the WebStorm IDE to develop a Node.js server. To follow the instructions, I installed eslint-config-standard by running: npm install --save-dev eslint-config-standard eslint-plugin-standard eslint-plugin-promise eslint-plugin-imp ...

Steps to include a timed message following a successful AJAX request (or error) using knockoutjs

How can I implement a timed update message feature after ajax success or error in knockout.js? One way to achieve this is: var ViewModel = { var self = this; self.message = ko.observable(""); self.setMessage = function(message, timeout){ ...

Setting the box width to "0" will actually render as a width of "1"

While attempting to create a box new THREE.BoxGeometry(opening.geometry.xLength, opening.geometry.yLength, opening.geometry.zLength) a situation arises where a box with 0 width is produced. new THREE.BoxGeometry(0, 1, 1) Surprisingly, it ends up render ...

Objects in Three.js cast shadows onto themselves based on their geometry

After experimenting a bit with clara.io, I want to recreate an image that was created using the software. I've spent days scouring the internet trying to figure out how to achieve what they refer to as "Realistic" rendering. In the image I'm try ...

Refresh Ajax to dynamically update multiple div elements based on a single value

Good Day, I have been implementing Eliza Witkowska's Ajax Auto Refresh code available at this link. My goal is to retrieve data from a database and distribute it into 3 different divs based on the value of the field dish_type, which contains integer ...

Reduce numerical values within tables

How can I shorten the numbers displayed on json / datatable? I have extracted json data from a website, but the figures shown in the json are too detailed. For instance, instead of displaying 408.43324032, I simply want to show 408 or 408x. https://i.ss ...

Iterate over the controls within an UpdatePanel, and interact with JavaScript functions

I'm attempting to change all TextBoxes into labels on my page using the following code: foreach (Control ctrl in masterform.Controls) { if (ctrl.GetType() == typeof(TextBox)) { TextBox t = ctrl as TextBox; t.ReadOnly = true; ...