Search Unity

Parent a Game Object to Vertex ID

Discussion in 'Scripting' started by Postjudice, Oct 21, 2014.

  1. Postjudice

    Postjudice

    Joined:
    Jan 24, 2013
    Posts:
    7
    Hello, I've tried exporting vertex constraints from maya .dae, to no avail.

    I'm trying to parent a game object to the vertex of a mesh being displaced by a procedural texture (like a boat on the ocean). I used a playmaker state machine to get vertex position and assign an object to the ID, but it doesn't follow the mesh displacement. I'm planning doing this across several subdivided planes each with their own "floating" game object.

    I'm wondering if it has something to do with the shader? Is there an easy way to do this with c#? Much appreciated for any help!

    Regards
     
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Hello! Are you moving the vertices around in the shader? I don't think you can get those positions back out from the graphics card. You can only get the vertex positions before they are sent to the graphics card.

    So if you're moving the vertices in the shader, you have to duplicate that calculation yourself or move the vertices before they go to the shader.
     
  3. Postjudice

    Postjudice

    Joined:
    Jan 24, 2013
    Posts:
    7
    HI! thanks for the reply!

    Ok, so in that case how would I store a dynamic array? would that be the collision mesh? And how to reference those point IDs?
     
  4. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    I know you can get an array of vertices from the mesh.
    http://docs.unity3d.com/ScriptReference/Mesh-vertices.html

    You should probably stop the shader from moving the vertices around and do it yourself in code. I haven't done much shader programming or worked with the Mesh class that much, so I could be wrong.
     
  5. Postjudice

    Postjudice

    Joined:
    Jan 24, 2013
    Posts:
    7
    I didn't even know that was a thing. So I would add a line in the shader that calls the mesh class? Thanks for the help, if you know of any more resources that would help me out I'd appreciate it, like an irc channel or something.

    Regards
     
  6. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Again, I'm not normally a shader or graphics programmer.

    From what I understand, once the vertex is sent to the shader, there is *no* way to get it back out. So if the shader moves the vertex, there is no way to know. You have to know the final position of the vertex BEFORE it goes to the shader.

    Maybe someone with more shader programming experience can shed some light on this issue.
     
    Last edited: Oct 22, 2014
  7. Postjudice

    Postjudice

    Joined:
    Jan 24, 2013
    Posts:
    7
    yes that would be awesome, So far I've just baked the keys in maya, i'm sad I couldn't get my truly random result in Unity.
     
  8. Postjudice

    Postjudice

    Joined:
    Jan 24, 2013
    Posts:
    7
    Just posting an update, still trying to figure this out! Is it even possible to write a CPU shader ? And I suspect using the my current shader is out of the question, so I have to start from scratch. I'm using the turbulence library on the asset store to displace my mesh. I would want a similar CPU side solution ... CPU procedurals