Smoother transitions with spline curves in Three.js

My current project involves drawing a CubicBezierCurve3 curve in three js. However, I want to enhance the drawing process by visualizing it as a moving rocket leaving behind a gas trail. Rather than having the entire curve drawn at once, I aim to draw it part-by-part with a smooth transition.

My Approach:

  1. To begin, I collect all the points that make up the CubicBezierCurve3 and store them in a variable named 'allpoints'. Let's assume that we have exactly 50 points in the CubicBezierCurve3.

    var curve = new THREE.CubicBezierCurve3(
            new THREE.Vector3( -5, 0, 20 ),
            new THREE.Vector3(0, 15, 0 ),
            new THREE.Vector3(0, 15, 0 ),
            new THREE.Vector3( 2, 0, -10 )
    );
    
    geometry = new THREE.Geometry();
    geometry.vertices = curve.getPoints( 50 );
    allpoints = geometry.vertices;
    
  2. During each iteration, I plot 10 points as follows:

Iteration 0: plots points 0 to 9 Iteration 1: plots points 10 to 19 Iteration 2: plots points 20 to 29 Iteration 3: plots points 30 to 39 Iteration 4: plots points 40 to 49

The function I've implemented ensures that 10 points are plotted in each iteration. With a total of 50 points, I call cancelAnimationFrame at the end of the 5th iteration to stop the drawing process. The function includes certain adjustments to handle timing issues; for instance, the 10-point sequence is only plotted every 10 iterations to ensure a smooth transition.

 function drawPointCloud() {
        // Function logic goes here...
    }

JS Fiddles:

  1. Check out this JS Fiddle example demonstrating the smooth transition concept
  2. Here's another JS Fiddle example showcasing all points in the CubicBezierCurve3

Is there a more efficient way or API available to achieve this incremental drawing effect? Additionally, I'm interested in adding a delay to the points before they disappear, similar to the fading of an LED. I am open to exploring alternative approaches to incrementally drawing parts of a given cubic bezier curve.

https://i.sstatic.net/O7y6M.png

Answer №1

Have you thought about incorporating a particle system using the THREE.GPUParticleSystem plugin? Check out this example for inspiration.

It immediately brought to mind the image of a "gas trail" from a rocket...

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

Reimagining scrolling through content with a stylish unordered list (a sleek alternative to a select box

After having our company website redesigned by a professional designer, our site now looks much more visually appealing. However, I have encountered difficulties when trying to implement their design using HTML and CSS. One particular challenge is the heav ...

Unable to load files in Handlebars when using Node and Express

Currently, I am in the process of developing a Node/Express web application for basic CRUD operations. However, I am encountering difficulties incorporating Handlebars into my project. Whenever I attempt to utilize Handlebars, none of the stylesheets from ...

Manipulating object information within a nested for loop

I have a variable called jobs in my scope, which is an array containing objects for each department along with their respective data. [ “Accounting”: { “foo” : “foo”, “bar” : "bar" }, “Delivery”: { ...

Jquery Validate doesn't consistently give a positive response

Having a button that triggers the jQuery validation plugin poses an issue where it consistently returns true, except when the fields are left empty. The rules set for validation seem to be disregarded. DEMO http://jsfiddle.net/sw87W/835/ $(document).read ...

Loading an OBJ file from a blob using three.js

I am currently attempting to load an OBJ file from a blob using Three.js. After referring to this resource and successfully loading STL files, I encountered an issue with loading OBJ files. The error message I received is as follows: TypeError: text.indexO ...

Guide on incorporating a refresh button to automatically update information from a database in MaterialUI's Datagrid

Recently diving into JavaScript, I encountered a common issue: The data for my table is sourced from a MySQL database through Axios Whenever CRUD operations are performed in the web app, the database is updated accordingly Although backend changes ...

What is causing the code behind to reject the href with 'aspx' in the anchor tag?

I am currently working on implementing a calendar control that will display Today's Due and Overdue items in separate accordion sections when a date is selected. To achieve this, I have written the necessary code in the back end and used a style.css f ...

Problem: The variable "$" is not defined in angular datatables causing a ReferenceError

Trying to implement Paging and sorting in my table, but encountered an error even after following all the steps mentioned here: . Tried troubleshooting the issue with no success. Ensured that all dependencies were installed properly. Below is the compo ...

`Exit out of the current tab and navigate back to the parent tab`

Looking to add a link on a webpage that will specifically close the active tab in a browser without affecting other tabs. Upon clicking the close link, the user should receive an alert message prompting them to confirm with two options: "YES" and "NO". If ...

Display each new array element on a separate line

let team = [['Sara', 'John', 'Kate']] let newTeam = team.map(function(r) { return r; }) outputs [ [ 'Sara', 'John', 'Kate' ] ] Is there a way to modify it so that each value is r ...

Guide to incorporating React component with Postgres database

I'm confused about a scenario where I have created a React project with the command npx create-my-app myProject, and within the public folder, there are multiple folders containing NodeJS for a Postgres database. My question is, if I need to access da ...

Add a new sibling item to Angular-UI-tree

I am trying to add a sibling item to a tree when clicked in angular-ui-tree (https://github.com/angular-ui-tree/angular-ui-tree) Here is an example of what I currently have: <item><input value"item A #1"><button>insert under</button& ...

Using an object method within a different object in JavaScript

I am attempting to create two objects, one from each of my classes - a Person object and a Drink object. I then want to invoke the drinking method by passing in a Drink object. However, I am struggling with how to do this. Here is my code, and I can't ...

Enabling the acceptance of blank values within an HTML5 date input field

When using an HTML5 date input for a field that corresponds to a nullable datetime column in the database, how can one avoid setting an empty value in the input field? In my AngularJS application, the ng-model is connected to a scope variable with an init ...

Three.js combined with Ember.js

I've been brainstorming ways to merge Ember.js with Three.js. My goal is to render multiple elements, manage the data with Ember.js bindings and general pub/sub handling, while also being able to manipulate the views/elements with three.js using THREE ...

When exporting from Substance Painter to GLTF in WebGL using Three.js, the colors appear completely dark

After importing my model (.fbx) into Substance Painter to apply a texture and then exporting it to the .gltf format, I noticed that the painted metal disappeared and was replaced by a shiny black material. When I viewed the exported model in the three.js/e ...

Ways to trigger a JavaScript function upon submission of my form

I have created a code snippet to validate and submit a contact form: formValidation: function() { if ( this.formData.name && this.formData.company && this.formData.email && this.formData.industry && this.formData.phone && this.fo ...

Deleting uploaded images in Cloudinary for Next.js is not allowed

After successfully implementing image uploads in cloudinary for Next.js, I encountered an issue with image deletion. Despite creating the necessary routes and components, the deletion functionality is not working as expected. I am unsure of what could be ...

Guide to adding information to an .xml document

Currently, I am working on building a website for a school project, specifically an online shop. I am focusing on the shop section, where I need to store data such as name, price, image, and description in either a text file or XML format. Right now, the w ...

Extracting server error messages on the client side using Node.js

Before storing data in the database, my server performs validation checks. If it is unable to save the data into the database, an error message is sent. In my client-side application, how can I retrieve and display this error message? Below is the HTTP r ...