Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name 3D Scanner V3
- @outputs X Y XAng YAng
- @persist Res Dist FOV Perf Scanning RangerFilter:array Ranger:ranger Screen:wirelink Texture:table
- @trigger
- #------------------------------------------Function definitions, don't touch------------------------------------------#
- if(first()) {
- function wirelink:initScreen(Res){ #Initialize the screen
- #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.
- This[1048574]=0
- This[1048569]=3
- This[1048575]=1
- This[1048572]=Res
- This[1048573]=Res
- }
- function wirelink:drawPixel(X,Y,Color:vector){ #Drawing function
- This[X+Y*Res]=rgb2digi(Color,3)
- }
- }
- #------------------------------------------Texture color definitions------------------------------------------#
- if(first()) {
- #SYNTAX: vec( Red, Green, Blue, Noise Level )
- Texture["default",vector4] = vec4(85, 156, 185, 0)
- Texture["grass",vector4] = vec4(44, 176, 55, 5)
- Texture["sand",vector4] = vec4(237, 201, 175, 0)
- Texture["metal",vector4] = vec4(172, 182, 190, 2)
- Texture["grate",vector4] = vec4(175, 175, 175, 6)
- Texture["concrete",vector4] = vec4(200, 200, 200, 3)
- Texture["dirt",vector4] = vec4(180, 147, 116, 2)
- Texture["snow",vector4] = vec4(235, 235, 235, 1)
- Texture["tile",vector4] = vec4(215, 215, 215, 2)
- Texture["wood",vector4] = vec4(130, 82, 1, 0)
- Texture["ice",vector4] = vec4(165, 242, 243, 1)
- Texture["slosh",vector4] = vec4(64, 164, 223, 0)
- }
- #------------------------------------------User configurable defaults------------------------------------------#
- if(first()) {
- Res = 256 #Default render resolution. Must be a power of two.
- FOV = 45 #Default field of view, in degrees.
- Dist = 500 #Distance at which the scan will be entirely black (soon to be deprecated!)
- Perf = 100 #Default performance setting, 100 being 100% (max)
- rangerHitWater(1) #Should the ranger hit water?
- }
- #------------------------------------------Initial setup stuff------------------------------------------#
- if(first()) {
- Screen = entity():isWeldedTo():wirelink()
- Screen:initScreen(Res)
- #Hologram to determine if the screen is upright or not
- holoCreate(0,Screen:entity():toWorld(vec(0,0,-10)),vec(1),Screen:entity():toWorld(ang(-90,0,0)))
- holoColor(0,vec(0,255,0))
- holoModel(0,"hqcone")
- holoParent(0,Screen:entity())
- holoAlpha(0,125)
- #Don't want people to fly infront of your scan and ruin it!
- RangerFilter = players()
- rangerPersist(1)
- rangerFilter(RangerFilter)
- print("[3D Scanner] Type /help in chat for scanner commands!")
- }
- runOnChat(1)
- runOnTick(1)
- #------------------------------------------Chat commands------------------------------------------#
- if(chatClk(owner())) {
- C = lastSaid():explode(" ")
- if(C[1,string] == "/reset") {
- hideChat(1)
- Screen:initScreen(Res)
- Scanning = 0
- X = 0
- Y = 0
- }
- if(C[1,string] == "/scan") {
- hideChat(1)
- if(!Scanning) {
- print("[3D Scanner] Scan started! Look at E2 for scan progress")
- Screen:initScreen(Res)
- Scanning = 1
- holoCreate(1,Screen:entity():toWorld(vec(0,0,-10)),vec(0.25),Screen:entity():toWorld(ang(0,0,0)))
- holoParent(1,Screen:entity())
- holoCreate(2)
- holoModel(2,"icosphere3")
- holoScale(2,vec(0.25))
- holoColor(2,vec(255,0,0))
- holoParent(2,Screen:entity())
- }
- }
- if(C[1,string] == "/fov") {
- hideChat(1)
- if(!Scanning) {
- N = C[2,string]:toNumber()
- if(N & N > 0 & N < 180) {
- FOV = N
- print("[3D Scanner] FOV set to " + N + " degrees")
- } else {
- print("[3D Scanner] Invalid FOV!")
- }
- }
- }
- if(C[1,string] == "/res") {
- hideChat(1)
- N = C[2,string]:toNumber()
- 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
- Res = N
- print("[3D Scanner] Scan resolution set to " + N + "x" + N)
- } else {
- print("[3D Scanner] Invalid scan resolution!")
- }
- }
- if(C[1,string] == "/perf") {
- hideChat(1)
- N = C[2,string]:toNumber()
- if(N > 0 & N <= 100) {
- Perf = N
- print("[3D Scanner] Performance limit set to " + N + "% of tick quota")
- } else {
- print("[3D Scanner] Invalid performance setting!")
- }
- }
- if(C[1,string] == "/dist") {
- hideChat(1)
- N = C[2,string]:toNumber()
- if(N > 0) {
- Dist = N
- print("[3D Scanner] Scan distance set to " + N + " source units")
- } else {
- print("[3D Scanner] Invalid scan distance!")
- }
- }
- if(C[1,string] == "/help") {
- hideChat(1)
- print("[3D Scanner] Commands:")
- print("/scan - Start a new scan with current settings")
- print("/fov X - Set field of view to X")
- print("/res X - Set resolution to X pixels by X pixels (power of 2s only)")
- print("/perf X - Set performance limit to X % of the tick quota - 100 max")
- print("/dist X - Set max distance to X (everything black beyond this dist")
- }
- }
- #------------------------------------------Scanning------------------------------------------#
- while(Scanning & perf(Perf)) {
- setName("3D Scanner V3 - " + floor((Y / Res) * 100) + "%")
- XAng = (((X/(Res-1))*2)-1)*FOV
- YAng = (((Y/(Res-1))*2)-1)*FOV
- holoAng(1,Screen:entity():toWorld(ang(-YAng, 0, XAng)))
- Ranger = rangerOffset(999999999,holoEntity(1):pos(),holoEntity(1):up()*-1)
- holoPos(2, Ranger:position())
- if(Ranger:hitWorld()) {
- if(Ranger:hitSky()) {
- Color = vec(Texture["default", vector4]:x(), Texture["default", vector4]:y(), Texture["default", vector4]:z()) + ((Y / Res) * 100)
- } else {
- if(Ranger:distance() < Dist - 25) {
- if(Texture[Ranger:matType(), vector4]) {
- 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()))
- } else {
- Color = vec(255)*abs(1-(clamp(Ranger:distance()/Dist,0,1)))
- }
- } else {
- Color = vec(0)
- }
- }
- } else {
- Color = Ranger:entity():getColor()*abs(1-(clamp(Ranger:distance()/Dist,0,1)))
- }
- Screen:drawPixel(X, Y, Color)
- #Screen:drawPixel(X, Y, vec(255)*(abs(1-(clamp(Ranger:distance()/Dist,0,1)))*hsv2rgb(vec(X%360,1,1)))) #LSD MODE!
- if(X < Res) {
- X++
- }
- if(X > Res - 1) {
- X = 0
- Y++
- }
- if(Y > Res - 1) {
- Scanning = 0
- holoDelete(1)
- holoDelete(2)
- X = 0
- Y = 0
- setName("3D Scanner V3")
- break
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement