问题
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