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

Closed
opened 4 years ago by JoseConseco · 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)
Poster

Added subscriber: @JoseConseco

Added subscriber: @JoseConseco
Poster

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.
Collaborator

Added subscribers: @Sergey, @lichtwerk

Added subscribers: @Sergey, @lichtwerk
Sergey was assigned by lichtwerk 4 years ago
Collaborator

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 removed their assignment 4 years ago
fclem was assigned by Sergey 4 years ago
Sergey commented 4 years ago
Owner

Added subscriber: @fclem

Added subscriber: @fclem
Sergey commented 4 years ago
Owner

@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.
Poster

@fclem, any chances you could look into this?

@fclem, any chances you could look into this?

Added subscriber: @Jandals

Added subscriber: @Jandals
fclem commented 4 years ago
Collaborator

@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.
Sergey commented 4 years ago
Owner

@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.
fclem removed their assignment 4 years ago
Sergey was assigned by fclem 4 years ago
fclem commented 4 years ago
Collaborator

The crash is fixed.

The crash is fixed.
Sergey commented 4 years ago
Owner

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

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

This issue was referenced by e4df8b005f

This issue was referenced by e4df8b005fef68a58a60e277286e689cf5dbac95
Poster

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 ?
Sergey commented 4 years ago
Owner

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.
Sergey commented 4 years ago
Owner

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sergey closed this issue 4 years ago

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.
Sergey commented 1 year ago
Owner

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.
Poster

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
Sergey commented 1 year ago
Owner

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/Collada
Interest/Compositing
Interest/Core
Interest/Cycles
Interest/Dependency Graph
Interest/Development Management
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/Modeling
Interest/Modifiers
Interest/Motion Tracking
Interest/Nodes & Physics
Interest/Overrides
Interest/Performance
Interest/Performance
Interest/Physics
Interest/Pipeline, Assets & I/O
Interest/Platforms, Builds, Tests & Devices
Interest/Translations
Interest/Undo
Interest/USD
Interest/Video Sequencer
legacy module/Animation & Rigging
legacy module/Core
legacy module/Development Management
legacy module/Eevee & Viewport
legacy module/Grease Pencil
legacy module/Modeling
legacy module/Nodes & Physics
legacy module/Pipeline, Assets & IO
legacy module/Platforms, Builds, Tests & Devices
legacy module/Python API
legacy module/Rendering & Cycles
legacy module/Sculpt, Paint & Texture
legacy module/Triaging
legacy module/User Interface
legacy module/VFX & Video
legacy project/1.0.0-beta.2
legacy project/Asset Browser (Archived)
legacy project/BF Blender: 2.8
legacy project/BF Blender: After Release
legacy project/BF Blender: Next
legacy project/BF Blender: Regressions
legacy project/BF Blender: Unconfirmed
legacy project/Blender 2.70
legacy project/Code Quest
legacy project/Datablocks and Libraries
legacy project/Eevee
legacy project/Game Animation
legacy project/Game Audio
legacy project/Game Data Conversion
legacy project/Game Engine
legacy project/Game Logic
legacy project/Game Physics
legacy project/Game Python
legacy project/Game Rendering
legacy project/Game UI
legacy project/GPU / Viewport
legacy project/GSoC
legacy project/Infrastructure: Websites
legacy project/LibOverrides - Usability and UX
legacy project/Milestone 1: Basic, Local Asset Browser
legacy project/Nodes
legacy project/OpenGL Error
legacy project/Papercut
legacy project/Pose Library Basics
legacy project/Python API
legacy project/Render & Cycles
legacy project/Render Pipeline
legacy project/Retrospective
legacy project/Sculpt, Paint & Texture
legacy project/Text Editor
legacy project/Tracker Curfew
legacy project/Triaging
legacy project/User Interface
legacy project/UV Editing
legacy project/VFX & Video
legacy project/Virtual Reality
legacy project/Wintab High Frequency
Meta/Good First Issue
Meta/Papercut
migration/requires-manual-verification
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 & Devices
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 Information 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

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#64805
Loading…
There is no content yet.