Skip to content

Commit e50bb4e

Browse files
committed
Add apply-and-continue shortcut for clipping
Pressing Spacebar now creates a cut without exiting the Clipping Tool, which is how it behaves in Hammer
1 parent afb663d commit e50bb4e

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

game/addons/tools/Code/Scene/Mesh/Tools/ClipTool.UI.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-

2-
namespace Editor.MeshEditor;
1+
namespace Editor.MeshEditor;
32

43
partial class ClipTool
54
{
@@ -63,6 +62,9 @@ public ClipToolWidget( ClipTool tool ) : base()
6362
[Shortcut( "mesh.clip-apply", "enter", typeof( SceneViewWidget ) )]
6463
void Apply() => _tool.Apply();
6564

65+
[Shortcut( "mesh.clip-apply-stay", "space", typeof( SceneViewWidget ) )]
66+
void ApplyAndContinue() => _tool.Apply( false );
67+
6668
[Shortcut( "mesh.clip-cancel", "ESC", typeof( SceneViewWidget ) )]
6769
void Cancel() => _tool.Cancel();
6870

game/addons/tools/Code/Scene/Mesh/Tools/ClipTool.cs

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
namespace Editor.MeshEditor;
32

43
[Alias( "tools.clip-tool" )]
@@ -72,7 +71,9 @@ void CacheSelectedMeshes()
7271

7372
foreach ( var group in Selection.OfType<MeshFace>().GroupBy( f => f.Component ) )
7473
{
75-
_targets[group.Key] = (group.Key.Mesh, [.. group.Select( f => f.Handle )]);
74+
var selectedFaces = new HashSet<HalfEdgeMesh.FaceHandle>( group.Select( f => f.Handle ) );
75+
var targetFaces = selectedFaces.Count == group.Key.Mesh.FaceHandles.Count() ? null : selectedFaces;
76+
_targets[group.Key] = (group.Key.Mesh, targetFaces);
7677
}
7778
}
7879

@@ -275,12 +276,18 @@ void UpdatePoints( SceneTraceResult tr )
275276
bool CanApply => _plane.HasValue && _targets.Count > 0;
276277

277278
void Apply()
279+
{
280+
Apply( true );
281+
}
282+
283+
void Apply( bool closeTool = true )
278284
{
279285
if ( !CanApply ) return;
280286

281287
_applied = true;
282288

283289
var components = _targets.Keys.Where( x => x.IsValid() ).ToArray();
290+
var selectAllFacesAfterApply = _faceSelection && _targets.Values.Any( x => x.Faces is null );
284291

285292
_newEdges.Clear();
286293

@@ -294,7 +301,8 @@ void Apply()
294301
.WithGameObjectCreations()
295302
.Push() )
296303
{
297-
Selection.Clear();
304+
if ( closeTool || _faceSelection )
305+
Selection.Clear();
298306

299307
foreach ( var (component, data) in _targets.ToArray() )
300308
{
@@ -303,34 +311,49 @@ void Apply()
303311
if ( _faceSelection == false && KeepMode == ClipKeepMode.Both )
304312
{
305313
var newMesh = ApplyClipBoth( component, data.Faces );
306-
Selection.Add( newMesh.GameObject );
314+
if ( closeTool )
315+
Selection.Add( newMesh.GameObject );
307316
}
308317
else
309318
{
310319
ApplyClip( component, _plane.Value, KeepMode, data.Faces );
311320
}
312321

313-
if ( _faceSelection == false )
322+
if ( closeTool && _faceSelection == false )
314323
{
315324
Selection.Add( component.GameObject );
316325
}
317326
}
318327

319328
if ( _faceSelection )
320329
{
321-
foreach ( var edge in _newEdges )
330+
if ( selectAllFacesAfterApply )
322331
{
323-
if ( !edge.IsValid() )
324-
continue;
332+
foreach ( var (component, data) in _targets )
333+
{
334+
if ( !component.IsValid() || data.Faces is not null )
335+
continue;
336+
337+
foreach ( var face in component.Mesh.FaceHandles )
338+
Selection.Add( new MeshFace( component, face ) );
339+
}
340+
}
341+
else
342+
{
343+
foreach ( var edge in _newEdges )
344+
{
345+
if ( !edge.IsValid() )
346+
continue;
325347

326-
var mesh = edge.Component.Mesh;
327-
mesh.GetFacesConnectedToEdge( edge.Handle, out var faceA, out var faceB );
348+
var mesh = edge.Component.Mesh;
349+
mesh.GetFacesConnectedToEdge( edge.Handle, out var faceA, out var faceB );
328350

329-
if ( faceA.IsValid )
330-
Selection.Add( new MeshFace( edge.Component, faceA ) );
351+
if ( faceA.IsValid )
352+
Selection.Add( new MeshFace( edge.Component, faceA ) );
331353

332-
if ( faceB.IsValid )
333-
Selection.Add( new MeshFace( edge.Component, faceB ) );
354+
if ( faceB.IsValid )
355+
Selection.Add( new MeshFace( edge.Component, faceB ) );
356+
}
334357
}
335358
}
336359

@@ -339,8 +362,16 @@ void Apply()
339362
}
340363

341364
Reset();
365+
_applied = false;
342366

343-
EditorToolManager.SetSubTool( _faceSelection ? nameof( FaceTool ) : nameof( ObjectSelection ) );
367+
if ( closeTool )
368+
{
369+
EditorToolManager.SetSubTool( _faceSelection ? nameof( FaceTool ) : nameof( ObjectSelection ) );
370+
}
371+
else if ( _faceSelection )
372+
{
373+
CacheSelectedMeshes();
374+
}
344375
}
345376

346377
void Cancel()

0 commit comments

Comments
 (0)