]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/patchmanip.cpp
Auto cap button
[xonotic/netradiant.git] / radiant / patchmanip.cpp
index e42fdc37edce1823c24d8a04d838b2ee07d341cb..e7f543dc27ff71cc1f15b64081be4a4ee3cf30c0 100644 (file)
@@ -196,6 +196,34 @@ 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;