Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function reflectOne(part, mirror, mod)
- local x,y,z,r00,r01,r02,r10,r11,r12,r20,r21,r22 = mirror.CFrame:toObjectSpace(part.CFrame):components()
- local mpart = part:Clone()
- mpart.CFrame = mirror.CFrame:toWorldSpace(CFrame.new(-x,y,z,r00,-r01,-r02,-r10,r11,r12,-r20,r21,r22))
- -- CornerWedgeParts are not symmetric so we rotate 90 degrees about
- -- the y axis and exchange the x and z sizes. (Currently only works
- -- right with integer sized parts since we cannot script other resolutions.)
- if part.className == "CornerWedgePart" then
- mpart.Size = Vector3.new(mpart.Size.z, mpart.Size.y, mpart.Size.x)
- mpart.CFrame = mpart.CFrame * CFrame.Angles(0,math.rad(90),0)
- end
- mpart.Parent = mod
- end
- ------------------------------------------------------------
- -- Clone and reflect all Parts and WedgeParts in everything in this
- -- model and recursively all contained models.
- local function reflectAll( srcModel, mirror, tgtModel )
- for k,v in pairs(srcModel:GetChildren()) do
- if v.className == "Model" then
- local m2 = Instance.new("Model", tgtModel)
- m2.Name = v.Name
- reflectAll(v, mirror, m2)
- elseif v:IsA("BasePart") then
- reflectOne(v, mirror, tgtModel)
- else
- local np = v:Clone()
- np.Parent = tgtModel
- end
- end
- end
- ------------------------------------------------------------
- function _G.reflect()
- local list = game.Selection:Get()
- if (not list) or (#list ~= 2) then
- error "Select both the model to be reflected and the mirror part"
- end
- local model = list[1]
- local mirror = list[2]
- if model.className ~= "Model" then
- model,mirror = mirror,model
- end
- if (model.className ~= "Model") or (not mirror:IsA("BasePart")) then
- error "Select both the model to be reflected and the mirror part"
- end
- local mmodel = Instance.new("Model", model.Parent)
- mmodel.Name = model.Name.."-M"
- reflectAll(model, mirror, mmodel)
- end
- -------------------------------------------------------------------
- print("Select the model and mirror part and in command bar type: _G.reflect()")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement