Last active
June 12, 2024 10:23
-
-
Save eeropic/eea5c38887178b1756d99da453e4977f to your computer and use it in GitHub Desktop.
After effects expressions and scripts collected from various authors and myself.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //dynamic parenting for 3d layers | |
| //Position | |
| L=thisComp.layer("Object center"); | |
| L.toWorld(L.effect(name)("3D Point")); | |
| //Scale | |
| L =thisComp.layer("Object center"); | |
| [L.transform.scale[0]/100*value[0],L.transform.scale[1]/100*value[1],L.transform.scale[2]/100*value[2]]; | |
| //Orientation | |
| L = thisComp.layer("Object center"); | |
| u = fromWorldVec(L.toWorldVec([1,0,0])); | |
| v = fromWorldVec(L.toWorldVec([0,1,0])); | |
| w = normalize(fromWorldVec(L.toWorldVec([0,0,1]))); | |
| sinb = clamp(w[0],-1,1); | |
| b = Math.asin(sinb); | |
| cosb = Math.cos(b); | |
| if (Math.abs(cosb) > .0005){ | |
| c = -Math.atan2(v[0],u[0]); | |
| a = -Math.atan2(w[1],w[2]); | |
| }else{ | |
| a = (sinb < 0 ? -1 : 1)*Math.atan2(u[1],v[1]); | |
| c = 0; | |
| } | |
| [radiansToDegrees(a),radiansToDegrees(b),radiansToDegrees(c)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //from Paul Conigliaro | |
| /******************************** | |
| Path Length | |
| Writes the length of the first selected path to the Info panel | |
| and copies result to clipboard | |
| ********************************/ | |
| { | |
| var thisComp = app.project.activeItem; | |
| var thisShape = thisComp.selectedProperties[0]; | |
| try{ | |
| var pathLength = Math.round(getPathLength(thisShape.property("Path").value)*100)/100; | |
| if($.os.indexOf("Macintosh") === -1) { var cmdString = 'cmd.exe /c cmd.exe /c "echo ' + pathLength + ' | clip"'; } | |
| else { var cmdString = 'echo "' + pathLength + '" | pbcopy'; } | |
| system.callSystem(cmdString); | |
| clearOutput(); | |
| writeLn("Path Length: " + pathLength + " pixels."); | |
| //Uncomment this line to display alert instead. | |
| //alert("Path Length: " + pathLength + " pixels."); | |
| } catch(e){ | |
| alert("ERROR: Did you select only paths?"); | |
| } | |
| function getPathLength(shapePath) { | |
| var len = 0; | |
| var verts = shapePath.vertices; | |
| var numVerts = verts.length; | |
| var ins = shapePath.inTangents; | |
| var outs = shapePath.outTangents; | |
| for (var i = 0; i < numVerts-1; i++) { len += getCurveLength(verts[i],verts[i+1],outs[i],ins[i+1]); } | |
| if(shapePath.closed == true) { len += getCurveLength(verts[numVerts-1],verts[0],outs[numVerts-1],ins[0]);} | |
| return len; | |
| //Curve Segement Length function from Hernan Torrisi | |
| function getCurveLength(initPos, endPos, outBezier, inBezier) { | |
| var k, curveSegments = 100, point, lastPoint = null, ptDistance, absToCoord, absTiCoord, triCoord1, triCoord2, triCoord3, liCoord1, liCoord2, ptCoord, perc, addedLength = 0, i, len; | |
| for (k = 0; k < curveSegments; k += 1) { | |
| point = []; | |
| perc = k / (curveSegments - 1); | |
| ptDistance = 0; | |
| absToCoord = []; | |
| absTiCoord = []; | |
| len = outBezier.length; | |
| for (i = 0; i < len; i += 1) { | |
| if (absToCoord[i] === null || absToCoord[i] === undefined) { | |
| absToCoord[i] = initPos[i] + outBezier[i]; | |
| absTiCoord[i] = endPos[i] + inBezier[i]; | |
| } | |
| triCoord1 = initPos[i] + (absToCoord[i] - initPos[i]) * perc; | |
| triCoord2 = absToCoord[i] + (absTiCoord[i] - absToCoord[i]) * perc; | |
| triCoord3 = absTiCoord[i] + (endPos[i] - absTiCoord[i]) * perc; | |
| liCoord1 = triCoord1 + (triCoord2 - triCoord1) * perc; | |
| liCoord2 = triCoord2 + (triCoord3 - triCoord2) * perc; | |
| ptCoord = liCoord1 + (liCoord2 - liCoord1) * perc; | |
| point.push(ptCoord); | |
| if (lastPoint !== null) { | |
| ptDistance += Math.pow(point[i] - lastPoint[i], 2); | |
| } | |
| } | |
| ptDistance = Math.sqrt(ptDistance); | |
| addedLength += ptDistance; | |
| lastPoint = point; | |
| } | |
| return addedLength; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //from Satoru Yonekura | |
| dist = effect(“Offset”)(“Slider”); // Position on path. | |
| w = effect(“Width”)(“Slider”); // Normal direction width. | |
| restpath = thisProperty; | |
| targetpath = thisComp.layer(“Path”).content(“Shape 1”).content(“Path 1”).path; // Target Path | |
| refpt = restpath.points(); | |
| refintan = restpath.inTangents(); | |
| refouttan = restpath.outTangents(); | |
| points =[]; | |
| intangents = []; | |
| outtangents = []; | |
| for(i=0; i<refpt.length; i++){ | |
| rest = refpt[i]; | |
| f = dist + rest[0] / thisComp.width; | |
| pathpoint = targetpath.pointOnPath(f); | |
| pathnormal = targetpath.normalOnPath(f); | |
| angle = Math.atan2(-pathnormal[0], pathnormal[1]); | |
| intanx = refintan[i][0] * Math.cos(angle) – refintan[i][1] * Math.sin(angle); | |
| intany = refintan[i][0] * Math.sin(angle) + refintan[i][1] * Math.cos(angle); | |
| outtanx = refouttan[i][0] * Math.cos(angle) – refouttan[i][1] * Math.sin(angle); | |
| outtany = refouttan[i][0] * Math.sin(angle) + refouttan[i][1] * Math.cos(angle); | |
| points.push( pathpoint + pathnormal * rest[1] *w); | |
| intangents.push( [intanx, intany * w] ); | |
| outtangents.push( [ outtanx, outtany * w] ); | |
| } | |
| createPath(points, intangents, outtangents); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment