overlay glasses
This commit is contained in:
@@ -1,21 +1,31 @@
|
|||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local itemDB = require('core.itemDB')
|
local itemDB = require('core.itemDB')
|
||||||
local Project = require('neural.project')
|
local UI = require('ui')
|
||||||
local UI = require('ui')
|
local Util = require('util')
|
||||||
local Util = require('util')
|
|
||||||
|
|
||||||
local peripheral = _G.peripheral
|
local device = _G.device
|
||||||
|
local gps = _G.gps
|
||||||
|
local parallel = _G.parallel
|
||||||
|
|
||||||
local scanner =
|
local glasses = device['plethora:glasses']
|
||||||
peripheral.find('neuralInterface') or
|
local scanner = device['plethora:scanner'] or
|
||||||
peripheral.find('plethora:scanner') or
|
|
||||||
peripheral.find('manipulator')
|
|
||||||
|
|
||||||
if not scanner or not scanner.scan then
|
|
||||||
error('Plethora scanner must be equipped')
|
error('Plethora scanner must be equipped')
|
||||||
|
|
||||||
|
local target
|
||||||
|
local projecting = { }
|
||||||
|
|
||||||
|
local function getPoint()
|
||||||
|
local pt = { gps.locate() }
|
||||||
|
return {
|
||||||
|
x = pt[1],
|
||||||
|
y = pt[2],
|
||||||
|
z = pt[3],
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local projecting
|
local offset = getPoint()
|
||||||
|
local canvas = glasses and glasses.canvas3d().create()
|
||||||
|
--{ -(offset.x % 1), -(offset.y % 1), -(offset.z % 1) }
|
||||||
|
|
||||||
UI:configure('Scanner', ...)
|
UI:configure('Scanner', ...)
|
||||||
|
|
||||||
@@ -106,7 +116,7 @@ end
|
|||||||
|
|
||||||
function page.detail:eventHandler(event)
|
function page.detail:eventHandler(event)
|
||||||
if event.type == 'grid_select' then
|
if event.type == 'grid_select' then
|
||||||
projecting = event.selected
|
target = event.selected
|
||||||
else
|
else
|
||||||
return UI.SlideOut.eventHandler(self, event)
|
return UI.SlideOut.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
@@ -124,9 +134,10 @@ function page:eventHandler(event)
|
|||||||
self.detail:show(self.blocks, self.grid:getSelected())
|
self.detail:show(self.blocks, self.grid:getSelected())
|
||||||
|
|
||||||
elseif event.type == 'cancel' then
|
elseif event.type == 'cancel' then
|
||||||
if Project.canvas then
|
if canvas then
|
||||||
Project.canvas.clear()
|
canvas.clear()
|
||||||
projecting = nil
|
target = nil
|
||||||
|
projecting = { }
|
||||||
end
|
end
|
||||||
self.detail:hide()
|
self.detail:hide()
|
||||||
end
|
end
|
||||||
@@ -134,17 +145,54 @@ function page:eventHandler(event)
|
|||||||
UI.Page.eventHandler(self, event)
|
UI.Page.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
|
|
||||||
if scanner.canvas then
|
if canvas then
|
||||||
Project:init(scanner.canvas())
|
|
||||||
|
|
||||||
Event.onInterval(.5, function()
|
Event.onInterval(.5, function()
|
||||||
if projecting then
|
if target then
|
||||||
local blocks = scanner.scan()
|
local pos, scanned
|
||||||
local pts = Util.filter(blocks, function(b)
|
|
||||||
return b.name == projecting.name and b.metadata == projecting.metadata
|
parallel.waitForAll(
|
||||||
end)
|
function()
|
||||||
Project.canvas.clear()
|
pos = getPoint()
|
||||||
Project:drawPoints(scanner.getMetaOwner(), pts, true, 0xFFDF50AA)
|
end,
|
||||||
|
function()
|
||||||
|
scanned = scanner.scan()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
local blocks = Util.reduce(scanned, function(acc, b)
|
||||||
|
if b.name == target.name and b.metadata == target.metadata then
|
||||||
|
b.wx = math.floor(pos.x + b.x)
|
||||||
|
b.wy = math.floor(pos.y + b.y)
|
||||||
|
b.wz = math.floor(pos.z + b.z)
|
||||||
|
b.id = table.concat({ math.floor(b.wx), math.floor(b.wy), math.floor(b.wz) }, ':')
|
||||||
|
acc[b.id] = b
|
||||||
|
end
|
||||||
|
return acc
|
||||||
|
end, { })
|
||||||
|
|
||||||
|
for _, b in pairs(blocks) do
|
||||||
|
if not projecting[b.id] then
|
||||||
|
projecting[b.id] = b
|
||||||
|
b.box = canvas.addBox(
|
||||||
|
pos.x - offset.x + b.x + -(pos.x % 1) + .25,
|
||||||
|
pos.y - offset.y + b.y + -(pos.y % 1) + .25,
|
||||||
|
pos.z - offset.z + b.z + -(pos.z % 1) + .25,
|
||||||
|
.5, .5, .5)
|
||||||
|
b.box.setDepthTested(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, b in pairs(projecting) do
|
||||||
|
if not blocks[b.id] then
|
||||||
|
projecting[b.id].box.remove()
|
||||||
|
projecting[b.id] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- canvas.recenter({
|
||||||
|
-- offset.x - pos.x,
|
||||||
|
-- offset.y - pos.y,
|
||||||
|
-- offset.z - pos.z,
|
||||||
|
-- })
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -152,6 +200,6 @@ end
|
|||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
UI:pullEvents()
|
UI:pullEvents()
|
||||||
|
|
||||||
if projecting then
|
if canvas then
|
||||||
Project.canvas:clear()
|
canvas:clear()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ local module = device['plethora:kinetic'] or error('Missing kinetic')
|
|||||||
local Kinetic = Util.shallowCopy(module)
|
local Kinetic = Util.shallowCopy(module)
|
||||||
|
|
||||||
function Kinetic.lookAt(pt)
|
function Kinetic.lookAt(pt)
|
||||||
--local x = pt.x < 0 and pt.x + .5 or pt.x - .5
|
|
||||||
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
|
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
|
||||||
return Kinetic.look(yaw, pitch)
|
return Kinetic.look(yaw, pitch)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local Array = require('array')
|
local Array = require('array')
|
||||||
local kinetic = require('plethora.kinetic')
|
local kinetic = require('neural.kinetic')
|
||||||
local Point = require('point')
|
local Point = require('point')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
@@ -9,11 +9,11 @@ local pos = { x = 0, y = 0, z = 0 }
|
|||||||
local sensor = device['plethora:sensor'] or error('Missing sensor')
|
local sensor = device['plethora:sensor'] or error('Missing sensor')
|
||||||
local intro = device['plethora:introspection'] or error('Missing introspection module')
|
local intro = device['plethora:introspection'] or error('Missing introspection module')
|
||||||
|
|
||||||
local ID = intro.getMetaOwner()
|
local ownerId = intro.getMetaOwner().id
|
||||||
|
|
||||||
local function findTargets()
|
local function findTargets()
|
||||||
local l = Array.filter(sensor.sense(), function(a)
|
local l = Array.filter(sensor.sense(), function(a)
|
||||||
return math.abs(a.motionY) > 0 and ID ~= a.id
|
return math.abs(a.motionY) > 0 and ownerId ~= a.id
|
||||||
end)
|
end)
|
||||||
table.sort(l, function(e1, e2)
|
table.sort(l, function(e1, e2)
|
||||||
return Point.distance(e1, pos) < Point.distance(e2, pos)
|
return Point.distance(e1, pos) < Point.distance(e2, pos)
|
||||||
|
|||||||
107
neural/ores.lua
Normal file
107
neural/ores.lua
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
local gps = _G.gps
|
||||||
|
local keys = _G.keys
|
||||||
|
local os = _G.os
|
||||||
|
local parallel = _G.parallel
|
||||||
|
local peripheral = _G.peripheral
|
||||||
|
|
||||||
|
local modules = peripheral.find('neuralInterface')
|
||||||
|
if not modules then
|
||||||
|
error('Plethora scanner must be equipped')
|
||||||
|
elseif not modules.canvas then
|
||||||
|
error('Overlay glasses module is required')
|
||||||
|
elseif not modules.scan then
|
||||||
|
error('Scanner module is required')
|
||||||
|
end
|
||||||
|
|
||||||
|
local targets = {
|
||||||
|
["minecraft:emerald_ore"] = 0x46FF26AA,
|
||||||
|
["minecraft:diamond_ore"] = 0x50F8FFAA,
|
||||||
|
["minecraft:gold_ore"] = 0xFFDF50AA,
|
||||||
|
["minecraft:redstone_ore"] = 0xCC121566,
|
||||||
|
["minecraft:lit_redstone_ore"] = 0xCC121566,
|
||||||
|
["minecraft:iron_ore"] = 0xFFAC8766,
|
||||||
|
["minecraft:lapis_ore"] = 0x0A107F66,
|
||||||
|
["minecraft:coal_ore"] = 0x20202066,
|
||||||
|
["quark:biotite_ore"] = 0x02051C66,
|
||||||
|
["minecraft:quartz_ore"] = 0xCCCCCC66,
|
||||||
|
["minecraft:glowstone"] = 0xFFDFA166
|
||||||
|
}
|
||||||
|
local projecting = { }
|
||||||
|
|
||||||
|
local function getPoint()
|
||||||
|
local pt = { gps.locate() }
|
||||||
|
return {
|
||||||
|
x = pt[1],
|
||||||
|
y = pt[2],
|
||||||
|
z = pt[3],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local offset = getPoint()
|
||||||
|
local canvas = modules.canvas3d().create()
|
||||||
|
|
||||||
|
local function run()
|
||||||
|
while true do
|
||||||
|
|
||||||
|
-- order matters
|
||||||
|
local scanned = modules.scan()
|
||||||
|
local pos = getPoint()
|
||||||
|
|
||||||
|
local blocks = { }
|
||||||
|
for _, b in pairs(scanned) do
|
||||||
|
if targets[b.name] then
|
||||||
|
b.wx = math.floor(pos.x + b.x)
|
||||||
|
b.wy = math.floor(pos.y + b.y)
|
||||||
|
b.wz = math.floor(pos.z + b.z)
|
||||||
|
b.id = table.concat({ math.floor(b.wx), math.floor(b.wy), math.floor(b.wz) }, ':')
|
||||||
|
blocks[b.id] = b
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, b in pairs(blocks) do
|
||||||
|
if not projecting[b.id] then
|
||||||
|
projecting[b.id] = b
|
||||||
|
b.box = canvas.addBox(
|
||||||
|
pos.x - offset.x + b.x + -(pos.x % 1) + .25,
|
||||||
|
pos.y - offset.y + b.y + -(pos.y % 1) + .25,
|
||||||
|
pos.z - offset.z + b.z + -(pos.z % 1) + .25,
|
||||||
|
.5, .5, .5, targets[b.name])
|
||||||
|
b.box.setDepthTested(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, b in pairs(projecting) do
|
||||||
|
if not blocks[b.id] then
|
||||||
|
projecting[b.id].box.remove()
|
||||||
|
projecting[b.id] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if math.abs(pos.x - offset.x) +
|
||||||
|
math.abs(pos.y - offset.y) +
|
||||||
|
math.abs(pos.z - offset.z) > 16 then
|
||||||
|
for _, b in pairs(projecting) do
|
||||||
|
projecting[b.id].box.remove()
|
||||||
|
projecting[b.id] = nil
|
||||||
|
end
|
||||||
|
offset = pos
|
||||||
|
canvas.recenter()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
parallel.waitForAny(
|
||||||
|
function()
|
||||||
|
print('Ore visualization started')
|
||||||
|
print('Press enter to exit')
|
||||||
|
while true do
|
||||||
|
local e, key = os.pullEventRaw('key')
|
||||||
|
if key == keys.enter or e == 'terminate' then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
run
|
||||||
|
)
|
||||||
|
|
||||||
|
canvas:clear()
|
||||||
Reference in New Issue
Block a user