Search Unity

Question dynamic vertex position from animated alembic mesh?

Discussion in 'Asset Importing & Exporting' started by MischmeisterM, May 9, 2023.

  1. MischmeisterM


    Feb 22, 2021
    trying to read vertex positions from an animated alembic mesh, so far i've only managed to get the initial positions

    ale = GetComponent<AlembicStreamPlayer>();
    ale.CurrentTime = 5f;
    mf = GetComponentInChildren<MeshFilter>();
    Mesh mesh = mf.mesh;
    Vector3[] vertices = mesh.vertices;

    setting currentTime only works for the original meshRenderer, mesh.vertices gives initial vertex positions regardless...

    Would somehow reading directly from the MeshRenderer's VertexBuffer work or is there a less complicated solution?
  2. rooose


    Unity Technologies

    Jun 8, 2022
    Hi MischmeisterM,

    Looking at the code sample, a few things could be causing this issue. Only setting the current time does not trigger an update of the vertices - you need to call UpdateImmediately instead. Also, make sure you get the MeshFilter you want, because there might be more than one.

    Here is an updated code sample that might work:

    Code (CSharp):
    1. ale = GetComponent<AlembicStreamPlayer>();
    2. // Set current time to 5 + update animation
    3. ale.UpdateImmediately(5);
    4. // Assuming the name of the meshfilter you are looking for is `LiquidEmitter`
    5. mesh = GetComponentsInChildren<MeshFilter>().First(x => == "LiquidEmitter").mesh;
    6. Vector3[] vertices = mesh.vertices;
    (You can also use GetComponentsInChildren<MeshFilter>() to get an array of all the different meshes)

    Let me know if that helps!
    Last edited: May 10, 2023
    MischmeisterM likes this.
  3. MischmeisterM


    Feb 22, 2021
    wonderful, that's the one... apparently was looking at the wrong docs...
    much appreciated!
    thomastt_unity and rooose like this.