I need to implement a wireframe for an object when a button is clicked. I am using the traverse
function to achieve this, and it works perfectly fine in the OBJMTLLoader. However, when I try to use it in a separate function as shown below and then click the button, it results in:
object is undefined
function wireframe(object){
//alert('hhhhhh');
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh )
{
//child.geometry.computeFaceNormals();
var geometry = child.geometry;
//console.log(geometry);
//geometry.dynamic = true;
material = child.material;
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
var useWireFrame = true;
if (useWireFrame) {
mesh.traverse(function (child) {
if (child instanceof THREE.Mesh)
{
//child.material.wireframe = true;
var wfh = new THREE.WireframeHelper( mesh, 0xffffff );
wfh.material.wireframe = true;
wfh.material.linewidth = 2; // looks much better if your PC will support it
scene.add( wfh );
}
});
}
}
});
}
Is it possible to traverse on the object onclick? Why am I encountering this error?