Is it possible to eliminate line segments from a line?

Currently facing a challenge with three.js as I attempt to accomplish a specific task. Unsure if I should start from scratch or stick with my current approach.

I am working on parsing a gcode file, essentially a large text file containing position and extrusion data for 3D printers. I am reading through it sequentially, loading all positions into THREE.Geometry() as vertices, and creating a line using these positions along with vertex colors.

This is the code snippet:

// Code snippet here

I have identified which pairs of vertices need to be invisible based on a flag in geometryArr. Now, I need to address them accordingly.

Attempts made so far: * Removing the relevant vertice pairs results in the line being drawn between the subsequent set of vertices. * Adding a second line with transparent (0 opacity) segments where needed did not yield desired outcomes. * Rendering each line segment individually caused severe performance issues due to the high number of line segments involved.

Wondering if THREE.Geometry and THREE.Line offer any functionality to remove specific line segments?


It seems that if not available, I might have to transfer this process to THREE.BufferGeometry and utilize shaders to render certain lines as invisible. A more time-consuming solution that I hoped to avoid.

Your assistance is greatly appreciated!

Answer №1

When working with geometry in three.js, there are two main ways to draw a line.

  1. To create a continuous line:
    THREE.Line( geometry, material );
  2. For a segmented line:
    THREE.LineSegments( geometry, material );

THREE.LineSegments

The THREE.LineSegments class connects every pair of subsequent vertices with a line. To achieve a continuous line using this class, you need to duplicate points in between.

Let's illustrate this with an example:

v1 = new THREE.Vector3( 0, 0, 0 );
v2 = new THREE.Vector3( 10, 0, 0 );
v3 = new THREE.Vector3( 20, 0, 0 );
v4 = new THREE.Vector3( 30, 0, 0 );

If you create a geometry with these points and use THREE.LineSegments:

geometry = new THREE.Geometry();
geometry.vertices.push( v1, v2, v3, v4 );

line = new THREE.LineSegments( geometry );

It will look like this:

.__.  .__.
1  2  3  4

However, if you do:

geometry = new THREE.Geometry();
geometry.vertices.push( v1, v2, v2, v3, v3, v4 );

line = new THREE.LineSegments( geometry );

it will look like this instead:

.__.__.__.
1  2  3  4

THREE.Line

In contrast, the THREE.Line class behaves differently as it always connects all vertices with a continuous line.

geometry = new THREE.Geometry();
geometry.vertices.push( v1, v2, v3, v4 );

line = new THREE.Line( geometry );

This will draw a continuous line connecting the points from the vertices array like so:

.__.__.__.
1  2  3  4

I trust that this explanation will assist you in resolving any issues you may encounter.

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

Utilizing helper functions in Node based on their specific types

In my helper module, I have different files like content, user, etc. These files define various helpers that can be used in the router. Below is the code for the router: router.js var helper = require("./helper"); function index(response) { response ...

Events in Three.js have an impact on the Document Object Model (

Here's a simple question for you. Is it possible to create click events in a three.js scene that can manipulate the DOM? For example, if an object is clicked in the scene, can it make a panel outside the scene become visible? Thank you! ...

Angular.js unable to locate image 404 Error occurs

I am facing a small issue. I want to display icons from categories that I receive from my REST API. To achieve this, I am using AngularJS with REST API which provides me with the designed icons. However, I encountered an error in Firebug: "NetworkError: 4 ...

Combining Django's CSRF token with AngularJS

I currently have Django running on an Apache server with mod_wsgi, and an AngularJS app being served directly by Apache rather than through Django. My goal is to make POST calls to the Django server that is utilizing rest_framework, but I am encountering d ...

The best approach for sending parameters to the parent class in TypeScript for optimal efficiency

What's the optimal solution to this problem? I really appreciate how we can specify attributes in the constructor and TypeScript takes care of handling everything to assign values to the props in JavaScript - like I did with 'department' her ...

Passing a PHP variable to an AJAX URL: A simple guide

Hey there! I am just getting started with javascript and I'm facing an issue while trying to send a PHP variable to an AJAX URL file. I can't seem to figure out where the problem lies. Any assistance would be greatly appreciated! In this scenari ...

Retrieve every hour between two specific timestamps

I am attempting to retrieve all dates between two timestamps that fall on a specific day of the week. I have a start date represented by 'start1' and an end date represented by 'end1'. Additionally, I have a list of days with correspon ...

Eliminate values from an array by utilizing either a for loop or a custom filtering function

I need help with removing specific URLs from an array every time they appear. Here is the list of URLs I want to filter out: "https://basueUrl.com/Claim" "https://basueUrl.com/ExplanationOfBenefit" This is my current array: Array= [ "https://b ...

I attempted to use the Stripe API, but it seems to be non

I seem to be encountering an issue with the stripe.customers.create. My goal is to create a new Stripe customer using the email address of the current user, and then update my user with the generated customer.id. Despite the fact that stripe.customers.cre ...

Does JavaScript sort dictionaries automatically?

Here's an issue we're facing: when the ajax script receives a dictionary from the server, the order changes: The server sent this: {753: 'Wraith', 752: 'Phantom Extended', 751: 'Phantom', 750: 'Ghost Extended&a ...

Unable to view new content as window does not scroll when content fills it up

As I work on developing a roulette system program (more to deter me from betting than to actually bet!), I've encountered an issue with the main window '#results' not scrolling when filled with results. The scroll should always follow the la ...

Extracting the month and year from a datetime string: A simple guide

I am working with a JSON object that includes a field called Month with a string datetime value- { Month : "31-Jan-2022 12:00 AM (EST)" .... .... } Is there a way to extract the Month Name and Year from this string using JavaScript's dat ...

Setting the ng-href attribute in Angular conditionally using a function

How can I dynamically set links in an angular controller based on a function's result? <a ng-href="{{ setLink('contact') }}" Inside the controller: angular.module("my-app") .controller('navController', ['$scope&apos ...

Utilize PHP in an APP Engine Application to send an email to a Gmail address

I have a project deployed on Google App Engine where I need to send an email once a user submits the contact form. My app is successfully deployed and I have implemented an ajax request to a PHP file, but unfortunately, it's not functioning as expect ...

Tips on how to showcase particular keys from json information in React

Here is a sample of Json data that I have: [ { "serial_number": "test1", "added_at": "2021-02-05T18:58:43.382943Z", "ser_mod": [ { "added_at": "2021-02-06T02: ...

Using Angular 2: A Beginner's Guide to Navigating with the Latest Angular 2.0.0-rc.1 Router

As I embarked on a new Angular 2 project, I was puzzled to discover that I inadvertently installed two different versions of the angular router: "@angular/router": "2.0.0-rc.1", "@angular/router-deprecated": "2.0.0-rc.1", Despite my best efforts, I co ...

React/Ionic: Avoiding SVG rendering using <img/> elements

I seem to be encountering an issue when trying to load SVG's in my React/Ionic App. I am fetching weather data from OpenWeatherMap and using the weather?.weather[0].icon property to determine which icon to display. I am utilizing icons from the follow ...

What could be the reason behind the login button not triggering the console message display?

I've decided to delve into web server development on my own and have been tweaking a GitHub repository for ExpressJS with Typescript that I stumbled upon. My initial goal is simple - just to have something displayed on the console when I click the log ...

Displaying multi-dimensional arrays through the console in JavaScript and showcasing their elements

My array is supposed to have 140 indexes in a single format like this: array:[0-140] //however, it currently appears as: array: [ 0: [0-99], 1: [100-140] ] I've confirmed multiple times that it is just one array of objects. Why is it s ...

Problem with jQuery's .prepend method being called twice on list items

Looking to enhance the appearance of a list by adding some icons before the anchor links within each list item. <ul class="submenu-children"> <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> ...