Вы находитесь на странице: 1из 3

Orient 3D layer to camera properly Auto-Orient 3D layers towards the camera in After Effects doesn't really work pr operly

since they point towards the camera object itself rather than being paral lel to the camera plane, so they can still look like they're at an angle. I foun d this expression, (like nearly all expressions, it's by Dan Ebberts) to do it p roperly. Put it on the Orientation of a 3d layer:

L u v w

= = = =

thisComp.layer("Camera 1"); fromWorldVec(L.toWorldVec([1,0,0])); fromWorldVec(L.toWorldVec([0,1,0])); 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)] Found at: http://forums.creativecow.net/thread/227/21917#21917

If not, you d need to use expressions to make a duplicate camera in the precomp an d then you can orientate towards that. That s a bit complicated to do robustly. On position of one-node camera: C = comp("Comp 1").activeCamera; thisLayer.fromWorld(C.toWorld([0,0,0])); On orientation of one-node camera: C = comp("Comp 1").activeCamera; glOr(C); function glOr(aL,aT){aT=(aT?aT:time);var x=normalize(aL.toWorldVec([1,0,0],aT)), y=normalize(aL.toWorldVec([0,1,0],aT)),z=normalize(aL.toWorldVec([0,0,1],aT));re turn [Math.atan2(-z[1],z[2]),Math.asin(z[0]),Math.atan2(-y[0],x[0])]*180/Math.PI } Otherwise, if the precomp is collapsed, you could use an expression on the layer . On position: L = comp("Comp 1").layer("Original layer"); L.toWorld(L.anchorPoint); On orientation: C = comp("Comp 1").activeCamera; L = thisLayer; lookAt(L.toWorld(L.anchorPoint), C.toWorld([0,0,0]));

Free To Distribute, but you must maintain this header if used without al teration, please also include a link to http://creative-workflow-hacks.com if po sted on the web If you use parts of this script please include my contact info as attrib ution (suggested but not required...thanks) v1.0 July 13, 2006 v1.1 July 14, 2006 updated to reflect input from Stu Maschwitz, all of t he expressions are based on his sample project v1.2 July 14, 2006 added autoLaunch of "Auto Orient" dialog from suggest

ion by Chris Prosser v1.3 July 15, 2006 changed "Auto Orient" off to position expression = p osition + [0,0,100] */ function main(){ var layers = activeItem.layers; var w = activeItem.width /2 ; var h = activeItem.height /2 ; app.beginUndoGroup("Apply Auto Camera Rig"); var cameraControlNull = activeItem.layers.addNull(); cameraControlNull.name = 'Camera Controls'; cameraControlNull.threeDLayer = true; var posX = cameraControlNull("Effects").addProperty("Slider Control"); posX.name = 'X Position'; posX.slider.setValue(w); var posY = cameraControlNull("Effects").addProperty("Slider Control"); posY.name = 'Y Position'; posY.slider.setValue(h); var posZ = cameraControlNull("Effects").addProperty("Slider Control"); posZ.name = 'Z Position'; var pan = cameraControlNull("Effects").addProperty("Slider Control"); pan.name = 'Pan'; var tilt = cameraControlNull("Effects").addProperty("Slider Control"); tilt.name = 'Tilt'; var roll = cameraControlNull("Effects").addProperty("Slider Control"); roll.name = 'Roll'; var focalLength = cameraControlNull("Effects").addProperty("Slider Contr ol"); focalLength.name = 'Focal Length (mm)'; focalLength.slider.setValue(35); var imagePlane = cameraControlNull("Effects").addProperty("Slider Contr ol"); imagePlane.name = 'Image Plane (horizontal inches)'; imagePlane.slider.setValue(.98); var positionExpression = '[effect("X Position")("Slider"), effect("Y Positio n")("Slider"), effect("Z Position")("Slider")]'; var yRotationExpression = 'effect("Pan")("Slider")'; cameraControlNull.yRotation.expression = yRotationExpression; cameraControlNull.position.expression = positionExpression; cameraControlNull.position.setValue([w,h]); var zoomExpression = 'FocalLength = thisComp.layer("Camera Controls").ef fect("Focal Length (mm)")("Slider");hFilmPlane = thisComp.layer("Camera Controls ").effect("Image Plane (horizontal inches)")("Slider") * 25.4;thisComp.width * ( FocalLength/hFilmPlane);'; var xRotationExpression = 'thisComp.layer("Camera Controls").effect("Til t")("Slider")';

var zRotationExpression = 'thisComp.layer("Camera Controls").effect("Rol l")("Slider")'; // !!! START OF CHANGES !!! var riggedCamera = activeItem.layers.addCamera('Rigged Camera',[w,h]); //var cameraPointOfInterestExpression = 'position + [0,0,100]'; //riggedCamera.pointOfInterest.expression = cameraPointOfInterestExpress ion; riggedCamera.zoom.expression = zoomExpression; riggedCamera.xRotation.expression = xRotationExpression; riggedCamera.zRotation.expression = zRotationExpression; riggedCamera.parent = cameraControlNull; riggedCamera.position.setValue([0,0,0]); riggedCamera.orientation.setValue([0,0,0]); //app.settings.getSetting(sectionName, keyName); if (parseInt(app.version) >= 8) { riggedCamera.autoOrient = AutoOrientType.NO_AUTO_ORIENT; } else { riggedCamera.pointOfInterest.setValue([0,0,100]); /*uncomment to use "Auto Orient" off remove alert('"Auto Camera Rig" needs to have Auto-Orient set to "Off", please set it in the following dialog'); app.executeCommand(app.findMenuCommandId("Auto-Orient...")); */ } // !!! END OF CHANGES !!! app.endUndoGroup(); } //check that a single active Comp is selected function checkPrerequisites(){ var selectAlert = "Please select a single active Comp."; if ((activeItem != null) && (activeItem instanceof CompItem)){ main(); }else{ alert(selectAlert); } } //globals var items = app.project.items; var activeItem = app.project.activeItem; checkPrerequisites();

Вам также может понравиться