home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2004 January / GSSH0104TT.iso / Extras / Tron20 / tron_tools.exe / TRON_Tools / Tools / MEL / ltExport.mel < prev   
Text File  |  2003-04-28  |  57KB  |  2,211 lines

  1. /*
  2.     LTA/LTC Exporter
  3.  
  4.     Requires ltaImport.mel to be fully functional.
  5.  
  6. */
  7. global proc string getSceneName()
  8. {
  9.     string $buffer[], $textureIndex;
  10.     string $sceneName = `file -q -sn`;
  11.     tokenize($sceneName, ".", $buffer);
  12.     string $scenePath = $buffer[0];
  13.     tokenize($scenePath, "/", $buffer);
  14.     string $scene = $buffer[size($buffer)-1];
  15.  
  16.     return $scene;
  17. }
  18.  
  19. global proc string getChar(string $line, int $index)
  20. {
  21.     $index++;
  22.     string $char = `substring $line $index $index`;
  23.     return $char;
  24. }
  25.  
  26. global proc getNewFilename()
  27. {
  28.     string $newFilename = `fileDialog -dm "~/*.lt*"`;
  29.     print($newFilename=="");
  30.     if($newFilename != "")
  31.     {
  32.         optionVar -sv lt_defaultFilename $newFilename;
  33.         textFieldButtonGrp -e -fi $newFilename lt_filename;
  34.     }
  35. }
  36.  
  37. global proc getDirectory( string $field)
  38. {
  39.     global string $targetDirectory;
  40.     string $targetNtDirectory;
  41.     string $targetPathElements[];
  42.     int $i, $pathElementsCount;
  43.     
  44.     fileBrowser "getTargetDirectory" "Choose Tool Path" "directory" 4;
  45.     tokenize $targetDirectory "/" $targetPathElements;
  46.     $pathElementsCount=size($targetPathElements);
  47.  
  48.     for ($i=0;$i<$pathElementsCount;$i++)
  49.               $targetNtDirectory=$targetNtDirectory+$targetPathElements[$i]+"\\";
  50.  
  51.     optionVar -sv $field $targetNtDirectory;
  52.     textFieldButtonGrp -e -fi $targetNtDirectory $field;
  53. }
  54.  
  55. global proc getTargetDirectory ( string $directory , string $type)
  56. {
  57.     global string $targetDirectory;
  58.     $targetDirectory=$directory + "/";
  59. }
  60.  
  61. global proc string getUniqueAnimName(string $filename, string $animName)
  62. {
  63.     int $fileId = `fopen $filename "r"`;
  64.     if($fileId ==0) 
  65.     {
  66.         fclose $fileId;
  67.         error("The programmer has failed you");            
  68.     }
  69.  
  70.     string $line, $buffer[], $animList[];
  71.     int  $index, $i, $len, $animNum = 0;
  72.  
  73.     while(!`feof $fileId`)
  74.     {
  75.         $line = `fgetline $fileId`;
  76.         
  77.         if(`gmatch $line "*animset*"`)
  78.         {
  79.             tokenize($line, "\"", $buffer);
  80.             $animList[$animNum] = $buffer[1];
  81.             $animNum++;
  82.         }
  83.     }
  84.     string $sortedList[] = `sort $animList`;
  85.  
  86.     for($i=0; $i<$animNum; $i++)
  87.     {        
  88.         if($sortedList[$i] == $animName)
  89.             $animName = $animName + "0";
  90.     }
  91.     fclose $fileId;
  92.     return $animName;
  93. }
  94.  
  95. global proc string getModelString()
  96. {
  97.     float $times[];
  98.     float $keyTimes[];
  99.     string $modelStrings[], $buffer[], $root[] = `ls -dag -type joint`;
  100.     if((!`objExists ($root[0] + ".modelStrings")`) || (!`objExists ($root[0] + ".keyTimes")`))
  101.         return "";
  102.     
  103.     string $timeString = `getAttr ($root[0] + ".keyTimes")`;
  104.     tokenize($timeString, " ", $buffer);
  105.     for($i = 0; $i < size($buffer); $i++)
  106.     {
  107.         $times[$i] = (float($buffer[$i]));
  108.         setKeyframe -t $times[$i] ($root[0] + ".tx"); 
  109.     }
  110.     string $modelString = `getAttr ($root[0] + ".modelStrings")`;
  111.     tokenize($modelString, "\"", $buffer);
  112.  
  113.     
  114.     $j=$k=0;
  115.     $modelString = "";
  116.     $keyTimeString = "";
  117.     for($i = 0; $i < size($buffer); $i++)
  118.     {
  119.         if(size($buffer[$j]) > 1)
  120.         {
  121.             $modelStrings[$k] = $buffer[$j];
  122.             $k++;    $j++;
  123.         }
  124.         $j++;
  125.     }
  126.  
  127.  
  128.     
  129.     int $j = 1;
  130.     $keyTimes[0] = -9999;
  131.     select -r (`ls -type animCurveTA -type animCurveTL`);
  132.  
  133.     int $stringHere;
  134.     string $string = "\t\t\t\t(values \n\t\t\t\t\t("; 
  135.     while($keyTimes[$j] > $keyTimes[$j-1])
  136.     {
  137.         for($i = 1; $i <= size($times); $i++)
  138.         {    
  139.             if(abs($keyTimes[$j] - $times[$i-1]) < 0.005) 
  140.             {    $stringHere = $i;  break;    }
  141.             else $stringHere = 0;
  142.         }
  143.         if($stringHere)
  144.             $string = $string  + "\"" + $modelStrings[$stringHere-1] + "\" ";
  145.         else 
  146.             $string = $string + "\"\" ";
  147.         $j++;
  148.         $keyTimes[$j] = `findKeyframe -time $keyTimes[$j-1] -which next`;
  149.     }
  150.     $string = $string + " )\n\t\t\t\t)\n";
  151.     select -cl; 
  152.     return $string;
  153. }
  154.  
  155. global proc findLTCconverter()
  156. {
  157.     $path = `optionVar -q lt_toolPath`;
  158.     if(!`file -q -ex ($path + "LTC.exe")`)
  159.         error("Can't proceed. Make sure the Tool Path folder contains LTC.exe\n");
  160. }
  161.  
  162. global proc renameFile(string $infile, string $outfile)
  163. {
  164.     string $buffer[];
  165.     tokenize($infile, "\\/", $buffer);
  166.     $sysInfile = $buffer[0];
  167.     for($i=1; $i<size($buffer); $i++)
  168.         $sysInfile = $sysInfile + "\\\\" + $buffer[$i];
  169.     
  170.  
  171.     tokenize($outfile, "\\/", $buffer);
  172.     $sysOutfile = $buffer[(size($buffer) - 1)];
  173.  
  174.     $cmd = "system(\"ren \\\"" + $sysInfile + "\\\" \\\"" + $sysOutfile + "\\\"\")";
  175.     eval($cmd);
  176. }
  177.  
  178. global proc copyFile(string $infile, string $outfile)
  179. {
  180.     string $buffer[];
  181.     tokenize($infile, "\\/", $buffer);
  182.     $sysInfile = $buffer[0];
  183.     for($i=1; $i<size($buffer); $i++)
  184.         $sysInfile = $sysInfile + "\\\\" + $buffer[$i];
  185.  
  186.     tokenize($outfile, "\\/", $buffer);
  187.     $sysOutfile = $buffer[0];
  188.     for($i=1; $i<size($buffer); $i++)
  189.         $sysOutfile = $sysOutfile + "\\\\" + $buffer[$i];
  190.  
  191.     $cmd = "system(\"copy \\\"" + $sysInfile + "\\\" \\\"" + $sysOutfile + "\\\"\")";
  192.     eval($cmd);
  193. }
  194.  
  195. global proc deleteFile(string $infile)
  196. {
  197.     string $buffer[];
  198.     tokenize($infile, "\\/", $buffer);
  199.     $sysInfile = $buffer[0];
  200.     for($i=1; $i<size($buffer); $i++)
  201.         $sysInfile = $sysInfile + "\\\\" + $buffer[$i];
  202.  
  203.     $cmd = "system(\"del \\\"" + $sysInfile + "\\\"\")";
  204.     eval($cmd);
  205. }
  206.  
  207. global proc modelPacker(string $file)
  208. {
  209.     string $buffer[];
  210.     string $noGeom = "";
  211.     if((`checkBox -q -en lt_compileNoGeomCheck`) && (`checkBox -q -v lt_compileNoGeomCheck`))
  212.         $noGeom = " -nogeom";    
  213.  
  214.     tokenize($file, "\\/", $buffer);
  215.     $sysFile = $buffer[0];
  216.     for($i=1; $i<size($buffer); $i++)
  217.         $sysFile = $sysFile + "\\\\" + $buffer[$i];
  218.  
  219.     string $path = `optionVar -q lt_toolPath`;
  220.  
  221.     tokenize($path, "\\/", $buffer);
  222.     $toolPath = $buffer[0];
  223.     for($i = 1;$i < size($buffer); $i++)
  224.         $toolPath = $toolPath + "\\\\" + $buffer[$i];
  225.     $toolPath = $toolPath + "\\\\model_packer d3d -ac2" + $noGeom + " -inplace";
  226.  
  227.     $cmd = "system(\"" + $toolPath + " \\\"" + $sysFile + "\\\" \")"; // -verbose\")";
  228.     evalEcho($cmd);
  229. }
  230.  
  231.  
  232.  
  233. global proc string getFileType(string $filename)
  234. {
  235.     string $buffer[];
  236.     tokenize($filename, ".", $buffer);
  237.     if(size($buffer) < 2 || size($buffer[(size($buffer))-1]) != 3)
  238.         error "Unknown filetype\n";
  239.  
  240.     return $buffer[size($buffer)-1];
  241. }
  242.  
  243. global proc string getTempLtaFile(string $filename)
  244. {
  245.     string $tmpLtaFilename;
  246.     $filetype = `getFileType $filename`;
  247.     if($filetype != "lta" && $filetype != "ltc")
  248.         error "Only works on ltc or lta files";
  249.     if($filetype == "ltc")
  250.     {
  251.         $tmpFilename = $filename + "temp.ltc";
  252.         $tmpLtaFilename = $filename + "temp.lta";
  253.         copyFile $filename $tmpFilename;
  254.         ltcConvert $tmpFilename "ltc";
  255.         return $tmpLtaFilename;
  256.     }
  257.     else 
  258.     {
  259.         $tmpLtaFilename = $filename + "temp.lta";
  260.         copyFile $filename $tmpLtaFilename;
  261.         return $tmpLtaFilename;
  262.     }
  263. }
  264.  
  265. global proc cleanUpTempLtaFile(string $filename)
  266. {    
  267.     string $tempLtc = (`substring $filename 1 ((size($filename))-1)`) + "c";
  268.     deleteFile $filename; 
  269.     deleteFile $tempLtc;
  270. }
  271.  
  272.  
  273.  
  274.  
  275. global proc ltaExportNoAppend(string $filename, int $append)
  276. {
  277.     string $textureIndex, $sockets, $weightSets, $buffer[];
  278.     string $sockets, $weightSets, $childModels, $keepFile, $ltcName;
  279.     string $lastLine, $tmpFilename, $defaultAnimName, $exportJoint[];
  280.     int  $timeRange, $weightSetExport;
  281.     float $xDim, $yDim, $zDim, $scale;
  282.  
  283.     $fileType = `substring $filename (size($filename)-2) (size($filename))`;
  284.     $fileBase = `substring $filename 1 (size($filename)-4)`;
  285.     $ltaName = $filename;
  286.     if($fileType == "ltc")
  287.     {
  288.         findLTCconverter;
  289.         $keepFile = $filename;
  290.         ltcConvert $filename "ltc";  
  291.         $filename = `substitute "ltc" $filename "lta"`;
  292.         $ltaName = $filename;
  293.         if(`file -q -ex $keepFile`) 
  294.             deleteFile $keepFile;
  295.         if(`file -q -ex $filename`)        
  296.         {    
  297.             $filename = $fileBase + "tmp_del.lta"; 
  298.             $ltcName = $fileBase + "tmp_del.ltc"; 
  299.         }
  300.  
  301.     }
  302.     else if($fileType != "lta")
  303.         $filename = $filename + ".lta";
  304.  
  305.         
  306.     $tmpFilename = "temp_tmp.lta";
  307.  
  308.     if(`window -ex ExportLtaUI`)
  309.         $defaultAnimName = `textFieldGrp -q -text lt_animName`;   
  310.     else
  311.         $defaultAnimName = `optionVar -q lt_defaultAnimName`;
  312.  
  313.     if($append)
  314.     {
  315.         $tmpFilename = $fileBase + $tmpFilename;
  316.         renameFile $ltaName $tmpFilename;
  317.         $defaultAnimName = getUniqueAnimName($tmpFilename, $defaultAnimName);
  318.     }
  319.  
  320.     string $root[] = `ls -dag -type joint`;
  321.  
  322.     if($defaultAnimName == "")
  323.     { $defaultAnimName = "default";  optionVar -sv lt_defaultAnimName "default";  }
  324.  
  325.     $scale = `floatFieldGrp -q -v1 lt_scale`;
  326.     $timeRange = `optionVar -q lt_defaultTimeRangeStatus`;
  327.     $weightSetExport = `optionVar -q lt_defaultSocketExportStatus`;
  328.     $childModelExport = `optionVar -q lt_defaultChildModelExportStatus`;
  329.     $compile = `optionVar -q lt_defaultCompileModelStatus`;
  330. //
  331. //
  332. //
  333.  
  334. int $ignoreBindPose = 1;
  335. int $exportWorldNode = 0;
  336.  
  337.  
  338.     string $cmd = "lithtechModelExport -all ";
  339.     
  340.     if($timeRange) 
  341.         $cmd = $cmd + "-usePlaybackRange ";
  342.     if($append)
  343.         $cmd = $cmd + "-append ";
  344.     if($ignoreBindPose)
  345.         $cmd = $cmd + "-ignoreBindPose ";
  346.     if($exportWorldNode)
  347.         $cmd = $cmd + "-exportWorldNode ";
  348.     
  349.     $cmd = $cmd + "-scale " + $scale + " \"" + $defaultAnimName + "\" \"" + $tmpFilename + "\"";
  350.     evalEcho($cmd);
  351.  
  352.  
  353.     $xDim = `optionVar -q lt_defaultUserDimX`;
  354.     $yDim = `optionVar -q lt_defaultUserDimY`;
  355.     $zDim = `optionVar -q lt_defaultUserDimZ`;
  356.     $exportJoint = `getSkeleton`;
  357.  
  358.     int $tmpFileId = `fopen $tmpFilename "r"`;
  359.     int $FileId = `fopen $filename "w"`;
  360.  
  361.     if(($tmpFileId != 0) && ($FileId !=0))
  362.     {
  363.         int $looking = 0;
  364.         $prevLine = "";
  365.         $lastLine = `fgetline $tmpFileId`;
  366.         while(!`feof $tmpFileId`)
  367.         {
  368.             $prevLine = $lastLine;
  369.             $lastLine = `fgetline $tmpFileId`;
  370.             fprint $FileId $prevLine;
  371.  
  372.             if(`gmatch $lastLine "*on-load-cmds*"`)
  373.             {
  374.                 if(`gmatch $lastLine "*(on-load-cmds )*"`)
  375.                     $lastLine = "(on-load-cmds \n";
  376.                 if($append)
  377.                 { 
  378.                     string $tmp1 = `fgetline $tmpFileId`;
  379.                     string $tmp2 = `fgetline $tmpFileId`;
  380.                     if(`gmatch $tmp2 "*anim*"`)
  381.                         fgetline $tmpFileId;
  382.                 }
  383.                     
  384.                 $lastLine = $lastLine + "\t(anim-bindings \n\t(\n\t\t";
  385.                  
  386.                     
  387.                 $lastLine = $lastLine + "(anim-binding \n\t\t\t(name \""
  388.                             + $defaultAnimName + "\" )\n\t\t\t(dims \n\t\t\t\t("
  389.                             + ($scale * $xDim) + " " + ($scale * $yDim) + " " + ($scale * $zDim) + " ))\n";
  390.  
  391.         
  392.                 
  393.                 if(`objExists ($exportJoint[0] + ".translation")`)
  394.                 {
  395.                     $trans = `getAttr ($exportJoint[0] + ".translation")`; 
  396.                     $lastLine = $lastLine + " (translation ( " + $trans + " ) )\n";
  397.                 }
  398.                 if(`objExists ($exportJoint[0] + ".interpolation")`)
  399.                 {
  400.                     $interp = `getAttr ($exportJoint[0] + ".interpolation")`; 
  401.                     $lastLine = $lastLine + " (interp-time " + $interp + " )\n";
  402.                 }
  403.                 $lastLine = $lastLine + ")\n";
  404.  
  405.                 if(!$append) $lastLine = $lastLine + "))\n";
  406.                 
  407.                 if(!$append)    
  408.                 {
  409.                 
  410.  
  411.                     if(`objExists ($exportJoint[0] + ".nodeFlags")` )
  412.                     {
  413.                         string $nodeFlags = `getAttr ($exportJoint[0] + ".nodeFlags")`;
  414.                         if((size($nodeFlags)) == (size($exportJoint)))
  415.                         {
  416.                             $lastLine = $lastLine + "\t\t(set-node-flags\n\t\t\t(\n";
  417.                             for($i = 0; $i < size($exportJoint); $i++)
  418.                             {
  419.                                 $flag = `substring $nodeFlags ($i+1) ($i+1)`;
  420.                                 $lastLine = $lastLine + "\t\t\t\t(\"" + $exportJoint[$i] + "\" " + $flag + " )\n";
  421.                             }
  422.                             $lastLine = $lastLine + "\t\t\t)\n\t\t)\n";
  423.                         }
  424.                         else 
  425.                             print "Error adding node flag settings\n";
  426.                     }
  427.         
  428.                     
  429.                     if(`objExists ($exportJoint[0] + ".cmdString")` )
  430.                     {    
  431.                         string $cmdString = `getAttr ($exportJoint[0] + ".cmdString")`;
  432.                         if($cmdString != "")
  433.                             $lastLine = $lastLine + "\t\t(set-command-string \"" + $cmdString + "\" )\n";
  434.                     }
  435.  
  436.                     if(`objExists ($exportJoint[0] + ".internalRadius")` )
  437.                     {    
  438.                         string $internalRadius = `getAttr ($exportJoint[0] + ".internalRadius")`;
  439.                         if($internalRadius != "")
  440.                             $lastLine = $lastLine + "\t\t(set-global-radius " + $internalRadius + " )\n";
  441.                     }
  442.             
  443.                     
  444.                     
  445.                     if(`objExists ($exportJoint[0] + ".childModels")` && $childModelExport)
  446.                     {
  447.                         string $childModels = `getAttr ($exportJoint[0] + ".childModels")`;
  448.                         if($childModels != "")
  449.                         {
  450.                             tokenize($childModels, " ", $buffer);
  451.                             $lastLine = $lastLine + "\t\t(add-childmodels\n\t\t\t(\n";
  452.                             for($i = 0; $i < size($buffer); $i++)
  453.                             {
  454.                                 $lastLine = $lastLine + "\t\t\t\t(child-model\n\t\t\t\t\t";
  455.                                 $lastLine = $lastLine + "(filename \"" + $buffer[$i] + "\" ) )\n";
  456.                             }
  457.                             $lastLine = $lastLine + "\t\t\t)\n\t\t)\n";
  458.                         }
  459.         
  460.                     }
  461.  
  462.                     string $LODGroups[] = `getLODInfo`;
  463.                     if(size($LODGroups) > 0)
  464.                     {
  465.                         $lastLine = $lastLine + "\t\t(lod-groups\n\t\t\t(\n";
  466.                         for($i = 0; $i < size($LODGroups); $i++)
  467.                         {
  468.                             tokenize($LODGroups[$i], " ", $buffer);
  469.                             $lastLine = $lastLine + "\t\t\t\t(create-lod-group \"" + $buffer[0] + "\"\n\t\t\t\t\t(lod-dists\n\t\t\t\t\t\t(";
  470.                             for($j = 0; $j < (size($buffer))/2; $j++)
  471.                                 $lastLine = $lastLine + $buffer[2*$j+1] + " " ;
  472.                             $lastLine = $lastLine + ")\n\t\t\t\t\t)\n\t\t\t\t\t(shapes\n\t\t\t\t\t\t(";
  473.                             for($j = 0; $j < (size($buffer))/2; $j++)
  474.                                 $lastLine = $lastLine + "\"" + $buffer[2*$j] + "\" " ;
  475.                             $lastLine = $lastLine + ")\n\t\t\t\t\t)\n\t\t\t\t)\n";
  476.  
  477.                         }
  478.                         $lastLine = $lastLine + "\t\t\t)\n\t\t)\n";
  479.                     }
  480.  
  481.  
  482.                 }
  483.  
  484.                 if($weightSetExport && !$append)
  485.                 {
  486.                     $weightSets = `getDefaultWeightSets`;
  487.                     $lastLine = $lastLine + $weightSets;
  488.                 }
  489. //                if((`objExists ($exportJoint[0] + ".weightSets")`) && $weightSetExport)
  490. //                {
  491. //                    $weightSets = `getAttr ($exportJoint[0] + ".weightSets")`;
  492. //                    $lastLine = $lastLine + "\t\t" + $weightSets + "\n";
  493. //                }
  494.  
  495.             }
  496.  
  497.             
  498.             if((`gmatch $lastLine "*tools-info*"`) && !$append)
  499.             {
  500.                 if(`objExists ($exportJoint[0] + ".DTXInfo")`)
  501.                 {
  502.                     string $DTXInfo = `getAttr ($exportJoint[0] + ".DTXInfo")`;
  503.                     tokenize($DTXInfo, " ", $buffer);
  504.                     fgetline $tmpFileId;
  505.                     $lastLine = $lastLine + "\t(\n\t\t(texture-bindings \n\t\t\t(\n";
  506.                     for($i = 0; $i < size($buffer); $i++)
  507.                     {
  508.                         if($buffer[$i] != "" && $buffer[$i] != "XXXX")
  509.                             $lastLine = $lastLine + "\t\t\t\t(" + $i + " \"" + $buffer[$i] + "\" )\n";
  510.                     }
  511.                     $lastLine = $lastLine + "\t\t\t)\n\t\t)\n\t)\n";
  512.                 }
  513.             }
  514.             
  515.             if(`gmatch $lastLine ("*animset \"" + $defaultAnimName + "\"*")`)
  516.             {
  517.                 if((`objExists ($exportJoint[0] + ".modelStrings")`)&&(`objExists ($exportJoint[0] + ".keyTimes")`))
  518.                 {
  519.                     $lastLine = $lastLine + (`fgetline $tmpFileId`);
  520.                     $lastLine = $lastLine + (`fgetline $tmpFileId`);
  521.                     $lastLine = $lastLine + (`fgetline $tmpFileId`);
  522.                     fprint $FileId $lastLine;
  523.  
  524.                     string $modelString = `getAttr ($exportJoint[0] + ".modelStrings")`;
  525.                     string $keyTime = `getAttr ($exportJoint[0] + ".keyTimes")`;
  526.  
  527.                     string $modelStrings[];
  528.                     float $keyTimes[];
  529.                     tokenize($modelString, "#", $modelStrings);
  530.                     tokenize($keyTime, " ", $buffer);
  531.                     
  532.                     for($i = 0; $i < size($buffer); $i++)
  533.                         $keyTimes[$i] = float($buffer[$i]);
  534.                     
  535.                     $lastLine = $animLine = "";
  536.                     while(!`gmatch $animLine "*\t)*"`)
  537.                     {
  538.                         $animLine = `fgetline $tmpFileId`;
  539.                         $lastLine = $lastLine + $animLine;
  540.                     }
  541.                     tokenize ($lastLine, "( )\n\t", $buffer);
  542.                     $lastLine = $lastLine + "\t\t\t(values\n\t\t\t\t(";
  543.  
  544.                     int $minBuffer = 0;
  545.                     for($i = 0; $i < size($keyTimes); $i++)
  546.                     {
  547.                         for($j = $minBuffer; $j < size($buffer); $j++)
  548.                         {
  549.                             if(float($buffer[$j]) >= $keyTimes[$i])
  550.                             {
  551.                                 print($buffer[$j] + " " + $modelStrings[$i] + "\n");
  552.                                 $lastLine = $lastLine + $modelStrings[$i] +  " ";    
  553.                                 $j++;
  554.                                 break;
  555.                             }
  556.                             else 
  557.                                 $lastLine = $lastLine + "\"\" ";
  558.                         }
  559.                         $minBuffer = $j;
  560.                     }
  561.                     $lastLine = $lastLine + " )\n\t\t\t)\n";
  562.                 }
  563.             }
  564.         }
  565.         fprint $FileId $lastLine;
  566.     }
  567.  
  568.         fclose $FileId;
  569.         fclose $tmpFileId;
  570.  
  571.     if($fileType == "ltc")
  572.     {
  573.         ltcConvert $filename "lta"; 
  574.         renameFile $ltcName $keepFile; 
  575.         if(`file -q -ex $ltaName`)
  576.             deleteFile $ltaName;
  577.     }
  578.  
  579.     deleteFile $tmpFilename; 
  580.  
  581.     if($compile)
  582.     {
  583.         if($fileType == "ltc")
  584.             modelPacker $keepFile;
  585.         if($fileType == "lta")
  586.             modelPacker $filename;
  587.     }
  588.     if(`window -ex ExportLtaUI`)
  589.         deleteUI ExportLtaUI;
  590.     if(`window -ex ltaWarningUI`)
  591.         deleteUI ltaWarningUI;
  592.  
  593.     print("Done\n");
  594. }
  595.  
  596. global proc ltaWarning()
  597. {
  598.     $ui_Width = 255;
  599.     $ui_Height= 125;
  600.  
  601.     if(`window -ex ltaWarningUI`)
  602.         deleteUI ltaWarningUI;
  603.  
  604.     window
  605.         -menuBar false 
  606.         -maximizeButton 0
  607.         -minimizeButton 0
  608.         -sizeable 0
  609.         -rtf 1
  610.         -w $ui_Width
  611.         -h $ui_Height
  612.         -title "ScottTech2000"
  613.         ltaWarningUI;
  614.     
  615.     columnLayout;
  616.         frameLayout
  617.             -label "Warning!"
  618.             -w ($ui_Width-10)
  619.             -h ($ui_Height-70);    
  620.             text -label "\nYou are about to overwrite an existing file...\n" -align "center";        
  621.         setParent ..;    
  622.         rowLayout
  623.             -numberOfColumns 3
  624.             -rat 1 "top" 2
  625.             -rat 2 "top" 2
  626.             -rat 3 "top" 2
  627.             -columnWidth 1 82
  628.             -columnWidth 2 82;
  629.             button -label "Overwrite" -al "center"
  630.                 -w 80    -h 30
  631.                 -c "string $filename = (`optionVar -q lt_defaultFilename`); ltaExportNoAppend $filename 0; if(`window -ex ltaWarningUI`) deleteUI ltaWarningUI;";
  632.  
  633.             button -label "Append" -al "center"
  634.                 -w 80    -h 30
  635.                 -c "string $filename = (`optionVar -q lt_defaultFilename`); ltaExportNoAppend $filename 1; if(`window -ex ltaWarningUI`) deleteUI ltaWarningUI;";
  636.  
  637.             button    -label "Cancel" -al "center"
  638.                 -w 80    -h 30
  639.     //            -c "deleteUI ltaWarningUI";
  640.                 -c "string $filename = (`optionVar -q lt_defaultFilename`); getHierarchy $filename; deleteUI ltaWarningUI;";                
  641.  
  642.         setParent;
  643.     setParent ..;
  644.  
  645.     showWindow ltaWarningUI;
  646. }
  647.  
  648. global proc string[] getHierarchy(string $filename)
  649. {    
  650.     string $line, $char, $joint[], $buffer[];
  651.     int  $index, $i, $jin[], $jout[], $looking = 0;
  652.  
  653.     $tmpLtaFilename = `getTempLtaFile $filename`;
  654.     int $fileId = `fopen $tmpLtaFilename "r"`;
  655.     if($fileId == 0) { print "Error opening file\n"; fclose $fileId; return {"",""}; }
  656.  
  657.     while(!`feof $fileId`)
  658.     {
  659.         $line = `fgetline $fileId`;
  660.         if(`gmatch $line "*hierarchy*"`)
  661.         {
  662.             $index = 0;
  663.             $looking = 1;
  664.         }
  665.  
  666.         if($looking)
  667.         {
  668.             if(`gmatch $line "*transform*"`)
  669.             {
  670.                 tokenize($line, "\"", $buffer);
  671.                 $joint[$index] = $buffer[1];
  672.  
  673.                 $tabCount = 0;
  674.                 for($i = 0; $i <size($line); $i++)
  675.                 {
  676.                     $char = `getChar $line $i`;
  677.                     if($char == "\t") 
  678.                         $tabCount++;
  679.                     else break;
  680.                 }
  681.                 
  682.                 $joint[$index+1] = string(($tabCount-1)/3-1);    
  683.                 $index = $index + 2;
  684.             }
  685.             if((`gmatch $line "*shape*"`) || (`gmatch $line "*animset*"`))
  686.             {
  687.                 break;
  688.             }                    
  689.         }        
  690.     }
  691.     fclose $fileId;
  692.     cleanUpTempLtaFile $tmpLtaFilename;
  693.  
  694.     for($i = 1; $i < (size($joint)); $i=$i+2)
  695.         $jin[($i-1)/2] = int($joint[$i]);
  696.     $jout[0] = 0;
  697.     for($i = 1; $i < size($jin); $i++)
  698.     {
  699.         if($jin[$i] != ($jin[$i-1] + 1))
  700.         {    
  701.             for($k = ($i-1); $k>=0; $k--)
  702.                 if($jin[$k] == ($jin[$i]-1))
  703.                 {
  704.                     $jout[$i] = $k;
  705.                     break;
  706.                 }
  707.         }
  708.         else
  709.             $jout[$i] = $i-1;
  710.         
  711.         $joint[2*$i +1] = string($jout[$i]);
  712.     }
  713.         $joint[1] = "0";
  714.         return $joint;
  715.     }
  716.  
  717.  
  718. global proc getSceneHierarchy()
  719. {    
  720.     string $skel[];
  721.     $selection = `ls -sl`;
  722.     $skelNodes = `ls -dag -type joint`;
  723.     select -hi $skelNodes[0];
  724.     $skel = `ls -sl -type joint`;
  725.     print $skel;
  726.     select -r $selection; 
  727. }
  728.  
  729. global proc string[] getLTAInfo(string $input, string $filename)
  730. {
  731.     string $line, $newLine, $buffer[], $output[];
  732.     int $searching = 0, $fileId = `fopen $filename "r"`;
  733.     int $i = 0, $open, $close, $diff;
  734.     if($fileId == 0)  error("Something's afoul");
  735.     $input = "*" + $input + "*";
  736.     $line = `fgetline $fileId`;
  737.  
  738.     while(!`feof $fileId`)
  739.     {
  740.         $line = `fgetline $fileId`;
  741.     
  742.         if(`gmatch $line $input` && !$searching)
  743.         {
  744.             $searching = 1;
  745.             $open = 0;
  746.             $close = 0;
  747.             $output[$i] = "";    
  748.         }
  749.  
  750.         if($searching)
  751.         {
  752.             tokenize($line, "\t\r\n", $buffer);
  753.             for($chunk in $buffer)
  754.                 $newLine = $newLine + $chunk;
  755.             $line = $newLine;
  756.             $newLine = "";
  757.  
  758.             $open = $open + `howMany "(" $line`;
  759.             $close = $close + `howMany ")" $line`;
  760.  
  761.             if($open <= $close)
  762.             {
  763.                 $output[$i] = $output[$i] + $line;
  764.                 $searching = 0;
  765.                 $i++;
  766.  
  767.                 if(($open < $close) && ($output[$i] != ""))
  768.                 {
  769.                     $len = size($output[$i]); 
  770.                     if(`substring $output[$i] $len $len` == " ")
  771.                         $len = $len - $close + $open + 1;
  772.                     else
  773.                         $len = $len - $close + $open;
  774.                     $output[$i] = `substring $output[$i] 1 $len`;
  775.                 }
  776.             }
  777.             else
  778.                 $output[$i] = $output[$i] + $line;
  779.         }
  780.     }
  781.     fclose $fileId; 
  782.     return $output;
  783. }
  784.  
  785. global proc int howMany(string $input, string $searchString)
  786. {
  787.     string $buffer[];
  788.     int $inLen, $outLen, $output;
  789.  
  790.     $input = `substring $input 1 1`;
  791.     $inLen = size($searchString);
  792.     $outLen = 0;
  793.     tokenize($searchString, $input, $buffer);
  794.         
  795.     for($i in $buffer)
  796.         $outLen = $outLen + size($i);
  797.     $output = $inLen - $outLen;
  798.     return $output;    
  799. }
  800.  
  801. global proc setInterp()
  802. {
  803.     string $root[] = `ls -dag -type joint`;
  804.     if(!`objExists ($root[0] + ".interpolation")`)
  805.         addAttr -ln "interpolation" -at "float" $root[0];
  806.     setAttr ($root[0] + ".interpolation") (`floatFieldGrp -q -v1 lt_interp`);
  807. }
  808.  
  809. global proc setAnimName()
  810. {
  811.     string $root[] = `ls -dag -type joint`;
  812.     if(!`objExists ($root[0] + ".animName")`)
  813.         addAttr -ln "animName" -dt "string" $root[0];
  814.     setAttr ($root[0] + ".animName") -type "string" (`textFieldGrp -q -text lt_animName`);
  815. }
  816.  
  817. global proc setFileName()
  818. {
  819.     string $root[] = `ls -dag -type joint`;
  820.     if(!`objExists ($root[0] + ".fileName")`)
  821.         addAttr -ln "fileName" -dt "string" $root[0];
  822.     setAttr ($root[0] + ".fileName") -type "string" (`textFieldButtonGrp -q -text lt_filename`);
  823.     
  824. }
  825.  
  826. global proc setScale()
  827. {
  828.     string $root[] = `ls -dag -type joint`;
  829.     if(!`objExists ($root[0] + ".ltScale")`)
  830.         addAttr -ln "ltScale" -at "float" $root[0];
  831.     setAttr ($root[0] + ".ltScale") (`floatFieldGrp -q -v1 lt_scale`);
  832. }
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839. global proc lta_Export()
  840. {
  841.     string $filename = `textFieldButtonGrp -q -fi lt_filename`;
  842.     optionVar -sv lt_defaultFilename $filename;
  843.  
  844.  
  845.     if(`file -q -ex $filename`)
  846.     {
  847. //        if(`file -q -w $filename`)
  848. //        {
  849.             if(`optionVar -q lt_defaultAppendStatus`)
  850.             {
  851.                 ltaExportNoAppend $filename 1;
  852.             }
  853.             else 
  854.                 ltaWarning;
  855. //        }
  856. //        else error("File is read-only");
  857.     }
  858.  
  859.  
  860.     else if(!(`file -q -ex $filename`))
  861.             ltaExportNoAppend $filename 0;    
  862.  
  863. }
  864.  
  865.  
  866.  
  867. global proc ltExport()
  868. {
  869.     int $ui_Width = 470;
  870.     int $ui_Height = 320;
  871.     string $buffer[], $textureIndex, $fileName;
  872.     string $sceneName = `file -q -sn`;
  873.     tokenize($sceneName, ".", $buffer);
  874.     string $scenePath = $buffer[0];
  875.     $scene = `getSceneName`;
  876.  
  877. /////////////////////////////////////////////
  878. // Create defaults if they don't exist
  879. /////////////////////////////////////////////
  880.  
  881.     if(!`optionVar -ex lt_defaultFilename`)
  882.         optionVar -sv lt_defaultFilename ($scenePath+".lta");
  883.  
  884.     if(!`optionVar -ex lt_defaultAppendStatus`)
  885.         optionVar -iv lt_defaultAppendStatus 0;
  886.  
  887.     if(!`optionVar -ex lt_defaultTimeRangeStatus`)
  888.         optionVar -iv lt_defaultTimeRangeStatus 1;
  889.  
  890.     if(!`optionVar -ex lt_defaultSocketExportStatus`)
  891.         optionVar -iv lt_defaultSocketExportStatus 0;
  892.     if(!`optionVar -ex lt_defaultChildModelExportStatus`)
  893.         optionVar -iv lt_defaultChildModelExportStatus 0;
  894.     if(!`optionVar -ex lt_defaultCompileModelStatus`)
  895.         optionVar -iv lt_defaulCcompileModelStatus 0;
  896.     if(!`optionVar -ex lt_defaultCompileNoGeomStatus`)
  897.         optionVar -iv lt_defaultCompileNoGeomStatus 0;
  898.  
  899.     if(!`optionVar -ex lt_defaultUserDimX`)
  900.         optionVar -fv lt_defaultUserDimX 128;
  901.     if(!`optionVar -ex lt_defaultUserDimY`)
  902.         optionVar -fv lt_defaultUserDimY 16;
  903.     if(!`optionVar -ex lt_defaultUserDimZ`)
  904.         optionVar -fv lt_defaultUserDimZ 16;
  905.     if(`optionVar -q lt_defaultUserDimX` == 0)
  906.         optionVar -fv lt_defaultUserDimX 128;
  907.     if(`optionVar -q lt_defaultUserDimY` == 0)
  908.         optionVar -fv lt_defaultUserDimY 16;
  909.     if(`optionVar -q lt_defaultUserDimZ` == 0)
  910.         optionVar -fv lt_defaultUserDimZ 16;
  911.  
  912.     if(!`optionVar -ex lt_defaultUserDimPrec`)
  913.         optionVar -iv lt_defaultUserDimPrec 0;
  914.     
  915.     string $root[] = `ls -dag -type joint`;
  916.     if($root[0] != "")
  917.     {
  918.         if(`objExists ($root[0] + ".dimX")`)
  919.             optionVar -fv lt_defaultUserDimX (`getAttr ($root[0] + ".dimX")`);
  920.         if(`objExists ($root[0] + ".dimY")`)
  921.             optionVar -fv lt_defaultUserDimY (`getAttr ($root[0] + ".dimY")`);
  922.         if(`objExists ($root[0] + ".dimZ")`)
  923.             optionVar -fv lt_defaultUserDimZ (`getAttr ($root[0] + ".dimZ")`);
  924.     }
  925.  
  926.     if(!`optionVar -ex lt_defaultAnimName`)
  927.         optionVar -sv lt_defaultAnimName $scene;
  928.             
  929.     if(!`optionVar -ex lt_toolPath`)
  930.         optionVar -sv lt_toolPath "";
  931.     if(!`optionVar -ex lt_gamePath`)
  932.         optionVar -sv lt_gamePath "";
  933.  
  934.  
  935.     float $scale = 1.0;
  936.     if(`objExists ($root[0] + ".ltScale")`)
  937.         $scale = `getAttr ($root[0] + ".ltScale")`;
  938.     else
  939.     {
  940.         addAttr -ln "ltScale" -at "float" $root[0];
  941.         setAttr ($root[0] + ".ltScale") $scale;    
  942.     }
  943.  
  944.  
  945.     if(`objExists ($root[0] + ".animName")`)
  946.         $animName = `getAttr ($root[0] + ".animName")`;
  947.     else
  948.     {
  949.         $animName = `optionVar -q lt_defaultAnimName`;
  950.         addAttr -ln "animName" -dt "string" $root[0];
  951.         setAttr ($root[0] + ".animName") -type "string" $animName;
  952.     }
  953.  
  954.  
  955.     if(`objExists ($root[0] + ".fileName")`)
  956.     {
  957.         $fileName = `getAttr ($root[0] + ".fileName")`;
  958. //        if(`gmatch $fileName "*TO2*"`)
  959. //        {
  960. //            $fileName = `substitute "TO2" $fileName "NOLF2"`;
  961. //            setAttr ($root[0] + ".fileName") -type "string" $fileName;
  962. //        }
  963.     }
  964.     else
  965.     {
  966.         $fileName = `optionVar -q lt_defaultFilename`;
  967.         addAttr -ln "fileName" -dt "string" $root[0];
  968.         setAttr ($root[0] + ".fileName") -type "string" $fileName;
  969.     }
  970.  
  971.     
  972.     float $interp = 200;
  973.     if(`objExists ($root[0] + ".interpolation")`)
  974.         $interp = `getAttr ($root[0] + ".interpolation")`;
  975.  
  976.  
  977.     fixShapePieceInfo;
  978.  
  979.  
  980.  
  981.     if(`window -ex ExportLtaUI`)
  982.         deleteUI ExportLtaUI;
  983.     window
  984.         -menuBar false 
  985.         -maximizeButton false
  986.         -sizeable 1
  987.         -w 5//$ui_Width
  988.         -h 5//$ui_Height
  989.         -rtf 1
  990.         -title "ScottTech2000"
  991.         ExportLtaUI;
  992.     columnLayout;    
  993.         frameLayout
  994.             -label "Filename"
  995.             -w 460
  996.             -h 45;
  997.             textFieldButtonGrp
  998.                 -cw 1 10
  999.                 -cw 2 390    
  1000.                 -label " "
  1001.                 -fi $fileName
  1002.                 -cc "setFileName"
  1003.                 -buttonLabel "Browse..."
  1004.                 -buttonCommand getNewFilename
  1005.                 lt_filename;
  1006.         setParent ..;
  1007.     rowLayout
  1008.         -numberOfColumns 2
  1009.         -cw 1 368
  1010.         -cw 2 120;    
  1011.         columnLayout;
  1012.             frameLayout
  1013.                 -label "Lta Export Options"
  1014.                 -w (362)
  1015.                 -h ($ui_Height-50);
  1016.                 columnLayout;
  1017.                     textFieldGrp
  1018.                         -cw 1 100
  1019.                         -cw 2 200
  1020.                         -label "Animation Name:" 
  1021.                         -text     $animName
  1022.                         -cc     "optionVar -sv lt_defaultAnimName (`textFieldGrp -q -text lt_animName`); setAnimName;"
  1023.                         lt_animName;
  1024.                     rowLayout
  1025.                         -numberOfColumns 2
  1026.                         -cw 1 100
  1027.                         -rat 1 "top" 5
  1028.                         -rat 2 "top" 5;
  1029.                         text -label "Options:" -al "right";
  1030.                         columnLayout;
  1031.                             checkBox 
  1032.                                 -label "Append animation if file exists?"
  1033.                                 -al "right"
  1034.                                 -value `optionVar -q lt_defaultAppendStatus`
  1035.                                 -cc     "optionVar -iv lt_defaultAppendStatus (`checkBox -q -v lt_appendCheck`)"
  1036.                                 lt_appendCheck;
  1037.                             checkBox 
  1038.                                 -label "Use time slider range?"
  1039.                                 -al "right"
  1040.                                 -value `optionVar -q lt_defaultTimeRangeStatus`
  1041.                                 -cc     "optionVar -iv lt_defaultTimeRangeStatus (`checkBox -q -v lt_timeRangeCheck`)"
  1042.                                 lt_timeRangeCheck;
  1043.                             checkBox 
  1044.                                 -label "Export weight-sets (ignored if appending)"
  1045.                                 -al "right"
  1046.                                 -value `optionVar -q lt_defaultSocketExportStatus`
  1047.                                 -cc     "optionVar -iv lt_defaultSocketExportStatus (`checkBox -q -v lt_socketExportCheck`)"
  1048.                                 lt_socketExportCheck;
  1049.                             checkBox 
  1050.                                 -label "Export child models (ignored if appending)"
  1051.                                 -al "right"
  1052.                                 -value `optionVar -q lt_defaultChildModelExportStatus`
  1053.                                 -cc     "optionVar -iv lt_defaultChildModelExportStatus (`checkBox -q -v lt_childModelExportCheck`)"
  1054.                                 lt_childModelExportCheck;
  1055.                             checkBox 
  1056.                                 -label "Compile model"
  1057.                                 -al "right"
  1058.                                 -value `optionVar -q lt_defaultCompileModelStatus`
  1059.                                 -cc     "optionVar -iv lt_defaultCompileModelStatus (`checkBox -q -v lt_compileModelCheck`); checkBox -e -en (`optionVar -q lt_defaultCompileModelStatus`) lt_compileNoGeomCheck;"
  1060.                                 lt_compileModelCheck;
  1061.                             checkBox 
  1062.                                 -label "Compile with no geometry"
  1063.                                 -al "right"
  1064.                                 -en    `optionVar -q lt_defaultCompileModelStatus`
  1065.                                 -value    `optionVar -q lt_defaultCompileNoGeomStatus`
  1066.                                 -cc     "optionVar -iv lt_defaultCompileNoGeomStatus (`checkBox -q -v lt_compileNoGeomCheck`)"
  1067.                                 lt_compileNoGeomCheck;
  1068.                             floatFieldGrp 
  1069.                                 -numberOfFields 3
  1070.                                 -label "User Dims (XYZ)"
  1071.                                 -cat 1 left 0 -cw 1 90 
  1072.                                 -cat 2 left 0 -cw 2 50        
  1073.                                 -cat 3 left 0 -cw 3 50
  1074.                                 -cat 4 left 0 -cw 4 50            
  1075.                                 -value1 `optionVar -q lt_defaultUserDimX` 
  1076.                                 -value2 `optionVar -q lt_defaultUserDimY` 
  1077.                                 -value3 `optionVar -q lt_defaultUserDimZ`
  1078.                                 -pre `optionVar -q lt_defaultUserDimPrec`
  1079.                                 -cc     "setUserDims"
  1080.                                 lt_userDims;
  1081.                                 popupMenu;
  1082.                                     menuItem -l "0" -c "floatFieldGrp -e -pre 0 lt_userDims; updateUserDims; optionVar -iv lt_defaultUserDimPrec 0;";
  1083.                                     menuItem -l "0.0" -c "floatFieldGrp -e -pre 1 lt_userDims; updateUserDims; optionVar -iv lt_defaultUserDimPrec 1;";
  1084.                                     menuItem -l "0.00" -c "floatFieldGrp -e -pre 2 lt_userDims; updateUserDims; optionVar -iv lt_defaultUserDimPrec 2;";
  1085.                                     menuItem -l "0.000" -c "floatFieldGrp -e -pre 3 lt_userDims; updateUserDims; optionVar -iv lt_defaultUserDimPrec 3;";
  1086.                             floatFieldGrp
  1087.                                 -numberOfFields 1
  1088.                                 -label "Scale"
  1089.                                 -cat 1 left 0 -cw 1 90
  1090.                                 -cat 2 left 0 -cw 2 100
  1091.                                 -value1 $scale        
  1092.                                 -cc     "setScale"
  1093.                                 lt_scale;  
  1094.                             floatFieldGrp
  1095.                                 -numberOfFields 1
  1096.                                 -label "Interpolation"
  1097.                                 -cat 1 left 0 -cw 1 90
  1098.                                 -cat 2 left 0 -cw 2 100
  1099.                                 -value1 $interp        
  1100.                             //    -cc     "optionVar -fv lt_defaultScale (`floatFieldGrp -q -v1 lt_interp`);"
  1101.                                 -cc    "string $root[] = `ls -dag -type joint`;
  1102.                                     if(!`objExists ($root[0] + \".interpolation\")`)
  1103.                                         addAttr -ln \"interpolation\" -at \"float\" $root[0];
  1104.                                     setAttr ($root[0] + \".interpolation\") (`floatFieldGrp -q -v1 lt_interp`);"
  1105.                             //    -cc "setInterp"
  1106.                                 lt_interp;  
  1107.                         setParent ..;
  1108.                     setParent ..;
  1109.                     textFieldButtonGrp 
  1110.                         -cw 1 80
  1111.                         -cw 2 220
  1112.                         -label "Tool Path:" 
  1113.                         -buttonLabel "Browse..."
  1114.                         -bc "getDirectory \"lt_toolPath\""
  1115.                         -fi `optionVar -q lt_toolPath`
  1116.                         -cc "optionVar -sv lt_toolPath (`textFieldGrp -q -text lt_toolPath`)"
  1117.                         lt_toolPath;
  1118.                     textFieldButtonGrp 
  1119.                         -cw 1 80
  1120.                         -cw 2 220
  1121.                         -label "Game Path:" 
  1122.                         -buttonLabel "Browse..."
  1123.                         -bc "getDirectory \"lt_gamePath\""
  1124.                         -fi `optionVar -q lt_gamePath`
  1125.                         -cc "optionVar -sv lt_gamePath (`textFieldGrp -q -text lt_gamePath`)"
  1126.                         lt_gamePath;
  1127.                 setParent ..;    
  1128.             setParent ..;
  1129.             rowLayout
  1130.                 -numberOfColumns 2
  1131.                 -rat 1 "top" 2
  1132.                 -rat 2 "top" 2
  1133.                 -columnWidth 1 170;
  1134.                 button  -label "Export" -w 160 -h 20 -c "lta_Export";
  1135.                 button  -label "Close"  -w 160 -h 20 -c "deleteUI ExportLtaUI";
  1136.             setParent ..;
  1137.         setParent ..;
  1138.         columnLayout;
  1139.             frameLayout
  1140.                 -label "Edit Options"
  1141.                 -w 92
  1142.                 -h ($ui_Height-50);            
  1143.                 columnLayout
  1144.                     -rs 2
  1145.                     -cat "left" 5;
  1146.                     button -label "User Dims" -w 79 -h 22 -c "showUserDims"; 
  1147.                     button -label "Sockets" -w 79 -h 22 -c "editSocketWin";//"ltaImport 1"; 
  1148.                     button -label "Weight Sets" -w 79 -h 22 -c "ltaImport 2"; 
  1149.                     button -label "Child Models" -w 79 -h 22 -c "childModelWin"; //"ltaImport 3";
  1150.                     button -label "Piece Info" -w 79 -h 22 -c "editPieceInfoWin";
  1151.                     button -label "CommandString" -w 79 -h 22 -c "editCommandStringWin";
  1152.                     button -label "Node Flags" -w 79 -h 22 -c "editNodeFlagsWin";
  1153.                     button -label "Set up LODs" -w 79 -h 22 -c "setUpLODWin";
  1154.                 setParent ..;
  1155.             setParent ..;
  1156.         setParent ..;
  1157.     setParent ..;            
  1158.     showWindow ExportLtaUI;
  1159.     scriptJob -p ExportLtaUI -e "SceneOpened" "optionVar -sv lt_defaultAnimName (`getSceneName`)";
  1160.     source "ltaImport.mel";
  1161.     setUserDims;
  1162. }
  1163.  
  1164.  
  1165. global proc string[] getSkeleton()
  1166. {
  1167.     string $outSkel[];
  1168.     
  1169.     string $sel[] = `ls -sl`;
  1170.     string $top[] = `ls -dag -type joint`;
  1171.     
  1172.     select -r -hi $top[0];
  1173.     string $skel[] = `ls -sl -type joint`;
  1174.     $outSkel[0] = $skel[(size($skel))-1];
  1175.     for ($i = 1; $i < size($skel); $i++)
  1176.         $outSkel[$i] = $skel[$i-1];
  1177.     
  1178.     select -r $sel;
  1179.     return $outSkel;
  1180. }
  1181.  
  1182. global proc setUpLODWin()
  1183. {
  1184.     print ((`getLODInfo`));
  1185. }
  1186.  
  1187.  
  1188.  
  1189. global proc string[] getLODInfo()
  1190. {
  1191.     string $longShape[], $root[] = `getSkeleton`;
  1192.     string $tmp[],  $shape[], $clusters[], $buffer[], $groupName[], $shapeName[];
  1193.     int $match, $count = 0;
  1194.  
  1195.     for ($node in $root)
  1196.     {
  1197.         $skinCluster = `listConnections -type skinCluster $node`;
  1198.         for($i = 0; $i < size($skinCluster); $i++)
  1199.         {
  1200.             for($j = 0; $j < size($clusters); $j++)
  1201.             {    
  1202.                 if($skinCluster[$i] == $clusters[$j])
  1203.                 {
  1204.                     $match = 1;
  1205.                     break;
  1206.                 }
  1207.             }
  1208.             if(!$match)
  1209.             {
  1210.                 $clusters[$count] = $skinCluster[$i];
  1211.                 $count++;
  1212.             }
  1213.             else
  1214.                 $match = 0;
  1215.         }
  1216.     }
  1217.     int $match = 0;
  1218.     int $numGroups = 0;
  1219.     string $LODGroups[];
  1220.     int $numDistance = 0;
  1221.     string $LODDistance[];
  1222.     $clusters = sort($clusters);
  1223.  
  1224. //print $clusters;
  1225.  
  1226.     for($i = 0; $i < size($clusters); $i++)
  1227.     {
  1228.         $shape = `skinCluster -q -g $clusters[$i]`;
  1229.         $piece = `listRelatives -fullPath -parent $shape[0]`;
  1230.         $longShape = `ls -l $piece[0]`;
  1231.         tokenize($longShape[0], "|", $buffer);
  1232.         
  1233.         $groupName[$i] = $buffer[1];
  1234.         $shapeName[$i] = $buffer[(size($buffer))-1];
  1235. //print ($groupName[$i] + " " + $shapeName[$i] + " " + $clusters[$i] + "\n");
  1236.  
  1237.         tokenize($groupName[$i], "_", $buffer);
  1238.         
  1239.  
  1240.  
  1241.         for($j = 0; $j < size($LODDistance); $j++)
  1242.         {
  1243.             if($buffer[1] == $LODDistance[$j])
  1244.             {
  1245.                 $match = 1;
  1246.                 break;
  1247.             }
  1248.         }
  1249.         if(!$match) 
  1250.         {
  1251.             $LODDistance[$numDistance] = $buffer[1];
  1252.             $numDistance++;
  1253.         }
  1254.         else
  1255.             $match = 0;
  1256.             
  1257.  
  1258.         if($buffer[1] == "0")
  1259.         {
  1260.             $LODGroups[$numGroups] = $shapeName[$i];
  1261.             $numGroups++;            
  1262.         }
  1263.     }
  1264.     for($i = 0; $i < $numDistance; $i++)
  1265.     {
  1266.         $LODGroups[$i] = "";
  1267.         for($j = 0; $j < size($groupName); $j++)
  1268.         {
  1269.             tokenize($groupName[$j], "_", $buffer);
  1270.             if($buffer[1] == $LODDistance[$i])
  1271.             {
  1272.                 $LODGroups[$i] = $LODGroups[$i] + $shapeName[$j] + " ";
  1273.             }
  1274.         }
  1275.     }
  1276.     
  1277.     string $newLODGroups[];
  1278.     for($i = 0; $i < $numDistance; $i++)
  1279.     {
  1280.         for($j = 0; $j < $numGroups; $j++)
  1281.         {
  1282.             tokenize($LODGroups[$i], " ", $buffer);
  1283.             $newLODGroups[$j] = $newLODGroups[$j] + $buffer[$j] + " " + $LODDistance[$i] + " " ;
  1284.         }
  1285.     }
  1286.  
  1287.     return $newLODGroups;
  1288.  
  1289. }
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295. global proc editSocketWin()
  1296. {
  1297.     string $socketData[];
  1298.     if(`window -ex SocketsUI`)
  1299.         deleteUI SocketsUI;
  1300.     string $root[] = `getSkeleton`;
  1301.     
  1302.     if (!`objExists ($root[0] + ".sockets")`)
  1303.         addAttr -ln "sockets" -dt "string" $root[0];
  1304.  
  1305.     showSockets;
  1306.  
  1307.     string $currentSockets = `getAttr ($root[0] + ".sockets")`;
  1308.     tokenize($currentSockets, " ", $socketData);
  1309.  
  1310.     window 
  1311.         -menuBar false
  1312.         -maximizeButton false
  1313.         -w 5 
  1314.         -h 5
  1315.         -rtf 1
  1316.         -title "ScottTech2000: Sockets"
  1317.         SocketsUI;    
  1318.         columnLayout;
  1319.             paneLayout
  1320.                 -w 190
  1321.                 -h 140;
  1322.                 textScrollList 
  1323.                     -w 190
  1324.                     -nr 10
  1325.                     lt_socketList;
  1326.                 for($i = 0; $i< (size($socketData))/8; $i++)
  1327.                     textScrollList -e -append $socketData[$i * 8 + 1] lt_socketList;
  1328.             setParent ..;
  1329.             rowLayout 
  1330.                 -numberOfColumns 3
  1331.                 -rat 1 "top" 2
  1332.                 -rat 2 "top" 2
  1333.                 -rat 3 "top" 2
  1334.                 -cw 1 65
  1335.                 -cw 2 65
  1336.                 -cw 3 65;
  1337.                 button -label "Add" -w 60 -h 25 -c "addSocketWin";
  1338.                 button -label "Remove" -w 60 -h 25 -c "removeSocket";
  1339.                 button -label "Import" -w 60 -h 25 -c "";//"ltaImport 1";
  1340.             setParent ..;
  1341.             rowLayout 
  1342.                 -numberOfColumns 3
  1343.                 -rat 1 "top" 2
  1344.                 -rat 2 "top" 2
  1345.                 -rat 3 "top" 2
  1346.                 -cw 1 65
  1347.                 -cw 2 65
  1348.                 -cw 3 65 ;
  1349.                 button -label "Show All" -w 60 -h 25 -c "showSockets";
  1350.                 button -label "Hide All" -w 60 -h 25 -c "hideSockets";
  1351.                 button -label "Close" -w 60 -h 25 -c "deleteUI SocketsUI";
  1352.             setParent ..;
  1353.         setParent ..;
  1354.  
  1355.     showWindow SocketsUI;
  1356. }
  1357.  
  1358.  
  1359.  
  1360. global proc addSocketWin()
  1361. {
  1362.     string $root[] = `getSkeleton`;
  1363.     if(`window -ex AddSocketUI`)
  1364.         deleteUI AddSocketUI;
  1365.  
  1366.     showSockets;
  1367.  
  1368.     string $addJoint[] = `ls -sl`;
  1369.     int $valid = 0;
  1370.     for($i = 0; $i < size($root); $i++)
  1371.         if($root[$i] == $addJoint[0]) $valid = 1;
  1372.     if(!$valid) error("Select an exportable joint");
  1373.  
  1374.     window 
  1375.         -menuBar false
  1376.         -maximizeButton false
  1377.         -w 5 
  1378.         -h 5
  1379.         -rtf 1
  1380.         -title "Add Socket"
  1381.         AddSocketUI;
  1382.         columnLayout;
  1383.             columnLayout;    
  1384.                 textFieldGrp 
  1385.                     -cw 1 60 
  1386.                     -cw 2 150 
  1387.                     -label "Socket"
  1388.                     -tx "NewSocket"
  1389.                     -cc     ""
  1390.                     lt_SocketName;
  1391.                 textFieldGrp
  1392.                     -cw 1 60
  1393.                     -cw 2 150
  1394.                     -label "Node"
  1395.                     -tx $addJoint[0]
  1396.                     -cc     ""
  1397.                     lt_NodeName;
  1398.             setParent ..;
  1399.             rowLayout
  1400.                 -numberOfColumns 2
  1401.                 -rat 1 "top" 2
  1402.                 -rat 2 "top" 2
  1403.                 -columnWidth 1 100;
  1404.                 button  -label "Add" -w 90 -h 25 -c "addSocket;";
  1405.                 button  -label "Cancel"  -w 90 -h 25 -c "deleteUI AddSocketUI";
  1406.             setParent ..;
  1407.         setParent ..;
  1408.     showWindow AddSocketUI;
  1409.     
  1410. }
  1411.  
  1412.  
  1413. global proc addSocket()
  1414. {
  1415.     
  1416.     string $socketData[];
  1417.     string $root[] = `getSkeleton`;
  1418.     if (!`objExists ($root[0] + ".sockets")`)
  1419.         addAttr -ln "sockets" -dt "string" $root[0];
  1420.  
  1421.     
  1422.     
  1423.     
  1424.     string $currentSockets = `getAttr ($root[0] + ".sockets")`;
  1425.     tokenize($currentSockets, " ", $socketData);
  1426.  
  1427.  
  1428.     
  1429.     
  1430.     string $addJoint = `textFieldGrp -q -text lt_NodeName`;
  1431.     int $valid = 0;
  1432.     for($i = 0; $i < size($root); $i++)
  1433.         if($root[$i] == $addJoint) 
  1434.             $valid = 1;
  1435.     if(!$valid) 
  1436.         error("Select an exportable joint");
  1437.  
  1438.  
  1439.     
  1440.     
  1441.     string $addSocket = `textFieldGrp -q -text lt_SocketName`;
  1442.     $valid = 1;
  1443.     for($i = 0; $i < (size($socketData))/8; $i++)
  1444.         if($addSocket == $socketData[$i * 8 + 1]) 
  1445.             $valid = 0;
  1446.     if(!$valid) 
  1447.         error("Enter unique socket name");
  1448.     if(`objExists $addSocket`) 
  1449.         error("Socket name conflicts with existing scene object");
  1450.     
  1451.  
  1452.     
  1453.     spaceLocator -n $addSocket;
  1454.     parent $addSocket $addJoint;
  1455.  
  1456.     addAttr -ln "Socket" -at bool $addSocket;
  1457.     setAttr ($addSocket + ".Socket") 1;
  1458.     setAttr ($addSocket + ".translate") 0 0 0;
  1459.     setAttr ($addSocket + ".rotate") 0 0 0;
  1460. //    setAttr ($addSocket + ".scale") 10 10 10;
  1461.  
  1462.  
  1463.  
  1464.     $currentSockets = $currentSockets + " " + $addJoint + " " + $addSocket + " 0 0 0 0 0 0";
  1465.     setAttr ($root[0] + ".sockets") -type "string" $currentSockets;
  1466.     textScrollList -e -append $addSocket lt_socketList;
  1467.  
  1468.     select -r $addJoint;
  1469.  
  1470.     deleteUI AddSocketUI;
  1471. }
  1472.  
  1473. global proc removeSocket()
  1474. {    
  1475.     string $socketData[];
  1476.     string $root[] = `getSkeleton`;
  1477.         
  1478.     string $currentSockets = `getAttr ($root[0] + ".sockets")`;
  1479.     tokenize($currentSockets, " ", $socketData);
  1480.     
  1481.     string $deleteSocket[] = `textScrollList -q -si lt_socketList`;
  1482.     int $index[] = `textScrollList -q -sii lt_socketList`;
  1483.  
  1484.     textScrollList -e -ri $deleteSocket[0] lt_socketList;
  1485.     delete $deleteSocket[0];
  1486.  
  1487.     string $newSockets = "";
  1488.     for($i = 0; $i < (size($socketData))/8; $i++)
  1489.     {
  1490.         if($i != ($index[0] - 1))
  1491.         {
  1492.             for($j = 0; $j < 8; $j++)
  1493.                 $newSockets = $newSockets + $socketData[8 * $i + $j] + " ";
  1494.         }
  1495.     }
  1496.  
  1497.     setAttr ($root[0] + ".sockets") -type "string" $newSockets;
  1498. }
  1499.  
  1500. global proc showSockets()
  1501. {
  1502.     $sel = `ls -sl`;
  1503.     string $socketData[];
  1504.     string $root[] = `getSkeleton`;
  1505.     string $currentSockets = `getAttr ($root[0] + ".sockets")`;
  1506.     tokenize($currentSockets, " ", $socketData);
  1507.  
  1508.     for($i = 0; $i < (size($socketData))/8; $i++)
  1509.     {
  1510.         $socketName = $socketData[$i * 8 + 1];
  1511.         if(!`objExists $socketName`)
  1512.         {
  1513.             spaceLocator -n $socketName;
  1514.             parent $socketName $socketData[$i * 8];
  1515.  
  1516.             addAttr -ln "Socket" -at bool $socketData[$i * 8 + 1];
  1517.             setAttr ($socketName + ".Socket") 1;
  1518.             setAttr ($socketName + ".tx") (float($socketData[$i * 8 + 2]));
  1519.             setAttr ($socketName + ".ty") (float($socketData[$i * 8 + 3]));
  1520.             setAttr ($socketName + ".tz") (float($socketData[$i * 8 + 4]));
  1521.             setAttr ($socketName + ".rx") (float($socketData[$i * 8 + 5]));
  1522.             setAttr ($socketName + ".ry") (float($socketData[$i * 8 + 6]));
  1523.             setAttr ($socketName + ".rz") (float($socketData[$i * 8 + 7]));
  1524.     //        setAttr ($socketName + ".scale") 10 10 10;
  1525.         }
  1526.     }
  1527.     select -r $sel;
  1528. }
  1529.  
  1530. global proc hideSockets()
  1531. {    
  1532.     $sel = `ls -sl`;
  1533.     string $socketData[];
  1534.     string $root[] = `getSkeleton`;
  1535.     string $currentSockets = `getAttr ($root[0] + ".sockets")`;
  1536.     tokenize($currentSockets, " ", $socketData);
  1537.  
  1538.     string $newSockets = "";
  1539.     for($i = 0; $i < (size($socketData))/8; $i++)
  1540.     {
  1541.         $socketName = $socketData[$i * 8 + 1];
  1542.         $newSockets = $newSockets + $socketData[$i * 8] + " " + $socketName + " " ;
  1543.  
  1544.         $tx = `getAttr ($socketName + ".tx")`;
  1545.         $newSockets = $newSockets + $tx + " " ;
  1546.         $ty = `getAttr ($socketName + ".ty")`;
  1547.         $newSockets = $newSockets + $ty + " " ;
  1548.         $tz = `getAttr ($socketName + ".tz")`;
  1549.         $newSockets = $newSockets + $tz + " " ;
  1550.         $rx = `getAttr ($socketName + ".rx")`;
  1551.         $newSockets = $newSockets + $rx + " " ;
  1552.         $ry = `getAttr ($socketName + ".ry")`;
  1553.         $newSockets = $newSockets + $ry + " " ;
  1554.         $rz = `getAttr ($socketName + ".rz")`;
  1555.         $newSockets = $newSockets + $rz + " " ;
  1556.         delete $socketName;
  1557.     }
  1558.     setAttr ($root[0] + ".sockets") -type "string" $newSockets;
  1559.     select -r $sel;
  1560. }
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569. global proc childModelWin()
  1570. {
  1571.     string $buffer[];
  1572.     if(`window -ex ChildModelUI`)
  1573.         deleteUI ChildModelUI;
  1574.     string $root[] = `getSkeleton`;
  1575.  
  1576.     if (!`objExists ($root[0] + ".childModels")`)
  1577.         addAttr -ln "childModels" -dt "string" $root[0];
  1578.  
  1579.     string $childModel = `getAttr ($root[0] + ".childModels")`;
  1580.     tokenize($childModel, " ", $buffer);
  1581.  
  1582.     window 
  1583.         -menuBar false
  1584.         -maximizeButton false
  1585.         -w 5 
  1586.         -h 5
  1587.         -rtf 1
  1588.         -title "ScottTech2000: Child Models"
  1589.         ChildModelUI;    
  1590.         columnLayout;
  1591.             paneLayout
  1592.                 -w 190
  1593.                 -h 140;
  1594.                 textScrollList 
  1595.                     -w 190
  1596.                     -nr 10
  1597.                     lt_childModelList;
  1598.                 for($i = 0; $i< size($buffer); $i++)
  1599.                     textScrollList -e -append $buffer[$i] lt_childModelList;
  1600.             setParent ..;
  1601.             rowLayout 
  1602.                 -numberOfColumns 3
  1603.                 -rat 1 "top" 2
  1604.                 -rat 2 "top" 2
  1605.                 -rat 3 "top" 2
  1606.                 -cw 1 65
  1607.                 -cw 2 65 
  1608.                 -cw 3 65;
  1609.                 button -label "Add" -w 60 -h 25 -c "addChildModel";
  1610.                 button -label "Remove" -w 60 -h 25 -c "removeChildModel";
  1611.                 button -label "Close" -w 60 -h 25 -c "deleteUI ChildModelUI";
  1612.             setParent ..;
  1613.         setParent ..;
  1614.  
  1615.     showWindow ChildModelUI;
  1616. }
  1617.  
  1618. global proc addChildModel()
  1619. {
  1620.  
  1621.     string $buffer[],$root[] = `getSkeleton`;
  1622.     string $filepath = dirname (`textFieldButtonGrp -q -fi lt_filename`);
  1623.  
  1624.     string $filename = `fileDialog -directoryMask "~/*.lt*"`;
  1625.     if ( $filename == "" )
  1626.         error "No file selected";
  1627.  
  1628.     if(!`gmatch $filename ("*" + $filepath + "*")`)
  1629.         error("Please don't use child models outside of model directory");
  1630.     
  1631.     int $pathLen = size($filepath);
  1632.     int $filenameLen = size($filename);
  1633.  
  1634.     $newfilename = `substring $filename ($pathLen+2) ($filenameLen-4)`;
  1635.     $newfilename = `substituteAllString $newfilename "/" "\\"`;
  1636.  
  1637.     if (!`objExists ($root[0] + ".childModels")`)
  1638.         addAttr -ln "childModels" -dt "string" $root[0];
  1639.     string $childModel = `getAttr ($root[0] + ".childModels")`;
  1640.     $childModel = $childModel + $newfilename + " ";
  1641.     
  1642.  
  1643.     setAttr ($root[0] + ".childModels") -type "string" $childModel;
  1644.     textScrollList -e -append $newfilename lt_childModelList;
  1645.  
  1646. }
  1647.  
  1648. global proc removeChildModel()
  1649. {
  1650.     string $buffer[],$root[] = `getSkeleton`;
  1651.     string $childModel = `getAttr ($root[0] + ".childModels")`;
  1652.     tokenize($childModel, " ", $buffer);
  1653.     
  1654.     $childModel = "";
  1655.     $removeIndex = `textScrollList -q -sii lt_childModelList`;
  1656.     for($i = 0; $i<size($buffer); $i++)
  1657.         if($i != ($removeIndex[0]-1))
  1658.             $childModel = $childModel + $buffer[$i] + " ";
  1659.  
  1660.     setAttr ($root[0] + ".childModels") -type "string" $childModel;
  1661.     textScrollList -e -rii $removeIndex[0] lt_childModelList;
  1662. }
  1663.  
  1664. global proc editNodeFlagsWin()
  1665. {
  1666.     string $nodeFlags ="", $buffer[];
  1667.     if(`window -ex NodeFlagsUI`)
  1668.         deleteUI NodeFlagsUI;
  1669.  
  1670.     string $root[] = `getSkeleton`;
  1671.  
  1672.     if(!`objExists ($root[0] + ".nodeFlags")`)
  1673.     {
  1674.         addAttr -ln "nodeFlags" -dt "string" $root[0];
  1675.         for ($i = 0; $i < size($root); $i++)
  1676.             $nodeFlags = $nodeFlags + "0";
  1677.         setAttr ($root[0] + ".nodeFlags") -type "string" $nodeFlags;
  1678.     }
  1679.     else
  1680.         $nodeFlags = `getAttr ($root[0] + ".nodeFlags")`;
  1681.     window 
  1682.         -menuBar false
  1683.         -maximizeButton false
  1684.         -w 5 
  1685.         -h 5
  1686.         -rtf 1
  1687.         -title "ScottTech2000: Node Flags"
  1688.         NodeFlagsUI;    
  1689.             scrollLayout
  1690.                 -h 300
  1691.                 -w 270;    
  1692.                 columnLayout;
  1693.                     checkBox 
  1694.                         -label $root[0] 
  1695.                         -v 0
  1696.                         ("lt_nodeFlag0");
  1697.                     for($i = 1; $i < size($root); $i++)
  1698.                     { 
  1699.                         checkBox 
  1700.                             -label $root[$i] 
  1701.                             -v (int(`substring $nodeFlags ($i+1) ($i+1)`))
  1702.                             -cc "setNodeFlags"
  1703.                             ("lt_nodeFlag" + $i);
  1704.                     }
  1705.                     setParent ..;
  1706.                 setParent ..;
  1707.             setParent ..;
  1708.     showWindow NodeFlagsUI; 
  1709.  
  1710. }
  1711.  
  1712.  
  1713. global proc setNodeFlags()
  1714. {
  1715.     string $root[] = `getSkeleton`;
  1716.     string $nodeFlags = "1";
  1717.     for($i =1; $i < size($root); $i++)
  1718.     {    
  1719.         $flag = 2 * (`checkBox -q -v ("lt_nodeFlag" + $i)`);
  1720.         $nodeFlags = $nodeFlags + $flag;
  1721.     }
  1722.  
  1723.     setAttr ($root[0] + ".nodeFlags") -type "string" $nodeFlags;
  1724. }
  1725.  
  1726.  
  1727. global proc editCommandStringWin()
  1728. {
  1729.     string $cmdString, $buffer[];
  1730.     $root = `ls -dag -type joint`;
  1731.     if(`window -ex CmdStringUI`)
  1732.         deleteUI CmdStringUI;
  1733.  
  1734.     if(!`objExists ($root[0] + ".cmdString")`)
  1735.     {
  1736.         addAttr -ln "cmdString" -dt "string" $root[0];
  1737.         $cmdString = "";
  1738.     }
  1739.     else
  1740.         $cmdString = `getAttr ($root[0] + ".cmdString")`;
  1741.  
  1742.     tokenize($cmdString, ";", $buffer);
  1743.     $cmdString = "";
  1744.     for($cmd in $buffer)
  1745.         $cmdString = $cmdString + $cmd + "\n"; 
  1746.     window 
  1747.         -menuBar false
  1748.         -maximizeButton false
  1749.         -w 5 
  1750.         -h 5
  1751.         -rtf 1
  1752.         -title "ScottTech2000: Command String"
  1753.         CmdStringUI;    
  1754.         columnLayout;
  1755.             text -label "Edit Command String:";
  1756.             paneLayout 
  1757.                 -h 120
  1758.                 -w 400
  1759.                 -cn "single";
  1760.                 scrollField
  1761.                     -wordWrap true
  1762.                     -text     $cmdString
  1763.                     -c     "setCommandString;"
  1764.                     lt_cmdString;
  1765.                 setParent ..;
  1766.             setParent ..;
  1767.             rowLayout
  1768.                 -numberOfColumns 3
  1769.                 -rat 1 "top" 2
  1770.                 -rat 2 "top" 2
  1771.                 -rat 3 "top" 2
  1772.                 -columnWidth 1 110
  1773.                 -columnWidth 2 110;
  1774.                 button  -label "Enter" -w 100 -h 30 -c "setCommandString;";
  1775.                 button  -label "Enter/Close"  -w 100 -h 30 -c "setCommandString; deleteUI CmdStringUI";
  1776.                 button  -label "Close"  -w 100 -h 30 -c "deleteUI CmdStringUI";
  1777.  
  1778.     showWindow CmdStringUI;        
  1779. }
  1780.  
  1781.  
  1782. global proc setCommandString()
  1783. {
  1784.     string $buffer[], $root[] = `ls -dag -type joint`;
  1785.     string $cmdString = `scrollField -q -text lt_cmdString`;
  1786.  
  1787.     tokenize($cmdString, "\n\r\t", $buffer); 
  1788.     $cmdString = "";
  1789.     for($cmd in $buffer)
  1790.         $cmdString = $cmdString + $cmd + ";"; 
  1791.     if(size($cmdString) == 1)
  1792.     {
  1793.         //$cmdString = "";
  1794.         deleteAttr ($root[0] + ".cmdString");
  1795.         return;
  1796.     }
  1797.     if(!`objExists ($root[0] + ".cmdString")`)
  1798.         addAttr -ln "cmdString" -dt "string" $root[0];
  1799.     setAttr ($root[0] + ".cmdString") -type "string" $cmdString;
  1800.  
  1801. }
  1802.  
  1803.  
  1804. global proc editPieceInfoWin()
  1805. {    
  1806.     int $numTex;
  1807.     string $rsData[], $sel[] = `ls -sl -l`;
  1808.  
  1809.     if(size($sel) == 0) return;
  1810.     if(`nodeType $sel[0]` != "transform") return;
  1811.  
  1812.     if(`window -ex PieceInfoUI`)
  1813.         deleteUI PieceInfoUI;
  1814.  
  1815.     for($item in $sel)
  1816.     {
  1817.         if(`objExists ($item + ".renderStyles")`)
  1818.             deleteAttr ($item + ".renderStyles");
  1819.         if(!`objExists ($item + ".RenderStyle")`)
  1820.         {     
  1821.             addAttr -ln "RenderStyle" -at long $item;
  1822.             setAttr ($item + ".RenderStyle")  0;
  1823.         }
  1824.  
  1825.         string $texAttr[] = `listAttr -st Texture0 -st Texture1 -st Texture2 -st Texture3 $sel[0]`;
  1826.         $numTex = size($texAttr);
  1827.  
  1828.         if((size($texAttr)!= 0) && $texAttr[0] != "Texture0")
  1829.         {
  1830.             for($i = 0; $i < size($texAttr); $i++)
  1831.                 deleteAttr ($item + "." + $texAttr[$i]);
  1832.         }
  1833.         if(!`objExists ($item + ".Texture0")`)
  1834.         {     
  1835.             addAttr -ln "Texture0" -at short $item;
  1836.             setAttr ($item + ".Texture0")  0;
  1837.         }
  1838.  
  1839.     }
  1840.  
  1841.     int $rsAttr = `getAttr ($sel[0] + ".RenderStyle")`;
  1842.  
  1843.     window 
  1844.         -menuBar false
  1845.         -maximizeButton false
  1846.         -sizeable 0
  1847.         -w 5 
  1848.         -h 5
  1849.         -rtf 1
  1850.         -title "ScottTech2000: Piece Info"
  1851.         PieceInfoUI;
  1852.     columnLayout;
  1853.         frameLayout
  1854.             -label "Texture Properties"
  1855.             -w 200
  1856.             -h 120;
  1857.             columnLayout;
  1858.                 optionMenu 
  1859.                     -label "Number of Textures"
  1860.                     -cc "updateTexIdState (int(`optionMenu -q -v st_numTex`))"
  1861.                     st_numTex;
  1862.  
  1863.                     menuItem -label "1";
  1864.                     menuItem -label "2";
  1865.                     menuItem -label "3";
  1866.                     menuItem -label "4";
  1867.                 text -label "\nTexture Indices:";
  1868.                 rowLayout 
  1869.                     -numberOfColumns 2
  1870.                     -cw 1 100
  1871.                     -cw 2 100;
  1872.                     columnLayout;
  1873.                         intFieldGrp 
  1874.                             -numberOfFields 1
  1875.                             -label "0:"
  1876.                             -cw 1 30 -cw 2 50
  1877.                             -ct2 left left 
  1878.                             -co2 5 5
  1879.                             -value1 (`getTexID $sel[0] 1`)
  1880.                             st_texID1;
  1881.                         intFieldGrp 
  1882.                             -numberOfFields 1
  1883.                             -label "2:"
  1884.                             -en1 0
  1885.                             -ct2 left left 
  1886.                             -co2 5 5
  1887.                             -cw 1 30 -cw 2 50
  1888.                             -value1 (`getTexID $sel[0] 3`)
  1889.                             st_texID3; 
  1890.                     setParent ..;
  1891.                     columnLayout;
  1892.                         intFieldGrp                         
  1893.                             -numberOfFields 1
  1894.                             -label "1:"
  1895.                             -en1 0
  1896.                             -cw 1 30 -cw 2 50
  1897.                             -ct2 left left 
  1898.                             -co2 5 5
  1899.                             -value1 (`getTexID $sel[0] 2`)
  1900.                             st_texID2;
  1901.                         intFieldGrp 
  1902.                             -numberOfFields 1
  1903.                             -label "3:"
  1904.                             -en1 0
  1905.                             -cw 1 30 -cw 2 50
  1906.                             -ct2 left left 
  1907.                             -co2 5 5
  1908.                             -value1 (`getTexID $sel[0] 4`)
  1909.                             st_texID4; 
  1910.                     setParent ..;
  1911.                 setParent ..;     
  1912.  
  1913.             setParent ..;
  1914.         setParent ..;
  1915.         frameLayout
  1916.             -label "RenderStyle Properties"
  1917.             -w 200
  1918.             -h 40;
  1919.             intFieldGrp 
  1920.                 -numberOfFields 1
  1921.                 -label "     RenderStyle Index:"
  1922.                 -cw 1 130 -cw 2 50
  1923.                 -ct2 left left 
  1924.                 -co2 5 5
  1925.                 -value1 $rsAttr
  1926.                 st_rsID;    
  1927.         setParent ..;
  1928.         frameLayout
  1929.             -label "ModelEdit Texture"
  1930.             -w 200
  1931.             -h 70;
  1932.             columnLayout;
  1933.                 textField
  1934.                     -w 190
  1935.                     -text (`getDTXInfo`)
  1936.                     -cc "setDTXInfo"
  1937.                     st_textureInfo;    
  1938.                 button
  1939.                     -w 190
  1940.                     -l "Browse...(BROKEN)";
  1941.             setParent ..;
  1942.         setParent ..;
  1943.         rowLayout
  1944.             -numberOfColumns 2
  1945.             -rat 1 "top" 2
  1946.             -rat 2 "top" 2
  1947.             -columnWidth 1 100;
  1948.             button  -label "Save" -w 95 -h 20 -c "updateRenderStyles";
  1949.             button  -label "Close" -w 95 -h 20 -c "deleteUI PieceInfoUI";
  1950.         setParent ..;
  1951.     setParent ..;    
  1952.     showWindow PieceInfoUI;
  1953.  
  1954.     updateTexIdState $numTex;
  1955.     optionMenu -e -sl $numTex st_numTex;
  1956. }
  1957.  
  1958.  
  1959. global proc string getDTXInfo()
  1960. {
  1961.     string $buffer[];
  1962.     string $root[] = `getSkeleton`;
  1963.     if(`objExists ($root[0] + ".DTXInfo")`)
  1964.     {
  1965.         string $DTXInfo = `getAttr ($root[0] + ".DTXInfo")`;
  1966.         int $texID = `intFieldGrp -q -value1 st_texID1`;
  1967.         tokenize($DTXInfo, " ", $buffer);
  1968.         if($buffer[$texID] != "XXXX")
  1969.             return $buffer[$texID];
  1970.     }
  1971.  
  1972.     return "";
  1973. }
  1974.  
  1975.  
  1976. global proc setDTXInfo()
  1977. {
  1978.     string $buffer[], $root[] = `getSkeleton`;
  1979.     string $DTXInfo = "", $newDTXInfo = `textField -q -text st_textureInfo`;
  1980.     int $texID = `intFieldGrp -q -value1 st_texID1`;
  1981.  
  1982.     if(`objExists ($root[0] + ".DTXInfo")`)
  1983.     {
  1984.         $DTXInfo = `getAttr ($root[0] + ".DTXInfo")`;
  1985.         tokenize ($DTXInfo, " ", $buffer);
  1986.         int $numTextures =  max( (size($buffer)), ($texID + 1 ) );
  1987.         $buffer[$texID] = $newDTXInfo;
  1988.         $DTXInfo = "";
  1989.  
  1990.         for($i = 0; $i < $numTextures; $i++)
  1991.         {
  1992.             if($buffer[$i] == "" || $buffer[$i] == "XXXX")
  1993.                 $DTXInfo = $DTXInfo + "XXXX ";
  1994.             else 
  1995.                 $DTXInfo = $DTXInfo + $buffer[$i] + " ";
  1996.         }
  1997.     }
  1998.     else 
  1999.     {
  2000.         addAttr -ln "DTXInfo" -dt "string" $root[0];
  2001.         if($texID > 0)
  2002.         {
  2003.             for($i = 0; $i < $texID; $i++)
  2004.             {
  2005.                 $DTXInfo = $DTXInfo + "XXXX ";
  2006.             }
  2007.             $DTXInfo = $DTXInfo + $newDTXInfo;
  2008.         }
  2009.         else
  2010.             $DTXInfo = $newDTXInfo;
  2011.     }
  2012.  
  2013.     setAttr -type "string" ($root[0] + ".DTXInfo") $DTXInfo;
  2014.  
  2015. }
  2016.  
  2017.  
  2018. global proc int getTexID(string $sel, int $number)
  2019. {
  2020.     int $texID;
  2021.     $number--;
  2022.     if(`objExists ($sel + ".Texture" + $number)`)
  2023.         $texID = `getAttr ($sel + ".Texture" + $number)`;
  2024.     else 
  2025.         $texID = 0;
  2026.     return $texID;
  2027. }
  2028.  
  2029.  
  2030. global proc updateTexIdState(int $num)
  2031. {    
  2032.     switch($num)
  2033.     {
  2034.         case 1: 
  2035.             intFieldGrp -e -en 0 st_texID2;
  2036.             intFieldGrp -e -en 0 st_texID3;
  2037.             intFieldGrp -e -en 0 st_texID4;
  2038.             break;
  2039.         case 2: 
  2040.             intFieldGrp -e -en 1 st_texID2;
  2041.             intFieldGrp -e -en 0 st_texID3;
  2042.             intFieldGrp -e -en 0 st_texID4;
  2043.             break;
  2044.         case 3:
  2045.             intFieldGrp -e -en 1 st_texID2;
  2046.             intFieldGrp -e -en 1 st_texID3;
  2047.             intFieldGrp -e -en 0 st_texID4;
  2048.             break;
  2049.         case 4:    
  2050.             intFieldGrp -e -en 1 st_texID2;
  2051.             intFieldGrp -e -en 1 st_texID3;
  2052.             intFieldGrp -e -en 1 st_texID4;
  2053.             break;
  2054.     }            
  2055.     optionMenu -e -sl (int($num)) st_numTex;
  2056. }
  2057.  
  2058. global proc updateRenderStyles()
  2059. {
  2060.     int $newRenStAtt = `intFieldGrp -q -v1 st_rsID`;
  2061.     
  2062.     $sel = `ls -sl`;
  2063.     for($item in $sel)
  2064.     {
  2065.         setAttr ($item + ".RenderStyle")  (`intFieldGrp -q -v1 st_rsID`);
  2066.         setAttr ($item + ".Texture0") (`intFieldGrp -q -v1 st_texID1`);
  2067.         if(`intFieldGrp -q -en1 st_texID2`)
  2068.         {
  2069.             if(!`objExists ($item + ".Texture1")`)
  2070.                 addAttr -ln "Texture1" -at short $item;
  2071.             setAttr ($item + ".Texture1") (`intFieldGrp -q -v1 st_texID2`);
  2072.         }
  2073.         else
  2074.             if(`objExists ($item + ".Texture1")`)
  2075.                 deleteAttr ($item + ".Texture1");
  2076.         if(`intFieldGrp -q -en1 st_texID3`)
  2077.         {
  2078.             if(!`objExists ($item + ".Texture2")`)
  2079.                 addAttr -ln "Texture2" -at short $item;
  2080.             setAttr ($item + ".Texture2") (`intFieldGrp -q -v1 st_texID3`);
  2081.         }
  2082.         else
  2083.             if(`objExists ($item + ".Texture2")`)
  2084.                 deleteAttr ($item + ".Texture2");
  2085.         if(`intFieldGrp -q -en1 st_texID4`)
  2086.         {
  2087.             if(!`objExists ($item + ".Texture3")`)
  2088.                 addAttr -ln "Texture3" -at short $item;
  2089.             setAttr ($item + ".Texture3") (`intFieldGrp -q -v1 st_texID4`);
  2090.         }
  2091.         else
  2092.             if(`objExists ($item + ".Texture3")`)
  2093.                 deleteAttr ($item + ".Texture3");
  2094.     }
  2095.  
  2096.     deleteUI PieceInfoUI;
  2097. }
  2098.  
  2099.  
  2100. global proc fixShapePieceInfo()
  2101. {
  2102.     string $root[] = `getSkeleton`;
  2103.     string $tmp[], $piece[], $shape[], $clusters[], $buffer[];
  2104.     int $match, $count = 0;
  2105.  
  2106.     for ($node in $root)
  2107.     {
  2108.         $skinCluster = `listConnections -type skinCluster $node`;
  2109.         for($i = 0; $i < size($skinCluster); $i++)
  2110.         {
  2111.             for($j = 0; $j < size($clusters); $j++)
  2112.             {    
  2113.                 if($skinCluster[$i] == $clusters[$j])
  2114.                 {
  2115.                     $match = 1;
  2116.                     break;
  2117.                 }
  2118.             }
  2119.             if(!$match)
  2120.             {
  2121.                 $clusters[$count] = $skinCluster[$i];
  2122.                 $count++;
  2123.             }
  2124.             else
  2125.                 $match = 0;
  2126.         }
  2127.     }
  2128.     for($i = 0; $i < size($clusters); $i++)
  2129.     {
  2130.         $shape = `skinCluster -q -g $clusters[$i]`;
  2131.         $piece = `listRelatives -fullPath -parent $shape[0]`;
  2132.  
  2133.         if(`objExists ($piece[0] + ".renderStyles")`)
  2134.         {
  2135.             string $rStyles = `getAttr ($piece[0] + ".renderStyles")`;
  2136.             deleteAttr ($piece[0] + ".renderStyles");
  2137.  
  2138.             tokenize($rStyles, " ", $buffer);
  2139.  
  2140.             addAttr -ln "RenderStyle" -at short $piece[0];
  2141.             setAttr ($piece[0] + ".RenderStyle") (int($buffer[0]));
  2142.  
  2143.             for($j = 0; $j < (size($buffer) - 2); $j++)
  2144.             {
  2145.                 addAttr -ln ("Texture" + $j) -at short $piece[0];
  2146.                 setAttr ($piece[0] + ".Texture" + $j)  (int($buffer[$j + 2])) ;
  2147.                 if ($j == 3) break; 
  2148.             }
  2149.  
  2150.         }
  2151.     }
  2152. }
  2153.  
  2154.  
  2155.  
  2156. global proc string getDefaultWeightSets()
  2157. {
  2158.     string $skel[] = `getSkeleton`;
  2159.     string $setNames[] = {"Null", "Upper", "Lower", "blink", "twitch", "Morph0", "Morph100"};
  2160.  
  2161.     string    $weightSets =  "\t\t\t(anim-weightsets\n\t\t\t\t(\n";
  2162.     
  2163.     for($name in $setNames)
  2164.     {
  2165.         $weightSets = $weightSets +    "\t\t\t\t\t(anim-weightset\n\t\t\t\t\t\t(name \"" + $name + "\" )\n\t\t\t\t\t\t(weights\n\t\t\t\t\t\t\t(";
  2166.         
  2167.         for($joint in $skel)
  2168.         {
  2169.             if($name == "twitch")
  2170.                 $weightSets = $weightSets + "2.000000 ";
  2171.             else if($name == "blink" && $joint == "Face_Eyelid")
  2172.                 $weightSets = $weightSets + "2.000000 ";
  2173.             else
  2174.                 $weightSets = $weightSets + "0.000000 ";
  2175.         }
  2176.  
  2177.         $weightSets = $weightSets +    ")\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n";
  2178.     }
  2179.     $weightSets = $weightSets +    "\t\t\t\t)\n\t\t\t)\n";
  2180.     
  2181.     return $weightSets;
  2182. }
  2183.  
  2184.  
  2185. global proc ltcConvert(string $filename, string $type)
  2186. {
  2187.  
  2188.     string $buffer[];
  2189.     string $path = `optionVar -q lt_toolPath`;
  2190.  
  2191.     tokenize($path, "\\/", $buffer);
  2192.     $ltcPath = $buffer[0];
  2193.     for($i = 1;$i < size($buffer); $i++)
  2194.         $ltcPath = $ltcPath + "\\\\" + $buffer[$i];
  2195.     $ltcPath = $ltcPath + "\\\\LTC";
  2196.  
  2197.     tokenize($filename, "/", $buffer);
  2198.     $newFilename = $buffer[0];
  2199.     for($i = 1;$i < size($buffer); $i++)
  2200.         $newFilename = $newFilename + "\\\\" + $buffer[$i];
  2201.     
  2202.     $cmd = "system(\"" + $ltcPath + " \\\"" + $newFilename + "\\\"\")";
  2203.     eval($cmd); 
  2204.  
  2205.     if($type == "lta")
  2206.         deleteFile $filename;
  2207.  
  2208. }
  2209.  
  2210.  
  2211.