Advertisement
SmokeDelsin

roblox mirror script

May 22nd, 2015
1,961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. local function reflectOne(part, mirror, mod)
  2.  
  3. local x,y,z,r00,r01,r02,r10,r11,r12,r20,r21,r22 = mirror.CFrame:toObjectSpace(part.CFrame):components()
  4.  
  5. local mpart = part:Clone()
  6.  
  7. mpart.CFrame = mirror.CFrame:toWorldSpace(CFrame.new(-x,y,z,r00,-r01,-r02,-r10,r11,r12,-r20,r21,r22))
  8.  
  9. -- CornerWedgeParts are not symmetric so we rotate 90 degrees about
  10. -- the y axis and exchange the x and z sizes. (Currently only works
  11. -- right with integer sized parts since we cannot script other resolutions.)
  12. if part.className == "CornerWedgePart" then
  13.  
  14. mpart.Size = Vector3.new(mpart.Size.z, mpart.Size.y, mpart.Size.x)
  15. mpart.CFrame = mpart.CFrame * CFrame.Angles(0,math.rad(90),0)
  16. end
  17.  
  18. mpart.Parent = mod
  19. end
  20.  
  21. ------------------------------------------------------------
  22. -- Clone and reflect all Parts and WedgeParts in everything in this
  23. -- model and recursively all contained models.
  24.  
  25. local function reflectAll( srcModel, mirror, tgtModel )
  26.  
  27. for k,v in pairs(srcModel:GetChildren()) do
  28.  
  29. if v.className == "Model" then
  30. local m2 = Instance.new("Model", tgtModel)
  31. m2.Name = v.Name
  32.  
  33. reflectAll(v, mirror, m2)
  34.  
  35. elseif v:IsA("BasePart") then
  36.  
  37. reflectOne(v, mirror, tgtModel)
  38.  
  39. else
  40. local np = v:Clone()
  41. np.Parent = tgtModel
  42. end
  43. end
  44. end
  45.  
  46.  
  47. ------------------------------------------------------------
  48. function _G.reflect()
  49.  
  50. local list = game.Selection:Get()
  51. if (not list) or (#list ~= 2) then
  52. error "Select both the model to be reflected and the mirror part"
  53. end
  54.  
  55. local model = list[1]
  56. local mirror = list[2]
  57.  
  58. if model.className ~= "Model" then
  59. model,mirror = mirror,model
  60. end
  61.  
  62. if (model.className ~= "Model") or (not mirror:IsA("BasePart")) then
  63. error "Select both the model to be reflected and the mirror part"
  64. end
  65.  
  66. local mmodel = Instance.new("Model", model.Parent)
  67. mmodel.Name = model.Name.."-M"
  68.  
  69. reflectAll(model, mirror, mmodel)
  70. end
  71.  
  72.  
  73. -------------------------------------------------------------------
  74.  
  75. print("Select the model and mirror part and in command bar type: _G.reflect()")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement