Simple hair children: Make twist affected by texture
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 15 Feb 2018 10:22:44 +0000 (11:22 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 15 Feb 2018 11:24:48 +0000 (12:24 +0100)
This completes twist feature, which is now possible to also control by
texture. Since textures can not easily contain negative values as well,
same trick with 0.5 neutral as vertex groups is used.

All in all, this twist features allows to do following things.

Original hair:

{F2287535}

Hair with scientifically calculated twist value of 0.5:

{F2287540}

And we can also twist braids in opposite directions dependent on left/right
side:

{F2287548}

release/scripts/startup/bl_ui/properties_texture.py
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_child.c
source/blender/blenkernel/intern/texture.c
source/blender/makesdna/DNA_particle_types.h
source/blender/makesdna/DNA_texture_types.h
source/blender/makesrna/intern/rna_particle.c

index 25e9ef3ee73060d27f5499a4cc0b8be11586c711..46b27c94419411f62b6e77d0015942a4fb7b61a7 100644 (file)
@@ -1173,6 +1173,7 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
             col = split.column()
             factor_but(col, "use_map_length", "length_factor", "Length")
             factor_but(col, "use_map_clump", "clump_factor", "Clump")
+            factor_but(col, "use_map_twist", "twist_factor", "Twist")
 
             col = split.column()
             factor_but(col, "use_map_kink_amp", "kink_amp_factor", "Kink Amplitude")
index 87322b5fddc56f2df1ad8a077d3ac9827a7e2d60..d7e0823360150c30c70e4e21d7ad3f6fabcb1cbb 100644 (file)
@@ -3568,6 +3568,7 @@ static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSetti
                        SET_PARTICLE_TEXTURE(PAMAP_KINK_AMP, ptex->kink_amp, mtex->kinkampfac);
                        SET_PARTICLE_TEXTURE(PAMAP_KINK_FREQ, ptex->kink_freq, mtex->kinkfac);
                        SET_PARTICLE_TEXTURE(PAMAP_DENS, ptex->exist, mtex->padensfac);
+                       SET_PARTICLE_TEXTURE(PAMAP_TWIST, ptex->twist, mtex->twistfac);
                }
        }
 
@@ -3668,6 +3669,7 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex
                        SET_PARTICLE_TEXTURE(PAMAP_GRAVITY, ptex->gravity, mtex->gravityfac);
                        SET_PARTICLE_TEXTURE(PAMAP_DAMP, ptex->damp, mtex->dampfac);
                        SET_PARTICLE_TEXTURE(PAMAP_LENGTH, ptex->length, mtex->lengthfac);
+                       SET_PARTICLE_TEXTURE(PAMAP_TWIST, ptex->twist, mtex->twistfac);
                }
        }
 
index fae304d65806b5240e3ebf0fa6b615fcb3f1f79e..48ecdb04348100855acfa3e8ffec52e189393c47 100644 (file)
@@ -358,6 +358,7 @@ void psys_apply_child_modifiers(ParticleThreadContext *ctx, struct ListBase *mod
                totkeys = ctx->segments + 1;
                max_length = ptex->length;
 
+               printf("%f\n", ptex->twist);
                for (k = 0, key = keys; k < totkeys; k++, key++) {
                        ParticlePathIterator iter;
                        psys_path_iter_get(&iter, keys, totkeys, parent_keys, k);
index fcedd8806158177b985d633ea270f8af19a77241..71b90641e025740a6a175b90dceb6df5a9d95997 100644 (file)
@@ -412,6 +412,7 @@ void BKE_texture_mtex_default(MTex *mtex)
        mtex->kinkfac = 1.0f;
        mtex->kinkampfac = 1.0f;
        mtex->roughfac = 1.0f;
+       mtex->twistfac = 1.0f;
        mtex->padensfac = 1.0f;
        mtex->lifefac = 1.0f;
        mtex->sizefac = 1.0f;
index 8dd4d46a596b706f3c360fe67b4e6b2c6e743752..9dbd1a18703fdc2d44c9535f075c7d98eacb95dd 100644 (file)
@@ -614,7 +614,8 @@ typedef enum eParticleTextureInfluence {
        PAMAP_KINK_AMP  = (1<<12),
        PAMAP_ROUGH             = (1<<9),
        PAMAP_LENGTH    = (1<<4),
-       PAMAP_CHILD             = (PAMAP_CLUMP | PAMAP_KINK_FREQ | PAMAP_KINK_AMP | PAMAP_ROUGH | PAMAP_LENGTH),
+       PAMAP_TWIST     = (1<<13),
+       PAMAP_CHILD             = (PAMAP_CLUMP | PAMAP_KINK_FREQ | PAMAP_KINK_AMP | PAMAP_ROUGH | PAMAP_LENGTH | PAMAP_TWIST),
 } eParticleTextureInfluence;
 
 #endif
index 995d7645dc0087df3040852910043cc12d95ca30..0eb54a9b5b38214a9b0bc1cf84bc7fb5c59edf6e 100644 (file)
@@ -86,7 +86,7 @@ typedef struct MTex {
        float timefac, lengthfac, clumpfac, dampfac;
        float kinkfac, kinkampfac, roughfac, padensfac, gravityfac;
        float lifefac, sizefac, ivelfac, fieldfac;
-       int pad2;
+       float twistfac;
 
        /* lamp */
        float shadowfac;
index caf120e0ea1f2eeca8dd33175b694298ef73b071..2710a18436732a09547e22749fffa77132e173ef 100644 (file)
@@ -1894,6 +1894,10 @@ static void rna_def_particle_settings_mtex(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Length", "Affect the child hair length");
        RNA_def_property_update(prop, 0, "rna_Particle_redo_child");
 
+       prop = RNA_def_property(srna, "use_map_twist", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "mapto", PAMAP_TWIST);
+       RNA_def_property_ui_text(prop, "Twist", "Affect the child twist");
+       RNA_def_property_update(prop, 0, "rna_Particle_redo_child");
 
        /* influence factors */
        prop = RNA_def_property(srna, "time_factor", PROP_FLOAT, PROP_NONE);
@@ -1975,6 +1979,12 @@ static void rna_def_particle_settings_mtex(BlenderRNA *brna)
        RNA_def_property_ui_range(prop, 0, 1, 10, 3);
        RNA_def_property_ui_text(prop, "Rough Factor", "Amount texture affects child roughness");
        RNA_def_property_update(prop, 0, "rna_Particle_redo_child");
+
+       prop = RNA_def_property(srna, "twist_factor", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "twistfac");
+       RNA_def_property_ui_range(prop, 0, 1, 10, 3);
+       RNA_def_property_ui_text(prop, "Twist Factor", "Amount texture affects child twist");
+       RNA_def_property_update(prop, 0, "rna_Particle_redo_child");
 }
 
 static void rna_def_particle_settings(BlenderRNA *brna)