Image
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "AE_InvertLayerTransform"

-- **************************************************
-- General information about this script
-- **************************************************

AE_InvertLayerTransform = {}

function AE_InvertLayerTransform:Name()
	return 'Invert layer transform'
end

function AE_InvertLayerTransform:Version()
	return '1.0'
end

function AE_InvertLayerTransform:UILabel()
	return 'Invert layer transform'
end

function AE_InvertLayerTransform:Creator()
	return 'Alexandra Evseeva'
end

function AE_InvertLayerTransform:Description()
	return ''
end

-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************

function AE_InvertLayerTransform:IsRelevant(moho)
	return true
end

function AE_InvertLayerTransform:IsEnabled(moho)
	return true
end

-- **************************************************
-- The guts of this script
-- **************************************************

function AE_InvertLayerTransform:Run(moho)
	moho.document:SetDirty()
	moho.document:PrepUndo(nil)
	
	-- Your code here:

	
	local printOutput = false --output calculated values for debug
	
	local mainLayer = moho.layer
	local mainMatrix = LM.Matrix:new_local()
	mainLayer:GetLayerTransform(moho.layerFrame, mainMatrix, moho.document)

	if not mainLayer:Parent() then

		local cameraMatrix = LM.Matrix:new_local()
		moho.document:GetCameraMatrix(moho.frame, cameraMatrix)
		cameraMatrix:Invert()
		cameraMatrix:Multiply(mainMatrix)
		mainMatrix:Set(cameraMatrix)
		
		if printOutput then AE_Utilities:Matrix2transform(cameraMatrix,printOutput) end

	end
	
	local invertedMatrix = LM.Matrix:new_local()
	invertedMatrix:Set(mainMatrix)
	invertedMatrix:Invert()
	local translation, rotationZ, scale = AE_Utilities:Matrix2transform(invertedMatrix)
	
	moho.layer.fTranslation:SetValue(moho.frame, translation)
	moho.layer.fRotationZ:SetValue(moho.frame, rotationZ)
	moho.layer.fScale:SetValue(moho.frame, scale)
	
end

Invert layer transform
Listed

Script type: Button/Menu

Uploaded: Jan 18 2021, 01:17

Inverts layer transform matrix

Installation Options:

This script, and all other scripts on this site are distributed as free software under the GNU General Public License 3.0 or later.
Downloads count: 1160