Wireframe visualization with rounded corners using Three JS

In my current project involving 3D objects, I decided to experiment with Three.js. My goal is to create a wireframe with rounded corners on a single axis. While I have made progress using two different methods, I'm still facing the challenge of connecting the outer wall faces with a single outline.

The first method involves defining a shape with new THREE.Shape(), extruding it into geometry with new THREE.ExtrudeGeometry(), extracting the edges of interest with new THREE.EdgesGeometry(), and then creating a mesh with new THREE.LineSegments().

I've also tried rendering a version of the box within it to hide the lines in the back.

Method one utilized the depth attribute on ExtrudeGeometry, but it produced excessive lines and didn't draw them only on the exterior faces. Adjusting the second parameter in EdgesGeometry to define the minimum angle rendered all or none of the lines.

The second approach involved creating two separate shapes, extruding them with a depth value of 0, and then repositioning the meshes slightly to give them depth.

While this method was closer to the desired outcome, I still couldn't achieve the edge connections as intended.

Is there a feasible solution for this issue?

https://i.sstatic.net/msBsw.png

For demonstration purposes, here's code snippet showcasing method one:

// JavaScript code snippet goes here...
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>

And here's a snippet demonstrating method two:

// Another JavaScript code snippet goes here...
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>

Edit

Exploring another suggested method by prisoner849 utilizing conditional line segments from this source: . This method yielded similar results to the first one. The challenge persists in either rendering all or none of the lines on the rounded side based on the minimum angle provided. Progress has been made, but the solution seems elusive.

// Additional JavaScript code snippet...
<script src="https://rawgithub.com/mrdoob/three.js/r118/build/three.js"></script>
<script src="https://rawgithub.com/mrdoob/three.js/r118/examples/js/utils/BufferGeometryUtils.js"></script>

Answer №1

Utilizing solely mesh edge data to achieve your desired outcome can be quite challenging, let me elaborate.

You are essentially drawing mesh edges and aiming to render only specific ones (such as the corners). In order to accomplish this, you need a distinguishing characteristic on those edges that sets them apart from others, allowing for isolation. Your attempt with utilizing angle proves difficult due to the similarity of angles present (angles are generally more effective in complex meshes).

I'm unable to think of another viable property that could assist in this situation, but creating your own custom property like vertex color is an option, though it does involve manual intervention. By designing your shapes in 3D modeling tools like Blender, you can easily assign vertex colors to these corner edges and subsequently use these colors during rendering to selectively display those vertices (potentially using a specialized shader). If you're currently generating your mesh, modifying the vertex color of these edges should be integrated into the generation process (although implementing this in three.js might pose challenges). Even if this approach proves successful, executing it effectively is arduous, as coloring all edges and rendering specific ones based on camera angle presents substantial difficulties.

To illustrate why this method may not yield favorable results:

Consider our object with 9 edges at each corner.

https://i.sstatic.net/LVhzh.jpg

For enhanced visibility, I've highlighted the edges of a corner. Upon rotating around the mesh, each edge forms the outline of the object's corner consecutively, making it impossible to depict the overall outline using just one of these edges.

https://i.sstatic.net/OZaUM.gif

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

Tips for creating a Material UI (next) dialog with generous top and bottom margins that extend off the screen

I am encountering a challenge with the layout. What am I looking for? I need a modal dialog that expands vertically, extending beyond the screen, centered both horizontally and vertically, with minimal margin on the top and bottom. Is this feature not d ...

Is it possible for me to determine when all images have finished loading in order to update the isLoaded variable to true?

I am using the template below: <template> <div v-if='isLoaded'> <div @click='selectSight(index)' v-for='(sight, index) in sights'> <img :src="'https://maps.googleapis.com/maps ...

"HTML and JavaScript: The search functionality fails when trying to search for a string that is sourced from an array

Could someone assist me with a comparison issue I'm encountering? I am trying to use the includes() method to compare a list in a table with a list of names stored in a string. Strangely, when I hardcode the string directly into the includes() method, ...

toggle back and forth between two div elements

I am trying to create a toggle effect between two divs, where clicking on one will change its border and header color to red while the other div disappears. I have tried using an IF statement in my JavaScript code, but it is not working as expected. Can so ...

Accessing JSON data from a URL for use within a specific context

I am currently utilizing the request module within Express to fetch a JSON file from a specified link. var url = 'https://api.github.com/users/google/repos'; request.get({ url: url, json: true, headers: {'User-Agent': &apo ...

Tips for showing legend symbols within tooltips on Highcharts

I've encountered an issue with Highcharts that I need help with. In my Highcharts chart, I'm trying to transfer the symbol from the legend to the tooltip. I'm tackling this challenge in two scenarios: Lines: I have two series, one with a ...

Transmitting an item through a GET request using parameters in Postman

Recently joining this site, I created my user account just a few days back. I am attempting to send a GET request using Postman, but it's not working as expected. There seems to be some issue. Here is what I am trying to accomplish: Using Postman: ...

The absence of a semi-colon in JSLint

I encountered an error message indicating a semicolon is missing, however I am unsure of where to place it. Here is the snippet of code: $('.animation1').delay(350).queue(function(){ $(this).addClass("animate-from-top") }); ...

Is it possible to detect a specific string being typed by the user in jQuery?

Similar to the way Facebook reacts when you mention a username by typing @username, how can jQuery be used to set up an event listener for [text:1]? I aim to trigger an event when the user types in [text: into a text field. ...

The setTimeout functionality is executing faster than expected

In my selenium test, I've noticed that the setTimeout function consistently finishes about 25% faster than it should. For example, when waiting for 20 seconds, the function completes after only 15 seconds. test.describe('basic login test',f ...

Exploring the nuances in semantics between AJAX and post/get requests

I'm currently trying to grasp the concept of 'AJAX.' I know that it is short for Async JavaScript over XML, although JSON can also be used instead of XML. As far as I understand, AJAX allows for updating only parts of a web page without need ...

Changing the background color of the canvas using Javascript

I want to create a rect on a canvas with a slightly transparent background, but I don't want the drawn rect to have any background. Here is an example of what I'm looking for: https://i.stack.imgur.com/axtcE.png The code I am using is as follo ...

Using a regular expression to replace text within a TextNode with a new DOM node

I am currently working on a function that preprocesses a Text Node within the HTML DOM. The main objective is to carry out interpolation or string templating. Essentially, the function examines occurrences that match the regular expressions /\${([^}] ...

Tips for preventing HTML ID clashes while integrating with the Document Object Model of external websites

When incorporating additional HTML elements into a webpage using Javascript or jQuery, along with external CSS declarations, it is important to avoid conflicts with existing IDs and class names already present on the page. This could lead to issues if ther ...

Error: JQuery's on() function is not defined

After modifying the code in the original and changed code boxes, I'm now encountering an Uncaught Type error: Undefined is not a function. Any thoughts on why this might be happening? Thanks Original: $('.comment').click(function(e){ ...

Generating a new array based on the keys found in a collection of objects

My array structure is quite complex with multiple objects containing different properties. let arr = [ { id: 1, name: "tony", hatColor: "blue" }, { id: 2, name: "larry", hatColor: "red" }, { id: 3, name ...

I am experiencing issues with the Nuxt.js (SPA) application constantly crashing on iOS Safari whenever I attempt to take multiple photos. Could this be due to a memory

An innovative application I developed utilizes Nuxt.js (SPA) to efficiently process up to 20 images captured with an iPhone in one go. Upon capturing the images, they are compressed to roughly 500KB using a library known as browser-image-compression and th ...

What is the best method to remove the identifier from checkboxes and buttons and iterate using a for loop?

Is there a way to eliminate the need for individual IDs on buttons and checkboxes? I'm looking to streamline my code and remove any duplicates. I attempted to target the checkboxes using const checkbox = document.querySelectorAll('input[type="che ...

Using jQuery and AJAX to send a post request in a Razor page and automatically redirect to the view returned by a MVC Action (similar to submitting

I send a json array to the MVC Action using either JQuery or Ajax, and the Action processes the request correctly. However, when the MVC Action returns a View, I am unsure of how to redirect to this View or replace the body with it. Overall, everything se ...

Tips for preventing circular dependencies in JavaScript/TypeScript

How can one effectively avoid circular dependencies? This issue has been encountered in JavaScript, but it can also arise in other programming languages. For instance, there is a module called translationService.ts where upon changing the locale, settings ...