Altering the trajectory of a tube in three.js during the rendering process

Here are the steps I take in my approach:

1) Establish an initial path for the tube by creating an array of positions of points.

2) Render the tube based on the created path.

3) Modify the path array.

4) Repeat step 2.

To achieve this, I believe functions like the following may be necessary:

function morphPath(path){
// implement some magic here
return newPath;
}

function morphTube(path){
// adjust the tube's vertices positions according to the provided path
}

Let's say I aim to display a snake that moves around dynamically.

I came across a complex example which is beautiful but challenging for me. Any help in gaining a basic understanding of how to address my problem would be greatly appreciated.

Example - http://codepen.io/tdhooper/full/ZGPOQJ/

In order to create the tube, I use the following function:

var geometry = new THREE.TubeGeometry( curve, 10, 3, 20, false );

I am seeking guidance on which function to utilize for curve creation and specifically how to morph (not scale, not rotate, not translate) the tube?

The array of points I work with is straightforward:

points = [{ x: 0, y: 0, z: 0}, { x: 1, y: 1, z: 0}, { x: 3, y: 0, z: 0}]

Answer №1

When you instantiate any type of Geometry in THREE.js, the instance is equipped with a 'vertices' property by default. In this scenario, using a Cylinder Geometry results in the generation of numerous vertices derived from the initial points array (Vector3) provided during curve creation.

Therefore, my suggestion would be to create a new path for every morphing requirement. Subsequently, for morphTube functionality, generate a fresh cylinder geometry based on the established path. You can either dispose of the existing geometry attached to the rendered mesh and replace it with the new one (a complex process at times), or manually transfer each vertex from the recently created cylinder geometry to the one currently linked with the mesh.

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

What steps should be followed to display an HTML page within an HTML div?

The question I have is a bit misleading, as I'm not looking for guidance on how to open an HTML document in a div. Rather, I am currently facing an issue where I am unable to replace the HTML file that I have already placed in a div. Initially, I pla ...

Guide to positioning a THREE.js plane onto the exterior of a spherical object

Just starting out with Threejs and 3D graphics. I'm interested in learning how to position a plane of any dimensions on the surface of a sphere. Here's an example image of what I'm aiming for: example image ...

Unable to conceal tab content upon clicking the identical tab

I recently implemented a tab system with panels that seems to be working well when switching between tabs. However, I'm facing an issue where clicking on the same tab does not hide the corresponding panel and reset the aria attributes as intended. I&a ...

Looking to retrieve data using Cheerio? If you're finding that the data appears empty in the page source but is visible when inspecting the elements, here's how you can go

I am encountering difficulties while trying to scrape data from another website. In my case, I notice that the data appears empty when viewing the page source, but it is visible when inspecting the elements. If you're confused, please refer to the fol ...

Argon-aframe is designed to dynamically respond to the user's exact geolocation

Currently, I am working on a project which can be found at this link: my codepen The main objective of my project is to create an immersive experience where users can walk through a virtual floor plan in VR as if they are walking in real life. I aim to u ...

Exploring different methods for drawing a polygon by iterating through JSON values

I am attempting to automatically draw a polygon using values stored in a database. The Python file I have returns JSON results to an AJAX call. In the AJAX success section, I need to iterate through the JSON data and automatically draw a polygon on a Googl ...

Add items to a fresh record using Mongoose and Express

In my model, I have an array of objects that I want to populate with new items when creating a NEW document. While I have found information on how to achieve this using findAndUpdate, I am struggling to figure out how to do it with the save() method. This ...

Screen the array and find at least one matching criterion

So, I've encountered a challenge that I'd like to address: Filtering an array based on specific conditions using Vue.js and lodash (or raw JavaScript). The Objects I'm Working With I have a list of Items. Each item may have (optional) cat ...

The ng-change event is triggered for radio buttons that are generated using ng-repeat the first time they appear, but not for subsequent appearances

Is it possible to trigger the updateRow method on every change of a radio button selection? Currently, the updateRow method is only being called the first time the radio button changes. How can I make sure it executes each time there is a change? Html: ...

What is the best way to transfer form input data from a child component to the parent component in React?

Recently delving into the world of React, I decided to experiment with forms. My project idea was straightforward - create a form component with input fields that, upon clicking submit, would pass the input values to the parent component ('App') ...

React - Anticipated an assignment or invocation of a function

Recently starting my journey with reactjs and encountered a small issue. A pesky error keeps popping up saying: Expect an assignment or function call. It's related to the User function, however, I do call that function when creating a new object. Any ...

What is the best way to integrate asynchronous computed observable with several concurrent $.ajax requests?

I'm currently working on implementing an asynchronous computed observable following the guide provided here. While I have successfully achieved this for a single ajax call, I am facing a challenge in figuring out how to perform multiple ajax calls in ...

Tampermonkey script encounters the error message "targetNode.dispatchEvent is not a recognized function"

I am attempting to press a button with Tampermonkey but keep encountering this error: userscript.html?id=2514f475-79e4-4e83-a523-6fef16dceeaa:10617 Uncaught TypeError: targetNode.dispatchEvent is not a function at triggerMouseEvent... Check out my scri ...

Show only relevant dropdown options when a radio button is selected, and also automatically adjust options when the page

I am working on a form that includes radio buttons and a dropdown list. If the user chooses 'girls', I need to display only caroms and chess, which are specified in the girlsGames variable. If the user selects boys, I want to show the dropdown ...

I am looking to remove identical innerText values from two arrays using JavaScript

Is it possible to use JavaScript to remove the "added" className of an element with the same innerText when the delete button (.btn-wrap>li>button) is clicked? <div class="table"> <ul> <li class="added">l ...

Resizing and uploading multiple images with accompanying descriptions

I am in need of a solution for uploading multiple images along with descriptions. Users will be uploading 1-10 large-sized images from cameras, so it would be ideal if the images could be resized before the upload. My requirements are: Compatibility wit ...

Trouble getting a sticky element to align with a two-column grid within a parent container

I'm looking to keep one column sticky in a two-column grid setup. My goal is to create a vertical navigation bar that's specific to a particular div within a single-page site, with a fixed horizontal navbar across the entire page. However, I&apos ...

Looping through Angular promises sequentially

I am faced with a dataset consisting of the following information. $scope.orders = [ { material: 'A', quantity: 32, orderNumber: 'dummy'}, { material: 'A', quantity: 65, orderNumber: 'dummy'}, ...

What is the best way to eliminate the content of an element using javascript/typescript?

The progress bar I'm working with looks like this: <progress class="progress is-small" value="20" max="100">20%</progress> My goal is to use javascript to remove value="20", resulting in: <progre ...

The jQuery framework is causing AJAX/API data to be duplicated in the

I've been encountering a common issue for which I can't seem to find a straightforward solution. My current challenge involves using an API to fetch JSON data through an AJAX call. Upon receiving the data, it appears twice in both the console an ...