Maya Camera Settings to Unity
-
Upload
- -
Category
Entertainment & Humor
-
view
1.562 -
download
11
description
Transcript of Maya Camera Settings to Unity
Maya Camera SettingsTo Unity
Unity Technologies Japan G.K.Community Evangelist
Nobuyuki Kobayashi
AbstructThis is how to move the Value of positon, rotation, near and far clipping planes, and FOV to Unity.
• You can get the values of FOV which is calculated from the Focal Length and the Vertical Film Aperture on Maya.
• You can set keys of FOV by setting keys on the channel of the Focal Length on Maya.
• You can export the FBX animation data including the locator which has been simulation-baked the attributes of Maya Main camera with the MEL script.
Sample Scene
I uploaded the sample scenes under URL.
http://d.pr/lLDx
Sample:Scene View in Maya
Sample:Camera View in Maya
Sample:Camera View in Unity
Workflow on Maya
Setting Animations to Camera● First, The name of your camera is Main_Camera, and the name of your camera’s shape is Main_CameraShape.
● Set the value of “Fit Resolution Gate” within Main_CameraShape to “Vertical” from the Attribute Editor.
● You can set the key on channels for Camera Animation below: ● Translate X/Y/Z, Rotate X/Y/Z, Focal Length at Main_Camera’s Channel Box ● If you want to set the key on FOV, you should do on Focal Length instead. ● You cannot set the key on Angle of View on Maya, because this value is calculated inside Maya.
Focal Length
Translate X/Y/Z, Rotate X/Y/Z
Setting Animations to Camera
Fit Resolution Gate
Focal Length
near and far clipping planes
Translate X/Y/Z, Rotate X/Y/Z
Making the locator● Make the new locator with “Create>Locator”● Change the name of the locator to “locator_Camera”
When you finished the constraint of camera
and locator, you will get the view like this.
Making constraints locator to camera
● Make point and orient constraints with the position and rotation of the locator_Camera to Main_Camera.● Select Main_Camera firstly, and select locator_Camera secondly, Make Constraints twice: Constrain>Point, Constrain>Orient● Check out “Maintain offset” in Option Window.● You can get the same values of position and rotation from Main_Camera to the locator_Camera.
Maintain offset
Sending the Value of Near Clipping Plane to the Scale.X of the locator_Camera
● Select “Scale X” from the Channel Box of “locator_Camera”, and Select “Edit>Expression” from the manu of the Channel Box.● Using the Expression Editor, copy and paste the MEL script below, inside the box named “Expression”.
float $ncp;$ncp = `getAttr Main_CameraShape.nearClipPlane`;setAttr locator_Camera.scaleX $ncp;Scale X
Expression
Expression
Edit
Edit
float $fcp;$fcp = `getAttr Main_CameraShape.farClipPlane`;setAttr locator_Camera.scaleY $fcp;
Sending the Value of Far Clipping Plane to the Scale.Y of the locator_Camera
● Select “Scale Y” from the Channel Box of “locator_Camera”, and Select “Edit>Expression” from the manu of the Channel Box.● Using the Expression Editor, copy and paste the MEL script below, inside the box named “Expression”.
Sending the Value of FOV to the Scale.Z of the locator_Camera● Finally select “Scale Z” and copy and paste the MEL script into Expression.
float $fl;float $vfa; float $FoV;// get focalLength from CameraShape node$fl = `getAttr Main_CameraShape.focalLength`;// get verticalFilmAperture from CameraShape node$vfa = `getAttr Main_CameraShape.verticalFilmAperture`;// caluculate FOV from two values above$FoV = 2.0 * atan((0.5 * $vfa) / ($fl * 0.03937)) * 57.29578;// send FOV to scale.ZsetAttr locator_Camera.scaleZ $FoV;
1 mm = 0.0393700787 inch1 rad=180/Pi=57.29578 degree
Simulation-Baking of the Value of Locator● Select from Translate.X to Scale.Z on the Channel Box.● Use the Simulation-Baking command to all keys baked, with “Edit>Keys>Bake Simulations” from menu.● If you want optimize F-Curves, open the Graph Editor and use “Curves>Simplify Curve” from menu.
All key are baked when you finish the simulation-baking.
Turn red in the boxBake Simulations
Keys
Edit
Export the FBX files● It is easy to export FBX files separately for understanding: the one includes objects which have animation data, the one includes the scene objects only, finally the one includes locator_Camera only.
● You use the FBX includes locator_Camera only as the Camera path.
• For example : We use the Ball.fbx (Animated Objects), the Floor.fbx (Scene files), and the MayaCamera.fbx as the camera path.
Workflow on Unity
Import the FBX files● First of all, you must set the same scale factor of Maya and Unity before you import the camera path FBX.● Setting below:
>When your unit of scale is Meter on Maya : When you export the FBX, Set the Unit of scale as Centimeters, and the value of Scale Factor of Unity is 0.01.
>When your unit of scale is Centimeter on Maya : When you export the FBX, Set the Unit of scale as Centimeters, and the value of Scale Factor of Unity is 1.
● After adjusting the scale factor, Import Ball.fbx, Floor.fbx, MayaCamera.fbx, you can get the same as scale of scene in Unity as Maya.
>When your unit of scale is Meter on Maya : When you export the FBX, Set the Unit of scale as Centimeters, and the value of Scale Factor of Unity is 0.01.
>When your unit of scale is Centimeter on Maya : When you export the FBX, Set the Unit of scale as Centimeters, and the value of Scale Factor of Unity is 1.
Import the FBX files
Setting the Main Camera of Unity to the child of MayaCamera
● Set the Main Camera of Unity to the child of MayaCamera object in Hierarchy● Set the local position and rotation of Main Camera below: ● Position(x,y,z) = (0,0,0)、Rotation(x,y,z)= (0,180,0)、Scale(x,y,z)=(1,1,1)● In this point, you can get the same position and rotation of Maya camera in Unity.
Set the Main Camera of Unity to the child of MayaCamera object in Hierarchy
Set the value of rotation.y = 180 to adjust the Maya coordinate system
Attaching the script to MayaCamera Object● Attach the script to MayaCamera objects below:
using UnityEngine;using System.Collections;
public class MayaCameraConverter : MonoBehaviour { Camera _camera;
void Awake () { _camera = GetComponentInChildren<Camera>(); }
void LateUpdate () { _camera.nearClipPlane = transform.localScale.x; _camera.farClipPlane = transform.localScale.y; _camera.fieldOfView = transform.localScale.z; }}