multiple colors and speedup for particle hair ?

Issue #280 resolved
Alessandro Padovani created an issue

As for sheet hair, it would be useful to have an option to generate one particle system per hair material, so if the hair gets multiple colors we can keep them in blender. Below an example with the toulouse hair that can have strands in a different color. Scene included.

edit. On a second thought, I guess this option could be useful to line and tube hair too, if they get multiple materials. Also changed the title accordingly.

Comments (25)

  1. Alessandro Padovani reporter

    note. May be this could also be implemented by adding a “select strands by material” button, so make hair could be run for every material, adding the new particle system to the same emitter.

  2. Alessandro Padovani reporter

    important note. Thomas, I see in the blog that hair conversion is supposed to be quadratic with the number of particles. Now this is just to point out that at the daz forum there's the hair conversion tool by Cinus that works similar to the plugin but it's very fast, though with some limits. It's open source and free. May be you can look at it to get some ideas for speedup. And I'm sure Cinus will also help if you need any explanation.

    https://www.daz3d.com/forums/discussion/445851/hair-converter-add-on-for-blender/

  3. Alessandro Padovani reporter

    This is also a simple idea for speedup but I don’t know if it is doable. That is, if the complexity is quadratic with the total number of particles, then we could split the hair by strands first, that’s linear, then apply the conversion to every strand.

    split the hair by strand
    for every strand
        apply the conversion
    

    For example for number of particles nop = 1000 and number of strands nos = 10 then we have 1000**2 = 1000000 for the quadratic complexity, and 1000+(1000/10)**2 = 11000 for the splitted strands complexity.

    Please Thomas let me know what you think. I also gave a look at the hair code but that’s too complex for me so I don’t know if the idea makes sense at all.

  4. Thomas Larsson repo owner

    Alessandro, multiple hair colors is a neat idea, and it should be doable with moderate effort. At least for sheets and tubes, a problem for polyline hair is that material numbers are stored in faces in Blender, and polyline hair doesn’t have any.

    If Cinus' tool can do the job, why not use it? When I wrote that conversion is quadratic, I meant sheet hair, polylines and tubes are faster. But I haven’t clocked it. The tool does split hair by strands, the problem is that the part that takes most time is the identification of strands from unsorted faces.

    What I have noticed is that the creation of multiple hair systems can be very slow. It seems like the time for adding a new particle system is always longer than it took to add the previous one, as you can tell from the numbers printed in the terminal window. This has to be a Blender problem.

  5. Alessandro Padovani reporter

    Cinus has some limits that diffeo has not. So it was just to point it out if you may be interested to look at it for speedup. As to identify strands I was supposing for it to be linear by selecting connected vertices. Not quatratic, or at least not quadratic with the global number of particles. But I may be very well wrong.

    select a random vertex
    select connected vertices, this is one strand
    exclude the selection from the vertex set and proceed with the next
    

  6. Alessandro Padovani reporter

    As for polyline materials I did a quick test by extruding a vertex then deleting the primitive so to get a polyline. It seems the polyline gets its material in blender though there are no faces. Scene included.

  7. Alessandro Padovani reporter

    As for speedup, I did a simple test with commit 9bf3605. First I made the toulouse hair to get the global speed, then I splitted toulouse into 3 objects and made them separately. Now as expected the split speed is much faster than the global speed. We have about 35 seconds for global vs about 1+5+8 = 14 seconds for the splitted version.

    This means that something is wrong with the strand splitting. We can get so much speed by simply splitting the mesh. So the plugin could use this trick itself. Unless I miss something that may be the case since I can’t understand the hair code.

    global speed

    splitted speed

  8. Thomas Larsson repo owner

    Well, I don’t really understand the sheet hair code myself any longer, so I don’t want to touch the core code unless necessary. But the idea to split the hair mesh into separate pieces was great. The hair is now separated into disconnected strands which are converted into hair guides separately, and the speed-up is massive.

  9. Alessandro Padovani reporter

    Thomas that’s great news. As for commit fc49078 I can’t get it to work though. It seems it only generates one particle system with one strand, even if I don’t check the resize option. I suspect the plugin overwrites the old particle system with the new one so we get only the last strand. Then I just tested the Toulouse hair so may be for some reason it works with a different hair if you used another one for testing.

    As a side note, if you get it to work, may be you can merge back the geometry strands into one object after conversion. This will avoid to get thousands of objects in the scene for some hair.

  10. Thomas Larsson repo owner

    Toulouse hair was the first thing I tested with. The hair meshes are deleted at the end, so the fact that they are still there indicates that something went wrong. Please check the terminal window.

    Aha. The name of the hair mesh must not end with .00x. If you rename the hair to something that does not contain a dot then it should work. Will fix that later today.

  11. Alessandro Padovani reporter

    Nope. Tested commit 9346136 and I end up as before. The scene I use is the attached toulouse.duf with two materials, but I also tried with a default toulouse and it’s the same. Exceptionally and for the sole purpose of testing I attached the blend file. I don’t think it is a great violation of the daz eula since toulouse is distributed free by daz and it’s an old product anyway. Please let me know if I can provide any other useful data.

    tested with daz studio 4.14 and blender 2.91

    Steps

    1. Import Toulouse with the dbz option
    2. separate the scalp
    3. select first the scalp then the hair
    4. make hair with the default options

  12. Alessandro Padovani reporter

    Works like a charm. It is INSANELY FAST too. Thank you Thomas this is so great !!!

    p.s. If possible may be it’s better to keep the hair mesh instead of deleting it. To try the conversion with different settings.

    p.p.s. Any hope for multiple materials ? For polylines I believe you may be fine by splitting one mesh per material as shown in the polyline example above. You know, we’re approaching Christmas and new toys are never enough 😋.

  13. Thomas Larsson repo owner

    The name bug is fixed now, and there is an option to keep the mesh hair. Or rather to reconstruct it, by joining the strands afterwards. This probably does not maintain vertex numbers, but I cannot think of a situation where that is important. If it is, you can always make a duplicate of the hair mesh before conversion.

    I will look into multiple materials soon.

  14. Alessandro Padovani reporter

    Commit a80b311 works great. Duplicating the hair before conversion is a good idea. Many hair come with style morphs and/or pose morphs so the user may like to try different styles and conversion parameters.

  15. Alessandro Padovani reporter

    As for commit 3fbe94f it works great. One minor issue, the Multi Materials option takes into account also the “Human” materials, that’s not converted to hair so those materials are not necessary.

    Then below it's toulouse with white strands converted to hair.

  16. Thomas Larsson repo owner

    I’m not sure excluding the base material is a good idea. A human material would be a material not used by any face in the mesh, if the skalp has been separated from hair mesh. One could check for unused materials by looping over all faces before the dialog is displayed, but that may cause notable delay for large hairs, and the gain is very little IMO.

  17. Alessandro Padovani reporter

    I see that now the hair tool deletes the particle systems in the emitter if there’s any already. It would be useful if the hair tool would just add to the particle systems, without deleting. This would allow for example to split the hair mesh by material then run the tool with different colors and resize options. Or in general to split the hair by any user need then run the tool with different parameters for each part. So this would be more flexible for hair creation.

    Please Thomas let me know what you think, I’ll mark as resolved anyway since the actual implementation is quite good already.

  18. Alessandro Padovani reporter

    I see commit 9517708 adds an option to keep the old particle systems in the emitter. It works great so I'm marking as resolved.

  19. Log in to comment