[Bf-blender-cvs] [f92ab71] temp_hair_flow: Automatically re-evaluate the flow solution on hair updates, as a replacement for the current distribution system.
Lukas Tönne
noreply at git.blender.org
Thu Jan 8 15:51:07 CET 2015
Commit: f92ab71f2f734c18da3dae4e09b1de4765f76a3b
Author: Lukas Tönne
Date: Thu Jan 8 15:50:18 2015 +0100
Branches: temp_hair_flow
https://developer.blender.org/rBf92ab71f2f734c18da3dae4e09b1de4765f76a3b
Automatically re-evaluate the flow solution on hair updates, as a
replacement for the current distribution system.
===================================================================
M release/scripts/startup/bl_ui/properties_particle.py
M source/blender/blenkernel/intern/particle_system.c
M source/blender/makesdna/DNA_particle_types.h
M source/blender/makesrna/intern/rna_particle.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py
index e7e4bc2..0243997 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -279,8 +279,13 @@ class PARTICLE_PT_hair_flow(ParticleButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
psys = context.particle_system
+ part = particle_get_settings(context)
col = layout.column()
+ col.prop(part, "count")
+ col.prop(part, "hair_length")
+ col.prop(part, "hair_flow_resolution")
+
col.operator("hair.solve_flow")
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index c538c9a..c2efcd2 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -76,6 +76,7 @@
#include "BKE_boids.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_collision.h"
+#include "BKE_editstrands.h"
#include "BKE_effect.h"
#include "BKE_particle.h"
#include "BKE_global.h"
@@ -92,6 +93,8 @@
#include "BKE_scene.h"
#include "BKE_bvhutils.h"
+#include "BPH_strands.h"
+
#include "PIL_time.h"
#include "RE_shader_ext.h"
@@ -3507,6 +3510,48 @@ static void save_hair(ParticleSimulationData *sim, float UNUSED(cfra))
}
}
+static bool psys_hair_flow_recalc(Scene *scene, Object *ob, ParticleSystem *psys)
+{
+ ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys);
+
+ unsigned int seed = psys->seed;
+ int max_strands = psys->part->totpart;
+ float max_length = psys->part->normfac * 4.f; /* XXX this is crap, but same as in RNA for the "hair_length" prop */
+ int segments = psys->part->hair_step;
+ int res = psys->part->hair_flow_resolution;
+
+ struct HairFlowData *data;
+
+ if (!psmd->dm)
+ return false;
+
+ data = BPH_strands_solve_hair_flow(scene, ob, max_length, res, NULL);
+ if (data) {
+ BMesh *bm = BKE_particles_to_bmesh(ob, psys);
+ DerivedMesh *dm = psmd->dm;
+ BMEditStrands *edit = BKE_editstrands_create(bm, dm);
+
+ /* generate new hair strands */
+ BPH_strands_sample_hair_flow(ob, edit, data, seed, max_strands, max_length, segments);
+
+ BKE_particles_from_bmesh(ob, psys, edit);
+ psys->flag |= PSYS_EDITED;
+ BKE_editstrands_free(edit);
+ MEM_freeN(edit);
+
+ BPH_strands_free_hair_flow(data);
+
+// WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_HAIR, NULL);
+// DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+
+ return true;
+ }
+ else
+ return false;
+
+// WM_event_add_notifier(C, NC_OBJECT | ND_DRAW | NA_SELECTED, ob);
+}
+
/* Code for an adaptive time step based on the Courant-Friedrichs-Lewy
* condition. */
static const float MIN_TIMESTEP = 1.0f / 101.0f;
@@ -4258,15 +4303,20 @@ static void psys_prepare_physics(ParticleSimulationData *sim)
psys_check_boid_data(sim->psys);
}
-static int hair_needs_recalc(ParticleSystem *psys)
-{
- if (!(psys->flag & PSYS_EDITED) && (!psys->edit || !psys->edit->edited) &&
- ((psys->flag & PSYS_HAIR_DONE)==0 || psys->recalc & PSYS_RECALC_RESET || (psys->part->flag & PART_HAIR_REGROW && !psys->edit)))
- {
- return 1;
- }
- return 0;
+static bool hair_needs_recalc(ParticleSystem *psys)
+{
+ bool is_done = psys->flag & PSYS_HAIR_DONE;
+ bool is_edited = (psys->flag & PSYS_EDITED) || (psys->edit && psys->edit->edited);
+ bool use_flow = psys->flag & PSYS_HAIR_FLOW;
+
+ bool needs_reset = psys->recalc & PSYS_RECALC_RESET;
+ bool needs_regrow = (psys->part->flag & PART_HAIR_REGROW) && !psys->edit;
+
+ if (use_flow)
+ return !is_done || needs_reset || needs_regrow;
+ else
+ return !is_edited && (!is_done || needs_reset || needs_regrow);
}
/* main particle update call, checks that things are ok on the large scale and
@@ -4331,30 +4381,36 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys)
}
/* (re-)create hair */
else if (hair_needs_recalc(psys)) {
- float hcfra=0.0f;
- int i, recalc = psys->recalc;
-
+ int recalc = psys->recalc;
+
free_hair(ob, psys, 0);
-
+
if (psys->edit && psys->free_edit) {
psys->free_edit(psys->edit);
psys->edit = NULL;
psys->free_edit = NULL;
}
-
- /* first step is negative so particles get killed and reset */
- psys->cfra= 1.0f;
-
- for (i=0; i<=part->hair_step; i++) {
- hcfra=100.0f*(float)i/(float)psys->part->hair_step;
- if ((part->flag & PART_HAIR_REGROW)==0)
- BKE_animsys_evaluate_animdata(scene, &part->id, part->adt, hcfra, ADT_RECALC_ANIM);
- system_step(&sim, hcfra);
- psys->cfra = hcfra;
- psys->recalc = 0;
- save_hair(&sim, hcfra);
+
+ if (psys->flag & PSYS_HAIR_FLOW) {
+ psys_hair_flow_recalc(scene, ob, psys);
}
-
+ else {
+ int i;
+
+ /* first step is negative so particles get killed and reset */
+ psys->cfra= 1.0f;
+
+ for (i=0; i<=part->hair_step; i++) {
+ float hcfra=100.0f*(float)i/(float)psys->part->hair_step;
+ if ((part->flag & PART_HAIR_REGROW)==0)
+ BKE_animsys_evaluate_animdata(scene, &part->id, part->adt, hcfra, ADT_RECALC_ANIM);
+ system_step(&sim, hcfra);
+ psys->cfra = hcfra;
+ psys->recalc = 0;
+ save_hair(&sim, hcfra);
+ }
+ }
+
psys->flag |= PSYS_HAIR_DONE;
psys->recalc = recalc;
}
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index 0714d9d..0b3716a 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -173,6 +173,8 @@ typedef struct ParticleSettings {
/* number of path segments, power of 2 except */
short draw_step, ren_step;
short hair_step, keys_step;
+ short hair_flow_resolution;
+ short pad3[3];
/* adaptive path rendering */
short adapt_angle, adapt_pix;
@@ -239,7 +241,7 @@ typedef struct ParticleSettings {
/* hair dynamics */
float bending_random;
- int pad3;
+ int pad4;
struct MTex *mtex[18]; /* MAX_MTEX */
@@ -254,7 +256,7 @@ typedef struct ParticleSettings {
/* modified dm support */
short use_modifier_stack;
- short pad4[3];
+ short pad5[3];
} ParticleSettings;
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index db2458b..b909ba2 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -2773,6 +2773,12 @@ static void rna_def_particle_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Hair Length", "Length of the hair");
RNA_def_property_update(prop, 0, "rna_Particle_reset");
+ prop = RNA_def_property(srna, "hair_flow_resolution", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "hair_flow_resolution");
+ RNA_def_property_range(prop, 1, INT_MAX);
+ RNA_def_property_ui_range(prop, 1, 100, 1, -1);
+ RNA_def_property_ui_text(prop, "Hair Flow Resolution", "Grid resolution for calculating hair flow");
+
/* physical properties */
prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, 0.00000001f, 100000.0f);
More information about the Bf-blender-cvs
mailing list