Commit: 88387ffa5912ecc9e52b73da3240282b4aecae25 Author: Lukas Tönne Date: Wed Apr 15 11:00:17 2015 +0200 Branches: alembic https://developer.blender.org/rB88387ffa5912ecc9e52b73da3240282b4aecae25
Object and particle system selection in the cache hair sim modifier. Before this the hair sim would be applied indiscriminately to all the strands in the cache data. Now an object/psys combination from the dupli cache must be selected. Note that this is not the actual target of the hair simulation, which still operates on the cache overrides instead. The Object/Psys only functions as a selectable key, if no matching data is found in the cache no hairsim will be applied. =================================================================== M release/scripts/startup/bl_ui/properties_object.py M source/blender/blenkernel/intern/cache_library.c M source/blender/makesdna/DNA_cache_library_types.h M source/blender/makesrna/intern/rna_cache_library.c =================================================================== diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py index 471cf2c..59d1211 100644 --- a/release/scripts/startup/bl_ui/properties_object.py +++ b/release/scripts/startup/bl_ui/properties_object.py @@ -437,6 +437,18 @@ class OBJECT_PT_duplication(ObjectButtonsPanel, Panel): params = md.parameters col = layout.column() + col.prop_search(md, "object", context.blend_data, "objects", icon='OBJECT_DATA') + sub = col.column() + if (md.object): + sub.prop_search(md, "hair_system", md.object, "particle_systems") + else: + sub.enabled = False + sub.prop(md, "hair_system") + + layout = layout.column() + layout.active = md.hair_system is not None + + col = layout.column() col.prop(params, "substeps") col.prop(params, "timescale") col.prop(params, "mass") diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c index 8b9e3ac..f86a7ec 100644 --- a/source/blender/blenkernel/intern/cache_library.c +++ b/source/blender/blenkernel/intern/cache_library.c @@ -648,6 +648,9 @@ static void hairsim_params_init(HairSimParams *params) static void hairsim_init(HairSimCacheModifier *hsmd) { + hsmd->object = NULL; + hsmd->hair_system = -1; + hairsim_params_init(&hsmd->sim_params); } @@ -667,48 +670,74 @@ static void hairsim_free(HairSimCacheModifier *hsmd) curvemapping_free(hsmd->sim_params.goal_stiffness_mapping); } +static void hairsim_foreach_id_link(HairSimCacheModifier *hsmd, CacheLibrary *cachelib, CacheModifier_IDWalkFunc walk, void *userdata) +{ + walk(userdata, cachelib, &hsmd->modifier, (ID **)(&hsmd->object)); +} + +static bool hairsim_find_data(HairSimCacheModifier *hsmd, DupliCache *dupcache, Object **r_ob, Strands **r_strands) +{ + DupliObjectData *dobdata; + ParticleSystem *psys; + DupliObjectDataStrands *link; + Strands *strands; + + if (!hsmd->object) + return false; + dobdata = BKE_dupli_cache_find_data(dupcache, hsmd->object); + if (!dobdata) + return false; + + psys = BLI_findlink(&hsmd->object->particlesystem, hsmd->hair_system); + if (!psys || !psys->part->type == PART_HAIR) + return false; + + strands = NULL; + for (link = dobdata->strands.first; link; link = link->next) { + if (link->strands && STREQ(link->name, psys->name)) { + strands = link->strands; + break; + } + } + if (!strands) + return false; + + *r_ob = hsmd->object; + *r_strands = strands; + return true; +} + static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *ctx, CacheProcessData *data, int frame, int frame_prev) { - struct DupliCacheIterator *iter; + Object *ob; + Strands *strands; + float mat[4][4]; + ListBase *effectors; + struct Implicit_Data *solver_data; /* skip first step and potential backward steps */ if (frame <= frame_prev) return; + if (!hairsim_find_data(hsmd, data->dupcache, &ob, &strands)) + return; + if (hsmd->sim_params.flag & eHairSimParams_Flag_UseGoalStiffnessCurve) curvemapping_changed_all(hsmd->sim_params.goal_stiffness_mapping); - iter = BKE_dupli_cache_iter_new(data->dupcache); - for (; BKE_dupli_cache_iter_valid(iter); BKE_dupli_cache_iter_next(iter)) { - DupliObjectData *dobdata = BKE_dupli_cache_iter_get(iter); - DupliObjectDataStrands *link; - float mat[4][4]; - - if (dobdata->ob) - mul_m4_m4m4(mat, data->mat, dobdata->ob->obmat); - else - copy_m4_m4(mat, data->mat); + if (ob) + mul_m4_m4m4(mat, data->mat, ob->obmat); + else + copy_m4_m4(mat, data->mat); - for (link = dobdata->strands.first; link; link = link->next) { - Strands *strands = link->strands; - ListBase *effectors; - - struct Implicit_Data *solver_data; - - BKE_strands_add_motion_state(strands); - - solver_data = BPH_strands_solver_create(strands, &hsmd->sim_params); - - effectors = pdInitEffectors(ctx->scene, dobdata->ob, NULL, hsmd->sim_params.effector_weights, true); - - BPH_strands_solve(strands, mat, solver_data, &hsmd->sim_params, (float)frame, (float)frame_prev, ctx->scene, effectors); - - pdEndEffectors(&effectors); - - BPH_mass_spring_solver_free(solver_data); - } - } - BKE_dupli_cache_iter_free(iter); + BKE_strands_add_motion_state(strands); + solver_data = BPH_strands_solver_create(strands, &hsmd->sim_params); + effectors = pdInitEffectors(ctx->scene, ob, NULL, hsmd->sim_params.effector_weights, true); + + BPH_strands_solve(strands, mat, solver_data, &hsmd->sim_params, (float)frame, (float)frame_prev, ctx->scene, effectors); + + pdEndEffectors(&effectors); + BPH_mass_spring_solver_free(solver_data); } CacheModifierTypeInfo cacheModifierType_HairSimulation = { @@ -717,7 +746,7 @@ CacheModifierTypeInfo cacheModifierType_HairSimulation = { /* structSize */ sizeof(HairSimCacheModifier), /* copy */ (CacheModifier_CopyFunc)hairsim_copy, - /* foreachIDLink */ (CacheModifier_ForeachIDLinkFunc)NULL, + /* foreachIDLink */ (CacheModifier_ForeachIDLinkFunc)hairsim_foreach_id_link, /* process */ (CacheModifier_ProcessFunc)hairsim_process, /* init */ (CacheModifier_InitFunc)hairsim_init, /* free */ (CacheModifier_FreeFunc)hairsim_free, diff --git a/source/blender/makesdna/DNA_cache_library_types.h b/source/blender/makesdna/DNA_cache_library_types.h index 84be8fd..9a2f602 100644 --- a/source/blender/makesdna/DNA_cache_library_types.h +++ b/source/blender/makesdna/DNA_cache_library_types.h @@ -148,6 +148,10 @@ typedef enum eHairSimParams_Flag { typedef struct HairSimCacheModifier { CacheModifier modifier; + struct Object *object; + int hair_system; + int pad; + HairSimParams sim_params; } HairSimCacheModifier; diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c index 281489d..bd72c91 100644 --- a/source/blender/makesrna/intern/rna_cache_library.c +++ b/source/blender/makesrna/intern/rna_cache_library.c @@ -68,6 +68,7 @@ EnumPropertyItem cache_modifier_type_items[] = { #include "BLI_string.h" #include "DNA_object_types.h" +#include "DNA_particle_types.h" #include "BKE_animsys.h" #include "BKE_cache_library.h" @@ -167,6 +168,55 @@ static void rna_CacheLibrary_modifier_clear(CacheLibrary *cachelib, bContext *UN BKE_cache_modifier_clear(cachelib); } +/* ------------------------------------------------------------------------- */ + +static int rna_HairSimulationCacheModifier_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value) +{ + /*HairSimCacheModifier *hsmd = ptr->data;*/ + Object *ob = value.data; + ParticleSystem *psys; + bool has_hair_system = false; + + for (psys = ob->particlesystem.first; psys; psys = psys->next) { + if (psys->part && psys->part->type == PART_HAIR) { + has_hair_system = true; + break; + } + } + return has_hair_system; +} + +static PointerRNA rna_HairSimulationCacheModifier_hair_system_get(PointerRNA *ptr) +{ + HairSimCacheModifier *hsmd = ptr->data; + ParticleSystem *psys = hsmd->object ? BLI_findlink(&hsmd->object->particlesystem, hsmd->hair_system) : NULL; + PointerRNA value; + + RNA_pointer_create(ptr->id.data, &RNA_ParticleSystem, psys, &value); + return value; +} + +static void rna_HairSimulationCacheModifier_hair_system_set(PointerRNA *ptr, PointerRNA value) +{ + HairSimCacheModifier *hsmd = ptr->data; + ParticleSystem *psys = value.data; + hsmd->hair_system = hsmd->object ? BLI_findindex(&hsmd->object->particlesystem, psys) : -1; +} + +static int rna_HairSimulationCacheModifier_hair_system_poll(PointerRNA *ptr, PointerRNA value) +{ + HairSimCacheModifier *hsmd = ptr->data; + ParticleSystem *psys = value.data; + + if (!hsmd->object) + return false; + if (BLI_findindex(&hsmd->object->particlesystem, psys) == -1) + return false; + if (!psys->part || psys->part->type != PART_HAIR) + return false; + return true; +} + #else static void rna_def_hair_sim_params(BlenderRNA *brna) @@ -273,6 +323,26 @@ static void rna_def_cache_modifier_hair_simulation(BlenderRNA *brna) RNA_def_struct_ui_text(srna, "Hair Simulation Cache Modifier", "Apply hair dynamics simulation to the cache"); RNA_def_struct_ui_icon(srna, ICON_HAIR); + prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "object"); + RNA_def_property_struct_type(prop, "Object"); + RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_HairSimulationCacheModifier_object_poll"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Object", "Object whose cache to simulate"); + RNA_def_property_update(prop, 0, "rna_CacheModifier_update"); + + prop = RNA_def_property(srna, "hair_system_index", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "hair_system"); + RNA_def_property_ui_text(prop, "Hair System Index", "Hair system cache to simulate"); + RNA_def_property_update(prop, 0, "rna_CacheModifier_update"); + + prop = RNA_def_property(srna, "hair_system", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_funcs(prop, "rna_HairSimulationCacheModifier_hair_system_get", "rna_HairSimulationCacheModifier_hair_system_set", NULL, "rna_HairSimulationCacheModifier_hair_system_poll"); + RNA_def_property_struct_type(prop, "ParticleSystem"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Hair System", "Hair system cache to simulate"); + RNA_def_property_update(prop, 0, "rna_CacheModifier_update"); + prop = RNA_def_property(srna, "parameters", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "sim_params"); RNA_def_property_struct_type(prop, "HairSimulationParameters"); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs