Search Unity

manipulating vertex

Discussion in 'Scripting' started by raymix, Sep 19, 2011.

  1. raymix

    raymix

    Joined:
    Aug 25, 2010
    Posts:
    192
    Hello Unity community,
    I'm here to ask simple question - how to find and manipulate specific vertex of a 3D object?

    To make question even simpler - Imagine box with 4 vertices. How do i manipulate one of top ones?
    All i ask for is where to look at. Not asking how to rotate or move them, just how to find desired vertex and do stuff to it.

    Thanks in advance
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
  3. raymix

    raymix

    Joined:
    Aug 25, 2010
    Posts:
    192
    It's not really answering the question, but thanks... i guess.
    Ofcourse i did go trough all the documentation, but it does not mean i actually understood it.

    Question still remains simple - how to find specific 1 out of 8 vertexes on a cube so i can manipulate it later.

    I could tell unity to show me all vertices in an array and do stuff to them, but how do i tell it to take exact vertex i want? Lets say using
    Print (thatParticularVertexOnTopOfCube);
    doStuffToIT();
     
  4. scarpelius

    scarpelius

    Joined:
    Aug 19, 2007
    Posts:
    966
    Your question have the answer in it (providing you read closely the page Jessy indicated). The most top vertex on an object should hold also the highest y value.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Note that a cube, if the normals are correct, has 24 vertices, not 8.

    --Eric
     
  6. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Probably. You could have one with a non-tiling, static normal map, for a non-skinned cube, and have the texture "bend" the normals back to where they would be, if you had "hard edges". (An object space normal map would be faster than a tangent space one for this mesh, and yield identical results, if it were baked properly.) I haven't learned enough about normal map baking yet to try this, but I bet the 24 verts approach would yield better results far away, do to mipmapping.
     
    Last edited: Sep 20, 2011
  7. raymix

    raymix

    Joined:
    Aug 25, 2010
    Posts:
    192
    Ok, think I know what you mean by highest value. Well, that makes it.. harder, but should work the trick. Was hoping Unity engine is somehow numerating or naming them like most of 3D modeling software.

    Also i was debugging vertex count on cube, log said it's 24, I got confused and came to forums for help.

    Now, after a bit of googling, i found out the answer to that. I always thought vertices can be shared trough faces connected to it, apparently not. If cube has 6 faces, each of them consists of 4 vertices. Multiplied together it makes 24. Basically this means that there are 3 vertices in the same point in 3D space all the time, included in calculations of graphics card. What a waste of calculations, making GPU calculate same vertex over and over again multiplied by faces connected to it.. meh

    anyway thanks for answers, think i'll be fine for now.

    edit: however, unusual and probably simple question - Batching:
    If i have 100 cubes out, Batched they are only doing 1 draw call since all are same
    What if i changed vertex position of one of boxes, making it look .. different. Would that now batch 99 boxes and make 2 draw calls instead, despite being same model and same material?
     
    Last edited: Sep 20, 2011
  8. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    It's not a waste; you get one normal per vertex, and you need three normals in the same place at every vertex on a hard cube. So, 8 vertices, multiplied by 3: 24. 6 faces x 4 vertices makes sense to a person, but that's not how the GPU sees it, which is what you actually need to worry about, in terms of vert count. You can have a cube with 8 vertices, but unless you have a normal map, the likes of which I was talking about, the lighting on it is going to make it resemble a "very blocky sphere".
     
    Last edited: Sep 20, 2011