mirror of
https://github.com/teverse/teverse
synced 2025-08-27 16:44:45 +02:00
Compare commits
No commits in common. "50d84f37fa7fa19427a733d8ace2bf65e618839a" and "15b40acf7139c6622e06232ac9e250b2ae02718a" have entirely different histories.
50d84f37fa
...
15b40acf71
@ -6,7 +6,3 @@ This repo contains open source components produced for Teverse.
|
|||||||
# Copyright
|
# Copyright
|
||||||
|
|
||||||
Copyright (c) 2019 teverse.com
|
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
|
|
@ -97,9 +97,7 @@ local function boundUpdate()
|
|||||||
bounds.max = controller.selection[1].position
|
bounds.max = controller.selection[1].position
|
||||||
|
|
||||||
for _,v in pairs(controller.selection) do
|
for _,v in pairs(controller.selection) do
|
||||||
if type(v) == "block" then
|
bounds:expand(v) -- new in 0.13.2
|
||||||
bounds:expand(v) -- new in 0.13.2
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -124,9 +122,7 @@ controller.registerCallback(function()
|
|||||||
|
|
||||||
for _,v in pairs(controller.selection) do
|
for _,v in pairs(controller.selection) do
|
||||||
if type(v.position) == "vector3" and type(v.size) == "vector3" then
|
if type(v.position) == "vector3" and type(v.size) == "vector3" then
|
||||||
if type(v) == "block" then
|
bounds:expand(v)
|
||||||
bounds:expand(v)
|
|
||||||
end
|
|
||||||
table.insert(boundingEvents, v:changed(boundUpdate))
|
table.insert(boundingEvents, v:changed(boundUpdate))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -190,6 +186,4 @@ keybinder:bind({
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
controller.box = boundingBox
|
|
||||||
|
|
||||||
return controller
|
return controller
|
@ -152,7 +152,7 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
grid.position = (avgPos / #selection.selection) + vector3(0, 0.1, 0)
|
grid.position = avgPos / #selection.selection
|
||||||
end
|
end
|
||||||
wait()
|
wait()
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
handTool = require("tevgit:workshop/controllers/sidetools/hand.lua"),
|
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"),
|
--scaleTool = require("tevgit:workshop/controllers/sidetools/scale.lua"),
|
||||||
--rotateTool = require("tevgit:workshop/controllers/sidetools/rotate.lua"),
|
--rotateTool = require("tevgit:workshop/controllers/sidetools/rotate.lua"),
|
||||||
}
|
}
|
||||||
|
@ -5,209 +5,16 @@ local toolName = "Move"
|
|||||||
local toolDesc = ""
|
local toolDesc = ""
|
||||||
local toolIcon = "fa:s-arrows-alt"
|
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 {
|
return {
|
||||||
name = toolName,
|
name = toolName,
|
||||||
icon = toolIcon,
|
icon = toolIcon,
|
||||||
desc = toolDesc,
|
desc = toolDesc,
|
||||||
|
|
||||||
activate = function()
|
activate = function()
|
||||||
settingsGui = ui.create("guiFrame", shared.workshop.interface["_toolBar"], {
|
print("tool activated")
|
||||||
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,
|
end,
|
||||||
|
|
||||||
deactivate = function ()
|
deactivate = function ()
|
||||||
if settingsGui then
|
print("tool deactivated")
|
||||||
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
|
end
|
||||||
}
|
}
|
@ -26,7 +26,6 @@ local toolBar = ui.create("guiFrame", toolDock, {
|
|||||||
local activeTool = nil
|
local activeTool = nil
|
||||||
|
|
||||||
local function toggleTool(toolName)
|
local function toggleTool(toolName)
|
||||||
--engine.sounds:play("tevurl:sound/click.ogg") -- too much?
|
|
||||||
if activeTool ~= toolName then
|
if activeTool ~= toolName then
|
||||||
if activeTool then
|
if activeTool then
|
||||||
tools[activeTool].deactivate()
|
tools[activeTool].deactivate()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user