@@ -76,6 +76,14 @@ public static Mesh SetXSize(this Mesh source, float min, float max)
76
76
return source . SetXSize ( min , max , Vector3 . one / 2f ) ;
77
77
}
78
78
79
+ /// <summary>
80
+ /// Sets vertices from min to max value on the x and z axis
81
+ /// </summary>
82
+ public static Mesh SetXZSize ( this Mesh source , Vector2 min , Vector2 max )
83
+ {
84
+ return source . SetXZSize ( min , max , Vector3 . one / 2f ) ;
85
+ }
86
+
79
87
/// <summary>
80
88
/// Sets vertices from min to max value on the x axis
81
89
/// </summary>
@@ -104,6 +112,38 @@ public static Mesh SetXSize(this Mesh source, float min, float max, Vector3 norm
104
112
return mesh ;
105
113
}
106
114
115
+ /// <summary>
116
+ /// Sets vertices from min to max value on the x axis
117
+ /// </summary>
118
+ public static Mesh SetXZSize ( this Mesh source , Vector2 min , Vector2 max , Vector3 normalizedCenter )
119
+ {
120
+ var mesh = source . Clone ( ) ;
121
+ var bounds = mesh . bounds ;
122
+ var vertices = mesh . vertices ;
123
+ var boundsCenter = ( bounds . min + bounds . size . Multiply ( normalizedCenter ) ) ;
124
+ // var originalLeftSize = boundsCenterX - bounds.min.x;
125
+ // var originalRightSize = bounds.max.x - boundsCenterX;
126
+
127
+ var leftOffsetX = min . x - bounds . min . x ;
128
+ var rightOffsetX = max . x - bounds . max . x ;
129
+
130
+ var leftOffsetZ = min . y - bounds . min . z ;
131
+ var rightOffsetZ = max . y - bounds . max . z ;
132
+
133
+ for ( var i = 0 ; i < vertices . Length ; i ++ )
134
+ {
135
+ var vert = vertices [ i ] ;
136
+ var x = vert . x < boundsCenter . x ? vert . x + leftOffsetX : vert . x + rightOffsetX ;
137
+ var z = vert . z < boundsCenter . z ? vert . z + leftOffsetZ : vert . z + rightOffsetZ ;
138
+ vertices [ i ] = new Vector3 ( x , vert . y , z ) ;
139
+ }
140
+
141
+ mesh . vertices = vertices ;
142
+ mesh . RecalculateBounds ( ) ;
143
+
144
+ return mesh ;
145
+ }
146
+
107
147
/// <summary>
108
148
/// Moves vertices from the center to each direction
109
149
/// </summary>
0 commit comments