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)
-----------------------------------------------------------