Display wireframe and solid color

后端 未结 4 676
清歌不尽
清歌不尽 2020-11-27 17:56

Is it possible to display the wireframe of the object and also the solid color of its faces on the same object? I found a way using a clone of the object and assign differen

4条回答
  •  盖世英雄少女心
    2020-11-27 18:35

    To render both a model and its wireframe, you can use a pattern like this one:

    // mesh
    var material = new THREE.MeshPhongMaterial( {
        color: 0xff0000,
        polygonOffset: true,
        polygonOffsetFactor: 1, // positive value pushes polygon further away
        polygonOffsetUnits: 1
    } );
    var mesh = new THREE.Mesh( geometry, material );
    scene.add( mesh )
    
    // wireframe
    var geo = new THREE.EdgesGeometry( mesh.geometry ); // or WireframeGeometry
    var mat = new THREE.LineBasicMaterial( { color: 0xffffff, linewidth: 2 } );
    var wireframe = new THREE.LineSegments( geo, mat );
    mesh.add( wireframe );
    

    The use of polygonOffset will help prevent z-fighting between the mesh material and the wireframe line. Consequently, the wireframe will look a lot better.

    fiddle: http://jsfiddle.net/tfjvggfu/24/

    EDIT: updated to three.js r.82

提交回复
热议问题