x


drawing vertices

I'm drawing vertices in the editor as gizmo spheres however the positions are always stationary, never moving when I adjust the position or scale of the object it's attached to. Is there something I'm missing?

void OnDrawGizmosSelected () {

    MeshFilter selectedMeshFilter = (MeshFilter)gameObject.GetComponent("MeshFilter");
    Mesh mesh = selectedMeshFilter.mesh;
    Vector3[] vertices  = mesh.vertices;
    Color[] colors = new Color[vertices.Length];

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

        Gizmos.DrawSphere (vertices[i], vertexSize);

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

}
more ▼

asked Aug 31 '10 at 12:50 AM

reissgrant gravatar image

reissgrant
246 14 15 25

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Yes. The Transform component equates to a matrix that gets applied to vertex data. Changing values in the Transform will not update the vertices array of a mesh, nor would you want it to. Instead, use Matrix4x4.TRS, with the values from the Transform, and apply that to the vertices array that you get.

more ▼

answered Aug 31 '10 at 01:27 AM

Jessy gravatar image

Jessy
15.6k 72 95 196

Thanks, this makes sense.

Aug 31 '10 at 01:32 AM reissgrant
(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
x137

asked: Aug 31 '10 at 12:50 AM

Seen: 1183 times

Last Updated: Aug 31 '10 at 12:50 AM