I did this to emulate an orbit with the characteristics of a person (jerky), but it can be used for other animations, such as transfers of objects, position and rotation.
function twController(node,prop,arr,dur){ var obj,first,second,xyz,i,v,tween,html,prev,starter; switch(node){ case "camera": obj = camera; break; default: obj = scene.getObjectByName(node); } xyz = "x,y,z".split(","); $.each(arr,function(i,v){ first = obj[prop]; second = {}; $.each(v,function(i,v){ second[xyz[i]] = v; }) tween = new TWEEN.Tween(first) .to(second, dur) .onUpdate(function(){ $.each(xyz,function(i,v){ obj[prop][xyz[i]] = first[xyz[i]]; }) }) .onComplete(function(){ html = []; $.each(xyz,function(i,v){ html.push(Math.round(first[xyz[i]])); }) $("#camPos").html(html.join(",")) }) if(i >0){ tween.delay(250); prev.chain(tween); } else{ starter = tween; } prev = tween; }); starter.start(); }
Chris glasier
source share