Game Development Reference
In-Depth Information
There are many other loaders for models in other file formats, including
CTM, OBJ, MTL, PLY, STL, UTF8, VRML, and VTK. These are located in the
examples/js/loaders folder. Almost all of the loaders have a load method, like the
ColladaLoader method mentioned previously, which takes a function to call when
loading is finished. However, loaders do not have a standardized format, and some
of them work in slightly different ways. In particular, the parameters passed to the
callback depend on the file type. You should check the examples folder for demos of
the loader you want to use to make sure you handle the returned result correctly.
In our case, we get a group of sub-meshes (in the result.scene ) back from the
ColladaLoader because Collada files can contain multiple meshes. We need to
modify the flag's materials to make sure each flag reflects its team's color:
result.scene.children[1].material = new THREE.MeshLambertMaterial({
color: type === 'R' ? 0xee1100 : 0x0066ee,
side: THREE.DoubleSide,
});
Recall that when we set up our camera to follow the player around in the last
chapter, we added the camera to the player object. Whenever objects are grouped
together this way, they can be accessed through the parent's children array. In this
case, we're using that array to alter the material for the cloth part of the flag to make
it blue or red depending on which team it belongs to.
In addition to loaders for standard 3D model file formats, there are a number of
Three.js-specific loaders included directly in the library. In particular, THREE.
JSONLoader is designed to load single meshes, while THREE.SceneLoader can
load entire scenes (including lighting, cameras, and other Three.js entities).
There are also built-in loaders for assets other than 3D models. For
example, we've already seen THREE.TextureLoader at work behind
the scenes of THREE.ImageUtils.loadTexture . You can also directly
load pieces of meshes, including geometry, images, and materials. Other
objects such as lights, cameras, and even arbitrary resources can be loaded
as well. However, these loaders are normally invoked under the hood of
the library rather than directly by developers because it usually makes
more sense to load entire models or scenes rather than the individual
pieces. As a result, we will not cover these loaders here, but you can find
them in the src/loaders folder if you would like to learn more.
 
Search WWH ::




Custom Search