From: Mattia Basaglia Date: Sun, 19 Jul 2015 08:31:22 +0000 (+0200) Subject: Apply auto cap textures to make caps X-Git-Tag: xonotic-v0.8.1~1^2~5^2~1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f3e01fbe74591240f5e08ad73ce515a6b633edad;p=xonotic%2Fnetradiant.git Apply auto cap textures to make caps --- diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index e7f543dc..4dd03828 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -67,6 +67,32 @@ void Scene_PatchConstructPrefab( scene::Graph& graph, const AABB aabb, const cha } } +void PatchAutoCapTexture( Patch& patch ) { + + AABB box = patch.localAABB(); + float x = box.extents.x(); + float y = box.extents.y(); + float z = box.extents.z(); + + int cap_direction = -1; + if ( x < y && x < z ) + cap_direction = 0; + else if ( y < x && y < z ) + cap_direction = 1; + else if ( z < x && z < x ) + cap_direction = 2; + + if ( cap_direction >= 0 ) + patch.ProjectTexture(cap_direction); + else + patch.NaturalTexture(); +} + +void Patch_AutoCapTexture(){ + UndoableCommand command( "patchAutoCapTexture" ); + Scene_forEachVisibleSelectedPatch( &PatchAutoCapTexture ); + SceneChangeNotify(); +} void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){ if ( ( type == eCapEndCap || type == eCapIEndCap ) @@ -89,8 +115,10 @@ void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, co NodeSmartReference cap( g_patchCreator->createPatch() ); Node_getTraversable( instance.path().parent() )->insert( cap ); - patch.MakeCap( Node_getPatch( cap ), type, ROW, true ); - Node_getPatch( cap )->SetShader( shader ); + Patch* cap_patch = Node_getPatch( cap ); + patch.MakeCap( cap_patch, type, ROW, true ); + cap_patch->SetShader( shader ); + PatchAutoCapTexture(*cap_patch); scene::Path path( instance.path() ); path.pop(); @@ -102,8 +130,10 @@ void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, co NodeSmartReference cap( g_patchCreator->createPatch() ); Node_getTraversable( instance.path().parent() )->insert( cap ); - patch.MakeCap( Node_getPatch( cap ), type, ROW, false ); - Node_getPatch( cap )->SetShader( shader ); + Patch* cap_patch = Node_getPatch( cap ); + patch.MakeCap( cap_patch, type, ROW, false ); + cap_patch->SetShader( shader ); + PatchAutoCapTexture(*cap_patch); scene::Path path( instance.path() ); path.pop(); @@ -196,34 +226,6 @@ void Scene_PatchCapTexture_Selected( scene::Graph& graph ){ SceneChangeNotify(); } - -void PatchAutoCapTexture( Patch& patch ) { - - AABB box = patch.localAABB(); - float x = box.extents.x(); - float y = box.extents.y(); - float z = box.extents.z(); - - int cap_direction = -1; - if ( x < y && x < z ) - cap_direction = 0; - else if ( y < x && y < z ) - cap_direction = 1; - else if ( z < x && z < x ) - cap_direction = 2; - - if ( cap_direction >= 0 ) - patch.ProjectTexture(cap_direction); - else - patch.NaturalTexture(); -} - -void Patch_AutoCapTexture(){ - UndoableCommand command( "patchAutoCapTexture" ); - Scene_forEachVisibleSelectedPatch( &PatchAutoCapTexture ); - SceneChangeNotify(); -} - class PatchFlipTexture { int m_axis;