Advertisement
MikeOverbeck

ImportMayaDataToonBoom

Jul 2nd, 2013
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. function importMayaCam(){
  2. //Author: Mike Overbeck 2013.
  3. //Code for Dialog box
  4. d = new Dialog;
  5. d.title = "paste Maya data";
  6. var obName = new LineEdit;
  7.  
  8. var Xloc = new LineEdit;
  9. var Yloc = new LineEdit;
  10. var Zloc = new LineEdit;
  11. var Xrot = new LineEdit;
  12. var Yrot = new LineEdit;
  13. var Zrot = new LineEdit;
  14. var focalLength = new LineEdit;
  15. var camAp = new LineEdit;
  16.  
  17. obName.label = "Object Name";
  18. obName.text = "";
  19. Xloc.label = "X location";
  20. Xloc.text = "";
  21. Yloc.label = "Y location";
  22. Yloc.text = "";
  23. Zloc.label = "Z location";
  24. Zloc.text = "";
  25. Xrot.label = "X rotation";
  26. Xrot.text = "";
  27. Yrot.label = "Y rotation";
  28. Yrot.text = "";
  29. Zrot.label = "Z rotation";
  30. Zrot.text = "";
  31. focalLength.label = "Focal Length";
  32. focalLength.text = "";
  33. camAp.label = "Horizontal Film Aperture";
  34. camAp.text = "";
  35.  
  36. var grouptitle = new GroupBox;
  37. var group = new GroupBox;
  38. var group2 = new GroupBox;
  39. group2.title = "Optional Attributes";
  40. grouptitle.add(obName);
  41. group.add(Xloc);
  42. group.add(Yloc);
  43. group.add(Zloc);
  44. group.add(Xrot);
  45. group.add(Yrot);
  46. group.add(Zrot);
  47. group2.add(focalLength);
  48. group2.add(camAp);
  49. d.add(grouptitle);
  50. d.add(group);
  51. d.add(group2);
  52. rc = d.exec();
  53. if (!rc){
  54. return;
  55. }
  56. //empty arrays that will hold usable data once user data is processed.
  57. XlocArray = [];
  58. YlocArray = [];
  59. ZlocArray = [];
  60. XrotArray = [];
  61. YrotArray = [];
  62. ZrotArray = [];
  63. focalArray = [];
  64. camApArray = [];
  65. FOVArray = [];
  66. //removes frame numbers, converts strings into float, and populates new arrays.
  67. function sansFrames(sourceString, targetArray) {
  68. sourceString = sourceString.split(" ");
  69. for (var i = 1; i < sourceString.length; i = i+2){
  70. targetArray.push(parseFloat(sourceString[i]));
  71. }
  72. }
  73. //Call functions to populate arrays.
  74. sansFrames(Xloc.text, XlocArray);
  75. sansFrames(Yloc.text, YlocArray);
  76. sansFrames(Zloc.text, ZlocArray);
  77. sansFrames(Xrot.text, XrotArray);
  78. sansFrames(Yrot.text, YrotArray);
  79. sansFrames(Zrot.text, ZrotArray);
  80. sansFrames(focalLength.text, focalArray);
  81. sansFrames(camAp.text, camApArray);
  82.  
  83. // Check that xyz locations or rotations have same number of data points.
  84. if(XlocArray.length != YlocArray.length || YlocArray.length != ZlocArray.length || XrotArray.length != YrotArray.length || YrotArray.length != ZrotArray.length){
  85. MessageBox.information("If you want to bring in location or rotation information, you must copy over all data of x, y, and z.");
  86. return;
  87. }
  88. // Ensures columns are named according to user input
  89. userPath = obName.text + "Path";
  90. userRot = obName.text + "Rot";
  91. userFocal = obName.text + "FOV";
  92. // newfunction that Applies arrays as keyframes for location and rotation
  93. function makeKeys(pathName, propX, propY, propZ){
  94. for(var i = 0; i< propX.length; i++){
  95. func.addKeyFrame3DPath(pathName, i + 1, propX[i], propY[i], propZ[i],0,0,0);
  96. }
  97. }
  98.  
  99. //creates empty columns
  100. if(XlocArray.length > 0){
  101. column.add(userPath, "3DPATH");
  102. makeKeys(userPath, XlocArray, YlocArray, ZlocArray);
  103. }
  104. if(XrotArray.length > 0){
  105. column.add(userRot, "QUATERNIONPATH");
  106. makeKeys(userRot, XrotArray, YrotArray, ZrotArray);
  107. }
  108.  
  109. // New function to convert Focal Distance and Aperture into FOV
  110.  
  111. var pi = Math.PI;
  112. var aspect = scene.defaultResolutionX() / scene.defaultResolutionY();
  113. function FOV(CamAp, FocLen){
  114. var CamApMM = CamAp * 25.4; //converts inches to mm
  115. var xrad = (Math.atan(((CamApMM / aspect) / 2) / FocLen)) * 2; //calculates Angle of View
  116. var AngleOfView = xrad*180/pi; //converts radians to degrees
  117. return AngleOfView;
  118. }
  119. //populates FOVArray if there is enough data present
  120.  
  121. if (focalArray.length == camApArray.length){
  122. for (var i = 0; i<focalArray.length; i++){
  123. FOVArray.push(FOV(camApArray[i], focalArray[i]));
  124. }
  125. } else{
  126. MessageBox.information("You need to copy both Focal Length and Horizontal Film Aperture to get an accurate camera FOV");
  127. }
  128. //creates column only if there is data. If not, no column.
  129. if (FOVArray.length > 0){
  130. column.add(userFocal, "BEZIER");
  131. for (var i = 0; i<FOVArray.length; i++){
  132. func.setBezierPoint(userFocal, i + 1, FOVArray[i], 0, 0, 0, 0, true, "STRAIGHT");
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement