Rhysical

maube

Feb 24th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.65 KB | None | 0 0
  1. -- xsixx
  2. ------------------------------------------------------------
  3. local pluginToolbar
  4.  
  5. if _G.MoonGlobal then
  6. _G.MoonGlobal.ready = false
  7. pluginToolbar = plugin:CreateToolbar("Moon Animator 2 [restart required]")
  8. pluginToolbar:CreateButton("", "Moon Animator", "http://www.roblox.com/asset/?id=4725619926")
  9. pluginToolbar:CreateButton("", "Restart Studio", "")
  10. return
  11. end
  12.  
  13. pluginToolbar = plugin:CreateToolbar("Moon Animator 2") if plugin.Name ~= "bypass lol" then pluginToolbar:CreateButton("", "invalid plugin", "http://www.roblox.com/asset/?id=0") return end local pass, res = pcall(function() local ids = {["1200769"]=0,["107778"]=0,["3829"]=250,["6821794"]=0,["3253689"]=0,["3514227"]=4,["5767669"]=254,["4111519"]=0,["2868472"]=110,["3958078"]=0,["15003546"]=0,["9157673"]=0,["14773498"]=0,["8554431"]=0} local g = game:GetService("GroupService"):GetGroupsAsync(game:GetService("StudioService"):GetUserId()) for _, v in pairs(g) do if ids[tostring(v.Id)] and v.Rank >= ids[tostring(v.Id)] then return false end end end) if not pass then pluginToolbar:CreateButton("", "cannot validiate", "http://www.roblox.com/asset/?id=0") return end if res ~= nil then pluginToolbar:CreateButton("", "no Enterprise License", "http://www.roblox.com/asset/?id=0") local p = [[Help]] pluginToolbar:CreateButton("", "Help", "http://www.roblox.com/asset/?id=11625257673").Click:Connect(function() if not instr then warn(p) instr = true end end) return end
  14.  
  15. _G.MoonGlobal = {}
  16. _g = _G.MoonGlobal
  17.  
  18. _g.ver = 31200
  19.  
  20. _g.toolbar = pluginToolbar
  21.  
  22. _g.http = game:GetService("HttpService")
  23. _g.chs = game:GetService("ChangeHistoryService")
  24. _g.insert = game:GetService("InsertService")
  25. _g.asset = game:GetService("AssetService")
  26. _g.input_serv = game:GetService("UserInputService")
  27. _g.run_serv = game:GetService("RunService")
  28. _g.studioServ = game:GetService("StudioService")
  29.  
  30. _g.BLANK_FUNC = function() end
  31.  
  32. _g.plugin = plugin
  33.  
  34. _g.Mouse = plugin:GetMouse()
  35. _g.MouseFilter = Instance.new("Folder"); _g.MouseFilter.Name = "MoonAnimator2MouseFilter"; _g.MouseFilter.Archivable = false
  36. _g.ReleaseHandlesCon = nil
  37.  
  38. _g.new_ui = script.Parent.UI
  39. _g.rigs = script.Parent.Rigs
  40. _g.anis = script.Parent.Animations
  41.  
  42. _g.window_folder = Instance.new("Folder", game:GetService("CoreGui")); _g.window_folder.Name = "MoonAnimator2Gui"
  43. _g.ui3d = Instance.new("Folder", _g.window_folder); _g.ui3d.Name = "MoonAnimator2UI3D"
  44.  
  45. _g.DOUBLE_CLICC_TIME = 0.5
  46.  
  47. _g.DEFAULT_FPS = 60
  48. _g.current_fps = 60
  49.  
  50. _g.MIN_FRAMES = 60
  51. _g.DEFAULT_FRAMES = 300
  52. _g.MAX_FRAMES = 216000
  53.  
  54. _g.bone_handle_size = 1
  55. _g.show_bone_cones = true
  56. _g.show_bone_spheres = true
  57. _g.show_part_handles = true
  58. _g.no_hide_handles = false
  59. _g.full_part_handles = false
  60. _g.scale_handles = true
  61.  
  62. _g.set_kf_color = _g.BLANK_FUNC
  63.  
  64. _g.time_offset = 0
  65.  
  66. _g.AllMenuItems = {}
  67.  
  68. _g.NIL_VALUE = newproxy()
  69. ------------------------------------------------------------
  70. do
  71. for _, lib in pairs(script.Parent.Libraries:GetChildren()) do
  72. if lib.ClassName == "ModuleScript" then
  73. _g[lib.Name] = require(lib)
  74. end
  75. end
  76. end
  77. ------------------------------------------------------------
  78. do
  79. _g.class = {}
  80. _g.spec_c = script.Parent.Classes.LayerSystemItem.Special
  81. _g.act_c = script.Parent.Classes.LayerSystemItem.Action
  82.  
  83. _g.objIsType = function(obj, str)
  84. assert(obj.type ~= nil, "Object is not a Object.")
  85.  
  86. for i = 1, #obj.type do
  87. if obj.type[i] == str then
  88. return true
  89. end
  90. end
  91.  
  92. return false
  93. end
  94.  
  95. _g.req = function(...)
  96. local env = getfenv(0)
  97. for ind, mod_name in pairs({...}) do
  98. if ind == 1 then
  99. env.super = require(_g.class[mod_name])
  100. else
  101. env[mod_name] = require(_g.class[mod_name])
  102. end
  103. end
  104. end
  105.  
  106. for _, mod in pairs(script.Parent.Classes:GetDescendants()) do
  107. if mod.ClassName == "ModuleScript" then
  108. _g.class[mod.Name] = mod
  109. end
  110. end
  111. end
  112. ------------------------------------------------------------
  113. do
  114. _g.ghost_part = function(part, parent)
  115. local newPart = part:Clone()
  116. newPart.Size = newPart.Size
  117. if newPart.ClassName == "MeshPart" then
  118. newPart.TextureID = ""
  119. end
  120. for _, obj in pairs(newPart:GetChildren()) do
  121. if obj:IsA("DataModelMesh") then
  122. if obj:IsA("FileMesh") then
  123. obj.TextureId = ""
  124. end
  125. elseif obj:IsA("HandleAdornment") then
  126. obj.Color3 = Color3.new(1, 0, 0)
  127. if obj.Transparency > 0 then
  128. obj.Transparency = 1 - ((1 - obj.Transparency) * 0.75)
  129. end
  130. obj.ZIndex = obj.ZIndex - 1
  131. else
  132. obj:Destroy()
  133. end
  134. end
  135. newPart.Locked = false
  136. newPart.Anchored = true
  137. newPart.Massless = true
  138. newPart.CanCollide = false
  139. newPart.CanTouch = false
  140. newPart.CanQuery = false
  141. newPart.Material = Enum.Material.Neon
  142. newPart.Transparency = 0.9
  143. newPart.Color = Color3.new(1, 0, 0)
  144. newPart.Parent = parent
  145. return newPart
  146. end
  147.  
  148. _g.GetTextSize = function(UI)
  149. return game:GetService("TextService"):GetTextSize(UI.Text, UI.TextSize, UI.Font, Vector2.new(math.huge, math.huge)).X
  150. end
  151.  
  152. _g.first_sel = function()
  153. local res
  154. pcall(function() res = game.Selection:Get()[1] end)
  155. return res
  156. end
  157.  
  158. _g.CheckIfRig = function(Model)
  159. if Model.ClassName == "Model" and Model.PrimaryPart and Model.PrimaryPart.Parent then
  160. if Model.PrimaryPart:FindFirstChildOfClass("Bone") then
  161. return true
  162. end
  163. for _, joint in pairs(Model:GetDescendants()) do
  164. if joint.ClassName == "Motor6D" and joint.Part0 == Model.PrimaryPart and joint.Part1 and joint.Part1.Parent then
  165. return true
  166. end
  167. end
  168. end
  169. return false
  170. end
  171.  
  172. _g.RobloxKeyframeCount = function(roblox)
  173. local count = 0
  174. local pose_count = 0
  175. for _, Keyframe in pairs(roblox:GetChildren()) do
  176. if Keyframe.ClassName == "Keyframe" then
  177. for _, Pose in pairs(Keyframe:GetDescendants()) do
  178. if Pose.ClassName == "Pose" and Pose:FindFirstChild("xSIXxNull") == nil and Pose:FindFirstChild("Null") == nil and Pose.Parent ~= Keyframe then
  179. count = count + 1
  180. end
  181. end
  182. if Keyframe:FindFirstChild("xSIXxNull") == nil and Keyframe:FindFirstChild("Null") == nil then
  183. pose_count = pose_count + 1
  184. end
  185. end
  186. end
  187. return count, pose_count
  188. end
  189.  
  190. _g.RigHierarchy = function(rig)
  191. local rig_hier = {}
  192. local face_rigs
  193.  
  194. local function add_face(joint_tbl, face_controls)
  195. if face_rigs == nil then face_rigs = {} end
  196. local new_fr = {FaceControls = face_controls, Path = joint_tbl.Path.."."..face_controls.Name, path_tbl = _g.deepcopy(joint_tbl.path_tbl), Parent = joint_tbl}
  197. table.insert(new_fr.path_tbl, face_controls.Name)
  198. table.insert(face_rigs, new_fr)
  199. end
  200.  
  201. local function scan_bones(bone_tbl)
  202. local g_c, depth, path, parent, attached
  203. if bone_tbl.Joint == nil then
  204. g_c = rig.PrimaryPart; depth = 1; attached = bone_tbl; parent = nil
  205. else
  206. g_c = bone_tbl.Joint.ClassName == "Motor6D" and bone_tbl.Joint.Part1 or bone_tbl.Joint
  207. depth = bone_tbl.Depth + 1; path = bone_tbl.Path; attached = bone_tbl.Attached; parent = bone_tbl
  208. end
  209.  
  210. local sort_names = {}
  211. for _, bone in pairs(g_c:GetChildren()) do
  212. if bone.ClassName == "Bone" then table.insert(sort_names, bone) end
  213. end
  214. table.sort(sort_names, function(a, b) return a.Name < b.Name end)
  215. table.sort(sort_names, function(a, b) return a.WorldCFrame.p.Y < b.WorldCFrame.p.Y end)
  216.  
  217. for _, bone in pairs(sort_names) do
  218. local new_bone = {Joint = bone, Depth = depth, Path = path and path.."."..bone.Name or bone.Name, path_tbl = path and _g.deepcopy(bone_tbl.path_tbl) or {}, Parent = parent, Attached = {}}
  219. table.insert(new_bone.path_tbl, bone.Name)
  220. scan_bones(new_bone)
  221. table.insert(attached, new_bone)
  222. if new_bone.Joint:FindFirstChildOfClass("FaceControls") then
  223. add_face(new_bone, new_bone.Joint:FindFirstChildOfClass("FaceControls"))
  224. end
  225. end
  226. end
  227.  
  228. local find_bone = rig.PrimaryPart:FindFirstChildOfClass("Bone")
  229. if find_bone then
  230. scan_bones(rig_hier)
  231. return rig_hier
  232. end
  233.  
  234. local geometry = {rig.PrimaryPart}
  235. local all_motor6d = {}
  236. local stacc = {}
  237.  
  238. for _, motor in pairs(rig:GetDescendants()) do
  239. if motor.ClassName == "Motor6D" and not string.find(motor.Name, "_GeoMotor6D") and (motor.Part0 and motor.Part0.Parent) and (motor.Part1 and motor.Part1.Parent) then
  240. if motor.Part0 == geometry[1] then
  241. local new_motor = {Joint = motor, Depth = 1, Path = motor.Part1.Name, path_tbl = {motor.Part1.Name}, Parent = nil, Attached = {}}
  242. table.insert(rig_hier, new_motor)
  243. table.insert(stacc, 1, new_motor)
  244. if new_motor.Joint.Part1:FindFirstChildOfClass("FaceControls") then
  245. add_face(new_motor, new_motor.Joint.Part1:FindFirstChildOfClass("FaceControls"))
  246. end
  247. end
  248. table.insert(all_motor6d, motor)
  249. end
  250. end
  251.  
  252. table.sort(all_motor6d, function(a, b) return a.Name < b.Name end)
  253. table.sort(stacc, function(a, b) return a.Joint.Name < b.Joint.Name end)
  254.  
  255. while (#stacc > 0) do
  256. local pop = table.remove(stacc, 1)
  257. if pop.Joint.Part1:FindFirstChildOfClass("Bone") then
  258. scan_bones(pop)
  259. end
  260. for _, motor in pairs(all_motor6d) do
  261. if motor.Part0 == pop.Joint.Part1 then
  262. local new_motor = {Joint = motor, Depth = pop.Depth + 1, Path = pop.Path.."."..motor.Part1.Name, path_tbl = _g.deepcopy(pop.path_tbl), Parent = pop, Attached = {}}
  263. table.insert(new_motor.path_tbl, motor.Part1.Name)
  264. table.insert(pop.Attached, new_motor)
  265. table.insert(stacc, 1, new_motor)
  266. if new_motor.Joint.Part1:FindFirstChildOfClass("FaceControls") then
  267. add_face(new_motor, new_motor.Joint.Part1:FindFirstChildOfClass("FaceControls"))
  268. end
  269. end
  270. end
  271. end
  272.  
  273. return rig_hier, face_rigs
  274. end
  275.  
  276. _g.RobloxToSimple = function(roblox, rig, fps)
  277. if roblox == nil then return nil, "animation is nil" end
  278.  
  279. if not _g.CheckIfRig(rig) then
  280. return nil, "not a rig"
  281. end
  282.  
  283. local target = nil
  284.  
  285. if type(roblox) == "number" then
  286. local succ, err = pcall(function()
  287. target = _g.insert:LoadAsset(roblox)
  288. for _, obj in pairs(target:GetChildren()) do
  289. if obj.ClassName == "KeyframeSequence" then
  290. target = obj
  291. break
  292. end
  293. end
  294. end)
  295. if not succ then return nil, "failed to insert animation from id" end
  296. elseif roblox.ClassName == "KeyframeSequence" then
  297. target = roblox
  298. else
  299. return nil, "animation is invalid"
  300. end
  301.  
  302. local primary_part = rig.PrimaryPart.Name.."\7"
  303. local rig_hier, face_rigs = _g.RigHierarchy(rig)
  304.  
  305. local rig_paths = {}
  306.  
  307. local get_paths = function(tbl, node)
  308. local path
  309. for _, str in pairs(node.path_tbl) do
  310. if path == nil then path = str else path = path.."\7"..str end
  311. end
  312.  
  313. local data
  314. if node.Joint then
  315. data = {node.Joint:GetDebugId(8), node.Joint}
  316. elseif node.FaceControls then
  317. data = {node.FaceControls:GetDebugId(8), node.FaceControls}
  318. end
  319.  
  320. tbl[primary_part..path] = data
  321. local count = #node.path_tbl - 1
  322. if count > 0 then
  323. tbl[path] = data
  324. if count > 1 then
  325. for i = 1, count - 1 do
  326. path = path:sub(path:find("\7") + 1)
  327. tbl[path] = data
  328. end
  329. end
  330. end
  331. end
  332.  
  333. local stacc = {}
  334. for _, joint in pairs(rig_hier) do
  335. table.insert(stacc, 1, joint)
  336. end
  337. while (#stacc > 0) do
  338. local pop = table.remove(stacc, 1)
  339. get_paths(rig_paths, pop)
  340. for _, joint in pairs(pop.Attached) do
  341. table.insert(stacc, 1, joint)
  342. end
  343. end
  344.  
  345. local face_rig_paths = {}
  346. if face_rigs then
  347. for _, tbl in pairs(face_rigs) do
  348. get_paths(face_rig_paths, tbl)
  349. end
  350. end
  351.  
  352. local function GetPoseHierarchy(Pose)
  353. local str = Pose.Name
  354. while (Pose.Parent and Pose.Parent.ClassName == "Pose") do
  355. Pose = Pose.Parent
  356. str = Pose.Name.."\7"..str
  357. end
  358. return str
  359. end
  360.  
  361. local Ease = require(_g.class.Ease)
  362. local final = {}
  363. local ani_events = {}
  364. local face_ani = {}
  365. local maxLength = 0
  366.  
  367. for _, Keyframe in pairs(target:GetChildren()) do
  368. if Keyframe.ClassName == "Keyframe" then
  369. local frm_pos = math.floor(Keyframe.Time * fps + 0.5)
  370. if frm_pos >= 0 then
  371. if frm_pos > maxLength then
  372. maxLength = frm_pos
  373. end
  374.  
  375. if Keyframe.Name ~= "Keyframe" then
  376. if ani_events[frm_pos] == nil then ani_events[frm_pos] = {} end
  377. ani_events[frm_pos].name = Keyframe.Name
  378. end
  379.  
  380. for _, Pose in pairs(Keyframe:GetDescendants()) do
  381. if Pose.ClassName == "Pose" and Pose.Weight > 0 and Pose:FindFirstChild("xSIXxNull") == nil and Pose:FindFirstChild("Null") == nil and Pose.Parent ~= Keyframe then
  382. local joint = rig_paths[GetPoseHierarchy(Pose)]
  383. if joint then
  384. local id = joint[1]
  385. joint = joint[2]
  386.  
  387. if final[id] == nil then
  388. final[id] = {Joint = joint, TargetValues = {}, Easing = {}}
  389. end
  390.  
  391. final[id].TargetValues[frm_pos] = Pose.CFrame
  392. if Pose:FindFirstChild("Ease") then
  393. local ease = Ease.Deserialize(Pose.Ease)
  394. final[id].Easing[frm_pos] = ease:Tableize()
  395. ease:Destroy()
  396. elseif Pose:FindFirstChild("xSIXxCustomStyle") then
  397. final[id].Easing[frm_pos] = {_tblType = "Ease", ease_type = Pose.xSIXxCustomStyle.Value, params = {Direction = Pose.xSIXxCustomDir.Value}}
  398. elseif Pose.EasingStyle.Name ~= "Linear" then
  399. final[id].Easing[frm_pos] = {_tblType = "Ease", ease_type = Pose.EasingStyle.Name, params = {Direction = Pose.EasingDirection.Name}}
  400. else
  401. final[id].Easing[frm_pos] = Ease.LINEAR_tbl()
  402. end
  403. end
  404. elseif Pose.ClassName == "NumberPose" and Pose.Weight > 0 then
  405. local face_controls = face_rig_paths[GetPoseHierarchy(Pose.Parent)]
  406. if face_controls then
  407. local debug_id = face_controls[1]
  408. if face_ani[debug_id] == nil then
  409. face_ani[debug_id] = {FaceControls = face_controls[2], Properties = {}}
  410. end
  411. local target_tbl = face_ani[debug_id].Properties
  412.  
  413. local id = Pose.Name
  414.  
  415. if target_tbl[id] == nil then
  416. target_tbl[id] = {TargetValues = {}, Easing = {}}
  417. end
  418.  
  419. target_tbl[id].TargetValues[frm_pos] = Pose.Value
  420. if Pose:FindFirstChild("Ease") then
  421. local ease = Ease.Deserialize(Pose.Ease)
  422. target_tbl[id].Easing[frm_pos] = ease:Tableize()
  423. ease:Destroy()
  424. elseif Pose:FindFirstChild("xSIXxCustomStyle") then
  425. target_tbl[id].Easing[frm_pos] = {_tblType = "Ease", ease_type = Pose.xSIXxCustomStyle.Value, params = {Direction = Pose.xSIXxCustomDir.Value}}
  426. elseif Pose.EasingStyle.Name ~= "Linear" then
  427. target_tbl[id].Easing[frm_pos] = {_tblType = "Ease", ease_type = Pose.EasingStyle.Name, params = {Direction = Pose.EasingDirection.Name}}
  428. else
  429. target_tbl[id].Easing[frm_pos] = Ease.LINEAR_tbl()
  430. end
  431. end
  432. elseif Pose.ClassName == "KeyframeMarker" then
  433. if ani_events[frm_pos] == nil then ani_events[frm_pos] = {} end
  434. table.insert(ani_events[frm_pos], {Pose.Name, Pose.Value})
  435. end
  436. end
  437. end
  438. end
  439. end
  440. return final, maxLength, ani_events, face_ani
  441. end
  442.  
  443. _g.RobloxToBuffers = function(roblox, rig, fps)
  444. local Ease = require(_g.class.Ease)
  445. local final = {}
  446.  
  447. local simple, length, ani_events, face_ani = _g.RobloxToSimple(roblox, rig, fps)
  448. if not simple then return end
  449.  
  450. local function add_buffers(target, data, tween, default)
  451. local buffer_tbl = {Target = target, Buffer = {}}
  452.  
  453. local all_pos = {}
  454. for kfPos, _ in pairs(data.TargetValues) do
  455. table.insert(all_pos, kfPos)
  456. end
  457. table.sort(all_pos, function(a,b) return a < b end)
  458.  
  459. local ini_value = default
  460. local ini_pos = 0
  461. local ease = data.Easing[0]
  462.  
  463. for _, kfPos in pairs(all_pos) do
  464. local final_value = data.TargetValues[kfPos]
  465. if kfPos == 0 then
  466. buffer_tbl.Buffer[0] = final_value
  467. else
  468. local dist = kfPos - ini_pos
  469. local ease_obj = ease and Ease.Detableize(ease) or Ease.LINEAR()
  470. for bufferPos = ini_pos, kfPos, 1 do
  471. buffer_tbl.Buffer[bufferPos] = tween(ini_value, final_value, ease_obj._func((bufferPos - ini_pos) / dist))
  472. end
  473. ease_obj:Destroy()
  474. ease = data.Easing[kfPos]
  475. end
  476. ini_value = final_value
  477. ini_pos = kfPos
  478. end
  479.  
  480. if ini_pos < length then
  481. for bufferPos = ini_pos + 1, length, 1 do
  482. buffer_tbl.Buffer[bufferPos] = buffer_tbl.Buffer[ini_pos]
  483. end
  484. end
  485.  
  486. return buffer_tbl
  487. end
  488.  
  489. for joint_id, data in pairs(simple) do
  490. if data.Joint.ClassName == "Motor6D" then
  491. local default = data.Joint.C1
  492. final[joint_id] = add_buffers(data.Joint, data, _g.ItemTable.TweenFunctions.Lerp, default)
  493. final[joint_id].Prop = "C1"
  494. final[joint_id].Default = default
  495. local c1_inv = default:Inverse()
  496. for ind, val in pairs(final[joint_id].Buffer) do
  497. final[joint_id].Buffer[ind] = (val * c1_inv):Inverse()
  498. end
  499. elseif data.Joint.ClassName == "Bone" then
  500. local default = CFrame.new()
  501. final[joint_id] = add_buffers(data.Joint, data, _g.ItemTable.TweenFunctions.Lerp, default)
  502. final[joint_id].Prop = "Transform"
  503. final[joint_id].Default = default
  504. end
  505. end
  506.  
  507. for fc_id, tbl in pairs(face_ani) do
  508. for prop, data in pairs(tbl.Properties) do
  509. local default = tbl.FaceControls[prop]
  510. final[fc_id.."_"..prop] = add_buffers(tbl.FaceControls, data, _g.ItemTable.TweenFunctions.Number, default)
  511. final[fc_id.."_"..prop].Prop = prop
  512. final[fc_id.."_"..prop].Default = default
  513. end
  514. end
  515.  
  516. return final, length
  517. end
  518.  
  519. _g.ExportItemObject = function(ItemObject)
  520. local exportFolder = Instance.new("Folder")
  521.  
  522. if ItemObject.RigContainer then
  523. local roblox_kfSeq = Instance.new("KeyframeSequence")
  524. roblox_kfSeq.Loop = ItemObject.LayerSystem.PlaybackHandler.Loop
  525. roblox_kfSeq.Priority = Enum.AnimationPriority[ItemObject.LayerSystem.ExportPriority]
  526. roblox_kfSeq.Name = ItemObject.LayerSystem.CurrentFile.Name
  527.  
  528. local primary_part = ItemObject.Path:GetItem().PrimaryPart.Name
  529.  
  530. local roblox_KeyframeMap = {}
  531. local function GetKeyframe(pos)
  532. if roblox_KeyframeMap[pos] == nil then
  533. roblox_KeyframeMap[pos] = Instance.new("Keyframe", roblox_kfSeq)
  534. roblox_KeyframeMap[pos].Time = pos / ItemObject.LayerSystem.FPS
  535.  
  536. if ItemObject.MarkerTrack and ItemObject.MarkerTrack.TrackItemPositions[pos] and ItemObject.MarkerTrack.TrackItemPositions[pos].frm_pos == pos then
  537. local foundMarker = ItemObject.MarkerTrack.TrackItemPositions[pos]
  538. if foundMarker.name ~= "" then
  539. roblox_KeyframeMap[pos].Name = ItemObject.MarkerTrack.TrackItemPositions[pos].name
  540. end
  541. if #foundMarker.KFMarkers > 0 then
  542. for _, kfm in pairs(foundMarker.KFMarkers) do
  543. local newKFMarker = Instance.new("KeyframeMarker", roblox_KeyframeMap[pos])
  544. newKFMarker.Name = kfm[1]
  545. newKFMarker.Value = kfm[2]
  546. end
  547. end
  548. end
  549. local null_Val = Instance.new("IntValue", roblox_KeyframeMap[pos])
  550. null_Val.Name = "Null"
  551. end
  552. return roblox_KeyframeMap[pos]
  553. end
  554.  
  555. local function GetPose(roblox_kf, path_tbl, nulled)
  556. table.insert(path_tbl, 1, primary_part)
  557. local roblox_Pose = roblox_kf
  558. for ind, obj_name in pairs(path_tbl) do
  559. local is_folder = obj_name:sub(1, 1) == "\7"
  560. local is_number = obj_name:sub(1, 1) == "\8"
  561. if is_folder or is_number then
  562. obj_name = obj_name:sub(2)
  563. end
  564. if roblox_Pose:FindFirstChild(obj_name) == nil then
  565. if not is_folder then
  566. roblox_Pose = Instance.new(is_number and "NumberPose" or "Pose", roblox_Pose)
  567. roblox_Pose.Weight = 0
  568. roblox_Pose.Name = obj_name
  569.  
  570. if nulled then
  571. local null_Val = Instance.new("IntValue", roblox_Pose)
  572. null_Val.Name = "Null"
  573. end
  574. else
  575. roblox_Pose = Instance.new("Folder", roblox_Pose)
  576. roblox_Pose.Name = obj_name
  577. end
  578. else
  579. roblox_Pose = roblox_Pose[obj_name]
  580. end
  581. end
  582. table.remove(path_tbl, 1)
  583. if nulled and roblox_Pose:FindFirstChild("Null") == nil then
  584. local null_Val = Instance.new("IntValue", roblox_Pose)
  585. null_Val.Name = "Null"
  586. end
  587. return roblox_Pose
  588. end
  589.  
  590. local function convert_track(KeyframeTrack, path_tbl, is_number)
  591. local is_bone = not is_number and _g.objIsType(KeyframeTrack, "BoneTrack") or false
  592.  
  593. local last_pos
  594. for pos, value, ease in KeyframeTrack:TargetValueIterator() do
  595. if last_pos then
  596. for p = last_pos + 1, pos - 1, 1 do
  597. local r_kf = GetKeyframe(p)
  598. local r_pose = GetPose(r_kf, path_tbl, true)
  599. r_pose.Weight = 1
  600. if is_number then
  601. r_pose.Value = KeyframeTrack.BufferMap[p]
  602. else
  603. r_pose.CFrame = is_bone and KeyframeTrack.BufferMap[p] or KeyframeTrack.BufferMap[p]:toObjectSpace(KeyframeTrack.defaultValue)
  604. end
  605.  
  606. end
  607. last_pos = nil
  608. end
  609.  
  610. local roblox_kf = GetKeyframe(pos)
  611. if roblox_kf:FindFirstChild("Null") then
  612. roblox_kf["Null"]:Destroy()
  613. end
  614.  
  615. local roblox_Pose = GetPose(roblox_kf, path_tbl)
  616. if roblox_Pose:FindFirstChild("Null") then
  617. roblox_Pose["Null"]:Destroy()
  618. end
  619. roblox_Pose.Weight = 1
  620. if is_number then
  621. roblox_Pose.Value = value
  622. else
  623. roblox_Pose.CFrame = is_bone and value or value:toObjectSpace(KeyframeTrack.defaultValue)
  624. end
  625.  
  626. if ease.ease_type == "Constant" then
  627. roblox_Pose.EasingStyle = Enum.PoseEasingStyle.Constant
  628. elseif ease.ease_type ~= "Linear" then
  629. ease:Serialize().Parent = roblox_Pose
  630. last_pos = pos
  631. end
  632. end
  633. end
  634.  
  635. local face_controls = {}
  636.  
  637. for partHier, KeyframeTrack in pairs(ItemObject.RigMap) do
  638. partHier = KeyframeTrack.path_tbl
  639.  
  640. local is_bone =_g.objIsType(KeyframeTrack, "BoneTrack")
  641. if is_bone and KeyframeTrack.Target:FindFirstChildOfClass("FaceControls") then
  642. table.insert(face_controls, {KeyframeTrack.Target:FindFirstChildOfClass("FaceControls"), partHier})
  643. elseif not is_bone and KeyframeTrack.Target.Part1:FindFirstChildOfClass("FaceControls") then
  644. table.insert(face_controls, {KeyframeTrack.Target.Part1:FindFirstChildOfClass("FaceControls"), partHier})
  645. end
  646. if KeyframeTrack.TrackItems.size > 0 then
  647. convert_track(KeyframeTrack, partHier)
  648. end
  649. end
  650.  
  651. for _, tbl in pairs(face_controls) do
  652. local face_control = tbl[1]
  653. local face_item = ItemObject.LayerSystem.LayerHandler.ItemMap[face_control:GetDebugId(8)]
  654. if face_item then
  655. local path_tbl = tbl[2]
  656. for prop, track in pairs(face_item.PropertyMap) do
  657. local new_path = _g.deepcopy(path_tbl); table.insert(new_path, "\7"..face_item.Path:GetItem().Name);table.insert(new_path, "\8"..prop)
  658. convert_track(track, new_path, true)
  659. end
  660. end
  661. end
  662.  
  663. if ItemObject.MarkerTrack then
  664. ItemObject.MarkerTrack.TrackItems:Iterate(function(Marker)
  665. if roblox_KeyframeMap[Marker.frm_pos] == nil then
  666. local roblox_kf = GetKeyframe(Marker.frm_pos)
  667. roblox_kf["Null"]:Destroy()
  668. end
  669. end)
  670. end
  671.  
  672. roblox_kfSeq.Parent = exportFolder
  673. end
  674.  
  675. if ItemObject.Path.ItemType == "Camera" then
  676. local camAniFolder = _g.new_ui.BlankCameraAni:Clone(); camAniFolder.Parent = exportFolder
  677. camAniFolder.Name = ItemObject.LayerSystem.CurrentFile.Name
  678. camAniFolder.Settings.Loop.Value = ItemObject.LayerSystem.PlaybackHandler.Loop
  679. camAniFolder.Settings.Reference.Value = ItemObject.LayerSystem.CameraReferencePart
  680. camAniFolder.Settings.Reference.Has.Value = ItemObject.LayerSystem.CameraReferencePart ~= nil
  681.  
  682. local function fix_cf(value)
  683. if camAniFolder.Settings.Reference.Value then
  684. return camAniFolder.Settings.Reference.Value.CFrame:ToObjectSpace(value)
  685. else
  686. return value
  687. end
  688. end
  689.  
  690. for propName, KeyframeTrack in pairs(ItemObject.PropertyMap) do
  691. if KeyframeTrack.TrackItems.size > 0 then
  692. local lastVal = KeyframeTrack.BufferMap[KeyframeTrack:GetLastTrackItem().frm_pos]
  693. if propName == "CFrame" then
  694. lastVal = fix_cf(lastVal)
  695. for pos = 0, ItemObject.LayerSystem.LayerHandler:GetLastKeyframePosition() do
  696. local cf_val = Instance.new("CFrameValue", camAniFolder.Frames)
  697. cf_val.Name = tostring(pos)
  698. cf_val.Value = KeyframeTrack.BufferMap[pos] and fix_cf(KeyframeTrack.BufferMap[pos]) or lastVal
  699. end
  700. elseif propName == "FieldOfView" then
  701. for pos = 0, ItemObject.LayerSystem.LayerHandler:GetLastKeyframePosition() do
  702. local nm_val = Instance.new("NumberValue", camAniFolder.FOV)
  703. nm_val.Name = tostring(pos)
  704. nm_val.Value = KeyframeTrack.BufferMap[pos] and KeyframeTrack.BufferMap[pos] or lastVal
  705. end
  706. end
  707. end
  708. end
  709. end
  710.  
  711. if #exportFolder:GetChildren() == 0 then exportFolder:Destroy() exportFolder = nil end
  712. return exportFolder
  713. end
  714.  
  715. _g.ResetUndoRedo = function()
  716. _g.chs:SetWaypoint("Moon Animator Reseting")
  717. _g.chs:SetWaypoint("Moon Animator Reset")
  718. _g.chs:ResetWaypoints()
  719. end
  720.  
  721. _g.ClosestValue = function(sorted_int_table, target_value, start_index)
  722. local table_size = #sorted_int_table
  723. local i, j, mid = 1, table_size, start_index
  724.  
  725. while i < j do
  726. if sorted_int_table[mid] == target_value then
  727. return sorted_int_table[mid]
  728. end
  729. if target_value < sorted_int_table[mid] then
  730. if mid > 1 and target_value > sorted_int_table[mid - 1] then
  731. if target_value - sorted_int_table[mid - 1] >= sorted_int_table[mid] - target_value then
  732. return sorted_int_table[mid]
  733. else
  734. return sorted_int_table[mid - 1]
  735. end
  736. end
  737. j = mid
  738. else
  739. if mid < table_size and target_value < sorted_int_table[mid + 1] then
  740. if target_value - sorted_int_table[mid] >= sorted_int_table[mid + 1] - target_value then
  741. return sorted_int_table[mid + 1]
  742. else
  743. return sorted_int_table[mid]
  744. end
  745. end
  746. i = mid + 1
  747. end
  748. mid = math.floor((i + j) / 2)
  749. end
  750.  
  751. return sorted_int_table[mid]
  752. end
  753.  
  754. _g.hex2rgb = function(hex)
  755. if #hex < 6 then return end
  756.  
  757. hex = hex:gsub("#","")
  758. return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
  759. end
  760.  
  761. _g.split = function(inputstr, sep)
  762. local t = {}
  763. for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  764. table.insert(t, str)
  765. end
  766. return t
  767. end
  768.  
  769. _g.round = function(n, b)
  770. return math.floor((n / b) + 0.5) * b
  771. end
  772.  
  773. _g.format_number = function(value)
  774. local str = string.format("%#.3f", value):gsub("%.?0+$", "")
  775. return str
  776. end
  777.  
  778. _g.reflect = function(cf)
  779. local x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = cf:components()
  780. x = -x
  781. R10 = -R10
  782. R20 = -R20
  783. R01 = -R01
  784. R02 = -R02
  785. return CFrame.new(x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22)
  786. end
  787.  
  788. _g.deepcopy = function(orig)
  789. local orig_type = type(orig)
  790. local copy
  791. if orig_type == 'table' then
  792. copy = {}
  793. for orig_key, orig_value in next, orig, nil do
  794. copy[_g.deepcopy(orig_key)] = _g.deepcopy(orig_value)
  795. end
  796. setmetatable(copy, _g.deepcopy(getmetatable(orig)))
  797. else
  798. copy = orig
  799. end
  800. return copy
  801. end
  802.  
  803. _g.csvToNumberTable = function(csv)
  804. csv = csv:gsub("%s+", "")..","
  805.  
  806. local vals = {}
  807. local getNum = nil
  808. repeat
  809. local findComma = csv:find(",")
  810. if findComma == nil then break end
  811. getNum = tonumber(csv:sub(1, findComma - 1))
  812. if getNum == nil then break end
  813. table.insert(vals, getNum)
  814. csv = csv:sub(findComma + 1)
  815. until false
  816.  
  817. return vals
  818. end
  819.  
  820. _g.TickToTime = function(t)
  821. local timeTable = os.date("*t", t)
  822. local pm = false
  823.  
  824. if timeTable.hour > 12 then
  825. pm = true
  826. timeTable.hour = timeTable.hour - 12
  827. elseif timeTable.hour == 12 then
  828. pm = true
  829. elseif timeTable.hour == 0 then
  830. timeTable.hour = 12
  831. end
  832.  
  833. if timeTable.min < 10 then
  834. timeTable.min = "0"..timeTable.min
  835. end
  836. if timeTable.sec < 10 then
  837. timeTable.sec = "0"..timeTable.sec
  838. end
  839.  
  840. local ending = pm and "PM" or "AM"
  841.  
  842. return timeTable.hour..":"..timeTable.min..":"..timeTable.sec.." "..ending.." "..timeTable.month.."/"..timeTable.day.."/"..timeTable.year
  843. end
  844.  
  845. _g.TimeConvert = function(orig, origUnit, destUnit, fps)
  846. if orig == nil then return nil end
  847.  
  848. if origUnit == "s" then
  849. orig = math.floor(orig * fps + 0.5)
  850. elseif origUnit == "t" then
  851. orig = ":"..string.gsub(orig, ":", "::")..":"
  852. local iter = string.gmatch(orig, ":(%d+):")
  853.  
  854. local vals = {}
  855. local count = -1
  856.  
  857. repeat
  858. local getNum = iter()
  859. if getNum == nil then break end
  860. getNum = tonumber(getNum)
  861. assert(getNum ~= nil, "Invalid time format.")
  862.  
  863. table.insert(vals, getNum)
  864. count = count + 1
  865. until false
  866.  
  867. orig = 0
  868. for _, num in pairs(vals) do
  869. orig = math.floor(orig + num * (fps ^ count))
  870. count = count - 1
  871. end
  872. end
  873.  
  874. local dest
  875.  
  876. if destUnit == "f" then
  877. dest = orig
  878. elseif destUnit == "s" then
  879. dest = orig / fps
  880. elseif destUnit == "t" then
  881. dest = ""
  882.  
  883. if orig >= fps ^ 2 then
  884. local get = math.floor(orig / (fps ^ 2))
  885. dest = dest..get..":"
  886. orig = math.floor(orig - get * (fps ^ 2))
  887. end
  888. if orig >= fps then
  889. local get = math.floor(orig / fps)
  890. if #dest > 0 then
  891. local str = tostring(get)
  892. if #str == 1 then str = "0"..str end
  893. dest = dest..str..":"
  894. else
  895. dest = dest..get..":"
  896. end
  897. orig = math.floor(orig - get * fps)
  898. else
  899. if #dest > 0 then
  900. dest = dest.."00:"
  901. else
  902. dest = dest.."0:"
  903. end
  904. end
  905.  
  906. local str = tostring(orig)
  907. if #str == 1 then str = "0"..str end
  908. dest = dest..str
  909. end
  910.  
  911. return dest
  912. end
  913.  
  914. _g.FormatFrameTime_f = function(frames, fps)
  915. return tostring(frames).."f", _g.TimeConvert(frames, "f", "t", fps)
  916. end
  917. _g.FormatFrameTime_s = function(frames, fps)
  918. return string.format("%.3f", _g.round(_g.TimeConvert(frames, "f", "s", fps), 0.001)).."s", _g.TimeConvert(frames, "f", "t", fps)
  919. end
  920.  
  921. _g.FormatFrameTime = _g.FormatFrameTime_f
  922. end
  923. ------------------------------------------------------------
  924. do
  925. _g.Window = require(_g.class.Window)
  926. _g.WindowData = require(_g.class.WindowData)
  927. _g.MenuBar = require(_g.class.MenuBar)
  928.  
  929. _g.Windows = {}
  930. for _, window in pairs(script.Parent.Windows:GetChildren()) do
  931. _g.Windows[window.Name] = require(window)
  932. end
  933.  
  934. _g.Toggles.CreateToggle("EaseWindow", {Default = false})
  935. _g.Toggles.SetToggleChanged("EaseWindow", function(value)
  936. _g.Windows.EditKeyframes = value and _g.Windows.EditKeyframes_Ease or _g.Windows.EditKeyframes_Value
  937. if value and _g.Windows.EditKeyframes_Value.Visible then
  938. local modal = _g.Windows.EditKeyframes_Value.ModalParent
  939. local pos = _g.Windows.EditKeyframes_Value.UI.Position
  940. _g.Windows.EditKeyframes_Value:Close()
  941. modal:OpenModal(_g.Windows.EditKeyframes_Ease, {pos = pos})
  942. elseif not value and _g.Windows.EditKeyframes_Ease.Visible then
  943. local modal = _g.Windows.EditKeyframes_Ease.ModalParent
  944. local pos = _g.Windows.EditKeyframes_Ease.UI.Position
  945. _g.Windows.EditKeyframes_Ease:Close()
  946. modal:OpenModal(_g.Windows.EditKeyframes_Value, {pos = pos})
  947. end
  948. end)
  949.  
  950. _g.Themer:SetTheme()
  951. end
  952. ------------------------------------------------------------
  953. do
  954. local win_Activate = _g.Windows.Activate
  955.  
  956. --local ver_ui = _g.new_ui.Version
  957. --local ver_check = pcall(function()
  958. -- local verCheck = game:GetService("MarketplaceService"):GetProductInfo(4725618216).Description
  959. -- if verCheck then
  960. -- local _, checkVer = string.find(verCheck, "!V")
  961. -- if checkVer then
  962. -- local theVer = tonumber(string.sub(verCheck, checkVer + 1))
  963. -- if theVer > _g.ver then
  964. -- ver_ui.Label.Text = "v"..tostring(_g.ver).." [OUT OF DATE, NEW v"..tostring(theVer).."]"
  965. -- ver_ui.Visible = true
  966. -- end
  967. -- end
  968. -- end
  969. --end)
  970. --if not ver_check then
  971. -- ver_ui.Label.Text = "[ OUT OF DATE ]"
  972. -- ver_ui.Visible = true
  973. --end
  974. --if ver_ui.Visible then
  975. -- win_Activate.g_e.Activate.UI.Visible = false
  976. -- win_Activate.g_e.Decline.UI.Visible = false
  977. -- for _, ui in pairs(_g.new_ui:GetChildren()) do
  978. -- if ui.ClassName == "ImageButton" then
  979. -- for _, v in pairs(ui:GetDescendants()) do
  980. -- if not pcall(function() local store = v.Text end) then
  981. -- pcall(function() v.Visible = false end)
  982. -- end
  983. -- end
  984. -- end
  985. -- end
  986. -- for _, win in pairs(_g.Windows) do
  987. -- if win.moon_img then
  988. -- win.moon_img.Visible = false
  989. -- end
  990. -- win.UI.TitleBar.Title.Visible = false
  991. -- end
  992. --end
  993. --ver_ui:Clone().Parent = _g.Windows.MoonAnimator.UI.TitleBar
  994. --ver_ui:Clone().Parent = _g.Windows.Activate.UI.TitleBar
  995.  
  996. local create = {
  997. pluginToolbar:CreateButton("",
  998. "Moon\nAnimator\n------------",
  999. "http://www.roblox.com/asset/?id=11624384141"),
  1000. pluginToolbar:CreateButton("",
  1001. "Character\nInserter\n------------",
  1002. "http://www.roblox.com/asset/?id=11624574138"),
  1003. pluginToolbar:CreateButton("",
  1004. "Easy\nWeld\n------------",
  1005. "http://www.roblox.com/asset/?id=11624574435"),
  1006. }
  1007.  
  1008. local buttons = {
  1009. but_MoonAnimator = create[1],
  1010. but_CharacterInserter = create[2],
  1011. but_Welder = create[3],
  1012. }
  1013.  
  1014. local events = {}
  1015.  
  1016. local target_open
  1017.  
  1018. local lic_ver = 2
  1019. _g.theme_key = "MoonAnimator2_Colors"
  1020.  
  1021. for name, but in pairs(buttons) do
  1022. table.insert(events, but.Click:Connect(function()
  1023. but:SetActive(false)
  1024. target_open = name:sub(5)
  1025. if win_Activate.Visible == false then
  1026. win_Activate:Open()
  1027. end
  1028. end))
  1029. end
  1030.  
  1031. function activate()
  1032. _g.Files.RefreshFiles()
  1033. for _, e in pairs(events) do
  1034. e:Disconnect()
  1035. end
  1036. if win_Activate.Visible then
  1037. win_Activate:Close()
  1038. end
  1039. win_Activate.g_e.Activate:SetActive(false)
  1040. win_Activate.g_e.Decline:SetActive(false)
  1041. plugin:SetSetting("MoonAnimator2Activated_"..tostring(lic_ver), true)
  1042.  
  1043. win_Activate.Contents.LicStatus.Text = "<b>ACTIVATED</b>"
  1044. win_Activate.Contents.LicStatus.Position = win_Activate.Contents.LicStatus.Position + UDim2.new(0, 1, 0, 0)
  1045. win_Activate:SetItemPaint(win_Activate.Contents.LicStatus, {TextColor3 = "main"})
  1046.  
  1047. for name, but in pairs(buttons) do
  1048. local window_name = name:sub(5)
  1049. but.Click:Connect(function()
  1050. but:SetActive(false)
  1051. _g.Windows[window_name]:Toggle()
  1052. end)
  1053. end
  1054. if target_open then
  1055. _g.Windows[target_open]:Toggle()
  1056. end
  1057. local SavedTheme = _g.plugin:GetSetting(_g.theme_key)
  1058. if SavedTheme ~= nil then
  1059. _g.Themer:SetTheme(SavedTheme)
  1060. end
  1061. end
  1062.  
  1063. if plugin:GetSetting("MoonAnimator2Activated_"..tostring(lic_ver)) then
  1064. activate()
  1065. else
  1066. table.insert(events, win_Activate.g_e.Activate.UI.MouseButton1Click:Connect(activate))
  1067. end
  1068.  
  1069. _g.ready = true
  1070. end
Advertisement
Add Comment
Please, Sign In to add comment