Sign in to follow this  
Followers 0
JCPalmer

Particle Hair

11 posts in this topic

I have just reverse engineered what happens to a Hair particle system when it is converted to a mesh.  No matter how many "segments" you say to use when it is a particle system, you get a block of 65 vertices (for 64 segments) for each strand.

In this picture of a system with 2 strands:

straightHairs.jpg.40ea09e770d0c1b3eb364b002fbfc78a.jpg

The output looks like this (already converted to left handed):

vert: 0 location: -.7644,1.2222,-.8473
vert: 1 location: -.7644,1.2549,-.8473
vert: 2 location: -.7644,1.2904,-.8473
vert: 3 location: -.7644,1.3285,-.8473
vert: 4 location: -.7644,1.3692,-.8473
vert: 5 location: -.7644,1.4122,-.8473
...
vert: 64 location: -.7644,4.7778,-.8473
=========================================
vert: 65 location: 1.2222,.1286,.33
vert: 66 location: 1.2549,.1286,.33
vert: 67 location: 1.2904,.1286,.33
vert: 68 location: 1.3285,.1286,.33
vert: 69 location: 1.3692,.1286,.33
vert: 70 location: 1.4122,.1286,.33
...
vert: 129 location: 4.7778,.1286,.33

Clearly 65 data points for a 25,000 hairs is not going to be practical for a line system.  In this example, it only really needs 2 points per strand.  Any ideas on a way to reduce the data points between the first and last, based on some kind of straightness between sets of 3 points tolerance?

When the strands are not straight, pulling out data points are going to make them look jagged, but with enough hairs, might this not be obscured?  Especially since you are probably not going to get this close.

curls.jpg.d6037f5911e18da106322e5689fddf0f.jpg

Like most of my topics, I'll probably be talking to myself once again.

Temechon and ozRocker like this

Share this post


Link to post
Share on other sites

Think the Blender operation Limited dissolve on the converted mesh might to a nice job.  Am starting to work on a LineMesh sub-class called Hair.  It does not strictly need to be a sub-class, but it is cleaner.

In order to build a LineMesh with multiple lines, you need to know how many vertices are in each line to build the vertexData.indices. I only know where each strand begins when it it first converted ( every 65 points ).  Limited dissolve might do all the "mathy stuff" to remove many points and still look good, but now I will not know how many points are in each strand.

Fortunately, I was already planning to start my export process while it is still a particlesystem, and do the conversion to a mesh operation right in the script.  The original reason I was going to do that is so that you can still edit / comb it after export.  All that is required is to push an undo state onto the stack before the conversion, then do an undo after all the data is sucked out.

bpy.ops.ed.undo_push()
        
# find the modifier name & temporarily convert it
for mod in [m for m in mesh.modifiers if m.type == 'PARTICLE_SYSTEM']:
    bpy.ops.object.modifier_convert( modifier = mod.name )
    break
        
bmesh.ops.dissolve_limit(args)

bpy.ops.ed.undo()

If I get all the beginning points of each strand BEFORE the dissolve, I can hopefully still find them afterward (and thus know the number of points in each line).

Deltakosh likes this

Share this post


Link to post
Share on other sites

@JCPalmer; I read most of your posts - but I know if you are asking a question that there is a very good chance it will be beyond my abilities :o

Not sure what you are planning here, but I have never liked hair creation with the particle system - all that "brushing" seems rather fussy 

cheers, gryff :)

Share this post


Link to post
Share on other sites

Well, I'm through.  There is a lot of overhead to get through to adding an entire new class of geometry across systems, especially when using source code generation,.  In this 20 strand example, the 1300 vertices (20 * 65) reduce down to 418 after a built-in limited dissolve with a 5 degree angle limit (hard coded).  That is a 68% reduction, and I am very pleased with the result.  Of course, 65 verts per strand is a pretty low bar, so it is easy to improve when you suck.

This might actually work.  I am 3 days in to a 5 day test.  I have already coded a JS routine to generate skeleton single bone matrix weights.  Have not tested that, and probably going to spend the rest of the time seeing what it really can do at scale, and how good it looks.

@gryff, I have basically closed code on TOB 5.3, for QI 1.1, and am doing an experiment before moving on.  The helmet hair specimens for MakeHuman are limited, and most not really that good.  I saw a turtorial on particle hair I thought pretty good.  It spent a lot of time on what not to do, perhaps your fussing. 

I do not know how far I am going to get.  For sure, it might only going to make it into TOB.

 

Share this post


Link to post
Share on other sites

I dunno, guys.  @JohnK's fur is pretty nice.  Yeah, I'm sure it is a post-processing effect, so it has limitations, and is a bit off-topic, here. 

Still, I think it needs to be "considered" when studying feasibility, plausibility, practicality and maybe some other 'alities' and 'ilities', too.  :)

As soon as you start down-scaling the number of verts in the strand, it loses its ability to "flow in the wind" and "swish with nice bendings" during fast head-turns.

Sucks, eh?  *nod*.  Depending upon the length of the strands, I think 64 path-points is actually not near enough.  All your girl NPC's are going to expect 1024 path-points per strand... or else they won't be able to "do their hair" in the latest fashions.  :)  Women be some hair-bendin' fools, they be.  :)

Share this post


Link to post
Share on other sites
6 hours ago, JCPalmer said:

It spent a lot of time on what not to do, perhaps your fussing.

@JCPalmer ; well, Jeff, if you go to the third tutorial in that series - where he is "brushing" the hair - he admits several times that it can be "frustrating", as the hair shoots through the body. :o

Short haircuts may not be too bad - long hair you need a diploma in hair styling :lol:

Still not sure where you are going - 20 strands ? What happens with a 1000 strands, even with Limited Dissolve?

cheers, gryff :)

Share this post


Link to post
Share on other sites

20, I was only really doing 2 strands with 10 children.  Need to get working process before trying scaled test. 

Speaking of, the scene now has 1538 strands.  I do not know how it got that number.  Limited dissolve did very little, so ended up with 98,768 vertices.  That stray coming out the front is not in Blender.  This is what stuff looks like when you are bootstrapping.  I'll shortly know more.  I am only going to have one page, so it can change at any time.

I actually do not think long hair (beyond shoulder length) is any good for games, due to head turns with hair cutting thru the body.  Make human only has 3 stock male heads of hair (black, brown, & Afro).  What about bald, or old guy with just a little combed over, or facial?  To get more believable characters you need more than 3.

Wingy, I looked at fur, but not for very long.  I am doing people not dogs.  When I ran your page on an A8 Ipad Air 2, my fps dropped to the high 20's.  I have never seen a single mesh do that before.  Do not know or care what a girl NPC is.

Share this post


Link to post
Share on other sites
30 minutes ago, JCPalmer said:

I actually do not think long hair (beyond shoulder length) is any good for games, due to head turns with hair cutting thru the body.  Make human only has 3 stock male heads of hair (black, brown, & Afro).  What about bald, or old guy with just a little combed over, or facial?  To get more believable characters you need more than 3.

Ohh I agree that long hair presents issues with head turning, Jeff.

As for MakeHuman and hair, the are some contributed community assets, including a beard and moustache. And as for bald - see image below of my old friend Sholto (created a few years back for Second Life ).  The hard one would be the "combover" case.

I will follow this thread with interest :)

cheers, gryff :)

 

sholto1.png

Share this post


Link to post
Share on other sites

The saga continues.  In this episode, I found that the 65 vertex per strand conversion rate only holds when the emitter mesh is a cube. Have to find a way that always works.  Seems like when I started shapekeys.  Now after 5 generations of dev, they are really solid.

Do not think that it is going to take that amount of effort here.  I have already found if I interrogate the meshes edges array, that the edges are in order of the lines.  Each edge has 2 indices into the vertices array(which are also in order though not always in 65 per stand).  Since both are in order, there is a jump where the 2nd vert index of the previous edge is not equal to the starting vert index of the next edge.  Do not think I even need the vertices to be in order.

edges.jpg.38c579abdb27da21d7ede174a2be91cf.jpg

This is about a 3 hour rework, but I like it.  It means that the clunky method of finding all the starts before the dissolve does not need to be done.  Can open up multiple work flow possibilities, if this gets this far.  My test for success with be that the stray stand in the face will be gone.

Assuming export gets straighten out to always work, the next hurtle I think is going to be the fragment shader.  When you get enough strands, then things are just solid color.  I know you need a face / 3 points to get a normal, but could not a direction / 2 points be a way to somehow differentiate a color slightly?  @Deltakosh?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.