From 5429d1b989e1eb2ea3f9897d428a99736c926783 Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 21 Jul 2009 17:18:11 +0000 Subject: [PATCH] new feature to smooth patches git-svn-id: svn://svn.icculus.org/netradiant/trunk@387 61c419a2-8eb2-4b30-bcec-8cead039b335 --- radiant/patch.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ radiant/patch.h | 1 + radiant/patchmanip.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/radiant/patch.cpp b/radiant/patch.cpp index 719e2412..59be212e 100644 --- a/radiant/patch.cpp +++ b/radiant/patch.cpp @@ -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;hm_vertex = vector3_mid(p1->m_vertex, p3->m_vertex); + p1 = p3; + } + } + + controlPointsChanged(); +} + void Patch::InsertRemove(bool bInsert, bool bColumn, bool bFirst) { undoSave(); diff --git a/radiant/patch.h b/radiant/patch.h index ddbbffbd..d55e712b 100644 --- a/radiant/patch.h +++ b/radiant/patch.h @@ -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); diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index 42129065..af278f99 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -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(), Accelerator('I', (GdkModifierType)GDK_CONTROL_MASK)); GlobalCommands_insert("RedisperseRows", FreeCaller(), Accelerator('E', (GdkModifierType)GDK_CONTROL_MASK)); GlobalCommands_insert("RedisperseCols", FreeCaller(), Accelerator('E', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK))); + GlobalCommands_insert("SmoothRows", FreeCaller(), Accelerator('W', (GdkModifierType)GDK_CONTROL_MASK)); + GlobalCommands_insert("SmoothCols", FreeCaller(), Accelerator('W', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK))); GlobalCommands_insert("MatrixTranspose", FreeCaller(), Accelerator('M', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK))); GlobalCommands_insert("CapCurrentCurve", FreeCaller(), Accelerator('C', (GdkModifierType)GDK_SHIFT_MASK)); GlobalCommands_insert("CycleCapTexturePatch", FreeCaller(), 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); -- 2.39.2