//Xolotl Studio
//Created by Ymmanuel Flores
//Copyright 2018 Crowdorchestra SAPI de CV. All rights reserved.
//HHConnect v 1.0.0.4

source "hhconnect/arnoldUDIMS.mel";
source "hhconnect/redshiftUDIMS.mel";
source "hhconnect/rendermanUDIMS.mel";
source "hhconnect/vrayUDIMS.mel";




global proc string hhconnect_sp_link_udims(string $out_path, string $mats, string $ext, string $rndr, string $mesh, int $packed, int $normal) {

    $materials = stringToStringArray($mats, "|");

    if($rndr == "ARNOLD"){
      if( `objExists ("AR_"+$mesh)` != 0 ) {
          if($packed == 1){
              updateARMaterialPkdUdims($out_path,$ext,$mesh);
          }else{
              updateARMaterialUdims($out_path,$ext,$mesh);
          }
      } else {
          if($packed == 1){
              addARMaterialPkdUdims($out_path,$ext,$mesh,$mats,$normal);
          }else{
              addARMaterialUdims($out_path,$ext,$mesh,$mats,$normal);
          }
      }
    }else if($rndr == "REDSHIFT"){
      if( `objExists ("RS_"+$mesh)` != 0 ) {
          if($packed == 1){
              updateRSMaterialPkdUdims($out_path,$ext,$mesh);
          }else{
              updateRSMaterialUdims($out_path,$ext,$mesh);
          }
      } else {
          if($packed == 1){
              addRSMaterialPkdUdims($out_path,$ext,$mesh,$mats,$normal);
          }else{
              addRSMaterialUdims($out_path,$ext,$mesh,$mats,$normal);
          }
      }
    }else if($rndr == "RENDERMAN"){
      if( `objExists ("RS_"+$mesh)` != 0 ) {
          if($packed == 1){
              updateRMMaterialPkdUdims($out_path,$ext,$mesh);
          }else{
              updateRMMaterialUdims($out_path,$ext,$mesh);
          }
      } else {
          if($packed == 1){
              addRMMaterialPkdUdims($out_path,$ext,$mesh,$mats,$normal);
          }else{
              addRMMaterialUdims($out_path,$ext,$mesh,$mats,$normal);
          }
      }
    }else if($rndr == "VRAY"){
      if( `objExists ("VR_"+$mesh)` != 0 ) {
          if($packed == 1){
              updateVRMaterialPkdUdims($out_path,$ext,$mesh);
          }else{
              updateVRMaterialUdims($out_path,$ext,$mesh);
          }
      } else {
          if($packed == 1){
              addVRMaterialPkdUdims($out_path,$ext,$mesh,$mats,$normal);
          }else{
              addVRMaterialUdims($out_path,$ext,$mesh,$mats,$normal);
          }
      }
    }

    return "SUCCESS";
}
