Is my approach to gradually unveiling a 3D object in Three.js correct?

I'm eager to craft a dynamic 3D line chart using three.js that emerges from left to right, similar to the demonstration on CNBC found here: http://youtu.be/ds7zhCqlrqk?t=12s

Initially, I explored options like hiding, masking, or clipping segments of the chart and animating the mask for a reveal effect, but it seemed unfeasible based on my research.

Therefore, I opted to reconstruct the chart's geometry and mesh entirely with each frame, gradually adding more elements to the chart. While this method performs adequately and stays within the required frame rate, it feels somewhat rudimentary, prompting me to seek simpler alternatives that might be eluding me.

For reference, you can view the current state of my project in this jsFiddle: http://jsfiddle.net/qzpC6/9/ Additionally, below is the function responsible for rebuilding the chart's geometry and mesh during each frame...

function incrementChart() {
    if (currentPoint == points.length - 1) {
        return;
    }

    var then = new Date().getTime();
    currentPoint++;
    var extent = startX;
    var vectors = [];
    for (var i = 0; i <= currentPoint; i++) {
        vectors.push(new THREE.Vector2(extent, 50 * points[i]));
        extent += spacing;
    }
    console.log(vectors);
    vectors.push(new THREE.Vector2(extent - spacing, -50));
    vectors.push(new THREE.Vector2(startX, -50));
    vectors.push(new THREE.Vector2(startX, 50 * points[0]));

    var newShape = new THREE.Shape(vectors);
    var newGeometry = newShape.extrude(extrudeSettings);
    var newShapeMesh = new THREE.Mesh(newShape.extrude(extrudeSettings), material);

    parent.remove(shapeMesh);
    shapeMesh = newShapeMesh;
    parent.add(shapeMesh);
    var now = new Date().getTime();
    console.log(now - then);
}

Answer №1

Are shaders something you're comfortable with? Consider implementing a ShaderMaterial where you can selectively remove fragments using gl_FragCoord.x

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

How should a string be properly converted to JSON format?

I am encountering an issue with converting the following string to JSON format const banner = " { "banners": [ { "startDate": "02/26/2021", "endDate": "12/25/2021","content": "Important ...

Is it possible to iterate through HTML form data using JSON arrays or objects?

I've been searching this website and the internet for a while now, trying to figure out how to save multiple arrays to my localStorage. I asked a question earlier which helped me progress a bit, but I'm still struggling to grasp the concept. I c ...

html inserting line break using label

I am attempting to dynamically set text to a label using jQuery. However, I am having trouble getting the <br> or \n to create new lines. Instead, all the text displays on the same line and wraps around. If you want to see my code in action, ch ...

How can I programmatically trigger the opening of a Material-UI Accordion in ReactJS?

All of the Accordions are assigned unique IDs: const CategoryDisplay: React.FC<Props> = (props) => { ... return ( <> <Accordion id={`category-${accordion.id}`}/> </> ); }; export default CategoryDisplay ...

javascript - modifying nested field based on condition in map

In the scenario of having an array like this: people = [ { name: 'Bob', sex: 'male', address:{ street: 'Elm Street', zip: '12893' } }, { name: ...

Tips on how to retrieve an Observable Array instead of a subscription?

Is there a way to modify this forkJoin function so that it returns an observable array instead of a subscription? connect(): Observable<any[]> { this.userId = this.authService.userId; this.habits$ = this.habitService.fetchAllById(this.userId); this.s ...

Is there a way to dynamically adjust the height of a DIV block?

I have a situation where I need the height of one div to automatically adjust based on changes in the height of another div. var height = jQuery('#leftcol').height(); height += 20; jQuery('.rightcol-botbg').height(height); Unfortun ...

Converting a string to an HTML object in Angular using Typescript and assigning it to a variable

I am facing an issue with passing HTML content from a service to a div element. I have a function that fetches HTML content as a string from a file and converts it into an HTML object, which I can see working in the console. However, when trying to assign ...

What could be causing this JavaScript to output undefined?

const urls = [ "http://x.com", "http://y.com", "http://z.com", ]; for (let j=0; j<urls.length; j++) { setTimeout(function() { console.log(urls[j]); }, 3000); } I'm inserting this code snippe ...

Discovering the worth of objects in a MongoDB array - a guide

I need assistance to access the value of a nested object within an array. I have the _id of the parent object and the _id of the child object in the array, but I am struggling to get the value of "solvedOn" in order to toggle a checkbox behavior. Here is ...

Converting an HTML <img> tag into a Base64 encoded image file: Step-by-step guide

Recently, I made changes to the appearance of an image by adding CSS filters using the "style" attribute of an <img> tag. <img src="myImage.png" style="filter: grayscale(100%)"> As a result, the image now has a different look and I am looking ...

Working with numerous query parameters within AngularJS

When interfacing with an external service, I’m receiving query parameters in the following format: url/?error=someError&error_description=someErrorDescription In my app.js file, I have attempted to handle this using the routeProvider as shown below ...

Is there a way to dynamically access BEM-style selectors using CSS modules?

For instance, I have this specific selector in my App.module.css file: .Column--active I want to access this selector from the App.js file in React using CSS modules. After importing all selectors from the CSS file as import styles from './App. ...

How to send a JSON object using Node.js Express 4.0

I'm currently working on parsing the JSON object sent in the request and displaying the data being transmitted. Below is my post request: $.ajax({ url: url, type: 'POST', contentType: 'application/json' ...

Perform an action when a button is clicked in a VueJs single-page application

How can I trigger the refreshMailList function when clicking on the mail-list component? This is my Vue instance with a custom mail-list component: Vue.component('mail-list', { props: ['inboxmail'], template: ` <div> ...

"Retrieve objects from an array based on specified minimum and maximum values, while also checking for any null

My current dataset is structured as follows: const data = [ { id: '11se23-213', name: 'Data1', points: [ { x: 5, y: 1.1 }, { x: 6, y: 2.1 }, { x: 7, y: 3.1 }, { x: 8, y: 1.5 }, { x: 9, y: 2.9 ...

Why is it that every time I install an npm package, it triggers a re-installation of all

Whenever I attempt to install a new package using npm, I face a frustrating problem where it also starts to install all of my other packages, leading to potential breakage and the need to reinstall my node modules. I am puzzled by this behavior and unsure ...

Apache conf file configured with CSP not functioning properly when serving PHP files

While configuring the Apache CSP lockdown for a site, I encountered an unusual behavior when opening the same file as a PHP script compared to opening it as an HTML file. The HTML file looks like this: <html> <head> <meta http-equiv= ...

The response from AJAX is successfully retrieved, however, the HTML code within the response is not being appended to the

html: <form method="POST"> <input type="text" name="input1" id="input1"> <input type="text" name="input2" id="input2"> <button type="button" onclick="checkInputs()">OK</button> </form> <div id="display_panels">< ...

Encountering a "Uncaught TypeError: Cannot read property 'render' of undefined" error in Three.js when using an object literal

I've been working on converting my code to object literal style. While I was able to successfully create the scene, I'm encountering some issues with the animation. One specific error message that I'm getting is "Uncaught TypeError: Cannot ...