[Bf-blender-cvs] [e8ecbf3a423] functions: Emit from other objects origin
Jacques Lucke
noreply at git.blender.org
Mon Jun 17 15:52:43 CEST 2019
Commit: e8ecbf3a4230138d2ea02f2a6a060219ea59815e
Author: Jacques Lucke
Date: Mon Jun 17 11:19:26 2019 +0200
Branches: functions
https://developer.blender.org/rBe8ecbf3a4230138d2ea02f2a6a060219ea59815e
Emit from other objects origin
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenlib/BLI_math.hpp
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_nodeparticles.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 b25ab0290d5..c54577ec638 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1666,6 +1666,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
def NODE_PARTICLES(self, layout, ob, md):
layout.prop(md, "control1")
layout.prop(md, "control2")
+ layout.prop(md, "emitter_object")
class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
diff --git a/source/blender/blenlib/BLI_math.hpp b/source/blender/blenlib/BLI_math.hpp
index c2a6206d6cb..9f9ab6d405e 100644
--- a/source/blender/blenlib/BLI_math.hpp
+++ b/source/blender/blenlib/BLI_math.hpp
@@ -5,6 +5,16 @@ namespace BLI {
struct float3 {
float x, y, z;
+ float3() = default;
+
+ float3(float *value) : x{value[0]}, y{value[1]}, z{value[2]}
+ {
+ }
+
+ float3(float x, float y, float z) : x{x}, y{y}, z{z}
+ {
+ }
+
friend float3 operator+(float3 a, float3 b)
{
return {a.x + b.x, a.y + b.y, a.z + b.z};
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index f16956cf8f1..cbd33856d21 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1974,6 +1974,7 @@ typedef struct FunctionPointsModifierData {
typedef struct NodeParticlesModifierData {
ModifierData modifier;
float control1, control2;
+ struct Object *emitter_object;
} NodeParticlesModifierData;
#endif /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 7ba9cb22ac4..fc0a601e5b2 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5988,6 +5988,11 @@ static void rna_def_modifier_node_particles(BlenderRNA *brna)
prop = RNA_def_float(srna, "control2", 0.0, -FLT_MAX, FLT_MAX, "Control 2", "", -10, 10);
RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "emitter_object", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Emitter Object", "Object to emit from");
+ RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
}
void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_nodeparticles.c b/source/blender/modifiers/intern/MOD_nodeparticles.c
index 0147165b6f1..013e755c0aa 100644
--- a/source/blender/modifiers/intern/MOD_nodeparticles.c
+++ b/source/blender/modifiers/intern/MOD_nodeparticles.c
@@ -37,6 +37,7 @@
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_scene.h"
+#include "BKE_library_query.h"
#include "BLI_math.h"
@@ -61,14 +62,30 @@ static RuntimeData *get_runtime_data(NodeParticlesModifierData *npmd)
return data;
}
-static void ensure_runtime_data(NodeParticlesModifierData *npmd)
+static BParticlesDescription create_current_description(Object *self,
+ NodeParticlesModifierData *npmd,
+ Depsgraph *depsgraph)
+{
+ float position[3] = {0, 0, 0};
+ if (npmd->emitter_object != NULL) {
+ Object *emitter_eval = DEG_get_evaluated_object(depsgraph, npmd->emitter_object);
+ copy_v3_v3(position, emitter_eval->loc);
+ }
+ mul_m4_v3(self->imat, position);
+ return BParticles_playground_description(npmd->control1, npmd->control2, position);
+}
+
+static void ensure_runtime_data(Object *self,
+ NodeParticlesModifierData *npmd,
+ Depsgraph *depsgraph)
{
if (npmd->modifier.runtime != NULL) {
return;
}
RuntimeData *runtime = MEM_callocN(sizeof(RuntimeData), __func__);
- runtime->description = BParticles_playground_description(npmd->control1, npmd->control2);
+
+ runtime->description = create_current_description(self, npmd, depsgraph);
runtime->solver = BParticles_solver_build(runtime->description);
runtime->state = BParticles_state_init(runtime->solver);
runtime->last_simulated_frame = 0.0f;
@@ -97,7 +114,7 @@ static Mesh *applyModifier(ModifierData *md,
Mesh *UNUSED(mesh))
{
NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md;
- ensure_runtime_data(npmd);
+ ensure_runtime_data(ctx->object, npmd, ctx->depsgraph);
RuntimeData *runtime = get_runtime_data(npmd);
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
@@ -105,8 +122,8 @@ static Mesh *applyModifier(ModifierData *md,
float fps = FPS;
if (current_frame != runtime->last_simulated_frame) {
- BParticlesDescription new_description = BParticles_playground_description(npmd->control1,
- npmd->control2);
+ BParticlesDescription new_description = create_current_description(
+ ctx->object, npmd, ctx->depsgraph);
BParticlesSolver new_solver = BParticles_solver_build(new_description);
if (current_frame == runtime->last_simulated_frame + 1) {
@@ -170,9 +187,20 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
return true;
}
-static void updateDepsgraph(ModifierData *UNUSED(md),
- const ModifierUpdateDepsgraphContext *UNUSED(ctx))
+static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
+{
+ NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md;
+ if (npmd->emitter_object) {
+ DEG_add_object_relation(
+ ctx->node, npmd->emitter_object, DEG_OB_COMP_TRANSFORM, "Node Particles Modifier");
+ }
+}
+
+static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
{
+ NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md;
+
+ walk(userData, ob, &npmd->emitter_object, IDWALK_CB_NOP);
}
static void foreachIDLink(ModifierData *UNUSED(md),
@@ -203,7 +231,7 @@ ModifierTypeInfo modifierType_NodeParticles = {
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
- /* foreachObjectLink */ NULL,
+ /* foreachObjectLink */ foreachObjectLink,
/* foreachIDLink */ foreachIDLink,
/* foreachTexLink */ NULL,
/* freeRuntimeData */ freeRuntimeData,
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 3acf8d8be8d..2a76f770bbb 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -12,7 +12,9 @@ typedef struct OpaqueBParticlesDescription *BParticlesDescription;
typedef struct OpaqueBParticlesSolver *BParticlesSolver;
typedef struct OpaqueBParticlesState *BParticlesState;
-BParticlesDescription BParticles_playground_description(float control1, float control2);
+BParticlesDescription BParticles_playground_description(float control1,
+ float control2,
+ float *emitter_position);
void BParticles_description_free(BParticlesDescription description);
BParticlesSolver BParticles_solver_build(BParticlesDescription description);
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 2efbb585040..f4531f035fa 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -94,9 +94,11 @@ class TestEmitter : public BParticles::Emitter {
}
};
-BParticlesDescription BParticles_playground_description(float control1, float control2)
+BParticlesDescription BParticles_playground_description(float control1,
+ float control2,
+ float *emitter_position)
{
- auto emitter = BParticles::new_point_emitter({4, 4, 4});
+ auto emitter = BParticles::new_point_emitter(emitter_position);
Description *description = new Description(
{new TestForce(control1), new TurbulenceForce(control2)}, {emitter.release()});
More information about the Bf-blender-cvs
mailing list