Created
January 15, 2018 04:01
-
-
Save tnydwrds/f920c3c9dfe804024df9eb95d0018699 to your computer and use it in GitHub Desktop.
Dirty MEL script to fix odd orthographic camera clipping planes with some scene units in Maya LT
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
/** | |
* Fix for system orthographic camera clipping planes not taking into account | |
* scene unit changes from centimeters. | |
*/ | |
global proc foccp_fixOrthoCameraClippingPlanes() { | |
float $offset_amount = 100, | |
$near_clip_plane, | |
$far_clip_plane, | |
$cur_far_clip_plane, | |
$center_of_interest; | |
string $log_header = "foccp: ", | |
$ortho_camera; | |
for ($ortho_camera in `listCameras -orthographic`) { | |
// Assumes the camera's center of interest reliably represents its | |
// current distance from the scene's origin. | |
$center_of_interest = `camera -query -centerOfInterest $ortho_camera`; | |
$cur_far_clip_plane = `camera -query -farClipPlane $ortho_camera`; | |
if ($cur_far_clip_plane < $center_of_interest) { | |
// Far clipping plane is set first to make sure setting the near | |
// won't be set to an out of bounds value. | |
$far_clip_plane = $center_of_interest + $offset_amount; | |
camera -edit -farClipPlane $far_clip_plane $ortho_camera; | |
$near_clip_plane = $center_of_interest - $offset_amount; | |
camera -edit -nearClipPlane $near_clip_plane $ortho_camera; | |
print `format -s $log_header -s $ortho_camera "^1s \"^2s\" camera center of interest is outside clipping plane bounds\n"`; | |
print `format -s $log_header -s $center_of_interest "^1s Center of interest: ^2s\n"`; | |
print `format -s $log_header -s $cur_far_clip_plane "^1s Far clipping plane: ^2s\n"`; | |
print `format -s $log_header -s $near_clip_plane -s $far_clip_plane "^1s Clipping planes adjusted to ^2s (near), ^3s (far)\n"`; | |
print "\n"; | |
} | |
} | |
} | |
scriptJob -event NewSceneOpened "foccp_fixOrthoCameraClippingPlanes"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you've never mucked with
userSetup.mel
before there is a gotcha when interacting with other scripts. Specifically I ran into an issue with this script and Unity's FBX Exporter.In the documentation for userSetup.mel, the following (version specific) paths are mentioned:
The Unity FBX Exporter bootstraps itself from what appears to be location that would apply to all Maya installs:
Turns out this won't get run if there is a version specific
userSetup.mel
as noted on Unity's FBX Exporter thread. So have to add the following line to the version specific setup script:Or I guess update your global(?) setup script, which already has Unity's bootstrap.