ThreeJS bringing Maya-style wireframe rendering to life

Currently, I am attempting to create a wireframe that will display quads instead of triangles by utilizing the following code:

var geo = new THREE.EdgesGeometry( _this.geometry ); // or WireframeGeometry
var mat = new THREE.LineBasicMaterial( { color: 0xffffff, linewidth: 2 } );
var wireframe = new THREE.LineSegments( geo, mat );
_this.scene.add( wireframe );

However, when the model is rendered, it does not show all the edges and still displays some triangles. Ideally, I want it to resemble how Maya presents wireframes.

I have learned that ThreeJS no longer supports Face4, causing it to always showcase triangles instead of quads. Is there any way to work around this limitation? I've heard about using a pixel shader to only display mesh edges, but I have struggled to comprehend and implement it successfully.

If possible, I would greatly appreciate guidance on achieving this goal, whether through existing threejs features or via a pixel shader method.

You can find the model source here.

Thank you!

Answer №1

In case anyone comes across this problem in the future, I wanted to share a solution.

After taking into consideration a suggestion from WestLangley, I decided to tweak the code in WireframeGeometry.js to exclude the rendering of interior diagonals that can sometimes show up when creating a wireframe. This adjustment gives a more familiar appearance to 3D artists as it resembles quad faces.

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

At the end of WireframeGeometry.js, you'll find the changes I've implemented. Admittedly, it's not the most elegant fix, but an alternative approach could involve computing the lines to display before threejs performs triangulation, storing pre-triangulated faces in a separate buffer.

// non-indexed BufferGeometry
position = geometry.attributes.position;

var _i = 0;
for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {

    for ( j = 0; j < 3; j ++ )
        // three edges per triangle, an edge is represented as (index1, index2)
        // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)

        // Included a simple check here to only add the vertices that are not diagonal lines
        if(!(j == 2 && _i == 1) || !(j == 1 && _i == 0)){
            index1 = 3 * i + j;
            vertex.fromBufferAttribute(position, index1);
            vertices.push(vertex.x, vertex.y, vertex.z);

            index2 = 3 * i + ( ( j + 1 ) % 3 );
            vertex.fromBufferAttribute(position, index2);
            vertices.push(vertex.x, vertex.y, vertex.z);
        }
    }

    _i++;
    if(_i == 2){
        _i = 0
    }
}

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

What are some ways to avoid the use of underline and slash symbols in material-ui/pickers?

Is there a way to remove the underline and slash characters that separate day, month, and year in the material ui pickers for version mui version 4? <KeyboardDatePicker margin="normal" id="date-picker-dialog" label="Dat ...

Retrieve particular attributes from an array of objects

I have an array of JavaScript objects structured as follows: let users = [{ "id": 9, "name": "Sulaymon", "family": "Yahyaei", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="deadabb2bfa7b3b1b0b6b99eb ...

What could be causing the error when attempting to send an HttpResponse from a Django View function?

Trying to utilize Ajax, I'm attempting to call a Django View function from JavaScript code. The View function is expected to return an HttpResponse, which should then be printed out on the console. However, upon inspection of the console, it simply s ...

Unable to access the current state within an asynchronous function in React.js

I have encountered an issue with updating state in the top-level component (App) and accessing the updated state in an asynchronous function defined within useEffect(). Here are more details: The problem arises when I try to retrieve the state of the cons ...

Is there a way for JavaScript to generate an image and smoothly transition it from its initial state to its final style?

I am currently working on a JavaScript game that involves moving IMG elements by adjusting their x/y/width/height/opacity properties and utilizing CSS transitions to smoothly move them to their target locations, triggering an event upon arrival. Everything ...

The retrieved information remains unchanged even after modifications are made on the subsequent Next.js server-side rendered page

I'm facing an interesting scenario with my application. It consists of two main pages - one displaying user account statistics and the other allowing users to edit these statistics. Both pages are rendered on the server side. When I navigate to the fi ...

Using Node.js to create a RESTful API that pulls information from MongoDB

I am currently working on creating a REST API using Node.js to retrieve the last N rows from a MongoDB collection. Here is my current code snippet: var express = require("express"); var app = express(); var bodyParser = require("body-pa ...

You have attempted to make an invalid hook call in the react chat app. Hooks can only be called within the body of a function component

Encountering problems like manifest.json:1 Manifest: Line: 1, column: 1, Syntax error. **Important Error Message/User Notification:** react-dom.development.js:20085 The above error occurred in the <WithStyles(ForwardRef(AppBar))> component: Arrange ...

If the width of the table is set to 100% in the CSS, the legend in the Flot chart will automatically shift to the

When the CSS for the table is set to { width:100%}, the Flot chart's legend moves to the left side. Is there any way to maintain the table { width:100%} while also preventing this shift, considering that the CSS is applied site-wide? Here is a jsfid ...

Retrieving data from an Array containing a mix of string and integer values represented as strings, organized by the length of the

Imagine you have an array structured like this: employeeArr = ['Steve', '80000', 'Jen', '90000', 'Bob', '40000'] Where employeeArr[0] and employeeArr[2] represent employee names, and employeeA ...

Tips for submitting a form and retrieving session count without the need to refresh the page after submitting the form

I have set up a form that includes hidden input fields to send data to a PHP script. The script stores the values in an array of sessions by using AJAX to reload the page. Once the data is submitted successfully, an HTML alert message is displayed in <p ...

What is the best way to incorporate a Json file into a JavaScript file?

Using JSON data in JavaScript I recently wrote a JavaScript program that selects a random "advice number" between 1 and 50. Now, I need to figure out how to access a JSON file for the advice messages. JavaScript file: Advice_number = Math.floor(Math.ran ...

Unusual behavior experienced with raycasting in Three JS when objects are are repositioned

Software Versions THREE.ObjectLoader2: 2.4.1 THREE.LoaderSupport.MeshBuilder: 1.2.1 THREE.LoaderSupport.WorkerSupport: 2.2.0 THREE.WebGLRenderer: 93 THREE.REVISION: 93 Anomalies Discovered During a raycast operation on objects within my scene, I encount ...

Nested within an it block are Protractor Jasmine describe blocks

Initially, the code provided below appears to be functioning properly. However, I have not come across anyone using this method before, leading me to question its validity and potential unforeseen drawbacks. The scenario involves writing an end-to-end tes ...

Creating Filled DIVs using JavaScript

Although it may appear to be a common inquiry, my specific needs have not been addressed in any of the Stack threads I've come across. I am dealing with a series of nested DIV statements, as demonstrated here (not all CSS included). I am looking to ...

The code to trigger the button with the ID 'Button' using Document.getElementById() is not executing the associated code-behind

Having just started coding in javascript/VB.NET, I am struggling to get my Button2 onClick event to work properly. The Code-Behind Click Event for Button1 in Page.aspx.vb: Protected Sub _lnbComments_Click(ByVal sender As Object, ByVal e As System.EventAr ...

Is there a way to verify if the user input matches the data in the database?

Currently, my JavaScript program randomly picks an image of an object from the database and shows it to the user. Each image is saved with the object's name, such as apple.gif. To confirm if the user's input response is correct for the test, I&ap ...

Tips for preventing NextJS from including a dynamically imported component in the main _app.js bundle while utilizing Module Aliases

Currently, I am in the process of transforming some shared-ui components into dynamically imported ones within NextJS 11. I have set up module aliases using @nx/next:library, for example @my-site/shared-ui, all exported from an index.ts file as shown belo ...

I'm encountering an issue where my information doesn't seem to be getting through to the Django

For some reason, the data I am trying to post to /api/recipe/recipes/ is not showing up in my HTML {% extends 'base.html' %} {% block content %} <!DOCTYPE html> <html> <head> <script src="h ...

The shading of this complex Three.js model appears unusual

We used Blender to create a 3D model by subtracting an extruded SVG from a flat base using a boolean difference operator. Essentially, we carved a picture into it. While the model looks good in Blender, when we load it into our simple, three.js-based web v ...