Free Function Friday Ep.39 – setMaskPaths

June 17th 2016 08:00:31am

Welcome to Free Function Friday episode setMaskPaths. In this episode we will be creating the companion function for the getMaskPaths function. Please make sure you have watched the getMaskPaths episode before continuing here.

I will be referring to that code in this episode and it is required knowledge to make setMaskPaths work properly. We will be going over the shape path attributes again as well since we will now need to assign each of them. The attributes are listed below as reference.

Follow along with the Adobe After Effects Scripting Guide as I go through the Shape Object section on page 172. Again I recommend using the AENhancers After Effects Scripting Guide for future use.

Shape object attributes:

  • closed: When true, the first and last vertices are connected to form a closed curve. When false, the closing segment is not drawn.
  • vertices: The anchor points of the shape. Specify each point as an array of two floating-point values, and collect the point pairs into an array for the complete set of points.
  • inTangents: The incoming tangent vectors, or direction handles, associated with the vertices of the shape.
  • outTangents: The outgoing tangent vectors, or direction handles, associated with the vertices of the shape.
  • featherSegLocs: An array containing each feather point’s mask path segment number (section of the mask path between vertices, numbered starting at 0).
  • featherRelSegLocs: An array containing each feather point’s relative position, from 0 to 1, on its mask path segment (section of the mask path between vertices, numbered starting at 0).
  • featherRadii: An array containing each feather point’s radius (feather amount); inner feather points have negative values.
  • featherInterps: An array containing each feather point’s radius interpolation type (0 for non-Hold feather points, 1 for Hold feather points).
  • featherTensions: An array containing each feather point’s tension amount, from 0 (0% tension) to 1 (100% tension).
  • featherTypes: An array containing each feather point’s direction, either 0 (outer feather point) or 1 (inner feather point).
  • featherRelCornerAngles: An array containing each feather point’s relative angle percentage between the two normals on either side of a curved outer feather boundary at a corner on a mask path. The angle value is 0% for feather points not at corners.

Source Code:

function setMaskPaths(layObj, maskData){
	var maskDataLen, curData, newShape, newMask, comp, addShape, addVectorGroup;
	maskDataLen = maskData[1].length;
	if(maskDataLen > 0){
		for(var s=0; s < maskDataLen; s++){
			curData = maskData[1][s];
			
			newShape = new Shape();
			
			newShape.vertices = curData.vertices;
			newShape.inTangents = curData.inTangents;
			newShape.outTangents = curData.outTangents;
			newShape.closed = curData.closed;
			
			newShape.featherTypes = curData.featherTypes;
			newShape.featherSegLocs = curData.featherSegLocs;
			newShape.featherRelSegLocs = curData.featherRelSegLocs;
			newShape.featherRadii = curData.featherRadii;
			newShape.featherInterps = curData.featherInterps;
			newShape.featherRelCornerAngles = curData.featherRelCornerAngles;
			newShape.featherTensions = curData.featherTensions;
			
			newMask = layObj.property("ADBE Mask Parade").addProperty("Mask");
			newMask.property("ADBE Mask Shape").setValue(newShape);
			newMask.name = maskData[0][s];
		}
	}
}
Checkout more:
Free Function Friday Ep.29 – isLayerRetimed
Free Function Friday Ep.5 – itemLongestSide
Free Function Friday Ep.6 – collectAllPrecomps
Free Function Friday Ep.4 – aeToOSFolder
Free Function Friday Ep.38 – getMaskPaths