Advertisement
CheezusCrust

Untitled

Dec 24th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. @name 3D Scanner V3
  2. @outputs X Y XAng YAng
  3. @persist Res Dist FOV Perf Scanning RangerFilter:array Ranger:ranger Screen:wirelink Texture:table
  4. @trigger
  5.  
  6. #------------------------------------------Function definitions, don't touch------------------------------------------#
  7. if(first()) {
  8. function wirelink:initScreen(Res){ #Initialize the screen
  9. #I don't actually know what any of these do, I pulled them from some other E2. I just know they make it work right.
  10. This[1048574]=0
  11. This[1048569]=3
  12. This[1048575]=1
  13. This[1048572]=Res
  14. This[1048573]=Res
  15. }
  16.  
  17. function wirelink:drawPixel(X,Y,Color:vector){ #Drawing function
  18. This[X+Y*Res]=rgb2digi(Color,3)
  19. }
  20. }
  21.  
  22. #------------------------------------------Texture color definitions------------------------------------------#
  23. if(first()) {
  24. #SYNTAX: vec( Red, Green, Blue, Noise Level )
  25.  
  26. Texture["default",vector4] = vec4(85, 156, 185, 0)
  27. Texture["grass",vector4] = vec4(44, 176, 55, 5)
  28. Texture["sand",vector4] = vec4(237, 201, 175, 0)
  29. Texture["metal",vector4] = vec4(172, 182, 190, 2)
  30. Texture["grate",vector4] = vec4(175, 175, 175, 6)
  31. Texture["concrete",vector4] = vec4(200, 200, 200, 3)
  32. Texture["dirt",vector4] = vec4(180, 147, 116, 2)
  33. Texture["snow",vector4] = vec4(235, 235, 235, 1)
  34. Texture["tile",vector4] = vec4(215, 215, 215, 2)
  35. Texture["wood",vector4] = vec4(130, 82, 1, 0)
  36. Texture["ice",vector4] = vec4(165, 242, 243, 1)
  37. Texture["slosh",vector4] = vec4(64, 164, 223, 0)
  38. }
  39.  
  40. #------------------------------------------User configurable defaults------------------------------------------#
  41. if(first()) {
  42. Res = 256 #Default render resolution. Must be a power of two.
  43. FOV = 45 #Default field of view, in degrees.
  44. Dist = 500 #Distance at which the scan will be entirely black (soon to be deprecated!)
  45. Perf = 100 #Default performance setting, 100 being 100% (max)
  46. rangerHitWater(1) #Should the ranger hit water?
  47. }
  48.  
  49. #------------------------------------------Initial setup stuff------------------------------------------#
  50. if(first()) {
  51. Screen = entity():isWeldedTo():wirelink()
  52. Screen:initScreen(Res)
  53.  
  54. #Hologram to determine if the screen is upright or not
  55. holoCreate(0,Screen:entity():toWorld(vec(0,0,-10)),vec(1),Screen:entity():toWorld(ang(-90,0,0)))
  56. holoColor(0,vec(0,255,0))
  57. holoModel(0,"hqcone")
  58. holoParent(0,Screen:entity())
  59. holoAlpha(0,125)
  60.  
  61. #Don't want people to fly infront of your scan and ruin it!
  62. RangerFilter = players()
  63. rangerPersist(1)
  64. rangerFilter(RangerFilter)
  65.  
  66. print("[3D Scanner] Type /help in chat for scanner commands!")
  67. }
  68.  
  69. runOnChat(1)
  70. runOnTick(1)
  71.  
  72. #------------------------------------------Chat commands------------------------------------------#
  73. if(chatClk(owner())) {
  74. C = lastSaid():explode(" ")
  75. if(C[1,string] == "/reset") {
  76. hideChat(1)
  77. Screen:initScreen(Res)
  78. Scanning = 0
  79. X = 0
  80. Y = 0
  81. }
  82. if(C[1,string] == "/scan") {
  83. hideChat(1)
  84. if(!Scanning) {
  85. print("[3D Scanner] Scan started! Look at E2 for scan progress")
  86.  
  87. Screen:initScreen(Res)
  88. Scanning = 1
  89. holoCreate(1,Screen:entity():toWorld(vec(0,0,-10)),vec(0.25),Screen:entity():toWorld(ang(0,0,0)))
  90. holoParent(1,Screen:entity())
  91.  
  92. holoCreate(2)
  93. holoModel(2,"icosphere3")
  94. holoScale(2,vec(0.25))
  95. holoColor(2,vec(255,0,0))
  96. holoParent(2,Screen:entity())
  97. }
  98. }
  99. if(C[1,string] == "/fov") {
  100. hideChat(1)
  101. if(!Scanning) {
  102. N = C[2,string]:toNumber()
  103. if(N & N > 0 & N < 180) {
  104. FOV = N
  105. print("[3D Scanner] FOV set to " + N + " degrees")
  106. } else {
  107. print("[3D Scanner] Invalid FOV!")
  108. }
  109. }
  110. }
  111. if(C[1,string] == "/res") {
  112. hideChat(1)
  113. N = C[2,string]:toNumber()
  114. if((N && (N - 1)) == 0 & N > 1 & N <= 512) { #Check whether the number is between 2 and 512, and that it's a power of two
  115. Res = N
  116. print("[3D Scanner] Scan resolution set to " + N + "x" + N)
  117. } else {
  118. print("[3D Scanner] Invalid scan resolution!")
  119. }
  120. }
  121. if(C[1,string] == "/perf") {
  122. hideChat(1)
  123. N = C[2,string]:toNumber()
  124. if(N > 0 & N <= 100) {
  125. Perf = N
  126. print("[3D Scanner] Performance limit set to " + N + "% of tick quota")
  127. } else {
  128. print("[3D Scanner] Invalid performance setting!")
  129. }
  130. }
  131. if(C[1,string] == "/dist") {
  132. hideChat(1)
  133. N = C[2,string]:toNumber()
  134. if(N > 0) {
  135. Dist = N
  136. print("[3D Scanner] Scan distance set to " + N + " source units")
  137. } else {
  138. print("[3D Scanner] Invalid scan distance!")
  139. }
  140. }
  141. if(C[1,string] == "/help") {
  142. hideChat(1)
  143. print("[3D Scanner] Commands:")
  144. print("/scan - Start a new scan with current settings")
  145. print("/fov X - Set field of view to X")
  146. print("/res X - Set resolution to X pixels by X pixels (power of 2s only)")
  147. print("/perf X - Set performance limit to X % of the tick quota - 100 max")
  148. print("/dist X - Set max distance to X (everything black beyond this dist")
  149. }
  150. }
  151.  
  152. #------------------------------------------Scanning------------------------------------------#
  153. while(Scanning & perf(Perf)) {
  154. setName("3D Scanner V3 - " + floor((Y / Res) * 100) + "%")
  155.  
  156. XAng = (((X/(Res-1))*2)-1)*FOV
  157. YAng = (((Y/(Res-1))*2)-1)*FOV
  158.  
  159. holoAng(1,Screen:entity():toWorld(ang(-YAng, 0, XAng)))
  160.  
  161. Ranger = rangerOffset(999999999,holoEntity(1):pos(),holoEntity(1):up()*-1)
  162.  
  163. holoPos(2, Ranger:position())
  164.  
  165. if(Ranger:hitWorld()) {
  166. if(Ranger:hitSky()) {
  167. Color = vec(Texture["default", vector4]:x(), Texture["default", vector4]:y(), Texture["default", vector4]:z()) + ((Y / Res) * 100)
  168. } else {
  169. if(Ranger:distance() < Dist - 25) {
  170. if(Texture[Ranger:matType(), vector4]) {
  171. Color = vec(Texture[Ranger:matType(), vector4]:x(), Texture[Ranger:matType(), vector4]:y(), Texture[Ranger:matType(), vector4]:z())*abs(1-(clamp(Ranger:distance()/Dist,0,1))) + vec(randint(-Texture[Ranger:matType(), vector4]:w(), Texture[Ranger:matType(), vector4]:w()))
  172. } else {
  173. Color = vec(255)*abs(1-(clamp(Ranger:distance()/Dist,0,1)))
  174. }
  175. } else {
  176. Color = vec(0)
  177. }
  178. }
  179. } else {
  180. Color = Ranger:entity():getColor()*abs(1-(clamp(Ranger:distance()/Dist,0,1)))
  181. }
  182.  
  183. Screen:drawPixel(X, Y, Color)
  184.  
  185. #Screen:drawPixel(X, Y, vec(255)*(abs(1-(clamp(Ranger:distance()/Dist,0,1)))*hsv2rgb(vec(X%360,1,1)))) #LSD MODE!
  186.  
  187. if(X < Res) {
  188. X++
  189. }
  190. if(X > Res - 1) {
  191. X = 0
  192. Y++
  193. }
  194. if(Y > Res - 1) {
  195. Scanning = 0
  196. holoDelete(1)
  197. holoDelete(2)
  198. X = 0
  199. Y = 0
  200. setName("3D Scanner V3")
  201. break
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement