Results 1 to 6 of 6
Like Tree8Likes
  • 8 Post By Spoon God

Thread: (E2) Auto Keyframer

  1. #1
    Wire Amateur Spoon God's Avatar
    Join Date
    Jul 2009
    Posts
    91

    Talking (E2) Auto Keyframer

    Watch, and be amazed! (Please?)

    NO! SERIOUSLY! Watch it ^

    So after watching countless numbers of gmod videos lacking animation that wasn't full of jump cuts, physics workarounds or massive jump cuts between poses, I decided to make an E2 to make things easier.

    So!
    You choose a ragdoll as an actor, and can make other ragdolls into poses you want the actor to do, in sequence. You can also set props for positioning and play and test the animation sequence in real time, at any time.

    It interpolates between positions and poses (like keyframes) at an adjustable speed.

    There are many chat commands, and it is possible to use chat commands on only one actor at a time when you have multiple chips spawned.

    When the E2 starts, it will print some info to your chat, along with a number in blue between double ::'s. This number is unique to the E2, and you use it to specify that single E2 for your chat commands.
    - Let's say you spawn it, and the number is :: 42 ::
    To give the E2 a chat command, you say:
    !42 <command> <parameters>
    ...Without the <> of course. Simple enough? It will also listen to !all so you can play or reset all the actors at once and test your scene in full.

    Actual Chat Commands:
    - Command <required parameters> [optional parameters] - Description.
    - Lock - Locks/Unlocks (You cannot select new keyframes while locked).
    - Unlock - Unlocks (does not toggle) an actor.
    - Pause - Pauses/Resumes. No force is applied to paused actors (Anti-lag).
    - Unpause - Unpauses (does not toggle) an actor.
    - Reset - Moves an actor back to keyframe 1.
    - Key <keyframe> - Highlights a keyframe, and makes the others transparent.
    - Highlight <keyframe> - Same as above.
    - Hide [keyframe] - Hides the guides for the specified keyframe, else all keyframes.
    - Show - Reveals all hidden keyframes, also undoes highlighting.
    - Unhide - Same as above.
    - Play [speed] - Moves the actor to frame 1 and plays through to the end.
    - Speed <speed> - Changes the speed of the animation - percent per tick.
    - Set <keyframe> - Moves the actor to the specified keyframe.
    - Rem <keyframe> - Removes the position and ragdoll from the specified keyframe.
    - Rem Key <keyframe> - Removes the ragdoll only from the specified keyframe.
    - Rem Pos <keyframe> - Removes the position only from the specified keyframe.
    - Remove ... - Same as above.
    - Del ... - Same as above.
    - Delete ...- Slightly different from above, oh, wait, IT'S THE SAME!

    Code:
    # By Spoon_God
    @name Keyframe Actor
    @persist Ready Reload C TC Max Wait Locked Paused Speed [ID M Comm]:string [O Main]:entity [Key Pos Bones]:array [R Y G B W Z]:vector [Inv Hid Vis]:vector4
    @model models/props_c17/clock01.mdl
    function void settings(){
        Speed = 3
    #[  Speed is how fast the ragdoll will move between keyframes.
        - Minimum 1
        - Maximum 10
    ]#
    }
    function string name(String:string){
        Array=String:explode("/")
        Array=Array[Array:count(),string]:explode(".")[1,string]:explode("_")
        foreach(I,N:string=Array){
            Array[I,string]=N[1]:upper()+N:sub(2):lower()
        }
        if(Array:count()>1){
            TempS=Array[2,string]
            Array[2,string]=Array[1,string]
            Array[1,string]=TempS
        }
        return Array:concat(" ")
    }
    function number setMax(){
        TempMax=Max
        Max=min(Pos:count(),Key:count())
        if(Max==TempMax){
            return 0
        }else{
            return 1
        }
    }
    function vector bonepos(Cyc:number,Entity:entity,Ind:number){
        return Pos[Cyc,entity]:toWorld(Entity:toLocal(Entity:bone(Ind):pos()))
    }
    function void msg(Message:string){
        printColor(B,ID,W,Message)
    }
    function void msg(Message:string,Focus:string,Color:vector){
        Msgs=Message:explode("&&")
        printColor(B,ID,W,Msgs[1,string],Color,Focus,W,Msgs[2,string])
    }
    function void msg(Message:string,Focus1:string,Focus2:string,Col  or:vector){
        Msgs=Message:explode("&&")
        printColor(B,ID,W,Msgs[1,string],Color,Focus1,W,Msgs[2,string],Color,Focus2,W,Msgs[3,string])
    }
    function void highlight(Num){
        foreach(I,XE:entity=Pos){
            XE:setColor(I==Num ? Vis : Hid)
        }
        foreach(I,XE:entity=Key){
            XE:setColor(I==Num ? Vis : Hid)
        }
        msg("Highlighting Keyframe &&.",Num:toString(),Y)
        runOnLast(1)
    }
    function refinesettings(){
        Speed=clamp(Speed,1,100)/100
    }
    function speed(NewSpeed){
        if(NewSpeed){
            Speed=NewSpeed
            msg("Speed set to &&.",NewSpeed:toString(),B)
            refinesettings()
        }
    }
    function number isKeyframe(Number){
        if(Number>0&Number<=Max){
            return 1
        }else{
            return 0
        }
    }
    function void hide(){
        foreach(I,XE:entity=Pos){
            XE:setColor(Inv)
        }
        foreach(I,XE:entity=Key){
            XE:setColor(Inv)
        }
        msg("Hiding && keyframes.","All",B)
        runOnLast(1)
    }
    function void hide(Num){
        Key[Num,entity]:setColor(Inv)
        Pos[Num,entity]:setColor(Inv)
        msg("Hiding keyframe &&.",Num:toString(),B)
        runOnLast(1)
    }
    function void unhighlight(Message:string){
        foreach(I,XE:entity=Pos){
            XE:setColor(Vis)
        }
        foreach(I,XE:entity=Key){
            XE:setColor(Vis)
        }
        if(Message){
            msg(Message)
        }
        runOnLast(0)
    }
    function void res(Message:string){
        Pause=0
        C=TC=1
        msg(Message)
    }
    if(tickClk()){
        if(Locked==0){
            if(O:keyAttack2()){
                if(O:weapon():type()!="gmod_tool"){
                    Ent=O:aimEntity()
                    if(Ent:owner()==O){
                        if(Ent:boneCount()>1){
                            if(Main){
                                if(Ent!=Main){
                                    foreach(I,E:entity=Key){
                                        if(E==Ent){
                                            Ent=O
                                            break
                                        }
                                    }
                                    if(Ent!=O){
                                        Key:pushEntity(Ent)
                                        setMax()
                                        msg("Keyframe &&Selected. (&&)",Key:count()+" ",name(Ent:model()),G)
                                    }
                                }
                            }else{
                                Main=Ent
                                Bones=Main:bones()
                                msg("Ragdoll Selected: '&&'.\nSelect keyframes with &&",name(Main:model()),"Mouse2",Y)
                            }
                        }elseif(Ent:type()=="prop_physics"){
                            foreach(I,E:entity=Pos){
                                if(E==Ent){
                                    Ent=O
                                    break
                                }
                            }
                            if(Ent!=O){
                                Pos:pushEntity(Ent)
                                setMax()
                                msg("Position &&Selected. (&&)",Pos:count()+" ",name(Ent:model()),G)
                            }
                        }
                    }
                }
            }
        }
        if(Ready){
            if(Reload){
                if(!O:keyReload()){Reload=0}
            }elseif(O:keyReload()){Reload=1
                TC++
            }
            C=min(C+Speed,TC)
            if(C>=Max+1){
                C-=Max
                TC-=Max
            }
            if(Paused){Wait=1}
            if(Wait>0){Wait--}else{Wait=3
                C1=floor(C)
                C2=ceil(C)
                if(C2>Max){C2=1}
                if(C1==C2){
                    R1=Key[C,entity]
                    foreach(I,Bone:bone=Bones){
                        if(!Bone:isFrozen()){
                            Target=bonepos(C1,R1,I)
                            Bone:applyForce(((Target-Bone:pos())*10-Bone:vel())*Bone:mass())
                        }
                    }
                }else{
                    R1=Key[C1,entity]
                    R2=Key[C2,entity]
                    foreach(I,Bone:bone=Bones){
                        if(!Bone:isFrozen()){
                            Target=bonepos(C1,R1,I)
                            Target=Target+(bonepos(C2,R2,I)-Target)*(C%1)
                            Bone:applyForce(((Target-Bone:pos())*10-Bone:vel())*Bone:mass())
                        }
                    }
                }
            }
        }elseif(Key:count()>0&Pos:count()>0){
            C=TC=Ready=1
        }
    }elseif(first()){
        settings()
        refinesettings()
        O=entity()
        O:setAlpha(0)
        runOnTick(1)
        R=vec(255,0,0)
        Y=vec(255,255,0)
        G=vec(0,255,0)
        B=vec(0,255,255)
        W=vec(255,255,255)
        Hid=vec4(255,255,255,128)
        Vis=vec4(255,255,255,255)
        runOnChat(1)
        ID=O:id():toString()
        Comm="!"+ID
        ID=":: "+ID+" :: "
        msg("Activated!\nSelect a ragdoll with &&.","Mouse2",B)
        O=owner()
    }
    if(chatClk(O)){
        Msg=O:lastSaid()
        Msgs=Msg:explode(" ")
        Cmd=Msgs[1,string]
        if(Cmd==Comm|Cmd:upper()=="!ALL"){
            hideChat(1)
            Cmd=Msgs[2,string]:upper()
            if(Cmd=="LOCK"){
                if(Locked){Locked=0
                    msg("Unlocked")
                }else{Locked=1
                    msg("Locked")
                }
            }elseif(Cmd=="UNLOCK"){
                if(Locked){Locked=0
                    msg("Unlocked")
                }else{
                    msg("Not locked")
                }
            }elseif(Cmd=="PAUSE"){
                if(Paused){Paused=0
                    msg("Unpaused")
                }else{Paused=1
                    msg("Paused")
                }
            }elseif(Cmd=="UNPAUSE"){
                if(Paused){Paused=0
                    msg("Unpaused")
                }else{
                    msg("Not paused")
                }
            }elseif(Cmd=="RESET"){
                if(Max>0){
                    res("Reset")
                }else{
                    msg("Could not reset")
                }
            }elseif(Cmd=="HIGHLIGHT"|Cmd=="KEY"){
                Num=floor(Msgs[3,string]:toNumber())
                if(isKeyframe(Num)){
                    highlight(Num)
                }else{
                    unhighlight("Resetting highlights")
                }
            }elseif(Cmd=="HIDE"){
                Num=floor(Msgs[3,string]:toNumber())
                if(isKeyframe(Num)){
                    hide(Num)
                }else{
                    hide()
                }
            }elseif(Cmd=="UNHIDE"|Cmd=="SHOW"){   
                unhighlight("Showing all keyframes")
            }elseif(Cmd=="PLAY"){
                speed(Msgs[3,string]:toNumber())
                res("Playing from start")
                timer("Play",250)
            }elseif(Cmd=="SPEED"){
                speed(Msgs[3,string]:toNumber())
            }elseif(Cmd=="SET"){
                Num=Msgs[3,string]:toNumber()
                if(isKeyframe(Num)){
                    if(round(Num)==Num){
                        C=TC=Num
                        msg("Set to keyframe &&.",Num:toString(),B)
                    }else{
                        C=Num
                        TC=ceil(Num)
                        msg("Set to keyframe && (&&).",floor(Num):toString(),"+"+round((Num%1)*100)+"%",B)
                    }
                }
            }elseif(Cmd=="DELETE"|Cmd=="DEL"|Cmd=="REMOVE"|Cmd=="REM"){
                Cmd=Msgs[3,string]:upper()
                if(Cmd=="POS"){
                    Num=floor(Msgs[4,string]:toNumber())
                    if(Num>0&Num<=Pos:count()){
                        Pos:remove(Num)
                        if(setMax()){
                            msg("Removed position && - Total keyframes: &&",Num:toString(),Max:toString(),Y)
                        }else{
                            msg("Removed position &&",Num:toString(),Y)
                        }
                    }else{
                        msg(Num+" %%","is not a valid position keyframe",R)
                    }
                }elseif(Cmd=="KEY"){
                    Num=floor(Msgs[4,string]:toNumber())
                    if(Num>0&Num<=Key:count()){
                        Key:remove(Num)
                        if(setMax()){
                            msg("Removed ragdoll && - Total keyframes: &&",Num:toString(),Max:toString(),Y)
                        }else{
                            msg("Removed ragdoll &&",Num:toString(),Y)
                        }
                    }else{
                        msg(Num+" %%","is not a valid ragdoll keyframe",R)
                    }
                }else{
                    Num=floor(Cmd:toNumber())
                    if(isKeyframe(Num)){
                        Key:remove(Num)
                        Pos:remove(Num)
                        Max--
                        msg("Removed keyframe && - Total keyframes: &&",Num:toString(),Max:toString(),Y)
                    }else{
                        msg(Num+" %%","is not a valid keyframe",R)
                    }
                }
            }
        }
    }
    if(clk("Play")){
        TC=Max
    }
    if(last()){
        unhighlight("")
    }
    Attached Files Attached Files
    Last edited by Spoon God; 02-27-2012 at 03:05 PM.
    (Ragdoll Keyframer) (Awesome Heads) (Fish Tank) (Virtual Fish Pond) (Fishing Rod) (Crap) (Sparkle) (Airboat Tank V2.0) (Balls of Rubber V2.0) (Bomb Truck) (Nuke Cannon) (Jet)
    If my computer is online, you can see all my new stuff at my E2 page.

  2. #2
    Ursus maritimus Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    6,694
    Blog Entries
    1

    Default Re: (E2) Auto Keyframer

    This is fucking epic.

  3. #3
    Indie Developer Okei's Avatar
    Join Date
    Jul 2011
    Location
    Romania,Bucharest
    Posts
    113

    Default Re: (E2) Auto Keyframer

    Today , when i was eating i was thinking , why nobody make cool stuf using bones? Then i saw this...
    Great work .

  4. #4
    Wire Amateur Spoon God's Avatar
    Join Date
    Jul 2009
    Posts
    91

    Default Re: (E2) Auto Keyframer

    Quote Originally Posted by Drunkie View Post
    This is fucking epic.
    Quote Originally Posted by Okei View Post
    Today , when i was eating i was thinking , why nobody make cool stuf using bones? Then i saw this...
    Great work .
    Thanks to the both of you.
    (Ragdoll Keyframer) (Awesome Heads) (Fish Tank) (Virtual Fish Pond) (Fishing Rod) (Crap) (Sparkle) (Airboat Tank V2.0) (Balls of Rubber V2.0) (Bomb Truck) (Nuke Cannon) (Jet)
    If my computer is online, you can see all my new stuff at my E2 page.

  5. #5
    Wire Sofaking xk4melot's Avatar
    Join Date
    Dec 2008
    Location
    WI
    Posts
    573

    Default Re: (E2) Auto Keyframer

    Very cool.

    Small world eh? Chaos has been my friend since like 6th grade lol.

  6. #6
    Wire Amateur Wully's Avatar
    Join Date
    Jan 2010
    Posts
    60

    Default Re: (E2) Auto Keyframer

    Outstanding work!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
unnecessary
unnecessary
unnecessary
unnecessary
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots