mirror of
https://github.com/teverse/teverse
synced 2025-08-26 08:04:46 +02:00
Compare commits
No commits in common. "9e722ea70888267521523ef576ab08f76a82bec1" and "c49e97ab71ff0082de4057b34cd85eda9dc0193f" have entirely different histories.
9e722ea708
...
c49e97ab71
@ -2,15 +2,6 @@
|
|||||||
|
|
||||||
local controller = {}
|
local controller = {}
|
||||||
|
|
||||||
local boundingBox = engine.construct("block", workspace, {
|
|
||||||
name = "_bounding",
|
|
||||||
wireframe = true,
|
|
||||||
static = true,
|
|
||||||
physics = false,
|
|
||||||
workshopLocked = true,
|
|
||||||
position = vector3(0, -100, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
controller.selection = {}
|
controller.selection = {}
|
||||||
|
|
||||||
controller.callbacks = {}
|
controller.callbacks = {}
|
||||||
@ -61,63 +52,4 @@ controller.hasSelection = function()
|
|||||||
return #controller.selection > 0
|
return #controller.selection > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local boundingEvents = {}
|
|
||||||
|
|
||||||
local function boundUpdate()
|
|
||||||
--inefficient, is called for each change
|
|
||||||
local bounds = aabb()
|
|
||||||
|
|
||||||
if #controller.selection > 0 then
|
|
||||||
bounds.min = controller.selection[1].position
|
|
||||||
bounds.max = controller.selection[1].position
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,v in pairs(controller.selection) do
|
|
||||||
bounds:expand(v.position + (v.size/2))
|
|
||||||
bounds:expand(v.position - (v.size/2))
|
|
||||||
end
|
|
||||||
|
|
||||||
boundingBox.position = bounds:getCentre()
|
|
||||||
boundingBox.size = bounds.max - bounds.min
|
|
||||||
end
|
|
||||||
|
|
||||||
controller.registerCallback(function()
|
|
||||||
for _,v in pairs(boundingEvents) do
|
|
||||||
v:disconnect()
|
|
||||||
end
|
|
||||||
boundingEvents = {}
|
|
||||||
|
|
||||||
local bounds = aabb()
|
|
||||||
|
|
||||||
if #controller.selection > 0 then
|
|
||||||
bounds.min = controller.selection[1].position
|
|
||||||
bounds.max = controller.selection[1].position
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,v in pairs(controller.selection) do
|
|
||||||
bounds:expand(v.position + (v.size/2))
|
|
||||||
bounds:expand(v.position - (v.size/2))
|
|
||||||
table.insert(boundingEvents, v:changed(boundUpdate))
|
|
||||||
end
|
|
||||||
|
|
||||||
boundingBox.position = bounds:getCentre()
|
|
||||||
boundingBox.size = bounds.max - bounds.min
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
local keybinder = require("tevgit:workshop/controllers/core/keybinder.lua")
|
|
||||||
local history = require("tevgit:workshop/controllers/core/history.lua")
|
|
||||||
|
|
||||||
keybinder:bind({
|
|
||||||
name = "delete",
|
|
||||||
key = enums.key.delete,
|
|
||||||
action = function()
|
|
||||||
history.beginAction(controller.selection, "Delete")
|
|
||||||
for _,v in pairs(controller.selection) do
|
|
||||||
v:destroy()
|
|
||||||
end
|
|
||||||
history.endAction()
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
return controller
|
return controller
|
@ -22,7 +22,7 @@ return {
|
|||||||
if not inputObj.systemHandled then
|
if not inputObj.systemHandled then
|
||||||
-- This is not a gui event, let's continue.
|
-- This is not a gui event, let's continue.
|
||||||
local hit = engine.physics:rayTestScreen(engine.input.mousePosition)
|
local hit = engine.physics:rayTestScreen(engine.input.mousePosition)
|
||||||
if hit and not hit.object.workshopLocked then
|
if hit then
|
||||||
-- user has clicked a object in 3d space.
|
-- user has clicked a object in 3d space.
|
||||||
if selection.isSelected(hit.object) then
|
if selection.isSelected(hit.object) then
|
||||||
-- user clicked a selected object,
|
-- user clicked a selected object,
|
||||||
@ -30,17 +30,9 @@ return {
|
|||||||
|
|
||||||
-- calculate the 'centre' of the selection
|
-- calculate the 'centre' of the selection
|
||||||
local bounds = aabb()
|
local bounds = aabb()
|
||||||
|
|
||||||
if #selection.selection > 0 then
|
|
||||||
bounds.min = selection.selection[1].position
|
|
||||||
bounds.max = selection.selection[1].position
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,v in pairs(selection.selection) do
|
for _,v in pairs(selection.selection) do
|
||||||
bounds:expand(v.position + (v.size/2))
|
bounds:expand(v.position)
|
||||||
bounds:expand(v.position - (v.size/2))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local centre = bounds:getCentre()
|
local centre = bounds:getCentre()
|
||||||
|
|
||||||
-- calculate the mouse's offset from the centre
|
-- calculate the mouse's offset from the centre
|
||||||
@ -66,11 +58,11 @@ return {
|
|||||||
-- fire a ray, exclude selected items.
|
-- fire a ray, exclude selected items.
|
||||||
local hits, didExclude = engine.physics:rayTestScreenAllHits(engine.input.mousePosition, selection.selection)
|
local hits, didExclude = engine.physics:rayTestScreenAllHits(engine.input.mousePosition, selection.selection)
|
||||||
if (#hits > 0) then
|
if (#hits > 0) then
|
||||||
local newCentre = hits[1].hitPosition - mouseOffset
|
local newCentre = hits[1].hitPosition + mouseOffset
|
||||||
local avgPos = vector3(0,0,0)
|
local avgPos = vector3(0,0,0)
|
||||||
for _,v in pairs(selection.selection) do
|
for _,v in pairs(selection.selection) do
|
||||||
if offsets[v] then
|
if offsets[v] then
|
||||||
v.position = newCentre + offsets[v]
|
v.position = newCentre - offsets[v]
|
||||||
avgPos = avgPos + v.position
|
avgPos = avgPos + v.position
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -92,8 +84,6 @@ return {
|
|||||||
selection.setSelection(hit.object)
|
selection.setSelection(hit.object)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
selection.setSelection({})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user