How to deform mesh in runtime

Hi.
I’m trying deform mesh through move the vertex in runtime.

but ,There is a gap in the generated mesh.
Could you tell me what is wrong?

Thank you.

Here is my script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test : MonoBehaviour
{
    Mesh mesh;
    Vector3[] initeVertices;
    Vector3[] vertices;
    Vector3[] normals;
    int[] initTri;

    public int frameCount = 0;
    void Start()
    {
        mesh = GetComponent<MeshFilter>().mesh;
        initTri = mesh.triangles;
        initeVertices = mesh.vertices;
        vertices = mesh.vertices;
        normals = mesh.normals;
    }

    int count = 0;
    void Update()
    {
        count++;
      
        if (count == frameCount)
        {
            var vtx = new Vector3[vertices.Length];
            for (var i = 0; i < vertices.Length; i++)
            {
                vtx[i] = initeVertices[i] + mesh.normals[i] * Random.value * 0.001f;
            }

            mesh.vertices = vtx;
            mesh.RecalculateTangents();
            mesh.RecalculateNormals();
            mesh.RecalculateBounds();
            count = 0;
        }
    }

}

This is my seen

some info on these links,

Thank you for comment.
but I use mesh, not shader .

It was not occurred in the other modeling software.
It doesn’t work with Unity mesh.
Could you tell me advice?

In the game engine, the mesh is split along UV seams. You don’t see those split edges because normals are unified along them, but they are there. When modifying the mesh from script, you should check for pairs of vertices occupying the same coordinates, then move them together

1 Like

I’m got it !
Please bear with me for asking so many times but ,if you know How to do it efficiently, would you tell me?

Sorry , I found this thread https://answers.unity.com/questions/1382854/welding-vertices-at-runtime.html .
Thank you for helping.

1 Like