[Bf-blender-cvs] [da598e31ebf] functions: support for outputting None/Points/Tetrahedons
Jacques Lucke
noreply at git.blender.org
Fri Sep 6 17:46:19 CEST 2019
Commit: da598e31ebfb2d86f916eba4ae001df1255507e2
Author: Jacques Lucke
Date: Fri Sep 6 17:44:25 2019 +0200
Branches: functions
https://developer.blender.org/rBda598e31ebfb2d86f916eba4ae001df1255507e2
support for outputting None/Points/Tetrahedons
===================================================================
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_bparticles_output.c
M source/blender/simulations/BParticles.h
M source/blender/simulations/bparticles/c_wrapper.cpp
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 374fd656e55..a87ca649ca7 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1675,6 +1675,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
def BPARTICLES_OUTPUT(self, layout, ob, md):
layout.prop(md, "source_object")
layout.prop(md, "source_particle_type")
+ layout.prop(md, "output_type")
class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index d843994c6d0..f785ef39f2a 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -2002,6 +2002,8 @@ typedef struct BParticlesOutputModifierData {
ModifierData modifier;
struct Object *source_object;
char source_particle_type[64];
+ unsigned int output_type;
+ char _pad[4];
} 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 22246d5a8dd..fcb57869322 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -6046,6 +6046,21 @@ static void rna_def_modifier_function_points(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
}
+const static EnumPropertyItem bparticles_output_type_items[] = {
+ {MOD_BPARTICLES_OUTPUT_POINTS,
+ "POINTS",
+ 0,
+ "Points",
+ "Create a mesh containing only vertices"},
+ {MOD_BPARTICLES_OUTPUT_TETRAHEDONS,
+ "TETRAHEDONS",
+ 0,
+ "Tetrahedons",
+ "Create a mesh that has a tetrahedon at every vertex position"},
+ {MOD_BPARTICLES_OUTPUT_NONE, "NONE", 0, "None", "Create no output mesh"},
+ {0, NULL, 0, NULL, NULL},
+};
+
static void rna_def_modifier_bparticles(BlenderRNA *brna)
{
StructRNA *srna;
@@ -6061,23 +6076,8 @@ static void rna_def_modifier_bparticles(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "BParticles Tree", "BParticles node tree");
RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
- const static EnumPropertyItem output_types[] = {
- {MOD_BPARTICLES_OUTPUT_POINTS,
- "POINTS",
- 0,
- "Points",
- "Create a mesh containing only vertices"},
- {MOD_BPARTICLES_OUTPUT_TETRAHEDONS,
- "TETRAHEDONS",
- 0,
- "Tetrahedons",
- "Create a mesh that has a tetrahedon at every vertex position"},
- {MOD_BPARTICLES_OUTPUT_NONE, "NONE", 0, "None", "Create no output mesh"},
- {0, NULL, 0, NULL, NULL},
- };
-
prop = RNA_def_property(srna, "output_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, output_types);
+ RNA_def_property_enum_items(prop, bparticles_output_type_items);
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");
@@ -6102,6 +6102,12 @@ static void rna_def_modifier_bparticles_output(BlenderRNA *brna)
RNA_def_property_ui_text(
prop, "Particle Type", "Name of the particle type that should be copied");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "output_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, bparticles_output_type_items);
+ 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");
}
void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_bparticles_output.c b/source/blender/modifiers/intern/MOD_bparticles_output.c
index e0d8563de0b..223a5af9301 100644
--- a/source/blender/modifiers/intern/MOD_bparticles_output.c
+++ b/source/blender/modifiers/intern/MOD_bparticles_output.c
@@ -64,7 +64,16 @@ static Mesh *applyModifier(ModifierData *md,
return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
}
- return BParticles_modifier_extract_mesh(simulation_state, bpmd->source_particle_type);
+ if (bpmd->output_type == MOD_BPARTICLES_OUTPUT_TETRAHEDONS) {
+ return BParticles_state_extract_type__tetrahedons(simulation_state,
+ bpmd->source_particle_type);
+ }
+ else if (bpmd->output_type == MOD_BPARTICLES_OUTPUT_POINTS) {
+ return BParticles_state_extract_type__points(simulation_state, bpmd->source_particle_type);
+ }
+ else {
+ return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
+ }
}
static void initData(ModifierData *UNUSED(md))
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 307f217d170..2bfc888b80f 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -26,8 +26,11 @@ void BParticles_simulate_modifier(struct BParticlesModifierData *bpmd,
Mesh *BParticles_modifier_point_mesh_from_state(BParticlesSimulationState simulation_state);
Mesh *BParticles_modifier_mesh_from_state(BParticlesSimulationState simulation_state);
-Mesh *BParticles_modifier_extract_mesh(BParticlesSimulationState simulation_state,
- const char *particle_type);
+
+Mesh *BParticles_state_extract_type__tetrahedons(BParticlesSimulationState simulation_state,
+ const char *particle_type);
+Mesh *BParticles_state_extract_type__points(BParticlesSimulationState simulation_state,
+ const char *particle_type);
void BParticles_modifier_free_cache(struct BParticlesModifierData *bpmd);
struct Mesh *BParticles_modifier_mesh_from_cache(struct BParticlesFrameCache *cached_frame);
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 18187c224d0..feb2b9f4d0f 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -159,6 +159,18 @@ static Mesh *distribute_tetrahedons(ArrayRef<float3> centers,
return mesh;
}
+static Mesh *distribute_points(ArrayRef<float3> points)
+{
+ Mesh *mesh = BKE_mesh_new_nomain(points.size(), 0, 0, 0, 0);
+
+ for (uint i = 0; i < mesh->totvert; i++) {
+ copy_v3_v3(mesh->mvert[i].co, points[i]);
+ mesh->mvert[i].no[2] = 32767;
+ }
+
+ return mesh;
+}
+
void BParticles_modifier_free_cache(BParticlesModifierData *bpmd)
{
if (bpmd->cached_frames == nullptr) {
@@ -200,14 +212,7 @@ Mesh *BParticles_modifier_point_mesh_from_state(BParticlesSimulationState state_
positions.extend(container->flatten_attribute<float3>("Position"));
});
- Mesh *mesh = BKE_mesh_new_nomain(positions.size(), 0, 0, 0, 0);
-
- for (uint i = 0; i < mesh->totvert; i++) {
- copy_v3_v3(mesh->mvert[i].co, positions[i]);
- mesh->mvert[i].no[2] = 32767;
- }
-
- return mesh;
+ return distribute_points(positions);
}
Mesh *BParticles_modifier_mesh_from_state(BParticlesSimulationState state_c)
@@ -252,8 +257,8 @@ Mesh *BParticles_modifier_mesh_from_cache(BParticlesFrameCache *cached_frame)
return mesh;
}
-Mesh *BParticles_modifier_extract_mesh(BParticlesSimulationState simulation_state_c,
- const char *particle_type)
+Mesh *BParticles_state_extract_type__tetrahedons(BParticlesSimulationState simulation_state_c,
+ const char *particle_type)
{
SimulationState &state = *unwrap(simulation_state_c);
ParticlesState &particles = state.particles();
@@ -270,6 +275,21 @@ Mesh *BParticles_modifier_extract_mesh(BParticlesSimulationState simulation_stat
return distribute_tetrahedons(positions, sizes, colors);
}
+Mesh *BParticles_state_extract_type__points(BParticlesSimulationState simulation_state_c,
+ const char *particle_type)
+{
+ SimulationState &state = *unwrap(simulation_state_c);
+ ParticlesState &particles = state.particles();
+ ParticlesContainer **container_ptr = particles.particle_containers().lookup_ptr(particle_type);
+ if (container_ptr == nullptr) {
+ return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
+ }
+ ParticlesContainer &container = **container_ptr;
+
+ auto positions = container.flatten_attribute<float3>("Position");
+ return distribute_points(positions);
+}
+
void BParticles_modifier_cache_state(BParticlesModifierData *bpmd,
BParticlesSimulationState state_c,
float frame)
More information about the Bf-blender-cvs
mailing list