Question
Snap anchor point in the middle of the composition
I am trying to snap the anchor point of a layer in the center of the composition under all circumstances, whether the layer has one or multiple parents and whether those parents or the layer undergo transformations (position, anchor point, scale, rotation).
This is what I have so far:
anchor point:
offset = [0,0];
scaleFactor = thisLayer.scale[0]/100;
if(thisLayer.hasParent){
testLayer = thisLayer;
while(testLayer.hasParent){
scaleFactor *= testLayer.parent.scale[0]/100;
offset -= testLayer.parent.toWorld(testLayer.parent.anchorPoint) - testLayer.parent.anchorPoint;
testLayer = testLayer.parent;
}
}
[thisComp.width/2, thisComp.height/2] - position + value + offset * scaleFactor
position:
offset = [0,0];
scaleFactor = thisLayer.scale[0]/100;
if(thisLayer.hasParent){
testLayer = thisLayer;
while(testLayer.hasParent){
scaleFactor *= testLayer.parent.scale[0]/100;
offset -= testLayer.parent.toWorld(testLayer.parent.anchorPoint) - testLayer.parent.anchorPoint;
testLayer = testLayer.parent;
}
}
[thisComp.width/2, thisComp.height/2] + offset * scaleFactor
it works perfectly if the layer has no parent, when I parent the layer, layer anchor point isn't snapped anymore.
