@@ -69,60 +69,32 @@ public static Mesh ExtendMesh(this Mesh source, Vector3 minExtends, Vector3 maxE
69
69
}
70
70
71
71
/// <summary>
72
- /// Sets vertices that are bigger than center x size
72
+ /// Sets vertices from min to max value on the x axis
73
73
/// </summary>
74
- public static Mesh SetXSizeRight ( this Mesh source , float size )
74
+ public static Mesh SetXSize ( this Mesh source , float min , float max )
75
75
{
76
- return source . SetXSizeRight ( size , Vector3 . one / 2f ) ;
76
+ return source . SetXSize ( min , max , Vector3 . one / 2f ) ;
77
77
}
78
78
79
79
/// <summary>
80
- /// Sets vertices that are bigger than center x size
80
+ /// Sets vertices from min to max value on the x axis
81
81
/// </summary>
82
- public static Mesh SetXSizeRight ( this Mesh source , float size , Vector3 normalizedCenter )
82
+ public static Mesh SetXSize ( this Mesh source , float min , float max , Vector3 normalizedCenter )
83
83
{
84
84
var mesh = source . Clone ( ) ;
85
85
var bounds = mesh . bounds ;
86
86
var vertices = mesh . vertices ;
87
- var boundsCenter = bounds . min + bounds . size . Multiply ( normalizedCenter ) ;
88
- var offset = size - bounds . size . x ;
89
-
90
- for ( var i = 0 ; i < vertices . Length ; i ++ )
91
- {
92
- var vert = vertices [ i ] ;
93
- var x = vert . x < boundsCenter . x ? vert . x - offset : vert . x ;
94
- vertices [ i ] = new Vector3 ( x , vert . y , vert . z ) ;
95
- }
87
+ var boundsCenterX = ( bounds . min + bounds . size . Multiply ( normalizedCenter ) ) . x ;
88
+ // var originalLeftSize = boundsCenterX - bounds.min.x;
89
+ // var originalRightSize = bounds.max.x - boundsCenterX;
96
90
97
- mesh . vertices = vertices ;
98
- mesh . RecalculateBounds ( ) ;
99
-
100
- return mesh ;
101
- }
102
-
103
- /// <summary>
104
- /// Sets vertices that are bigger than center x size
105
- /// </summary>
106
- public static Mesh SetXSizeLeft ( this Mesh source , float size )
107
- {
108
- return source . SetXSizeLeft ( size , Vector3 . one / 2f ) ;
109
- }
110
-
111
- /// <summary>
112
- /// Sets vertices that are bigger than center x size
113
- /// </summary>
114
- public static Mesh SetXSizeLeft ( this Mesh source , float size , Vector3 normalizedCenter )
115
- {
116
- var mesh = source . Clone ( ) ;
117
- var bounds = mesh . bounds ;
118
- var vertices = mesh . vertices ;
119
- var boundsCenter = bounds . min + bounds . size . Multiply ( normalizedCenter ) ;
120
- var offset = size - bounds . size . x ;
91
+ var leftOffset = min - bounds . min . x ;
92
+ var rightOffset = max - bounds . max . x ;
121
93
122
94
for ( var i = 0 ; i < vertices . Length ; i ++ )
123
95
{
124
96
var vert = vertices [ i ] ;
125
- var x = vert . x > boundsCenter . x ? vert . x + offset : vert . x ;
97
+ var x = vert . x < boundsCenterX ? vert . x + leftOffset : vert . x + rightOffset ;
126
98
vertices [ i ] = new Vector3 ( x , vert . y , vert . z ) ;
127
99
}
128
100
0 commit comments