[Bf-blender-cvs] [f359672c358] master: Particles: spawn particles on mesh surface
Jacques Lucke
noreply at git.blender.org
Thu Jul 23 22:30:49 CEST 2020
Commit: f359672c3589c5c474abe1de78fcf39dd59e3532
Author: Jacques Lucke
Date: Thu Jul 23 22:30:05 2020 +0200
Branches: master
https://developer.blender.org/rBf359672c3589c5c474abe1de78fcf39dd59e3532
Particles: spawn particles on mesh surface
===================================================================
M source/blender/blenkernel/BKE_persistent_data_handle.hh
M source/blender/blenlib/BLI_float3.hh
M source/blender/blenlib/BLI_float4x4.hh
M source/blender/blenlib/BLI_rand.hh
A source/blender/blenlib/BLI_vector_adaptor.hh
M source/blender/blenlib/CMakeLists.txt
M source/blender/nodes/intern/node_socket.cc
M source/blender/simulation/intern/particle_mesh_emitter.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_persistent_data_handle.hh b/source/blender/blenkernel/BKE_persistent_data_handle.hh
index 721132560e3..884e4c00766 100644
--- a/source/blender/blenkernel/BKE_persistent_data_handle.hh
+++ b/source/blender/blenkernel/BKE_persistent_data_handle.hh
@@ -85,45 +85,45 @@ class PersistentObjectHandle : public PersistentIDHandle {
class PersistentDataHandleMap {
private:
- Map<int32_t, const ID *> id_by_handle_;
- Map<const ID *, int32_t> handle_by_id_;
+ Map<int32_t, ID *> id_by_handle_;
+ Map<ID *, int32_t> handle_by_id_;
public:
- void add(int32_t handle, const ID &id)
+ void add(int32_t handle, ID &id)
{
BLI_assert(handle >= 0);
handle_by_id_.add(&id, handle);
id_by_handle_.add(handle, &id);
}
- PersistentIDHandle lookup(const ID *id) const
+ PersistentIDHandle lookup(ID *id) const
{
const int handle = handle_by_id_.lookup_default(id, -1);
return PersistentIDHandle(handle);
}
- PersistentObjectHandle lookup(const Object *object) const
+ PersistentObjectHandle lookup(Object *object) const
{
- const int handle = handle_by_id_.lookup_default((const ID *)object, -1);
+ const int handle = handle_by_id_.lookup_default((ID *)object, -1);
return PersistentObjectHandle(handle);
}
- const ID *lookup(const PersistentIDHandle &handle) const
+ ID *lookup(const PersistentIDHandle &handle) const
{
- const ID *id = id_by_handle_.lookup_default(handle.handle_, nullptr);
+ ID *id = id_by_handle_.lookup_default(handle.handle_, nullptr);
return id;
}
- const Object *lookup(const PersistentObjectHandle &handle) const
+ Object *lookup(const PersistentObjectHandle &handle) const
{
- const ID *id = this->lookup((const PersistentIDHandle &)handle);
+ ID *id = this->lookup((const PersistentIDHandle &)handle);
if (id == nullptr) {
return nullptr;
}
if (GS(id->name) != ID_OB) {
return nullptr;
}
- return (const Object *)id;
+ return (Object *)id;
}
};
diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh
index b2633985ac7..13ec563578b 100644
--- a/source/blender/blenlib/BLI_float3.hh
+++ b/source/blender/blenlib/BLI_float3.hh
@@ -143,6 +143,17 @@ struct float3 {
return normalize_v3(*this);
}
+ /**
+ * Normalizes the vector inplace.
+ */
+ void normalize()
+ {
+ normalize_v3(*this);
+ }
+
+ /**
+ * Returns a normalized vector. The original vector is not changed.
+ */
float3 normalized() const
{
float3 result;
diff --git a/source/blender/blenlib/BLI_float4x4.hh b/source/blender/blenlib/BLI_float4x4.hh
index 185cffd13ac..5698d06f05d 100644
--- a/source/blender/blenlib/BLI_float4x4.hh
+++ b/source/blender/blenlib/BLI_float4x4.hh
@@ -71,8 +71,8 @@ struct float4x4 {
float4x4 inverted() const
{
- float result[4][4];
- invert_m4_m4(result, values);
+ float4x4 result;
+ invert_m4_m4(result.values, values);
return result;
}
@@ -86,6 +86,13 @@ struct float4x4 {
return this->inverted();
}
+ float4x4 transposed() const
+ {
+ float4x4 result;
+ transpose_m4_m4(result.values, values);
+ return result;
+ }
+
struct float3x3_ref {
const float4x4 &data;
diff --git a/source/blender/blenlib/BLI_rand.hh b/source/blender/blenlib/BLI_rand.hh
index 612ac0bbe19..7a98ee0f2bb 100644
--- a/source/blender/blenlib/BLI_rand.hh
+++ b/source/blender/blenlib/BLI_rand.hh
@@ -62,6 +62,15 @@ class RandomNumberGenerator {
return (int32_t)(x_ >> 17);
}
+ /**
+ * \return Random value (0..N), but never N.
+ */
+ int32_t get_int32(int32_t max_exclusive)
+ {
+ BLI_assert(max_exclusive > 0);
+ return this->get_int32() % max_exclusive;
+ }
+
/**
* \return Random value (0..1), but never 1.0.
*/
@@ -78,6 +87,35 @@ class RandomNumberGenerator {
return (float)this->get_int32() / 0x80000000;
}
+ template<typename T> void shuffle(MutableSpan<T> values)
+ {
+ /* Cannot shuffle arrays of this size yet. */
+ BLI_assert(values.size() <= INT32_MAX);
+
+ for (int i = values.size() - 1; i >= 2; i--) {
+ int j = this->get_int32(i);
+ if (i != j) {
+ std::swap(values[i], values[j]);
+ }
+ }
+ }
+
+ /**
+ * Compute uniformly distributed barycentric coordinates.
+ */
+ float3 get_barycentric_coordinates()
+ {
+ float rand1 = this->get_float();
+ float rand2 = this->get_float();
+
+ if (rand1 + rand2 > 1.0f) {
+ rand1 = 1.0f - rand1;
+ rand2 = 1.0f - rand2;
+ }
+
+ return float3(rand1, rand2, 1.0f - rand1 - rand2);
+ }
+
float2 get_unit_float2();
float3 get_unit_float3();
float2 get_triangle_sample(float2 v1, float2 v2, float2 v3);
diff --git a/source/blender/blenlib/BLI_vector_adaptor.hh b/source/blender/blenlib/BLI_vector_adaptor.hh
new file mode 100644
index 00000000000..cadffc0b445
--- /dev/null
+++ b/source/blender/blenlib/BLI_vector_adaptor.hh
@@ -0,0 +1,105 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __BLI_VECTOR_ADAPTOR_HH__
+#define __BLI_VECTOR_ADAPTOR_HH__
+
+/** \file
+ * \ingroup bli
+ *
+ * A `blender::VectorAdaptor` is a container with a fixed maximum size and does not own the
+ * underlying memory. When an adaptor is constructed, you have to provide it with an uninitialized
+ * array that will be filled when elements are added to the vector. The vector adaptor is not able
+ * to grow. Therefore, it is undefined behavior to add more elements than fit into the provided
+ * buffer.
+ */
+
+#include "BLI_span.hh"
+
+namespace blender {
+
+template<typename T> class VectorAdaptor {
+ private:
+ T *begin_;
+ T *end_;
+ T *capacity_end_;
+
+ public:
+ VectorAdaptor() : begin_(nullptr), end_(nullptr), capacity_end_(nullptr)
+ {
+ }
+
+ VectorAdaptor(T *data, int64_t capacity, int64_t size = 0)
+ : begin_(data), end_(data + size), capacity_end_(data + capacity)
+ {
+ }
+
+ VectorAdaptor(MutableSpan<T> span) : VectorAdaptor(span.data(), span.size(), 0)
+ {
+ }
+
+ void append(const T &value)
+ {
+ BLI_assert(end_ < capacity_end_);
+ new (end_) T(value);
+ end_++;
+ }
+
+ void append(T &&value)
+ {
+ BLI_assert(end_ < capacity_end_);
+ new (end_) T(std::move(value));
+ end_++;
+ }
+
+ void append_n_times(const T &value, int64_t n)
+ {
+ BLI_assert(end_ + n <= capacity_end_);
+ uninitialized_fill_n(end_, n, value);
+ end_ += n;
+ }
+
+ void extend(Span<T> values)
+ {
+ BLI_assert(end_ + values.size() <= capacity_end_);
+ uninitialized_copy_n(values.data(), values.size(), end_);
+ end_ += values.size();
+ }
+
+ int64_t capacity() const
+ {
+ return capacity_end_ - begin_;
+ }
+
+ int64_t size() const
+ {
+ return end_ - begin_;
+ }
+
+ bool is_empty() const
+ {
+ return begin_ == end_;
+ }
+
+ bool is_full() const
+ {
+ return end_ == capacity_end_;
+ }
+};
+
+} // namespace blender
+
+#endif /* __BLI_VECTOR_ADAPTOR_HH__ */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index d7d1d701bc8..db44ebe8e55 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -267,6 +267,7 @@ set(SRC
BLI_utility_mixins.hh
BLI_uvproject.h
BLI_vector.hh
+ BLI_vector_adaptor.hh
BLI_vector_set.hh
BLI_vector_set_slots.hh
BLI_vfontdata.h
diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc
index 49868505d68..57c8d51975e 100644
--- a/source/blender/nodes/intern/node_socket.cc
+++ b/source/blender/nodes/intern/node_socket.cc
@@ -586,10 +586,10 @@ static bNodeSocketType *make_socket_type_string()
class ObjectSocketMultiFunction : public blender::fn::MultiFunction {
private:
- const Object *object_;
+ Object *object_;
public:
- ObjectSocketMultiFunction(const Object *object) : object_(object)
+ ObjectSocketMultiFunction(Object *object) : object_(object)
{
blender::fn::MFSignatureBuilder signature = this->get_builder("Object Socket");
signature.depends_on_context();
@@ -631,7 +631,7 @@ static bNodeSocketType *make_socket_type_object()
return blender::fn::MFDataType::ForSingle<blender::bke::PersistentObjectHandle>();
};
socktype->expand_in_mf_network = [](blender::nodes::SocketMFNetworkBuilder &builder) {
- const Object *object = builder.socket_default_value<bNodeSocketValueObject>()->value;
+ Object *object = builder.socket_default_value<bNodeSocketValueObject>()->value;
builder.construct_generator_fn<ObjectSocketMultiFunction>(object);
};
return socktype;
diff --git a/source/blender/simulation/intern/particle_mesh_emitter.cc b/source/blender/simulation/intern/particle_mesh_emitter.cc
index ab2ee0c81ed..486cd1142c3 100644
--- a/source/blender/simulation/intern/particle_mesh_emitter.cc
+++ b/source/blender/simulation/intern/particle_mesh_emitter.cc
@@ -18,6 +18,9 @@
#include "BLI_float4x4.hh"
#include "BLI_rand.hh"
+#include "BLI_vector_adaptor.hh"
+
+#include "BKE_mesh_runtime.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -26,14 +29,14 @@
namespace blender::sim {
struct EmitterSettings {
- const Object *object;
+ Object *object;
float rate;
};
-static void compute_birth_times(float rate,
- TimeInterval emit_interval,
- ParticleMeshEmitterSimulationState &state,
- Vector<float> &r_birth_times)
+stati
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list