- Home /
 
The question is answered, right answer was accepted
mesh-morph scaling badly
EDIT, i have kindof figured out what is happening, when i change the object scale to (.1,1,1), the vertex positions for x are being changed flat. so i am losing the morph settings for that axis. i have to take the object scale into account in the vertex morph settings and it should be the same in all axes.
I thought that because I was using global positioning with transform.TransformPoint then the vertex is will morph relative to global position, but that's wrong.
Here is a picture and the code: 
 private var org = Vector3.zero; 
 var scale = 1;
 private var vtxArray : Vector3[];
 var radius = 200;
 
 function Start () {
     var mesh : Mesh = GetComponent(MeshFilter).mesh;
     
     if (vtxArray == null)
         vtxArray = mesh.vertices;
     
     var vertices = new Vector3[vtxArray.Length];
     for (var i=0;i<vertices.Length;i++)
     {
         var vertex = vtxArray[i];
 
         vtxArray[i] =  transform.TransformPoint(vtxArray[i]);
         vertex.y += Mathf.Sin(vtxArray[i].z*.1 + vtxArray[i].x*.1) * scale;
         vertex.x += Mathf.Sin(vtxArray[i].y*.1 + vtxArray[i].z*.2) * scale;
         vertex.z += Mathf.Sin(vtxArray[i].x*.1 + vtxArray[i].y*.1) * scale;
 
         vertices[i] = vertex;
     }
     mesh.vertices = vertices;
     mesh.RecalculateNormals();
     
     DestroyImmediate(collider);
     gameObject.AddComponent("MeshCollider");
 }
 
              Answer by MountDoomTeam · Nov 02, 2012 at 04:52 PM
the problem is the scale of the objects, setting vertex mutations using TransformPoint will be scaled back relative to the objects scale, so if you really want to apply a global scale morph, you have to counter the objects scale settings.
Follow this Question
Related Questions
Generate mesh from raycast positions, independent of rotations 0 Answers
Do I need to split my mesh up to properly UV texture it? 1 Answer
How do you scale a sphere or object by 2x using Mesh.vertices 2 Answers
MeshCollider is not getting updated when adding vertex to mesh 1 Answer
Easy way to convert a bunch of vertices to triangles or uv's? 1 Answer