How to improve the performace for vertex normal editor

How to improve the performace for vertex normal editor

Anonymous
Not applicable
333 Views
0 Replies
Message 1 of 1

How to improve the performace for vertex normal editor

Anonymous
Not applicable
// the name of the float field
			global string $floatFieldName="";
			global string $sliderX="";
			global string $sliderY="";
			global string $sliderZ="";
			//global float $normalDirx[]={0.0, 0.0, 0.0};
			
			global string  $radio2  ;
			
			
			

global proc updateX()
{
    global string $sliderX;
     
    float $v = `floatSliderGrp -q -v $sliderX`;
     global float $normalDirx[];

 $normalDirx[0]=$v;
print("$normalDir:" + $normalDirx[0] + "\n");
}
global proc updateY()
{
    global string $sliderY;
     
    float $v = `floatSliderGrp -q -v $sliderY`;
     global float $normalDirx[];

 $normalDirx[1]=$v;
print("$normalDir:" + $normalDirx[1] + "\n");
}
global proc updateZ()
{
    global string $sliderZ;
     
    float $v = `floatSliderGrp -q -v $sliderZ`;
     global float $normalDirx[2];

 $normalDirx[2]=$v;
print("$normalDir:" + $normalDirx[2] + "\n");
}

global proc funcAdd()
{
    global float $vertexNormal[];
     global float $normalDirx[];
            string $vertex[]=`ls -sl -fl`;
            for( $vert in  $vertex)
            {
                $vertexNormal = `polyNormalPerVertex -q -xyz $vert`;
               int $size = size($vertexNormal);
    		
    		// loop through the array and print each value [for loop notes]
        		for($i=0;$i<$size;$i+=3) 
        		{
                     
                      float $new[]={$vertexNormal[$i+0]+$normalDirx[0],$vertexNormal[$i+1]+$normalDirx[1],$vertexNormal[$i+2]+$normalDirx[2]};
                      // print $vert ;
                   
                    
                   //  select $vert;
                   // polyNormalPerVertex -xyz $new[0]$new[1]$new[2];//
                     polyNormalPerVertex -xyz $new[0]$new[1]$new[2] $vert;
                   
                }
             }
          //  select -clear;
           //   for( $vert in  $vertex)
          //    {
          //      select -add $vert;
          //     }
}
global proc funcSub()
{
    global float $vertexNormal[];
     global float $normalDirx[];
            string $vertex[]=`ls -sl -fl`;
             for( $vert in  $vertex)
            {
                $vertexNormal = `polyNormalPerVertex -q -xyz $vert`;
               int $size = size($vertexNormal);
    		
    		// loop through the array and print each value [for loop notes]
        		for($i=0;$i<$size;$i+=3) 
        		{
                     
                      float $new[]={$vertexNormal[$i+0]-$normalDirx[0],$vertexNormal[$i+1]-$normalDirx[1],$vertexNormal[$i+2]-$normalDirx[2]};
                       // print $vert ;
                     select $vert;
                    polyNormalPerVertex -xyz $new[0]$new[1]$new[2];//
                   
                }
             }
             
             select -clear;
              for( $vert in  $vertex)
              {
                select -add $vert;
               }

}
global proc funcMul()
{
    global float $vertexNormal[];
     global float $normalDirx[];
            string $vertex[]=`ls -sl -fl`;
            for( $vert in  $vertex)
            {
                $vertexNormal = `polyNormalPerVertex -q -xyz $vert`;
                int $size = size($vertexNormal);
    		
    		// loop through the array and print each value [for loop notes]
        		for($i=0;$i<$size;$i+=3) 
        		{
        		     if($normalDirx[0]>0)
                    {
                         $vertexNormal[$i+0]*= $normalDirx[0];
                     }
                       if($normalDirx[1]>0)
                    {
                         $vertexNormal[$i+1]*= $normalDirx[1];
                     }
                       if($normalDirx[2]>0)
                    {
                         $vertexNormal[$i+2]*= $normalDirx[2];
                     }
                         select $vert;
                          polyNormalPerVertex -xyz $vertexNormal[0]$vertexNormal[1]$vertexNormal[2];
                   
                }
 
            }
            
            select -clear;
              for( $vert in  $vertex)
              {
                select -add $vert;
               }
}
global proc funcDiv()
{
    
     global float $normalDirx[];
            string $vertex[]=`ls -sl -fl`;
            for( $vert in  $vertex)
            {
                $vertexNormal = `polyNormalPerVertex -q -xyz $vert`;
                int $size = size($vertexNormal);
    		
    		// loop through the array and print each value [for loop notes]
        		for($i=0;$i<$size;$i+=3) 
        		{
        		     if($normalDirx[0]>0)
                    {
                         $vertexNormal[$i+0]/= $normalDirx[0];
                     }
                       if($normalDirx[1]>0)
                    {
                         $vertexNormal[$i+1]/= $normalDirx[1];
                     }
                       if($normalDirx[2]>0)
                    {
                         $vertexNormal[$i+2]/= $normalDirx[2];
                     }
                         select $vert;
                          polyNormalPerVertex -xyz $vertexNormal[0]$vertexNormal[1]$vertexNormal[2];
                   
                }
 
            }
            
            select -clear;
              for( $vert in  $vertex)
              {
                select -add $vert;
               }
}
global proc funcSet()
{
    global float $vertexNormal[];
     global float $normalDirx[];
            string $vertex[]=`ls -sl -fl`;
            for( $vert in  $vertex)
            {
                $vertexNormal = `polyNormalPerVertex -q -xyz $vert`;
       
             polyNormalPerVertex -xyz $normalDirx[0]$normalDirx[1]$normalDirx[2];
            }
}
global proc string get_radio_state(string $radio)
{
   string $selected =  `radioCollection -q -select $radio`;
   return `radioButton -q -label $selected`;
}
global proc funcApplyXYZ()
{
  global string $radio2;
    string $ss= `get_radio_state($radio2)`;
   // print $ss;
   
    if($ss=="  +  ")
    {
   
       funcAdd();
    }
    if($ss=="  -  ")
    {
   
       funcSub();
    }
    if($ss=="  X  ")
    {
   
       funcMul();
    }
    if($ss=="  /  ")
    {
   
       funcDiv();
    }
    
    
}

global proc funcX()
{
     global float $normalDirx[];
      float $x_normalDirx[]={$normalDirx[0],$normalDirx[1],$normalDirx[2]};
     $normalDirx[1]=0;
      $normalDirx[2]=0;
    funcApplyXYZ();
     $normalDirx[1]=$x_normalDirx[1];
      $normalDirx[2]=$x_normalDirx[2];
    
}
global proc funcY()
{
     global float $normalDirx[];
      float $x_normalDirx[]={$normalDirx[0],$normalDirx[1],$normalDirx[2]};
     $normalDirx[0]=0;
      $normalDirx[2]=0;
    funcApplyXYZ();
     $normalDirx[0]=$x_normalDirx[0];
      $normalDirx[2]=$x_normalDirx[2];
    
}
global proc funcZ()
{
     global float $normalDirx[];
      float $x_normalDirx[]={$normalDirx[0],$normalDirx[1],$normalDirx[2]};
     $normalDirx[1]=0;
      $normalDirx[0]=0;
    funcApplyXYZ();
     $normalDirx[1]=$x_normalDirx[1];
      $normalDirx[0]=$x_normalDirx[0];
    
}

			// window creation scoped to prevent unesseccary
			// globals being defined
			{
				window -title "FireBirdNoramlEditor" ;
			
			   columnLayout -adjustableColumn true; 
			   
			    rowLayout -numberOfColumns 2  ;
             
                button -label "AppX" -command "funcX";

     $sliderX = `floatSliderGrp  
                    -label "X"
                    -field true
                    -value 0 -min 0 -max 1
                    -s 0.05
                    -changeCommand "updateX()"
                   `;
                    setParent..;
                    
                     rowLayout -numberOfColumns 2  ;
             
                button -label "AppY" -command "funcY";
                    
       $sliderY = `floatSliderGrp  
                    -label "Y"
                    -field true
                    -value 0 -min 0 -max 1
                      -s 0.05
                    -changeCommand "updateY()"
                   `;
                   setParent..;
                    rowLayout -numberOfColumns 2  ;
             
                button -label "AppZ" -command "funcZ";
         $sliderZ = `floatSliderGrp  
                    -label "Z"
                    -field true
                    -value 0 -min 0 -max 1
                      -s 0.05
                    -changeCommand "updateZ()"
                   `;
                   setParent..;
                   
               rowLayout -numberOfColumns 4 -columnWidth4 150 150 150  150
               -columnAlign3 "center" "center" "center";
               
               $radio2 = `radioCollection`;
               
               $add  = `radioButton -label "  +  "`;
               $sub = `radioButton -label "  -  "`;
               $mul  = `radioButton -label "  X  "`;
               $div  = `radioButton -label "  /  "`;
                 
                 
                    
                    radioCollection -edit -select $add $radio2;
                   
                 setParent..;
                 
                  button -label "Apply XYZ" -command "funcApplyXYZ";
                    button -label "Use this" -command "funcSet";
     
    	//floatField -minValue -1 -maxValue 1 -value 0 -precision 4 -step .01;
		//		
						//$radio1 = `radioCollection`;
		
						// add some radio buttons to the collection
					//	$on  = `radioButton -label "On"`;
					//	$off = `radioButton -label "Off"`;
				//	window -e -width 50 -height 50 myWindow;
				showWindow ;
				 
			}

I want to edit the vertex normals ,but it is very slow when i apply the value. for example ,select 200 vertexes ,and change the normal x value ,then press the AppX button, i will take 10-20s ....very slow! any hint to improve it?no.png

0 Likes
334 Views
0 Replies
Replies (0)