Best options for animation in THREE.JS

前端 未结 5 496
鱼传尺愫
鱼传尺愫 2020-12-29 14:39

What is the best options for animations (texture animations, moving objects, hiding/showing object,...) in three.js ? Do you use extra lib. such as tween.js or something els

5条回答
  •  抹茶落季
    2020-12-29 15:00

    I made this to emulate orbiting with human characteristics (jerky) but it can be used for other animations like object translations, positions and rotations.

    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();
    }
    

提交回复
热议问题