0

I am trying to display the wireframe of an object file loaded with OBJLoader(). This is the part of the code I am using:

var loader = new THREE.OBJLoader();

loader.load( filePath, function ( object ) {

        object.traverse( function ( child ) {

        if ( child instanceof THREE.Mesh ){

        var  geometry = child.geometry;

        materialMesh = child.material;

        mesh = new THREE.Mesh(geometry, materialMesh);

        var useWireFrame = true;
          if (useWireFrame) {
              mesh.traverse(function (child) {
                    if (child instanceof THREE.Mesh) 
                      {
                        child.material.wireframe = true;
                        hild.material.color = new THREE.Color( 0xff0000 );
                      }
                });
              }

          }// end if

           scene.add( object );
        });

    });

In the following picture it's the result I would like to get:

enter image description here

However, this is what I get with my code:

enter image description here

There are diagonals on each cell! Can anyone tell me what I should modify to obtain a result equivalent to the first picture ?

Thank you!

Sim81
  • 1,574
  • 2
  • 9
  • 15
  • You have to draw quad instead of triangle as a primitive of a mesh to get that as wireframe which i think is not supported in ThreeJS. So i think its not possible to get the result that you want using wireframe. Instead you can try to use `GridHelper` on your mesh to get a similar effect. – Rasheduzzaman Sourov Apr 01 '19 at 06:10
  • Hi, thank you for your answer, please see my comment below. – Sim81 Apr 02 '19 at 02:58

2 Answers2

1

A wireframe helper normally visualizes the actual wireframe model of your object defined by its primitives. Quads are no primitive in WebGL. Only triangles, lines and points (see WebGL specification). Hence, there is also no wireframe helper in three.js that produces your intended visual result.

Mugen87
  • 28,829
  • 4
  • 27
  • 50
  • Thank you for your answer, but what you see in the pictures are the same file objects. The one is the top is visualized by blender the second one by ThreeJS scene. So the primitives are not triangles! there should be a way to obtain the same visualization. – Sim81 Apr 02 '19 at 02:57
  • Are you aware that your Blender object is triangulated when you export it? – Mugen87 Apr 02 '19 at 08:35
1

If you want to render a wireframe of a given geometry, you can now use this pattern:

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

WireframeGeometry will render all edges. EdgesGeometry will render the hard edges only.

Also see this related answer on how to render both a model and its wireframe.

Vu Tan
  • 11
  • 1