8
$\begingroup$

We can convert hair into 3D editable objects via the modifier tab, this means there must be an API to get the hair vertices instantly from python.

Can you explain it and all it's parameters and arguments?

I need it to start my project "Pholygonal", a polygonal hair generator controlled by the hair particle system.

$\endgroup$

1 Answer 1

14
$\begingroup$

Here is a little snippet that prints out all the coordinates of the hair vertices from the first particle system on a selected object. Make sure the object has a hair particle system.

import bpy

object = bpy.context.object
hairs = object.particle_systems[0].particles
for i, h in enumerate(hairs):
    print('hair number {i}:'.format(i=i))
    for i, hv in enumerate(h.hair_keys):
        print('  vertex {i} coordinates: {co}'.format(i=i, co=hv.co))

particle_systems[0] is used to get to the first particle system of the object. After this the particles are all the particles in the system (in this case the hairs). The hair vertices are accessed with hair_keys. Finally to get the coordinates of a hair vertex you use co.

If you want the coordinate of only one hair vertex, you could type it in one nasty line:

bpy.context.object.particle_systems[0].particles[0].hair_keys[0].co

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .