Sunday, October 30, 2011

Alpha Review



Jump to see my current code




//==================TO DO==============================//
/*
-user input check for empty footprint submission
polyUnite, group
add user config ledge
make building hollow
implement building scaling (generate more floors)
    -add multiple types

-create selection for floors+ledge via groups
-attach jobScript for scaleY
-when user scalesY, take floor height and add/subtract floors if necessary
-update the text inside numFloors
-move -r 0 -4.866739 0 test.scalePivot test.rotatePivot ; //moves pivot
-add base and roof

-pickWalk -d up; //to access an object's group
-for ( $i=0; $i < size($conds); $i++ ){

//==================TO FIX==============================//
-how to select objects in a group???? (TO FIX)
-How to manipulate Maya scale function
-update GUI when ledge changes
-add a curve as a tool
-FIX SCALING BUG

   


*/


//================== CREATE GUI ==============================//

if(`window -exists myUI`){
    deleteUI myUI; //deletes duplicate UI if it exists
    windowPref -remove myUI;
}

window -title "CIS 497: SmallTown" myUI;

tabLayout myTab;
    //BULDING CREATER TAB
    columnLayout -adjustableColumn 1 columnCreation;
        frameLayout -label "Building Attributes";
            columnLayout;
                textFieldGrp -l "Building Name:" -tx "DEFAULT_BLDG" Building_Name;
                textFieldButtonGrp -l "Foot Print:" -tx "DEFAULT_SQUARE_PLANE" -bl "Set" -buttonCommand "getSelectedFootPrint" FootPrint_Name;
            setParent ..;
        setParent ..;
        frameLayout -label "Floor Attributes" -collapsable true;
            columnLayout;
                intFieldGrp -l "# of Floors:" -v1 3 NumFloors;
                floatFieldGrp -l "Floor Height:" -v1 3 FloorHeight;
                floatFieldGrp -l "Ledge Height:" -v1 1 LedgeHeight;
                floatFieldGrp -l "Ledge Protrusion:" -v1 0.2 ledgeProtrusion;
                //ledge depth
            setParent ..;
        setParent ..;
        frameLayout -label "Window Attributes" -collapsable true;
            columnLayout;
                floatFieldGrp -l "Height Ratio:" -v1 0.8 WindowHeightRatio;
                floatFieldGrp -l "Width Ratio:" -v1 0.5 WindowWidthRatio;
            setParent ..;
        setParent ..;   
        button -l "Create" -command "createBuilding";   
    setParent ..;
   

    //COMPONENT SELECTION TAB
    columnLayout -rowSpacing 0 -adjustableColumn 1 columnSelection;
        text -label "\nClick on component type to filter them from the current selection \n";
        button -label "Floors" -command "selectComponent(\"floor\")" floorSelection;
        button -label "Ledges" -command "selectComponent(\"ledge\")" ledgeSelection;
        button -label "Windows" -command "selectComponent(\"window\")" windowSelection;
        button -label "ALL" -command "select -all" allSelection;
    setParent ..;
   
//Edit tab attributes
tabLayout -edit
    -tabLabel columnCreation "Creation"
    -tabLabel columnSelection "Selection"
myTab;

   
   
showWindow myUI; // displays the window


//=================== BUILDING CREATION ============================//

//Main method that generates the building geometry
global proc createBuilding(){
    createFootPrint();
    createFloors();
   
    //put the building in a group
    select -all;
    string $buildingGroup = `group -name building`;
   
    //move building pivot
    select -r building.scalePivot;
    move -y 0;
    select -r building;
   
    //gets the children within the group
    /*
    string $geoNodes[] = `listRelatives -children -path $buildingGroup`;
    for($n = 0; $n < size($geoNodes); $n++){
        select -add $geoNodes[$n];
        print ($geoNodes[$n] + "\n");
    }
    */


   
   
   
   
   
    scriptJob -attributeChange "building.sy" "checkY";
   
    //delete footprint after everything's been created?
    //polyUnite to unite everything?
}

//creates the floors according to user specification
global proc createFloors(){
    string $footprintName = `textFieldButtonGrp -q -tx FootPrint_Name`;
    int $numFloors = `intFieldGrp -q -v1 NumFloors`;
    float $floorHeight =`floatFieldGrp -q -v1 FloorHeight`;
    float $ledgeHeight = `floatFieldGrp -q -v1 LedgeHeight`;
    float $currentHeight = 0.0;
   
    int $i;
    for($i=0; $i<$numFloors; $i++){
        createFloor($i, $footprintName, $currentHeight, $floorHeight, $ledgeHeight);
        $currentHeight += ($floorHeight + $ledgeHeight);
    }
}

//creates a single floor starting from the specified current height
global proc createFloor(int $numFloor, string $footprint, float $startHeight, float $floorHeight, float $ledgeHeight){
    string $tempFloorName = "floor" + $numFloor;
    string $tempFloor[] = `duplicate -name $tempFloorName $footprint`;
    select -replace $tempFloor[0];
    move -relative 0 $startHeight 0;
    ConvertSelectionToFaces;
    polyExtrudeFacet -kft true -ltz $floorHeight;
    print("created: " + $tempFloorName + "\n");
   
    //create the ledge that goes above a floor (for now)
    float $ledgeProtrusion = `floatFieldGrp -q -v1 ledgeProtrusion` + 1.0;
    string $ledgeName =  "ledge" + $numFloor;
    string $tempFloor[] = `duplicate -name $ledgeName $footprint`;
    select -replace $tempFloor[0];
    float $ledgeTrans = $startHeight+$floorHeight;
    move -relative 0 $ledgeTrans 0;
    scale -relative $ledgeProtrusion $ledgeProtrusion $ledgeProtrusion; //user config later
    ConvertSelectionToFaces;
    polyExtrudeFacet -kft true -ltz $ledgeHeight;
    print("created: " + $ledgeName + "\n");
   
    //group the floor and ledge
    select -d;
    select $tempFloorName;
    select -add $ledgeName;
    string $levelName = "level" + $numFloor;
    //group -name $levelName;
    //print("grouped: " + $levelName + "\n");
   
   
    //scriptJob such that selecting a floor or ledge will select the group level it belongs to
    //scriptJob -ct "SomethingSelected" "pickWalk -d up";
}


//sets text for building footprint textbox. Assumes user only selected one object
global proc getSelectedFootPrint(){
    $selection = `ls -sl`;
    textFieldButtonGrp -edit -text $selection FootPrint_Name;
}

//establishes footprint for building
global proc createFootPrint(){
    $footprintName = `textFieldButtonGrp -q -tx FootPrint_Name`;
    if($footprintName == "DEFAULT_SQUARE_PLANE"){
        string $createdFootPrint[] = `polyPlane -ch on -o on -w 10 -h 10 -cuv 2 -name "DEFAULT_SQUARE_PLANE"`;
        select -r $createdFootPrint[0];
    }
    /*else{
        select -r $footprintName;
    }*/
    print("createFootPrint complete!!\n");
}


//=================== BUILDING SELECTION ============================//

//filters out all ledges from a user's selection
global proc selectComponent(string $name){
    string $selection[] = `ls -sl`;
   
    for( $obj in $selection){
        if( `substring $obj 1 5` != $name){
            select -d $obj;
        }
    }
}

//=================== BUILDING EDITING ============================//
global proc checkY(){
    //print("CHECK Y\n");
    int $numFloors = `intFieldGrp -q -v1 NumFloors`;
    float $floorHeight =`floatFieldGrp -q -v1 FloorHeight`;
    float $ledgeHeight = `floatFieldGrp -q -v1 LedgeHeight`;
    string $footprintName = `textFieldButtonGrp -q -tx FootPrint_Name`;
   
    float $sy = `getAttr building.sy`;
    float $currentHeight = 0.0;
    for($i=0; $i<$numFloors; $i++){
        $currentHeight += ($floorHeight + $ledgeHeight);
    }
    float $newHeight = $sy * $currentHeight;

   
   
    print("S.Y IS: " + $sy + " CURRENT HEIGHT IS: " + $currentHeight + " NEW HEIGHT IS: " + $newHeight + "\n");
   
    print("CHECK\n");
    //createFloor($numFloors, $footprintName, $newHeight, $floorHeight, $ledgeHeight);
    //add floor to building group
   
   
    //first delete everything
    for($i=0; $i<$numFloors; $i++){
        $delFloor = "floor" + $i;
        $delLedge = "ledge" + $i;
        delete $delFloor;
        delete $delLedge;
    }

   
    //then recreate everything again with the recalculated values
    $numFloors = $newHeight / ($floorHeight + $ledgeHeight); //first get the closest number of floors as an int
    $floorHeight = $newHeight / $numFloors - $ledgeHeight; //then adjust the floorHeight such that the new Height is exactly what the user specified
    $currentHeight = 0;
   
    for($i=0; $i<$numFloors; $i++){
        createFloor($i, $footprintName, $currentHeight, $floorHeight, $ledgeHeight);
        $currentHeight += ($floorHeight + $ledgeHeight);
    }
   
    //replace the values in the GUI
    intFieldGrp -edit -v1 $numFloors NumFloors;   
    floatFieldGrp -edit -v1 $floorHeight FloorHeight;   
   
    refresh;

   
   
}



















//===================OLD STUFF============================//


// Retrieves all values from the GUI and assigns them to variables
// NOT CALLED, FOR REFERENCE ONLY
global proc retrieveGUIValues(){
    //building attributes
    $buildingName = `textFieldGrp -q -tx Building_Name`;
    $footprintName = `textFieldButtonGrp -q -tx FootPrint_Name`;
   
    //floor attributes
    $numFloors = `intFieldGrp -q -v1 NumFloors`;
    $floorHeight =`floatFieldGrp -q -v1 FloorHeight`;
    $ledgeHeight = `floatFieldGrp -q -v1 LedgeHeight`;
   
    //window attributes
    $windowHeightRatio = `floatFieldGrp -q -v1 WindowHeightRatio`;
    $windowWidthRatio = `floatFieldGrp -q -v1 WindowWidthRatio`;
   
    //check
    print ("creating building named " + $buildingName + " with " + $numFloors + " floors! LOL Just Kidding! \n");

}

/*
global proc makeSimpleBuilding(int $height){
   polyPlane -name myPlane -sw 3 -sh 3;
   ConvertSelectionToFaces;
   polyExtrudeFacet -kft true -ltz $height;
}

global proc printText(){
    print "\n You have clicked me!";
}

window;
columnLayout;
    button -label "button yay" -command "printText()";
showWindow;

window;
columnLayout -adjustableColumn true;
textField -text "Enter building height" -enterCommand "makeSimpleBuilding(3)";
showWindow;
*/






No comments:

Post a Comment