Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local inf = math.huge
- local axes = {'X','Y','Z'}
- local function fastComputeAABB(model)
- local min = { inf, inf, inf }
- local max = { -inf, -inf, -inf }
- for _,obj in pairs(model:GetDescendants()) do
- if obj:IsA("BasePart") then
- local cf = obj.CFrame
- local origin = cf.p
- local up,right,look = cf.upVector,cf.rightVector,cf.lookVector
- local halfSize = obj.Size/2
- local hx,hy,hz = halfSize.X, halfSize.Y, halfSize.Z
- local worldR,worldU,worldL,vertex
- for x = -1,1,2 do
- worldR = right * (x * hx)
- for y = -1,1,2 do
- worldU = up * (y * hy)
- for z = -1,1,2 do
- worldL = look * (z * hz)
- vertex = (origin + worldR + worldU + worldL)
- for axisId = 1,3 do
- local coord = vertex[axes[axisId]]
- if coord < min[axisId] then
- min[axisId] = coord
- end
- if coord > max[axisId] then
- max[axisId] = coord
- end
- end
- end
- end
- end
- end
- end
- min = Vector3.new(unpack(min))
- max = Vector3.new(unpack(max))
- return Region3.new(min,max)
- end
Add Comment
Please, Sign In to add comment