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

ScriptName = "AE_ResetLayerTransform"

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

AE_ResetLayerTransform = {}

function AE_ResetLayerTransform:Name()
	return "Reset Layer Transform"
end

function AE_ResetLayerTransform:Version()
	return "1.0"
end

function AE_ResetLayerTransform:UILabel()
	return "Reset Layer Transform"
end

function AE_ResetLayerTransform:Creator()
	return "Alexandra Evseeva"
end

function AE_ResetLayerTransform:Description()
	return "Set layer translation, scale and rotation Z to default values, saving vertices and child layers unmoved."
end




-- **************************************************
-- Recurring values
-- **************************************************

-- AE_ResetLayerTransform.value1 = false

-- **************************************************
-- Is Enabled
-- **************************************************

function AE_ResetLayerTransform:IsEnabled(moho)
	return true
end


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

function AE_ResetLayerTransform:Run(moho)

	moho.document:PrepUndo(moho.layer)
	moho.document:SetDirty()
	
	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
	
	if mainLayer:LayerType() == MOHO.LT_VECTOR then
		local mesh = moho:LayerAsVector(mainLayer):Mesh()
		for p = 0, mesh:CountPoints()-1 do
			local point = mesh:Point(p)
			local currentPos = point.fAnimPos:GetValue(moho.layerFrame)
			mainMatrix:Transform(currentPos)
			point.fAnimPos:SetValue(moho.layerFrame, currentPos)
		end
	end
	if mainLayer:IsGroupType() then
		local group = moho:LayerAsGroup(mainLayer)
		for ch = 0, group:CountLayers()-1 do
			local childLayer = group:Layer(ch)
			local childMatrix = LM.Matrix:new_local()
			childLayer:GetLayerTransform(moho.layerFrame, childMatrix, moho.document)
			local resultMatrix = LM.Matrix:new_local()
			resultMatrix:Set(mainMatrix)
			resultMatrix:Multiply(childMatrix)
			local translation, rotationZ, scale = AE_Utilities:Matrix2transform(resultMatrix, printOutput)
			childLayer.fTranslation:SetValue(moho.layerFrame, translation)
			childLayer.fRotationZ:SetValue(moho.layerFrame, rotationZ)
			childLayer.fScale:SetValue(moho.layerFrame, scale)
		end
	end

	local pos = LM.Vector3:new_local()
	mainLayer.fTranslation:SetValue(moho.layerFrame, pos)
	mainLayer.fRotationZ:SetValue(moho.layerFrame, 0)
	local scale = LM.Vector3:new_local()
	scale:Set(1,1,1)
	mainLayer.fScale:SetValue(moho.layerFrame, scale)
	
end





Reset layer transform
Listed

Script type: Button/Menu

Uploaded: Jan 18 2021, 01:15

Resets transform moving it to direct child layers

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: 50