prerender functions

This example is the same as the previous one, except that the code has a structure that will scale to larger applications more easily. Specifically, the VWBug constructor loads the model, and also implements a prerender function which does the animation (this function is often called prerender instead). This gets the animation code out of the rendering function, which can otherwise become unreadable in larger applications. Note that one additional safety check on the movement is implemented as well.

this.prerender = function(dt) {  
  if (!this.mesh)  return;
  var dx = new THREE.Vector3();
  dx.sub(this.goal,this.mesh.position);
  if (dx.length() > closeEnough) {
    dx.normalize();
    dx.multiplyScalar(dt*this.speed);
    this.mesh.position.addSelf(dx);
  }
};

1-2-three
example 11: prerender functions