Switch Selection concept for v13.5

General Moho topics.

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Switch Selection concept for v13.5

Post 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
User avatar
synthsin75
Posts: 9973
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Switch Selection concept for v13.5

Post 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.
User avatar
gilcartunista
Posts: 55
Joined: Mon Mar 14, 2016 7:13 pm
Location: https://www.facebook.com/gil.cartunista
Contact:

Re: Switch Selection concept for v13.5

Post 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
User avatar
synthsin75
Posts: 9973
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Switch Selection concept for v13.5

Post 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.
User avatar
DK
Posts: 2854
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Re: Switch Selection concept for v13.5

Post by DK »

Sounds exciting Wes! Look forward to seeing it. :shock:
Cheers
D.K
User avatar
hayasidist
Posts: 3523
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Switch Selection concept for v13.5

Post 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)
User avatar
synthsin75
Posts: 9973
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Switch Selection concept for v13.5

Post 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.
User avatar
hayasidist
Posts: 3523
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Switch Selection concept for v13.5

Post 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!!
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Switch Selection concept for v13.5

Post by A.Evseeva »

Wes, what about the script, did You finish it?
Is it possible to see even a part of code, please...
User avatar
synthsin75
Posts: 9973
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Switch Selection concept for v13.5

Post 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.
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Switch Selection concept for v13.5

Post 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.
User avatar
synthsin75
Posts: 9973
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Switch Selection concept for v13.5

Post 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. :oops:

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)
			-----------------------------------------------------------
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Switch Selection concept for v13.5

Post 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
User avatar
synthsin75
Posts: 9973
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Switch Selection concept for v13.5

Post by synthsin75 »

Thank you, Alexandra!
User avatar
synthsin75
Posts: 9973
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Switch Selection concept for v13.5

Post 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.
Image
Post Reply