the integration of shapes in three.js is malfunctioning

There has been a dynamic change in the path.

The previous render function was as follows (where LENGTH, getPosition(), RADIUS, MATERIAL, and SCENE have already been set)

var prevPosition = getPosition();
for(var i =0; i < LENGTH; i++) {
    drawPath(getPosition());
}

function drawPath(currentPosition) {
    var spline = new THREE.CatmullRomCurve3([prevPosition, currentPosition]);
    var geometry = new THREE.TubeGeometry(spline, 1, RADIUS);
    var mesh = new THREE.Mesh(geometry, MATERIAL);
    SCENE.add(mesh);
}

The previous render method was functioning effectively. However, I made a modification to enhance performance.

The modified render function now looks like this:

var mergedGeometry = new THREE.Geometry();
function drawPath(currentPosition) {
    var spline = new THREE.CatmullRomCurve3([prevPosition, currentPosition]);
    var geometry = new THREE.TubeGeometry(spline, 1, RADIUS);
    mergedGeometry.merge(geometry);
    var mesh = new THREE.Mesh(mergedGeometry, MATERIAL);
    SCENE.add(mesh);
} 

Unfortunately, the mesh is not appearing on display. I am unsure about the reason behind this issue. Would appreciate some guidance or insights. Thank you!

Answer №1

It seems there may be some confusion between geometry and mesh. Geometry serves as a building block for a mesh. To enhance your geometry, convert it into a new mesh object and then include this fresh mesh in the scene.

Consider the following approach:

let combinedGeometry = new THREE.Geometry();
let previousPosition = getPosition();
for(let iterator = 0; iterator < LENGTH; iterator++) {
    drawCurve(getPosition());
}

let customizedMesh = new THREE.Mesh(combinedGeometry, MATERIAL);
SCENE.add(customizedMesh);

function drawCurve(currentPos) {
    let curve = new THREE.CatmullRomCurve3([previousPosition, currentPos]);
    let variantGeometry = new THREE.TubeGeometry(curve, 1, RADIUS);
    combinedGeometry.merge(variantGeometry);
} 

If you encounter any obstacles, feel free to refer to this live example of mesh merging: http://jsfiddle.net/abcd1234/

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

A dynamically-generated dropdown element in the DOM is being duplicated due to JavaScript manipulation

Currently, I am dynamically adding a dropdown element to the page using javascript. The goal is for this dropdown to modify the properties displayed on a map. However, when attempting to add the element after the map loads, I encounter an issue where the d ...

What is the most efficient method for examining dependencies in Yarn 2 (berry)?

Is there a way to check for vulnerabilities in Yarn 2 dependencies? In Yarn 1.x, you could run yarn audit, similar to npm audit. However, this command is not available in Yarn 2. According to this issue on the Yarn berry Github, it may not be implemented ( ...

The three.js live server is displaying a blank white screen instead of the expected black background

As I attempt to set up my three.js following tutorials on Youtube, using Visual Studio Code, I encounter a perplexing issue. Despite copying the script precisely as demonstrated in the tutorials, every time I check the live server, instead of seeing a blac ...

terminate the express middleware and return a custom HTTP status code

Is it possible to use custom middleware to return a 404 or 401 error to the user and prevent other handlers from running? I tried implementing the following code: function SomeMiddleware(req, res, next) { if(user.notRealOrSomething) { throw new Htt ...

Effective ways to transmit a variable array from an HTML document to a PHP server

Is there a better method for transferring a variable array from HTML to PHP? I attempted to use the serialize function, but it doesn't seem to be functioning correctly. Any suggestions would be greatly appreciated. //HTML var arrayTextAreasNames = [ ...

Are third-party scripts and HTML widgets able to replicate your website's data, including cookies, HTML, and other elements?

Currently, I am in the process of constructing a website that incorporates a third-party weather HTML widget. The widget is sourced from a trusted and reliable source on the web. It consists of a link and small JavaScript tags that are executed once loaded ...

A comprehensive guide on how to find keywords within an array and then proceed to make all text within the parent div tag stand

I am currently looking for a webpage that displays a list of products based on keywords from an array. Once it detects any word in the array, it highlights it with a red background - everything is working smoothly so far. However, I now wish for the script ...

Performing a dynamic animation by toggling the class of an element with "classList.toggle" in JavaScript

I have been attempting to incorporate a fade animation using CSS when altering the class of the input and label elements within a form by utilizing the classList.toggle method in JavaScript. I'm puzzled as to why my code isn't producing the desir ...

Decreased storage space requirements following transfer to S3 bucket using nodejs

I am currently facing an issue with uploading files from a specific folder location to an S3 bucket using the nodejs aws-sdk. The files I am working with are deepzoom images (.dzi). While the files seem to be successfully uploaded to my S3 bucket, I have n ...

"npm is the go-to tool for managing client-side JavaScript code

As I delved into a document outlining the npm Developer Guide, a question sprang to mind. Is it within the realm of possibility to construct a web client application using javascript/css/html with npm at the helm? And if so, might there be examples avail ...

View the picture directly on this page

Currently, I am in the process of creating a gallery and I would like the images to open on top of everything in their original size when clicked by the user. My expertise lies in HTML and CSS at the moment, but I am open to learning JavaScript and jQuery ...

What could be the reason for the jQuery animate function not functioning properly?

I am having an issue with this code. I have followed the syntax for animate() but it is not working as expected. <!DOCTYPE html> <html> <head> <style> #testing { background-color: skyblue; Position: absolute; ...

Issues with JQuery Radio button selection in Internet Explorer 6

Here is some code that I am working with: <input type="radio" name="HotelSearch_Measure" value="Miles"> <input type="radio" name="HotelSearch_Measure" value="KM"> While this code functions properly in IE9, Chrome, and Firefox, it does not wor ...

Expanding a JavaScript list using HTML inputs

I have a script where a grid dynamically displays a list of words. Is there a way to populate the word list in the grid using HTML? Currently, I am doing this... var listOfWords = ["mat", "cat", "dog", "pit", "pot", "fog"]; Can additional words be adde ...

Finding the position of the biggest floating point number in the array

What is the best way to find the index of the largest element in an array of floating point numbers? [0.000004619778924223204, 0.8323721355744392, 0.9573732678543363, 1.2476616422122455e-14, 2.846605856163335e-8] Once the index of the largest element is ...

Tips for adding content to several elements at once using jQuery

My HTML structure is as follows : <span class="section2 section4">hello</span> <span class="section1">World</span> <div class="tab" id="tab1"></div> <div class="tab" id="tab2"></div> <div class="tab" id= ...

What is the process of transforming a string into an angular binding?

I have a variable called message that contains the text "you are moving to {{output.number}}". I attempted to insert this into a div element using $("#message").html(message); However, it just displayed the entire string without replacing {{output.number ...

Troubleshooting Node Commands malfunctioning following NodeJS update

I have encountered an issue while trying to update my node version. I deleted the nodejs file from the ProgramFilesx86 folder and then used the Windows installer to install the latest version. However, when I attempt to initialize a node project or use npx ...

Tips for transferring a dataTable from C# code behind to jQuery

I am trying to pass a string as a table of data from C# code behind to jQuery using two functions: C# [System.Web.Services.WebMethod(EnableSession = true)] public static List<ListItem> GetImageArray(string AccNo) { string result = string.Empty; ...

Where can I find the JavaScript code that controls the button function?

Is there a method to identify the trigger that activates a button's specific action and page refresh, such as this example: <input type="submit" name="name" value="some value" id="mt1_main_btn" class="btn_next"> Simply copying the button does ...