Mirror modifier and hair disconnect/reconnect not working together
Open, ConfirmedPublic


System Information
Linux (Arch), GTX 1080

Blender Version
2.79b f4dc9f9d68b

Short description of error

When using a hair particle system on an object with a mirror modifier, and trying to disconnect and then reconnect the hair the particle positions are messed up.

Exact steps for others to reproduce the error

  • create a cube object
  • add a mirror modifier with merge and clipping options enabled (it seems to happen in the same way with separated mirrored cubes also, though)
  • add a hair particle system to the object

  • comb hair in particle edit mode

  • disconnect and reconnect particle system

  • enable 'Simple' children in particle system settings and disable them again

More Info

  • After the steps done for the first and second blend files everything looks good. Adding a particle system and particle edit on a mirror object seems to work.
  • But disconnecting and reconnecting has the (immediately to be seen) effect of moving all the hair from the 'mirrored' (right) part of the object to the rightmost end of the left part, as shown in the third blend file
  • Enabling and disabling children shows that in addition to that problem the particle system data seems to have been messed up further by the disconnect/reconnect, as after that last step the hair positions are completely messed up.


Brecht Van Lommel (brecht) triaged this task as Confirmed priority.EditedMay 28 2018, 2:00 PM

The problem here is that the "Use Modifier Stack" setting is not properly taken into account for these disconnect/reconnect operators.

Hi @Brecht Van Lommel (brecht), @omgold (omgold), I've seen you discuss this on the mailinglist (and I understand reaching out here as for some reason this report seemed to slip under the radar)
But: why not continue here? This way others (including me) can follow and participate much better.
Sorry for the wall of text, but pasting from the mailinglist, so it doesnt get lost...


thanks you very much for taking the time to explain.

After more checking of the behavior with or without using dm_deformed, I understand things somewhat better.

  • I believe what you mean with 'use modifier stack' in combination with subsurf not working well is, that generative modifiers garble the face indices, so changes like switching the modifiers on/off or changing subdivision level will result in the hair >being a complete mess. Correct?
  • What surprised me a little, though, was that disconnect/reconnect will result in garbage also in the presence of generative modifiers, *without* 'use modifier stack' enabled. E.g. for subsurf the hair will be attached at the location of the original >mesh, leaving a gap.
  • I found, when using dm_final instead of dm_deformed, both with and without 'use modifier stack', the hairs are placed nicely after a reconnect, but in both cases, they seem not to be attached correctly. This will only become visible after deforming >or moving geometry around.
  • Only got a rough understanding about the latter problem. The culprit seems to be this:

    tpa->num_dmcache = psys_particle_dm_face_lookup(target_dm, dm, tpa->num, tpa->fuv, NULL);

    As far as I get it, psys_particle_dm_face_lookup() doesn't do the right thing then. The other place, where this is used, psys_calc_dmcache() in source/blender/blenkernel/intern/particle_system.c, seem to have a special treatment for the case of >'use modifier stack' enabled.

Best regards,

>By default for hair, it is attached to the original mesh before modifier
>stack evaluation, referencing one of the faces in the original mesh. The
>advice is generally to apply the mirror modifier before starting hair
>In your file the "Use Modifier Stack" option is enabled, which attaches the
>hair to the mesh after modifier evaluation. This makes it work for the
>mirror modifier (but will not work so well in other cases like subsurf
>which is why the option is off by default).
>The bug seems to be that the disconnect/reconnect hair operator does not
>take into account this "Use Modifier Stack" setting, in that case it should
>use the final mesh instead of the deformed (original) mesh.
> >On Sun, May 27, 2018 at 7:35 PM, Oliver Mangold <o.mangold at gmail.com> wrote:
> >
> >Hi,
> >
> >I would like to fix a bug, concerning disconnect/reconnect of hairs on an
> >object with a mirror modifier. I already reported it (
> >https://developer.blender.org/T54488), but now I also dug a little into
> >the relevant code. My findings are, that in the function
> >remap_hair_emitter(), which does the main work of reconnecting hair to the
> >mesh, there is a weird case decision
> >
> > if (target_psmd->dm_final->deformedOnly) {
> > /* we don't want to mess up target_psmd->dm when
> >converting to global coordinates below */
> > dm = target_psmd->dm_final;
> > }
> > else {
> > dm = target_psmd->dm_deformed;
> > }
> >
> >where in my tests the second branch is taken, thus dm_deformed is used for
> >the further steps, in particular to build the BVH which is used to search
> >for the nearest face to connect the a hair to.
> >
> > bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_FACES, 2);
> >
> >It seems that in dm_final the mirrored faces are present, while in
> >dm_deformed they are not. Thus was happens is, that the hair on the
> >mirrored side get connected to the nearest point of the nearest unmirrored
> >face. The problem goes away when removing the case decision and always
> >using dm_final. Checking the history, once it worked that way, and was
> >changed to the current situation in this commit:
> >
> >commit 0666de06f3119ff1640f1eb66833cd4feb669209
> >Date: Thu Jan 15 18:15:52 2015 +0100
> >
> > Fix for particle system copy: This has to make sure the ORIGSPACE data
> > layer is available.
> >
> > Otherwise particle mapping to the new mesh cannot work with subdivided
> > and constructively-modified meshes.
> >
> >I have to admit, that I got lost at that point. I'm not familiar enough
> >with the code yet, to understand what really is the idea behind selecting
> >dm_final or dm_deformed, and what problem exactly was fixed by that. Would
> >be great if someone could explain. How can this bug be fixed without
> >breaking the fix of the commit above?
> >
> >Best regards,
> >
> >O.

@Philipp Oeser (lichtwerk) Yes, of course. Sorry in case I failed to follow the preferred procedures. No secret that I'm rather new around here.

In any case, I looked further into the matter, and as psys_calc_dmcache() is just setting num_dmcache = DMCACHE_ISCHILD in the case of 'use modifier stack', I did this also, and voila stuff seems to work. Apparently the marker DMCACHE_ISCHILD is abused to handle the case of modifier stacks also. In case this reasoning is right, and you want to try, here is the fix:


I'm still trying to understand the wrong placement of hair after disconnect with subsurf and 'use modifier stack' disabled. I will let you know, if I can figure out more.

About the situation with subsurf and no 'use modfiier stack', not it is clearer to me. The reconnect in this case seems to work like this:

  • Find face and point on mesh closest to location of hair root. For this the location of the hair root is taken after modifiers, while the mesh is taken before modifiers.
  • Offset between this closest point and old location of hair root is computed.
  • This offset is added to locations of all hair keys.

I guess the best way to solve this, would be to use the final mesh (after modifiers) in the first step. The problem that appears there, though, is that the index of the face the hair is attached to has to be giving on the original mesh. I couldn't find a method available to do that, so I didn't come up with a patch (yet). Basically what would be needed is the inverse of psys_particle_dm_face_lookup().