Can't generate particle hair edit 'comb cache' in blender 2.8 #64805

Closed
opened 2019-05-18 18:15:24 +02:00 by Jose Conseco · 25 comments

System Information
Operating system: Windows-10-10.0.17134 64 Bits
Graphics card: GeForce GTX 660/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 416.94

Blender Version
Broken: version: 2.80 (sub 69), branch: blender2.7, commit date: 2019-05-17 23:36, hash: 03672e7783
Worked: blender 2.79

Short description of error
Can't generate particle hair edit data with simple script that goes into particle -edimode, and generates one brush stroke (worked in 2.79):

bpy.ops.particle.particle_edit_toggle()
# do 'empty' stroke to generate combing cache
bpy.ops.particle.brush_edit( 
stroke=[{"name": "", "location": (0, 0, 0), "mouse": (11, 11), "pressure": 0, "size": 0, "pen_flip": False, "time": 0, "is_start": False},
             {"name": "", "location": (0, 0, 0), "mouse": (12, 12), "pressure": 0, "size": 0, "pen_flip": False, "time": 0, "is_start": False}])
bpy.ops.particle.particle_edit_toggle()

Cache is not generate. Poll error is thrown, but same steps work if executed manually.
image.png
Exact steps for others to reproduce the error

  1. Open blend file: ParticleCache_generate.blend
  2. Run script, then execute new operator (in 3d view) with spacebar -> simple operator.
  3. Blender gives error: bpy.ops.particle.brush_edit.poll(). But user can comb hair fine, no poll error, and editmode hair cache is created ok. Only python way of generating cache fails. (I do not think python devs can generate 'groom cache' the way it is now)
**System Information** Operating system: Windows-10-10.0.17134 64 Bits Graphics card: GeForce GTX 660/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 416.94 **Blender Version** Broken: version: 2.80 (sub 69), branch: blender2.7, commit date: 2019-05-17 23:36, hash: `03672e7783` Worked: blender 2.79 **Short description of error** Can't generate particle hair edit data with simple script that goes into particle -edimode, and generates one brush stroke (worked in 2.79): ``` bpy.ops.particle.particle_edit_toggle() # do 'empty' stroke to generate combing cache bpy.ops.particle.brush_edit( stroke=[{"name": "", "location": (0, 0, 0), "mouse": (11, 11), "pressure": 0, "size": 0, "pen_flip": False, "time": 0, "is_start": False}, {"name": "", "location": (0, 0, 0), "mouse": (12, 12), "pressure": 0, "size": 0, "pen_flip": False, "time": 0, "is_start": False}]) bpy.ops.particle.particle_edit_toggle() ``` Cache is not generate. Poll error is thrown, but same steps work if executed manually. ![image.png](https://archive.blender.org/developer/F7045625/image.png) **Exact steps for others to reproduce the error** 1. Open blend file: [ParticleCache_generate.blend](https://archive.blender.org/developer/F7045627/ParticleCache_generate.blend) 2. Run script, then execute new operator (in 3d view) with spacebar -> simple operator. 3. Blender gives error: bpy.ops.particle.brush_edit.poll(). But user can comb hair fine, no poll error, and editmode hair cache is created ok. Only python way of generating cache fails. (I do not think python devs can generate 'groom cache' the way it is now)
Author

Added subscriber: @JoseConseco

Added subscriber: @JoseConseco
Author

After digging bit more.
bpy.ops.particle.brush_edit() -this can generate particle edit cache ok if we are already in particle mode.
The problem is that if we are in obj mode, and in script switch to particle_edit_toggle() ('Particle') mode, then particle.brush_edit poll fails. I tried to call despgraph.update() before particle.brush_edit but it dosen't help.

After digging bit more. bpy.ops.particle.brush_edit() -this can generate particle edit cache ok **if we are already in particle mode**. The problem is that if we are in obj mode, and in script switch to particle_edit_toggle() ('Particle') mode, then particle.brush_edit poll fails. I tried to call despgraph.update() before particle.brush_edit but it dosen't help.
Member

Added subscribers: @Sergey, @lichtwerk

Added subscribers: @Sergey, @lichtwerk
Sergey Sharybin was assigned by Philipp Oeser 2019-06-03 13:31:52 +02:00
Member

Can confirm, while polling (PE_poll, pe_get_current), psys->edit is NULL

Some findings:

  • It seems it is set up correctly in the modeswitch (particle_edit_toggle_exec):
  • edit = PE_create_current(depsgraph, scene, ob);
  • PE_create_particle_edit will also assign it to the psys: psys->edit = edit;
  • but somehow lost inbetween the particle_edit_toggle_exec and the call to bpy.ops.particle.brush_edit

(not sure if this is all relevant and not sure how much of a temporary data psys->edit really is, this might all work as expected and bug might be somewhere else...)

@Sergey: mind checking?

Can confirm, while polling (`PE_poll`, `pe_get_current`), `psys->edit` is NULL Some findings: - It seems it is set up correctly in the modeswitch (`particle_edit_toggle_exec`): - `edit = PE_create_current(depsgraph, scene, ob);` - `PE_create_particle_edit` will also assign it to the psys: `psys->edit = edit;` - but somehow lost inbetween the `particle_edit_toggle_exec` and the call to `bpy.ops.particle.brush_edit` (not sure if this is all relevant and not sure how much of a temporary data `psys->edit` really is, this might all work as expected and bug might be somewhere else...) @Sergey: mind checking?
Sergey Sharybin removed their assignment 2019-06-13 12:52:43 +02:00
Clément Foucault was assigned by Sergey Sharybin 2019-06-13 12:52:43 +02:00

Added subscriber: @fclem

Added subscriber: @fclem

@fclem, team work time!

Part of the issue is that particle system is wrongly tagged for recalc. Caused by a mistake in runtime field initialization. Can be fixed by P1002: (An Untitled Masterwork)

diff --git a/source/blender/modifiers/intern/MOD_particlesystem.c b/source/blender/modifiers/intern/MOD_particlesystem.c
index 02d477b1bde..03b6e48600d 100644
--- a/source/blender/modifiers/intern/MOD_particlesystem.c
+++ b/source/blender/modifiers/intern/MOD_particlesystem.c
@@ -186,11 +186,12 @@ static void deformVerts(ModifierData *md,
                          runtime->mesh_final->totedge != runtime->totdmedge ||
                          runtime->mesh_final->totface != runtime->totdmface)) {
     psys->recalc |= ID_RECALC_PSYS_RESET;
-    runtime->totdmvert = runtime->mesh_final->totvert;
-    runtime->totdmedge = runtime->mesh_final->totedge;
-    runtime->totdmface = runtime->mesh_final->totface;
   }
 
+  runtime->totdmvert = runtime->mesh_final->totvert;
+  runtime->totdmedge = runtime->mesh_final->totedge;
+  runtime->totdmface = runtime->mesh_final->totface;
+
   if (!(ctx->object->transflag & OB_NO_PSYS_UPDATE)) {
     struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
     psmd->flag &= ~eParticleSystemFlag_psys_updated;

However, after this is fixed i've got crash in depth drawing. Seems that DRW_draw_depth_object() expects mesh batch cache to be already allocated. However, this is not the case here: the object is tagged for geometry update when toggling particle edit mode. I guess is is where batch cache gets removed.

Operator works fine because viewport is drawn prior to stroke and that ensures all needed batch caches.

@fclem, team work time! Part of the issue is that particle system is wrongly tagged for recalc. Caused by a mistake in runtime field initialization. Can be fixed by [P1002: (An Untitled Masterwork)](https://archive.blender.org/developer/P1002.txt) ``` diff --git a/source/blender/modifiers/intern/MOD_particlesystem.c b/source/blender/modifiers/intern/MOD_particlesystem.c index 02d477b1bde..03b6e48600d 100644 --- a/source/blender/modifiers/intern/MOD_particlesystem.c +++ b/source/blender/modifiers/intern/MOD_particlesystem.c @@ -186,11 +186,12 @@ static void deformVerts(ModifierData *md, runtime->mesh_final->totedge != runtime->totdmedge || runtime->mesh_final->totface != runtime->totdmface)) { psys->recalc |= ID_RECALC_PSYS_RESET; - runtime->totdmvert = runtime->mesh_final->totvert; - runtime->totdmedge = runtime->mesh_final->totedge; - runtime->totdmface = runtime->mesh_final->totface; } + runtime->totdmvert = runtime->mesh_final->totvert; + runtime->totdmedge = runtime->mesh_final->totedge; + runtime->totdmface = runtime->mesh_final->totface; + if (!(ctx->object->transflag & OB_NO_PSYS_UPDATE)) { struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); psmd->flag &= ~eParticleSystemFlag_psys_updated; ``` However, after this is fixed i've got crash in depth drawing. Seems that `DRW_draw_depth_object()` expects mesh batch cache to be already allocated. However, this is not the case here: the object is tagged for geometry update when toggling particle edit mode. I guess is is where batch cache gets removed. Operator works fine because viewport is drawn prior to stroke and that ensures all needed batch caches.
Author

@fclem, any chances you could look into this?

@fclem, any chances you could look into this?

Added subscriber: @Jandals

Added subscriber: @Jandals

@Sergey Can you still reproduce the crash? I can't reproduce it even if I checkout the original broken commit. I did test with and without your fix but it does not change the outcome of the operator poll function.

I tried with a debug build with and without asan.

@Sergey Can you still reproduce the crash? I can't reproduce it even if I checkout the original broken commit. I did test with and without your fix but it does not change the outcome of the operator poll function. I tried with a debug build with and without asan.

@fclem, ugh, it was relying on 36faf739a7 which caused some issues and needs re-consideration.

For this specific case i think you can safely use P1018 (just don't commit it). If you can solve the crash, i can then solve the issue with unintended hair reset.

@fclem, ugh, it was relying on 36faf739a7 which caused some issues and needs re-consideration. For this specific case i think you can safely use [P1018](https://archive.blender.org/developer/P1018.txt) (just don't commit it). If you can solve the crash, i can then solve the issue with unintended hair reset.
Clément Foucault removed their assignment 2019-07-01 15:47:18 +02:00
Sergey Sharybin was assigned by Clément Foucault 2019-07-01 15:47:18 +02:00

The crash is fixed.

The crash is fixed.

Thanks! Will have a look into solving the unwanted hair reset.

Thanks! Will have a look into solving the unwanted hair reset.

This issue was referenced by e4df8b005f

This issue was referenced by e4df8b005fef68a58a60e277286e689cf5dbac95
Author

Just to be clear, I do not really care about hair combing error when switching from object mode - to particle edit mode. I just wish there was way to generate particle hair 'comb cache', so that later I can write hair_key.co to it. Maybe it would be easier to make new operator for generatig particle comb cache ?

Just to be clear, I do not really care about hair combing error when switching from object mode - to particle edit mode. I just wish there was way to generate particle hair 'comb cache', so that later I can write hair_key.co to it. Maybe it would be easier to make new operator for generatig particle comb cache ?

Well, this is a tricky call. In this case it seems it's easy to fix this particular case, especially since it's technically regression compared to 2.79. I do have D5162 which i will commit in a bit.

Well, this is a tricky call. In this case it seems it's easy to fix this particular case, especially since it's technically regression compared to 2.79. I do have [D5162](https://archive.blender.org/developer/D5162) which i will commit in a bit.

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Added subscriber: @shash29-dev

Added subscriber: @shash29-dev

Hi,
Using blender 2.91 and experiencing the same problem. Is the hair reset thing fixed?

A manual brush-stroke before toggling out of particle mode still seems to be necessary to keep the updated hair structure through a python script.
If done without the stroke, the hair structure is lost.

Hi, Using blender 2.91 and experiencing the same problem. Is the hair reset thing fixed? A manual brush-stroke before toggling out of particle mode still seems to be necessary to keep the updated hair structure through a python script. If done without the stroke, the hair structure is lost.

Is possible that the issue got re-introduced, as the particle system is a very fragile area.
Can you reproduce the issue with the steps and file from this report?

Is possible that the issue got re-introduced, as the particle system is a very fragile area. Can you reproduce the issue with the steps and file from this report?

usc_head_vtxgp.blend

system-info.txt

alpha_test.py

strands00001.txt

Adding necessary files to reproduce the error. In the .py file's last line, toggling out of particle mode does the hair reset. If 102 line is commented, the hair structure is preserved but no cache is generated until a manual stroke is done.

Running the alpha_test.py with all other attached files in the working directory reproduces the issue.

[usc_head_vtxgp.blend](https://archive.blender.org/developer/F10673579/usc_head_vtxgp.blend) [system-info.txt](https://archive.blender.org/developer/F10673575/system-info.txt) [alpha_test.py](https://archive.blender.org/developer/F10673574/alpha_test.py) [strands00001.txt](https://archive.blender.org/developer/F10673682/strands00001.txt) Adding necessary files to reproduce the error. In the .py file's last line, toggling out of particle mode does the hair reset. If 102 line is commented, the hair structure is preserved but no cache is generated until a manual stroke is done. Running the alpha_test.py with all other attached files in the working directory reproduces the issue.
Author

I just tested original script from first post and it works ok (except api change for bpy.ops.particle.brush_edit , but cache is generated correctly)

I just tested original script from first post and it works ok (except api change for bpy.ops.particle.brush_edit , but cache is generated correctly)

I don't know what I am doing wrong. From the original script also, I keep on getting poll errors on brush_edit.

Is the hair reset issue is generated in the attached example (alpha_test) by running:

blender --python alpha_test.py

Please verify

I don't know what I am doing wrong. From the original script also, I keep on getting poll errors on brush_edit. Is the hair reset issue is generated in the attached example (alpha_test) by running: ``` blender --python alpha_test.py ``` Please verify

If the initial report works fine, please submit a new bug report.

If the initial report works fine, please submit a new bug report.

Added subscriber: @sydianchen

Added subscriber: @sydianchen

@Sergey Hi, I tested script of first post in Blender 3.1 and it raised one poll error as well. Is there any chance this error could be fixed again? I simply just want to find a way to write hairkey.co.

Anyway, I solved this comb cache problem by adjusting hair using this line of code:

ob.particle_systems[0].particles[0].hair_keys[0].co_object_set(ob, ob.modifiers[0], ob.particle_systems[0].particles[0], mathutils.Vector((0, 0, 0)))

Now I can change co as I wanted.

@Sergey Hi, I tested script of first post in Blender 3.1 and it raised one poll error as well. Is there any chance this error could be fixed again? I simply just want to find a way to write hairkey.co. Anyway, I solved this comb cache problem by adjusting hair using this line of code: ``` ob.particle_systems[0].particles[0].hair_keys[0].co_object_set(ob, ob.modifiers[0], ob.particle_systems[0].particles[0], mathutils.Vector((0, 0, 0))) ``` Now I can change `co` as I wanted.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
8 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#64805
No description provided.