Search Unity

Question Parametrising Hair Grooms with the strand based hair system

Discussion in 'General Graphics' started by dav_ege, May 9, 2023.

  1. dav_ege

    dav_ege

    Joined:
    Apr 22, 2019
    Posts:
    17
    I am trying to implement hair for humanoid avatars in VR using Unity's strand based hair system.
    I created a simple groom in maya and followed this tutorial:
    https://learn.unity.com/tutorial/prepare-your-project?uv=2021.2&projectId=635a945cedbc2a39658709de

    I plan to model different grooms and import them as alembic files, however i would like to allow for some parametrisation, e.g. it would be great to be able to adjust the length of the hair in unity.

    I dont know a lot about curve modeling, but it seems like there are no native options in the hair components nor the alembic file importer. Is something like this possible, maybe using blendshapes or by somehow baking different lengths in an alembic animation (as i understand it, simulated animations is what this format was originally meant to do anyways)?
     
  2. rooose

    rooose

    Unity Technologies

    Joined:
    Jun 8, 2022
    Posts:
    30
    Hi dav_ege,

    Just to clarify, would you want to 'switch' between each groom (change directly from one variation to the other), or interpolate between them (see the hair grow or shorten progressively)?

    To interpolate, one thing to try would be to have two samples in your Alembic file, (1) the shortest variation and (2) the longest variation, and then animate the AlembicStreamPlayer time property to vary the length.

    Let me know if that helps!
     
    dav_ege likes this.
  3. dav_ege

    dav_ege

    Joined:
    Apr 22, 2019
    Posts:
    17
    The second is exactly what i meant. If i could smoothly interpolate between two styles/lengths like that, that would be perfect. I will try that out and report if it works. Thank you!
     
    rooose likes this.
  4. dav_ege

    dav_ege

    Joined:
    Apr 22, 2019
    Posts:
    17
    So i tried this out. I modified the hair groom to be slightly longer in Blender by creating and animating a Shapekey. I then exported the groom as an alembic file and imported it into Unity. However, when i attach an AlembicStreamPlayer component to my hair object (which already has a hair instance component to actually display the hair) and manipulate the time property, nothing happened. I also tried reimporting the alembic file, just specifying specific frames, but again nothing happened. I am inexpierenced when it comes the strand based hair system, or the alembic file format, so i may just misunderstand the approach, could you elaborate on how you would achieve this?
     
  5. rooose

    rooose

    Unity Technologies

    Joined:
    Jun 8, 2022
    Posts:
    30
    Hi, thanks for trying it out! After looking into this, it looks like it might be a limitation on the Hair System side. I'll investigate some more and get back to you if I find anything!
     
    dav_ege likes this.
  6. rooose

    rooose

    Unity Technologies

    Joined:
    Jun 8, 2022
    Posts:
    30
    Hi dav_ege, alembic groom assets cannot be modified at runtime without re-baking the whole thing every time there is a change. At the moment, it looks like you can only modify the length at runtime by using a procedural groom instead of an alembic groom.
     
    dav_ege likes this.
  7. dav_ege

    dav_ege

    Joined:
    Apr 22, 2019
    Posts:
    17
    Hi rooose, thank you so much for looking into that! For my intended purposes though, changing the alembic grooms in the editor whilst not at runtime would actually suffice!
    Do you think that is possible? I tried reimporting alembic files at different frames in their animation and rebuilding the hair asset, but nothing happened. I am wondering if i made a mistake when creating the alembic file or if that approach simply doesn't work.
     
  8. rooose

    rooose

    Unity Technologies

    Joined:
    Jun 8, 2022
    Posts:
    30
    Hi dav_ege,
    I think that would be possible, I will to make it work on my side to share steps on how to do it. I will get back to you once it works!
     
  9. rooose

    rooose

    Unity Technologies

    Joined:
    Jun 8, 2022
    Posts:
    30
    Hi again,

    I managed to make it work in the Editor! Basically, on the Unity side, it should be pretty straightforward.
    - Import your alembic groom
    - Make sure your alembic groom comes with an animation. If there is none, it was probably not exported properly. It should look like this: ImportResult.png

    - In the import settings, check 'Add Curve Renderer'
    - Import your groom in your scene, you should see something like this:
    alembicGroom_step1.png

    - In the scene hierarchy, select your groom. If you modify the 'Time' property in the inspector, you should see it change

    On the Maya side, I struggled a bit more to make it work. Here is what worked for me:
    - I used XGen to generate my groom
    - I worked from a collection preset that I converted to a XGen Interactive Groom. A non-interactive groom did not work. If you don't have one, you can use 'Generate > Convert to interactive groom'. If it is an option, you can also create an interactive groom directly.
    - I animated the scale property of my interactive groom rather than the length property of my initial collection
    - I used 'Generate > Cache > Create New Cache' to export my alembic cache rather than using Arnold to export (using Arnold did not work). I used the start/end setting and set it to my start and end frames.

    I don't have that much experience with Maya, so there is probably a better way to make this work, but this is what ended up working for me! Also if you need any more clarification, let me know :)