From 786d1cb88e5f57cf909e5530115ec09fe1db015a Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Sun, 13 Aug 2023 21:49:17 -0400 Subject: [PATCH 01/12] Update RegionState.lua --- src/State/RegionState.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/State/RegionState.lua b/src/State/RegionState.lua index 44c215c..3003605 100644 --- a/src/State/RegionState.lua +++ b/src/State/RegionState.lua @@ -95,6 +95,23 @@ 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): () + 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 + self:AddRegion(RegionName, RegionPart.CFrame, RegionPart.Size) + end + end + end +end + --[[ Marks a region as visible to another. --]] @@ -162,4 +179,4 @@ end -return (RegionState :: any) :: Types.RegionState \ No newline at end of file +return (RegionState :: any) :: Types.RegionState From 63f1a09b4123631946883b36b26afd1229dbff81 Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Sun, 13 Aug 2023 22:02:14 -0400 Subject: [PATCH 02/12] Update README.md --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 17de6c0..5af2b9f 100644 --- a/README.md +++ b/README.md @@ -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 +`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) +--// RegionCulling will generate all regions based on the provided instances. +``` + ## ModelCulling `ModelCulling` controls the hiding of models based on `RegionState`. Almost all API calls will be to `BindModelToRegion`, which returns @@ -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. \ No newline at end of file +See [LICENSE](LICENSE) for details. From 314fa0f0f67bede1445bf52a42353c592c783ea8 Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Sun, 13 Aug 2023 22:04:12 -0400 Subject: [PATCH 03/12] Update RegionState.lua --- src/State/RegionState.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/State/RegionState.lua b/src/State/RegionState.lua index 3003605..4beb0e2 100644 --- a/src/State/RegionState.lua +++ b/src/State/RegionState.lua @@ -101,6 +101,9 @@ easier customization. Name each region with the appropriate title and then add parts to determine their region. --]] function RegionState:InsertRegionsFromInstance(Instances: Model | Folder | Instance): () + 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 @@ -110,6 +113,9 @@ function RegionState:InsertRegionsFromInstance(Instances: Model | Folder | Insta end end end + --// TODO + --// Perform region checks to maybe auto-connect intersecting regions? + --// May not apply to all regions however. end --[[ From 2f328f3c620729615e62ec59ad5a6e37d4088ed1 Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Sun, 13 Aug 2023 22:34:29 -0400 Subject: [PATCH 04/12] Update README.md Re-elaborate on README --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5af2b9f..fd6c5b2 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ 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 +#### Quicker Region Setup `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 @@ -79,10 +79,11 @@ Regions : Instance ``` Using the instance above as an example, ```lua -local RegionCulling = require(game:GetService("ReplicatedStorage"):WaitForChild("RegionCulling")) +local ReplicatedStorage = game:GetService("ReplicatedStorage") +local RegionCulling = require(ReplicatedStorage:WaitForChild("RegionCulling")) local RegionState = RegionCulling.RegionState -RegionState:InsertRegionsFromInstance(game.ServerStorage.Regions) +RegionState:InsertRegionsFromInstance(ReplicatedStorage:WaitForChild("Regions")) --// RegionCulling will generate all regions based on the provided instances. ``` From b6a4e0493004abe1fc44a37637bfbd3902603b33 Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Sun, 13 Aug 2023 23:17:43 -0400 Subject: [PATCH 05/12] Update RegionState.spec.lua need to setup my TestEZ again to test this, so bear with me. --- test/State/RegionState.spec.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/State/RegionState.spec.lua b/test/State/RegionState.spec.lua index f6103a1..792423d 100644 --- a/test/State/RegionState.spec.lua +++ b/test/State/RegionState.spec.lua @@ -142,5 +142,19 @@ return function() expect(RegionStateObject:IsRegionVisible("Region2")).to.equal(false) expect(RegionStateObject:IsRegionVisible("Region3")).to.equal(false) end) + + it("should build regions from parts", function() + local InstanceTree = Instance.new("Folder") + InstanceTree.Name = "Regions" + local Region4 = Instance.new("Model", InstanceTree) + Region4.Name = "Region4" + local BasePart = Instance.new("BasePart", Region4) + BasePart.CFrame = CFrame.new(0, 4, 0) + BasePart.Size = Vector3.new(2, 2, 2) + + RegionStateObject:InsertRegionsFromInstance(InstanceTree) + expect(RegionStateObject.Regions["Region4"]).never.to.equal(nil) + expect(RegionStateObject:IsInRegion("Region4", Vector3.new(0, 1, 0))).to.equal(true) + end) end) -end \ No newline at end of file +end From be8c878b34ff67370be64e8f81654587e6af1742 Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:03:09 -0400 Subject: [PATCH 06/12] Update RegionState.spec.lua --- test/State/RegionState.spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/State/RegionState.spec.lua b/test/State/RegionState.spec.lua index 792423d..e314d5f 100644 --- a/test/State/RegionState.spec.lua +++ b/test/State/RegionState.spec.lua @@ -148,13 +148,13 @@ return function() InstanceTree.Name = "Regions" local Region4 = Instance.new("Model", InstanceTree) Region4.Name = "Region4" - local BasePart = Instance.new("BasePart", Region4) + local BasePart = Instance.new("Part", Region4) BasePart.CFrame = CFrame.new(0, 4, 0) BasePart.Size = Vector3.new(2, 2, 2) RegionStateObject:InsertRegionsFromInstance(InstanceTree) - expect(RegionStateObject.Regions["Region4"]).never.to.equal(nil) - expect(RegionStateObject:IsInRegion("Region4", Vector3.new(0, 1, 0))).to.equal(true) + expect(RegionStateObject:IsInRegion("Region4", Vector3.new(0, 1, 0))).to.equal(false) + expect(RegionStateObject:IsInRegion("Region4", Vector3.new(0, 3, 0))).to.equal(true) end) end) end From 8633a2c7977c8d7e69f87721b509c37d90c1c8a8 Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:03:26 -0400 Subject: [PATCH 07/12] Update Types.lua --- src/Types.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Types.lua b/src/Types.lua index 6380137..9bf478b 100644 --- a/src/Types.lua +++ b/src/Types.lua @@ -15,6 +15,7 @@ export type BaseRegionState = { GetCurrentVisibleRegions: (self: BaseRegionState) -> ({string}), IsRegionVisible: (self: BaseRegionState, RegionName: string) -> (boolean), AddRegion: (self: BaseRegionState, RegionName: string, Center: CFrame, Size: Vector3) -> (), + InsertRegionsFromInstance: (self: BaseRegionState, Instances: Instance) -> (), ConnectRegions: (self: BaseRegionState, RegionName1: string, RegionName2: string) -> (), SetVisibleWhenOutsideRegions: (self: BaseRegionState, RegionName: string) -> (), StartUpdating: (self: BaseRegionState) -> (), @@ -99,4 +100,4 @@ export type ModelCulling = { StartModelFlattening: (self: ModelCulling) -> (), } -return true \ No newline at end of file +return true From 34dde437338c3c7f64548fcd732b3b63114cdd94 Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:04:45 -0400 Subject: [PATCH 08/12] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd6c5b2..a019368 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,9 @@ 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 +#### Secondary Region Setup `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. +Depending on use cases, a variety of ways to setup regions is possible. ``` Regions : Instance |- Region1 : Instance From a299d47ee66187413cd8411400739036939d6761 Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:09:50 -0400 Subject: [PATCH 09/12] Update RegionState.lua --- src/State/RegionState.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/State/RegionState.lua b/src/State/RegionState.lua index 4beb0e2..a2fcbc7 100644 --- a/src/State/RegionState.lua +++ b/src/State/RegionState.lua @@ -107,15 +107,14 @@ function RegionState:InsertRegionsFromInstance(Instances: Model | Folder | Insta 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 - self:AddRegion(RegionName, RegionPart.CFrame, RegionPart.Size) + for _, Inst in RegionParent:GetChildren() do + if not Inst:IsA("BasePart") then + continue end + local RegionPart : BasePart = Inst :: BasePart + self:AddRegion(RegionName, RegionPart.CFrame, RegionPart.Size) end end - --// TODO - --// Perform region checks to maybe auto-connect intersecting regions? - --// May not apply to all regions however. end --[[ From 4359bc2f143d0991f3f37cf146afea695833045a Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:13:15 -0400 Subject: [PATCH 10/12] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a019368..a0786a2 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,8 @@ local InRegion = RegionState:IsInRegion("Region1", Vector3.new()) --Bool for if #### Secondary Region Setup `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. -Depending on use cases, a variety of ways to setup regions is possible. +Depending on use cases, a variety of ways to setup regions is possible. One way is by storing additional regions that can allow you to expand a previous region to an easily customizable size. +When rooms are not entire models this may be of use as it allows such behavior. ``` Regions : Instance |- Region1 : Instance From 4bf996002557c7136fc7028aba3a3c75d7a5876b Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:17:34 -0400 Subject: [PATCH 11/12] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a0786a2..b958cbd 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,8 @@ RegionState:SetVisibleWhenOutsideRegions("Region3") --Make it so region 1 can see 2 and 3. --ConnectRegions makes it so both regions can see each other. -RegionStateObject:ConnectRegions("Region1", "Region2") -RegionStateObject:ConnectRegions("Region1", "Region3") +RegionState:ConnectRegions("Region1", "Region2") +RegionState:ConnectRegions("Region1", "Region3") --Set up the models (next section) From 697e069e551f4692ea0e9c5dfb1e3d8cea6f0acb Mon Sep 17 00:00:00 2001 From: Coasterteam <21298244+coasterteam@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:18:11 -0400 Subject: [PATCH 12/12] Update BufferedRegionState.lua getting used to this code style, sorry about all the commits! don't have github desktop connected for this one rn --- src/State/BufferedRegionState.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/State/BufferedRegionState.lua b/src/State/BufferedRegionState.lua index 437493e..704b3c7 100644 --- a/src/State/BufferedRegionState.lua +++ b/src/State/BufferedRegionState.lua @@ -92,6 +92,15 @@ function BufferedRegionState:AddRegion(RegionName: string, Center: CFrame, Size: self.WrappedRegionState:AddRegion(RegionName, Center, Size) 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 BufferedRegionState:InsertRegionsFromInstance(Instances: Model | Folder | Instance): () + self.WrappedRegionState:InsertRegionsFromInstance(Instances) +end + --[[ Marks a region as visible to another. --]] @@ -115,4 +124,4 @@ end -return (BufferedRegionState :: any) :: Types.BufferedRegionState \ No newline at end of file +return (BufferedRegionState :: any) :: Types.BufferedRegionState