Is possible?

Dears,

My name is Bruno and I´m a student in Computer Science´s Undergraduate´s Course in Brazil. I will conclude my course at this semester and, as requested by my University, I need to present a formal work to that. I´m actually working on deformable meshes using Unity (fantastic software!), doing something similar to the “Mii System Creator”, like on Wii console.

My work is doing well in some way, “morphing” the mesh using parameters like height, pounds, strenght but I´m having serious troubles with deformable meshes (aka mesh´s vertex list) in Unity. Let´s me explain in steps:

  1. I created a script that receives the mesh (M) and a controller point (P) wich I change its position by translation on Y-axis;
  2. The script detects a raycast from P to M and define a vertex point (V) in M;
  3. So, I determine the distance (D) between V and each other vertex in M, in order to translate (by any factor) just vertex with a threshold on D.

The steps 1 to 3 are well done! The mesh M associated with the controller point P change its form (here is the deformable thing) like P translation, using some kind of equation (we are using linear transformation, but we intend to use something more robust like gaussian or Bezier - this is not a problem).

My “big trouble” appears on the 3rd step. As our algorithm works with parameters (first at all we are using just the position of P), we calculate the vertex changing on M using V and P translation. BUT, the mesh deforming is accumulating the vertex translations. We tried to save the original mesh and apply the deformable function over it, but for some reason, still accumulating the vertex translations. It´ll be better wether we just pass the deformable factor and the mesh change its shape.

I hope someone here could explain how to fix that.

Best regards!

Bruno

Hi, welcome to the forum!

When deforming a mesh, a good approach is to store a reference to the original vertex array and then replace mesh.vertices with a new array:-

var origVerts: Vector3[];
var verts: Vector3[];

function Start() {
    var mf: MeshFilter = GetComponent(MeshFilter);
    origVerts = mf.mesh.vertices;
    verts = new Vector3[origVerts.Length];
}

Then, on each update, apply the deformation to each original vertex, storing the result in the new vertex array:-

for (i = 0; i < origVerts.Length; i++) {
    var currVert = origVerts[i];
    // Deformation...
    verts[i] = currVert;
}

For the kind of thing you are doing, you will probably need to update the original vertices to show the deformation, but do this only after the user has completely finished editing a given part.

You’ve help me a lot thanks so much, it’s works. :smile: