//Beckman Institute // Imaging Technology Group // University of Illinois at Urbana-Champaign // 405 N. Mathews, Urbana, IL 61801 // itg@itg.uiuc.edu // Copyright 2001, Board of Trustees of the University of Illinois, // All Rights Reserved // This is unpublished proprietary software developed by the Beckman // Institute Imaging Technology Group (ITG) at the University of // Illinois at Urbana-Champaign (UIUC). The copyright notice above does not // evidence any actual or intended publication of such software. // This software may not be redistributed for any purpose and may not // be used for or incorporated in commercial products or services without // the prior written permission of UIUC c/o The Beckman Institute Imaging // Technology Group. // All advertising materials mentioning features or use of this software // must display the following acknowledgement: This product includes software // developed by The Beckman Institute Imaging Technology Group at the // University of Illinois at Urbana-Champaign. // UIUC MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE // FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED // WARRANTY. THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE // USERS OF THIS SOFTWARE. //Script to displace 2D color gradient microscope images to 3D displacement maps// //Supports setting up stereo animations and stereo stills for 3D crystaleyes glasses// //if you are using a version of maya less than 3.0, look down 20 or so lines to// // the ******** and remove the line after that.// // Thanks to all the people who helped me at the MEL Developers forum// // at Highend3d.com. Could not have made this without their help// // Please do not remove my name or the University's name from this script// //if any improvements are made on this script, I would love to have them// //email them to me at jrgilles@itg.uiuc.edu// //To run this, source the script, then run deleteWindow from the script editor, this can also //be put into a shelf button in the format of //source "c:/maya/scripts/geo.mel"; (filling in the correct path for the location) //deleteWindow; //LINE 39 39 39 39 39 39 39 39 global string $t2mDisImage; global string $t2mColorImage="blank"; global float $scaleSide; global float $scaleY; global float $scaleBack; global proc geo (int $stereo) { //(string $ImageName, int $TessU, int $TessV, int $GridU, int $GridV)// select -all; delete; float $scaleY; float $scaleSide; float $scaleBack; float $scaleFactor; float $scaleDepth; float $scaleWidth; //$scaleFactor=$scaleY/$scaleSide; source buildPanelPopupMenu.mel; string $ImageName = `textField -q -tx ImagePath`; string $ColorMap = `textField -q -tx ColorPath`; $scaleSide = `floatField -q -v fltWidth`; $scaleY = `floatField -q -v fltHeight`; $scaleBack = `floatField -q -v fltDepth`; if ($scaleSide>$scaleBack) { print ("\n"+$scaleSide+" Larger\n"); $scaleFactor=$scaleY/$scaleSide; $scaleDepth=$scaleBack/$scaleSide; $scaleWidth=1; } else if ($scaleSide<$scaleBack) { print ("\n"+$scaleBack+" Larger\n"); $scaleFactor=$scaleY/$scaleBack; $scaleWidth=$scaleSide/$scaleBack; $scaleDepth=1; } else if ($scaleSide==$scaleBack) { print ("\n"+$scaleBack+"is Equal To "+$scaleSide+"\n"); $scaleDepth=1; $scaleWidth=1; $scaleFactor=$scaleY/$scaleBack; } else print "\nInput not Working!\n"; //string $t2mColorImage; //string $t2mDisImage; //string $ImageName=$t2mDisImage; //string $ColorMap=$t2mColorImage; int $TessU = `intSliderGrp -q -v utessSlider`; int $TessV = `intSliderGrp -q -v vtessSlider`; int $GridU = `intSliderGrp -q -v ugridSlider`; int $GridV = `intSliderGrp -q -v vgridSlider`; int $LightsOn = `checkBox -q -v lightBox`; int $AnimateOn = `checkBox -q -v animateBox`; editMenuUpdate MayaWindow|mainEditMenu; scriptedPanel -e -rp modelPanel1 hyperShadePanel1; ls -type defaultShaderList; ls -type defaultTextureList; listNodeTypes "shader/surface"; listNodeTypes texture; currentProjectParentDir(); ls -type defaultShaderList; ls -type defaultTextureList; listNodeTypes "shader/surface"; listNodeTypes texture; currentProjectParentDir(); findNewCurrentModelView; // PREVIOUS OPENS HYPERSHADE WINDOW TO FIX ERROR // nurbsPlane -p 0 0 0 -ax 0 1 0 -w 1 -lr 1 -d 3 -u $GridU -v $GridV -ch 1; objectMoveCommand; //************For Maya versions below 3 the next line must be removed************// setAttr "nurbsPlaneShape1.featureDisplacement" 0; setAttr "nurbsPlaneShape1.explicitTessellationAttributes" 1; setAttr "nurbsPlaneShape1.numberU" $TessU; setAttr "nurbsPlaneShape1.numberV" $TessV; editMenuUpdate MayaWindow|mainEditMenu; //hyperShade -createNode "phong" "hyperShadePanel1HyperShadeEd"; renderCreateNode("-asShader","surfaceShader","phong","",0,0,1,1,0,"hyperShadePanel1HyperShadeEd"); shadingNode -asShader phong; sets -renderable true -noSurfaceShader true -empty -name phong1SG; //workAreaAddCallback hyperShadePanel1HyperShadeEdOptionMenu hyperShadePanel1HyperShadeEd "phong1"; //workAreaSelectCallback hyperShadePanel1HyperShadeEdOptionMenu hyperShadePanel1HyperShadeEd "phong1"; ls -type defaultShaderList; ls -type defaultTextureList; listNodeTypes "shader/surface"; listNodeTypes texture; currentProjectParentDir(); refreshAE; autoUpdateAttrEd; hyperShade -createNode "file" "hyperShadePanel1HyperShadeEd"; renderCreateNode("-as2DTexture","","file","",0,0,1,0,0,"hyperShadePanel1HyperShadeEd"); shadingNode -asTexture file; shadingNode -asUtility place2dTexture; attributeMenu -finishMenu -editor hyperShadePanel1HyperShadeEd -plug file1.outColor -inputs 1 phong1; popupMenu -e -deleteAllItems hyperShadePanel1HyperShadeEdPopupMenu; defaultNavigation -ce -d phong1SG.displacementShader -source file1; shadingNode -asShader displacementShader; shadingNode -asUtility bump2d; setAttr file1.filter 0.0; setAttr file1.filterOffset 0.001953125; setAttr bump2d1.bumpFilter 0.0; setAttr bump2d1.bumpFilterOffset 0.001953125; ls -type defaultShaderList; ls -type defaultTextureList; listNodeTypes "shader/surface"; listNodeTypes texture; currentProjectParentDir(); editMenuUpdate MayaWindow|mainEditMenu; autoUpdateAttrEd; select -r file1 ; source AEfileTemplate.mel; //Previous line needed to source AEFileTemplate so the displacement will work // AEassignTextureCB file1.fileTextureName $ImageName "image"; defaultNavigation -source phong1 -destination |nurbsPlane1|nurbsPlaneShape1.instObjGroups[0] -connectToExisting; select -r nurbsPlane1; setAttr nurbsPlaneShape1.boundingBoxScale -type double3 21.0725 21.0725 21.0725; editMenuUpdate MayaWindow|mainEditMenu; displacementToPoly; setAttr "nurbsPlane1_displacement1.scaleY" $scaleFactor; setAttr "nurbsPlane1_displacement1.scaleX" $scaleWidth; setAttr "nurbsPlane1_displacement1.scaleZ" $scaleDepth; shadingNode -asShader phong; sets -renderable true -noSurfaceShader true -empty -name phong3SG; connectAttr -f phong3.outColor phong3SG.surfaceShader; select -r phong3; //showEditor phong3; //rename phong3 "displaceShader"; //defaultNavigation -cn -d displaceShader.color; //createRenderNode -allWithTexturesUp "defaultNavigation -f true -ce -s %node -d phong3.color" ""; //defaultNavigation -dtv -d phong3.color; shadingNode -asTexture file; shadingNode -asUtility place2dTexture; connectAttr -f place2dTexture3.coverage file3.coverage; connectAttr -f place2dTexture3.translateFrame file3.translateFrame; connectAttr -f place2dTexture3.rotateFrame file3.rotateFrame; connectAttr -f place2dTexture3.mirror file3.mirror; connectAttr -f place2dTexture3.stagger file3.stagger; connectAttr -f place2dTexture3.wrapU file3.wrapU; connectAttr -f place2dTexture3.wrapV file3.wrapV; connectAttr -f place2dTexture3.repeatUV file3.repeatUV; connectAttr -f place2dTexture3.offset file3.offset; connectAttr -f place2dTexture3.rotateUV file3.rotateUV; connectAttr -f place2dTexture3.noiseUV file3.noiseUV; connectAttr place2dTexture3.outUV file3.uv; connectAttr place2dTexture3.outUvFilterSize file3.uvFilterSize; //defaultNavigation -f true -ce -s file3 -d phong3.color; connectAttr -f file3.outColor phong3.color; //defaultNavigation -source file3 -destination |nurbsPlane1_displacement1|nurbsPlaneShape1_displacement1.instObjGroups[0] -connectToExisting; //connectAttr -f file3.outColor lambert1.color; if ($ColorMap!="") AEassignTextureCB file3.fileTextureName $ColorMap "image"; else AEassignTextureCB file3.fileTextureName $ImageName "image"; defaultNavigation -source phong3 -destination |nurbsPlane1_displacement1|nurbsPlaneShape1_displacement1.instObjGroups[0] -connectToExisting; editMenuUpdate MayaWindow|mainEditMenu; //updateShadingMenu MayaWindow|mayaMainWindowForm|formLayout6|viewPanes|modelPanel4|menu27 modelPanel4;// //updateShadingMenu MayaWindow|mayaMainWindowForm|formLayout6|viewPanes|modelPanel4|menu27 modelPanel4;// modelEditor -e -da smoothShaded -ao false modelPanel4; editMenuUpdate MayaWindow|mainEditMenu; //updateShadingMenu MayaWindow|mayaMainWindowForm|formLayout6|viewPanes|modelPanel4|menu27 modelPanel4;// //updateShadingMenu MayaWindow|mayaMainWindowForm|formLayout6|viewPanes|modelPanel4|menu27 modelPanel4;// modelEditor -e -displayTextures 1 modelPanel4; editMenuUpdate MayaWindow|mainEditMenu; select -r nurbsPlane1 ; delete; camera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.4173 -horizontalFilmOffset 0 -verticalFilmAperture 0.9449 -verticalFilmOffset 0 -filmFit Horizontal -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.01 -farClipPlane 1000 -orthographic 0 -orthographicWidth 30; objectMoveCommand; cameraMakeNode 1 ""; setAttr "camera1.translateX" 1.008; setAttr "camera1.translateY" 1.019; setAttr "camera1.translateZ" 1.342; setAttr "camera1.rotateX" -32.999; setAttr "camera1.rotateY" 37.2; setAttr "cameraShape1.horizontalFilmAperture" 1.417; setAttr "cameraShape1.verticalFilmAperture" 0.945; setAttr "cameraShape1.focalLength" 35; setAttr "cameraShape1.lensSqueezeRatio" 1; setAttr "cameraShape1.fStop" 5.6; setAttr "cameraShape1.focusDistance" 5; setAttr "cameraShape1.shutterAngle" 144; setAttr "cameraShape1.centerOfInterest" 4.379; move -r -1.008 -1.019 -1.342 camera1.scalePivot camera1.rotatePivot; lookThroughModelPanel camera1 modelPanel4; select nurbsPlane1_displacement1; select -r displacementShader1; delete; select -r displacementShader2; delete; select -r phong1; delete; select -r phong2; delete; //select -r phong3; //delete; select -cl; setAttr "nurbsPlaneShape1_displacement1.smoothShading" off; setAttr "phong3.ambientColor" -type double3 0.19834 0.19834 0.19834 ; setAttr "phong3.incandescence" -type double3 0.0248 0.0248 0.0248 ; if ($LightsOn) lights; if ($AnimateOn) { animate; if ($stereo==1) stereo; } if ($stereo==2) {still;} deleteUI displace; print ($scaleY+"\n"+$scaleSide+"\n"+$scaleFactor+"\n"); } global proc animate () { editMenuUpdate MayaWindow|mainEditMenu; playbackOptions -e -min 1.00 -max 135; //setMinMaxPlayback MayaWindow|mayaMainWindowForm|formLayout10|formLayout19|floatField3 MayaWindow|mayaMainWindowForm|formLayout10|formLayout19|floatField4;// //floatField -e -v `playbackOptions -q -ast` MayaWindow|mayaMainWindowForm|formLayout10|formLayout19|floatField2;// //floatField -e -v `playbackOptions -q -aet` MayaWindow|mayaMainWindowForm|formLayout10|formLayout19|floatField5;// select -r nurbsPlane1_displacement1 ; currentTime 1 ; setAttr "nurbsPlane1_displacement1.rotateY" 0; setKeyframe "nurbsPlane1_displacement1.ry"; currentTime 120 ; setAttr "nurbsPlane1_displacement1.rotateY" 180; setKeyframe "nurbsPlane1_displacement1.ry"; currentTime 60 ; setKeyframe "nurbsPlane1_displacement1.rz"; setKeyframe "nurbsPlane1_displacement1.rx"; currentTime 120 ; setAttr "nurbsPlane1_displacement1.rotateZ" -29.227; setAttr "nurbsPlane1_displacement1.rotateX" -36.565; setKeyframe "nurbsPlane1_displacement1.rz"; setKeyframe "nurbsPlane1_displacement1.rx"; currentTime 1; } global proc lights () { //Reset spotlight attributes to default// defaultSpotLight(1, 1,1,1, 0, 50, 0, 10, 0, 0,0,0, 1); setAttr "spotLight1.translateX" .0369; setAttr "spotLight1.translateY" .924; setAttr "spotLight1.translateZ" 1.5; setAttr "spotLight1.rotateX" -31.2; setAttr "spotLight1.rotateY" 2; //Spot Light 2 below// defaultSpotLight(1, 1,1,1, 0, 50, 0, 10, 0, 0,0,0, 1); setAttr "spotLight2.translateX" -1.093; setAttr "spotLight2.translateY" .899; setAttr "spotLight2.translateZ" -.916; setAttr "spotLight2.rotateX" -33.6; setAttr "spotLight2.rotateY" -130.4; //Spot Light 3 below// defaultSpotLight(1, 1,1,1, 0, 50, 0, 10, 0, 0,0,0, 1); setAttr "spotLight3.translateX" 1.194; setAttr "spotLight3.translateY" 1.014; setAttr "spotLight3.translateZ" -.556; setAttr "spotLight3.rotateX" -40.2; setAttr "spotLight3.rotateY" 116; //Spot Light 1 below// defaultSpotLight(1, 1,1,1, 0, 50, 0, 10, 0, 0,0,0, 1); setAttr "spotLight4.translateX" 0; setAttr "spotLight4.translateY" 1.8; setAttr "spotLight4.translateZ" .094; setAttr "spotLight4.rotateX" -88.2; setAttr "spotLight4.rotateY" 2; defaultAmbientLight(1, 0.45, 1,1,1, "0", 0,0,0, "1"); move -r 0 0.6083549 0 ; setAttr "ambientLightShape1.intensity" .32; setAttr "spotLightShape1.intensity" .3; setAttr "spotLightShape2.intensity" .3; setAttr "spotLightShape3.intensity" .3; setAttr "spotLightShape4.intensity" .3; setAttr "spotLightShape1.coneAngle" 58; setAttr "spotLightShape2.coneAngle" 58; setAttr "spotLightShape3.coneAngle" 58; setAttr "spotLightShape4.coneAngle" 58; setAttr "spotLightShape1.useDepthMapShadows" off; setAttr "spotLightShape2.useDepthMapShadows" off; setAttr "spotLightShape3.useDepthMapShadows" off; setAttr "spotLightShape4.useDepthMapShadows" off; setAttr "spotLightShape1.dmapBias" 0; setAttr "spotLightShape2.dmapBias" 0; setAttr "spotLightShape3.dmapBias" 0; setAttr "spotLightShape4.dmapBias" 0; currentTime 1 ; select -cl; } global proc displaceWindow() { string $t2mColorImage; string $t2mDisImage; global int $stereo=0; float $scaleSide; float $scaleY; float $scaleBack; setNone($stereo=0); if ($stereo!=0) $stereo=0; deleteUI killit; windowPref -remove displace; window -t "Displacement Map" -wh 405 650 displace; columnLayout -cw 400; text -l "Image Path:"; textField -w 350 ImagePath; button -l "browse" -c "gload"; text -l " "; text -l "Enter Path to Map a Different File for Shading"; textField -w 350 ColorPath; button -l "browse" -c "cload"; string $ImageName = `textField -q -tx ImagePath`; text -l " "; checkBox -w 75 -v 1 -l "Lights" lightBox; checkBox -w 75 -v 1 -l "Animate" animateBox; text -l " "; text -l "If you would like to set scaling, enter the hight, width and depth here."; text -l "The default values will, in most cases, give a good image, but are not"; text -l "scientifically accurate in preserving scales.\n"; text -l "(range: 0-9999)\n"; text -l "Width:"; floatField -w 60 -pre 1 -min 0 -max 9999 -v 1000 fltWidth; $scaleSide = `floatField -q -v fltWidth`; text -l "Depth:"; floatField -w 60 -pre 2 -min 0 -max 9999 -v 1000 fltDepth; $scaleBack = `floatField -q -v fltDepth`; text -l "Height:"; floatField -w 60 -pre 2 -min 0 -max 9999 -v 130 fltHeight; $scaleY = `floatField -q -v fltHeight`; text -l " "; radioButtonGrp -numberOfRadioButtons 3 -sl 3 -labelArray3 "StereoAnimation" "StereoStill" "None" -on1 "setAnim($stereo=1)" -on2 "setStill($stereo=2)" -on3 "setNone($stereo=0)" stereoGrp; text -l " "; intSliderGrp -l "Tessellation U" -v 16 -f true -s 1 -min 1 -max 40 -fmx 400 -fmn 1 utessSlider; text -l " "; intSliderGrp -l "Tessellation V" -v 16 -f true -s 1 -min 1 -max 40 -fmx 400 -fmn 1 vtessSlider; text -l " "; intSliderGrp -l "Grid Units U" -v 12 -f true -s 1 -min 1 -max 40 -fmx 400 -fmn 1 ugridSlider; text -l " "; intSliderGrp -l "Grid Units V" -v 12 -f true -s 1 -min 1 -max 40 -fmx 400 -fmn 1 vgridSlider; text -l " "; button -w 390 -l "Displace Geometry" -command "geo($stereo)"; //button -w 390 -l "Displace Geometry" -command "var"; showWindow displace; } global proc int setNone(int $stereo){ $stereo=0; return $stereo;} global proc int setAnim(int $stereo){ $stereo=1; return $stereo;} global proc int setStill(int $stereo){ $stereo=2; return $stereo;} global proc deleteWindow () { window -t "Delete Scene" -wh 200 150 killit; columnLayout -cw 50; text -l "Running this script will delete everything\nfrom your scene. OK to DELETE?\n"; text -l " "; button -w 192 -l "DELETE" -command displaceWindow; text -l " "; button -w 192 -l "CANCEL" -command abort; showWindow killit; } global proc abort (){ deleteUI killit;} global proc abortStill (){ deleteUI ssc;} global proc testit() { string $ImageName = `textField -q -tx ImagePath`; int $TessU = `intSliderGrp -q -v utessSlider`; int $TessV = `intSliderGrp -q -v vtessSlider`; int $GridU = `intSliderGrp -q -v ugridSlider`; int $GridV = `intSliderGrp -q -v vgridSlider`; int $LightsOn = `checkBox -q -v lightBox`; int $AnimateOn = `checkBox -q -v animateBox`; int $StereoOn = `checkBox -q -v stereoBox`; string $ImageBrowse = `button -q ImagePath2`; print( $ImageBrowse + "\n"); print( $TessU + "\n"); print( $TessV + "\n"); print( $ImageName + "\n"); print( $GridU + "\n"); print( $GridV + "\n"); print( $LightsOn + "\n"); print( $AnimateOn + "\n"); } global proc stereo(){ select -r camera1; setAttr "camera1.rotateY" 31.7; select -cl; } global proc still(){ windowPref -remove ssc; window -t "Stereo Still Control" -wh 250 200 ssc; columnLayout -cw 100; text -l "1. Position camera for first still image."; text -l "2. Render out the still from the camera view."; text -l "3. Click GetStereo to calculate the stereo image."; text -l "4. Render it out with a different name."; text -l " "; text -l " "; button -w 192 -l "GetStereo" -command runStill; text -l " "; button -w 192 -l "Cancel" -command abortStill; showWindow ssc; } global proc runStill () { deleteUI ssc; float $test1=`getAttr camera1.translateZ`; float $test2=`getAttr camera1.translateX`; float $test3=`getAttr camera1.translateY`; float $test4=(sqrt(($test1*$test1)+($test2*$test2)+($test3*$test3))); float $adjRotX=-($test2-1.008); float $adjRotY=-($test3-1.019); float $adjRotZ=-($test1-1.342); move -r $adjRotX $adjRotY $adjRotZ camera1.scalePivot camera1.rotatePivot; float $adjCR; if ($test4<0.8620381493) $adjCR=-(-(1.819*$test4*$test4)+(5.001*$test4)-0.959); else if (0.8620381493<=$test4<=2.060688233) $adjCR=-((-7.097*$test4*$test4*$test4*$test4)+(45.171*$test4*$test4*$test4)-(107.849*$test4*$test4)+(116.243*$test4)-43.062); else if (2.060688233<$test4<=4.574631405) $adjCR=-(-0.060*$test4*$test4+0.575*$test4+4.868); else if ($test4>4.574631405) $adjCR=-(0.004*$test4+6.232); print ("camera1.translateZ= "+$test1 +"\n"); print ("camera1.translateX= "+$test2 +"\n"); print ("camera1.translateY= "+$test3 +"\n"); print ("adjust pivotX= "+$adjRotX +"\n"); print ("adjust pivotY= "+$adjRotY +"\n"); print ("adjust pivotZ= "+$adjRotZ +"\n"); print ("Vector Length= "+$test4 +"\n"); print ("Degrees of Adjustment= "+$adjCR +"\n"); float $loadCR=`getAttr camera1.rotateY`; float $stillR = $loadCR+$adjCR; print ("Previous Camera Angle= "+$loadCR +"\n"); print ("New Camera Angle= "+$stillR +"\n"); //setAttr "camera1.rotateY" $stillR;// } global proc gload(){ string $t2mDisImage; string $loadFileName=`fileDialog`; print($loadFileName+" \n"); $RegExp=".*"; //$loadFileName = `substitute ".*/" $loadFileName ""`; print($loadFileName+" \n"); if($loadFileName != ""){ print("Loading....\n"); }else{ print("You did not select a file correctly!\n"); } $t2mDisImage=$loadFileName; textField -edit -fileName $t2mDisImage ImagePath; print $t2mDisImage; } global proc cload(){ //gimmie an error string $t2mColorImage; string $loadFileNameC=`fileDialog`; print($loadFileNameC+" \n"); $RegExp=".*"; //$loadFileName = `substitute ".*/" $loadFileNameC ""`; print($loadFileNameC+" \n"); if($loadFileNameC != ""){ print("Loading....\n"); }else{ print("You did not select a file correctly!\n"); } $t2mColorImage=$loadFileNameC; textField -edit -fileName $t2mColorImage ColorPath; print $t2mColorImage; } //global proc var(){ //float $scaleY; //float $scaleSide; //$scaleSide = `floatField -q -v fltWidth`; //$scaleY = `floatField -q -v fltHeight`; //print ("\n"+$scaleY+"\n"+$scaleSide+"\n");}