@quenty/getgroundplane 10.8.0 → 10.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +3 -3
- package/src/Shared/batchRaycast.lua +8 -6
- package/src/Shared/getGroundPlane.lua +43 -42
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.8.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/getgroundplane@10.8.0...@quenty/getgroundplane@10.8.1) (2025-04-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [10.8.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/getgroundplane@10.7.1...@quenty/getgroundplane@10.8.0) (2025-02-18)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/getgroundplane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/getgroundplane",
|
|
3
|
-
"version": "10.8.
|
|
3
|
+
"version": "10.8.1",
|
|
4
4
|
"description": "Function that uses raycasting to determine the groundplane in Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/loader": "^10.8.
|
|
28
|
+
"@quenty/loader": "^10.8.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@quenty/loader": "file:../loader"
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
|
|
37
37
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Batch raycast utility function
|
|
3
4
|
@private
|
|
@@ -5,10 +6,11 @@
|
|
|
5
6
|
]=]
|
|
6
7
|
|
|
7
8
|
local function batchRaycast(
|
|
8
|
-
originList, directionList,
|
|
9
|
-
ignoreListWorkingEnvironment,
|
|
10
|
-
ignoreFunc, keepIgnoreListChanges
|
|
11
|
-
)
|
|
9
|
+
originList: {Vector3}, directionList: { Vector3 },
|
|
10
|
+
ignoreListWorkingEnvironment: { Instance },
|
|
11
|
+
ignoreFunc: (Instance) -> boolean, keepIgnoreListChanges: boolean
|
|
12
|
+
): { RaycastResult }
|
|
13
|
+
|
|
12
14
|
local resultList = {}
|
|
13
15
|
local initialIgnoreListLength = #ignoreListWorkingEnvironment
|
|
14
16
|
|
|
@@ -19,7 +21,7 @@ local function batchRaycast(
|
|
|
19
21
|
for i in next, originList do
|
|
20
22
|
local origin = originList[i]
|
|
21
23
|
local direction = directionList[i]
|
|
22
|
-
local target--we'll use these later maybe
|
|
24
|
+
local target --we'll use these later maybe
|
|
23
25
|
local offset
|
|
24
26
|
while true do
|
|
25
27
|
local result = workspace:Raycast(origin, direction, params)
|
|
@@ -29,7 +31,7 @@ local function batchRaycast(
|
|
|
29
31
|
|
|
30
32
|
if not target then--initialize these
|
|
31
33
|
target = origin + direction
|
|
32
|
-
offset = 1e-3/direction.
|
|
34
|
+
offset = 1e-3 / direction.Magnitude * direction
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
origin = result.Position - offset
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Function that uses raycasting to determine the groundplane in Roblox.
|
|
3
4
|
@class getGroundPlane
|
|
@@ -7,7 +8,7 @@ local require = require(script.Parent.loader).load(script)
|
|
|
7
8
|
|
|
8
9
|
local batchRaycast = require("batchRaycast")
|
|
9
10
|
|
|
10
|
-
local function resolvePlane(basis, points, norms)
|
|
11
|
+
local function resolvePlane(basis: CFrame, points: { Vector3 }, norms: { Vector3 }): (Vector3?, Vector3?)
|
|
11
12
|
local n = #points
|
|
12
13
|
|
|
13
14
|
--[[
|
|
@@ -22,54 +23,55 @@ local function resolvePlane(basis, points, norms)
|
|
|
22
23
|
local xy, yz, yc = 0, 0, 0
|
|
23
24
|
|
|
24
25
|
for i = 1, n do
|
|
25
|
-
local p = basis:
|
|
26
|
-
local x = p.
|
|
27
|
-
local y = p.
|
|
28
|
-
local z = p.
|
|
29
|
-
xx = xx + x*x
|
|
30
|
-
xz = xz + x*z
|
|
26
|
+
local p = basis:PointToObjectSpace(points[i])
|
|
27
|
+
local x = p.X
|
|
28
|
+
local y = p.Y
|
|
29
|
+
local z = p.Z
|
|
30
|
+
xx = xx + x * x
|
|
31
|
+
xz = xz + x * z
|
|
31
32
|
xc = xc + x
|
|
32
|
-
zz = zz + z*z
|
|
33
|
+
zz = zz + z * z
|
|
33
34
|
zc = zc + z
|
|
34
35
|
cc = cc + 1
|
|
35
|
-
xy = xy + x*y
|
|
36
|
-
yz = yz + y*z
|
|
36
|
+
xy = xy + x * y
|
|
37
|
+
yz = yz + y * z
|
|
37
38
|
yc = yc + y
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
local det = cc*xx*zz - cc*xz*xz + 2*xc*xz*zc - xx*zc*zc - xc*xc*zz
|
|
41
|
-
if det*det > 1e-12 then
|
|
42
|
-
local u = (cc*xy*zz - cc*xz*yz + xz*yc*zc + xc*yz*zc - xy*zc*zc - xc*yc*zz)/det
|
|
43
|
-
local v = (cc*xx*yz - cc*xy*xz + xc*xz*yc - xc*xc*yz + xc*xy*zc - xx*yc*zc)/det
|
|
44
|
-
local h = (xc*xz*yz - xz*xz*yc + xy*xz*zc - xx*yz*zc - xc*xy*zz + xx*yc*zz)/det
|
|
41
|
+
local det = cc * xx * zz - cc * xz * xz + 2 * xc * xz * zc - xx * zc * zc - xc * xc * zz
|
|
42
|
+
if det * det > 1e-12 then
|
|
43
|
+
local u = (cc * xy * zz - cc * xz * yz + xz * yc * zc + xc * yz * zc - xy * zc * zc - xc * yc * zz) / det
|
|
44
|
+
local v = (cc * xx * yz - cc * xy * xz + xc * xz * yc - xc * xc * yz + xc * xy * zc - xx * yc * zc) / det
|
|
45
|
+
local h = (xc * xz * yz - xz * xz * yc + xy * xz * zc - xx * yz * zc - xc * xy * zz + xx * yc * zz) / det
|
|
45
46
|
local pos = Vector3.new(0, h, 0)
|
|
46
|
-
local nrm = Vector3.new(-u, 1, -v).
|
|
47
|
-
return basis*pos, basis:
|
|
47
|
+
local nrm = Vector3.new(-u, 1, -v).Unit
|
|
48
|
+
return basis * pos, basis:VectorToWorldSpace(nrm), h, u, v
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
local uSum = 0
|
|
51
52
|
local vSum = 0
|
|
52
53
|
for i = 1, n do
|
|
53
|
-
local norm = basis:
|
|
54
|
-
local x = norm.
|
|
55
|
-
local y = norm.
|
|
56
|
-
local z = norm.
|
|
57
|
-
uSum = uSum - x/y
|
|
58
|
-
vSum = vSum - z/y
|
|
54
|
+
local norm = basis:VectorToObjectSpace(norms[i])
|
|
55
|
+
local x = norm.X
|
|
56
|
+
local y = norm.Y
|
|
57
|
+
local z = norm.Z
|
|
58
|
+
uSum = uSum - x / y
|
|
59
|
+
vSum = vSum - z / y
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
if cc ~= 0 then
|
|
62
|
-
local u = uSum/cc
|
|
63
|
-
local v = vSum/cc
|
|
64
|
-
local h = (yc - u*xc - v*zc)/cc
|
|
63
|
+
local u = uSum / cc
|
|
64
|
+
local v = vSum / cc
|
|
65
|
+
local h = (yc - u * xc - v * zc) / cc
|
|
65
66
|
local pos = Vector3.new(0, h, 0)
|
|
66
|
-
local nrm = Vector3.new(-u, 1, -v).
|
|
67
|
-
return basis*pos, basis:
|
|
67
|
+
local nrm = Vector3.new(-u, 1, -v).Unit
|
|
68
|
+
return basis * pos, basis:VectorToWorldSpace(nrm), h, u, v
|
|
68
69
|
end
|
|
69
|
-
end
|
|
70
70
|
|
|
71
|
+
return nil, nil
|
|
72
|
+
end
|
|
71
73
|
|
|
72
|
-
local goldenAngle = (3 - 5^0.5)*math.pi
|
|
74
|
+
local goldenAngle = (3 - 5 ^ 0.5) * math.pi
|
|
73
75
|
|
|
74
76
|
--[=[
|
|
75
77
|
Uses -y as the direction
|
|
@@ -92,34 +94,33 @@ local goldenAngle = (3 - 5^0.5)*math.pi
|
|
|
92
94
|
@within getGroundPlane
|
|
93
95
|
]=]
|
|
94
96
|
local function getGroundPlane(
|
|
95
|
-
basis, radius, length, sampleCount,
|
|
96
|
-
ignoreList, ignoreFunc
|
|
97
|
-
)
|
|
98
|
-
debug.profilebegin("
|
|
97
|
+
basis: CFrame, radius: number, length: number, sampleCount: number,
|
|
98
|
+
ignoreList: { Instance }, ignoreFunc: (Instance) -> boolean
|
|
99
|
+
): (Vector3?, Vector3?)
|
|
100
|
+
debug.profilebegin("createRayData")
|
|
101
|
+
|
|
99
102
|
local originList = table.create(sampleCount)
|
|
100
103
|
local directionList = table.create(sampleCount)
|
|
101
104
|
|
|
102
105
|
local d = basis:VectorToWorldSpace(Vector3.new(0, -length, 0))
|
|
103
106
|
|
|
104
107
|
for i = 1, sampleCount do
|
|
105
|
-
local r = radius*math.sqrt((i - 1)/sampleCount)
|
|
106
|
-
local x = r*math.cos(goldenAngle*i)
|
|
107
|
-
local z = r*math.sin(goldenAngle*i)
|
|
108
|
+
local r = radius * math.sqrt((i - 1) / sampleCount)
|
|
109
|
+
local x = r * math.cos(goldenAngle * i)
|
|
110
|
+
local z = r * math.sin(goldenAngle * i)
|
|
108
111
|
local o = basis:PointToWorldSpace(Vector3.new(x, 0, z))
|
|
109
112
|
|
|
110
113
|
originList[i] = o
|
|
111
114
|
directionList[i] = d
|
|
112
115
|
end
|
|
116
|
+
|
|
113
117
|
debug.profileend()
|
|
114
118
|
|
|
115
119
|
debug.profilebegin("batchRaycast")
|
|
116
|
-
local resultList = batchRaycast(
|
|
117
|
-
originList, directionList,
|
|
118
|
-
ignoreList, ignoreFunc, false
|
|
119
|
-
)
|
|
120
|
+
local resultList = batchRaycast(originList, directionList, ignoreList, ignoreFunc, false)
|
|
120
121
|
debug.profileend()
|
|
121
122
|
|
|
122
|
-
debug.profilebegin("
|
|
123
|
+
debug.profilebegin("separateRaycastResults")
|
|
123
124
|
local n = 0
|
|
124
125
|
local poses = table.create(sampleCount)
|
|
125
126
|
local norms = table.create(sampleCount)
|