@name Entity Node Generator
@inputs 
@outputs Pnodes:table 
@outputs Ob Obj:array
@persist [Obj Radi Names]:array Ob Pnodes:table Loc:vector
@trigger 
@model models/props_junk/PopCan01a.mdl
interval(500)
if(findCanQuery()){
    Entity=entity()
    findInSphere(Entity:pos(),3000)
    findClipToClass("prop_physics")

#    findIncludeClass("prop_physics")
#    findExcludeClass("body")
#    findExcludeClass("ai_")
#    findExcludeClass("weapon")
    Obj=findToArray()
#    Radi=array()
#    for(C=1,Obj:count()){
#        Rad=Obj[C,entity]:radius()
#        if(Rad>50){
#            Radi:pushNumber(Rad)
#        }
#    }
}
Gap=30 #how much clearance do you need?
if(Obj:count()>1&0){
    for(C=1,Obj:count()){
        O1=Obj[C,entity]
        for(D=1,Obj:count()){
            if(Obj){
                O2=Obj[D,entity]
                Dist1=O1:pos():distance(O2:pos())
                Dist2=(Dist1-(O1:radius()+O2:radius()))
                
                if((Dist2>=Gap)&Dist2<=O1:radius()*5){
                    #Spot=((O1:pos()-O2:pos())*(Dist2/Dist1))+O2:pos()
                    Edge1=(O2:pos()-O1:pos()):normalized()*O1:radius()+O1:pos()
                    Edge2=(O1:pos()-O2:pos()):normalized()*O2:radius()+O2:pos()
                    Spot=(Edge1+Edge2)/2
                    Pnodes:pushArray(array(Spot,Pnodes:count()))
                    holoCreate(holoRemainingSpawns(),Spot)
                }
            }
        }
    }
    
}

#########Solidity Test##############
#interval(500)

#if(first()){
#        for(C=1,7){
#            holoCreate(C,entity():pos(),vec(1,1,1)/2)
#        }
#        Names=array()
#        Names:pushString("X")
#        Names:pushString("-X")
#        Names:pushString("Y")
#        Names:pushString("-Y")
#        Names:pushString("Z")
#        Names:pushString("-Z")
#        
#}
Solidity=1 #identify if the object can be entered and place nodes at the entry points
if(Solidity){
    if(Ob<=Obj:count()){timer("retry",20)}
    while(Ob<=Obj:count()&perf()){
        Traces=array()
        O=owner()
        
        #Aim=O:aimEntity()
        Aim=Obj[Ob,entity]
        Loc=Aim:massCenter()
    
        if(Aim&Loc){
            #rangerIgnoreWorld(1)
            #rangerPersist(1)
            
            Box=Aim:boxSize()
            #Gap=30 #how far from the edge of the prop should the node be?
            #Locate entry points on a given prop
            Boxes=array()
            Boxes:pushNumber(Box:x()/2+Gap)
            Boxes:pushNumber(Box:y()/2+Gap)
            Boxes:pushNumber(Box:z()/2+Gap)
            #get the direction vectors of the prop
            Dirvec=array()
            Dirvec:pushVector(Aim:forward())
            Dirvec:pushVector(Aim:right())
            Dirvec:pushVector(Aim:up())
            for(C=1,6){
                B=round(C/2)
                Exp=-1^C
                Local=Loc+Boxes[B,number]*(Exp*Dirvec[B,vector])
    
                Traces[C,number]=!rangerOffset(Loc,Local):hit() #this much I need
                if(Traces[C,number]&Local:isInWorld()){
                    #holoPos(C,Local)
                    
                    holoCreate(holoRemainingSpawns(),Local)
                    
                    Pnodes:pushArray(array(Local,Pnodes:count()))
                }else{
                    #Traces[Names[C,string],ranger]:distance()
                    
                    #Pnodes:pushArray(array(Local,Pnodes:count()))
                }
            }
            if(Traces:sum()){ #if it's hollow in some way
                Pnodes:pushArray(array(Loc,Pnodes:count()))
                holoCreate(holoRemainingSpawns(),Loc)
                #holoPos(7,Loc)
                #holoAng(7,Aim:angles())
            }else{ #if it's solid
                
            }
            
            
            
        }else{
            for(C=1,7){
                holoPos(C,entity():pos())
            }
        }
        Ob++
    }
}
