threejs how to remove wireframe with WireframeHelper

冷暖自知 提交于 2019-12-25 06:22:51

问题


here i have function to add wireframe for the objects, so am using the following function to do it, on the first condition it is working and i can apply wireframe

 function wireframe(state){


                      if(state=='on')
                      {
                          var wfh = new THREE.WireframeHelper( mesh, 0xf00e0e );
                          wfh.material.wireframe = true;
                          //wfh.material.linewidth = 1; // looks much better if your PC will support it
                          scene.add( wfh );                     

                      }
                      if(state=='off')
                      {
                           var wfh1 = new THREE.WireframeHelper( mesh,0xf00e0e );
                           wfh1.material.wireframe = false;
                           scene.remove(wfh1);  
                      }

            }

in on the second condition i want remove the applied wireframe on object, so remove the scene with scene.remove(wfh1);, it doesn't work wireframes are not removed from the object


回答1:


I think this is what you want. You need a global variable to store the wireframe object assign a value to it just once (if statement) and then selectively add it or remove it from the scene.

var wfh;

function wireframe (state) {

    if  ( state=='on' )
    {
        if ( wfh === `undefined` )    // so you dont add a new wfh each time you call wireframe
            wfh = new THREE.WireframeHelper( mesh, 0xf00e0e );

        scene.add( wfh );                     
    }
    else if ( state=='off' )
    {
        scene.remove( wfh );  
    }
}


来源:https://stackoverflow.com/questions/24407374/threejs-how-to-remove-wireframe-with-wireframehelper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!