Potato228

onLockMy

Mar 29th, 2023 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.95 KB | None | 0 0
  1.  
  2. local Library = {};
  3.  
  4. local Camera = workspace.CurrentCamera;
  5. local ToScreen = Camera.WorldToViewportPoint;
  6.  
  7. local RS = game:GetService("RunService");
  8.  
  9. local nVector3 = Vector3.new;
  10. local nVector2 = Vector2.new;
  11. local nDrawing = Drawing.new;
  12. local nColor = Color3.fromRGB;
  13. local nCFrame = CFrame.new;
  14. local nCFAngles = CFrame.Angles;
  15.  
  16. local rad = math.rad;
  17. local pi = math.pi;
  18. local round = math.round;
  19.  
  20. local Insert = table.insert;
  21. local Char = string.char;
  22. local Random = math.random;
  23. local Seed = math.randomseed;
  24. local Time = os.time;
  25.  
  26. local charset = {};
  27.  
  28. for i = 48, 57 do Insert(charset, Char(i)) end;
  29. for i = 65, 90 do Insert(charset, Char(i)) end;
  30. for i = 97, 122 do Insert(charset, Char(i)) end;
  31.  
  32. local function random_string(length)
  33. Seed(Time());
  34.  
  35. if length > 0 then
  36. return random_string(length - 1) .. charset[Random(1, #charset)];
  37. else
  38. return "";
  39. end;
  40. end;
  41.  
  42. local function checkCamView(pos)
  43. return ((pos - Camera.CFrame.Position).Unit):Dot(Camera.CFrame.LookVector) > 0;
  44. end
  45.  
  46. function Library:New3DLine()
  47. local _line = {
  48. Visible = false;
  49. ZIndex = 1;
  50. Transparency = 1;
  51. Color = nColor(255, 255, 255);
  52. Thickness = 1;
  53. From = nVector3(0,0,0);
  54. To = nVector3(0,0,0);
  55. };
  56. local _defaults = _line;
  57. _line.line = nDrawing("Line");
  58.  
  59. -- Update Step Function --
  60. function _line:Update()
  61. if not _line.Visible then
  62. _line.line.Visible = false;
  63. else
  64. _line.line.Visible = _line.Visible or _defaults.Visible;
  65. _line.line.ZIndex = _line.ZIndex or _defaults.ZIndex;
  66. _line.line.Transparency = _line.Transparency or _defaults.Transparency;
  67. _line.line.Color = _line.Color or _defaults.Color;
  68. _line.line.Thickness = _line.Thickness or _defaults.Thickness;
  69.  
  70. local _from, v1 = ToScreen(Camera, _line.From);
  71. local _to, v2 = ToScreen(Camera, _line.To);
  72.  
  73. if (v1 and v2) or (checkCamView(_line.From) and checkCamView(_line.To)) then
  74. _line.line.From = nVector2(_from.x, _from.y);
  75. _line.line.To = nVector2(_to.x, _to.y);
  76. else
  77. _line.line.Visible = false;
  78. end;
  79. end
  80. end;
  81. --------------------------
  82.  
  83. local step_Id = "3D_Line"..random_string(10);
  84. RS:BindToRenderStep(step_Id, 1, _line.Update);
  85.  
  86. -- Remove Line --
  87. function _line:Remove()
  88. RS:UnbindFromRenderStep(step_Id);
  89.  
  90. self.line:Remove();
  91. end;
  92. -----------------
  93.  
  94. return _line;
  95. end;
  96.  
  97. function Library:New3DCube()
  98. local _cube = {
  99. Visible = false;
  100. ZIndex = 1;
  101. Transparency = 1;
  102. Color = nColor(255, 255, 255);
  103. Thickness = 1;
  104. Filled = true;
  105.  
  106. Position = nVector3(0,0,0);
  107. Size = nVector3(0,0,0);
  108. Rotation = nVector3(0,0,0);
  109. };
  110. local _defaults = _cube;
  111. for f = 1, 6 do
  112. _cube["face"..tostring(f)] = nDrawing("Quad");
  113. end;
  114.  
  115. -- Update Step Function --
  116. function _cube:Update()
  117. if not _cube.Visible then
  118. for f = 1, 6 do
  119. _cube["face"..tostring(f)].Visible = false;
  120. end;
  121. else
  122. for f = 1, 6 do
  123. f = "face"..tostring(f)
  124. _cube[f].Visible = _cube.Visible or _defaults.Visible;
  125. _cube[f].ZIndex = _cube.ZIndex or _defaults.ZIndex;
  126. _cube[f].Transparency = _cube.Transparency or _defaults.Transparency;
  127. _cube[f].Color = _cube.Color or _defaults.Color;
  128. _cube[f].Thickness = _cube.Thickness or _defaults.Thickness;
  129. _cube[f].Filled = _cube.Filled or _defaults.Filled;
  130. end;
  131.  
  132. local rot = _cube.Rotation or _defaults.Rotation;
  133. local pos = _cube.Position or _defaults.Position;
  134. local _rotCFrame = nCFrame(pos) * nCFAngles(rad(rot.X), rad(rot.Y), rad(rot.Z));
  135.  
  136. local _size = _cube.Size or _defaults.Size;
  137. local _points = {
  138. [1] = (_rotCFrame * nCFrame(_size.X, _size.Y, _size.Z)).p;
  139. [2] = (_rotCFrame * nCFrame(_size.X, _size.Y, -_size.Z)).p;
  140. [3] = (_rotCFrame * nCFrame(_size.X, -_size.Y, _size.Z)).p;
  141. [4] = (_rotCFrame * nCFrame(_size.X, -_size.Y, -_size.Z)).p;
  142. [5] = (_rotCFrame * nCFrame(-_size.X, _size.Y, _size.Z)).p;
  143. [6] = (_rotCFrame * nCFrame(-_size.X, _size.Y, -_size.Z)).p;
  144. [7] = (_rotCFrame * nCFrame(-_size.X, -_size.Y, _size.Z)).p;
  145. [8] = (_rotCFrame * nCFrame(-_size.X, -_size.Y, -_size.Z)).p;
  146. };
  147.  
  148. local _vis = true;
  149.  
  150. for p = 1, #_points do
  151. local _p, v = ToScreen(Camera, _points[p]);
  152. local _stored = _points[p];
  153. _points[p] = nVector2(_p.x, _p.y);
  154.  
  155. if not v and not checkCamView(_stored) then
  156. _vis = false;
  157. break;
  158. end;
  159. end;
  160.  
  161. if _vis then
  162. _cube.face1.PointA = _points[1]; -- Side
  163. _cube.face1.PointB = _points[2];
  164. _cube.face1.PointC = _points[4];
  165. _cube.face1.PointD = _points[3];
  166.  
  167. _cube.face2.PointA = _points[5]; -- Side
  168. _cube.face2.PointB = _points[6];
  169. _cube.face2.PointC = _points[8];
  170. _cube.face2.PointD = _points[7];
  171.  
  172. _cube.face3.PointA = _points[1]; -- Side
  173. _cube.face3.PointB = _points[5];
  174. _cube.face3.PointC = _points[7];
  175. _cube.face3.PointD = _points[3];
  176.  
  177. _cube.face4.PointA = _points[2]; -- Side
  178. _cube.face4.PointB = _points[4];
  179. _cube.face4.PointC = _points[8];
  180. _cube.face4.PointD = _points[6];
  181.  
  182. _cube.face5.PointA = _points[1]; -- Top
  183. _cube.face5.PointB = _points[2];
  184. _cube.face5.PointC = _points[6];
  185. _cube.face5.PointD = _points[5];
  186.  
  187. _cube.face6.PointA = _points[3]; -- Bottom
  188. _cube.face6.PointB = _points[4];
  189. _cube.face6.PointC = _points[8];
  190. _cube.face6.PointD = _points[7];
  191. else
  192. for f = 1, 6 do
  193. _cube["face"..tostring(f)].Visible = false;
  194. end;
  195. end;
  196. end;
  197. end;
  198. --------------------------
  199.  
  200. local step_Id = "3D_Cube"..random_string(10);
  201. RS:BindToRenderStep(step_Id, 1, _cube.Update);
  202.  
  203. -- Remove Cube --
  204. function _cube:Remove()
  205. RS:UnbindFromRenderStep(step_Id);
  206.  
  207. for f = 1, 6 do
  208. self["face"..tostring(f)]:Remove();
  209. end;
  210. end;
  211. -----------------
  212.  
  213. return _cube;
  214. end;
  215.  
  216. function Library:New3DSquare()
  217. local _square = {
  218. Visible = false;
  219. ZIndex = 1;
  220. Transparency = 1;
  221. Color = nColor(255, 255, 255);
  222. Thickness = 1;
  223. Filled = true;
  224.  
  225. Position = nVector3(0,0,0);
  226. Size = nVector2(0,0);
  227. Rotation = nVector3(0,0,0);
  228. }
  229. local _defaults = _square;
  230. _square.square = nDrawing("Quad");
  231.  
  232. -- Update Step Function --
  233. function _square:Update()
  234. if not _square.Visible then
  235. _square.square.Visible = false;
  236. else
  237. _square.square.Visible = _square.Visible or _defaults.Visible;
  238. _square.square.ZIndex = _square.ZIndex or _defaults.ZIndex;
  239. _square.square.Transparency = _square.Transparency or _defaults.Transparency;
  240. _square.square.Color = _square.Color or _defaults.Color;
  241. _square.square.Thickness = _square.Thickness or _defaults.Thickness;
  242. _square.square.Filled = _square.Filled or _defaults.Filled;
  243.  
  244. local rot = _square.Rotation or _defaults.Rotation;
  245. local pos = _square.Position or _defaults.Position;
  246. local _rotCFrame = nCFrame(pos) * nCFAngles(rad(rot.X), rad(rot.Y), rad(rot.Z));
  247.  
  248. local _size = _square.Size or _defaults.Size;
  249. local _points = {
  250. [1] = (_rotCFrame * nCFrame(_size.X, 0, _size.Y)).p;
  251. [2] = (_rotCFrame * nCFrame(_size.X, 0, -_size.Y)).p;
  252. [3] = (_rotCFrame * nCFrame(-_size.X, 0, _size.Y)).p;
  253. [4] = (_rotCFrame * nCFrame(-_size.X, 0, -_size.Y)).p;
  254. };
  255.  
  256. local _vis = true;
  257.  
  258. for p = 1, #_points do
  259. local _p, v = ToScreen(Camera, _points[p]);
  260. local _stored = _points[p];
  261. _points[p] = nVector2(_p.x, _p.y);
  262.  
  263. if not v and not checkCamView(_stored) then
  264. _vis = false;
  265. break;
  266. end;
  267. end;
  268.  
  269. if _vis then
  270. _square.square.PointA = _points[1];
  271. _square.square.PointB = _points[2];
  272. _square.square.PointC = _points[4];
  273. _square.square.PointD = _points[3];
  274. else
  275. _square.square.Visible = false;
  276. end;
  277. end;
  278. end;
  279. --------------------------
  280.  
  281. local step_Id = "3D_Square"..random_string(10);
  282. RS:BindToRenderStep(step_Id, 1, _square.Update);
  283.  
  284. -- Remove Square --
  285. function _square:Remove()
  286. RS:UnbindFromRenderStep(step_Id);
  287.  
  288. _square.square:Remove();
  289. end;
  290. -----------------
  291.  
  292. return _square;
  293. end;
  294.  
  295. function Library:New3DCircle()
  296. local _circle = {
  297. Visible = false;
  298. ZIndex = 1;
  299. Transparency = 1;
  300. Color = nColor(255, 255, 255);
  301. Thickness = 1;
  302.  
  303. Position = nVector3(0,0,0);
  304. Radius = 10;
  305. Rotation = nVector2(0,0);
  306. };
  307. local _defaults = _circle;
  308. local _lines = {};
  309.  
  310. local function makeNewLines(r)
  311. for l = 1, #_lines do
  312. _lines[l]:Remove();
  313. end;
  314.  
  315. _lines = {};
  316.  
  317. for l = 1, 1.5*r*pi do
  318. _lines[l] = nDrawing("Line");
  319. end;
  320. end;
  321.  
  322. -- Update Step Function --
  323. local previousR = _circle.Radius or _defaults.Radius;
  324. makeNewLines(previousR);
  325.  
  326. function _circle:Update()
  327. local rot = _circle.Rotation or _defaults.Rotation;
  328. local pos = _circle.Position or _defaults.Position;
  329. local _rotCFrame = nCFrame(pos) * nCFAngles(rad(rot.X), 0, rad(rot.Y));
  330.  
  331. local _radius = _circle.Radius or _defaults.Radius;
  332. if previousR ~= _radius then makeNewLines(_radius) end;
  333.  
  334. local _increm = 360/#_lines;
  335.  
  336. if not _circle.Visible then
  337. for ln = 1, #_lines do
  338. _lines[ln].Visible = false;
  339. end;
  340. else
  341. for l = 1, #_lines do
  342. if _lines[l] and rawget(_lines[l], "__OBJECT_EXISTS") then
  343. _lines[l].Visible = _circle.Visible or _defaults.Visible;
  344. _lines[l].ZIndex = _circle.ZIndex or _defaults.ZIndex;
  345. _lines[l].Transparency = _circle.Transparency or _defaults.Transparency;
  346. _lines[l].Color = _circle.Color or _defaults.Color;
  347. _lines[l].Thickness = _circle.Thickness or _defaults.Thickness;
  348.  
  349. local p1 = (_rotCFrame * nCFrame(0, 0, -_radius)).p;
  350. local _previousPosition, v1 = ToScreen(Camera, p1);
  351.  
  352. _rotCFrame = _rotCFrame * nCFAngles(0, rad(_increm), 0);
  353.  
  354. local p2 = (_rotCFrame * nCFrame(0, 0, -_radius)).p;
  355. local _nextPosition, v2 = ToScreen(Camera, p2);
  356.  
  357. if (v1 and v2) or (checkCamView(p1) and checkCamView(p2)) then
  358. _lines[l].From = nVector2(_previousPosition.x, _previousPosition.y);
  359. _lines[l].To = nVector2(_nextPosition.x, _nextPosition.y);
  360. else
  361. _lines[l].Visible = false;
  362. end;
  363. end;
  364. end;
  365. end;
  366.  
  367. previousR = _circle.Radius or _defaults.Radius;
  368. end;
  369. --------------------------
  370.  
  371. local step_Id = "3D_Circle"..random_string(10);
  372. RS:BindToRenderStep(step_Id, 1, _circle.Update);
  373.  
  374. -- Remove Circle --
  375. function _circle:Remove()
  376. RS:UnbindFromRenderStep(step_Id)
  377.  
  378. for ln = 1, #_lines do
  379. _lines[ln]:Remove();
  380. end;
  381. end;
  382. -----------------
  383.  
  384. return _circle;
  385. end;
  386.  
  387. return Library;
Add Comment
Please, Sign In to add comment