Created
January 15, 2013 21:18
-
-
Save max-mapper/4542146 to your computer and use it in GitHub Desktop.
horse.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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