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


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
