What's the Deal with MeshLine and Line Thickness in Three.js in 2021?

I was looking to create a curved line in Three.js with a thickness greater than one. After some research, I found that using Three.MeshLine seemed to be the solution. However, I have come across several reports (and experienced it myself) stating that the code provided in the repository example triggers a "Class constructor cannot be invoked without 'new'" error and disrupts the line.

I am curious if anyone has figured out a way to make MeshLine work with recent versions of Three. The code snippet below is from the latest release (last commit made a year ago). It's possible that I might be missing something or that the repository is no longer being maintained.

var scene, camera, renderer, points, line;
 
function init() {
  scene = new THREE.Scene();
  camera = new THREE.PerspectiveCamera(75, 640 / 480, 0.1, 1000);
 
  renderer = new THREE.WebGLRenderer();
  renderer.setSize(640, 480);
  document.body.appendChild(renderer.domElement);
  camera.position.z = 9;
 
  points = [];
  for (var i = -10; i < 10.1; i += 0.1) {
    points.push([i, Math.sin(i), 0]);
  }
 
  line = new MeshLine();
  line.setPoints(points.flat());
 
  var material = new MeshLineMaterial({ color: new THREE.Color(0xffff00), lineWidth: 0.1, dashArray: 0.1, dashRatio: 0.2});
  material.transparent = true;
  mesh = new THREE.Mesh(line, material);
 
  scene.add(mesh);
 
  animate();
}
 
function animate() {
 
  renderer.render(scene, camera);
  requestAnimationFrame(animate);
}

Answer №1

The reason why the project THREE.MeshLine is unable to support newer versions (> r127) is because it currently relies on extending the BufferGeometry class in this manner:

THREE.BufferGeometry.call(this)

This approach is outdated as BufferGeometry is now an ES6 class, rendering this syntax invalid in JavaScript. Consequently, the developers of THREE.MeshLine will need to update their codebase by transitioning to ES6.

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

The global JavaScript variable is refusing to be posted during the DataTable Ajax request

I've been struggling to send an additional custom value to my MVC controller for a server-side data table. Despite trying various approaches, the value I want always ends up being null in my view model. Here is my code snippet: $(document).ready(func ...

My email submission function is malfunctioning

my contact form in my website is not working properly. I have tried troubleshooting the issue by checking the contact.php file but it doesn't seem to be the problem. The script that I am using for the form submission is shown below: <!--Contact U ...

Is OnPush Change Detection failing to detect state changes?

Curious about the issue with the OnPush change detection strategy not functioning properly in this demonstration. My understanding is that OnPush change detection should activate when a property reference changes. To ensure this, a new array must be set e ...

Differences between Array `forEach` and `map()`

I am having trouble displaying the options list even though I am passing an array. Any assistance would be greatly appreciated. Thank you. const options_A = [ { label: "AA", value: "AA" }, { label: "BB", valu ...

Where can I find the previous version of three.js? What is causing the incompatibility between the old and new versions of

Why is my app facing issues with the updated version of three.js? Can I find the previous version of three.js and why isn't the new version compatible? ...

Focusing on the combination of Phonegap, Angular JS, and Onsen for app development

We are working on developing an app using PhoneGap, Angular JS, and Onsen. One issue we are facing is that we are unable to center the header in a modal. The code snippet is provided below: <ons-modal var="modalVariable"> <ons-navigator var"de ...

Refreshing a Nextjs page upon clicking a route button for the very first time

Essentially, when the initial page is built and we are on the index page, clicking any button that changes the route - using methods like push or replace in the-router function triggers a page refresh. After the first reload, subsequent clicks on the but ...

Exploring the JsonArray Response entity

Trying to decode my fetch response: fetch('restservices/users/', fetchOptions) .then(function (response) { if (response.ok) { console.log('1'); console.log(response) const responseSjon = response.json ...

What is the best way to perform an atomic update on an embedded document within an array using mongoose? The operation should only update the latest document and then return the updated

Currently, I am delving into node.js and MongoDB with mongoose. //Document in mongoDB { name: 'first', _id: '1000' phases: [{ _id: 1, phaseName: 'phase1', stories: [{ _id: s1, sname: ...

In Chrome, it seems like every alternate ajax request is dragging on for ten times longer than usual

I've been running into an issue with sending multiple http requests using JavaScript. In Chrome, the first request consistently takes around 30ms while the second request jumps up to 300ms. From then on, subsequent requests alternate between these two ...

The instanceof function provides an erroneous response when verifying a valid condition

SCENARIO // debugging Discord applications import { Client } from 'discord.js'; export class Debugger { constructor(public client: Client) { console.log(client instanceof Client); // outputs false } } // main.ts import { Client ...

What is the best way to implement this design using CSS or JavaScript?

I would like to enhance the appearance of my school website during these challenging times of the pandemic by adding some CSS or JavaScript elements. However, I am unsure how to go about it. ...

Unlocking the power of accessing nested data in JSON files dynamically

Building a new feature that allows users to input a word, choose the language, and receive the definition along with an example using the API service. To retrieve the desired data at position 0 of "exclamation" in the "meaning" section. This ensures that ...

What are your thoughts on the practice of utilizing the useState hook within a component to send data to its parent component?

I have been working on developing an Input component that can be dynamically used in any page to store input values. The component also includes an attribute called getValue, which allows the parent component to access the input value. In my App.js file, I ...

Using jQuery to animate a form submission in CodeIgniter

I have integrated two jQuery plugins into my application, which are: jQuery validate : . jQuery blockui : http://malsup.com/jquery/block/#download The application is developed using PHP Codeigniter and jQuery. It consists of a form created with the fol ...

Guide to encapsulating an angular material form within a component and making it accessible to the FormGroup as a formControl property

My goal is to create a custom component (let's call it custom-input) that acts as a formControl element using Angular material components. It should include the following structure: <mat-form-field > <input matInput [formControl]=" ...

Error encountered in Three.js when using multiple canvases and loading JSON geometry

I have been working on creating multiple views and came across an example code here which worked flawlessly when I tried it. However, when I replaced the geometries with ones I created in Blender, I encountered an error: Cannot read property 'length ...

Navigate to element based on data attributes

Trying to find a way to scroll an element to a specific ID using data-attributes instead of anchor tags. Here is what I have so far: When a button is clicked, it should display the content and scroll to the element that matches the data-attributes. Howeve ...

Duplicate entry being created in select due to Angular copy operation

There is a select drop-down on my page with three options: orange, banana, and mango. I have a button that allows me to add a new item to the list. When I have orange selected in the drop-down and click the add button to add a new fruit like peach, I end u ...

The declaration for "Control" is not present, possibly being restricted by its protection level

I'm really struggling to get the jQuery datepicker working in ASP.NET. I've tried various examples, but nothing seems to work for me. Even though I'm fairly new to ASP.NET, I am learning quickly! Here is the script I am trying to use: < ...