Advertisement
KrYn0MoRe

animator converter v2

Sep 6th, 2022 (edited)
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.56 KB | None | 0 0
  1. function round(num, idp)
  2.     local mult = 10^(idp or 3)
  3.     return math.floor(num * mult + 0.5) / mult
  4. end
  5.  
  6. function ConvertCFrame(cf, degrees)
  7.     local str = ""
  8.     if round(cf.X) ~= 0 or round(cf.Y) ~= 0 or round(cf.Z) ~= 0 then
  9.         str = ("%s,%s,%s,"):format(round(cf.X), round(cf.Y), round(cf.Z))
  10.     else
  11.         str = "0,0,0,"
  12.     end
  13.     local x, y, z = cf:toEulerAnglesXYZ()
  14.     x, y, z = round(x), round(y), round(z)
  15.    
  16.     --
  17.     if x ~= 0 or y ~= 0 or z ~= 0 then
  18.         local function AddAngle(n, comma)
  19.             str = str..(n == 0 and n or round(math.deg(n))) .. ','
  20.         end
  21.         AddAngle(x, true)
  22.         AddAngle(y, true)
  23.         AddAngle(z)
  24.     end
  25.     --
  26.    
  27.     return str
  28. end
  29.  
  30. function SequenceToModule(sequence,p)
  31.     if sequence and sequence:IsA("KeyframeSequence") then
  32.         local source = "\n" .. sequence.Name.."={"
  33.  
  34.         local function AddLine(text, depth)
  35.             source = source.."\n"..string.rep(" ", depth or 0)..text
  36.             --source = source.."\n"..text
  37.         end
  38.  
  39.         AddLine("Properties={", 1)
  40.         AddLine("Looping="..tostring(sequence.Loop)..",", 2)
  41.         AddLine("Priority='"..tostring(sequence.Priority.Name).."'", 2)
  42.         AddLine("},", 1)
  43.  
  44.         AddLine("Keyframes={", 1)
  45.  
  46.         local function GetPoses(start, depth)
  47.             local depth = depth or 2
  48.  
  49.             local hidden --= (start.Name == "HumanoidRootPart")
  50.             if hidden then
  51.                 depth = depth - 1
  52.             end
  53.  
  54.             if start:IsA("Pose") and not hidden then
  55.                 AddLine('["'..start.Name..'"]={', depth)
  56.  
  57.                 if start.Weight > 0 and ConvertCFrame(start.CFrame, true) then
  58.                     AddLine("CF={"..ConvertCFrame(start.CFrame, true).."},", depth + 1)
  59.                     if start.EasingDirection.Name ~= Enum.EasingDirection.In.Name then
  60.                         AddLine("ED='"..start.EasingDirection.Name.."',", depth + 1)
  61.                     end
  62.                     if start.EasingStyle.Name ~= Enum.EasingStyle.Linear.Name then
  63.                         AddLine("ES='"..start.EasingStyle.Name.."',", depth + 1)
  64.                     end
  65.                 end
  66.             elseif start:IsA("KeyframeMarker") then
  67.                 AddLine('["'..start.Name..'"]={', depth)
  68.                 AddLine("Marker="..tostring(true), depth + 1)
  69.             else
  70.                 hidden = true
  71.             end
  72.            
  73.             for _, v in pairs(start:GetChildren()) do
  74.                 GetPoses(v, depth + 1)
  75.             end
  76.            
  77.             if not hidden then
  78.                 AddLine('},', depth)
  79.             end
  80.         end
  81.        
  82.         local added_time = {}
  83.        
  84.         for _, v in pairs(sequence:GetChildren()) do
  85.             if v:IsA("Keyframe") then
  86.                 added_time[v.Time] = 1
  87.                 AddLine("['"..round(v.Time).."']={", 2)
  88.                 if v.Name ~= 'Keyframe' then
  89.                     AddLine("Name='"..v.Name.."',", 3)
  90.                 end
  91.                 GetPoses(v)
  92.                 AddLine("},", 2)
  93.             end
  94.         end
  95.  
  96.         AddLine("}\n},", 1)
  97.  
  98.         return source
  99.     end
  100. end
  101.  
  102. local t = ''
  103.  
  104. workspace.anims.Folder:ClearAllChildren()
  105.  
  106. for i,v in pairs(workspace.anims:GetChildren()) do
  107.     local s = SequenceToModule(v,v.Parent.Folder)
  108.     if s then
  109.         t = t .. s
  110.     end
  111. end
  112.  
  113. t = 'return {' .. t .. '}'
  114.  
  115. function add(text,par,asd)
  116.     local modules = {}
  117.     local t = text
  118.     if asd then
  119.         print(#t)
  120.     end
  121.     if #t < 200000 then
  122.         local sourcefile = Instance.new("ModuleScript", par or workspace.anims.Folder)
  123.         sourcefile.Source = t
  124.         sourcefile.Name = "Source"
  125.        
  126.         table.insert(modules,sourcefile)
  127.     else
  128.         local p = 1
  129.         local c = 1
  130.         repeat
  131.             local sourcefile = Instance.new("ModuleScript", par or workspace.anims.Folder)
  132.             sourcefile.Source = t:sub(p,p+199998)
  133.             sourcefile.Name = "Source" .. c
  134.  
  135.             table.insert(modules,sourcefile)
  136.             p += 199999
  137.             c += 1
  138.             wait(0.1)
  139.         until p > #t
  140.     end
  141.     warn(#t)
  142.     return modules
  143. end
  144.  
  145. local mods = add(t)
  146. t = ''
  147. wait(0.1)
  148. for i,v in pairs(mods) do
  149.     local data = require(v)
  150.     t = t .. game:GetService("HttpService"):JSONEncode(data)
  151.     v:Destroy()
  152.     wait(0.1)
  153. end
  154. add(t,nil,true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement