// source hdriSunConnector.mel; hdriSunConnector // // Usage: // It will probably break if the default V-Ray Environment Placement node (VRayPlaceEnvTex1) is changed. // Only tested on Maya 2012 Windows // Instructions: // Run the script again to change/replace the HDRI. // If you can't see the sun straight away in align mode, just move around with the camera source vrayCreateGlobalsTab.mel; global proc hidePolyToggle(){ string $visPanel[]=`getPanel -vis`; int $mode; if (size($visPanel)>0) { for ($panel in $visPanel) { if (`match "^modelPanel" $panel`=="modelPanel") { $mode=`modelEditor -q -polymeshes $panel`; if ($mode>0) modelEditor -e -polymeshes false -strokes false -nurbsCurves false $panel; else modelEditor -e -polymeshes true -strokes true -nurbsCurves true $panel; } } } else print ("// Warning: No model panels to modify. \n"); } global proc hdriButtonKill() { string $hud = "hdriSunButton"; string $envCheck[] = `ls -type VRayPlaceEnvTex`; string $hdriPlacement_name = $envCheck[0]; string $domeCheck[] = `ls -type VRayLightDomeShape`; string $hdriDome_name = $domeCheck[0]; string $envfileCheck[] = `listConnections -s 1 -type file $hdriDome_name`; if (`headsUpDisplay -q -ex $hud`) headsUpDisplay -rem $hud; if (`objExists $hdriPlacement_name`) select -r $hdriPlacement_name; hidePolyToggle; //lets swap jpg for hdr or exr string $fileAttribute = `getAttr ($envfileCheck[0]+".fileTextureName")`; string $tokenArray[]; tokenize($fileAttribute, ".", $tokenArray); string $format = $tokenArray[1]; string $filename = $tokenArray[0]; string $exr = `filetest -e ($filename+".exr")`; string $hdr = `filetest -e ($filename+".hdr")`; if ($format == "jpg" && $exr != 0) setAttr -type "string" ($envfileCheck[0]+".fileTextureName") ($tokenArray[0]+".exr"); if ($format == "jpg" && $hdr != 0) setAttr -type "string" ($envfileCheck[0]+".fileTextureName") ($tokenArray[0]+".hdr"); print "// Result: Successfully connected HDRI and V-Ray Sun. \n"; } global proc hdriButtonEx(){ string $geoSunCheck[] = `ls -type VRayGeoSun`; string $geoSun = $geoSunCheck[0]; string $findsun[] = `listRelatives -p $geoSun`; string $envCheck[] = `ls -type VRayPlaceEnvTex`; string $hdriPlacement_name = $envCheck[0]; string $domeCheck[] = `ls -type VRayLightDomeShape`; string $hdriDome_name = $domeCheck[0]; string $hdriSunExpression = "hdriSun_expression"; string $cameraTempName = "camera_temp"; string $hdriSun = ($findsun[0]+".rotateY = -"+$hdriPlacement_name+".horRotation"); string $hdriDome = ($findsun[0]+".rotateY = -"+$hdriDome_name+".rotateY"); //string $whatvp = `getPanel -wf`; expression -s $hdriSun -name $hdriSunExpression; lookThru persp; delete $cameraTempName; //DisplayShaded; setAttr ($hdriDome_name+".viewportTexEnable") 0; } global proc hdriSunConnector () { /*if (!`objExists $geoSun`) ( string $sunTransformNode = `createNode "VRayGeoSun"`; $vraySunNode = vrayGetVRayNode("VRaySunShape", "-asLight", 1, $sunTransformNode); $vraySunTargetNode = vrayGetVRayNode("VRaySunTarget", "-asLight", 1, ""); if (! `isConnected ($vraySunTargetNode+".source") ($vraySunNode+".target")`) { connectAttr -f ($vraySunTargetNode+".source") ($vraySunNode+".target"); } setAttr ($sunTransformNode + ".greset") true; $sunTargetTransformNode = vrayGetParent($vraySunTargetNode); if (!isParentOf($sunTargetTransformNode, $sunTransformNode)) parent $sunTransformNode $sunTargetTransformNode; }*/ string $hdriSunExpression = "hdriSun_expression"; string $hdriSunSuccess = "//Result: Successfully connected HDRI and V-Ray Sun.\n"; string $hdriPlacement_name; string $domeCheck[] = `ls -type VRayLightDomeShape`; string $hdriDome_name = $domeCheck[0]; string $hdriPlacementCheck[] = `ls -type VRayPlaceEnvTex`; string $hdriPlacement = $hdriPlacementCheck[0]; string $geoSunCheck[] = `ls -type VRayGeoSun`; string $geoSun = $geoSunCheck[0]; string $node = "vrayEnvironmentPreviewTm"; string $hdriSunLight = "hdriSun_VRayLightDome"; string $envifile = "hdriSun_file"; //string $envifilebg = "hdriSun_file_bg"; string $geoSunTransform[]; string $hdriSun_rotation = "hdriSun_rotation"; string $gamma = "hdriSun_gamma"; string $whatvp = `getPanel -wf`; string $cameraTempName = "camera_temp"; string $rels[]; // Create V-Ray settings exist if(!`objExists vraySettings`) vrayCreateVRaySettingsNode; // Check if $cameraTempName exists and script is working properly if(`objExists $cameraTempName`) delete $cameraTempName; if(`objExists $hdriSunExpression`) hdriReplace(); else { // Realigns if expression ever becomes broken if(size($hdriPlacement) > 0 && $geoSun == 1) { setAttr ($hdriPlacement + ".horFlip") 0; setAttr ($hdriPlacement + ".horRotation") 0; setAttr ($geoSun + ".tx") -407.819; setAttr ($geoSun + ".ty") 336.591; setAttr ($geoSun + ".tz") 2.297; setAttr ($geoSunTransform[0] +".rotateY") 0; } // Main aligning sequence. if (size($geoSun) > 0) { $createdNode = `createNode "camera" -n ($cameraTempName+"Shape")`; setAttr -lock true ($cameraTempName + ".tx"); setAttr -lock true ($cameraTempName + ".ty"); setAttr -lock true ($cameraTempName + ".tz"); setAttr ($cameraTempName + ".rx") 0; setAttr ($cameraTempName + ".ry") 90; setAttr ($cameraTempName + ".rz") 0; lookThru $cameraTempName; setAttr ($geoSun + ".tx") -407.819; setAttr ($geoSun + ".ty") 336.591; setAttr ($geoSun + ".tz") 2.297; select -r $geoSun; TranslateToolWithSnapMarkingMenu; setAttr ($hdriDome_name+".viewportTexEnable") 1; hudButton -s 2 -b 5 -vis 1 -l "Finished Aligning" -bw 200 -bsh "roundRectangle" -pc "hdriButtonEx" -rc "hdriButtonKill" hdriSunButton; hidePolyToggle; } else { // Attempt to create nodes and connect if nothing exists print "// Warning: V-Ray Sun and HDRI does not exist, attempting to create nodes. Please select HDRI image \n"; vrayCreateVRaySun(); $envifile = `shadingNode -asTexture file -n "hdriSun_file"`; setAttr ($envifile+".colorGain") -type double3 1.2 1.2 1.2; $hdriPlacement_name = `shadingNode -asUtility VRayPlaceEnvTex -n hdriSun_VRayPlaceEnvTex`; setAttr ($hdriPlacement_name + ".mappingType") 2; connectAttr -force ($hdriPlacement_name + ".outUV") ($envifile+".uvCoord"); //Connect HDRI to Background //$envifilebg = `shadingNode -asTexture file`; //connectAttr -force ($hdriPlacement_name + ".outUV") ($envifilebg+".uvCoord"); //connectAttr -force ($envifilebg + ".outColor") vraySettings.cam_envtexBg; //connectAttr -force ($envifilebg + ".outColor") vraySettings.cam_envtexRefract; //setAttr ($envifilebg+".colorGain") -type double3 $v $v $v ; //connectNodeToAttrOverride($envifilebg, "vraySettings.cam_envtexBg"); //connectNodeToAttrOverride($envifilebg, "vraySettings.cam_envtexRefract"); hdriSunOpen ("hdriSunTexture "+$envifile+".fileTextureName"); //check if dome exists string $domeCheck[] = `ls -type VRayLightDomeShape`; if (size($domeCheck) == 0) $hdriSunLight = `shadingNode -asLight VRayLightDomeShape -n "hdriSun_VRayLightDomeShape"`; if (size($domeCheck) == 1) $hdriSunLight = $domeCheck[0]; //Connect HDRI to Environment Dome setAttr ($hdriSunLight+".useDomeTex") 1; setAttr ($hdriSunLight +".viewportTexEnable") 0; setAttr ($hdriSunLight +".invisible") 0; setAttr ($hdriSunLight +".affectAlpha") 0; //connectNodeToAttrOverride($envifile, ($hdriSunLight+".domeTex")); connectAttr -force ($envifile+".outColor") ($hdriSunLight +".domeTex"); //Add automatic gamma correction vray addAttributesFromGroup $envifile vray_file_gamma 1; vrayAddAttr $envifile vrayFileGammaEnable; vrayAddAttr $envifile vrayFileColorSpace; vrayAddAttr $envifile vrayFileGammaValue; setAttr ($envifile+".vrayFileColorSpace") 1; setAttr ($envifile+".vrayFileGammaValue") 1; setAttr ($hdriSunLight +".viewportTexEnable") 1; setAttr ($hdriSunLight+".texResolution") 2048; setAttr ($envifile+".filter") .1; select -r $hdriPlacement_name; sets -n $hdriSun_rotation; select -clear; hdriSunConnector; } } } //File Browser dialogue fix global proc hdriSunOpen( string $cmd ){ fileBrowser ($cmd, "Select HDRI Image", "image", 0); //string $cmd; //string $basicFilter = "JPGs (*.jpg)"; //string $dir = "K:/Library/Maya/textures/HDRI"; //string $file[] = `fileDialog2 -fm 1 -fileFilter $basicFilter -dialogStyle 2 -dir $dir -cap "Select HDRI Image"`; //$cmd = fromNativePath( $file[0] ); } global proc int hdriSunTexture( string $fileAttribute, string $filename, string $fileType ){ setAttr $fileAttribute -type "string" $filename; string $currentDir = `workspace -q -dir`; retainWorkingDirectory ($currentDir); string $tokenArray[]; tokenize($fileAttribute, ".", $tokenArray); string $fileNode = $tokenArray[0]; return true; } // Replace HDRI confirm global proc hdriReplace() { hdriButtonKill; string $env_file = "hdriSun_file"; string $geoSunCheck[] = `ls -type VRayGeoSun`; string $geoSun = $geoSunCheck[0]; string $hdriSunExpression = "hdriSun_expression"; string $result = `confirmDialog -t "V-Ray Sun + HDRI" -m "V-Ray Sun and HDRI are already connected. Would you like to replace the HDRI image? \n " -b "OK" -button "Cancel" -db "OK" -cancelButton "Cancel" -icn question -ds "Cancel"`; if ($result == "OK") { delete $hdriSunExpression; hdriSunConnector; select -r $env_file ; hdriSunOpen ("hdriSunTexture " + $env_file+".fileTextureName"); select -r $geoSun; TranslateToolWithSnapMarkingMenu; hidePolyToggle; } } global proc hdriSunClean(){ string $hdriPlacement_name = "hdriSun_VRayPlaceEnvTex"; string $hdriSunExpression = "hdriSun_expression"; string $cameraTempName = "camera_temp"; string $hdriPlacement = "hdriSun_VRayPlaceEnvTex"; string $envifile = "hdriSun_file"; string $hud = "hdriSunButton"; string $geoSunCheck[] = `ls -type VRayGeoSun`; string $geoSun = $geoSunCheck[0]; string $domeCheck[] = `ls -type VRayLightDomeShape`; string $hdriDome_name = $domeCheck[0]; if (`objExists $hud`) headsUpDisplay -rem $hud; if (`objExists $hdriSunExpression`) delete $hdriSunExpression; if (`objExists $hdriPlacement_name`) delete $hdriPlacement_name; if (`objExists $cameraTempName`) delete $cameraTempName; if (`objExists $hdriPlacement`) delete $hdriPlacement; if (`objExists $hdriDome_name`) delete $hdriDome_name; if (`objExists $geoSun`) delete $geoSun; if (`objExists $envifile`) delete $envifile; }