My goal is to import obj files into a WebGL scene with the help of Three.js. I came across some sample codes, like the one below, that seemed to work well. However, I am curious about the purpose of the command
object.traverse();
What does this command do? And what could possibly go wrong if we skip the traversing step? Any insights would be greatly appreciated.
// Setting up the loader and loading the model
var oLoader = new THREE.OBJLoader();
oLoader.load('models/chair.obj', function(object, materials) {
// var material = new THREE.MeshFaceMaterial(materials);
var material2 = new THREE.MeshLambertMaterial({ color: 0xa65e00 });
object.traverse( function(child) {
if (child instanceof THREE.Mesh) {
// Applying custom material
child.material = material2;
// Enabling casting shadows
child.castShadow = true;
child.receiveShadow = true;
}
});
object.position.x = 0;
object.position.y = 0;
object.position.z = 0;
object.scale.set(1, 1, 1);
lesson6.scene.add(object);
});