diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-09-06 17:34:21 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-09-06 17:34:21 +0300 |
commit | 5045219ca978dbadd4644dfe9c43d101e792416f (patch) | |
tree | 0e253e53fc2df2480994648242e6f7f65674b295 | |
parent | d30979dddb30390986b23c7d9bdfe621ce401181 (diff) |
separate BParticles Output modifier
-rw-r--r-- | release/scripts/startup/bl_ui/properties_data_modifier.py | 23 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_draw.c | 1 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 19 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 39 | ||||
-rw-r--r-- | source/blender/modifiers/CMakeLists.txt | 3 | ||||
-rw-r--r-- | source/blender/modifiers/MOD_modifiertypes.h | 1 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_bparticles.c | 86 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_bparticles.h | 10 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_bparticles_output.c | 123 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_util.c | 1 | ||||
-rw-r--r-- | source/blender/simulations/BParticles.h | 3 |
11 files changed, 206 insertions, 103 deletions
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py index aaa5d872f3d..374fd656e55 100644 --- a/release/scripts/startup/bl_ui/properties_data_modifier.py +++ b/release/scripts/startup/bl_ui/properties_data_modifier.py @@ -1662,20 +1662,19 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel): props.modifier_name = md.name def BPARTICLES(self, layout, ob, md): - layout.prop(md, "mode") - if md.mode == 'SIMULATOR': - row = layout.row(align=True) - row.prop(md, "bparticles_tree") - props = row.operator("bp.new_bparticles_tree", text="", icon="ADD") - props.object_name = ob.name - props.modifier_name = md.name + row = layout.row(align=True) + row.prop(md, "bparticles_tree") + props = row.operator("bp.new_bparticles_tree", text="", icon="ADD") + props.object_name = ob.name + props.modifier_name = md.name + + layout.operator("object.bparticles_clear_cache", text="Clear Cache") - layout.operator("object.bparticles_clear_cache", text="Clear Cache") + layout.prop(md, "output_type") - layout.prop(md, "output_type") - elif md.mode == 'PASSIVE': - layout.prop(md, "source_object") - layout.prop(md, "source_particle_type") + def BPARTICLES_OUTPUT(self, layout, ob, md): + layout.prop(md, "source_object") + layout.prop(md, "source_particle_type") class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel): diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 32436af598f..84125a5ee00 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -2184,6 +2184,7 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te) case eModifierType_FunctionDeform: case eModifierType_FunctionPoints: case eModifierType_BParticles: + case eModifierType_BParticlesOutput: case NUM_MODIFIER_TYPES: data.icon = ICON_DOT; diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 36a80b51926..d843994c6d0 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -89,6 +89,7 @@ typedef enum ModifierType { eModifierType_FunctionDeform = 55, eModifierType_FunctionPoints = 56, eModifierType_BParticles = 57, + eModifierType_BParticlesOutput = 58, NUM_MODIFIER_TYPES } ModifierType; @@ -1988,27 +1989,19 @@ typedef enum eBParticlesOutputType { MOD_BPARTICLES_OUTPUT_NONE, } eBParticlesOutputType; -typedef enum eBParticlesModifierMode { - MOD_BPARTICLES_MODE_SIMULATOR, - MOD_BPARTICLES_MODE_PASSIVE, -} eBParticlesModifierMode; - typedef struct BParticlesModifierData { ModifierData modifier; - unsigned int mode; - /* Simulator Settings */ unsigned int output_type; - struct bNodeTree *bparticles_tree; - unsigned int num_cached_frames; - char _pad[4]; + struct bNodeTree *bparticles_tree; BParticlesFrameCache *cached_frames; +} BParticlesModifierData; - /* Passive Settings */ +typedef struct BParticlesOutputModifierData { + ModifierData modifier; struct Object *source_object; char source_particle_type[64]; - -} BParticlesModifierData; +} BParticlesOutputModifierData; #endif /* __DNA_MODIFIER_TYPES_H__ */ diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 63b01af8b62..22246d5a8dd 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -148,6 +148,7 @@ const EnumPropertyItem rna_enum_object_modifier_type_items[] = { {eModifierType_Softbody, "SOFT_BODY", ICON_MOD_SOFT, "Soft Body", ""}, {eModifierType_Surface, "SURFACE", ICON_MODIFIER, "Surface", ""}, {eModifierType_BParticles, "BPARTICLES", ICON_NONE, "BParticles", ""}, + {eModifierType_BParticlesOutput, "BPARTICLES_OUTPUT", ICON_NONE, "BParticles Output", ""}, {0, NULL, 0, NULL, NULL}, }; @@ -582,6 +583,8 @@ static StructRNA *rna_Modifier_refine(struct PointerRNA *ptr) return &RNA_FunctionPointsModifier; case eModifierType_BParticles: return &RNA_BParticlesModifier; + case eModifierType_BParticlesOutput: + return &RNA_BParticlesOutputModifier; /* Default */ case eModifierType_None: case eModifierType_ShapeKey: @@ -6049,32 +6052,10 @@ static void rna_def_modifier_bparticles(BlenderRNA *brna) PropertyRNA *prop; srna = RNA_def_struct(brna, "BParticlesModifier", "Modifier"); - RNA_def_struct_ui_text(srna, "Node Particles Modifier", ""); + RNA_def_struct_ui_text(srna, "BParticles Modifier", ""); RNA_def_struct_sdna(srna, "BParticlesModifierData"); RNA_def_struct_ui_icon(srna, ICON_NONE); - const static EnumPropertyItem mode_types[] = { - {MOD_BPARTICLES_MODE_SIMULATOR, - "SIMULATOR", - 0, - "Simulator", - "Use this modifier as main simulator"}, - {MOD_BPARTICLES_MODE_PASSIVE, - "PASSIVE", - 0, - "Passive", - "This modifiers only copies particle data from another object"}, - {0, NULL, 0, NULL, NULL}, - }; - - prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_items(prop, mode_types); - RNA_def_property_ui_text( - prop, "Mode", "Use the modifier as active simulator or only copy data from other modifier"); - RNA_def_property_update(prop, 0, "rna_Modifier_update"); - - /* Simulator Mode */ - prop = RNA_def_property(srna, "bparticles_tree", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "BParticles Tree", "BParticles node tree"); @@ -6100,8 +6081,17 @@ static void rna_def_modifier_bparticles(BlenderRNA *brna) RNA_def_property_ui_text( prop, "Output Type", "Method for creating the output mesh from the particle data"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); +} + +static void rna_def_modifier_bparticles_output(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; - /* Passive Mode */ + srna = RNA_def_struct(brna, "BParticlesOutputModifier", "Modifier"); + RNA_def_struct_ui_text(srna, "BParticles Output Modifier", ""); + RNA_def_struct_sdna(srna, "BParticlesOutputModifierData"); + RNA_def_struct_ui_icon(srna, ICON_NONE); prop = RNA_def_property(srna, "source_object", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); @@ -6242,6 +6232,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_function_deform(brna); rna_def_modifier_function_points(brna); rna_def_modifier_bparticles(brna); + rna_def_modifier_bparticles_output(brna); } #endif diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index 8d18488d234..e508e38546e 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -45,6 +45,8 @@ set(SRC intern/MOD_array.c intern/MOD_bevel.c intern/MOD_boolean.c + intern/MOD_bparticles.c + intern/MOD_bparticles_output.c intern/MOD_build.c intern/MOD_cast.c intern/MOD_cloth.c @@ -74,7 +76,6 @@ set(SRC intern/MOD_meshsequencecache.c intern/MOD_mirror.c intern/MOD_multires.c - intern/MOD_bparticles.c intern/MOD_none.c intern/MOD_normal_edit.c intern/MOD_ocean.c diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h index 58f70520b90..10f8d83b5bc 100644 --- a/source/blender/modifiers/MOD_modifiertypes.h +++ b/source/blender/modifiers/MOD_modifiertypes.h @@ -84,6 +84,7 @@ extern ModifierTypeInfo modifierType_WeightedNormal; extern ModifierTypeInfo modifierType_FunctionDeform; extern ModifierTypeInfo modifierType_FunctionPoints; extern ModifierTypeInfo modifierType_BParticles; +extern ModifierTypeInfo modifierType_BParticlesOutput; /* MOD_util.c */ void modifier_type_init(ModifierTypeInfo *types[]); diff --git a/source/blender/modifiers/intern/MOD_bparticles.c b/source/blender/modifiers/intern/MOD_bparticles.c index 003cf4220d3..4dab2611dd7 100644 --- a/source/blender/modifiers/intern/MOD_bparticles.c +++ b/source/blender/modifiers/intern/MOD_bparticles.c @@ -41,19 +41,18 @@ #include "BLI_math.h" +#include "MOD_bparticles.h" #include "MOD_util.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" -#include "BParticles.h" - typedef struct RuntimeData { BParticlesSimulationState simulation_state; float last_simulated_frame; } RuntimeData; -static RuntimeData *get_runtime_struct(BParticlesModifierData *bpmd) +static RuntimeData *get_or_create_runtime_struct(BParticlesModifierData *bpmd) { if (bpmd->modifier.runtime == NULL) { RuntimeData *runtime = MEM_callocN(sizeof(RuntimeData), __func__); @@ -65,6 +64,11 @@ static RuntimeData *get_runtime_struct(BParticlesModifierData *bpmd) return bpmd->modifier.runtime; } +static RuntimeData *get_runtime_struct(BParticlesModifierData *bpmd) +{ + return bpmd->modifier.runtime; +} + static void free_runtime_data(RuntimeData *runtime) { BParticles_simulation_free(runtime->simulation_state); @@ -80,17 +84,33 @@ static void free_modifier_runtime_data(BParticlesModifierData *bpmd) } } -static Mesh *apply_modifier__simulator(BParticlesModifierData *bpmd, - const struct ModifierEvalContext *ctx, - Mesh *UNUSED(mesh)) +BParticlesSimulationState MOD_bparticles_find_simulation_state(Object *object) { + BLI_assert(object != NULL); + BParticlesModifierData *bpmd = (BParticlesModifierData *)modifiers_findByType( + object, eModifierType_BParticles); + if (bpmd == NULL) { + return NULL; + } + RuntimeData *runtime = get_runtime_struct(bpmd); + if (runtime == NULL) { + return NULL; + } + return runtime->simulation_state; +} + +static Mesh *applyModifier(ModifierData *md, + const struct ModifierEvalContext *ctx, + Mesh *UNUSED(mesh)) +{ + BParticlesModifierData *bpmd = (BParticlesModifierData *)md; BParticlesModifierData *bpmd_orig = (BParticlesModifierData *)modifier_get_original( &bpmd->modifier); Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); float current_frame = BKE_scene_frame_get(scene); - RuntimeData *runtime = get_runtime_struct(bpmd); + RuntimeData *runtime = get_or_create_runtime_struct(bpmd); if (runtime->simulation_state == NULL) { runtime->simulation_state = BParticles_new_simulation(); @@ -105,7 +125,7 @@ static Mesh *apply_modifier__simulator(BParticlesModifierData *bpmd, } else { free_modifier_runtime_data(bpmd); - runtime = get_runtime_struct(bpmd); + runtime = get_or_create_runtime_struct(bpmd); runtime->simulation_state = BParticles_new_simulation(); runtime->last_simulated_frame = current_frame; BParticles_modifier_free_cache(bpmd_orig); @@ -125,41 +145,6 @@ static Mesh *apply_modifier__simulator(BParticlesModifierData *bpmd, } } -static Mesh *apply_modifier__passive(BParticlesModifierData *bpmd, - const struct ModifierEvalContext *UNUSED(ctx), - Mesh *UNUSED(mesh)) -{ - if (bpmd->source_object == NULL) { - return BKE_mesh_new_nomain(0, 0, 0, 0, 0); - } - BParticlesModifierData *source_bpmd = (BParticlesModifierData *)modifiers_findByType( - bpmd->source_object, eModifierType_BParticles); - if (source_bpmd == NULL) { - return BKE_mesh_new_nomain(0, 0, 0, 0, 0); - } - RuntimeData *source_runtime_data = get_runtime_struct(source_bpmd); - if (source_runtime_data == NULL) { - return BKE_mesh_new_nomain(0, 0, 0, 0, 0); - } - if (source_runtime_data->simulation_state == NULL) { - return BKE_mesh_new_nomain(0, 0, 0, 0, 0); - } - - return BParticles_modifier_extract_mesh(source_runtime_data->simulation_state, - bpmd->source_particle_type); -} - -static Mesh *applyModifier(ModifierData *md, const struct ModifierEvalContext *ctx, Mesh *mesh) -{ - BParticlesModifierData *bpmd = (BParticlesModifierData *)md; - if (bpmd->mode == MOD_BPARTICLES_MODE_SIMULATOR) { - return apply_modifier__simulator(bpmd, ctx, mesh); - } - else { - return apply_modifier__passive(bpmd, ctx, mesh); - } -} - static void initData(ModifierData *UNUSED(md)) { } @@ -194,19 +179,16 @@ static bool dependsOnTime(ModifierData *UNUSED(md)) return true; } -static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) +static void updateDepsgraph(ModifierData *UNUSED(md), + const ModifierUpdateDepsgraphContext *UNUSED(ctx)) { - BParticlesModifierData *bpmd = (BParticlesModifierData *)md; - if (bpmd->source_object) { - DEG_add_object_relation( - ctx->node, bpmd->source_object, DEG_OB_COMP_GEOMETRY, "Passive BParticles Modifier"); - } } -static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData) +static void foreachObjectLink(ModifierData *UNUSED(md), + Object *UNUSED(ob), + ObjectWalkFunc UNUSED(walk), + void *UNUSED(userData)) { - BParticlesModifierData *bpmd = (BParticlesModifierData *)md; - walk(userData, ob, &bpmd->source_object, IDWALK_CB_NOP); } static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData) diff --git a/source/blender/modifiers/intern/MOD_bparticles.h b/source/blender/modifiers/intern/MOD_bparticles.h new file mode 100644 index 00000000000..c0d31b85f6b --- /dev/null +++ b/source/blender/modifiers/intern/MOD_bparticles.h @@ -0,0 +1,10 @@ +#include "BParticles.h" + +#ifndef __MOD_BPARTICLES_H__ +# define __MOD_BPARTICLES_H__ + +struct Object; + +BParticlesSimulationState MOD_bparticles_find_simulation_state(struct Object *object); + +#endif /* __MOD_BPARTICLES_H__ */ diff --git a/source/blender/modifiers/intern/MOD_bparticles_output.c b/source/blender/modifiers/intern/MOD_bparticles_output.c new file mode 100644 index 00000000000..e0d8563de0b --- /dev/null +++ b/source/blender/modifiers/intern/MOD_bparticles_output.c @@ -0,0 +1,123 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2019 by the Blender Foundation. + * All rights reserved. + * ***** END GPL LICENSE BLOCK ***** + * + */ + +/** \file blender/modifiers/intern/MOD_bparticles_output.c + * \ingroup modifiers + * + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_modifier_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "BKE_mesh.h" +#include "BKE_modifier.h" +#include "BKE_scene.h" +#include "BKE_library_query.h" + +#include "BLI_math.h" + +#include "MOD_bparticles.h" +#include "MOD_util.h" + +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" + +#include "BParticles.h" + +static Mesh *applyModifier(ModifierData *md, + const struct ModifierEvalContext *UNUSED(ctx), + Mesh *mesh) +{ + BParticlesOutputModifierData *bpmd = (BParticlesOutputModifierData *)md; + if (bpmd->source_object == NULL) { + return mesh; + } + + BParticlesSimulationState simulation_state = MOD_bparticles_find_simulation_state( + bpmd->source_object); + if (simulation_state == NULL) { + return BKE_mesh_new_nomain(0, 0, 0, 0, 0); + } + + return BParticles_modifier_extract_mesh(simulation_state, bpmd->source_particle_type); +} + +static void initData(ModifierData *UNUSED(md)) +{ +} + +static void freeData(ModifierData *UNUSED(md)) +{ +} + +static void copyData(const ModifierData *md, ModifierData *target, const int flag) +{ + modifier_copyData_generic(md, target, flag); +} + +static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) +{ + BParticlesOutputModifierData *bpmd = (BParticlesOutputModifierData *)md; + if (bpmd->source_object) { + DEG_add_object_relation( + ctx->node, bpmd->source_object, DEG_OB_COMP_GEOMETRY, "BParticles Output Modifier"); + } +} + +static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData) +{ + BParticlesOutputModifierData *bpmd = (BParticlesOutputModifierData *)md; + walk(userData, ob, &bpmd->source_object, IDWALK_CB_NOP); +} + +ModifierTypeInfo modifierType_BParticlesOutput = { + /* name */ "BParticles Output", + /* structName */ "BParticlesOutputModifierData", + /* structSize */ sizeof(BParticlesOutputModifierData), + /* type */ eModifierTypeType_Constructive, + /* flags */ eModifierTypeFlag_AcceptsMesh, + /* copyData */ copyData, + + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, + /* applyModifier */ applyModifier, + + /* initData */ initData, + /* requiredDataMask */ NULL, + /* freeData */ freeData, + /* isDisabled */ NULL, + /* updateDepsgraph */ updateDepsgraph, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ foreachObjectLink, + /* foreachIDLink */ NULL, + /* foreachTexLink */ NULL, + /* freeRuntimeData */ NULL, +}; diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index 4b1d8071ea4..257907c9b8d 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -310,5 +310,6 @@ void modifier_type_init(ModifierTypeInfo *types[]) INIT_TYPE(FunctionDeform); INIT_TYPE(FunctionPoints); INIT_TYPE(BParticles); + INIT_TYPE(BParticlesOutput); #undef INIT_TYPE } diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h index a5047dca712..307f217d170 100644 --- a/source/blender/simulations/BParticles.h +++ b/source/blender/simulations/BParticles.h @@ -12,6 +12,7 @@ struct Mesh; struct Depsgraph; struct BParticlesModifierData; struct BParticlesFrameCache; +struct Depsgraph; typedef struct OpaqueBParticlesSimulationState *BParticlesSimulationState; @@ -19,7 +20,7 @@ BParticlesSimulationState BParticles_new_simulation(void); void BParticles_simulation_free(BParticlesSimulationState simulation_state); void BParticles_simulate_modifier(struct BParticlesModifierData *bpmd, - Depsgraph *depsgraph, + struct Depsgraph *depsgraph, BParticlesSimulationState simulation_state, float time_step); |