x


How to pose vertices.

Well I want my mesh - plane should swim over water surface as paper. For that i would like modify position of mesh vertices, but my script doesn't work (

function Start(){
    thisMatrix = transform.localToWorldMatrix;

    mesh= GetComponent(MeshFilter).mesh;
    vertices = mesh.vertices;

}

function Update(){

        for (var i = 0; i < vertices.Length; i++){

           Mypos = thisMatrix.MultiplyPoint3x4(vertices[i]);
           Mypos.y+=20;

           if (Physics.Raycast (Mypos, -Vector3.up,hit, 30)) {
             print(hit.point);
             vertices[i] = hit.point;        
           }
           mesh.vertices = vertices;
           mesh.RecalculateBounds();
        }

    }
more ▼

asked Feb 11 '12 at 05:42 PM

2dkot gravatar image

2dkot
76 15 21 28

Any suggestion?

Feb 12 '12 at 12:16 PM 2dkot

as far I understand I should convert world coordinates to mesh vertices coordinates or something...

Feb 12 '12 at 12:36 PM 2dkot
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Found solution:

I needed transform.worldToLocalMatrix to transform

world coordinates to local mesh coordinates. this whole script:

var mesh : Mesh;
var vertices : Vector3[];
var Mypos:Vector3;
var Mypos1:Vector3;
var hit : RaycastHit;
var thisMatrix: Matrix4x4;
var meshMatrix:Matrix4x4;


function Start(){
    thisMatrix = transform.localToWorldMatrix;
    meshMatrix = transform.worldToLocalMatrix;

    mesh= GetComponent(MeshFilter).mesh;
    vertices = mesh.vertices;

}

function Update(){


    for (var i = 0; i < vertices.Length; i++){

       Mypos = thisMatrix.MultiplyPoint3x4(vertices[i]);
       Mypos.y+=100;

       if (Physics.Raycast (Mypos, -Vector3.up,hit, 120)) {
       Mypos = meshMatrix.MultiplyPoint3x4(hit.point;);
       vertices[i] = Mypos;        
       }

    }
       mesh.vertices = vertices;
       mesh.RecalculateBounds();
}
more ▼

answered Feb 12 '12 at 12:49 PM

2dkot gravatar image

2dkot
76 15 21 28

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x139

asked: Feb 11 '12 at 05:42 PM

Seen: 429 times

Last Updated: Feb 12 '12 at 12:49 PM