]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
new feature to smooth patches
authordivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Tue, 21 Jul 2009 17:18:11 +0000 (17:18 +0000)
committerdivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Tue, 21 Jul 2009 17:18:11 +0000 (17:18 +0000)
git-svn-id: svn://svn.icculus.org/netradiant/trunk@387 61c419a2-8eb2-4b30-bcec-8cead039b335

radiant/patch.cpp
radiant/patch.h
radiant/patchmanip.cpp

index 719e2412d58763ce30858b2604bd0b8104f3f5f7..59be212ee50f6226371ccfb466be714b597758a3 100644 (file)
@@ -396,6 +396,47 @@ void Patch::Redisperse(EMatrixMajor mt)
   controlPointsChanged();
 }
 
+void Patch::Smooth(EMatrixMajor mt)
+{
+  std::size_t w, h, width, height, row_stride, col_stride;
+  PatchControl* p1, * p2, * p3;
+
+  undoSave();
+
+  switch(mt)
+  {
+  case COL:
+    width = (m_width-1)>>1;
+    height = m_height;
+    col_stride = 1;
+    row_stride = m_width;
+    break;
+  case ROW:
+    width = (m_height-1)>>1;
+    height = m_width;
+    col_stride = m_width;
+    row_stride = 1;
+    break;
+  default:
+    ERROR_MESSAGE("neither row-major nor column-major");
+    return;
+  }
+
+  for(h=0;h<height;h++)
+  {
+    p1 = m_ctrl.data()+(h*row_stride)+col_stride;
+    for(w=0;w<width-1;w++)
+    {
+      p2 = p1+col_stride;
+      p3 = p2+col_stride;
+      p2->m_vertex = vector3_mid(p1->m_vertex, p3->m_vertex);
+      p1 = p3;
+    }
+  }
+  
+  controlPointsChanged();
+}
+
 void Patch::InsertRemove(bool bInsert, bool bColumn, bool bFirst)
 {
   undoSave();
index ddbbffbd2cc4c993fa46cbe2a2038d6addfb2993..d55e712b97547e31abb39c15e4fd1e6b0eb20035 100644 (file)
@@ -973,6 +973,7 @@ public:
   void InvertMatrix();
   void TransposeMatrix();
   void Redisperse(EMatrixMajor mt);
+  void Smooth(EMatrixMajor mt);
   void InsertRemove(bool bInsert, bool bColumn, bool bFirst);
   Patch* MakeCap(Patch* patch, EPatchCap eType, EMatrixMajor mt, bool bFirst);
   void ConstructSeam(EPatchCap eType, Vector3* p, std::size_t width);
index 421290654864996c02299e81fb8e0e90c71b8cc0..af278f990b2975fac86d9eeeb03ff1bdd7f25c8e 100644 (file)
@@ -294,6 +294,24 @@ void Scene_PatchRedisperse_Selected(scene::Graph& graph, EMatrixMajor major)
   Scene_forEachVisibleSelectedPatch(PatchRedisperse(major));
 }
 
+class PatchSmooth
+{
+  EMatrixMajor m_major;
+public:
+  PatchSmooth(EMatrixMajor major) : m_major(major)
+  {
+  }
+  void operator()(Patch& patch) const
+  {
+    patch.Smooth(m_major);
+  }
+};
+
+void Scene_PatchSmooth_Selected(scene::Graph& graph, EMatrixMajor major)
+{
+  Scene_forEachVisibleSelectedPatch(PatchSmooth(major));
+}
+
 class PatchTransposeMatrix
 {
 public:
@@ -547,7 +565,7 @@ void Patch_RedisperseRows()
 {
   UndoableCommand undo("patchRedisperseRows");
 
-  Scene_PatchRedisperse_Selected(GlobalSceneGraph(), COL);
+  Scene_PatchRedisperse_Selected(GlobalSceneGraph(), ROW);
 }
 
 void Patch_RedisperseCols()
@@ -557,6 +575,20 @@ void Patch_RedisperseCols()
   Scene_PatchRedisperse_Selected(GlobalSceneGraph(), COL);
 }
 
+void Patch_SmoothRows()
+{
+  UndoableCommand undo("patchSmoothRows");
+
+  Scene_PatchSmooth_Selected(GlobalSceneGraph(), ROW);
+}
+
+void Patch_SmoothCols()
+{
+  UndoableCommand undo("patchSmoothColumns");
+
+  Scene_PatchSmooth_Selected(GlobalSceneGraph(), COL);
+}
+
 void Patch_Transpose()
 {
   UndoableCommand undo("patchTranspose");
@@ -724,6 +756,8 @@ void Patch_registerCommands()
   GlobalCommands_insert("InvertCurve", FreeCaller<Patch_Invert>(), Accelerator('I', (GdkModifierType)GDK_CONTROL_MASK));
   GlobalCommands_insert("RedisperseRows", FreeCaller<Patch_RedisperseRows>(), Accelerator('E', (GdkModifierType)GDK_CONTROL_MASK));
   GlobalCommands_insert("RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator('E', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
+  GlobalCommands_insert("SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator('W', (GdkModifierType)GDK_CONTROL_MASK));
+  GlobalCommands_insert("SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator('W', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
   GlobalCommands_insert("MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator('M', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
   GlobalCommands_insert("CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator('C', (GdkModifierType)GDK_SHIFT_MASK));
   GlobalCommands_insert("CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator('N', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
@@ -793,6 +827,11 @@ void Patch_constructMenu(GtkMenu* menu)
       menu_tearoff (menu_3);
     create_menu_item_with_mnemonic(menu_3, "Rows", "RedisperseRows");
     create_menu_item_with_mnemonic(menu_3, "Columns", "RedisperseCols");
+    GtkMenu* menu_4 = create_sub_menu_with_mnemonic (menu_in_menu, "Smooth");
+    if (g_Layout_enableDetachableMenus.m_value)
+      menu_tearoff (menu_4);
+    create_menu_item_with_mnemonic(menu_4, "Rows", "SmoothRows");
+    create_menu_item_with_mnemonic(menu_4, "Columns", "SmoothCols");
     create_menu_item_with_mnemonic(menu_in_menu, "Transpose", "MatrixTranspose");
   }
   menu_separator (menu);