Skip to content

Commit 065f915

Browse files
committed
Updating change mesh size
1 parent 38e3344 commit 065f915

File tree

1 file changed

+11
-39
lines changed

1 file changed

+11
-39
lines changed

Scripts/Extensions/MeshExtensions.cs

+11-39
Original file line numberDiff line numberDiff line change
@@ -69,60 +69,32 @@ public static Mesh ExtendMesh(this Mesh source, Vector3 minExtends, Vector3 maxE
6969
}
7070

7171
/// <summary>
72-
/// Sets vertices that are bigger than center x size
72+
/// Sets vertices from min to max value on the x axis
7373
/// </summary>
74-
public static Mesh SetXSizeRight(this Mesh source, float size)
74+
public static Mesh SetXSize(this Mesh source, float min, float max)
7575
{
76-
return source.SetXSizeRight(size, Vector3.one/2f);
76+
return source.SetXSize(min, max, Vector3.one / 2f);
7777
}
7878

7979
/// <summary>
80-
/// Sets vertices that are bigger than center x size
80+
/// Sets vertices from min to max value on the x axis
8181
/// </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)
8383
{
8484
var mesh = source.Clone();
8585
var bounds = mesh.bounds;
8686
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;
9690

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;
12193

12294
for (var i = 0; i < vertices.Length; i++)
12395
{
12496
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;
12698
vertices[i] = new Vector3(x, vert.y, vert.z);
12799
}
128100

0 commit comments

Comments
 (0)