Friday, April 8, 2011

'Auto Building Maker' By Rumesh Tharanga - MEL Script.

Concept and Programme Logic Testing

I wrote this script to test the concept came into my mind about automating and instancing buildings in a 3D scene. And did this as a simple script to test basic work flow behind whole concept. I am about to develop some complex scripting system to make an entirely customizable object instancing interface, which  will be able to use for my movie 'Ananthavarthana (අනන්තාවර්තන) - curvedInfinity'. 'Ananthavarthana' literally has to be populated with thousands of objects. Even duplicating will not be an option for such complex situations. 

So I thought of developing some sort of system that will save my time and work as my guardian. 

So I will be able to - Populate any Scenery with Buildings or with any other object that is not Identical one to a another. Moreover that, I will be able to instantiate Characters and their animations as well. (Eg - Some robots in a hallway walking all around avoiding each other or standing randomly, random moments.) 

Hopefully the script system I am about to develop for 'Ananthavarthana (අනන්තාවර්තන) - curvedInfinity' will be available for everyone for free after the movie has been released.

So in this script you will see some basic work flow behind it. And please mind that, this is the first Script of its' kind written by me; it has a few bugs in it, which I didn't fix. My mere intention was to test the idea arouse in my mind.

You will get a basic idea how this script works by following  video.
 


Following video shows some example this script is in action.



Here are some of my original drawings and main flow chart that I used to develop some basic maths behind this process. These images present only about 20% of entire flow, I am sorry that I didn't draw flow charts for every possible solution as almost all the time I find it easy to keep the programme flow in my mind while I am coding rather than drawing on paper.
The Basic shape and Main parts in the building that is changeable. A cluster is the part that repeats.
The main flow chart. And please note that every command in square boxes are some other flow charts I only mentioned as single commands.
User inputs, which are used to automated creation of buildings.

Math design for duplication of windows and how they should be spread across a floor.

Inner extrude of Building base.
And, Here you go with the Script...
 /*
    Author: Rumesh Tharanga
    Script Name: skyscrapers_builderUI.mel
    Script Version: 1.0
    Maya Version:  2011

    usage:
*/



global proc buttonActionEx(string $val1, string $val2, string $val3, string $val4, string $val0, string $val5, string $val6, string $val7, string $val8, string $val9, string $val10, string $val11, string $val12, string $val13, string $val14, string $val15, string $val16, string $val17, string $val18, string $val19) {

    string $temVal1 = `intFieldGrp -q -v1 $val1`;
    string $temVal2 = `intFieldGrp -q -v2 $val2`;
    string $temVal3 = `checkBoxGrp -q -value1 $val3`;
    string $temVal4 = `intSliderGrp -q -v $val4`;
    string $temVal0 = `intSliderGrp -q -v $val0`;
    string $temVal5 = `intSliderGrp -q -v $val5`;
    string $temVal6 = `intSliderGrp -q -v $val6`;
    string $temVal7 = `intSliderGrp -q -v $val7`;
    string $temVal8 = `intSliderGrp -q -v $val8`;
    string $temVal9 = `intSliderGrp -q -v $val9`;
    string $temVal10 = `intSliderGrp -q -v $val10`;
    string $temVal11 = `intSliderGrp -q -v $val11`;
    string $temVal12 = `checkBoxGrp -q -value1 $val12`;
    string $temVal13 = `intSliderGrp -q -v $val13`;
    string $temVal14 = `intSliderGrp -q -v $val14`; //Disabled
    string $temVal15 = `intSliderGrp -q -v $val15`; //Disabled
    string $temVal16 = `checkBoxGrp -q -value1 $val16`;
    string $temVal17 = `intSliderGrp -q -v $val17`;
    string $temVal18 = `intSliderGrp -q -v $val18`;
    string $temVal19 = `intSliderGrp -q -v $val19`;
  
    // Call Main Proceeders.
    createRequiredNodes();
  
    float $TEMx = $temVal1;
    float $TEMy = $temVal2;
    float $TEMz = $temVal4;
    float $widthScale = $TEMx*($TEMz/100);
    float $depthScale = $TEMy*($TEMz/100);
  
        float $startingHeightTem;
        if ($temVal3 == "1") {
            makeBase($temVal1, $temVal2, $temVal0, $temVal4);
            $startingHeightTem = $temVal0;
        } else { $startingHeightTem = 0;
                 spaceLocator -n locObj_moveRotate; // This locator will be used
                                       // to Move and Rotate respective Building.      
         }
      
        /*
        string $baseSt;
        if ($temVal3 == "1") {
            $baseSt = "true";
        } else { $baseSt = "false"; }
      
        */
      
        string $floorDivSt;
        if ($temVal12 == "1") {
            $floorDivSt = "true";
        } else { $floorDivSt = "false"; }
      
        string $hasTopSt;
        if ($temVal16 == "1") {
            $hasTopSt = "true";
        } else { $hasTopSt = "false"; }
  
    makeClusters($temVal7, $widthScale, $depthScale, $startingHeightTem, $temVal8, $temVal9, $floorDivSt, $temVal3, $temVal4, $temVal10, $temVal11, $hasTopSt, $temVal17, $temVal18, $temVal19);
}


//***************************************************************************************************************
// User Interface.
global proc  skyscrapers_builderUI() {
    
    string $mainDialog = `window
                        -title "skyscrapers Builder By Rumesh Tharanga- [Testing Concept and Programme Logic]"
                        -widthHeight 1000 800`;
  
    columnLayout;
        frameLayout -collapsable true
                        -label "Building Width And Depth" -width 700;
            rowColumnLayout -nc 1;
                global string $buildingWidthDepth;
                $buildingWidthDepth = `intFieldGrp -numberOfFields 2
                                       -label "Building Width And Depth"
                                       -value1 10 -value2 10`; 
            //setParent;
        //setParent;
    
        rowColumnLayout -nc 1;
            global string $hasBase;
            $hasBase = `checkBoxGrp -label "Make a Base" -v1 1`;
            //-onCommand "frameLayout -edit -en true $buildingWD"
            //-offCommand "frameLayout -edit -en false $buildingWD"`;
        //setParent;
      
        frameLayout -collapsable true -label "Values for Making Base" -width 700;
            rowColumnLayout -nc 1;
                 global string $inwardExtrudePrecentage;
                 $inwardExtrudePrecentage = `intSliderGrp -label "Inward Extrude Precentage"
                                        -minValue 10 -maxValue 100 -field true
                                        -fieldMinValue -10 -fieldMaxValue 100
                                        -value 70`;    
                 global string $baseHeight;
                 $baseHeight = `intSliderGrp -label "Base Height"
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 4`;
                global string $amountOfBaseConsPerWidth;
                $amountOfBaseConsPerWidth = `intSliderGrp -label "Amount of Base Cons per Width" -en false
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 10`;
                global string $amountOfBaseConsPerDepth;
                $amountOfBaseConsPerDepth = `intSliderGrp -label "Amount of Base Cons per Depth" -en false
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 10`;
            //setParent;
        //setParent;
      
        frameLayout -collapsable true -label "Values For Making A Clusters and Floors" -width 700;
            rowColumnLayout -nc 1;
                global string $amountOfClusters;
                $amountOfClusters = `intSliderGrp -label "Amount of clusters Building Has"
                                        -minValue 0 -maxValue 1000 -field true
                                        -fieldMinValue -0 -fieldMaxValue 700
                                        -value 5`;
                global string $heightOfAFloor;
                $heightOfAFloor = `intSliderGrp -label "Height of a single floor"
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 2`;
                global string $amountOfFloorPerACluster;
                $amountOfFloorPerACluster = `intSliderGrp -label "Amount of floor per a cluster"
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 3`;
                global string $amountOfWindowsPerWidth;
                $amountOfWindowsPerWidth = `intSliderGrp -label "Amount of Windows per width"
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 5`;
                global string $amountOfWindowsPerDepth;
                $amountOfWindowsPerDepth = `intSliderGrp -label "Amount of Windows per Depth"
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 5`;
                global string $hasClusterDividers;
                $hasClusterDividers = `checkBoxGrp -label "Make Cluster Dividers" -v1 1`;
                global string $clusterDividersHeight;
                $clusterDividersHeight = `intSliderGrp -label "Cluster Dividers Height"
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 2`;
                global string $midExtrudeHeight;
                $midExtrudeHeight = `intSliderGrp -label "Mid Extrude Height" -en false
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 2`;
                global string $midExtrudeAmount;
                $midExtrudeAmount = `intSliderGrp -label "Mid Extrude Amount" -en false
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 2`;          
            //setParent;
        //setParent;
      
        frameLayout -collapsable true -label "Building Floor And Tip" -width 700;
            rowColumnLayout -nc 1;
                global string $hasATip;
                $hasATip = `checkBoxGrp -label "Make A Building Tip" -v1 1`;
                global string $topHeight;
                $topHeight = `intSliderGrp -label "Building Top Height"
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 3`;
                global string $topInwardExtrudePrecentage;
                $topInwardExtrudePrecentage = `intSliderGrp -label "Top Inward extrude precentage"
                                        -minValue 10 -maxValue 100 -field true
                                        -fieldMinValue -10 -fieldMaxValue 100
                                        -value 60`;
                global string $tipHeight;
                $tipHeight = `intSliderGrp -label "Tip Height"
                                        -minValue 0 -maxValue 100 -field true
                                        -fieldMinValue -0 -fieldMaxValue 100
                                        -value 4`;
            //setParent;
        //setParent;
      
        rowColumnLayout -nc 2;
            //string $buildIt =
            button -label "Buil It" -command "buttonActionEx($buildingWidthDepth, $buildingWidthDepth, $hasBase, $inwardExtrudePrecentage, $baseHeight, $amountOfBaseConsPerWidth, $amountOfBaseConsPerDepth, $amountOfClusters, $heightOfAFloor, $amountOfFloorPerACluster, $amountOfWindowsPerWidth, $amountOfWindowsPerDepth, $hasClusterDividers, $clusterDividersHeight, $midExtrudeHeight, $midExtrudeAmount, $hasATip, $topHeight, $topInwardExtrudePrecentage, $tipHeight)";
            //string $cancelThis =
            button -label "Cancel";
        //setParent;
    //setParent;        
    showWindow $mainDialog;
} //End of making UI.


// Make Required Nodes for grouping Objects.
global proc createRequiredNodes () {
  
    if (!`objExists skyScrapers_grp`) {
  
        createNode "transform" -n "skyScrapers_grp"; //Global Node.
      
        createNode "transform" -n "basesGrp" -p "|skyScrapers_grp";
            createNode "transform" -n "baseConsGrp" -p "|skyScrapers_grp|basesGrp";
            createNode "transform" -n "baseSolidsGrp" -p "|skyScrapers_grp|basesGrp";
        createNode "transform" -n "clustersGrp" -p "|skyScrapers_grp";
            createNode "transform" -n "floorsGrp" -p "|skyScrapers_grp|clustersGrp";
                createNode "transform" -n "floorWallsGrp" -p "|skyScrapers_grp|clustersGrp|floorsGrp";
                createNode "transform" -n "floorWindowsGrp" -p "|skyScrapers_grp|clustersGrp|floorsGrp";
            createNode "transform" -n "floorDividersGrp" -p "|skyScrapers_grp|clustersGrp";
        createNode "transform" -n "roofTopsGrp" -p "|skyScrapers_grp";
            createNode "transform" -n "topBasesGrp" -p "|skyScrapers_grp|roofTopsGrp";
            createNode "transform" -n "topSolidsGrp" -p "|skyScrapers_grp|roofTopsGrp";
            createNode "transform" -n "tipsGrp" -p "|skyScrapers_grp|roofTopsGrp";

        createNode "transform" -n "objectMoveRotateLocatorsGrp";
      
        shadingNode -asShader blinn -n blinn_baseSolid;
        setAttr "blinn_baseSolid.color" 0 .5 0;
      
        shadingNode -asShader blinn -n blinn_baseCons;
        setAttr "blinn_baseCons.color" 0 0 1;
      
        shadingNode -asShader blinn -n blinn_floor;
        setAttr "blinn_floor.color" 0 1 0;
      
        shadingNode -asShader blinn -n blinn_floorWall;
        setAttr "blinn_floorWall.color" 0 1 1;
      
        shadingNode -asShader blinn -n blinn_window;
        setAttr "blinn_window.color" 1 0 0;
      
      
        shadingNode -asShader blinn -n blinn_floorDivider;
        setAttr "blinn_floorDivider.color" 1 0 1;
      
        shadingNode -asShader blinn -n blinn_topSolid;
        setAttr "blinn_topSolid.color" 1 1 1;
      
        shadingNode -asShader blinn -n blinn_tip;
        setAttr "blinn_tip.color" .5 0 .5;
    }
}

// Proceeder for Making The BASE.
global proc makeBase(float $baseWidth, float $baseDepth, float $baseHeight, float $inwardExtrudePrecentage) {

    spaceLocator -n locObj_moveRotate; // This locator will be used
                                       // to Move and Rotate respective Building.
 
// This proceeder will make the base of the building.
    polyCube -n baseSolid -ch off;
  
    hyperShade -a blinn_baseSolid;
  
     string $selected[] = `ls -sl`;
     string $temEval = "move 0 -0.5 0 "+ $selected[0] +".scalePivot "+ $selected[0] +".rotatePivot";
    eval($temEval);
    scale -a $baseWidth 0.5 $baseDepth;
    select -r |baseSolid.f[1];
    polyExtrudeFacet -ch off -ws on -ty ($baseHeight/2);
    float $inwardXScale = $baseWidth*($inwardExtrudePrecentage/100);
    float $inwardZScale = $baseDepth*($inwardExtrudePrecentage/100);
    print ($inwardXScale + "\n" + $inwardZScale +  "\n");
    polyExtrudeFacet -ch off -ws on -ty ($baseHeight/2);
  
    parentConstraint -mo |locObj_moveRotate |baseSolid;

//move most upper vertices inward.   
        //cordination for +/-values in Z direciotn will store in '$zDepthCord'.
    float $zDepthCord = ($baseDepth * $inwardExtrudePrecentage)/200;
        //cordination for +/-values in X direciotn will store in '$xWidthCord'.
    float $xWidthCord = ($baseWidth * $inwardExtrudePrecentage)/200;
        // Setting vertices inward.
    select -r |baseSolid.vtx[12];
        move -a (-$xWidthCord) 4 ($zDepthCord);
    select -r |baseSolid.vtx[13];
        move -a ($xWidthCord) 4 ($zDepthCord);
    select -r |baseSolid.vtx[14];
        move -a ($xWidthCord) 4 (-$zDepthCord);
    select -r |baseSolid.vtx[15];
        move -a (-$xWidthCord) 4 (-$zDepthCord);
  
    parent |baseSolid |skyScrapers_grp|basesGrp|baseSolidsGrp;
  
//Building 'Base Cons'.
     polyCube -n baseCon0 -ch off;
  
     hyperShade -a blinn_baseCons;
   
     string $selected[] = `ls -sl`;
     $temEval = "move 0 -0.5 0 "+ $selected[0] +".scalePivot "+ $selected[0] +".rotatePivot";
    eval($temEval);
    move ($baseWidth/2) (.5) ($baseDepth/2);
    float $conWidth;
  
    if ($baseWidth >= $baseDepth){
        $conWidth = ($baseWidth/$baseDepth);
    }
    else {
        $conWidth = ($baseDepth/$baseWidth);
    }
    scale -a (.5) (($baseHeight/2)-.2) ($conWidth-.2);

    select -tgl |skyScrapers_grp|basesGrp|baseConsGrp;
    parent;
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;

    int $x=0;
    for ($x = ($baseDepth/$conWidth); $x > 0; $x--) { //Loop
        duplicate;
        move -r 0 0 (-$conWidth);
      
        parentConstraint -mo |locObj_moveRotate `ls -sl`;
    }
    duplicate;
    rotate -r 0 90 0;
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;
  
    for ($x = ($baseWidth/$conWidth); $x > 0; $x--) { //Loop
        duplicate;
        move -r (-$conWidth) 0 0;
      
        parentConstraint -mo |locObj_moveRotate `ls -sl`;
    }
    duplicate;
    rotate -r 0 90 0;
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;
  
    for ($x = ($baseDepth/$conWidth); $x > 0; $x--) { //Loop
        duplicate;
        move -r 0 0 ($conWidth);
      
        parentConstraint -mo |locObj_moveRotate `ls -sl`;
    }
    duplicate;
    rotate -r 0 90 0;
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;
  
    for ($x = ($baseWidth/$conWidth); $x > 0; $x--) { //Loop
        duplicate;
        move -r ($conWidth) 0 0;
      
        parentConstraint -mo |locObj_moveRotate `ls -sl`;
    }
   // select -cl;
 }
 // EnD of Proceeder, Making The Base.

//************************************************************************************************
 //Proceeder for Making A Cluster.
global proc makeClusters(int $amountOfClusters, float $clusterWidth, float $clusterDepth, float $startingHeight, float $heightOfAFloor, float $amountOfFloorsPerCluster, string $hasFloorDivider, float $floorDividerHeight, float $floorDividerMidExtrudePrecentage, float $windowsPerFloorWidth, float $windowsPerFloorDepth, string $hasATop, float $topHeight, float $topInwardExtrudePrecentage, float $tipHeight) {

    float $currStartingHeight = $startingHeight;
    string $temEval;
    int $y=0;
    for ($y=$amountOfClusters; $y>0; $y--) {  
// Make Floors.
        int $x=0;
        for ($x = $amountOfFloorsPerCluster; $x > 0; $x--) {
            makeAFloor($clusterWidth, $clusterDepth, $heightOfAFloor, $windowsPerFloorWidth, $windowsPerFloorDepth, $currStartingHeight);
            $currStartingHeight += $heightOfAFloor;
        } //EnD Making Floors.
      
        // Make a Divider
        if ($hasFloorDivider == "true") {
            polyCube -n floorDivider -ch off -sy 3;
          
            hyperShade -a blinn_floorDivider;
          
            string $selected[] = `ls -sl`;
            $temEval = "move 0 -0.5 0 "+ $selected[0] +".scalePivot "+ $selected[0] +".rotatePivot";
            eval($temEval);
            move 0 ($currStartingHeight + 0.5) 0;
            scale ($clusterWidth+0.2) $floorDividerHeight ($clusterDepth+0.2);
            $currStartingHeight += $floorDividerHeight;
          
            select -tgl |skyScrapers_grp|clustersGrp|floorDividersGrp;
            parent;
          
            parentConstraint -mo |locObj_moveRotate `ls -sl`;
          
            //select -r floorDivider.f[12];
            //select -tgl floorDivider.f[5];
            //select -tgl floorDivider.f[1];
            //select -tgl floorDivider.f[9];
  
            //scale -r -.1 0 -.1;
        }
    }
    if ($hasATop == "true") {
            polyCube -n topSolid -ch off;
          
            hyperShade -a blinn_topSolid;
          
            string $selected[] = `ls -sl`;
            $temEval = "move 0 -0.5 0 "+ $selected[0] +".scalePivot "+ $selected[0] +".rotatePivot";
            eval($temEval);
            move 0 ($currStartingHeight + 0.5) 0;   
            scale ($clusterWidth-0.2) (($topHeight*10)/100) ($clusterDepth-0.2);
          
            parentConstraint -mo |locObj_moveRotate `ls -sl`;

            //string $selectedFace[] =`ls -sl`;
            select -r |topSolid.f[1];
            polyExtrudeFacet -ch off -ws on -ty ($topHeight-0.2);
      
        //move most upper vertices inward.   
                //cordination for +/-values in Z direciotn will store in '$zDepthCord'.
            float $zDepthCord = ($clusterDepth * $topInwardExtrudePrecentage)/200;
                //cordination for +/-values in X direciotn will store in '$xWidthCord'.
            float $xWidthCord = ($clusterWidth * $topInwardExtrudePrecentage)/200;
                // Setting vertices inward.
            select -r |topSolid.vtx[8];
                move -a (-$xWidthCord) ($currStartingHeight+$topHeight) ($zDepthCord);
            select -r |topSolid.vtx[9];
                move -a ($xWidthCord) ($currStartingHeight+$topHeight) ($zDepthCord);
            select -r |topSolid.vtx[10];
                move -a ($xWidthCord) ($currStartingHeight+$topHeight) (-$zDepthCord);
            select -r |topSolid.vtx[11];
                move -a (-$xWidthCord) ($currStartingHeight+$topHeight) (-$zDepthCord);
          
            parent |topSolid |skyScrapers_grp|roofTopsGrp|topSolidsGrp;
          
            $currStartingHeight += $topHeight;
          
            polyCube -n tip -ch off;
          
            hyperShade -a blinn_tip;
          
            string $selected[] = `ls -sl`;
            $temEval = "move 0 -0.5 0 "+ $selected[0] +".scalePivot "+ $selected[0] +".rotatePivot";
            eval($temEval);
            move 0 ($currStartingHeight + 0.5) 0;   
            scale ($xWidthCord/2) ($tipHeight) ($zDepthCord/2);
          
            select -tgl |skyScrapers_grp|roofTopsGrp|tipsGrp;
            parent;
          
            parentConstraint -mo |locObj_moveRotate `ls -sl`;              
     }
     parent |locObj_moveRotate |objectMoveRotateLocatorsGrp;
     select -clear;
}
// EnD of Proceeder, Making The Cluster.

//************************************************************************************************
// Proceeder Making A Floor.

global proc makeAFloor(float $floorWidth, float $floorDepth, float $floorHeight, float $windowsPerWidth, float $windowsPerDepth, float $floorStartingHeight) {
// Making wall...
     polyCube -n floorWall -ch off;
   
     hyperShade -a blinn_floorWall;
   
     string $selected[] = `ls -sl`;
     $temEval = "move 0 -0.5 0 "+ $selected[0] +".scalePivot "+ $selected[0] +".rotatePivot";
    eval($temEval);
    move -a 0 ($floorStartingHeight + 0.5) 0;
    scale -a $floorWidth $floorHeight $floorDepth;
  
    select -tgl |skyScrapers_grp|clustersGrp|floorsGrp|floorWallsGrp;
    parent;
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;
  
// End of Making wall.
//Making floor of floor...
    polyCube -n floor -ch off;
  
    hyperShade -a blinn_floor;
  
    move -a 0 ($floorStartingHeight) 0;
    scale -a ($floorWidth + 0.2) (($floorHeight*5)/100) ($floorDepth + 0.2);

    select -tgl |skyScrapers_grp|clustersGrp|floorsGrp|floorWallsGrp;
    parent;
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;
  
// EnDing Making floor of floor.

    float $widthOfAWindow = ($floorDepth - ((0.3 * $windowsPerDepth) + 0.3))/$windowsPerDepth;
    float $heightOfAWindow = $floorHeight - 0.6;
  
// Building Windows on a side...
    polyCube -n aWindow -ch off;
  
    hyperShade -a blinn_window;
  
    move -a ($floorWidth/2) ($floorStartingHeight + ($floorHeight/2)) (($floorDepth/2)-(($heightOfAWindow/2) + 0.3));
    scale -a 0.3 ($heightOfAWindow) ($widthOfAWindow);
  
    select -tgl |skyScrapers_grp|clustersGrp|floorsGrp|floorWindowsGrp;
    parent;
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;
  
    int $x=0;
    for ($x = $windowsPerDepth; $x > 1; $x--) {
        duplicate;
        move -r 0 0 (-($widthOfAWindow+0.3));
      
        parentConstraint -mo |locObj_moveRotate `ls -sl`;
    }
// Building Windows on This Side Completed.

// Building Windows on a side...
    duplicate;
    rotate -r 0 90 0;
  
    $widthOfAWindow = ($floorWidth - ((0.3 * $windowsPerWidth) + 0.3))/$windowsPerWidth;
    $heightOfAWindow = $floorHeight - 0.6;
  
    move -a (($floorWidth/2)-(($widthOfAWindow/2)+0.3)) ($floorStartingHeight + ($floorHeight/2)) ($floorDepth/2);
    scale -a 0.3 ($heightOfAWindow) ($widthOfAWindow);
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;
  
    $x=0;
    for ($x = $windowsPerWidth; $x >1; $x--) {
        duplicate;
        move -r (-($widthOfAWindow+0.3)) 0 0;
      
        parentConstraint -mo |locObj_moveRotate `ls -sl`;
    }
// Building Windows on This Side Completed.

// Building Windows on a side...
    duplicate;
    rotate -r 0 90 0;  

    $widthOfAWindow = ($floorDepth - ((0.3 * $windowsPerDepth) + 0.3))/$windowsPerDepth;
    $heightOfAWindow = $floorHeight - 0.6;
  
    move -a (-($floorWidth/2)) ($floorStartingHeight + ($floorHeight/2)) (($floorDepth/2)-(($heightOfAWindow/2) + 0.3));
    scale -a 0.3 ($heightOfAWindow) ($widthOfAWindow);
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;
  
    for ($x = $windowsPerDepth; $x > 1; $x--) {
        duplicate;
        move -r 0 0 (-($widthOfAWindow+0.3));
      
        parentConstraint -mo |locObj_moveRotate `ls -sl`;
    }
// Building Windows on This Side Completed.

// Building Windows on a side...
    duplicate;
    rotate -r 0 90 0;
  
    $widthOfAWindow = ($floorWidth - ((0.3 * $windowsPerWidth) + 0.3))/$windowsPerWidth;
    $heightOfAWindow = $floorHeight - 0.6;
  
    move -a (-(($floorWidth/2)-(($widthOfAWindow/2)+0.3))) ($floorStartingHeight + ($floorHeight/2)) (-($floorDepth/2));
    scale -a 0.3 ($heightOfAWindow) ($widthOfAWindow);
  
    parentConstraint -mo |locObj_moveRotate `ls -sl`;
  
    $x=0;
    for ($x = $windowsPerWidth; $x >1; $x--) {
        duplicate;
        move -r ($widthOfAWindow+0.3) 0 0;
      
        parentConstraint -mo |locObj_moveRotate `ls -sl`;
    }
// Building Windows on This Side Completed.

}
// EnD of Proceeder, Making A Floor.
//***************************************************************************************************************


Some possible bugs:  Windows duplicating math should be refined. I have seen some offsets of window placements with some values.
Higher File size in Hard Disk and takes a lot virtual Memory(RAM)-  I have used Maya "Parent Constraint" to parent every piece in respective building to a locator, which you will be using to move buildings. But Constraints takes a lot capacity in hard driver to save the file as well as a lot memory in RAM. So you will run out of memory after you created some buildings. So the recommended solution to get rid of this bug is; after you created and moved the building to the desired location you can delete all the 'Constraints' by - "Edit >Delete All by type > Constraints" or Select "skyScrapers_grp" group in outliner and then "Edit > Delete by type > Constraints". That will take care of your problem but you will loos the ability of moving and rotating your building.


Anyway I have thought of some solutions to get rid of above bugs but unfortunately I won't be fixing this particular script as this was only a test.

If you would like to test this script, copy and past above script in to a text editor and save it by giving "skyscrapers_builderUI.mel" as the file name in "maya\scripts" folder. (You will find "maya\scripts" folder in your documents folder) And restart Maya. In Maya 'Command Line' type "skyscrapers_builderUI" and hit 'Enter' on the keyboard. If you did everything fine you Should see following dialog box.
After you hit "Built It" button script will built your building. (Please be Patience, sometimes script takes a few seconds, maybe minutes, depending on higher values you entered, to build up meshes.). After building was made you will see a locator has been created in global 0, 0, 0 position. Select the locator and it will allow you to Move or Rotate your Building. I am afraid for this version Scaling doesn't available, but you can be clever and change the script for your need.

See you Next time...

Happy Scripting...

Rumesh Tharanga.

6 comments:

  1. Holy moly rumesh bro, i'm gonna faint (%_%) :D


    Nice Work Bro, Keep Doing :)

    ReplyDelete
  2. I have no idea what the script means! hehee but the outcome definitely looks interesting :-)

    ReplyDelete
  3. Wow...Amazing code !..but I'm not going to try it !..lol

    ReplyDelete