@name 3-Point Bezier Joint
@persist [Start Mid End]:entity

if(first()) {
    #include "mantle/vector"
    #include "mantle/angle"
    Start=propSpawn("models/sprops/cuboids/height06/size_1/cube_6x6x6.mdl",1)
    Mid=propSpawn("models/sprops/cuboids/height06/size_1/cube_6x6x6.mdl",1)
    End=propSpawn("models/sprops/cuboids/height06/size_1/cube_6x6x6.mdl",1)
    
    Start:setAlpha(0)
    Mid:setAlpha(0)
    End:setAlpha(0)
    
    for(I=1,6) {
        holoCreate(I)
        holoModel(I,"models/sprops/cuboids/height06/size_1/cube_6x6x6.mdl")
    }
    
    holoColor(1,vec(255,0,0))
    holoColor(2,vec(255,255,0))
    holoColor(2,vec(0,255,0))
}

holoPos(1,Start:pos())
holoPos(2,Mid:pos())
holoPos(3,End:pos())

local Ln=bezier(3,Start:pos(),Mid:pos(),End:pos())

foreach(I,V:vector=Ln) {
    holoPos(3+I,V)
    local NP=I<3 ? Ln[I+1,vector] : End:pos()
    local Mid=(V+NP)/2
    local Len=(V-NP):length()/6
    local Ang=(V-NP):toAngle()
    holoScale(3+I,vec(Len,0.1,0.1))
    holoAng(3+I,Ang)
}

interval(1000)

if(last()) {
    Start:propDelete()
    Mid:propDelete()
    End:propDelete()
}
