@quenty/cframeserializer 4.0.0 → 4.0.1-canary.461.ef0ff45.0
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/LICENSE.md +1 -1
- package/package.json +6 -2
- package/src/Shared/CFrameSerializer.lua +50 -36
- package/src/node_modules.project.json +7 -0
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.0.1-canary.461.ef0ff45.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/cframeserializer@4.0.0...@quenty/cframeserializer@4.0.1-canary.461.ef0ff45.0) (2024-04-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Update cframe serialize to handle NaN values in JSON ([5b36417](https://github.com/Quenty/NevermoreEngine/commit/5b36417a9fb6256a79118897364febd4dabb0d1e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [4.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/cframeserializer@3.1.0...@quenty/cframeserializer@4.0.0) (2022-09-27)
|
|
7
18
|
|
|
8
19
|
|
package/LICENSE.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/cframeserializer",
|
|
3
|
-
"version": "4.0.0",
|
|
3
|
+
"version": "4.0.1-canary.461.ef0ff45.0",
|
|
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",
|
|
@@ -27,5 +27,9 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@quenty/loader": "10.1.1-canary.461.ef0ff45.0",
|
|
32
|
+
"@quenty/math": "2.6.0"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "ef0ff45686a7f2f93156fc1bd2b459e55076b07e"
|
|
31
35
|
}
|
|
@@ -7,18 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
local HttpService = game:GetService("HttpService")
|
|
9
9
|
|
|
10
|
-
local
|
|
10
|
+
local require = require(script.Parent.loader).load(script)
|
|
11
11
|
|
|
12
|
-
local
|
|
13
|
-
local floor = math.floor
|
|
14
|
-
local PI = math.pi
|
|
15
|
-
local Angles = CFrame.Angles
|
|
12
|
+
local Math = require("Math")
|
|
16
13
|
|
|
17
|
-
local
|
|
18
|
-
return floor(n + 0.5)
|
|
19
|
-
end
|
|
14
|
+
local CFrameSerializer = {}
|
|
20
15
|
|
|
21
16
|
local PRECISION = 10000
|
|
17
|
+
local MULTIPLIER = 128
|
|
22
18
|
|
|
23
19
|
--[=[
|
|
24
20
|
Outputs the rotation
|
|
@@ -27,26 +23,26 @@ local PRECISION = 10000
|
|
|
27
23
|
]=]
|
|
28
24
|
function CFrameSerializer.outputRotationAzure(cf)
|
|
29
25
|
local lookVector = cf.LookVector
|
|
30
|
-
local azumith = atan2(-lookVector.X, -lookVector.Z)
|
|
26
|
+
local azumith = math.atan2(-lookVector.X, -lookVector.Z)
|
|
31
27
|
local ybase = (lookVector.X^2 + lookVector.Z^2)^0.5
|
|
32
|
-
local elevation = atan2(lookVector.Y, ybase)
|
|
28
|
+
local elevation = math.atan2(lookVector.Y, ybase)
|
|
33
29
|
|
|
34
|
-
local withoutRoll = Angles(0, azumith, 0) * Angles(elevation, 0, 0) + cf.Position
|
|
30
|
+
local withoutRoll = CFrame.Angles(0, azumith, 0) * CFrame.Angles(elevation, 0, 0) + cf.Position
|
|
35
31
|
local _, _, roll = (withoutRoll:Inverse()*cf):ToEulerAnglesXYZ()
|
|
36
32
|
|
|
37
33
|
-- Atan2 -> in the range [-pi, pi]
|
|
38
|
-
azumith = round((azumith /
|
|
39
|
-
roll = round((roll /
|
|
40
|
-
elevation = round((elevation / (
|
|
41
|
-
|
|
42
|
-
--
|
|
43
|
-
Buffer:WriteSigned(21, roll)
|
|
44
|
-
Buffer:WriteSigned(21, elevation)
|
|
34
|
+
azumith = Math.round((azumith / math.pi ) * PRECISION)
|
|
35
|
+
roll = Math.round((roll / math.pi ) * PRECISION)
|
|
36
|
+
elevation = Math.round((elevation / (math.pi/2)) * PRECISION)
|
|
37
|
+
|
|
38
|
+
-- Buffer:WriteSigned(22, azumith)
|
|
39
|
+
-- Buffer:WriteSigned(21, roll)
|
|
40
|
+
-- Buffer:WriteSigned(21, elevation)
|
|
45
41
|
|
|
46
42
|
local px, py, pz = cf.X, cf.Y, cf.Z
|
|
47
|
-
px = round(px *
|
|
48
|
-
py = round(py *
|
|
49
|
-
pz = round(pz *
|
|
43
|
+
px = Math.round(px * MULTIPLIER)
|
|
44
|
+
py = Math.round(py * MULTIPLIER)
|
|
45
|
+
pz = Math.round(pz * MULTIPLIER)
|
|
50
46
|
return {px, py, pz, azumith, roll, elevation}
|
|
51
47
|
end
|
|
52
48
|
|
|
@@ -60,6 +56,22 @@ function CFrameSerializer.toJSONString(cf)
|
|
|
60
56
|
return HttpService:JSONEncode(CFrameSerializer.outputRotationAzure(cf))
|
|
61
57
|
end
|
|
62
58
|
|
|
59
|
+
--[=[
|
|
60
|
+
Returnst true if it's a table encoded cframe
|
|
61
|
+
|
|
62
|
+
@param data any
|
|
63
|
+
@return boolean
|
|
64
|
+
]=]
|
|
65
|
+
function CFrameSerializer.isRotationAzure(data)
|
|
66
|
+
return type(data) == "table"
|
|
67
|
+
and type(data[1]) == "number"
|
|
68
|
+
and type(data[2]) == "number"
|
|
69
|
+
and type(data[3]) == "number"
|
|
70
|
+
and type(data[4]) == "number"
|
|
71
|
+
and type(data[5]) == "number"
|
|
72
|
+
and type(data[6]) == "number"
|
|
73
|
+
end
|
|
74
|
+
|
|
63
75
|
--[=[
|
|
64
76
|
Decodes a CFrame from JSON. For serialization in attributes.
|
|
65
77
|
|
|
@@ -67,7 +79,12 @@ end
|
|
|
67
79
|
@return CFrame
|
|
68
80
|
]=]
|
|
69
81
|
function CFrameSerializer.fromJSONString(str)
|
|
70
|
-
|
|
82
|
+
local decoded = HttpService:JSONDecode(str)
|
|
83
|
+
if CFrameSerializer.isRotationAzure(decoded) then
|
|
84
|
+
return CFrameSerializer.readRotationAzure(decoded)
|
|
85
|
+
else
|
|
86
|
+
return nil
|
|
87
|
+
end
|
|
71
88
|
end
|
|
72
89
|
|
|
73
90
|
--[=[
|
|
@@ -76,29 +93,26 @@ end
|
|
|
76
93
|
@return Vector3
|
|
77
94
|
]=]
|
|
78
95
|
function CFrameSerializer.readPosition(data)
|
|
79
|
-
return Vector3.new(data[1]/
|
|
96
|
+
return Vector3.new(data[1]/MULTIPLIER, data[2]/MULTIPLIER, data[3]/MULTIPLIER)
|
|
80
97
|
end
|
|
81
98
|
|
|
82
99
|
--[=[
|
|
83
100
|
Returns the CFrame
|
|
101
|
+
|
|
84
102
|
@param data { number, number, number, number, number, number }
|
|
85
103
|
@return Vector3
|
|
86
104
|
]=]
|
|
87
105
|
function CFrameSerializer.readRotationAzure(data)
|
|
88
106
|
local azumith = data[4]
|
|
89
|
-
local roll = data[5] --Buffer:ReadSigned(21)
|
|
90
|
-
local elevation = data[6] --Buffer:ReadSigned(21)
|
|
91
|
-
|
|
92
|
-
azumith =
|
|
93
|
-
roll =
|
|
94
|
-
elevation = (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
--rot = rot * Angles(0, 0, roll)
|
|
99
|
-
local rot = Angles(0, azumith, 0) * Angles(elevation, 0, roll)
|
|
100
|
-
--
|
|
101
|
-
return rot + Vector3.new(data[1]/128, data[2]/128, data[3]/128) --, azumith, roll, elevation}
|
|
107
|
+
local roll = data[5] -- Buffer:ReadSigned(21)
|
|
108
|
+
local elevation = data[6] -- Buffer:ReadSigned(21)
|
|
109
|
+
|
|
110
|
+
azumith = math.pi * (azumith/PRECISION)
|
|
111
|
+
roll = math.pi * (roll/PRECISION)
|
|
112
|
+
elevation = (math.pi/2) * (elevation/PRECISION)
|
|
113
|
+
|
|
114
|
+
local cframe = CFrame.Angles(0, azumith, 0) * CFrame.Angles(elevation, 0, roll)
|
|
115
|
+
return cframe + Vector3.new(data[1]/MULTIPLIER, data[2]/MULTIPLIER, data[3]/MULTIPLIER) --, azumith, roll, elevation}
|
|
102
116
|
end
|
|
103
117
|
|
|
104
118
|
return CFrameSerializer
|