Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local HttpService = game:GetService("HttpService")
- -- Function to serialize a CFrame
- local function serializeCFrame(cframe)
- local components = { cframe:GetComponents() }
- return {
- X = components[1],
- Y = components[2],
- Z = components[3],
- R00 = components[4], R01 = components[5], R02 = components[6],
- R10 = components[7], R11 = components[8], R12 = components[9],
- R20 = components[10], R21 = components[11], R22 = components[12]
- }
- end
- -- Function to serialize a rig
- local function serializeRig(rig)
- local serialized = {}
- local function recurse(part)
- local data = {
- Name = part.Name;
- ClassName = part.ClassName;
- ParentName = part.Parent and part.Parent.Name or nil;
- Properties = {};
- Attributes = {};
- }
- -- Serialize BasePart properties
- if part:IsA("BasePart") then
- data.Properties.CFrame = serializeCFrame(part.CFrame)
- data.Properties.Size = { X = part.Size.X, Y = part.Size.Y, Z = part.Size.Z }
- data.Properties.CanCollide = part.CanCollide
- data.Properties.Anchored = part.Anchored
- data.Properties.Material = part.Material.Value
- data.Properties.Transparency = part.Transparency
- if not part:IsA("MeshPart") and not part:IsA("UnionOperation") and not part:IsA("PartOperation") and not part:IsA("NegateOperation") and not part:IsA("IntersectOperation") and not part:IsA("WedgePart") and not part:IsA("TrussPart") and not part:IsA("CornerWedgePart") then
- data.Properties.Shape = part.Shape.Value
- end
- data.Properties.Color = { R = part.Color.R, G = part.Color.G, B = part.Color.B }
- end
- -- Serialize MeshPart properties
- if part:IsA("MeshPart") then
- data.Properties.MeshId = part.MeshId
- data.Properties.TextureId = part.TextureID
- data.Properties.RenderFidelity = part.RenderFidelity.Value
- end
- -- Serialize Motor6D properties
- if part:IsA("Weld") or part:IsA("Motor6D") then
- data.Properties.C0 = serializeCFrame(part.C0)
- data.Properties.C1 = serializeCFrame(part.C1)
- data.Properties.Part0 = part.Part0 and part.Part0.Name or nil
- data.Properties.Part1 = part.Part1 and part.Part1.Name or nil
- end
- -- Serialize Humanoid properties
- if part:IsA("Humanoid") then
- data.Properties.Health = part.Health
- data.Properties.MaxHealth = part.MaxHealth
- data.Properties.WalkSpeed = part.WalkSpeed
- data.Properties.JumpPower = part.JumpPower
- data.Properties.HipHeight = part.HipHeight
- data.Properties.EvaluateStateMachine = part.EvaluateStateMachine
- data.Properties.RequiresNeck = part.RequiresNeck
- data.Properties.AutoRotate = part.AutoRotate
- data.Properties.AutomaticScalingEnabled = part.AutomaticScalingEnabled
- data.Properties.AutoJumpEnabled = part.AutoJumpEnabled
- data.Properties.MaxSlopeAngle = part.MaxSlopeAngle
- data.Properties.BreakJointsOnDeath = part.BreakJointsOnDeath
- end
- if part:IsA("Attachment") then
- data.Properties.CFrame = serializeCFrame(part.CFrame)
- end
- if part:IsA("Decal") then
- data.Properties.Texture = part.Texture
- data.Properties.Transparency = part.Transparency
- data.Properties.Color3 = { R = part.Color3.R, G = part.Color3.G, B = part.Color3.B }
- data.Properties.ZIndex = part.ZIndex
- end
- if part:IsA("SpecialMesh") then
- data.Properties.MeshId = part.MeshId or ""
- data.Properties.MeshType = part.MeshType or "Head"
- data.Properties.Offset = { X = part.Offset.X, Y = part.Offset.Y, Z = part.Offset.Z }
- data.Properties.Scale = { X = part.Scale.X, Y = part.Scale.Y, Z = part.Scale.Z }
- data.Properties.VertexColor = { X = part.VertexColor.X, Y = part.VertexColor.Y, Z = part.VertexColor.Z }
- data.Properties.TextureId = part.TextureId or ""
- end
- if part:GetAttributes() then
- for name,value in pairs(part:GetAttributes()) do
- if name and value then
- pcall(function()
- print(name,value)
- data.Attributes[name] = value
- end)
- end
- end
- end
- -- Recurse into children
- data.Children = {}
- for _, child in ipairs(part:GetChildren()) do
- table.insert(data.Children, recurse(child))
- end
- return data
- end
- table.insert(serialized, recurse(rig))
- return HttpService:JSONEncode(serialized)
- end
- -- GUI setup
- local screenGui = Instance.new("ScreenGui")
- local textBox = Instance.new("TextBox")
- screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
- screenGui.Name = "RigExporter"
- textBox.Size = UDim2.new(0.8, 0, 0.4, 0)
- textBox.Position = UDim2.new(0.1, 0, 0.3, 0)
- textBox.TextScaled = true
- textBox.TextWrapped = true
- textBox.ClearTextOnFocus = false
- textBox.PlaceholderText = "Exported Rig Data"
- textBox.Text = ""
- textBox.Parent = screenGui
- local model = game.Workspace:FindFirstChild("Neon Arcade")
- if model then
- setclipboard(tostring(serializeRig(model)))
- else
- textBox.Text = "Model not found"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement