@quenty/cframeserializer 4.7.1 → 4.7.2
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 +4 -4
- package/src/Shared/CFrameSerializer.lua +17 -14
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
|
+
## [4.7.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/cframeserializer@4.7.1...@quenty/cframeserializer@4.7.2) (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
|
## [4.7.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/cframeserializer@4.7.0...@quenty/cframeserializer@4.7.1) (2025-03-21)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/cframeserializer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/cframeserializer",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.2",
|
|
4
4
|
"description": "Optimized these functions for speed as well as preserving fidality. In the future, use Roblox's orthogonal angle format.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@quenty/loader": "^10.8.
|
|
32
|
-
"@quenty/math": "^2.7.
|
|
31
|
+
"@quenty/loader": "^10.8.1",
|
|
32
|
+
"@quenty/math": "^2.7.2"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
|
|
35
35
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Optimized these functions for speed as well as preserving fidality.
|
|
3
4
|
In the future, use Roblox's orthogonal angle format.
|
|
@@ -16,24 +17,26 @@ local CFrameSerializer = {}
|
|
|
16
17
|
local PRECISION = 10000
|
|
17
18
|
local MULTIPLIER = 128
|
|
18
19
|
|
|
20
|
+
export type SerializedCFrame = { number }
|
|
21
|
+
|
|
19
22
|
--[=[
|
|
20
23
|
Outputs the rotation
|
|
21
24
|
@param cf CFrame
|
|
22
25
|
@return { number, number, number, number, number, number }
|
|
23
26
|
]=]
|
|
24
|
-
function CFrameSerializer.outputRotationAzure(cf)
|
|
27
|
+
function CFrameSerializer.outputRotationAzure(cf: CFrame): SerializedCFrame
|
|
25
28
|
local lookVector = cf.LookVector
|
|
26
29
|
local azumith = math.atan2(-lookVector.X, -lookVector.Z)
|
|
27
|
-
local ybase = (lookVector.X^2 + lookVector.Z^2)^0.5
|
|
30
|
+
local ybase = (lookVector.X ^ 2 + lookVector.Z ^ 2) ^ 0.5
|
|
28
31
|
local elevation = math.atan2(lookVector.Y, ybase)
|
|
29
32
|
|
|
30
33
|
local withoutRoll = CFrame.Angles(0, azumith, 0) * CFrame.Angles(elevation, 0, 0) + cf.Position
|
|
31
|
-
local _, _, roll = (withoutRoll:Inverse()*cf):ToEulerAnglesXYZ()
|
|
34
|
+
local _, _, roll = (withoutRoll:Inverse() * cf):ToEulerAnglesXYZ()
|
|
32
35
|
|
|
33
36
|
-- Atan2 -> in the range [-pi, pi]
|
|
34
|
-
azumith
|
|
35
|
-
roll
|
|
36
|
-
elevation = Math.round((elevation / (math.pi/2)) * PRECISION)
|
|
37
|
+
azumith = Math.round((azumith / math.pi) * PRECISION)
|
|
38
|
+
roll = Math.round((roll / math.pi) * PRECISION)
|
|
39
|
+
elevation = Math.round((elevation / (math.pi / 2)) * PRECISION)
|
|
37
40
|
|
|
38
41
|
-- Buffer:WriteSigned(22, azumith)
|
|
39
42
|
-- Buffer:WriteSigned(21, roll)
|
|
@@ -43,7 +46,7 @@ function CFrameSerializer.outputRotationAzure(cf)
|
|
|
43
46
|
px = Math.round(px * MULTIPLIER)
|
|
44
47
|
py = Math.round(py * MULTIPLIER)
|
|
45
48
|
pz = Math.round(pz * MULTIPLIER)
|
|
46
|
-
return {px, py, pz, azumith, roll, elevation}
|
|
49
|
+
return { px, py, pz, azumith, roll, elevation }
|
|
47
50
|
end
|
|
48
51
|
|
|
49
52
|
--[=[
|
|
@@ -52,7 +55,7 @@ end
|
|
|
52
55
|
@param cf CFrame
|
|
53
56
|
@return string
|
|
54
57
|
]=]
|
|
55
|
-
function CFrameSerializer.toJSONString(cf)
|
|
58
|
+
function CFrameSerializer.toJSONString(cf: CFrame): string
|
|
56
59
|
return HttpService:JSONEncode(CFrameSerializer.outputRotationAzure(cf))
|
|
57
60
|
end
|
|
58
61
|
|
|
@@ -62,7 +65,7 @@ end
|
|
|
62
65
|
@param data any
|
|
63
66
|
@return boolean
|
|
64
67
|
]=]
|
|
65
|
-
function CFrameSerializer.isRotationAzure(data)
|
|
68
|
+
function CFrameSerializer.isRotationAzure(data: any): boolean
|
|
66
69
|
return type(data) == "table"
|
|
67
70
|
and type(data[1]) == "number"
|
|
68
71
|
and type(data[2]) == "number"
|
|
@@ -78,7 +81,7 @@ end
|
|
|
78
81
|
@param str string
|
|
79
82
|
@return CFrame
|
|
80
83
|
]=]
|
|
81
|
-
function CFrameSerializer.fromJSONString(str)
|
|
84
|
+
function CFrameSerializer.fromJSONString(str: string): CFrame?
|
|
82
85
|
local decoded = HttpService:JSONDecode(str)
|
|
83
86
|
if CFrameSerializer.isRotationAzure(decoded) then
|
|
84
87
|
return CFrameSerializer.readRotationAzure(decoded)
|
|
@@ -92,17 +95,17 @@ end
|
|
|
92
95
|
@param data { number, number, number, number, number, number }
|
|
93
96
|
@return Vector3
|
|
94
97
|
]=]
|
|
95
|
-
function CFrameSerializer.readPosition(data)
|
|
96
|
-
return Vector3.new(data[1]/MULTIPLIER, data[2]/MULTIPLIER, data[3]/MULTIPLIER)
|
|
98
|
+
function CFrameSerializer.readPosition(data: SerializedCFrame): Vector3
|
|
99
|
+
return Vector3.new(data[1] / MULTIPLIER, data[2] / MULTIPLIER, data[3] / MULTIPLIER)
|
|
97
100
|
end
|
|
98
101
|
|
|
99
102
|
--[=[
|
|
100
103
|
Returns the CFrame
|
|
101
104
|
|
|
102
105
|
@param data { number, number, number, number, number, number }
|
|
103
|
-
@return
|
|
106
|
+
@return CFrame
|
|
104
107
|
]=]
|
|
105
|
-
function CFrameSerializer.readRotationAzure(data)
|
|
108
|
+
function CFrameSerializer.readRotationAzure(data: SerializedCFrame): CFrame
|
|
106
109
|
local azumith = data[4]
|
|
107
110
|
local roll = data[5] -- Buffer:ReadSigned(21)
|
|
108
111
|
local elevation = data[6] -- Buffer:ReadSigned(21)
|