currently adding a wireframe works perfectly. Removing too, except that my textures are gone and I am left with a “black-ish” model.
What is the proper way of removing a wireframe and bring the model back in its old state?
function toggleWireframe()
{
if(wireframe == false) {
model.traverse(function(child) {
if (child.isMesh) {
// Add a mesh which will be used for our wireframe
let geometry = child.geometry;
let material = child.material.color = new THREE.Color(0x000000);
let mesh = new THREE.Mesh(geometry, material);
mesh.name = 'mesh';
scene.add(mesh);
// Setup our wireframe
const wireframeGeometry = new THREE.WireframeGeometry(geometry);
const wireframeMaterial = new THREE.LineBasicMaterial({color: 0xFFFFFF});
const wireframe = new THREE.LineSegments(wireframeGeometry, wireframeMaterial);
wireframe.name = 'wireframe';
mesh.add(wireframe);
}
});
wireframe = true;
} else {
scene.remove(scene.getObjectByName('mesh'));
scene.remove(scene.getObjectByName('wireframe'));
wireframe = false;
}
}
If I use that code, I cannot remove the wireframe anymore.
The reason that I added a mesh is because I dont want any textures to show when I apply the wireframe. I want the model to be “grey”
let material = child.material.color = new THREE.Color(0x000000);
What happens here is that you overwrite the original color of the model’s material. Even if you remove the wireframe and the respective mesh, the color of the model is still changed. I think it’s better if you create an own material for the wireframe display.