Page MenuHome

Cannot set hair coordinates from Python in Blender 2.8
Open, Needs Triage by DeveloperPublic

Description

System Information
Operating system: Windows-7-6.1.7601-SP1 64 Bits
Graphics card: Quadro K2200/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 385.54

Blender Version
Broken: version: 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: rBf6cb5f54494e

Short description of error
The script below creates a sphere with a hair particle system with a single hair. In Blender 2.79, I can edit the hair coordinates, but not in Blender 2.80 and later. The critical line in the script

v.co = verts[n]

where v is a hair vertex. It has no effect in Blender 2.80.

Output in Blender 2.79:
HAIR 0 5

0 (0, 0, 1) <Vector (0.0000, -0.0000, 1.0000)>
1 (0, 0, 2) <Vector (0.0000, -0.0000, 2.0000)>
2 (1, 0, 3) <Vector (1.0000, -0.0000, 3.0000)>
3 (2, 0, 3) <Vector (2.0000, -0.0000, 3.0000)>
4 (3, 0, 2) <Vector (3.0000, -0.0000, 2.0000)>

In Blender 2.80 and later:
HAIR 0 5

0 (0, 0, 1) <Vector (0.0000, 0.0000, 0.0000)>
1 (0, 0, 2) <Vector (0.0000, 0.0000, 0.0000)>
2 (1, 0, 3) <Vector (0.0000, 0.0000, 0.0000)>
3 (2, 0, 3) <Vector (0.0000, 0.0000, 0.0000)>
4 (3, 0, 2) <Vector (0.0000, 0.0000, 0.0000)>

Exact steps for others to reproduce the error

import bpy

strands = [
  [(0,0,1), (0,0,2), (1,0,3), (2,0,3), (3,0,2)]
]

bpy.ops.mesh.primitive_ico_sphere_add()
ob = bpy.context.object
bpy.ops.object.particle_system_add()
psys = ob.particle_systems.active
hlen = int(len(strands[0]))
psys.name = ("Hair%d" % hlen)

pset = psys.settings
pset.type = 'HAIR'
pset.count = int(len(strands))
pset.hair_step = hlen-1
pset.render_type = 'PATH'
pset.child_nbr = 1

bpy.ops.object.mode_set(mode='PARTICLE_EDIT')
bpy.ops.object.mode_set(mode='OBJECT')

for m,hair in enumerate(psys.particles):
    verts = strands[m]
    hair.location = verts[0]
    print("HAIR", m, len(verts))
    if len(verts) < len(hair.hair_keys):
        continue
    for n,v in enumerate(hair.hair_keys):
        # This line does not bite in Blender >= 2.80
        v.co = verts[n]
        print("  ", n, verts[n], v.co)
    pass

bpy.ops.object.mode_set(mode='PARTICLE_EDIT')
bpy.ops.object.mode_set(mode='OBJECT')

Details

Type
Bug