How do I set custom edge colors for shapes in Three.js instead of only using wireframe:true?

Looking to create a unique 3d bar graph with custom-colored edges. Seeking ideas on how to achieve this effect. Here is the code for creating my shapes:

var threeWidth = 400,
  threeHeight = 300;
var viewAngle = 45,
  aspect = threeWidth / threeHeight,
  near = 0.1,
  far = 10000;

var $chart = $('#chart');
var renderer = new THREE.WebGLRenderer();
var camera = new THREE.PerspectiveCamera(viewAngle, aspect, near, far);
var scene = new THREE.Scene();
scene.add(camera);

renderer.setSize(threeWidth, threeHeight);
$chart.append(renderer.domElement);

var geometry = new THREE.BoxGeometry( 10, 100, 10 );
var material = new THREE.MeshBasicMaterial( {color: 0xCC0000} );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );

Answer №1

Starting from version r81, the use of EdgesHelper is no longer recommended. Instead, you should utilize:

// edges geometry
var geometry = new THREE.EdgesGeometry( mesh.geometry ); // or WireframeGeometry
var material = new THREE.LineBasicMaterial( { color: 0xffff00, linewidth: 2 } );
var edges = new THREE.LineSegments( geometry, material );
mesh.add( edges ); // add wireframe as a child of the parent mesh

To learn more, check out the related discussion on Github

Answer №2

While browsing the web, I came across this piece of code that caught my attention...

let border = new THREE.EdgesHelper( shape, 0xff0000);
border.material.linewidth = 3;
scene.add(border);

Check out this helpful fiddle I found.
For more information on EdgesHelper, click here.

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

Style the date using moment

All languages had a question like this except for JavaScript. I am trying to determine, based on the variable "day," whether it represents today, tomorrow, or any other day. ...

Establishing the request body for RESTful web services utilizing the POST technique

Hey there, I'm currently working on creating a REST response using the POST method. I want to pass variables dynamically instead of hardcoding them. However, I am encountering an issue when trying to send an array as a parameter to the REST web servic ...

Utilizing jQuery and AJAX for submitting multiple POST requests

Experiencing a problem with posting data via AJAX using a drag and drop interface. The data is being sent to the POST URL as intended, but there's a recurring issue where the POST request occurs twice, causing the processing URL to handle the data aga ...

Implementing JavaScript to visually showcase an external content on my website

Just made my first post! I was wondering about a javascript issue...here's the code I'm working with: <html> <head> <title>Geolocation Demo</title> </head> <body> <h1>Geolocation Demo</ ...

Retrieve the decimal separator and other locale details from the $locale service

After reviewing the angular $locale documentation, I noticed that it only provides an id (in the form of languageId-countryId). It would be helpful to have access to more specific information such as the decimal separator character. Is there a way to retri ...

I'm curious if there is a specific jQuery event that triggers right before an element loses focus or right before the next element gains focus

I am facing a situation where I have two input elements in a form that are closely connected. The first element triggers an ajax call to check for existing data in the database when the user tries to move away from it, while the second element opens a moda ...

Enhanced input field with segmented design, featuring autocomplete and automatic focusing

My current setup involves using the following code snippet: {[1, 2, 3, 4, 5, 6].map((i) => ( <Form.Control key={"code-cell-" + i} className="mx-2 p-0 text-center shadow-none verificatio ...

What causes the application to function correctly in Firefox while experiencing issues in Chrome?

Our web application is currently embedded within an iframe on a portal, and we are in the process of changing the domain for this portal. While testing with the new domain, we have encountered some issues where the portal loads successfully in Firefox but ...

What challenges arise when implementing Javascript Postback functions in an ASP.NET Web Application?

While overseeing an ASP.NET Web application originally built by an outsourcing firm but now managed in-house, I've come across some Javascript functions added to the Master Page to handle postback events. Here's a snippet of the code - var i ...

Version 2 of the Microsoft Logo Animation

I made some changes to my Microsoft logo animation project. You can view the updated version on CodePen. Overall, I'm pretty happy with how it turned out except for one issue. I'm struggling to determine the right timing to end the animation so ...

Tips for avoiding cropped images on mobile websites:

I recently created a website that looks perfect on desktop but appears cropped on mobile devices. The site in question is doc.awsri.com Here are the images causing the issue: https://i.stack.imgur.com/eRJXU.png The problem arises when viewing it on a ph ...

A helpful guide on how to dynamically input database values into the href attribute of an 'a' tag

How do I successfully pass an ID to href in my code? When I try to return it via req.params, it keeps coming back as undefined. I need the ID from the URL in order to use the findOne method to access the data stored in the database. I've searched thr ...

Tips for preventing flickering caused by set Interval in angular 2+

Displaying dynamic latitude and longitude data on Google Maps while using setInterval() function. Code snippet below: this.timer = setInterval(()=>{this.getMapData();},30000); An issue arises where the map flickers when updating the data with this.get ...

Delaying Variable Assignment in Node.js until Callback Function Completes

I am currently working with Node.js, Express, MongoDB, and Mongoose in my project. One specific task involves fetching the largest id number of a document from the MongoDB database and passing it back to the program. To better organize my code, I moved thi ...

Checking for valid zip code using a regular expression in JavaScript

Thank you for the suggestions, everyone. I have made some modifications to the script based on your advice and it appears to be functioning correctly now. <script src="jquery-1.4.2.min.js" type="text/javascript"></script> <script> $ ...

What is the most efficient way to eliminate div elements from the DOM tree individually?

Check out this example. If you click the add button, a user card is added. You can remove all cards by clicking the "Clear" button. But how can you delete individual cards by clicking the "close" icon on each one? Here's the HTML code: <div clas ...

In the readmore.js script, position the "readmore" link within a div instead of outside of it

I have added annotations that vary in length, so I am looking to integrate the readmore.js plugin. To ensure uniform sizing for all annotations (even empty ones), I need to set a minimum height for the div container. <annotation> <div style="wi ...

NodeJS - Headers cannot be modified once they have already been sent to the client

I've recently discovered a solution to the issue I was facing, which involves adding a return statement after sending a response. However, despite implementing the return statement, the error persists. const dbEditCourse = (req, res, db, logger) => ...

Look into HTML and JavaScript problems specific to IOS devices

I have encountered some HTML markup and JavaScript functionality issues on my web-app that seem to only occur on iPad and iPhone. Unfortunately, I do not have access to any iOS devices to debug these problems. How can I replicate and troubleshoot these i ...

How can I efficiently fetch data from Firebase, manipulate it through computations, and present it using React Hooks?

I am currently working on retrieving multiple "game" objects from Firebase Storage, performing statistical calculations on them, and then presenting the game statistics in a table. Here is an overview of my code structure: function calculateTeamStatistics( ...