Are there three Line Pieces made of unique materials?

I attempted to create a complex graph with over 10k edges using three.js. While LinePieces helped improve performance, I struggled to assign unique colors to each edge since only one "material" could be used for the Line object.

Below is part of the code snippet:

function drawEdges() {
    edgeGeometry = new THREE.Geometry();
    edgeMaterial = new THREE.LineBasicMaterial({ opacity: 0.1 });
        foreach source-target node pair:
            edgeGeometry.vertices.push(new THREE.Vector3(source.x, source.y));
            edgeGeometry.vertices.push(new THREE.Vector3(target.x, target.y));
    }
    var edges = new THREE.Line(edgeGeometry, edgeMaterial, THREE.LinePieces);
    scene.add(edges);
}

My query is: Is it feasible to utilize different materials when utilizing THREE.LinePieces? Any assistance on this matter would be greatly appreciated.

Thank you in advance.

Answer №1

If you are utilizing the WebGLRenderer, it is possible.

To achieve this, your geometry must include a declaration of geometry.colors, which should be an array populated with instances of THREE.Color(), with its length matching the number of vertices.

Next, define your material and mesh as follows:

var material = new THREE.LineBasicMaterial( {
    color: 0xffffff,
    vertexColors: THREE.VertexColors
} );

var mesh = new THREE.Line( geometry, material, THREE.LinePieces );

For a visual example, visit:

Version utilized: three.js r.57

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

Adapting imports in Typescript for seamless npm distribution

Currently, I'm facing an issue with module resolution while compiling my NPM package written in Typescript for publishing. In my project, I've been using non-relative imports to avoid the hassle of excessive ../../../. However, according to TypeS ...

"Encountered an error while trying to fetch a PHP file using AngularJS $http.get - Error message

I am currently working with the file api.php which fetches necessary data from a database. require_once 'db.php'; $con = mysql_connect($host,$user,$pass); $dbs = mysql_select_db($databaseName, $con); $query=mysql_query("SELECT * FROM $tableName" ...

What is the jQuery Autocomplete syntax like?

Though my experience with jQuery is limited, I have successfully implemented Autocomplete code that highlights the search characters in the dropdown rows: .autocomplete({ delay: 500, minLength: 0, source: function(request, response) { ...

Three.js Pin Placement for Clothing

I am in need of assistance! I am currently working on a simulation involving a cloth that is attached to four corners. I am attempting to reposition the pins at coordinates 0, 10, 88, 98 within a 10x10 array. My goal is to place each pin at a different pos ...

Utilizing NodeJS application to connect to Sharepoint 2019 On-Premises Web Services

Recently, I/T in my organization set up a new Sharepoint 2019 OnPromise with a hybrid configuration that utilizes Azure AD for authentication. As the site collection admin for our Sharepoint website, the URL to access it is Upon accessing this URL, I am ...

What is preventing the angular.bootstrap code from functioning properly in AngularJS versions prior to V1.6?

Can someone explain why when using the URL http://code.angularjs.org/snapshot/angular.js everything works fine in my code within the <script> tag, but when I switch to https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js, Angular does ...

Adjusting the date backward by one month results in a difference of 30 days, transitioning from July 31st to August

I'm feeling a bit overwhelmed by the code below. var forDt = new Date("2017-07-31"+ "T09:00:00.000"); var workDt = new Date(); workDt.setDate(forDt.getDate() - 1); date_prev = workDt.toISOString().slice(0, 10); Today is August 1st. I cli ...

The JavaScript function for clearing an asp.net textbox is not functioning properly

I am working on an ASP.net project and have encountered an issue with two textboxes. When one textbox is clicked on, I want the other one to clear. Below is the code I have for the textboxes: <asp:TextBox runat="server" ID="box1" onfocus="clearBox2()" ...

Is there a simple method in JavaScript to combine, structure, and join numerous multi-dimensional arrays in a specific manner (from right to left)?

Looking for a simple solution to merge, flatten, and concatenate multiple multi-dimensional arrays in JavaScript in a specific manner (from right to left) # Example [['.class1', '.class2'], ['.class3', ['.class4', & ...

How do I retrieve URL parameters in Vue.js?

Hello, I am currently working on creating my own websites and I am new to vue.js. I am having trouble getting parameters from the URL. I have tried multiple methods but none seem to work. Here is an example URL: example.com:8080/login. On this page, there ...

The JSON property is not defined

After making an AJAX call to retrieve data, I receive a JSON Object instead of a string. When I log the object, all its properties appear correctly. However, when attempting to log one specific property, it shows up as undefined. Here is a snapshot of my ...

Refreshing Bootstrap table data after an AJAX post request

I have implemented a bootstrap table to display rows from a database in MVC ASP.NET. The data is stored in a ViewBag and then returned with the ViewBag included as data to be displayed. Here is an example of how it looks: <div class="row rpad"> ...

Subscriber client successfully activated and operational via the command line interface

I have incorporated a script into my PHP file that reads the Pusher channel and performs various actions when a new event occurs on the specified channel. If I access the following URL in my browser: http:/localhost/pusher.php and keep it open, the p ...

How can I incorporate Vue draggable feature in my project using cards?

I've been attempting to integrate vuedraggable with Vuetify Cards, but I'm facing an issue where the drag and drop functionality doesn't seem to work when the cards are in a single row. Interestingly, it works perfectly fine when they are di ...

What is the purpose of a form that includes a text input field and a button that triggers a JavaScript function when the enter key is pressed?

<form action=""> <input id="user_input" onKeyDown="if(event.keyCode == 13)document.getElementById('okButton').click()" > <input id="okButton" type="button" onclick="JS_function();" value="OK"> </form> I'm trying to a ...

Delaying the activation of the code until the image upload is complete

I'm having trouble synchronizing code to upload an image using a vue composable, wait for the upload to finish, and then store the Firebase storage URL into a database. Despite getting the URL, the success code fires before the upload is complete. My ...

Troubleshooting: Vue.js custom select element not responding to blur event

Unique Scenario A custom autocomplete select component has been created that not only autocompletes but also allows for adding a new value if the result is not found. This functionality was discovered to be missing in the vue-select module. Explore the C ...

What is the best way to eliminate the first even number from a string?

My task involves working with a string containing only numbers. For example: let inputString = "1234"; The Challenge I need to create a function that will return the string excluding the first even number, if one exists. Example Output: " ...

Tips for utilizing [(ngModel)] with an object that is empty, null, or undefined in Angular 4

When trying to assign [(ngModel)] inside my .html code to an empty (null or undefined) object, I encountered the error message _co.object is null. There are two scenarios: one where the object has a value and one where it does not. The ngModel works fine i ...

Steps to retrieve an incorrect fruit when it is located as the initial item within the array

Currently tackling the precourse material for a coding bootcamp and hitting a roadblock with this particular question. Despite my best efforts, I just can't seem to meet one of the 7 conditions required. Let me outline the question, my attempted solut ...