[Bf-blender-cvs] [5c733ab445c] functions: move responsibility of registering attributes to node frontend
Jacques Lucke
noreply at git.blender.org
Sun Sep 22 14:16:10 CEST 2019
Commit: 5c733ab445ce571c877b22e0f44dd1ea3157d290
Author: Jacques Lucke
Date: Sun Sep 22 14:14:03 2019 +0200
Branches: functions
https://developer.blender.org/rB5c733ab445ce571c877b22e0f44dd1ea3157d290
move responsibility of registering attributes to node frontend
===================================================================
M source/blender/simulations/bparticles/event_interface.hpp
M source/blender/simulations/bparticles/events.cpp
M source/blender/simulations/bparticles/events.hpp
M source/blender/simulations/bparticles/node_frontend.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/event_interface.hpp b/source/blender/simulations/bparticles/event_interface.hpp
index 9a5ebc52d25..4e9d06daf64 100644
--- a/source/blender/simulations/bparticles/event_interface.hpp
+++ b/source/blender/simulations/bparticles/event_interface.hpp
@@ -217,13 +217,6 @@ class Event {
* already. However, the attributes of new particles can be changed.
*/
virtual void execute(EventExecuteInterface &interface) = 0;
-
- /**
- * Allows to define which attributes are required by the event.
- */
- virtual void attributes(AttributesDeclaration &UNUSED(interface))
- {
- }
};
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 21fda074c98..c844ff356f4 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -9,11 +9,6 @@ namespace BParticles {
/* Age Reached Event
******************************************/
-void AgeReachedEvent::attributes(AttributesDeclaration &builder)
-{
- builder.add<uint8_t>(m_identifier, 0);
-}
-
void AgeReachedEvent::filter(EventFilterInterface &interface)
{
AttributesRef attributes = interface.attributes();
@@ -32,7 +27,7 @@ void AgeReachedEvent::filter(EventFilterInterface &interface)
float end_time = interface.step_end_time();
auto birth_times = attributes.get<float>("Birth Time");
- auto was_activated_before = attributes.get<uint8_t>(m_identifier);
+ auto was_activated_before = attributes.get<uint8_t>(m_is_triggered_attribute);
for (uint pindex : interface.pindices()) {
if (was_activated_before[pindex]) {
@@ -61,7 +56,7 @@ void AgeReachedEvent::filter(EventFilterInterface &interface)
void AgeReachedEvent::execute(EventExecuteInterface &interface)
{
- auto was_activated_before = interface.attributes().get<uint8_t>(m_identifier);
+ auto was_activated_before = interface.attributes().get<uint8_t>(m_is_triggered_attribute);
for (uint pindex : interface.pindices()) {
was_activated_before[pindex] = true;
}
@@ -72,14 +67,9 @@ void AgeReachedEvent::execute(EventExecuteInterface &interface)
/* Custom Event
***********************************************/
-void CustomEvent::attributes(AttributesDeclaration &builder)
-{
- builder.add<uint8_t>(m_identifier, 0);
-}
-
void CustomEvent::filter(EventFilterInterface &interface)
{
- auto was_activated_before = interface.attributes().get<uint8_t>(m_identifier);
+ auto was_activated_before = interface.attributes().get<uint8_t>(m_is_triggered_attribute);
TemporaryVector<uint> pindices_to_check;
pindices_to_check.reserve(interface.pindices().size());
@@ -107,7 +97,7 @@ void CustomEvent::filter(EventFilterInterface &interface)
void CustomEvent::execute(EventExecuteInterface &interface)
{
- auto was_activated_before = interface.attributes().get<uint8_t>(m_identifier);
+ auto was_activated_before = interface.attributes().get<uint8_t>(m_is_triggered_attribute);
for (uint pindex : interface.pindices()) {
was_activated_before[pindex] = true;
}
@@ -118,11 +108,6 @@ void CustomEvent::execute(EventExecuteInterface &interface)
/* Collision Event
***********************************************/
-void MeshCollisionEvent::attributes(AttributesDeclaration &builder)
-{
- builder.add<int32_t>(m_identifier, -1);
-}
-
uint MeshCollisionEvent::storage_size()
{
return sizeof(EventStorage);
@@ -132,7 +117,7 @@ void MeshCollisionEvent::filter(EventFilterInterface &interface)
{
AttributesRef attributes = interface.attributes();
auto positions = attributes.get<float3>("Position");
- auto last_collision_step = attributes.get<int32_t>(m_identifier);
+ auto last_collision_step = attributes.get<int32_t>(m_last_collision_attribute);
auto position_offsets = interface.attribute_offsets().get<float3>("Position");
uint current_update_index = interface.simulation_state().time().current_update_index();
@@ -190,7 +175,7 @@ void MeshCollisionEvent::execute(EventExecuteInterface &interface)
TemporaryArray<float3> local_normals(array_size);
TemporaryArray<uint> looptri_indices(array_size);
- auto last_collision_step = interface.attributes().get<int32_t>(m_identifier);
+ auto last_collision_step = interface.attributes().get<int32_t>(m_last_collision_attribute);
uint current_update_index = interface.simulation_state().time().current_update_index();
for (uint pindex : interface.pindices()) {
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
index 18c707a8b28..b5a036f8cc2 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -18,41 +18,39 @@ using BLI::float4x4;
class AgeReachedEvent : public Event {
private:
- std::string m_identifier;
+ std::string m_is_triggered_attribute;
ParticleFunction *m_inputs_fn;
Action &m_action;
public:
- AgeReachedEvent(StringRef identifier, ParticleFunction *inputs_fn, Action &action)
- : m_identifier(identifier), m_inputs_fn(inputs_fn), m_action(action)
+ AgeReachedEvent(StringRef is_triggered_attribute, ParticleFunction *inputs_fn, Action &action)
+ : m_is_triggered_attribute(is_triggered_attribute), m_inputs_fn(inputs_fn), m_action(action)
{
}
- void attributes(AttributesDeclaration &builder) override;
void filter(EventFilterInterface &interface) override;
void execute(EventExecuteInterface &interface) override;
};
class CustomEvent : public Event {
private:
- std::string m_identifier;
+ std::string m_is_triggered_attribute;
ParticleFunction *m_inputs_fn;
Action &m_action;
public:
- CustomEvent(StringRef identifier, ParticleFunction *inputs_fn, Action &action)
- : m_identifier(identifier), m_inputs_fn(inputs_fn), m_action(action)
+ CustomEvent(StringRef is_triggered_attribute, ParticleFunction *inputs_fn, Action &action)
+ : m_is_triggered_attribute(is_triggered_attribute), m_inputs_fn(inputs_fn), m_action(action)
{
}
- void attributes(AttributesDeclaration &builder) override;
void filter(EventFilterInterface &interface) override;
void execute(EventExecuteInterface &interface) override;
};
class MeshCollisionEvent : public Event {
private:
- std::string m_identifier;
+ std::string m_last_collision_attribute;
Object *m_object;
BVHTreeFromMesh m_bvhtree_data;
float4x4 m_local_to_world_begin;
@@ -75,12 +73,12 @@ class MeshCollisionEvent : public Event {
};
public:
- MeshCollisionEvent(StringRef identifier,
+ MeshCollisionEvent(StringRef last_collision_attribute,
Object *object,
Action &action,
float4x4 local_to_world_begin,
float4x4 local_to_world_end)
- : m_identifier(identifier), m_object(object), m_action(action)
+ : m_last_collision_attribute(last_collision_attribute), m_object(object), m_action(action)
{
BLI_assert(object->type == OB_MESH);
m_local_to_world_begin = local_to_world_begin;
@@ -96,7 +94,6 @@ class MeshCollisionEvent : public Event {
free_bvhtree_from_mesh(&m_bvhtree_data);
}
- void attributes(AttributesDeclaration &builder) override;
uint storage_size() override;
void filter(EventFilterInterface &interface) override;
void execute(EventExecuteInterface &interface) override;
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 5ff91d73541..ce803b1c1fa 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -46,6 +46,7 @@ class InfluencesCollector {
MultiMap<std::string, Force *> &m_forces;
MultiMap<std::string, Event *> &m_events;
MultiMap<std::string, OffsetHandler *> &m_offset_handlers;
+ StringMap<AttributesDeclaration> &m_attributes;
};
class VTreeData {
@@ -508,8 +509,11 @@ static void PARSE_age_reached_event(InfluencesCollector &collector,
vnode->output(0, "Event"));
Action &action = vtree_data.build_action_list(vnode, "Execute on Event");
+ std::string is_triggered_attribute = vnode->name();
+
for (const std::string &system_name : system_names) {
- Event *event = new AgeReachedEvent(vnode->name(), inputs_fn, action);
+ collector.m_attributes.lookup(system_name).add<uint8_t>(is_triggered_attribute, 0);
+ Event *event = new AgeReachedEvent(is_triggered_attribute, inputs_fn, action);
collector.m_events.add(system_name, event);
}
}
@@ -641,9 +645,12 @@ static void PARSE_mesh_collision(InfluencesCollector &collector,
float4x4 local_to_world_begin =
world_transition.update_float4x4(object->id.name, "obmat", object->obmat).start;
+ std::string last_collision_attribute = vnode->name();
+
for (const std::string &system_name : system_names) {
Event *event = new MeshCollisionEvent(
- vnode->name(), object, action, local_to_world_begin, local_to_world_end);
+ last_collision_attribute, object, action, local_to_world_begin, local_to_world_end);
+ collector.m_attributes.lookup(system_name).add<int32_t>(last_collision_attribute, -1);
collector.m_events.add(system_name, event);
}
}
@@ -708,8 +715,11 @@ static void PARSE_custom_event(InfluencesCollector &collector,
vnode->output(0, "Event"));
Action &action = vtree_data.build_action_list(vnode, "Execute on Event");
+ std::string is_triggered_attribute = vnode->name();
+
for (const std::string &system_name : system_names) {
- Event *event = new CustomEvent(vnode->name(), inputs_fn, action);
+ Event *event = new CustomEvent(is_triggered_attribute, inputs_fn, action);
+ collector.m_attributes.lookup(system_name).add<uint8_t>(system_name, 0);
collector.m_events.add(system_name, event);
}
}
@@ -767,8 +777,15 @@ static void collect_influences(VTreeData &vtree_data,
forces,
r_events_per_type,
r_offset_handler_per_type,
+ r_attributes_per_type,
};
+ for (VirtualNode *vnode : vtree_data.vtree().nodes_with_idname(particle_system_idname
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list