Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to easily mass-create regions #1

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ local IsVisible = RegionState:IsRegionVisible("Region1") --Bool for if a region
local InRegion = RegionState:IsInRegion("Region1", Vector3.new()) --Bool for if a point is in a region
```

## Quicker Region Setup
TheNexusAvenger marked this conversation as resolved.
Show resolved Hide resolved
`RegionState` offers an additional method that makes it easier to create a centralized folder of "Regions" that you can easily customize, expand, rotate, resize, and re-position.
```
Regions : Instance
|- Region1 : Instance
| |-- ZonePart : BasePart
| |-- ZonePart : BasePart
|- Region2 : Instance
| |-- ZonePart : BasePart
```
Using the instance above as an example,
```lua
local RegionCulling = require(game:GetService("ReplicatedStorage"):WaitForChild("RegionCulling"))
local RegionState = RegionCulling.RegionState

RegionState:InsertRegionsFromInstance(game.ServerStorage.Regions)
TheNexusAvenger marked this conversation as resolved.
Show resolved Hide resolved
--// RegionCulling will generate all regions based on the provided instances.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of a future-tense comment after the action instead of a present-tense comment before. --// is also not used in any other code blocks.

```

## ModelCulling
`ModelCulling` controls the hiding of models based on `RegionState`.
Almost all API calls will be to `BindModelToRegion`, which returns
Expand Down Expand Up @@ -159,4 +178,4 @@ before retrying. Waiting may be required before getting a proper reading.

# License
This project is available under the terms of the MIT License.
See [LICENSE](LICENSE) for details.
See [LICENSE](LICENSE) for details.
25 changes: 24 additions & 1 deletion src/State/RegionState.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ function RegionState:AddRegion(RegionName: string, Center: CFrame, Size: Vector3
})
end

--[[
Creates regions based on a pre-determined model/folder, provides for quicker setup &
easier customization.
Name each region with the appropriate title and then add parts to determine their region.
--]]
function RegionState:InsertRegionsFromInstance(Instances: Model | Folder | Instance): ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typing in Types.lua disagrees with Model | Folder | Instance. Instance should cover this without any issue.

if #Instances:GetChildren() == 0 then
error("Instance \"" .. Instances:GetFullName() .. "\" has no child instances, unable to build Regions from it.")
end
for _, RegionParent in Instances:GetChildren() do
--Get the region name from the child name
local RegionName = RegionParent.Name
for _, RegionPart in RegionParent:GetChildren() do
if RegionPart:IsA("BasePart") then
coasterteam marked this conversation as resolved.
Show resolved Hide resolved
self:AddRegion(RegionName, RegionPart.CFrame, RegionPart.Size)
end
end
end
--// TODO
--// Perform region checks to maybe auto-connect intersecting regions?
coasterteam marked this conversation as resolved.
Show resolved Hide resolved
--// May not apply to all regions however.
end

--[[
Marks a region as visible to another.
--]]
Expand Down Expand Up @@ -162,4 +185,4 @@ end



return (RegionState :: any) :: Types.RegionState
return (RegionState :: any) :: Types.RegionState