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

React: Updating useState array by removing the first element triggered by an event or timer

I am currently working on a function that populates a useState array containing objects representing cars. These cars appear on the left side of the screen and move across until they are off-screen. My goal is to remove these cars from the state array once ...

The embedded component is throwing an error stating that the EventEmitter is not defined in

Currently, I am delving into the realm of angular and facing an issue. The problem lies in emitting an event from a component nested within the main component. Despite my efforts, an error persists. Below is a snippet of my code: import { Component, OnIn ...

When a textbox is modified and a button is clicked in ASP.NET, triggering both client-side and server-side events

I have a popup that allows users to change an address. It contains three text boxes (Address, Province, and ZIP) and one DropDownList for the City. When the ZIP code is changed, an ajax call updates the province text box. I also want to later populate the ...

What is the best way to set the width of a w2grid to 100%

Has anyone tried using w2grid before? I'm having trouble figuring out how to make it fill its container 100%. Here's the HTML snippet: <div id="a" style="width:100%"> <!-- top left container--> <div>This ...

Restricting the frequency at which a specific key value is allowed to appear in JSON documents

Within my JSON file, there is an array structured like this: { "commands": [ { "user": "Rusty", "user_id": "83738373", "command_name": "TestCommand", "command_reply": "TestReply" } ] } I have a requirement to restrict the num ...

Having trouble setting the `variant='dense'` for material-ui Toolbar – it remains at a height of 64px no matter what

Implemented a hello world AppBar/Toolbar with the variant='dense' style. import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import registerServiceWorker from './registerServiceWo ...

Issue with the scope of Bootstrap Accordion

Observing that the event triggers on a single Bootstrap accordion can affect all other accordions on the same page, I am wondering if there is a way to isolate this behavior without altering the markup or using $(this). Any suggestions? Check out this exam ...

Right now, I am sending out 3 GET requests for JSON files using Axios. I wonder if they are being loaded simultaneously or one after the other

In the process of developing my application, I am loading 3 JSON files to gather information about a game's characters, spells, and more. As of now, I have implemented 3 functions that utilize axios to make GET requests and store the responses. Howeve ...

Interactive Show Map with Autocompletion Feature

I attempted to implement autocompletion for my application and integrate it with Google Maps, but I'm encountering issues. The code for autocompletion is located in a separate JavaScript file called autocomplete.js. Since I already have a Google Map ...

Using innerHTML in React to remove child nodes Tutorial

I'm encountering slow performance when unmounting over 30,000 components on a page using conditional rendering triggered by a button click. This process takes around 10+ seconds and causes the page to hang. Interestingly, setting the parent container& ...

Creating dynamic content in the Ajax-enabled Smart Admin theme: A step-by-step guide

As I work on developing an application for a client, my focus is on creating a web service using Laravel5 for the backend. To enhance the user interface of this web service, I have chosen to incorporate the Smart Admin Theme, specifically utilizing the Aja ...

apply styling to the placeholder with CSS

I have been attempting to customize the styling of the placeholder text. After setting the color to red within the input class, I did not see any changes. Even after conducting research and referring to this link Styling the placeholder in a TextField, I w ...

Issue with TypeScript in Vue3: Unable to access computed property from another computed property

In my Vue3 project with TypeScript, I am encountering an issue where I am unable to access the properties of the returned JavaScript object from one computed property in another computed property using dot notation or named indexing. For instance, when tr ...

React Higher Order Component (HOC) encountered an ESLint issue: spreading props is not

Does eslint lack intelligence? The Higher Order Component (HOC) is quite generic, so I struggle to specify the incoming options/props as they are dynamic based on the component being wrapped by this HOC at any given time. I am encountering an error statin ...

Obtain the user's email using nodemailer

I created a contact form using Nodemailer that I am having trouble with. Take a look at the code below: let mailOptions = { from: '<<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e3636360e363636602d2123">[emai ...

Display the iframe website without it being visible to the user

Is there a way to load a separate website, such as a Wikipedia article, in an iframe on a webpage without freezing up the whole page when it becomes visible after clicking a "show" button? And if not, how can we display a loading gif while the iframe is ...

Jquery not populating table as anticipated

I am having an issue with populating a table using a JSON file. The first row works fine, but the subsequent rows are not showing up. Can someone please help me identify what I am doing incorrectly? Is my looping structure flawed? Thank you for your assi ...

Implementing Dual Submit Buttons in Node.js using Express Framework

Struggling with implementing a like and dislike function in my node js app. Currently, I can only do one at a time. Below is the HTML code snippet: <form method="post" name="ratings"> <input type="submit" name="vote" value="like"> < ...

Components in array not displaying in React

I've been struggling to generate a table from an array in React. Typically, I retrieve data from a database, but for testing purposes, I manually created the array to ensure the data is correct. Despite following examples by enclosing my map code with ...

When running `grunt serve: dist`, an error is thrown stating: "Unknown provider: utilProvider <- util <- NavbarController"

I am facing a problem with my angularJS website that is built using the yeoman angular-fullstack generator. When I run grunt serve, everything works perfectly fine. However, when I try to run grunt serve:dist, I encounter this error: grunt serve: dist -&g ...