@name Arm Hologram
@inputs Button1 Button2 Button3 Button4 Button5
@outputs HoloArm
@persist A [Entity Owner]:entity
interval(100)

if(first()){
    Entity=entity()
    Owner=owner()
    
    # arm main
    
    holoCreate(1)
    holoScale(1,vec(1,1,1) )
    holoPos(1,Entity:toWorld(vec(-5,-17.5,20)))
    holoColor(1,vec(255,255,255))
    holoAng(1,Entity:toWorld(ang(-90,90,0)))
    holoModel(1,"models/Mechanics/robotics/b3.mdl")
    holoMaterial(1, "phoenix_storms/metalfloor_2-3")
    holoParent(1,Entity)
    
    holoCreate(2)
    holoScale(2,vec(1,1,1) )
    holoPos(2,Entity:toWorld(vec(-3,-17.5,76)))
    holoColor(2,vec(255,255,255))
    holoAng(2,Entity:toWorld(ang(90,90,180)))
    holoModel(2,"models/Mechanics/robotics/h2.mdl")
    holoMaterial(2,"phoenix_storms/metalfloor_2-3")
    holoParent(2,Entity)
    
    holoCreate(3)
    holoScale(3,vec(1,1,1) )
    holoPos(3,Entity:toWorld(vec(-1,-17.5,132)))
    holoColor(3,vec(255,255,255))
    holoAng(3,Entity:toWorld(ang(90,90,180)))
    holoModel(3,"models/Mechanics/robotics/d2.mdl")
    holoMaterial(3,"phoenix_storms/metalfloor_2-3")
    holoParent(3,Entity)
    
    # platform base
    
    holoCreate(4)
    holoScale(4,vec(1,1,1) )
    holoPos(4,Entity:toWorld(vec(-5,0,3)))
    holoColor(4,vec(255,255,255))
    holoAng(4,Entity:toWorld(ang(0,180,0)))
    holoModel(4,"models/Mechanics/robotics/d2.mdl")
    holoMaterial(4,"phoenix_storms/iron_rails")
    holoParent(4,Entity)
    
    holoCreate(5)
    holoScale(5,vec(1,1,1))
    holoPos(5,Entity:toWorld(vec(-5,-35,3)))
    holoColor(5,vec(255,255,255) )
    holoAng(5,Entity:toWorld(ang()))
    holoModel(5,"models/Mechanics/robotics/d2.mdl")
    holoMaterial(5,"phoenix_storms/iron_rails")
    holoParent(5,Entity)
    
    holoCreate(6)
    holoScale(6,vec(1,1,1))
    holoPos(6,Entity:toWorld(vec(-5,-17.5,3)))
    holoColor(6,vec(255,255,255) )
    holoAng(6,Entity:toWorld(ang()))
    holoModel(6,"models/hunter/plates/plate1x1.mdl")
    holoMaterial(6, "phoenix_storms/fender_white")
    holoParent(6,Entity)
    
    # end effector
    
    holoCreate(7)
    holoScale(7,vec(1,1,1))
    holoPos(7,Entity:toWorld(vec(-5.5,-17.5,170)))
    holoColor(7,vec(255,255,255))
    holoAng(7,Entity:toWorld(ang(0,0,-90)))
    holoModel(7,"models/Mechanics/robotics/d1.mdl")
    holoMaterial(7,"phoenix_storms/metal")
    holoParent(7,Entity)
    
    holoCreate(8)
    holoScale(8,vec(1,1,1))
    holoPos(8,Entity:toWorld(vec(7.5,-17.5,185)))
    holoColor(8,vec(255,255,255))
    holoAng(8,Entity:toWorld(ang(-90,90,0)))
    holoModel(8,"models/Mechanics/robotics/b1.mdl")
    holoMaterial(8,"phoenix_storms/stripes")
    holoParent(8,Entity)
    
    holoCreate(9)
    holoScale(9,vec(1,1,1))
    holoPos(9,Entity:toWorld(vec(-17.5,-17.5,185)))
    holoColor(9,vec(255,255,255))
    holoAng(9,Entity:toWorld(ang(-90,90,180)))
    holoModel(9,"models/Mechanics/robotics/b1.mdl")
    holoMaterial(9,"phoenix_storms/stripes")
    holoParent(9,Entity)
    
    # joints
    # A1 -> A2: 10
    holoCreate(10,Entity:toWorld(vec(-5,-17.5,50)),vec(0),Entity:toWorld(ang()))
    holoMaterial(10,"models/wireframe")
    
    # A2->A3: 11
    holoCreate(11,Entity:toWorld(vec(-5,-17.5,100)),vec(0),Entity:toWorld(ang()))
    holoMaterial(11,"models/wireframe")
    
    # A3->END EFFECTOR: 12
    holoCreate(12,Entity:toWorld(vec(-5,-17.5,175)),vec(0),Entity:toWorld(ang()))
    holoMaterial(12,"models/wireframe")
    
    # rotary platform
    
    holoCreate(13)
    holoScale(13,vec(0.9))
    holoPos(13,Entity:toWorld(vec(-5,-17.5,3)))
    holoParent(13,Entity)
    holoModel(13,"models/hunter/tubes/circle2x2.mdl")
    holoScale(13,vec(0.4,0.4,2))
    
    # reparent with respect to joints
    holoParent(13,6) # rotary -> base
    holoParent(1,13) # a1 -> rotary
    holoParent(10,1) # j1->a1
    holoParent(2,10) # a2->j1
    holoParent(11,2) # j1->a2
    holoParent(3,11) # a2->j2
    holoParent(12,3) # j2->a2
    
    holoParent(7,12) # end
    holoParent(8,12) # end
    holoParent(9,12) # end
}

local Time=curtime()
local Rot=Time*15
local Sin=sin(Rot%360)*45

holoAng(13,Entity:toWorld(ang(0,curtime()*15,0)))
holoAng(10,holoEntity(13):toWorld(ang(0,0,Sin)))
holoAng(11,holoEntity(2):toWorld(ang(0,90,-Sin*0.8)))
holoAng(12,holoEntity(3):toWorld(ang(0,90,-Sin-45)))
