Combine disjointed WebGL lines into a cohesive entity

I am facing a challenge with rendering multiple WebGL lines that share the same style. To optimize performance, I aim to render them all as one object in a single draw call.

The issue arises from these lines not connecting to each other.

Take a look at this example: http://jsfiddle.net/b6jgS/6/

Observe how the rings connect, which is not my desired outcome. Nevertheless, I still want them to be drawn in a single draw call.

The code snippet below showcases the generation of geometry for multiple rings:

# Please excuse the coffeescript!
ringsGeom =  new THREE.Geometry()
for u in [-2..2]
  for v in [0..100]
    ringsGeom.vertices.push new THREE.Vector3(
      Math.sin(v/100 * 2 * Math.PI)
      Math.cos(v/100 * 2 * Math.PI)
      u
    )


rings = new THREE.Line(
  ringsGeom
  new THREE.LineBasicMaterial(
    color: 0xffff00
    linewidth: 1
  )
)
scene.add rings

How can I achieve drawing multiple discrete and disconnected lines as a single object?

Answer №1

To create your line, you first build your geometry using an array of point pairs representing individual line segments. Then, you can instantiate your line like this:

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

For a practical example, take a look at GridHelper.js.

This tip is specifically for three.js version r.58.

By the way, three.js already includes the requestAnimationFrame() shim, so no need to add it separately.

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

Issue Detected at a Precise Line Number - Android Studio

Despite my numerous attempts to modify the specific line in question, including leaving it empty, turning it into a comment, or removing it entirely, the error message persists. I even went as far as deleting the class and creating a new one, but the same ...

Why is my Vue list not showing the key values from a JavaScript object?

I am struggling to utilize a v-for directive in Vue.js to display the keys of a JavaScript object in a list. Initially, the object is empty but keys and values are populated based on an API call. Here's an example of the data structure (I used JSON.st ...

Is it advisable to use an autosubmit form for processing online payments?

Situation: In the process of upgrading an outdated PHP 4 website, I am tasked with implementing an online payment system. This will involve utilizing an external payment platform/gateway to handle transactions. After a customer has completed their order ...

The issue of inaccurate positioning and rotation in three.js is often attributed to problems with sprite

I'm attempting to generate a sprite with text without utilizing TextGeometry for improved performance. var fontsize = 18; var borderThickness = 4; var canvas = document.createElement('canvas'); var context = canvas.getContext('2d' ...

Changing data in Chart.js, strategies for modifying data after chart creation!

Apologies if this question seems basic. The challenge I am facing is that I need to utilize the same data for multiple charts, but with slight variations in options for each chart. The data is as follows: var data = { labels: freq, datase ...

Is there a way to execute JavaScript tests by incorporating debugger statements?

There isn't a one-size-fits-all solution to this question, and it hasn't been addressed on Stack Overflow either. My background is in Python, where I can use import pdb; pdb.set_trace() to debug code step by step with a debugger. How can I achiev ...

The Express.js static() function seems to have trouble serving files from subdirectories that are more than one level deep

My Express.js app has a folder structure displayed on the left. Line 19 utilizes static(). The path for './client' is defined, with path.join() included as well. In the network log on the right, all assets load properly except for the components ...

What is causing the duplication of Google Map drawing controls?

I've been trying to integrate the Google Maps JavaScript API into my React project to create a map with polygon drawing capabilities. The map itself is functioning perfectly fine, but I'm encountering an issue where two sets of drawing controls a ...

Navigating from the Login Page to the Dashboard in Vue.js following successful token validation

I am facing an issue with the code that is supposed to redirect the User to the dashboard page if they have a token. Despite generating a JWT token from my Spring Boot backend and sending it to Vue for processing, the redirection is not working as expect ...

What could be the reason for the absence of the HTTP response in the network tab of the Chrome debugger?

After utilizing Postman to test my web service, I was able to find the WS's response in the http response body. However, when I made a call using ajax in my web application, I encountered an issue where I could no longer locate the response. The tab ...

What is the method for inserting indicators between yAxis values in a yAxis ChartJs graph?

I have a line chart displaying the link below: https://i.sstatic.net/yUAHf.png There is a noticeable gap between 0-0.7 on the chart. I am looking to add an indicator similar to the one shown in this image: https://i.sstatic.net/pRjsY.png The desired ou ...

Duplicate the identical data retrieval query, this time utilizing a JavaScript Ajax post method

To enhance the data request query, implement a JavaScript Ajax post method to avoid page refresh when the button is pressed. This will allow for requesting another page and displaying it in a designated section on the webpage. Here's the code snippet ...

Having trouble selecting an element by name that contains a specific string followed by [..] using jQuery

I have elements with names like kra[0][category], kra[1][category], and so on. However, I am facing difficulties in selecting these elements by name. Here is my jQuery code: $("[name=kra[0][category]]").prop("disabled", true); ...

Using multiple $lookup with arrays of objects: A guide

Suppose I have a collection with the following data structures: post col: { _id: ObjectId("5fce0e137ff7401634bad2ac") address: "new york" description: "this is a great city" image: "images\0.46448596 ...

Is it possible to access the Firebase user object beyond the confines of the Firebase function?

Despite successfully logging users into my application using Google Auth from Firebase, I am facing an issue where the User object does not display on the front end of my application (which utilizes Pug templates). How can I resolve this? The code snippet ...

The JSON data retrieved from the API is showing as undefined for the property

Currently, I am working on a project that involves utilizing the Shopify API to fetch products and related data from a store in JSON format. While I was able to successfully retrieve the JSON object from the API, I encountered an issue when trying to acces ...

React - Updating the Color of a Specific Div within a Map Component

Currently, I am delving into React and Material UI and facing an issue with changing the background color of a clicked div. As it stands, all the divs are being affected when one is clicked. My goal is to have the background color transition from white to ...

Delayed callback on blur

I am developing an AutoComplete feature in React that displays a list of suggested completions as the user types into a text box. When a suggestion is clicked, it should trigger a callback function, and the dropdown should disappear when the text box loses ...

Trouble with incrementing JavaScript dictionary values within a nested for loop

I am currently working on analyzing shark attack data with d3.js using a csv file named shark.csv. I have encountered a problem while implementing a nested for-loop in my code. The csv file contains information about shark attacks categorized by continent ...

Issue: .catch(error) function in Node / Express not returning as expectedDescription: After

I'm currently developing a REST API and focusing on effectively managing all error scenarios. Upon successful completion of the API call, I make sure to return the success object to the calling function and then send the response to the client. Howev ...