The Best Way to Display Quad Wireframe in Three.js using OBJ Model

I am trying to display the wireframe of OBJ meshes using Three.js. However, Three.js can only render triangles, so I came up with the idea of creating a line for each edge of the model.

After parsing the OBJ file and iterating through its vertices and faces, I was able to achieve the desired functionality.


On the right side, you can see the standard LineSegments model with triangles, while on the left is my attempt at rendering the actual wireframe.

Code: https://codepen.io/flolu/pen/zYrexyr

https://i.sstatic.net/2KSak.png

However, I am facing some challenges with my approach

1. Performance Issues

Adding all the lines seems to cause lag in the viewport, which is surprising given that the model isn't very large.

2. Clipping Problems

In certain areas of the mesh, the lines are not being rendered. This could be due to the inner mesh being rendered with triangles, causing some clipping.

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

3. Feasibility Concerns

Since I have limited experience working with OBJ files, I am unsure if this method will work for all meshes. Additionally, I would prefer a solution that can be applied to other file formats as well.

For example, changing line 182 from

const model = antler;

to

const model = test;

loads another model, but some edges are missing. https://i.sstatic.net/0n5r9.png


It would be great if someone could enhance the CodePen example :)

Answer №1

Question 1:

The performance of this method suffers greatly because each frame independently renders 4370 lines! This high number of drawcalls can severely impact a machine's framerate. I suggest creating a single LineSegments object with all the required vertex pairs instead of numerous individual Line objects. This way, all lines will be rendered in a single call!

Question 2:

To avoid clipping, you can set the material to depthTest: false and adjust the renderOrder to be higher than the white mesh so that it renders on top of it.

Question 3:

Regarding your OBJ, the construction of it will determine the solution. It's worth noting that posting multiple questions in one post on Stack Overflow is discouraged as it can diminish the effectiveness of the platform. In the future, consider breaking down your questions or seek assistance from a more open-ended forum like

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

Encountered a failure while loading modules in AngularJS

When I tried opening the index.html page using Chrome, I encountered an error stating that the correct modules could not be found. Uncaught SyntaxError: Unexpected token < angular.js:1 Uncaught SyntaxError: Unexpected token < controller.js:1 ...

What is the best way to save data from an ng-repeat array in MEANJS?

I've been exploring MEANJS at meanjs.org and I'm having trouble storing array data for ng-repeat in the deal object, which includes dealtype and dealprice. Despite setting up addFields for the ng-repeat input tag in the create form, the data isn& ...

Utilizing Electron API within an Angular Component

I'm hoping to utilize a locally stored video file in electron and play it within my angular component. Despite exposing the loadLocalFile function to prevent the need for setting nodeIntegration to true, I keep receiving a Security Warning : This re ...

Using Spring Boot and AJAX to dynamically load content as users scroll down the page

Hi there! I've been running into some issues with Spring Boot and AJAX. Currently, I have buttons that need to be clicked in order to navigate to another page (next, previous). I'd like to use an AJAX request instead to load my page when scrollin ...

Obtain Node Information in THREE.js

I'm working on a mesh using a unique shader. In the vertex shader, I am adjusting the original position of the geometry vertices. Now, my challenge is to be able to retrieve and access these new vertex positions from outside of the shader. How can I s ...

"Unlocking the secret to fetching the id of the clicked element within a Highchart context menu

Is it possible to retrieve the id of a clicked button on the highchart context menu? Alternatively, is there a way to execute the click function twice? const contextButtonArray = []; contextButtonArray.push({ { text: 'TEST BUTTON&ap ...

Tips for uploading a jpg image to the server using react-camera

My objective is to transfer an image captured from a webcam to a Lambda function, which will then upload it to AWS S3. The Lambda function appears to work during testing, but I'm struggling to determine the exact data that needs to be passed from the ...

Using Twig path to pass Ajax URL parameter

I'm facing an issue in my Twig view when passing parameters in the AJAX URL path. Since Twig is executed before JavaScript, it doesn't recognize the input value passed as a parameter. Is there a way to solve this without passing the param in data ...

Issues with debuggers in Chrome and Firefox with AngularJS are causing frustration for developers

Currently, I am in the process of developing a hybrid application that combines AngularJS with Angular 8. As part of my testing procedure, I am attempting to debug the application. However, I have encountered an issue where the debuggers function properly ...

Is there a way to use jQuery to adjust the text color once it has been clicked on?

I have been struggling to change the text color upon clicking on it without any success. Within my code, there are seven labels - one for the question, four for the answer options, one for the correct answer, and the last one for the explanation. The desi ...

What is the best way to pass multiple variables to a PHP file with AJAX using a GET request?

Can you help me figure out how to send both an I.D. value and a name value to a php file using ajax? Currently, I am successfully sending just the I.D. variable, however, when I attempt to add the name variable, the function stops working. The code that w ...

What is the best way to verify if a value matches the container ID in Vue?

I am trying to create a condition where a property is checked against the ID of a div container. If they match, I want to display the container. For example, in the code snippet below, I need to compare the activeWindow property with the div id. If they a ...

Waiting for all API queries in VueJS is important to ensure that all data has been

Hey there, I currently have an API set up using Django Rest Framework and the front end is built with VueJS. I have a form view that can either be used to Add New or Modify existing data. The structure of the form remains the same, but it checks if an ID ...

Firebase Authentication error code "auth/invalid-email" occurs when the email address provided is not in a valid format, triggering the message "The email address is

Currently, I am working on integrating Firebase login and registration functionality into my Angular and Ionic 4 application. Registration of user accounts and password retrieval are functioning properly as I can see the accounts in my Firebase console. Ho ...

What is the best way to invoke a function in a class from a different class in Angular 6?

Below is the code snippet: import { Component, OnInit, ViewChild } from '@angular/core'; import { AuthService } from '../core/auth.service'; import { MatRadioButton, MatPaginator, MatSort, MatTableDataSource } from '@angular/mater ...

discovering a new type of mutation through the use of Vuex

Vue Component computed: { score () { this.$store.commit('fetchCoordinates'); console.log(this.$store.getters.cordinate); } } store.js export default { state: { lat:'ok', }, getters:{ cordinate(state){ r ...

Slideshow of table rows in HTML

On a webpage, I am populating an HTML table with a random number of rows ranging from 1 to 100. Regardless of the total number of rows, the requirement is to display only 10 rows at a time on the screen and then shift to the next set of 10 rows every 5 sec ...

The detailed record of this run can be accessed at:

npm ERR! code ENOTEMPTY npm ERR! syscall rename npm ERR! path /usr/local/lib/node_modules/expo-cli npm ERR! dest /usr/local/lib/node_modules/.expo-cli-dKBr48UN npm ERR! errno -39 npm ERR! ENOTEMPTY: The directory cannot be renamed because ...

The light/dark mode toggle is a one-time use feature

I've been experimenting with creating a button to toggle between light and dark modes on my website. Initially, it's set to light mode, but when I try switching to dark mode, it works fine. However, the issue arises when attempting to switch back ...

Access the JavaScript variable in a webview and store it in an Android variable

I have been attempting to retrieve a variable from a webview, but I am only able to make modifications like this: browser.loadUrl("javascript:var x = document.getElementById('login').value = 'something';"); However, I need to be able ...