Animations of bezier curves created with Three.js

UPDATED: SOLUTION FOUND

I am in need of guidance on how to create animation for the movement of points along a curve to simulate string motion in 3D while keeping performance in mind.

Imagine multiple strings between two points, for example.

Check out this Fiddle for the code. (code updated)

  1. I have a curveObject and I'm attempting to update the position of point1. (code updated)

      var camera, scene, renderer;
      var angle1 = angle2 = 0;
      var curve1, point1, curveObject, geometryCurve, materialCurve;
      var params1 = {P0x: 0, P0y: 0,
                  P1x: 2, P1y: 2,
                  P2x: -2, P2y: 1,
                  P3x: 0, P3y: 3,
                  steps: 30};

      scene = new THREE.Scene();
      camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 10000);
      camera.position.z = 10;
      scene.add(camera);
      renderer = new THREE.WebGLRenderer( { antialias: true } );
      renderer.setClearColor( 0x16112b, 1 );
      renderer.setSize(window.innerWidth, window.innerHeight);
      document.body.appendChild(renderer.domElement);

      createBezierCurveNEW = function (cpList, steps) {

        var N = Math.round(steps)+1 || 20;

        var geometry = new THREE.Geometry();
        var curve = new THREE.CubicBezierCurve3();

        var cp = cpList[0];
        curve.v0 = new THREE.Vector3(cp[0], cp[1], cp[2]);
        cp = cpList[1];
        curve.v1 = new THREE.Vector3(cp[0], cp[1], cp[2]);
        cp = cpList[2];
        curve.v2 = new THREE.Vector3(cp[0], cp[1], cp[2]);
        cp = cpList[3];
        curve.v3 = new THREE.Vector3(cp[0], cp[1], cp[2]);

        var j, stepSize = 1/(N-1);
        for (j = 0; j < N; j++) {
            geometry.vertices.push( curve.getPoint(j * stepSize) );
        }
        return geometry;
      };


      function CreateCurve(){
        scene.remove(curve1);
        var controlPoints1 = [
            [params1.P0x, params1.P0y, 0],
            [params1.P1x, params1.P1y, 0],
            [params1.P2x, params1.P2y, 0],
            [params1.P3x, params1.P3y, 0] ];
        var curveGeom1 = createBezierCurveNEW(controlPoints1, params1.steps);
        var mat = new THREE.LineBasicMaterial( { color: 0x000000, linewidth: 5 } );
        curve1 = new THREE.Line( curveGeom1, mat );
        scene.add(curve1);
      };
      CreateCurve();


      function animate() {
          CreateCurve();
          render();
          angle1 -= .007;
          angle2 += .003;
          params1.P1x = Math.cos(angle1)+2;
          params1.P1y = Math.sin(angle1)+3;
          params1.P2x = -Math.cos(angle2)-2;
          params1.P2y = Math.cos(angle2)+1;
          requestAnimationFrame(animate);
        };
        animate();

      function render() {
          renderer.render(scene, camera);
        };
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r83/three.min.js"></script>
I can see that values are incrementing in the console, but there is no visual feedback happening. My assumption is that I need to update the curve somehow.

The ultimate objective is to smoothly animate a slow sine-like movement of the curve, similar to moving control points of a bezier curve in Photoshop.

(The goal has been achieved, although not by my own work. I came across some helpful code from this source, so a big thank you to those individuals.)

There is limited information available on curve animation in Three.js.

Perhaps someone has already made progress on something similar.

Answer №1

(I successfully achieved the goal with some help from a code library I found at this link. Huge thanks to the developers of that library!)

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

Include the session variable as an argument in the onload() function call

I've encountered a problem while trying to send the session variable $_SESSION["post-code"] as a parameter in the following code snippet... <body onload="getLocation('<?php echo $_SESSION['post-code'];?>')"> Within my ...

Stop the infiltration of emotions into your style

Utilizing the JsonForms React Component to dynamically generate an HTML form in my web application. The framework I am using handles all view rendering on the server side. To integrate this component, I compiled a small react component by running npm run b ...

Guidelines for incorporating role-based permissions in a React application

I am developing a MERN application that has various features catering to different roles. I need the ability to display specific data, navigation options, and divs based on the user's role while hiding these elements from others. It is important to no ...

tips for converting a single observable item into an observable list

Within my Angular project, there exists an observable object with the following structure: export interface FavoritesResponse { wallet: boolean; deposit: boolean; withdraw: boolean; transfer: boolean; exchange: boolean; ticket: boolean; accou ...

What causes the variable to be invisible in the imported file?

Within the main.js file, there is a specific code snippet: var test_mysql = require('./test_mysql.js') ... //additional code before(function(){ test_mysql.preparingDB(test_mysql.SQL_query.clear_data); // or test_mysql.preparingDB(SQL ...

Incorporate a hanging indent within the text enclosed by the <li> element

(revised multiple times to enhance clarity) Disclaimer: I did not create the HTML code. Below is the structure of the HTML (please note that the links and text following them are on the same line): <li> <strong>Heading of section</str ...

Unable to locate and interact with a specific element within a dropdown menu while utilizing Protractor

I am currently facing an issue with selecting a checkbox from a dropdown in jq widgets. The code seems to work fine when the element is visible on the screen, but fails otherwise. I have tried various methods such as executeScript and scrollIntoView to bri ...

Determine the quantity of items that meet specific criteria

The initial state of my store is set as follows: let initialState = { items: [], itemsCount: 0, completedCount: 0 }; Whenever I dispatch an action with the type ADD_ITEM, a new item gets added to the items array while also incrementing the count in ...

Switch Between Different Background Colors for Table Rows With Each Click

This script changes colors when a row in a specific column is clicked: $(document).ready(function(){ $("#rowClick").children("tbody").children("tr").children("td").click(function(){ $(this.parentNode).toggleClass("enroute"); }); }); CSS: .placed{ b ...

How can we effectively map Typescript Enums using their keys without relying on a Map?

Consider the following Enum instances: export enum TopicCategories { GUIDES = 'Guides', TASKS = 'Tasks', CONCEPTS = 'Concepts', FORMULAS = 'Formulas', BLOGS = 'Blogs' } export enum Top ...

Associating models using a many-to-many relationship in Sequelize unexpectedly restricts the ability to modify attributes in the join table

I am in the process of incorporating a voting feature into my app, allowing users to vote on responses from other users. The backend of my Node app is built using Express and Sequelize. Currently, I am utilizing a SQLite database for testing convenience. ...

Using request-promise from npm, send a request with a self-generated certificate in JavaScript

When trying to make a simple request using the request-promise library, I encountered an error due to having a self-signed cert in my chain. This is a requirement that cannot be avoided. Fortunately, with NPM, I was able to specify the cert for installing ...

Is AngularJS not able to effectively manage the button type "reset"?

I currently have the following code snippet: <form name="editor"> <h2>Create/Update</h2> {{ editor.title.$error.required }} <div ng-class="{ 'has-error': editor.title.$invalid && editor.title.$dirty, &apo ...

What is the typical response time for a request using javascript axios?

In my current application, I am fetching data from an API and everything is functioning correctly. However, I am interested in determining the duration of each request in milliseconds. To achieve this, I implemented interceptors using axios. The challenge ...

Ways to stop the react-router from causing the page to refresh

Need assistance with React Router issue I'm working on a project in reactJs using react-router-dom v5. I have set up a default route for routing. <Redirect to={"someComponent"}/> The problem is that when I refresh the page, it auto ...

Update JSON values using JavaScript or jQuery

In the code snippet provided, there is an issue where nameElem.data('index') does not change, causing it to always display element 1 in the list. I attempted to change the json value with cardInfo[i].data.index = index;, but that did not solve th ...

Wait for a reply from one GET request before initiating the next one in node

When working with node, I am making two consecutive calls to an API. My goal is to ensure that the first GET request has completed before triggering the second one, using data from the response of the first call. To achieve this, I have experimented with ...

How about "Incorporate Google Auth into your Vue.js project with modular

I'm on the search for a project that showcases using Vue.js and the Google client library to authenticate with JavaScript, but without the need for transpilers, bundlers, or Node/npm. Does anyone know of such an example out there? I simply want to cre ...

Modify the properties of a particular component

I have an array of rooms filled with data: const room = (<Room points={points} scene={this.scene} key={this.rooms.length} keyV={this.rooms.length} />) this.roomData.push(room); For example, I now have 3 rooms each with their ...

Unable to display label in form for Angular 2/4 FormControl within a FormGroup

I'm having trouble understanding how to: Use console.log to display a specific value Show a value in a label on an HTML page Display a value in an input text field Below is my TypeScript component with a new FormGroup and FormControls. this.tracke ...