Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created January 15, 2013 21:18
Show Gist options
  • Save max-mapper/4542146 to your computer and use it in GitHub Desktop.
Save max-mapper/4542146 to your computer and use it in GitHub Desktop.
horse.js
var loader = new game.THREE.JSONLoader( true )
loader.load( "/horse.js", function( geometry ) {
window.horseGeometry = horseGeometry = geometry
})
function Horse() {
this.radius = 600
this.theta = 0
this.duration = 1000
this.keyframes = 15
this.interpolation = this.duration / this.keyframes
this.lastKeyframe = 0
this.currentKeyframe = 0
this.lastPositionTime = Date.now()
var mesh = new game.THREE.Mesh( horseGeometry, new game.THREE.MeshLambertMaterial( { color: 0x606060, morphTargets: true } ) )
mesh.scale.set( 0.25, 0.25, 0.25 )
this.mesh = mesh
}
Horse.prototype.tick = function() {
if (Date.now() - this.lastPositionTime > 150) return
var time = Date.now() % this.duration
var keyframe = Math.floor( time / this.interpolation )
if ( keyframe != this.currentKeyframe ) {
this.mesh.morphTargetInfluences[ this.lastKeyframe ] = 0
this.mesh.morphTargetInfluences[ this.currentKeyframe ] = 1
this.mesh.morphTargetInfluences[ keyframe ] = 0
this.lastKeyframe = this.currentKeyframe
this.currentKeyframe = keyframe
}
this.mesh.morphTargetInfluences[ keyframe ] = ( time % this.interpolation ) / this.interpolation
this.mesh.morphTargetInfluences[ this.lastKeyframe ] = 1 - this.mesh.morphTargetInfluences[ keyframe ]
}
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment