@@ -4,12 +4,24 @@ namespace Editor.MeshEditor;
44[ Title ( "Block" ) , Icon ( "rectangle" ) ]
55public class BlockPrimitive : PrimitiveBuilder
66{
7- public bool Top { get ; set ; } = true ;
8- public bool Bottom { get ; set ; } = true ;
9- public bool Left { get ; set ; } = true ;
10- public bool Right { get ; set ; } = true ;
11- public bool Front { get ; set ; } = true ;
12- public bool Back { get ; set ; } = true ;
7+ [ Flags ]
8+ public enum Side
9+ {
10+ [ Hide ]
11+ None = 0 ,
12+
13+ Top = 1 << 0 ,
14+ Bottom = 1 << 1 ,
15+ Left = 1 << 2 ,
16+ Right = 1 << 3 ,
17+ Front = 1 << 4 ,
18+ Back = 1 << 5 ,
19+
20+ [ Hide ]
21+ All = Top | Bottom | Left | Right | Front | Back
22+ }
23+
24+ public Side Sides { get ; set ; } = Side . All ;
1325 public bool Hollow { get ; set ; } = false ;
1426
1527 [ Hide ] private BBox _box ;
@@ -32,9 +44,10 @@ public override void Build( PolygonMesh mesh )
3244 maxs = _box . Maxs ;
3345 }
3446
35- if ( Top )
47+ bool Has ( Side s ) => ( Sides & s ) != 0 ;
48+
49+ if ( Has ( Side . Top ) )
3650 {
37- // x planes - top first
3851 mesh . AddFace (
3952 new Vector3 ( mins . x , mins . y , maxs . z ) ,
4053 new Vector3 ( maxs . x , mins . y , maxs . z ) ,
@@ -43,9 +56,8 @@ public override void Build( PolygonMesh mesh )
4356 ) ;
4457 }
4558
46- if ( Bottom )
59+ if ( Has ( Side . Bottom ) )
4760 {
48- // x planes - bottom
4961 mesh . AddFace (
5062 new Vector3 ( mins . x , maxs . y , mins . z ) ,
5163 new Vector3 ( maxs . x , maxs . y , mins . z ) ,
@@ -54,9 +66,8 @@ public override void Build( PolygonMesh mesh )
5466 ) ;
5567 }
5668
57- if ( Left )
69+ if ( Has ( Side . Left ) )
5870 {
59- // y planes - left
6071 mesh . AddFace (
6172 new Vector3 ( mins . x , maxs . y , mins . z ) ,
6273 new Vector3 ( mins . x , mins . y , mins . z ) ,
@@ -65,9 +76,8 @@ public override void Build( PolygonMesh mesh )
6576 ) ;
6677 }
6778
68- if ( Right )
79+ if ( Has ( Side . Right ) )
6980 {
70- // y planes - right
7181 mesh . AddFace (
7282 new Vector3 ( maxs . x , maxs . y , maxs . z ) ,
7383 new Vector3 ( maxs . x , mins . y , maxs . z ) ,
@@ -76,9 +86,8 @@ public override void Build( PolygonMesh mesh )
7686 ) ;
7787 }
7888
79- if ( Front )
89+ if ( Has ( Side . Front ) )
8090 {
81- // x planes - farthest
8291 mesh . AddFace (
8392 new Vector3 ( maxs . x , maxs . y , mins . z ) ,
8493 new Vector3 ( mins . x , maxs . y , mins . z ) ,
@@ -87,9 +96,8 @@ public override void Build( PolygonMesh mesh )
8796 ) ;
8897 }
8998
90- if ( Back )
99+ if ( Has ( Side . Back ) )
91100 {
92- // x planes - nearest
93101 mesh . AddFace (
94102 new Vector3 ( maxs . x , mins . y , maxs . z ) ,
95103 new Vector3 ( mins . x , mins . y , maxs . z ) ,
0 commit comments