Advertisement
scriptingtales

Script Lua Roblox test

Jul 13th, 2023
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.75 KB | None | 0 0
  1.  
  2. --Converted with ttyyuu12345's model to script plugin v4
  3. function sandbox(var,func)
  4.     local env = getfenv(func)
  5.     local newenv = setmetatable({},{
  6.         __index = function(self,k)
  7.             if k=="script" then
  8.                 return var
  9.             else
  10.                 return env[k]
  11.             end
  12.         end,
  13.     })
  14.     setfenv(func,newenv)
  15.     return func
  16. end
  17. cors = {}
  18. mas = Instance.new("Model",game.StarterPlayer.StarterCharacterScripts)
  19. LocalScript0 = Instance.new("LocalScript")
  20. SelectionBox1 = Instance.new("SelectionBox")
  21. ModuleScript2 = Instance.new("ModuleScript")
  22. ModuleScript3 = Instance.new("ModuleScript")
  23. ModuleScript4 = Instance.new("ModuleScript")
  24. ModuleScript5 = Instance.new("ModuleScript")
  25. ModuleScript6 = Instance.new("ModuleScript")
  26. LocalScript0.Name = "Tutorial"
  27. LocalScript0.Parent = mas
  28. table.insert(cors,sandbox(LocalScript0,function()
  29. local p = game:GetService("Players").LocalPlayer
  30. local m = p:GetMouse()
  31. local cam = workspace.CurrentCamera
  32.  
  33. local selObj = nil
  34. local camCframe = nil
  35. local oS = nil
  36. local coolnessOffset = Vector3.new()
  37.  
  38. local function canMove(ob)
  39.     return ob.Name == "Object"
  40. end
  41.  
  42. local function getCP(r, p)
  43.     local rO, D = r.Origin - p, r.Direction
  44.     return rO - ( rO:Dot(D)/D:Dot(D) ) * D
  45. end
  46.  
  47. local function angleBetween(v1, v2)
  48.     return math.acos(v1:Dot(v2)/(v1.magnitude * v2.magnitude))
  49. end
  50.  
  51.  
  52. local e = game:GetService("ReplicatedStorage").UpdPhys
  53. local rr = require(script:WaitForChild("RotatedRegion3"))
  54.  
  55. m.Button1Down:Connect(function()
  56.     if m.Target and canMove(m.Target) then
  57.         m.Target.CanCollide = false
  58.         camCframe = cam.CFrame:ToObjectSpace(m.Target.CFrame)
  59.         oS = m.Target.Size
  60.         coolnessOffset = -getCP(m.UnitRay, m.Target.Position)
  61.         e:FireServer(m.Target)
  62.         m.Target.Anchored = true
  63.         m.Target.Velocity = Vector3.new()
  64.         m.Target.RotVelocity = Vector3.new()
  65.         selObj = m.Target
  66.     end
  67. end)
  68.  
  69. m.Button1Up:Connect(function()
  70.     if selObj then
  71.         selObj.Anchored = false
  72.         selObj.CanCollide = true
  73.     end
  74.     selObj = nil
  75. end)
  76.  
  77. game:GetService("RunService").RenderStepped:Connect(function(dt)
  78.     coolnessOffset = coolnessOffset:Lerp(Vector3.new(), 0.2)
  79. end)
  80.  
  81. game:GetService("RunService").RenderStepped:Connect(function(dt)
  82.     if selObj then
  83.         selObj.CFrame = cam.CFrame:ToWorldSpace(camCframe)
  84.         local ray = Ray.new(cam.CFrame.p, cam.CFrame.LookVector * 1000)
  85.         local _, p, n = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent, selObj})
  86.         local dist = ((cam.CFrame.p - p).magnitude - selObj.Size.magnitude / 2) * -math.cos(angleBetween(ray.Direction, n))
  87.        
  88.         selObj.Size = (oS * dist / camCframe.p.magnitude)
  89.         selObj.Position = cam.CFrame.p + cam.CFrame.LookVector * dist
  90.        
  91.         for i = 1, 0, -0.01 do
  92.             local R = rr.fromPart(selObj)
  93.             if #R:cast({script.Parent, selObj}, 1) > 0 then
  94.                 dist = dist * i
  95.                 selObj.Size = (oS * dist / camCframe.p.magnitude)
  96.                 selObj.Position = cam.CFrame.p + cam.CFrame.LookVector * dist
  97.             else
  98.                 break
  99.             end
  100.         end
  101.            
  102.         selObj.Position = selObj.Position + coolnessOffset
  103.     end
  104. end)
  105. end))
  106. SelectionBox1.Parent = LocalScript0
  107. SelectionBox1.Visible = false
  108. SelectionBox1.Color = BrickColor.new("Institutional white")
  109. SelectionBox1.Color3 = Color3.new(1, 1, 1)
  110. SelectionBox1.LineThickness = 0.009999999776482582
  111. SelectionBox1.SurfaceColor = BrickColor.new("Really black")
  112. SelectionBox1.SurfaceColor3 = Color3.new(0, 0, 0)
  113. ModuleScript2.Name = "RotatedRegion3"
  114. ModuleScript2.Parent = LocalScript0
  115. table.insert(cors,sandbox(ModuleScript2,function()
  116. --[[
  117. This rotated region3 module is a bit different than the one I previously wrote. This uses GJK to do the collision calculations and
  118. as such does not calculate the minimum translation vector. In addition it does not calculate the intersection points anymore either.
  119. I don't think that had much place in a rotated region3 module.
  120.  
  121. As far as new features the module now supports a vast array of shapes and point clouds meaning more accurate collision!
  122.  
  123. API:
  124.  
  125. Constructors:
  126.     region.new(cframe, size)
  127.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  128.         > the corners like a block part.
  129.     region.block(cframe, size)
  130.         > This is the exact same as the region.new constructor, but has a different name.
  131.     region.wedge(cframe, size)
  132.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  133.         > the corners like a wedge part.
  134.     region.cornerWedge(cframe, size)
  135.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  136.         > the corners like a cornerWedge part.
  137.     region.cylinder(cframe, size)
  138.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  139.         > the corners like a cylinder part.
  140.     region.ellipsoid(cframe, size)
  141.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  142.         > the corners like a ball part.
  143.     region.pointCloud(cloud)
  144.         > Creates a region from a table of points. The region is treated as a convex 3D shape when doing the collision detections.
  145.     region.fromPart(part)
  146.         > Creates a region from a part in the game. It can be used on any base part, but the region
  147.         > will treat unknown shapes (meshes, unions, etc) as block shapes.
  148.  
  149. Methods:
  150.     region:cast(ignore instance or table (descendants as well), int maxParts)
  151.         > returns a table full of parts that are inside the region
  152.     region:castPart(basePart)
  153.         > returns a boolean as to whether or not a given part is within a region or not
  154.     region:castPoint(vector3)
  155.         > returns a boolean as to whether or not a given point is within a region or not
  156.    
  157. Properties:
  158.     region.CFrame
  159.         > cframe that represents the center of the region
  160.     region.Size
  161.         > vector3 that represents the size of the region
  162. --]]
  163.  
  164. local gjk = require(script:WaitForChild("gjk"));
  165. local support = require(script:WaitForChild("supports"));
  166. local vertices = require(script:WaitForChild("vertices"));
  167. local draw = require(script:WaitForChild("draw"));
  168.  
  169. local region3 = {};
  170. local region3_mt = {__index = region3};
  171.  
  172. -- private functions
  173.  
  174. local type = type;
  175. local unpack = unpack;
  176. local insert = table.insert;
  177. local R3 = Region3.new;
  178.  
  179. local v3 = Vector3.new;
  180.  
  181. local function centroid(t)
  182.     local sum = t[1] - t[1];
  183.     for i = 1, #t do sum = sum + t[i]; end;
  184.     return sum / #t;
  185. end;
  186.  
  187. local function classify(part)
  188.     if (part.ClassName == "Part") then
  189.         if (part.Shape == Enum.PartType.Block) then
  190.             return region3.block(part.CFrame, part.Size);
  191.         elseif (part.Shape == Enum.PartType.Cylinder) then
  192.             return region3.cylinder(part.CFrame, part.Size);
  193.         elseif (part.Shape == Enum.PartType.Ball) then
  194.             return region3.ellipsoid(part.CFrame, part.Size);
  195.         end;
  196.     elseif (part.ClassName == "WedgePart") then
  197.         return region3.wedge(part.CFrame, part.Size);
  198.     elseif (part.ClassName == "CornerWedgePart") then
  199.         return region3.cornerWedge(part.CFrame, part.Size);
  200.     elseif (part:IsA("BasePart")) then -- mesh, CSG, truss, etc... just use block
  201.         return region3.block(part.CFrame, part.Size);
  202.     end;
  203. end;
  204.  
  205. -- public static functions
  206.  
  207. function region3.new(cf, size)
  208.     local self = {};
  209.     self.CFrame = cf;
  210.     self.Size = size;
  211.     self.input = {vertices.block(cf, size * 0.5, {})};
  212.     self.support = support.pointCloud;
  213.     self.centroid = cf.p;
  214.     return setmetatable(self, region3_mt);
  215. end;
  216.  
  217. region3.block = region3.new;
  218.  
  219. function region3.wedge(cf, size)
  220.     local self = {};
  221.     self.CFrame = cf;
  222.     self.Size = size;
  223.     self.input = {vertices.wedge(cf, size * 0.5, {})};
  224.     self.support = support.pointCloud;
  225.     self.centroid = centroid(self.input[1]);
  226.     return setmetatable(self, region3_mt);
  227. end;
  228.  
  229. function region3.cornerWedge(cf, size)
  230.     local self = {};
  231.     self.CFrame = cf;
  232.     self.Size = size;
  233.     self.input = {vertices.cornerWedge(cf, size * 0.5, {})};
  234.     self.support = support.pointCloud;
  235.     self.centroid = centroid(self.input[1]);
  236.     return setmetatable(self, region3_mt);
  237. end;
  238.  
  239. function region3.cylinder(cf, size)
  240.     local self = {};
  241.     self.CFrame = cf;
  242.     self.Size = size;
  243.     self.input = {cf, size * 0.5};
  244.     self.support = support.cylinder;
  245.     self.centroid = cf.p;
  246.     return setmetatable(self, region3_mt);
  247. end;
  248.  
  249. function region3.ellipsoid(cf, size)
  250.     local self = {};
  251.     self.CFrame = cf;
  252.     self.Size = size;
  253.     self.input = {cf, size * 0.5};
  254.     self.support = support.ellipsoid;
  255.     self.centroid = cf.p;
  256.     return setmetatable(self, region3_mt);
  257. end;
  258.  
  259. function region3.pointCloud(cloud)
  260.     local self = {};
  261.     self.CFrame = CFrame.new(centroid(cloud));
  262.     self.Size = v3();
  263.     self.input = cloud;
  264.     self.support = support.pointCloud;
  265.     self.centroid = self.CFrame.p;
  266.     return setmetatable(self, region3_mt);
  267. end;
  268.  
  269. function region3.fromPart(part)
  270.     return classify(part);
  271. end;
  272.  
  273. -- public methods
  274.  
  275. function region3:castPoint(point)
  276.     local direction = self.centroid - point;
  277.     return gjk(self.input, {point}, self.support, support.point, direction);
  278. end;
  279.  
  280. function region3:castPart(part)
  281.     local against = classify(part);
  282.     local direction = self.centroid - against.centroid;
  283.     return gjk(self.input, against.input, self.support, against.support, direction);
  284. end;
  285.  
  286. function region3:cast(ignore, maxParts)
  287.     local ignore = type(ignore) == "table" and ignore or {ignore};
  288.     local maxParts = maxParts or 20;
  289.    
  290.     local min, max = {}, {};
  291.     for _, enum in next, {Enum.NormalId.Right, Enum.NormalId.Top, Enum.NormalId.Back} do
  292.         local direction = Vector3.FromNormalId(enum);
  293.         insert(min, self.support(-direction, unpack(self.input)));
  294.         insert(max, self.support(direction, unpack(self.input)));
  295.     end;
  296.     min, max = v3(min[1].x, min[2].y, min[3].z), v3(max[1].x, max[2].y, max[3].z);
  297.    
  298.     local allignedR3 = R3(min, max);
  299.     local parts = game.Workspace:FindPartsInRegion3WithIgnoreList(allignedR3, ignore, maxParts);
  300.    
  301.     -- debug stuff
  302.     --game.Workspace.CurrentCamera:ClearAllChildren();
  303.     --draw.line(min, max, game.Workspace.CurrentCamera);
  304.    
  305.     local inRegion = {};
  306.     for i = 1, #parts do
  307.         local part = parts[i];
  308.         if (self:castPart(part)) then
  309.             insert(inRegion, part);
  310.         end;
  311.     end;
  312.     return inRegion;
  313. end;
  314.  
  315. -- return module
  316.  
  317. return region3;
  318. end))
  319. ModuleScript3.Name = "gjk"
  320. ModuleScript3.Parent = ModuleScript2
  321. table.insert(cors,sandbox(ModuleScript3,function()
  322. local v3 = Vector3.new;
  323. local dot = v3().Dot;
  324. local cross = v3().Cross;
  325.  
  326. local unpack = unpack;
  327. local insert = table.insert;
  328. local remove = table.remove;
  329.  
  330. local function tripleProduct(a, b, c)
  331.     -- (a x b) x c = b * (c . a) - a * (c . b)
  332.     return b * dot(c, a) - a * dot(c, b);
  333. end;
  334.  
  335. local function containsOrigin(simplex, direction)
  336.     local a = simplex[#simplex];
  337.     local a0 = -a;
  338.     if (#simplex == 4) then
  339.         local b, c, d = simplex[3], simplex[2], simplex[1];
  340.         local ba, ca, da = b - a, c - a, d - a;
  341.         local abc = cross(ba, ca);
  342.         local adb = cross(da, ba);
  343.         local acd = cross(ca, da);
  344.         abc = dot(abc, da) > 0 and -abc or abc;
  345.         adb = dot(adb, ca) > 0 and -adb or adb;
  346.         acd = dot(acd, ba) > 0 and -acd or acd;
  347.         if (dot(abc, a0) > 0) then
  348.             remove(simplex, 1);
  349.             direction = abc;
  350.         elseif (dot(adb, a0) > 0) then
  351.             remove(simplex, 2);
  352.             direction = adb;
  353.         elseif (dot(acd, a0) > 0) then
  354.             remove(simplex, 3);
  355.             direction = acd;
  356.         else
  357.             return true;
  358.         end;
  359.     elseif (#simplex == 3) then
  360.         local b, c = simplex[2], simplex[1];
  361.         local ba, ca = b - a, c - a;
  362.         local baPerp, caPerp = tripleProduct(ca, ba, ba), tripleProduct(ba, ca, ca);
  363.         if (dot(baPerp, a0) > 0) then
  364.             remove(simplex, 1);
  365.             direction = baPerp;
  366.         elseif (dot(caPerp, a0) > 0) then
  367.             remove(simplex, 2);
  368.             direction = caPerp;
  369.         else
  370.             local abc = ba:Cross(ca);
  371.             if (dot(abc, a0) == 0) then return true; end;
  372.             direction = (dot(abc, a0) > 0) and abc or -abc;
  373.         end;
  374.     else
  375.         local b = simplex[1];
  376.         local ba = b - a;
  377.         direction = tripleProduct(ba, a0, ba);
  378.     end;
  379.     return false, direction;
  380. end;
  381.  
  382. local function collision(A, B, supportA, supportB, direction)
  383.     local simplex = {supportA(direction, unpack(A)) - supportB(-direction, unpack(B))};
  384.     direction = -direction;
  385.     while (true) do
  386.         insert(simplex, supportA(direction, unpack(A)) - supportB(-direction, unpack(B)));     
  387.         if (dot(simplex[#simplex], direction) < 0) then
  388.             return false;
  389.         else
  390.             local pass, newDirection = containsOrigin(simplex, direction);
  391.             if (pass) then return true; end;
  392.             direction = newDirection;
  393.         end;
  394.     end;
  395. end;
  396.  
  397. return collision;
  398.  
  399. end))
  400. ModuleScript4.Name = "supports"
  401. ModuleScript4.Parent = ModuleScript2
  402. table.insert(cors,sandbox(ModuleScript4,function()
  403. -- support functions for GJK
  404. -- Ego
  405.  
  406. local v3 = Vector3.new;
  407. local dot = v3().Dot;
  408.  
  409. local cos = math.cos;
  410. local sin = math.sin;
  411. local min = math.min;
  412. local abs = math.abs;
  413. local huge = math.huge;
  414. local sqrt = math.sqrt;
  415. local atan2 = math.atan2;
  416.  
  417. local AXIS = v3(1, 0, 0);
  418. local ORIGIN = v3(0, 0, 0);
  419.  
  420. -- math functions
  421.  
  422. local function rayPlane(p, v, s, n)
  423.     local r = p - s;
  424.     local t = -dot(r, n) / dot(v, n);
  425.     return p + t * v, t;
  426. end;
  427.  
  428. -- support functions
  429.  
  430. local function point(direction, p)
  431.     return p;
  432. end;
  433.  
  434. local function pointCloud(direction, cloud)
  435.     local max, maxProj = nil, -huge;
  436.     for i = 1, #cloud do
  437.         local proj = dot(cloud[i], direction)
  438.         if (proj > maxProj) then
  439.             max = cloud[i];
  440.             maxProj = proj;
  441.         end;
  442.     end;
  443.     return max;
  444. end;
  445.  
  446. local function cylinder(direction, cf, size)
  447.     direction = cf:vectorToObjectSpace(direction);
  448.     local radius = min(size.y, size.z);
  449.     local dotT, cPoint = dot(direction, AXIS), v3(size.x, 0, 0);
  450.     local h, t, final;
  451.     if (dotT == 0) then
  452.         final = direction.unit * radius;
  453.     else
  454.         cPoint = dotT > 0 and cPoint or -cPoint;
  455.         h, t = rayPlane(ORIGIN, direction, cPoint, AXIS);
  456.         local diff = h - cPoint;
  457.         if (diff.magnitude > radius) then
  458.             diff = diff.unit * radius;
  459.         end;
  460.         final = cPoint + diff;
  461.     end;
  462.     return cf:pointToWorldSpace(final);
  463. end;
  464.  
  465. local function ellipsoid(direction, cf, size)
  466.     direction = cf:vectorToObjectSpace(direction)
  467.     local p0 = (size * direction).unit;
  468.     return cf:pointToWorldSpace(size*p0);
  469. end
  470.  
  471. return {
  472.     pointCloud = pointCloud;
  473.     cylinder = cylinder;
  474.     ellipsoid = ellipsoid;
  475.     point = point;
  476. };
  477. end))
  478. ModuleScript5.Name = "draw"
  479. ModuleScript5.Parent = ModuleScript2
  480. table.insert(cors,sandbox(ModuleScript5,function()
  481. -- 3D drawing functions
  482. -- contains a few basic 3D shapes that are useful when testing, etc
  483. -- EgoMoose
  484.  
  485. local wedge = Instance.new("WedgePart");
  486. wedge.Anchored = true;
  487. wedge.TopSurface = Enum.SurfaceType.Smooth;
  488. wedge.BottomSurface = Enum.SurfaceType.Smooth;
  489.  
  490. local part = Instance.new("Part");
  491. part.Size = Vector3.new(0.1, 0.1, 0.1);
  492. part.Anchored = true;
  493. part.TopSurface = Enum.SurfaceType.Smooth;
  494. part.BottomSurface = Enum.SurfaceType.Smooth;
  495. part.Material = Enum.Material.Neon;
  496.  
  497. local function drawPoint(p, parent)
  498.     local point = part:Clone();
  499.     point.CFrame = CFrame.new(p);
  500.     point.BrickColor = BrickColor.Blue();
  501.     point.Parent = parent;
  502.     return point;
  503. end;
  504.  
  505. local function drawLine(a, b, parent)
  506.     local v = (b - a);
  507.     local cf = CFrame.new(a + v * 0.5, b);
  508.     local line = part:Clone();
  509.     line.CFrame = cf;
  510.     line.Size = Vector3.new(0.1, 0.1, v.magnitude);
  511.     line.BrickColor = BrickColor.Red();
  512.     line.Parent = parent;
  513.     return line;
  514. end
  515.  
  516. local function drawTriangle(a, b, c, parent, transparency)
  517.     local edges = {
  518.         {longest = (c - b), other = (a - b), position = b};
  519.         {longest = (a - c), other = (b - c), position = c};
  520.         {longest = (b - a), other = (c - a), position = a};
  521.     };
  522.     table.sort(edges, function(a, b) return a.longest.magnitude > b.longest.magnitude end);
  523.     local edge = edges[1];
  524.     local theta = math.acos(edge.longest.unit:Dot(edge.other.unit));
  525.     local s1 = Vector2.new(edge.other.magnitude * math.cos(theta), edge.other.magnitude * math.sin(theta));
  526.     local s2 = Vector2.new(edge.longest.magnitude - s1.x, s1.y);
  527.     local p1 = edge.position + edge.other * 0.5;
  528.     local p2 = edge.position + edge.longest + (edge.other - edge.longest) * 0.5;
  529.     local right = edge.longest:Cross(edge.other).unit;
  530.     local up = right:Cross(edge.longest).unit;
  531.     local back = edge.longest.unit;
  532.     local cf1 = CFrame.new(
  533.         p1.x, p1.y, p1.z,
  534.         -right.x, up.x, back.x,
  535.         -right.y, up.y, back.y,
  536.         -right.z, up.z, back.z
  537.     );
  538.     local cf2 = CFrame.new(
  539.         p2.x, p2.y, p2.z,
  540.         right.x, up.x, -back.x,
  541.         right.y, up.y, -back.y,
  542.         right.z, up.z, -back.z
  543.     );
  544.     local w1 = wedge:Clone();
  545.     local w2 = wedge:Clone();
  546.     w1.Size = Vector3.new(0.2, s1.y, s1.x);
  547.     w2.Size = Vector3.new(0.2, s2.y, s2.x);
  548.     w1.Transparency = transparency or 0;
  549.     w2.Transparency = transparency or 0;
  550.     w1.CFrame = cf1;
  551.     w2.CFrame = cf2;
  552.     w1.Parent = parent;
  553.     w2.Parent = parent;
  554. end;
  555.  
  556. return {
  557.     triangle = drawTriangle;
  558.     point = drawPoint;
  559.     line = drawLine;
  560. };
  561. end))
  562. ModuleScript6.Name = "vertices"
  563. ModuleScript6.Parent = ModuleScript2
  564. table.insert(cors,sandbox(ModuleScript6,function()
  565. -- calculate corners and points on shape
  566. -- useful for a lot of 3D math, eg convex hull, GJK, etc.
  567. -- EgoMoose
  568.  
  569. local cos = math.cos;
  570. local sin = math.sin;
  571. local insert = table.insert;
  572.  
  573. local cornerMultipliers = {
  574.     Vector3.new(1, 1, 1);
  575.     Vector3.new(1, 1, -1);
  576.     Vector3.new(1, -1, -1);
  577.     Vector3.new(-1, -1, -1);
  578.     Vector3.new(-1, -1, 1);
  579.     Vector3.new(-1, 1, 1);
  580.     Vector3.new(-1, 1, -1);
  581.     Vector3.new(1, -1, 1);
  582. }
  583.  
  584. -- the functions that get the vertices
  585.  
  586. local function block(cf, size, t)
  587.     for i = 1, #cornerMultipliers do
  588.         insert(t, cf * (size * cornerMultipliers[i]));
  589.     end
  590.     return t;
  591. end;
  592.  
  593. local WEDGE = {1, 3, 4, 5, 6, 8};
  594. local function wedge(cf, size, t)
  595.     for i = 1, #WEDGE do
  596.         insert(t, cf * (size * cornerMultipliers[WEDGE[i]]));
  597.     end;
  598.     return t;
  599. end;
  600.  
  601. local CORNERWEDGE = {2, 3, 4, 5, 8};
  602. local function cornerWedge(cf, size, t)
  603.     for i = 1, #CORNERWEDGE do
  604.         insert(t, cf * (size * cornerMultipliers[CORNERWEDGE[i]]));
  605.     end;
  606.     return t;
  607. end;
  608.  
  609. local PI2 = math.pi * 2;
  610. local function cylinder(cf, size, t, amt)
  611.     local amt = amt or 10;
  612.     local div = PI2 / amt;
  613.     local c1, c2 = cf * (size * Vector3.new(1, 0, 0)), cf * (size * Vector3.new(-1, 0, 0));
  614.     local up, axis = cf * (size * Vector3.new(1, 1, 0)) - c1, (c1 - cf.p).unit;
  615.     for i = 1, amt do
  616.         local theta = div * i;
  617.         -- vector axis angle rotation
  618.         local v = up * cos(theta) + up:Dot(axis) * axis * (1 - cos(theta)) + axis:Cross(up) * sin(theta);
  619.         insert(t, c1 + v);
  620.         insert(t, c2 + v);
  621.     end;
  622.     return t;
  623. end;
  624.  
  625. local function ball(cf, size, t, amt1, amt2)
  626.     local right, forward, up = cf.rightVector * size.x, cf.lookVector * size.z, cf.upVector * size.y;
  627.     local amt1, amt2 = amt1 or 8, amt2 or 8;
  628.     local div1, div2 = PI2 / amt1, PI2 / amt2;
  629.     for i = 1, amt1 do
  630.         local theta = i * div1;
  631.         local horizontal = forward * cos(theta) + right * sin(theta);
  632.         for j = 1, amt2 do
  633.             local theta2 = j * div2;
  634.             local p = cf.p + horizontal * cos(theta2) + up * sin(theta2);
  635.             insert(t, p)
  636.         end;
  637.     end;
  638.     return t;
  639. end;
  640.  
  641. -- special functions
  642.  
  643. local function getAllVertices(parts, t)
  644.     local t = t or {};
  645.     for i = 1, #parts do
  646.         local part = parts[i];
  647.         if (part.ClassName == "Part") then
  648.             if (part.Shape == Enum.PartType.Block) then
  649.                 block(part.CFrame, part.Size*0.5, t);
  650.             elseif (part.Shape == Enum.PartType.Cylinder) then
  651.                 cylinder(part.CFrame, part.Size*0.5, t);
  652.             elseif (part.Shape == Enum.PartType.Ball) then
  653.                 ball(part.CFrame, part.Size*0.5, t);
  654.             end;
  655.         elseif (part.ClassName == "WedgePart") then
  656.             wedge(part.CFrame, part.Size*0.5, t);
  657.         elseif (part.ClassName == "CornerWedgePart") then
  658.             cornerWedge(part.CFrame, part.Size*0.5, t);
  659.         elseif (part:IsA("BasePart")) then -- mesh, CSG, truss, etc... just use block
  660.             block(part.CFrame, part.Size*0.5, t);
  661.         end;
  662.     end;
  663.     return t;
  664. end;
  665.  
  666. -- module
  667.  
  668. return {
  669.     block = block;
  670.     wedge = wedge;
  671.     cornerWedge = cornerWedge;
  672.     cylinder = cylinder;
  673.     ball = ball;
  674.     getAllVertices = getAllVertices;
  675. };
  676. end))
  677. for i,v in pairs(mas:GetChildren()) do
  678.     v.Parent = game:GetService("Lighting")
  679.     pcall(function() v:MakeJoints() end)
  680. end
  681. mas:Destroy()
  682. for i,v in pairs(cors) do
  683.     spawn(function()
  684.         pcall(v)
  685.     end)
  686. end
  687.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement