[Bf-blender-cvs] [4945003ffd5] fracture_modifier: remesh modifier can now remesh particle systems as well
Martin Felke
noreply at git.blender.org
Fri Dec 29 20:39:20 CET 2017
Commit: 4945003ffd521426c27381bcb3c15f6714878074
Author: Martin Felke
Date: Fri Dec 29 20:38:53 2017 +0100
Branches: fracture_modifier
https://developer.blender.org/rB4945003ffd521426c27381bcb3c15f6714878074
remesh modifier can now remesh particle systems as well
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_remesh.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index c269f0f13e4..9247be37776 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1122,6 +1122,13 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
if md.mode == 'METABALL':
row = layout.row()
+ row.prop(md, "input")
+ if 'PARTICLES' in md.input:
+ row = layout.row()
+ row.prop(md, "psys")
+ row = layout.row()
+ row.prop(md, "filter")
+ row = layout.row()
col = row.column(align=True)
col.prop(md, "mball_size")
col = row.column(align=True)
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index bc8c3b5db94..7b908fdf9d4 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1234,6 +1234,18 @@ typedef enum RemeshModifierMode {
MOD_REMESH_MBALL = 3,
} RemeshModifierMode;
+
+typedef enum MetaballRemeshFlags {
+ MOD_REMESH_VERTICES = (1 << 0),
+ MOD_REMESH_PARTICLES = (1 << 1),
+} MetaballRemeshFlags;
+
+typedef enum {
+ eRemeshFlag_Alive = (1 << 0),
+ eRemeshFlag_Dead = (1 << 1),
+ eRemeshFlag_Unborn = (1 << 2),
+} MetaballRemeshPsysFlag;
+
typedef struct RemeshModifierData {
ModifierData modifier;
@@ -1250,6 +1262,9 @@ typedef struct RemeshModifierData {
float wiresize;
float thresh;
float basesize[3];
+ int input;
+ int pflag;
+ int psys;
/* octree depth */
char depth;
@@ -1257,6 +1272,7 @@ typedef struct RemeshModifierData {
char flag;
char mode;
char pad;
+ char pad2[4];
} RemeshModifierData;
/* Skin modifier */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 4d581b523f6..bf5b1ee6f14 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -3855,6 +3855,19 @@ static void rna_def_modifier_remesh(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL}
};
+ static EnumPropertyItem mesh_items[] = {
+ {MOD_REMESH_VERTICES, "VERTICES", 0, "Vertices", "Output a metaball surface using vertex input data"},
+ {MOD_REMESH_PARTICLES, "PARTICLES", 0, "Particles", "Output a metaball surface using particle input data"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ static EnumPropertyItem filter_items[] = {
+ {eRemeshFlag_Alive, "ALIVE", 0, "Alive", "Output a metaball surface using alive particle input data"},
+ {eRemeshFlag_Dead, "DEAD", 0, "Dead", "Output a metaball surface using dead particle input data"},
+ {eRemeshFlag_Unborn, "UNBORN", 0, "Unborn", "Output a metaball surface using unborn particle input data"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
StructRNA *srna;
PropertyRNA *prop;
@@ -3937,6 +3950,25 @@ static void rna_def_modifier_remesh(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Size",
"The base size of each metaball element");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "input", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, mesh_items);
+ RNA_def_property_flag(prop, PROP_ENUM_FLAG);
+ RNA_def_property_ui_text(prop, "Input", "Which input source to consider in remeshing");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "psys", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "psys");
+ RNA_def_property_range(prop, 0, INT_MAX);
+ RNA_def_property_ui_text(prop, "Particle System Index", "Index of the input particle system to use");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "filter", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "pflag");
+ RNA_def_property_enum_items(prop, filter_items);
+ RNA_def_property_flag(prop, PROP_ENUM_FLAG);
+ RNA_def_property_ui_text(prop, "Filter", "Which particles to consider in remeshing");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
}
static void rna_def_modifier_ocean(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c
index 39ce2c67941..5742cb2d4f8 100644
--- a/source/blender/modifiers/intern/MOD_remesh.c
+++ b/source/blender/modifiers/intern/MOD_remesh.c
@@ -29,6 +29,7 @@
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_DerivedMesh.h"
@@ -37,6 +38,7 @@
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
#include "MOD_modifiertypes.h"
@@ -63,6 +65,10 @@ static void initData(ModifierData *md)
rmd->thresh = 0.6f;
rmd->wiresize = 0.4f;
rmd->rendersize = 0.2f;
+
+ rmd->input = 0;
+ rmd->pflag = 1;
+ rmd->psys = 0;
}
static void copyData(ModifierData *md, ModifierData *target)
@@ -148,8 +154,141 @@ static void dualcon_add_quad(void *output_v, const int vert_indices[4])
output->curface++;
}
+static int get_particle_positions(RemeshModifierData *rmd, ParticleSystem *psys, float (**pos)[3])
+{
+ //take alive, for now
+ ParticleData *pa;
+ int i = 0, j = 0;
+
+ for (i = 0; i < psys->totpart; i++)
+ {
+ pa = psys->particles + i;
+ if (pa->alive == PARS_UNBORN && (rmd->pflag & eRemeshFlag_Unborn) == 0) continue;
+ if (pa->alive == PARS_ALIVE && (rmd->pflag & eRemeshFlag_Alive) == 0) continue;
+ if (pa->alive == PARS_DEAD && (rmd->pflag & eRemeshFlag_Dead) == 0) continue;
+
+ if (j == 0) {
+ (*pos) = MEM_mallocN(sizeof(float) * 3, "part pos");
+ copy_v3_v3((*pos)[0], pa->state.co);
+ j++;
+ }
+ else {
+ (*pos) = MEM_reallocN((*pos), sizeof(float) * 3 * (j+1));
+ copy_v3_v3((*pos)[j], pa->state.co);
+ j++;
+ }
+ }
+
+ return j;
+}
+
+static ParticleSystem *get_psys(RemeshModifierData *rmd, Object *ob, bool render)
+{
+ ParticleSystem *psys;
+ ModifierData *ob_md = (ModifierData*)rmd;
+
+ psys = BLI_findlink(&ob->particlesystem, rmd->psys - 1);
+ if (psys == NULL)
+ return NULL;
+
+ /* If the psys modifier is disabled we cannot use its data.
+ * First look up the psys modifier from the object, then check if it is enabled.
+ */
+
+ for (ob_md = ob->modifiers.first; ob_md; ob_md = ob_md->next) {
+ if (ob_md->type == eModifierType_ParticleSystem) {
+ ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)ob_md;
+ if (psmd->psys == psys) {
+ int required_mode;
+
+ if (render) required_mode = eModifierMode_Render;
+ else required_mode = eModifierMode_Realtime;
+
+ if (modifier_isEnabled(ob_md->scene, ob_md, required_mode))
+ {
+ return psys;
+ }
+
+ return NULL;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+static DerivedMesh *repolygonize(RemeshModifierData *rmd, DerivedMesh* derived, ParticleSystem *psys, bool render)
+{
+ DerivedMesh *dm = NULL, *result = NULL;
+ MVert *mv = NULL, *mv2 = NULL;
+ float (*pos)[3] = NULL;
+ int i = 0, n = 0;
+
+ if (((rmd->input & MOD_REMESH_VERTICES)==0) && (rmd->input & MOD_REMESH_PARTICLES))
+ {
+ //particles only
+
+ if (psys == NULL)
+ return derived;
+
+ n = get_particle_positions(rmd, psys, &pos);
+ dm = CDDM_new(n, 0, 0, 0, 0);
+ mv = dm->getVertArray(dm);
+
+ for (i = 0; i < n; i++)
+ {
+ copy_v3_v3(mv[i].co, pos[i]);
+ }
+
+ result = BKE_repolygonize_dm(dm, rmd->thresh, rmd->basesize, rmd->wiresize, rmd->rendersize, render);
+ dm->release(dm);
+
+ if (pos)
+ MEM_freeN(pos);
+
+ return result;
+ }
+ else if ((rmd->input & MOD_REMESH_VERTICES) && ((rmd->input & MOD_REMESH_PARTICLES) == 0))
+ {
+ //verts only
+ return BKE_repolygonize_dm(derived, rmd->thresh, rmd->basesize, rmd->wiresize, rmd->rendersize, render);
+ }
+ else if ((rmd->input & MOD_REMESH_VERTICES) && (rmd->input & MOD_REMESH_PARTICLES))
+ {
+ //both, for simplicity only use vert data here
+ n = 0;
+
+ if (psys)
+ n = get_particle_positions(rmd, psys, &pos);
+
+ dm = CDDM_new(n + derived->numVertData, 0, 0, 0, 0);
+ mv = dm->getVertArray(dm);
+ mv2 = derived->getVertArray(derived);
+
+ for (i = 0; i < n; i++)
+ {
+ copy_v3_v3(mv[i].co, pos[i]);
+ }
+
+ for (i = n; i < n + derived->numVertData; i++)
+ {
+ copy_v3_v3(mv[i].co, mv2[i-n].co);
+ }
+
+ result = BKE_repolygonize_dm(dm, rmd->thresh, rmd->basesize, rmd->wiresize, rmd->rendersize, render);
+ dm->release(dm);
+
+ if (pos)
+ MEM_freeN(pos);
+
+ return result;
+ }
+
+ return NULL;
+}
+
static DerivedMesh *applyModifier(ModifierData *md,
- Object *UNUSED(ob),
+ Object *ob,
DerivedMesh *dm,
ModifierApplyFlag flag)
{
@@ -198,7 +337,10 @@ static DerivedMesh *applyModifier(ModifierData *md,
result->dirty |= DM_DIRTY_NORMALS;
}
else {
- result = BKE_repolygonize_dm(dm, rmd->thresh, rmd->basesize, rmd->wiresize, rmd->rendersize, flag & MOD_APPLY_RENDER);
+ ParticleSystem* psys = NULL;
+ bool render = flag & MOD_APPLY_RENDER;
+ psys = get_psys(rmd, ob, render);
+ result = repolygonize(rmd, dm, psys, render);
}
if (result && (rmd->flag & MOD_REMESH_SMOOTH_SHADING)) {
More information about the Bf-blender-cvs
mailing list