home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MACRO / UVSHADEB.M < prev    next >
Text File  |  1996-07-31  |  4KB  |  214 lines

  1. //
  2. //    法線方向を面単位で揃える
  3. //
  4. function UniformNormalVec()
  5. {
  6.     var    i, vers;
  7.     var    temp, temp_pos, temp_vec, uv[2];
  8.  
  9.     PolyLoadInit();
  10.     while( PolyLoad())
  11.     {
  12.         vers = PolyVertexs();
  13.         if( PolyType() & POLY_SHADE )
  14.         {
  15.             for( i = 0; i< vers; i++ )
  16.             {
  17.                 temp = PolyGetVertex( i );
  18.                 temp_pos = Position( temp );
  19.                 temp_vec = Vector( temp );
  20.                 Mapping( temp, uv );
  21.                 if( PolyVector().temp_vec < 0 )
  22.                 {
  23.                     temp = Vertex( temp_pos, temp_vec*(-1), uv[0], uv[1] );
  24.                     PolySetVertex( temp, i );
  25.                 }
  26.             }
  27.             PolySave();
  28.         }
  29.     }
  30. }
  31.  
  32. //
  33. //        選択範囲の境界面の法線方向を変更する
  34. //
  35. function EditNormalVecforSelect()
  36. {
  37.     var    type, msg[3], temp, temp2, temp3, points1, points2;
  38.     var    points, temp_points, new_points, uv[2];
  39.     var    prev_sel, sel1, sel2;
  40.     var    i, j;
  41.  
  42.     if( SelectPolygons() == 0 )
  43.     {
  44.         Warning();
  45.         if( MESSAGE == ON )
  46.             Message( error_msg3 );
  47.         return;
  48.     }
  49.  
  50.     DlogOpen( "選択境界の法線変更",2 );
  51.     msg[0] = "    平均化    ";
  52.     msg[1] = " 選択面に同化 ";
  53.     msg[2] = "非選択面に同化";
  54.     DlogSelect( 1, "法線修正方法", msg, 0 );
  55.     if( DlogWait())
  56.         type = DlogAnswer( 1 );
  57.     else
  58.     {
  59.         Warning();
  60.         return;
  61.     }
  62.  
  63.     prev_sel = Select();
  64.     sel1 = SelectAdjoint(Select())^prev_sel;
  65.     Select( sel1 );
  66.     points1 = VertexSelect();
  67.     Select( prev_sel );
  68.     SelectAll( TRUE, SELECT_XOR );
  69.     sel2 = SelectAdjoint(Select())&prev_sel;
  70.     Select( sel2 );
  71.     points2 = VertexSelect();
  72.     points = VertexPositionVertex( points1 ) & VertexPositionVertex( points2 );
  73.     new_points = VertexSet();
  74.     for( i = 0; i< Vertexs( points ); i++ )
  75.     {
  76.         temp = VertexGetVertex( points, i );
  77.         if( type == 0 )
  78.         {
  79.             temp_points = VertexSelectPosition( points1, temp );
  80.             temp_points = temp_points | VertexSelectPosition( points2, temp );
  81.         }
  82.         else if( type == 1 )
  83.             temp_points = VertexSelectPosition( points2, temp );
  84.         else
  85.             temp_points = VertexSelectPosition( points1, temp );
  86.  
  87.         temp2 = vector( 0, 0, 0 );
  88.         for( j = 0; j < Vertexs( temp_points ); j++ )
  89.         {
  90.             temp3 = Vector( VertexGetVertex( temp_points, j ));
  91.             if( temp2.temp3 < 0 )
  92.                 temp3 = -temp3;
  93.             temp2 += temp3;
  94.         }
  95.         temp2 = unit( temp2 )*VEC_LEN;
  96.         new_points = new_points | VertexSet(Vertex( Position( temp ), temp2 ));
  97.     }
  98.  
  99.     if( type == 0 )
  100.         sel1 = sel1 | sel2;
  101.     else if( type == 1 )
  102.         sel1 = sel1;
  103.     else
  104.         sel1 = sel2;
  105.     SelectPolyType( POLY_SHADE, TRUE, SELECT_UPDATE );
  106.     SelectPolyType( POLY_UVSHADE, TRUE, SELECT_OR );
  107.     sel1 = sel1 & Select();
  108.     Select( sel1 );
  109.     PolyLoadInit();
  110.     while( PolyLoad())
  111.     {
  112.         for( i = 0; i< PolyVertexs(); i++ )
  113.         {
  114.             temp = PolyGetVertex( i );
  115.             Mapping( temp, uv );
  116.             temp = Position( temp );
  117.             temp = VertexGetVertex( points, temp );
  118.             if( temp >= 0 )
  119.             {
  120.                 temp2 = VertexGetVertex( new_points, temp );
  121.                 PolySetVertex (Vertex( Position( temp2 ), Vector( temp2 ), uv ), i );
  122.             }
  123.         }
  124.         PolySave();
  125.     }
  126.     Select( sel1 );
  127.     UniformNormalVec();
  128.     Select( prev_sel );
  129.     Update( CLEAR, WIN_PERS );
  130.     UpdateObject();
  131. }
  132.  
  133. function SumNormalVec()
  134. {
  135. }
  136.  
  137. function SeparateNormalVec()
  138. {
  139. }
  140.  
  141.  
  142. //
  143. //    点の法線を編集する
  144. //
  145. function EditNormalVec()
  146. {
  147.     var point_temp[2];
  148.     var v, cur_vec, cur_map[2];
  149.     var j, vers, key, temp;
  150.     var pick, draw_flag = ON, plane[3];
  151.  
  152.     var    prev;
  153.     var    i;
  154.     var    prev_sel, sel, temp_sel;
  155.     var    flag;
  156.  
  157.     prev = Cursor();
  158.     if( prev != PolyVertex( prev ))
  159.     {
  160.         Warning();
  161.         if( MESSAGE == ON )
  162.             Message( error_msg1 );
  163.         return;
  164.     }
  165.  
  166.     prev_sel = Select();
  167.     SelectAll( TRUE );
  168.     SelectArea( TRUE, SELECT_AND | SELECT_SUB, prev, prev );
  169.     sel = Select();
  170.     Select( prev_sel );
  171.  
  172.     flag = FALSE;
  173.     temp_sel = sel ^ sel;
  174.     for( i = 0; i< SelectPolygons( sel ); i++ )
  175.     {
  176.         PolyLoad( sel, i );
  177.         if(( PolyType() == POLY_SHADE )|( PolyType() == POLY_UVSHADE ))
  178.             flag = TRUE;
  179.         else
  180.             temp_sel = temp_sel | SelectCurrent();
  181.     }
  182.     sel = sel ^ temp_sel;
  183.  
  184.     if( flag == FALSE )
  185.     {
  186.         Warning();
  187.         if( MESSAGE == ON )
  188.         {
  189.             Message( "法線の立っている面はありません" );
  190.         }
  191.         return;
  192.     }
  193.  
  194.     PushMenu();
  195.     Status_org = Status_title;
  196.     MenuPosition( Menu( " 動作設定(&S)",
  197.             "移動中止    ESC",    MenuQuit
  198.         ), Menu_Title );
  199.     ClearStatus();
  200.     Status_title[0] = "【法線変更中】";
  201.     DrawStatus();
  202.     quit_flag = FALSE;
  203.  
  204.  
  205.  
  206.     Select( prev_sel );
  207.     Update( CLEAR );
  208.     UpdateObject();
  209.     pers_rotation_flag = FALSE;
  210.     PopMenu();
  211.     Status_title = Status_org;
  212.     DrawStatus();
  213. }
  214.