Advertisement
scriptingtales

Roblox Superliminal Perspective trick test

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