-
Dynamically Creating Vertex Array
I am a bit of a newb in this area but I’m trying to
bring myself up to speed.
Any help is appreciated!I have 3 nulls in a comp. (this example below only uses on for simplicity)
Each null has 3 key frames for position.I’m writing code to loop through each keyframe and extract the [x,y]
position data for each of the nulls on the given keyframe.
I concatenate the data as a string which I later split out into an
array that will be used to define the maskshape vertices of
a mask on a solid layer at the same keyframe as the concatenated
extracted [x,y] data from the nulls.I hope that makes sense to you.
The problem is that after using the string split command
I don’t end up with an array as the the javascript documentation
claims and AFX scripting throws an error saying I don’t have an
array. Please see code below.
var vComp = projectItem("compMouth");
var vNullPos = vComp.layer(1).property("ADBE Transform Group").property("ADBE Position");var IT_Tracker_01 = [[169.609649658203,-2.60592651367188]]; //in tangents
var OT_Tracker_01= [[-160.638397216797,2.46807861328125]]; //out tangentsvar myMask = vComp.layer("mouth").mask(1);
myProperty = myMask.property("ADBE Mask Shape");
myPath = myProperty.value;var strPosKeyVal = "";
UpdatePositionXY () ;
function UpdatePositionXY () {
// iterate through all KEY FRAMES FOR EACH TRACKER -- ASSUMPTION IS THAT ALL TRACKERS WILL HAVE THE SAME NUMBER OF KEYFRAMES AS THE FIRST TRACKER WHICH IS BEING USED TO GET numKeys
for (var j = 1; j <= vNullPos.numKeys; j++){//iterate through all trackers null for the key frame
//concatenate all tracker null [x,y] into an array of vertices
for (var tracker = 1; tracker <= 1; tracker++){
strPosKeyVal = strPosKeyVal + vComp.layer(tracker).property("ADBE Transform Group").property("ADBE Position").keyValue(j).toString() + "|" ;
}}
//AT THIS POINT WE WOULD HAVE CONCATENATED ALL THE TRACKERS X,Y INTO A STRING FOR THE J'TH KEYFRAMEmyPath.closed = true;
myMask.rotoBezier = false;strPosKeyVal = strPosKeyVal.substring(0, strPosKeyVal.length-1)
VertArray = strPosKeyVal.split('|');
// Build vert Array
for(var i=0; i<VertArray.length; i++) { // GOES THROUGH EACH OF THE KEYFRAMES AND SETS THE VERTICES TO THE TRACKERS X,Y FOR THAT KEYFRAME
myPath.inTangents = IT_Tracker_01;
myPath.outTangents = OT_Tracker_01;
myPath.vertices = VertArray[i]; // @@@@@@@@@@@@@@@@@@ HERE IS THE PROBLEM -- AFX SAYS THAT THIS IS NOT AN ARRAY
myProperty.setValueAtTime(i+1,myPath);
}}