Created
July 15, 2015 16:12
-
-
Save Hoikohroh/3785f4b044d7d3b5678b to your computer and use it in GitHub Desktop.
Adobe AfterEffects script (JSX):Z_scale
This file contains 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
/* | |
Adobe AfterEffects Script (JSX) | |
Z_scale | |
v20150716 | |
*/ | |
////////////////////////////////variable declaration//////////////////////////////// | |
var thisComp= app.project.activeItem; | |
var selectedLayers= new Array(); | |
var thisLayer = null; | |
var distance,newScale,cam,CamP,CamZ; | |
var thisW,thisH,newCamera; | |
////////////////////////////////body//////////////////////////////// | |
app.beginUndoGroup("FitToComp_offsetZ"); | |
if(thisComp instanceof CompItem){ | |
selectedLayers = thisComp.selectedLayers; | |
if(selectedLayers.length > 0){ | |
cam = thisComp.activeCamera; | |
if (cam == null){ | |
createCam(); | |
cam = thisComp.activeCamera; | |
}; | |
CamP = cam.position.value[2]; | |
CamZ = cam.Zoom.value; | |
for(i=0; i < selectedLayers.length; i++){ | |
thisLayer = selectedLayers[i]; | |
if (thisLayer.threeDLayer){ | |
adjustScale(thisLayer,CamP,CamZ); | |
}; | |
}; | |
} else { | |
alert('unselected layer'); | |
}; | |
} else { | |
alert('unselected compositon'); | |
}; | |
app.endUndoGroup(); | |
////////////////////////////////functions//////////////////////////////// | |
function adjustScale(Lay,ValP,ValZ){ | |
distance = Lay.Position.value[2] - ValP; | |
newScale = (distance / ValZ) * 100; | |
Lay.scale.setValue([newScale,newScale,newScale]); | |
}; | |
function createCam() | |
{ | |
app.beginUndoGroup("Create Camera"); | |
thisW = thisComp.width /2 ; | |
thisH = thisComp.height /2 ; | |
newCamera = thisComp.layers.addCamera("camera", [thisW,thisH]); | |
newCamera.Position.setValue([thisW,thisH,newCamera.Position.value[2]]); | |
app.endUndoGroup(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment