local w={}local z={TrussPart=Vector3.new(2,2,2),UnionOperation=Vector3.new(0,0,0)}function w.Scale(w,g,H)for w,C in pairs(w)do if C:IsA("\066\097\115\101\080\097\114\116")then local w=z[C.ClassName]or Vector3.new(.05,.05,.05)local x=C.Position-H local Q=C.CFrame-C.CFrame.p local h=C:FindFirstChildWhichIsA("\068\097\116\097\077\111\100\101\108\077\101\115\104")local V=h and C.Size*h.Scale or C.Size local q=V*g if not C:IsA("\084\114\117\115\115\080\097\114\116")and not C:IsA("\085\110\105\111\110\079\112\101\114\097\116\105\111\110")then if q.X<w.X or q.Y<w.Y or q.Z<w.Z then if not h then h=Instance.new("\083\112\101\099\105\097\108\077\101\115\104",C)if C:IsA("\087\101\100\103\101\080\097\114\116")then h.MeshType="\087\101\100\103\101"elseif C:IsA("\067\111\114\110\101\114\087\101\100\103\101\080\097\114\116")then h.MeshType="\067\111\114\110\101\114\087\101\100\103\101"elseif C:IsA("\080\097\114\116")then if C.Shape.Name=="\066\097\108\108"then h.MeshType="\083\112\104\101\114\101"elseif C.Shape.Name=="\067\121\108\105\110\100\101\114"then h.MeshType="\067\121\108\105\110\100\101\114"else h.MeshType="\066\114\105\099\107"end else h.MeshType="\066\114\105\099\107"end end end end C.Size=q if h then h.Scale=q/C.Size h.Offset=h.Offset*g end C.CFrame=CFrame.new(H+x*g)*Q end end end return w
---
-- @module ScaleModel

local lib = {}

local MINIMUM_SIZES = {
	["TrussPart"] = Vector3.new(2, 2, 2);
	["UnionOperation"]  = Vector3.new(0, 0, 0);
}

--- Scales a group of parts around a centroid
-- @param parts Table of parts, the parts to scale
-- @param Scale The scale to scale by
-- @param Centroid Vector3, the center to scale by
function lib.Scale(parts, scale, Centroid)
	for _, Object in pairs(parts) do
		if Object:IsA("BasePart") then

			local MinSize = MINIMUM_SIZES[Object.ClassName] or Vector3.new(0.05, 0.05, 0.05)

			local ObjectOffset = Object.Position - Centroid
			local ObjectRotation = Object.CFrame - Object.CFrame.p

			local FoundMesh = Object:FindFirstChildWhichIsA("DataModelMesh")
			local TrueSize = FoundMesh and Object.Size * FoundMesh.Scale or Object.Size
			local NewSize = TrueSize * scale

			if not Object:IsA("TrussPart") and not Object:IsA("UnionOperation") then
				if NewSize.X < MinSize.X or NewSize.Y < MinSize.Y or NewSize.Z < MinSize.Z then
					if not FoundMesh then
						FoundMesh = Instance.new("SpecialMesh", Object)

						if Object:IsA("WedgePart") then
							FoundMesh.MeshType = "Wedge"
						elseif Object:IsA("CornerWedgePart") then
							FoundMesh.MeshType = "CornerWedge"

						elseif Object:IsA("Part") then

							if Object.Shape.Name == "Ball" then
								FoundMesh.MeshType = "Sphere"
							elseif Object.Shape.Name == "Cylinder" then
								FoundMesh.MeshType = "Cylinder"
							else
								FoundMesh.MeshType = "Brick"
							end
						else
							FoundMesh.MeshType = "Brick"
						end
					end
				end
			end

			Object.Size = NewSize

			if FoundMesh then
				FoundMesh.Scale = NewSize / Object.Size
				FoundMesh.Offset = FoundMesh.Offset * scale

				-- if FoundMesh.Scale == Vector3.new(1, 1, 1) and FoundMesh.Offset == Vector3.new(0, 0, 0) then
				-- 	FoundMesh:Destroy()
				-- end
			end

			Object.CFrame = CFrame.new(Centroid + (ObjectOffset * scale)) * ObjectRotation
		end
	end
end

return lib