Advertisement
Guest User

BYC Reborn Model Compressor

a guest
Jun 29th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.81 KB | None | 0 0
  1. local API = {} --(c)Missing Studios
  2.  
  3. EncoderAssist = {
  4.     ["Surface"] = {
  5.         Smooth = 0,
  6.         Glue = 1,
  7.         Weld = 2,
  8.         Studs = 3,
  9.         Inlet = 4,
  10.         Universal = 5,
  11.         Hinge = 6,
  12.         Motor = 7,
  13.         SteppingMotor = 8,
  14.         Unjoinable = 9,
  15.         SmoothNoOutlines = 10,
  16.     };
  17.     ["Material"] = {
  18.         Plastic = 0,
  19.         SmoothPlastic = 1,
  20.         Wood = 2,
  21.         Marble = 3,
  22.         Slate = 4,
  23.         Concrete = 5,
  24.         Granite = 6,
  25.         Brick = 7,
  26.         Pebble = 8,
  27.         CorrodedMetal = 9,
  28.         DiamondPlate = 10,
  29.         Foil = 11,
  30.         Grass = 12,
  31.         Sand = 13,
  32.         Fabric = 14,
  33.         Ice = 15,
  34.         Metal = 16,
  35.         WoodPlanks = 17,
  36.         Cobblestone = 18,
  37.         Neon = 19,
  38.     };
  39.     ["BasePart"] = {
  40.         Part = 0,
  41.         WedgePart = 1,
  42.         CornerWedgePart = 2,
  43.         TrussPart = 3,
  44.         Seat = 4,
  45.         SkateboardPlatform = 5,
  46.         VehicleSeat = 6,
  47.         FlagStand = 7,
  48.         SpawnLocations = 8,
  49.         Terrain = 9
  50.     };
  51.     ["Shape"] = {
  52.         Ball = 0,
  53.         Block = 1,
  54.         Cylinder = 2
  55.     };
  56.     ["Face"] = {
  57.         Top = 1,
  58.         Bottom = 2,
  59.         Right = 3,
  60.         Left = 4,
  61.         Back = 5,
  62.         Front = 6
  63.     };
  64.     ["SurfaceInput"] = {
  65.         NoInput = 0,
  66.         LeftTread = 1,
  67.         RightTread = 2,
  68.         Steer = 3,
  69.         Throttle = 4,
  70.         UpDown = 5,
  71.         Action1 = 6,
  72.         Action2 = 7,
  73.         Action3 = 8,
  74.         Action4 = 9,
  75.         Action5 = 10,
  76.         Constant = 11,
  77.         Sin = 12
  78.     };
  79.     ["Mesh"] = {
  80.         BlockMesh = 0,
  81.         CylinderMesh = 1,
  82.         SpecialMesh = 2,
  83.     };
  84.     ["MeshType"] = {
  85.         Head = 0,
  86.         Torso = 1,
  87.         Wedge = 2,
  88.         Sphere = 3,
  89.         Cylinder = 4,
  90.         FileMesh = 5,
  91.         Brick = 6,
  92.         Prism = 7,
  93.         Pyramid = 8,
  94.         ParallelRamp = 9,
  95.         RightAngleRamp = 10,
  96.         CornerWedge = 11,
  97.     };
  98.     ["Light"] = {
  99.         SpotLight = 0,
  100.         PointLight = 1,
  101.     };
  102.    
  103.     ["SpecialPartInfo"] = {
  104.         B = {TextureId = "rbxassetid://150281996"};
  105.         W = {MeshId = "http://www.roblox.com/asset/?id=1033714"};
  106.         R = {MeshId = "http://roblox.com/asset/?id=2251534"};
  107.     };
  108. }
  109.  
  110. function EncoderAssist:GetValueFromInt(TableName,Int)
  111.     if EncoderAssist[TableName] then
  112.         for i,v in pairs(EncoderAssist[TableName]) do
  113.             if v == Int then return tostring(i) end
  114.         end
  115.     end
  116. end
  117.  
  118. function EncoderAssist:ConstructInstanceFromData(data,Chamber)
  119.     local Part = data
  120.     local G = Part[1]
  121.     local CF = Part[2]
  122.     local S = Part[3]
  123.     local I = Part[4]
  124.    
  125.     local NewPart = Instance.new(EncoderAssist:GetValueFromInt("BasePart",G[1]),Chamber)
  126.     if NewPart:IsA("FormFactorPart") then NewPart.FormFactor = "Symmetric" end
  127.    
  128.     NewPart.Anchored = true
  129.     NewPart.Locked = true
  130.     NewPart.Name = G[6]
  131.     NewPart.Material = EncoderAssist:GetValueFromInt("Material",G[3])
  132.     NewPart.Transparency = G[4]
  133.     NewPart.Reflectance = G[5]
  134.     NewPart.BrickColor = BrickColor.new(G[2])
  135.     NewPart.BackSurface = EncoderAssist:GetValueFromInt("Surface",I[1])
  136.     NewPart.BottomSurface = EncoderAssist:GetValueFromInt("Surface",I[2])
  137.     NewPart.FrontSurface = EncoderAssist:GetValueFromInt("Surface",I[3])
  138.     NewPart.LeftSurface = EncoderAssist:GetValueFromInt("Surface",I[4])
  139.     NewPart.RightSurface = EncoderAssist:GetValueFromInt("Surface",I[5])
  140.     NewPart.TopSurface = EncoderAssist:GetValueFromInt("Surface",I[6])
  141.     NewPart.Size = Vector3.new(S[1],S[2],S[3])
  142.     NewPart.CFrame = CFrame.new(CF[1],CF[2],CF[3]) * CFrame.Angles(math.rad(CF[4]),math.rad(CF[5]),math.rad(CF[6]))
  143.    
  144.     spawn(function()
  145.         local class = G[6]:sub(1,1)
  146.         if class == "Y" or class == "Z" then
  147.             NewPart.Name = class == "Y" and "X2" or class == "Z" and "X3" or "X"
  148.         elseif class == "B" then
  149.             for _,w in pairs(Enum.NormalId:GetEnumItems()) do
  150.                 local texture = Instance.new("Decal",NewPart)
  151.                 texture.Texture = EncoderAssist.SpecialPartInfo.B.TextureId
  152.                 texture.Face = w
  153.             end
  154.         elseif class == "W" then
  155.             local mesh = Instance.new("SpecialMesh",NewPart)
  156.             mesh.MeshType = "FileMesh"
  157.             mesh.MeshId = EncoderAssist.SpecialPartInfo.W.MeshId
  158.         elseif class == "R" then
  159.             local mesh = Instance.new("SpecialMesh",NewPart)
  160.             mesh.MeshType = "FileMesh"
  161.             mesh.MeshId = EncoderAssist.SpecialPartInfo.R.MeshId
  162.             if NewPart.Size.X ~= 2 then
  163.                 mesh.Scale = Vector3.new(.5,.5,.5)
  164.             end
  165.         elseif class == "L" then
  166.             local light = Instance.new("PointLight",NewPart)
  167.             light.Color = NewPart.BrickColor.Color
  168.             light.Shadows = true
  169.         elseif class == "C" then
  170.             Instance.new("CylinderMesh",NewPart)
  171.         elseif class == "M" then
  172.             Instance.new("SpecialMesh",NewPart)
  173.         elseif class == "N" then
  174.             NewPart.CanCollide = false
  175.         end
  176.     end)
  177.     if NewPart:IsA("VehicleSeat") then NewPart.HeadsUpDisplay = false end
  178.     if G[6] == "o" then NewPart.CanCollide = false end
  179.     if G[7] then
  180.         local bindCode = Instance.new("IntValue",NewPart)
  181.         bindCode.Name = "BindCode"
  182.         bindCode.Value = G[7]
  183.     end
  184.     if I[7] then
  185.         NewPart.Shape = EncoderAssist:GetValueFromInt("Shape",I[7])
  186.     end
  187.     wait()
  188. end
  189.  
  190. function API:GenPass()
  191.     local Seed = string.sub(string.reverse(game.Workspace.DistributedGameTime),1,4)
  192.     local Quantifier = string.sub(game.JobId,1,3)
  193.     return "#"..string.reverse( ( Quantifier or 0 ) .."-"..Seed..string.char(math.random(65,126))..math.floor(math.random()*100).."-"..string.char(math.random(65,90))..string.char(math.random(65,90)).."-"..math.random(0,9))
  194. end
  195.  
  196. function API:EncodeModel(model)
  197.    
  198.     local http = game:GetService("HttpService")
  199.     local BaseParts = {}
  200.     local ChunksEncoded = -1
  201.     local IsFinished = false
  202.    
  203.     function GetBP(scope)
  204.         for _,w in pairs(scope:GetChildren()) do
  205.             if w:IsA("BasePart") then
  206.                 table.insert(BaseParts,w)
  207.             end
  208.             GetBP(w)
  209.         end
  210.     end
  211.     GetBP(model)
  212.     local TablesPerDataChunk = 200
  213.     local Times = math.floor(#BaseParts/TablesPerDataChunk)
  214.     local Data = {}
  215.     for iteration = 0,Times do
  216.         spawn(function()
  217.             local DataChunk = {}
  218.             local start = iteration * TablesPerDataChunk + 1
  219.             local finish = start + TablesPerDataChunk - 1
  220.             if finish > #BaseParts then finish = #BaseParts end
  221.             for z = start,finish do
  222.                 local Part = BaseParts[z]
  223.                 local P = {
  224.                     {
  225.                         EncoderAssist.BasePart[Part.ClassName],
  226.                         Part.BrickColor.Number,
  227.                         EncoderAssist.Material[Part.Material.Name],
  228.                         Part.Transparency,
  229.                         Part.Reflectance,
  230.                         string.sub(Part.Name,2,2),
  231.                     };
  232.                     {
  233.                         Part.CFrame.x;             Part.CFrame.y;             Part.CFrame.z;
  234.                         Part.Rotation.x;           Part.Rotation.y;           Part.Rotation.z;
  235.                     };
  236.                     {Part.Size.x,Part.Size.y,Part.Size.z};
  237.                     {
  238.                         EncoderAssist.Surface[Part.BackSurface.Name];
  239.                         EncoderAssist.Surface[Part.BottomSurface.Name];
  240.                         EncoderAssist.Surface[Part.FrontSurface.Name];
  241.                         EncoderAssist.Surface[Part.LeftSurface.Name];
  242.                         EncoderAssist.Surface[Part.RightSurface.Name];
  243.                         EncoderAssist.Surface[Part.TopSurface.Name];
  244.                     };
  245.                 }
  246.                
  247.                 for i,v in pairs(P[2]) do
  248.                     if string.find(v,"e") then
  249.                         local pos = string.find(v,"e")
  250.                         P[2][i] = string.sub(v,1,pos <= string.len(math.floor(v))+4 and pos - 1 or string.len(math.floor(v))+4)..string.sub(v,pos)
  251.                     else
  252.                         local wh,fr = math.modf(v)
  253.                         if string.len(fr) > 5 then
  254.                             local new = string.sub(v,1,string.len(wh)+4)
  255.                             if new == "0" or new == "-0" then
  256.                                 P[2][i] = 0
  257.                             else
  258.                                 P[2][i] = new
  259.                             end
  260.                         end
  261.                     end
  262.                 end
  263.                
  264.                 for i,v in pairs(P[3]) do
  265.                     local wh,fr = math.modf(v)
  266.                     if string.len(fr) > 5 then
  267.                         local new = string.sub(v,1,string.len(wh)+4)
  268.                         if new == "0" or new == "-0" then
  269.                             P[3][i] = 0
  270.                         else
  271.                             P[3][i] = new
  272.                         end
  273.                     end
  274.                 end
  275.                
  276.                 if tonumber(Part.Name:sub(3,3)) then P[1][6] = Part.Name:sub(2,3) end
  277.                 if Part:IsA("Part") then P[4][7] = EncoderAssist.Shape[Part.Shape.Name] end
  278.                 if Part:findFirstChild("BindCode") and Part.BindCode.Value ~= 0 then P[1][7] = Part.BindCode.Value end
  279.                 if z == 1 then print(http:JSONEncode(P)) end
  280.                 table.insert(DataChunk,P)
  281.             end
  282.             table.insert(Data,DataChunk)
  283.             ChunksEncoded = ChunksEncoded + 1
  284.             print(ChunksEncoded,Times)
  285.         end)
  286.     end
  287.     repeat wait() until ChunksEncoded == Times
  288.     print("Complete.")
  289.     print(string.len(http:JSONEncode(Data)))
  290.     return http:JSONEncode(Data)
  291. end
  292. ----------------------------------
  293. function API:SaveDataToCloud(data,namespace,scope)
  294.     local StrLimit = 55000
  295.     local pass = namespace and namespace or API:GenPass()
  296.     local user = scope and scope or "CyberCloudCreations"
  297.     local CCC = game:GetService("DataStoreService"):GetDataStore(pass,user)
  298.    
  299.     local Number = math.ceil(string.len(data)/StrLimit)
  300.     local Saved = 0
  301.     local DoneSaving = 0
  302.     local datacopy = data
  303.    
  304.     for i = 1,Number do
  305.         local chunk = string.sub(datacopy,1,StrLimit)
  306.         spawn(function()
  307.             Saved = Saved + 1
  308.             CCC:SetAsync(i,chunk)
  309.             print(string.len(chunk).."STR")
  310.             DoneSaving = DoneSaving + 1
  311.             print(DoneSaving.."/"..Number)
  312.         end)
  313.         datacopy = string.sub(datacopy,StrLimit + 1)
  314.     end
  315.     repeat wait() until DoneSaving == Number
  316.     CCC:SetAsync("Entries",Number)
  317.    
  318.     return pass,user,Number
  319. end
  320. ----------------------------------
  321. function API:GetEncodedDataFromCloud(Code,scope)
  322.     local GDS = game:GetService("DataStoreService"):GetDataStore(Code,scope or "CyberCloudCreations")
  323.    
  324.     local CodeDone = 1
  325.     local Entries = GDS:GetAsync("Entries")
  326.     local ModelData = ""
  327.    
  328.     for x = 1, Entries do
  329.         spawn(function()
  330.             local DataChunk = GDS:GetAsync(x)
  331.             repeat wait() until CodeDone == x
  332.             ModelData = ModelData..DataChunk
  333.             CodeDone = CodeDone + 1
  334.             print(CodeDone.."/"..Entries)
  335.         end)
  336.     end
  337.    
  338.     repeat wait() until CodeDone == Entries + 1
  339.     return ModelData
  340. end
  341. ----------------------------------
  342. function API:ConstructModelFromCloud(Code,scope,parent)
  343.     local GDS = game:GetService("DataStoreService"):GetDataStore(Code,scope or "CyberCloudCreations")
  344.     local Chamber = Instance.new("Model",parent)
  345.     Chamber.Name = "Construction"
  346.    
  347.     local CodeDone = 1
  348.     local Entries = GDS:GetAsync("Entries")
  349.     local ModelData = ""
  350.    
  351.     for x = 1, Entries do
  352.         spawn(function()
  353.             local DataChunk = GDS:GetAsync(x)
  354.             repeat wait() until CodeDone == x
  355.             ModelData = ModelData..DataChunk
  356.             CodeDone = CodeDone + 1
  357.             print(CodeDone.."/"..Entries)
  358.         end)
  359.     end
  360.    
  361.     repeat wait() until CodeDone == Entries + 1
  362.     ModelData = game:GetService("HttpService"):JSONDecode(ModelData)
  363.     CodeDone = 0
  364.    
  365.     for _,w in pairs(ModelData) do
  366.         spawn(function()
  367.             local Data = w
  368.             for _,v in pairs(Data) do
  369.                 EncoderAssist:ConstructInstanceFromData(v,Chamber)
  370.             end
  371.             CodeDone = CodeDone + 1
  372.             print(CodeDone,#ModelData)
  373.         end)
  374.     end
  375.  
  376.     repeat wait() until CodeDone == #ModelData
  377.    
  378.     Chamber:MakeJoints()
  379.     return Chamber
  380. end
  381. ----------------------------------
  382. function API:ConstructModelFromData(data,parent)
  383.    
  384.     local Chamber = Instance.new("Model",parent)
  385.     Chamber.Name = "Construction"
  386.    
  387.     local ModelData = game:GetService("HttpService"):JSONDecode(data)
  388.     local CodeDone = 0
  389.    
  390.     for _,w in pairs(ModelData) do
  391.         spawn(function()
  392.             local Data = w
  393.             for _,v in pairs(Data) do
  394.                 spawn(function()
  395.                     EncoderAssist:ConstructInstanceFromData(v,Chamber)
  396.                 end)
  397.             end
  398.             CodeDone = CodeDone + 1
  399.             print(CodeDone,#ModelData)
  400.         end)
  401.     end
  402.  
  403.     repeat wait() until CodeDone == #ModelData
  404.    
  405.     Chamber:MakeJoints()
  406.     return Chamber
  407. end
  408. ----------------------------------
  409. function API:CountParts(model)
  410.     local Count = 0
  411.     function int(scope)
  412.         for _,w in pairs(scope:GetChildren()) do
  413.             if w:IsA("BasePart") then
  414.                 Count = Count + 1
  415.             end
  416.             int(w)
  417.         end
  418.     end
  419.     int(model)
  420.    
  421.     return Count
  422. end
  423. ----------------------------------
  424. function API:AnchorModel(model,anchor)
  425.     local function int(scope)
  426.         for _,w in pairs(scope:GetChildren()) do
  427.             if w:IsA("BasePart") then
  428.                 model.Anchored = anchor
  429.             end
  430.             int(w)
  431.         end
  432.     end
  433.     int(model)
  434.     return model
  435. end
  436.  
  437.  
  438. ----------------------------------
  439. function API:ManipulateParts(model,tableofproperties)
  440.     local function int(scope)
  441.         for _,w in pairs(scope:GetChildren()) do
  442.             spawn(function()
  443.                 if w:IsA("BasePart") then
  444.                     for _,v in pairs(tableofproperties) do
  445.                         w[_] = v
  446.                     end
  447.                 end
  448.                 int(w)
  449.             end)
  450.         end
  451.     end
  452.     int(model)
  453.     return model
  454. end
  455. ----------------------------------
  456.  
  457. return API
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement