[Bf-blender-cvs] [6bb09a50fbe] functions: support for computing vectors per particle
Jacques Lucke
noreply at git.blender.org
Wed Dec 18 13:53:25 CET 2019
Commit: 6bb09a50fbed7759b0e6f2b8e6dcd87f0ab1e1b5
Author: Jacques Lucke
Date: Wed Dec 18 11:06:55 2019 +0100
Branches: functions
https://developer.blender.org/rB6bb09a50fbed7759b0e6f2b8e6dcd87f0ab1e1b5
support for computing vectors per particle
===================================================================
M source/blender/blenlib/BLI_monotonic_allocator.h
M source/blender/simulations/bparticles/actions.cpp
M source/blender/simulations/bparticles/events.cpp
M source/blender/simulations/bparticles/forces.cpp
M source/blender/simulations/bparticles/node_frontend.cpp
M source/blender/simulations/bparticles/offset_handlers.cpp
M source/blender/simulations/bparticles/particle_function.cpp
M source/blender/simulations/bparticles/particle_function.hpp
===================================================================
diff --git a/source/blender/blenlib/BLI_monotonic_allocator.h b/source/blender/blenlib/BLI_monotonic_allocator.h
index 16e46c85007..a18369dfbdc 100644
--- a/source/blender/blenlib/BLI_monotonic_allocator.h
+++ b/source/blender/blenlib/BLI_monotonic_allocator.h
@@ -90,8 +90,8 @@ class MonotonicAllocator : NonCopyable, NonMovable {
StringRefNull copy_string(StringRef str)
{
- void *buffer = this->allocate(str.size() + 1, 1);
- memcpy(buffer, str.data(), str.size() + 1);
+ char *buffer = (char *)this->allocate(str.size() + 1, 1);
+ str.copy_to__with_null(buffer);
return StringRefNull((const char *)buffer);
}
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 7582d8ec1f2..af5297a8a06 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -54,10 +54,11 @@ void SetVelocityAction::execute(ActionInterface &interface)
{
auto velocities = interface.attributes().get<float3>("Velocity");
- auto inputs = m_inputs_fn->compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, interface.pindices(), interface.attributes());
for (uint pindex : interface.pindices()) {
- float3 velocity = inputs->get<float3>("Velocity", 0, pindex);
+ float3 velocity = inputs.get_single<float3>("Velocity", 0, pindex);
velocities[pindex] = velocity;
}
@@ -68,10 +69,11 @@ void RandomizeVelocityAction::execute(ActionInterface &interface)
{
auto velocities = interface.attributes().get<float3>("Velocity");
- auto inputs = m_inputs_fn->compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, interface.pindices(), interface.attributes());
for (uint pindex : interface.pindices()) {
- float randomness = inputs->get<float>("Randomness", 0, pindex);
+ float randomness = inputs.get_single<float>("Randomness", 0, pindex);
float3 old_velocity = velocities[pindex];
float old_speed = old_velocity.length();
@@ -86,9 +88,10 @@ void ChangeColorAction::execute(ActionInterface &interface)
{
auto colors = interface.attributes().get<rgba_f>("Color");
- auto inputs = m_inputs_fn->compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, interface.pindices(), interface.attributes());
for (uint pindex : interface.pindices()) {
- rgba_f color = inputs->get<rgba_f>("Color", 0, pindex);
+ rgba_f color = inputs.get_single<rgba_f>("Color", 0, pindex);
colors[pindex] = color;
}
}
@@ -97,9 +100,10 @@ void ChangeSizeAction::execute(ActionInterface &interface)
{
auto sizes = interface.attributes().get<float>("Size");
- auto inputs = m_inputs_fn->compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, interface.pindices(), interface.attributes());
for (uint pindex : interface.pindices()) {
- float size = inputs->get<float>("Size", 0, pindex);
+ float size = inputs.get_single<float>("Size", 0, pindex);
sizes[pindex] = size;
}
}
@@ -108,9 +112,10 @@ void ChangePositionAction::execute(ActionInterface &interface)
{
auto positions = interface.attributes().get<float3>("Position");
- auto inputs = m_inputs_fn->compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, interface.pindices(), interface.attributes());
for (uint pindex : interface.pindices()) {
- float3 position = inputs->get<float3>("Position", 0, pindex);
+ float3 position = inputs.get_single<float3>("Position", 0, pindex);
positions[pindex] = position;
}
}
@@ -128,11 +133,12 @@ void ExplodeAction::execute(ActionInterface &interface)
Vector<float3> new_velocities;
Vector<float> new_birth_times;
- auto inputs = m_inputs_fn->compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, interface.pindices(), interface.attributes());
for (uint pindex : interface.pindices()) {
- uint parts_amount = std::max(0, inputs->get<int>("Amount", 0, pindex));
- float speed = inputs->get<float>("Speed", 1, pindex);
+ uint parts_amount = std::max(0, inputs.get_single<int>("Amount", 0, pindex));
+ float speed = inputs.get_single<float>("Speed", 1, pindex);
new_positions.append_n_times(positions[pindex], parts_amount);
new_birth_times.append_n_times(interface.current_times()[pindex], parts_amount);
@@ -156,11 +162,12 @@ void ExplodeAction::execute(ActionInterface &interface)
void ConditionAction::execute(ActionInterface &interface)
{
- auto inputs = m_inputs_fn->compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, interface.pindices(), interface.attributes());
Vector<uint> true_pindices, false_pindices;
for (uint pindex : interface.pindices()) {
- if (inputs->get<bool>("Condition", 0, pindex)) {
+ if (inputs.get_single<bool>("Condition", 0, pindex)) {
true_pindices.append(pindex);
}
else {
@@ -204,9 +211,11 @@ void SetAttributeAction::execute(ActionInterface &interface)
GenericMutableArrayRef attribute = *attribute_opt;
- auto inputs = m_inputs_fn.compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ m_inputs_fn, interface.pindices(), interface.attributes());
+
for (uint pindex : interface.pindices()) {
- void *value = inputs->get("Value", 0, pindex);
+ const void *value = inputs.get_single("Value", 0, pindex);
void *dst = attribute[pindex];
m_attribute_type.copy_to_initialized(value, dst);
}
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 56e5cae9de3..3ff0af6f594 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -15,12 +15,13 @@ void AgeReachedEvent::filter(EventFilterInterface &interface)
AttributesRef attributes = interface.attributes();
auto ids = attributes.get<int32_t>("ID");
- auto inputs = m_inputs_fn->compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, interface.pindices(), interface.attributes());
LargeScopedArray<float> trigger_ages(attributes.size());
for (uint pindex : interface.pindices()) {
- float age = inputs->get<float>("Age", 0, pindex);
- float variation = inputs->get<float>("Variation", 1, pindex);
+ float age = inputs.get_single<float>("Age", 0, pindex);
+ float variation = inputs.get_single<float>("Variation", 1, pindex);
int32_t id = ids[pindex];
float random_factor = BLI_hash_int_01(id);
trigger_ages[pindex] = age + random_factor * variation;
@@ -81,10 +82,11 @@ void CustomEvent::filter(EventFilterInterface &interface)
}
}
- auto inputs = m_inputs_fn->compute(pindices_to_check, interface.attributes());
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, pindices_to_check, interface.attributes());
for (uint pindex : pindices_to_check) {
- bool condition = inputs->get<bool>("Condition", 0, pindex);
+ bool condition = inputs.get_single<bool>("Condition", 0, pindex);
if (condition) {
interface.trigger_particle(pindex, 0.0f);
}
diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp
index bef5794c5e6..015fa62bcde 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -12,10 +12,11 @@ void CustomForce::add_force(ForceInterface &interface)
{
MutableArrayRef<float3> dst = interface.combined_destination();
- auto inputs = m_inputs_fn->compute(interface);
+ auto inputs = ParticleFunctionResult::Compute(
+ *m_inputs_fn, interface.pindices(), interface.attributes());
for (uint pindex : interface.pindices()) {
- dst[pindex] += inputs->get<float3>("Force", 0, pindex);
+ dst[pindex] += inputs.get_single<float3>("Force", 0, pindex);
}
}
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index abfbb6d0e41..cbb15e3b103 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -117,33 +117,41 @@ class InlinedTreeData {
ParticleFunction *particle_function_for_all_inputs(const XNode &xnode)
{
- ScopedVector<const MFInputSocket *> sockets_to_compute;
+ Vector<const MFInputSocket *> sockets_to_compute;
+ Vector<std::string> names_to_compute;
for (const XInputSocket *xsocket : xnode.inputs()) {
if (m_inlined_tree_data_graph.is_mapped(*xsocket)) {
sockets_to_compute.append(&m_inlined_tree_data_graph.lookup_dummy_socket(*xsocket));
+ names_to_compute.append(xsocket->name());
}
}
- return this->particle_function_for_sockets(sockets_to_compute);
+ return this->particle_function_for_sockets(std::move(sockets_to_compute),
+ std::move(names_to_compute));
}
ParticleFunction *particle_function_for_inputs(const XNode &xnode, ArrayRef<uint> input_indices)
{
- ScopedVector<const MFInputSocket *> sockets_to_compute;
+ Vector<const MFInputSocket *> sockets_to_compute;
+ Vector<std::string> names_to_compute;
for (uint i : input_indices) {
const MFInputSocket &socket = m_inlined_tree_data_graph.lookup_dummy_socket(xnode.input(i));
sockets_to_compute.append(&socket);
+ names_to_compute.append(xnode.input(i).name());
}
- return this->particle_function_for_sockets(sockets_to_compute);
+ return this->particle_function_for_sockets(std::move(sockets_to_compute),
+ std::move(names_to_compute));
}
- ParticleFunction *particle_function_for_sockets(Vector<const MFInputSocket *> sockets_to_compute)
+ ParticleFunction *particle_function_for_sockets(Vector<const MFInputSocket *> sockets_to_compute,
+ Vector<std::string> names_to_compute)
{
+
const MultiFunction &fn = this->construct<FN::MF_EvaluateNetwork>(
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list