//To run the script you can copy from here till the end of script.
/* In this tutorial we are going to make a modeling reference box with reference images placed on the faces of the box, the faces are normalized and finally planner mapping is done to get the image placed perfectly*/
// this proc creates the window and a float value field where a user can enter his required //value for the modeling box width, height and depth in cm.
proc refBox()
{
global string $box;
polyCube -ch on -o on -cuv 4 ;
// here we give a name to the window and initialize the window
string $winName = `window -title "Ref_Cube" -rtf 1`;
columnLayout -adjustableColumn true;
// here we create a column and give the labels to the fields.
text -label "Width Height Depth" -align "center";
setParent .. ;
// now we align the column / row layout for the controls of the window
columnLayout -rowSpacing 5 -columnWidth 150;
rowLayout -numberOfColumns 1 -columnWidth1 255;
$box = `floatFieldGrp -numberOfFields 3 -extraLabel "cm" -value1 10.0 -value2 10.0 -value3 20.0`;
setParent .. ;
setParent .. ;
columnLayout -adjustableColumn true;
button -label "Create Box" -width 120 -align "center" -annotation "Set Cube Value for Refrence Box" -command "getBoxValue";
setParent .. ;
columnLayout -rowSpacing 5 -columnWidth 150;
separator -width 300;
rowLayout -numberOfColumns 2 -columnWidth2 150 150;
button -label "Set reverse normalise" -width 120 -annotation "Reverse and normalise all side of Refrence Box" -command "reverseNorm";
setParent .. ;
separator -width 300;
rowLayout -numberOfColumns 2 -columnWidth2 150 150;
button -label "Set Front Image" -width 120 -command "setimagef";
setParent .. ;
rowLayout -numberOfColumns 2 -columnWidth2 150 150;
button -label "Set Back Image" -width 120 -command "setimageb";
setParent .. ;
rowLayout -numberOfColumns 2 -columnWidth2 150 150;
button -label "Set Right Image" -width 120 -command "setimagers";
setParent .. ;
rowLayout -numberOfColumns 2 -columnWidth2 150 150;
button -label "Set Left Image" -width 120 -command "setimagels";
setParent .. ;
rowLayout -numberOfColumns 2 -columnWidth2 150 150;
button -label "Set Top Image" -width 120 -command "setimaget";
setParent .. ;
setParent .. ;
separator -width 300;
columnLayout -adjustableColumn true;
button -label "planar Mapping" -align "center" -width 120 -command "planar";
setParent .. ;
separator -width 300;
// here we show the window
showWindow $winName;
window -edit -widthHeight 280 320 $winName;
}
// this proc merely echoes the value of the box and set the values to create the box.
global proc getBoxValue()
{
global string $box;
float $v[] = `floatFieldGrp -q -v $box`;
print("The current value of the slider is " + $v[0] + "\n");
setAttr ("polyCube1.width") $v[0];
setAttr ("polyCube1.height") $v[1];
setAttr ("polyCube1.depth") $v[2];
}
// from here onwards we write the proc to sets the images for references
// First we set the front image by the proc “setimagef”
global proc setimagef()
{
select -r pCube1.f[2];
select -r pCube1.f[2] ;
shadingNode -asShader lambert;
sets -renderable true -noSurfaceShader true -empty -name lambert2SG;
select -r pCube1.f[2] ;
connectAttr -f lambert2.outColor lambert2SG.surfaceShader;
sets -e -forceElement lambert2SG;
select -r pCube1.f[2] ;
defaultNavigation -createNew -destination "lambert2.color";
createRenderNode -allWithTexturesUp "defaultNavigation -force true -connectToExisting -source %node -destination lambert2.color" "";
defaultNavigation -defaultTraversal -destination "lambert2.color";
select -r pCube1.f[2] ;
shadingNode -asTexture file;
shadingNode -asUtility place2dTexture;
connectAttr -f place2dTexture1.coverage file1.coverage;
connectAttr -f place2dTexture1.translateFrame file1.translateFrame;
connectAttr -f place2dTexture1.rotateFrame file1.rotateFrame;
connectAttr -f place2dTexture1.mirrorU file1.mirrorU;
connectAttr -f place2dTexture1.mirrorV file1.mirrorV;
connectAttr -f place2dTexture1.stagger file1.stagger;
connectAttr -f place2dTexture1.wrapU file1.wrapU;
connectAttr -f place2dTexture1.wrapV file1.wrapV;
connectAttr -f place2dTexture1.repeatUV file1.repeatUV;
connectAttr -f place2dTexture1.offset file1.offset;
connectAttr -f place2dTexture1.rotateUV file1.rotateUV;
connectAttr -f place2dTexture1.noiseUV file1.noiseUV;
connectAttr -f place2dTexture1.vertexUvOne file1.vertexUvOne;
connectAttr -f place2dTexture1.vertexUvTwo file1.vertexUvTwo;
connectAttr -f place2dTexture1.vertexUvThree file1.vertexUvThree;
connectAttr -f place2dTexture1.vertexCameraOne file1.vertexCameraOne;
connectAttr place2dTexture1.outUV file1.uv;
connectAttr place2dTexture1.outUvFilterSize file1.uvFilterSize;
defaultNavigation -force true -connectToExisting -source file1 -destination lambert2.color;
connectAttr -force file1.outColor lambert2.color;
}
// First we set the back image by the proc “setimageb”
global proc setimageb()
{
select -r pCube1.f[0] ;
select -r pCube1.f[0] ;
shadingNode -asShader lambert;
sets -renderable true -noSurfaceShader true -empty -name lambert3SG;
select -r pCube1.f[0] ;
connectAttr -f lambert3.outColor lambert3SG.surfaceShader;
sets -e -forceElement lambert3SG;
select -r pCube1.f[0] ;
defaultNavigation -createNew -destination "lambert3.color";
createRenderNode -allWithTexturesUp "defaultNavigation -force true -connectToExisting -source %node -destination lambert3.color" "";
defaultNavigation -defaultTraversal -destination "lambert3.color";
select -r pCube1.f[0] ;
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.mirrorU file3.mirrorU;
connectAttr -f place2dTexture3.mirrorV file3.mirrorV;
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 -f place2dTexture3.vertexUvOne file3.vertexUvOne;
connectAttr -f place2dTexture3.vertexUvTwo file3.vertexUvTwo;
connectAttr -f place2dTexture3.vertexUvThree file3.vertexUvThree;
connectAttr -f place2dTexture3.vertexCameraOne file3.vertexCameraOne;
connectAttr place2dTexture3.outUV file3.uv;
connectAttr place2dTexture3.outUvFilterSize file3.uvFilterSize;
defaultNavigation -force true -connectToExisting -source file3 -destination lambert3.color;
connectAttr -force file3.outColor lambert3.color;
}
// First we set the rightside image by the proc “setimagers”
global proc setimagers()
{
select -r pCube1.f[5] ;
select -r pCube1.f[5] ;
shadingNode -asShader lambert;
sets -renderable true -noSurfaceShader true -empty -name lambert4SG;
select -r pCube1.f[5] ;
connectAttr -f lambert4.outColor lambert4SG.surfaceShader;
sets -e -forceElement lambert4SG;
select -r pCube1.f[5] ;
defaultNavigation -createNew -destination "lambert4.color";
createRenderNode -allWithTexturesUp "defaultNavigation -force true -connectToExisting -source %node -destination lambert4.color" "";
defaultNavigation -defaultTraversal -destination "lambert4.color";
select -r pCube1.f[5] ;
shadingNode -asTexture file;
shadingNode -asUtility place2dTexture;
connectAttr -f place2dTexture5.coverage file5.coverage;
connectAttr -f place2dTexture5.translateFrame file5.translateFrame;
connectAttr -f place2dTexture5.rotateFrame file5.rotateFrame;
connectAttr -f place2dTexture5.mirrorU file5.mirrorU;
connectAttr -f place2dTexture5.mirrorV file5.mirrorV;
connectAttr -f place2dTexture5.stagger file5.stagger;
connectAttr -f place2dTexture5.wrapU file5.wrapU;
connectAttr -f place2dTexture5.wrapV file5.wrapV;
connectAttr -f place2dTexture5.repeatUV file5.repeatUV;
connectAttr -f place2dTexture5.offset file5.offset;
connectAttr -f place2dTexture5.rotateUV file5.rotateUV;
connectAttr -f place2dTexture5.noiseUV file5.noiseUV;
connectAttr -f place2dTexture5.vertexUvOne file5.vertexUvOne;
connectAttr -f place2dTexture5.vertexUvTwo file5.vertexUvTwo;
connectAttr -f place2dTexture5.vertexUvThree file5.vertexUvThree;
connectAttr -f place2dTexture5.vertexCameraOne file5.vertexCameraOne;
connectAttr place2dTexture5.outUV file5.uv;
connectAttr place2dTexture5.outUvFilterSize file5.uvFilterSize;
defaultNavigation -force true -connectToExisting -source file5 -destination lambert4.color;
connectAttr -force file5.outColor lambert4.color;
}
// First we set the leftside image by the proc “setimagels”
global proc setimagels()
{
select -r pCube1.f[4] ;
select -r pCube1.f[4] ;
shadingNode -asShader lambert;
sets -renderable true -noSurfaceShader true -empty -name lambert5SG;
select -r pCube1.f[4] ;
connectAttr -f lambert5.outColor lambert5SG.surfaceShader;
sets -e -forceElement lambert5SG;
select -r pCube1.f[4] ;
defaultNavigation -createNew -destination "lambert5.color";
createRenderNode -allWithTexturesUp "defaultNavigation -force true -connectToExisting -source %node -destination lambert5.color" "";
defaultNavigation -defaultTraversal -destination "lambert5.color";
select -r pCube1.f[4] ;
shadingNode -asTexture file;
shadingNode -asUtility place2dTexture;
connectAttr -f place2dTexture6.coverage file6.coverage;
connectAttr -f place2dTexture6.translateFrame file6.translateFrame;
connectAttr -f place2dTexture6.rotateFrame file6.rotateFrame;
connectAttr -f place2dTexture6.mirrorU file6.mirrorU;
connectAttr -f place2dTexture6.mirrorV file6.mirrorV;
connectAttr -f place2dTexture6.stagger file6.stagger;
connectAttr -f place2dTexture6.wrapU file6.wrapU;
connectAttr -f place2dTexture6.wrapV file6.wrapV;
connectAttr -f place2dTexture6.repeatUV file6.repeatUV;
connectAttr -f place2dTexture6.offset file6.offset;
connectAttr -f place2dTexture6.rotateUV file6.rotateUV;
connectAttr -f place2dTexture6.noiseUV file6.noiseUV;
connectAttr -f place2dTexture6.vertexUvOne file6.vertexUvOne;
connectAttr -f place2dTexture6.vertexUvTwo file6.vertexUvTwo;
connectAttr -f place2dTexture6.vertexUvThree file6.vertexUvThree;
connectAttr -f place2dTexture6.vertexCameraOne file6.vertexCameraOne;
connectAttr place2dTexture6.outUV file6.uv;
connectAttr place2dTexture6.outUvFilterSize file6.uvFilterSize;
defaultNavigation -force true -connectToExisting -source file6 -destination lambert5.color;
connectAttr -force file6.outColor lambert5.color;
}
// First we set the topside image by the proc “setimaget”
global proc setimaget()
{
select -r pCube1.f[3] ;
select -r pCube1.f[3] ;
shadingNode -asShader lambert;
sets -renderable true -noSurfaceShader true -empty -name lambert6SG;
select -r pCube1.f[3] ;
connectAttr -f lambert6.outColor lambert6SG.surfaceShader;
sets -e -forceElement lambert6SG;
select -r pCube1.f[3] ;
defaultNavigation -createNew -destination "lambert6.color";
createRenderNode -allWithTexturesUp "defaultNavigation -force true -connectToExisting -source %node -destination lambert6.color" "";
defaultNavigation -defaultTraversal -destination "lambert6.color";
select -r pCube1.f[3] ;
shadingNode -asTexture file;
shadingNode -asUtility place2dTexture;
connectAttr -f place2dTexture9.coverage file9.coverage;
connectAttr -f place2dTexture9.translateFrame file9.translateFrame;
connectAttr -f place2dTexture9.rotateFrame file9.rotateFrame;
connectAttr -f place2dTexture9.mirrorU file9.mirrorU;
connectAttr -f place2dTexture9.mirrorV file9.mirrorV;
connectAttr -f place2dTexture9.stagger file9.stagger;
connectAttr -f place2dTexture9.wrapU file9.wrapU;
connectAttr -f place2dTexture9.wrapV file9.wrapV;
connectAttr -f place2dTexture9.repeatUV file9.repeatUV;
connectAttr -f place2dTexture9.offset file9.offset;
connectAttr -f place2dTexture9.rotateUV file9.rotateUV;
connectAttr -f place2dTexture9.noiseUV file9.noiseUV;
connectAttr -f place2dTexture9.vertexUvOne file9.vertexUvOne;
connectAttr -f place2dTexture9.vertexUvTwo file9.vertexUvTwo;
connectAttr -f place2dTexture9.vertexUvThree file9.vertexUvThree;
connectAttr -f place2dTexture9.vertexCameraOne file9.vertexCameraOne;
connectAttr place2dTexture9.outUV file9.uv;
connectAttr place2dTexture9.outUvFilterSize file9.uvFilterSize;
defaultNavigation -force true -connectToExisting -source file9 -destination lambert6.color;
connectAttr -force file9.outColor lambert6.color;
}
// Here we set the planner mapping on the faces
global proc planar ()
{
select -r pCube1.f[2] ;
polyProjection -ch 1 -type Planar -ibd on -md z pCube1.f[2];
select -r pCube1.f[0] ;
polyProjection -ch 1 -type Planar -ibd on -md z pCube1.f[0];
select -r pCube1.f[5] ;
polyProjection -ch 1 -type Planar -ibd on -md x pCube1.f[5];
select -r pCube1.f[4] ;
polyProjection -ch 1 -type Planar -ibd on -md x pCube1.f[4];
select -r pCube1.f[3] ;
polyProjection -ch 1 -type Planar -ibd on -md y pCube1.f[3];
}
// here we do the normalisation of the cube faces
global proc reverseNorm ()
{
displayCull -bfc true; // here we set the back face culling to true
select -r pCube1.f[0:5] ;
polyNormal -normalMode 4 -userNormalMode 0 -ch 1 pCube1.f[0:5];
}
// Finally we call the main procedure
refBox;
/* End of the script */
|