I was wondering if there is any way to make unity stop splitting vertices at uv seams… It is really frustrating, I am distorting a mesh and it just makes a massive seam in the mesh.
I have looked at the import setting lots of times and I can’t find anything…
Also, I have this script:
#pragma strict
var speed : float;
var dist : float;
private var nextChange : float;
private var verticesbackup : Vector3[];
function Start () {
verticesbackup = GetComponent(MeshFilter).mesh.vertices;
}
function Update () {
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var vertices : Vector3[] = mesh.vertices;
var normals : Vector3[] = mesh.normals;
if(Time.time > nextChange){
nextChange = Time.time+speed;
for (var i = 0; i < vertices.Length; i++) {
var random = Vector3(Random.Range(-dist,dist), verticesbackup[i].y, Random.Range(-dist,dist));
vertices[i] = Vector3.Lerp(verticesbackup[i], random, Time.deltaTime*5);
}
}
mesh.vertices = vertices;
}
It is supposed to smoothly distort the vertices, but it lacks the smooth part.
And I can’t figure out a method of making the Vector3.lerp get called every frame and not have a new position generated every frame.
If anyone can help with this I would be extremely grateful.
Firstly no you cant stop Unity making extra vertices. To solve your problem try adding the line below somewhere before the for loop to make the random number the same each time through. This wont solve your gap problem to sort that out you will need to get the distrotion amount as some function of the vertex position such as a noise function that takes a Vector 3 as an input, which is what I do for the noise modifier in MegaFiers, or build a table of values before hand checking for duplicate vertex positions.
thanks for your help, I am trying to have the random position generated for each vertex every set amount of time. The Vector3.lerp has to be called every frame or it won’t work… I think. Will this random.seed help with this?
Well I would generate an array of Vector3 the same size as the number of verts and set the values you want each point to move to in there and then use that table in your lerp call instead of calling random.
Well your lerp will not work with that as you need the last value to go from 0 to 1, your value will never do that, so you need a lerpvalue which you add Time.deltaTime to and then use Mathf.Clamp01() to keep it in the correct range. Also you dont need to fetch the vertices from the mesh every frame and you will want to call mesh.RecalculateNormals() after setting the new vertices.
#pragma strict var speed : float; var dist : float; var color : Color = color.white; var transparency : float = .1; private var nextChange : float; var verticesbackup : Vector3[ ]; var randomArray : Vector3[ ]; function Start () {
** renderer.material.SetColor(“_TintColor”, Color(color.r, color.g, color.b, transparency));**
** verticesbackup = GetComponent(MeshFilter).mesh.vertices;**
** randomArray = GetComponent(MeshFilter).mesh.vertices;** } function Update () { var mesh : Mesh = GetComponent(MeshFilter).mesh; var vertices : Vector3[ ] = mesh.vertices; var normals : Vector3[ ] = mesh.normals;
if(Time.time > nextChange){
** nextChange = Time.time+speed;**
** for (var x = 0; x < 242; x++) {**
** randomArray[×] = Vector3(Random.Range(-dist,dist), verticesbackup[×].y, Random.Range(-dist,dist));**
** }** }
for (var i = 0; i < vertices.Length; i++) { // var random = Vector3(Random.Range(-dist,dist), verticesbackup*.y, Random.Range(-dist,dist));* vertices = Vector3.Lerp(verticesbackup, randomArray_, Mathf.Clamp01(Time.deltaTime5)); } mesh.vertices = vertices; mesh.RecalculateNormals(); }[/B]* I did what you said to the best of my ability… It still only moves every few seconds… This is my first experience with modifying mesh through script… Can you be a little more specific about what I have to do? Thanks so much._
// Variables outside the update
float lerpval = 0.0f; // current lerp val
float timetolerp = 5.0f; // how long to take to lerp to new positions
// inside Update just before you for loop
lerpval += Time.deltaTime;
float lval = Mathf.Clamp01(lerpval / timetolerp);
and then use lval as the last argument of your Vector3.Lerp
Getting there, but for some reason you are now generating the lerp to values every frame. As for ending up as a small line do you set the dist value to anything?