Page 2 of 4
Re: Switch Selection concept for v13.5
Posted: Sat Jan 30, 2021 9:12 am
by A.Evseeva
synthsin75 wrote: ↑Fri Jan 29, 2021 6:49 pm
While it's easy enough to pass arguments from Moho Lua to external apps/scripts, it's not as easy to get data back. I think the only way is to write the data to a file, so Lua can read it.
It can be done with:
Code: Select all
function capture(cmd)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
return s
end
This will return text, external command (script) outputs with its "print" calls
Re: Switch Selection concept for v13.5
Posted: Sat Jan 30, 2021 9:35 pm
by synthsin75
A.Evseeva wrote: ↑Sat Jan 30, 2021 9:12 am
synthsin75 wrote: ↑Fri Jan 29, 2021 6:49 pm
While it's easy enough to pass arguments from Moho Lua to external apps/scripts, it's not as easy to get data back. I think the only way is to write the data to a file, so Lua can read it.
It can be done with:
Code: Select all
function capture(cmd)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
return s
end
This will return text, external command (script) outputs with its "print" calls
Thanks. I'll have to play around with that.
Re: Switch Selection concept for v13.5
Posted: Wed Feb 03, 2021 11:22 pm
by gilcartunista
Hi Wes! I did this example! for the Switch Selection concept test, my version is MOHO11.
https://drive.google.com/drive/folders/ ... sp=sharing
Re: Switch Selection concept for v13.5
Posted: Thu Feb 11, 2021 5:45 am
by synthsin75
Just an update....
I'm making good progress on getting this working well enough to release. I've already solved a major usability problem and no longer need to restart Moho to update switch icons. There's still some work left to do, so I don't yet know how long until I can release it.
Re: Switch Selection concept for v13.5
Posted: Thu Feb 11, 2021 5:49 am
by DK
Sounds exciting Wes! Look forward to seeing it.
Cheers
D.K
Re: Switch Selection concept for v13.5
Posted: Thu Feb 11, 2021 9:01 am
by hayasidist
synthsin75 wrote: ↑Thu Feb 11, 2021 5:45 am
...I've already solved a major usability problem and no longer need to restart Moho to update switch icons. ....
out of curiosity - would the solution to that also allow icons in any tool to be updated (IOW, not that this example would actually be needed, but e.g. showing different icons for bezier in add point)
Re: Switch Selection concept for v13.5
Posted: Thu Feb 11, 2021 5:22 pm
by synthsin75
hayasidist wrote: ↑Thu Feb 11, 2021 9:01 am
synthsin75 wrote: ↑Thu Feb 11, 2021 5:45 am
...I've already solved a major usability problem and no longer need to restart Moho to update switch icons. ....
out of curiosity - would the solution to that also allow icons in any tool to be updated (IOW, not that this example would actually be needed, but e.g. showing different icons for bezier in add point)
If you're using an
ImageButton, yes. But if it's directly on the tool options, like the bezier button, (where it's not being invoked by a menu) it might require jumping to/from frame zero and back to get it to redraw.
Re: Switch Selection concept for v13.5
Posted: Thu Feb 11, 2021 6:51 pm
by hayasidist
synthsin75 wrote: ↑Thu Feb 11, 2021 5:22 pm
hayasidist wrote: ↑Thu Feb 11, 2021 9:01 am
synthsin75 wrote: ↑Thu Feb 11, 2021 5:45 am
...I've already solved a major usability problem and no longer need to restart Moho to update switch icons. ....
out of curiosity - would the solution to that also allow icons in any tool to be updated (IOW, not that this example would actually be needed, but e.g. showing different icons for bezier in add point)
If you're using an
ImageButton, yes. But if it's directly on the tool options, like the bezier button, (where it's not being invoked by a menu) it might require jumping to/from frame zero and back to get it to redraw.
ok! sounds really useful... looking forward to that as much if not more than the switch tool!!
Re: Switch Selection concept for v13.5
Posted: Mon May 10, 2021 6:20 pm
by A.Evseeva
Wes, what about the script, did You finish it?
Is it possible to see even a part of code, please...
Re: Switch Selection concept for v13.5
Posted: Mon May 10, 2021 7:23 pm
by synthsin75
A.Evseeva wrote: ↑Mon May 10, 2021 6:20 pm
Wes, what about the script, did You finish it?
Is it possible to see even a part of code, please...
I haven't finished it yet. I've been busy with the beta and paid scripting work.
The last piece I really need is to center a layer's content (bound box) in the camera, to render the icons for each switch. Matrix transforms always do my head in. So if anyone already has code to center a bounding box, by layer translation/scale or camera moves, that would help a ton.
Re: Switch Selection concept for v13.5
Posted: Tue May 11, 2021 5:36 am
by A.Evseeva
synthsin75 wrote: ↑Mon May 10, 2021 7:23 pm
So if anyone already has code to center a bounding box, by layer translation/scale or camera moves, that would help a ton.
Ok, please figure out what do you need as a method getting something as args (a layer? or a bounding rectangle in layer space?) and returning something (bounding rectangle in pixels or what else... how it will be used?) and I'll try to help with it.
Re: Switch Selection concept for v13.5
Posted: Tue May 11, 2021 5:56 am
by synthsin75
A.Evseeva wrote: ↑Tue May 11, 2021 5:36 am
synthsin75 wrote: ↑Mon May 10, 2021 7:23 pm
So if anyone already has code to center a bounding box, by layer translation/scale or camera moves, that would help a ton.
Ok, please figure out what do you need as a method getting something as args (a layer? or a bounding rectangle in layer space?) and returning something (bounding rectangle in pixels or what else... how it will be used?) and I'll try to help with it.
I just need to center and zoom in on the content a layer (no matter the transforms of parent layers), so it fills the project dimensions. It doesn't matter how, as long as I can undo it after I render the button icons.
Here's some of what I've been doing. It's a complete mess.
Code: Select all
for i=0, group:CountLayers()-1 do
local layer = group:Layer(i)
local name = layer:Name()
switch:SetValue(0, name)
--center and zoom------------------------------------------
moho.document:SetShape(W,H)
moho.layer.fScale:SetValue(0, scale)
--[[moho.layer.fTranslation:SetValue(0, pos)]]
BB = layer:Bounds(0)
--print(name, " ", BB.fMax.x, " ", BB.fMax.y, " ", BB.fMin.x, " ", BB.fMin.y)
max = BB:MaxDimension2D()
center = BB:Center2D()
--[[if (center.x > center.y) then
x = max/2
y = 0
else
x = 0
y = max/2
end]]
--max = moho:DocToPixel(max)
--center switch
--vec3:Set(pos.x-pos.x-x, pos.y-pos.y-y, pos.z)
--moho.layer.fTranslation:SetValue(0, vec3)
local pos = layer.fTranslation:GetValue(0)
layer:AlignWithCamera(0, moho.document, true)
--scale switch
dim = W/max
if (center.x > center.y) then
dim = H/max
end
vec3:Set(dim, dim, dim)
--moho.layer.fScale:SetValue(0, vec3)
local zoom = moho.document.fCameraZoom:GetValue(0)
moho.document.fCameraZoom:SetValue(0, max*48)
moho.document:SetShape(self.size, self.size)
-----------------------------------------------------------
Re: Switch Selection concept for v13.5
Posted: Tue May 11, 2021 5:26 pm
by A.Evseeva
You can use GetGlobalLayerMatrix from my utility script:
http://mohoscripts.com/script/ae_utilities
this way:
Code: Select all
--get global layer matrix and transform layer bounds with it to make them global
local layerGlobal = AE_Utilities:GetGlobalLayerMatrix(moho, layer, moho.frame)
local BB = layer:Bounds(moho.frame)
layerGlobal:Transform(BB)
--place camera to zoom to global layer bounds
local oldCameraPos = moho.document.fCameraTrack:GetValue(moho.frame)
local newCameraPos = LM.Vector3:new_local()
newCameraPos:Set(BB:Center2D().x, BB:Center2D().y, oldCameraPos.z)
local oldZoom = moho.document.fCameraZoom:GetValue(moho.frame)
moho.document:SetShape(self.size, self.size)
moho.document.fCameraTrack:SetValue(moho.frame, newCameraPos)
local camAngle = 2.0 * math.atan(BB:MaxDimension2D()/(newCameraPos.z * 2))
local newZoom = 60 / (180.0 * camAngle/math.pi)
moho.document.fCameraZoom:SetValue(moho.frame, newZoom)
here is the method's code:
Code: Select all
function AE_Utilities:GetGlobalLayerMatrix(moho, layer, frame)
local prevMatrix = LM.Matrix:new_local()
prevMatrix:Identity()
local nextLayer = layer
repeat
local prevLayer = nextLayer
local matrix = LM.Matrix:new_local()
nextLayer:GetLayerTransform(frame, matrix, moho.document)
matrix:Multiply(prevMatrix)
prevMatrix:Set(matrix)
if nextLayer:Parent() then nextLayer = nextLayer:Parent() end
until nextLayer == prevLayer
local cameraMatrix = LM.Matrix:new_local()
moho.document:GetCameraMatrix(frame, cameraMatrix)
cameraMatrix:Invert()
cameraMatrix:Multiply(prevMatrix)
return cameraMatrix
end
Re: Switch Selection concept for v13.5
Posted: Tue May 11, 2021 5:36 pm
by synthsin75
Thank you, Alexandra!
Re: Switch Selection concept for v13.5
Posted: Tue May 18, 2021 1:39 am
by synthsin75
Thanks to the above help from Alexandra and a break in my other work, I should be able to release this this week. It's very close. I just need to fix some image file management.
