function TOOL:CalcOffset( ent )
-- makes ghosts' DoRagdollBone() 5-7 times faster
if CLIENT && mem[ent] && mem[ent].frame == FrameNumber() then return mem[ent].transl, mem[ent].rot end
local usephysics = self:GetClientBool( USEPHYSICS )
local worldspace = self:GetClientBool( WORLDSPACE )
local dir = self:GetClientNumber( DIRECTION )
local offset = self:GetClientVector( OFFSET )
local offset_td = self:GetClientBool( OFFTIMESDIM )
local rot = self:GetClientAngle( ROTATION )
local roto = self:GetClientVector( ROTORIGIN )
local ang, mins, maxs, rotoffset
if worldspace then
ang = Angle(0,0,0)
mins, maxs = ent:WorldSpaceAABB()
rotoffset = vector_origin
--[[
roto = ent:LocalToWorld( roto ) - ent:GetPos()
rotoffset = roto - VecRotate( roto, rot )
rot = ent:LocalToWorldAngles( ang - rot )
--]]
else
ang = ent:GetAngles()
assert( !(usephysics && CLIENT) )
if usephysics && IsValid( ent:GetPhysicsObject() ) then
for _, obj in PhysObjects(ent) do
local omins, omaxs = obj:GetAABB()
if !mins then
mins = obj:LocalToWorldVector(omins)
maxs = obj:LocalToWorldVector(omaxs)
else
mins = VecMin( mins, obj:LocalToWorldVector(omins) )
maxs = VecMax( maxs, obj:LocalToWorldVector(omaxs) )
end
end
else
mins, maxs = ent:OBBMins(), ent:OBBMaxs()
end
--offset = ent:LocalToWorld( offset ) - ent:GetPos()
rotoffset = roto - VecRotate( roto, rot )
rotoffset = ent:LocalToWorld( rotoffset ) - ent:GetPos()
rot = ent:LocalToWorldAngles( rot ) - ent:GetAngles()
end
local dimensions = maxs - mins
if offset_td then
offset.x = offset.x * dimensions.x
offset.y = offset.y * dimensions.y
offset.z = offset.z * dimensions.z
end
local transl = dir == 0 and vector_origin or (-1)^(dir-1) * ang[ dirs[dir] ](ang) * dimensions[ dims[dir] ] -- ÿ ìàíüÿã, çíàþ.
offset = ang:Forward()*offset.x - ang:Right()*offset.y + ang:Up()*offset.z
transl = transl + offset + rotoffset
if CLIENT then mem[ent] = { frame = FrameNumber(), transl = transl, rot = rot } end
return transl, rot
end