Compare commits

...

2 Commits

Author SHA1 Message Date
teverse 50d84f37fa Bug Fix 2019-12-23 20:16:15 +00:00
Jay 3524d7b08f drag tool 2019-12-23 17:43:21 +00:00
6 changed files with 210 additions and 6 deletions

View File

@ -6,3 +6,7 @@ This repo contains open source components produced for Teverse.
# Copyright
Copyright (c) 2019 teverse.com
# Acknowledgements
- sound/click.ogg sourced from http://soundbible.com/1705-Click2.html
- sound/tick.ogg sourced from http://soundbible.com/2044-Tick.html

View File

@ -97,7 +97,9 @@ local function boundUpdate()
bounds.max = controller.selection[1].position
for _,v in pairs(controller.selection) do
bounds:expand(v) -- new in 0.13.2
if type(v) == "block" then
bounds:expand(v) -- new in 0.13.2
end
end
end
@ -122,7 +124,9 @@ controller.registerCallback(function()
for _,v in pairs(controller.selection) do
if type(v.position) == "vector3" and type(v.size) == "vector3" then
bounds:expand(v)
if type(v) == "block" then
bounds:expand(v)
end
table.insert(boundingEvents, v:changed(boundUpdate))
end
end
@ -186,4 +190,6 @@ keybinder:bind({
end
})
controller.box = boundingBox
return controller

View File

@ -152,7 +152,7 @@ return {
end
end
grid.position = avgPos / #selection.selection
grid.position = (avgPos / #selection.selection) + vector3(0, 0.1, 0)
end
wait()
end

View File

@ -4,7 +4,7 @@
return {
handTool = require("tevgit:workshop/controllers/sidetools/hand.lua"),
--moveTool = require("tevgit:workshop/controllers/sidetools/move.lua"),
moveTool = require("tevgit:workshop/controllers/sidetools/move.lua"),
--scaleTool = require("tevgit:workshop/controllers/sidetools/scale.lua"),
--rotateTool = require("tevgit:workshop/controllers/sidetools/rotate.lua"),
}

View File

@ -5,16 +5,209 @@ local toolName = "Move"
local toolDesc = ""
local toolIcon = "fa:s-arrows-alt"
local selection = require("tevgit:workshop/controllers/core/selection.lua")
local history = require("tevgit:workshop/controllers/core/history.lua")
local ui = require("tevgit:workshop/controllers/ui/core/ui.lua")
local shared = require("tevgit:workshop/controllers/shared.lua")
local boundingBoxChangedEvent;
local gridGuideline;
local handles;
local settingsGui = nil
local function updateHandles()
if handles then
if selection.box.size == vector3(0,0,0) then
for _,v in pairs(handles) do
v[1].size = vector3(0,0,0)
v[1].opacity = 0
end
else
for _,v in pairs(handles) do
v[1].position = selection.box.position + selection.box.rotation* ((v[2] * selection.box.size/2) + (v[2]*1.5))
v[1]:lookAt(selection.box.position)
v[1].rotation = v[1].rotation * quaternion():setEuler(math.rad(90), 0, 0)
v[1].size = vector3(0.2, 0.4, 0.2)
v[1].opacity = 1
end
end
end
end
local axes = {"x", "y", "z"}
return {
name = toolName,
icon = toolIcon,
desc = toolDesc,
activate = function()
print("tool activated")
settingsGui = ui.create("guiFrame", shared.workshop.interface["_toolBar"], {
size = guiCoord(0, 120, 0, 28),
position = guiCoord(0, 80, 0, 0),
backgroundAlpha = 0.8,
borderRadius = 4
}, "primary")
ui.create("guiTextBox", settingsGui, {
size = guiCoord(0.6, 0, 0, 18),
position = guiCoord(0, 5, 0, 5),
text = "Grid Step",
fontSize = 18,
textAlpha = 0.8
}, "primaryText")
local gridStep = 0.25
local gridStepInput = ui.create("guiTextBox", settingsGui, {
size = guiCoord(0.4, -6, 0, 18),
position = guiCoord(0.6, 3, 0, 5),
text = tostring(gridStep),
fontSize = 18,
textAlpha = 0.8,
borderRadius = 4,
align = enums.align.middle,
readOnly = false
}, "primaryVariant")
gridStepInput:on("changed", function()
gridStep = tonumber(gridStepInput.text) or 0
end)
local offsets = {}
keyEvent = engine.input:keyPressed(function( inputObj )
if inputObj.key == enums.key.r and isDragging then
local targetRot = quaternion:setEuler(0,math.rad(-45),0)
for _,v in pairs(selection.selection) do
if offsets[v] then
offsets[v][2] = offsets[v][2] * targetRot
v.rotation = offsets[v][2]
end
end
end
end)
-- This is used to raycast the user's mouse position to an axis
gridGuideline = engine.construct("block", workspace, {
name = "_GridGuideline",
size = vector3(0, 0, 0),
colour = colour(1, 1, 1),
opacity = 0,
workshopLocked = true,
castsShadows = false
})
handles = {}
for axisNumber, axis in pairs(axes) do
for i = -1, 1, 2 do
local face = vector3(0, 0, 0)
face[axis] = i
local handle = engine.construct("block", nil, {
name = "_CreateMode_",
castsShadows = false,
opacity = 0,
renderQueue = 1,
doNotSerialise = true,
size = vector3(0.1, 0.1, 0.1),
colour = colour(axisNumber == 1 and 1 or 0, axisNumber == 2 and 1 or 0, axisNumber == 3 and 1 or 0),
emissiveColour = colour(axisNumber == 1 and 1 or 0, axisNumber == 2 and 1 or 0, axisNumber == 3 and 1 or 0),
workshopLocked = true,
mesh = "primitive:cone"
})
handle:mouseLeftPressed(function()
gridGuideline.size = vector3(300, 0.1, 300)
local last = nil
while engine.input:isMouseButtonDown(enums.mouseButton.left) do
-- Position and rotate the invisible guideline to face the camera.
-- We use this guideline to raycast with
local pos1 = gridGuideline.position
pos1[axis] = 0
local pos2 = workspace.camera.position
pos2[axis] = 0
local lookAt = gridGuideline.rotation:setLookRotation( pos1 - pos2 )
gridGuideline.rotation = lookAt * quaternion():setEuler(math.rad(90),0,0)
gridGuideline.position = selection.box.position
local mouseHits = engine.physics:rayTestScreenAllHits( engine.input.mousePosition )
local mouseHit = nil
-- We only want the gridGuideline
for _,hit in pairs(mouseHits) do
if hit.object == gridGuideline then
mouseHit = hit
goto skip_loop
end
end
::skip_loop::
if mouseHit and mouseHit.object == gridGuideline then
local target = mouseHit.hitPosition
local didMove = true
if last ~= nil then
local translateBy = vector3(0, 0, 0)
translateBy[axis] = target[axis] - last
if gridStep ~= 0 then
translateBy = shared.roundVector3(translateBy, gridStep)
if translateBy[axis] == 0 then
didMove = false
end
end
for _,v in pairs(selection.selection) do
if type(v.position) == "vector3" then
v.position = v.position + translateBy
end
end
end
if didMove then
last = target[axis]
end
end
wait()
end
gridGuideline.size = vector3(0, 0, 0)
end)
table.insert(handles, {handle, face})
end
end
boundingBoxChangedEvent = selection.box:changed(updateHandles)
updateHandles()
end,
deactivate = function ()
print("tool deactivated")
if settingsGui then
settingsGui:destroy()
settingsGui = nil
end
if boundingBoxChangedEvent then
boundingBoxChangedEvent:disconnect()
boundingBoxChangedEvent = nil
end
if gridGuideline then
gridGuideline:destroy()
gridGuideline = nil
end
if handles then
for _,v in pairs(handles) do
v[1]:destroy()
end
handles = nil
end
end
}

View File

@ -26,6 +26,7 @@ local toolBar = ui.create("guiFrame", toolDock, {
local activeTool = nil
local function toggleTool(toolName)
--engine.sounds:play("tevurl:sound/click.ogg") -- too much?
if activeTool ~= toolName then
if activeTool then
tools[activeTool].deactivate()