function ViewportWindow._createVPF(v,d,R)local b=Instance.new("\086\105\101\119\112\111\114\116\070\114\097\109\101")b.LightColor=Color3.new(0,0,0)b.Size=UDim2.new(1,0,1,0)b.Position=UDim2.new(0,0,0,0)b.AnchorPoint=Vector2.new(0,0)b.BackgroundTransparency=1 b.LightDirection=-Lighting:GetSunDirection()b.Ambient=Lighting.Ambient b.Name=d b.ZIndex=R b.CurrentCamera=v.camera b.Parent=v.surfaceGui return b end function ViewportWindow._refreshVisibility(x,d,R,v,b)local i,L=Helpers.getAABB({R*Vector3.new(-v.X/2+b,v.Y/2-b,-b),R*Vector3.new(v.X/2-b,v.Y/2-b,-b);R*Vector3.new(v.X/2-b,-v.Y/2+b,-b),R*Vector3.new(-v.X/2+b,-v.Y/2+b,-b);d.Position})local f=x.worldRoot:FindPartsInRegion3(Region3.new(i.Position+L/2,i.Position-L/2),nil,math.huge)local N={}for d,R in pairs(f)do R.LocalTransparencyModifier=1 N[R]=true end for d,R in pairs(x.worldRoot:GetDescendants())do if R:IsA("\066\097\115\101\080\097\114\116")and not N[R]then R.LocalTransparencyModifier=0 end end end
-- Private

function ViewportWindow:_createVPF(name, zindex)
	local vpf = Instance.new("ViewportFrame")
	vpf.LightColor = Color3.new(0, 0, 0)
	vpf.Size = UDim2.new(1, 0, 1, 0)
	vpf.Position = UDim2.new(0, 0, 0, 0)
	vpf.AnchorPoint = Vector2.new(0, 0)
	vpf.BackgroundTransparency = 1
	vpf.LightDirection = -Lighting:GetSunDirection()
	vpf.Ambient = Lighting.Ambient
	vpf.Name = name
	vpf.ZIndex = zindex
	vpf.CurrentCamera = self.camera
	vpf.Parent = self.surfaceGui

	return vpf
end

function ViewportWindow:_refreshVisibility(cameraCFrame, surfaceCFrame, surfaceSize, marginOfError)
	local aabbCF, aabbSize = Helpers.getAABB({
		surfaceCFrame
			* Vector3.new(-surfaceSize.X / 2 + marginOfError, surfaceSize.Y / 2 - marginOfError, -marginOfError),
		surfaceCFrame
			* Vector3.new(surfaceSize.X / 2 - marginOfError, surfaceSize.Y / 2 - marginOfError, -marginOfError),
		surfaceCFrame
			* Vector3.new(surfaceSize.X / 2 - marginOfError, -surfaceSize.Y / 2 + marginOfError, -marginOfError),
		surfaceCFrame
			* Vector3.new(-surfaceSize.X / 2 + marginOfError, -surfaceSize.Y / 2 + marginOfError, -marginOfError),
		cameraCFrame.Position,
	})

	-- region3 is more performant tmk over newer API which allows rotation (which we don't need)
	-- local overlap = self.worldRoot:GetPartBoundsInBox(aabbCF, aabbSize)
	local overlap = self.worldRoot:FindPartsInRegion3(
		Region3.new(aabbCF.Position + aabbSize / 2, aabbCF.Position - aabbSize / 2),
		nil,
		math.huge
	)

	local overlapped = {}
	for _, part in pairs(overlap) do
		part.LocalTransparencyModifier = 1
		overlapped[part] = true
	end

	for _, instance in pairs(self.worldRoot:GetDescendants()) do
		if instance:IsA("BasePart") and not overlapped[instance] then
			instance.LocalTransparencyModifier = 0
		end
	end
end
