Graphics Reference
In-Depth Information
scene.add(obj);
});
As you can see, we pass both .obj and .mtl files into the load function.
The final argument of this load function is a callback function. This call-
back function will be called when the model is done loading.
3. At this point, you can do everything you want with the loaded model. In this
example, we add the scaling and rotation functionality through the menu in
the top-right section and apply these properties to the render function:
function render() {
renderer.render(scene, camera);
var lego =
scene.getObjectByName('lego');
if (lego) {
lego.rotation.y +=
control.rotationSpeed;
lego.scale.set(control.scale,
control.scale, control.scale);
}
requestAnimationFrame(render);
}
How it works...
The .obj and .mtl file formats are well-documented formats. OBJMTLLoader
parses the information from these two files and creates geometries and materials
based on that information. It uses the .obj file to determine an object's geometry
and uses information from the .mtl file to determine the material, which is
THREE.MeshLambertMaterial in this case, to be used for each geometry.
Three.js then combines these together into THREE.Mesh objects and returns a
single THREE.Object3D object that contains all the parts of the Lego figure, which
you can then add to the scene.
Search WWH ::




Custom Search