Page MenuHome

Python Write Access to Hair Particle Data Broken (2.8 vs. 2.79)
Closed, ResolvedPublic


System Information
Operating system: Windows-10-10.0.17763 64 Bits
Graphics card: GeForce GTX 1060/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 388.73

Blender Version
Broken: version: 2.80 (sub 74), branch: blender2.7, commit date: 2019-06-04 00:52, hash: rBc13e10a7404d
Worked: version 2.79, any build.

Short description of error
The python bindings to edit hair particle data don't appear to be working in blender 2.8. The same bindings work perfectly in blender 2.79 builds.

CONTEXT: We have been using this hair particle data editing mechanism in blender 2.79 to load Alembic hair curves and convert them to Cycles hair rendering primitives. Importing the curves in Blender creates Bezier curves which need to be tessellated in order to render in Cycles. If there is another mechanism to import Alembic curves directly into Blender as Cycles hair primitives, please let me know.

Exact steps for others to reproduce the error

  1. Load "hair_python_280.blend". In the Python console,
dg = bpy.context.evaluated_depsgraph_get()
hair = dg.objects["hair_emitter"].particle_systems["hair"]
hair.particles[0].hair_keys[0].co = Vector((5, 5, 5))

Note that I'm trying to use the new depsgraph through "evaluated_depsgraph_get()". It's interesting to see that the particle position snaps back as soon as the last bpy.ops.particle.particle_edit_toggle() is called. I suspect a python binding needs to be exposed to trigger the same scene graph update which occurs after a brush edit.

  1. For reference, using the following lines in blender 2.79 works. I'm including a file where you can try it "hair_python_279.blend".
hair =["hair_emitter"].particle_systems["hair"]
hair.particles[0].hair_keys[0].co = Vector((5, 5, 5))



Event Timeline

Cadillaxx removed a subscriber: Cadillaxx.
Sebastian Parborg (zeddb) lowered the priority of this task from Needs Triage by Developer to Confirmed, Medium.

@Sergey Sharybin (sergey), I see that you've worked on earlier today, which is very similar in spirit to this task: modifying hair particle data from Python in order to convert blender curves to hair particles. Fixing this issue would allow us to start using Blender 2.8.

Converting helps us render curves natively in Cycles. I'm interested in getting your opinion on the best way to import Alembic curves directly to hair particles (instead of Blender curves), what do you suggest? FYI, converting 300k curves to hair particles (in Blender 2.79 where it worked) is pretty slow, is there a way to set an array of particles directly from Python?

@Olivier Maury (omaury) seting particle works ok in blender now, since T64805 fix. You just have to generate comb cache that was mentioned in T64805 bug.

Thanks Jose, it does work now :)

For reference, I ended up writing a custom command in C (in particle_edit.c), transferring the curves to existing hair particles. The python route was getting unreasonably slow: We are importing Alembic caches with animated grooms, and transferring 300k curves per frames would not have been reasonable in terms of performance. Do you have any suggestions on how to do this otherwise? Maybe creating an animated hair cache externally?

Philipp Oeser (lichtwerk) closed this task as Resolved.Aug 14 2019, 1:29 PM

@Olivier Maury (omaury): I assume this can be closed now? (from reading this, all issues seem to be resolved?)

Will actually do this (closing), feel free to comment again (or reopen) if issues persist...

This comment was removed by Rhett Jackson (jandals).