Graphics Reference
In-Depth Information
If you check the
animate
box, an animation that automatically morphs this car will
start.
How to do it…
To use morphing animations, we need to take the following steps:
1. The first thing we need to do is load the model that contains morph targets.
For this recipe, we've got a
JSON
-based model, which we load like this:
var jsonLoader = new THREE.JSONLoader();
jsonLoader.load("../assets/models/morph/
car.js",
function(model, materials) {
...
});
Here, we use
THREE.JSONLoader
to load a model, and once it is loaded,
we call the provided function.
2. Before we create
THREE.Mesh
, there is one additional step we need to take.
We need to set the
morphTargets
property on the materials that are set to
true
:
materials.forEach(function(mat) {
mat.morphTargets = true;
});