Object sockets work now, but only the new Object Transforms and the Particle Mesh Emitter node use it. The emitter does not actually use the mesh surface yet. Instead, new particles are just emitted around the origin of the object. Internally, handles to object data blocks are passed around in the network, instead of raw object pointers. Using handles has a couple of benefits: * The caller of the function has control over which handles can be resolved and therefore limit access to specific data. The set of data blocks that is accessed by a node tree should be known statically. This is necessary for a proper integration with the dependency graph. * When the pointer to an object changes (e.g. after restarting Blender), all handles are still valid. * When an object is deleted, the handle is invalidated without causing crashes. * The handle is just an integer that can be stored per particle and can be cached easily. The mapping between handles and their corresponding data blocks is stored in the Simulation data block.
175 lines
4.9 KiB
C++
175 lines
4.9 KiB
C++
/*
|
|
* 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 __FN_MULTI_FUNCTION_SIGNATURE_HH__
|
|
#define __FN_MULTI_FUNCTION_SIGNATURE_HH__
|
|
|
|
/** \file
|
|
* \ingroup fn
|
|
*
|
|
* The signature of a multi-function contains the functions name and expected parameters. New
|
|
* signatures should be build using the MFSignatureBuilder class.
|
|
*/
|
|
|
|
#include "FN_multi_function_param_type.hh"
|
|
|
|
#include "BLI_vector.hh"
|
|
|
|
namespace blender::fn {
|
|
|
|
struct MFSignature {
|
|
std::string function_name;
|
|
/* Use RawAllocator so that a MultiFunction can have static storage duration. */
|
|
RawVector<std::string> param_names;
|
|
RawVector<MFParamType> param_types;
|
|
RawVector<int> param_data_indices;
|
|
bool depends_on_context = false;
|
|
|
|
int data_index(int param_index) const
|
|
{
|
|
return param_data_indices[param_index];
|
|
}
|
|
};
|
|
|
|
class MFSignatureBuilder {
|
|
private:
|
|
MFSignature &data_;
|
|
int span_count_ = 0;
|
|
int virtual_span_count_ = 0;
|
|
int virtual_array_span_count_ = 0;
|
|
int vector_array_count_ = 0;
|
|
|
|
public:
|
|
MFSignatureBuilder(MFSignature &data) : data_(data)
|
|
{
|
|
BLI_assert(data.param_names.is_empty());
|
|
BLI_assert(data.param_types.is_empty());
|
|
BLI_assert(data.param_data_indices.is_empty());
|
|
}
|
|
|
|
/* Input Param Types */
|
|
|
|
template<typename T> void single_input(StringRef name)
|
|
{
|
|
this->single_input(name, CPPType::get<T>());
|
|
}
|
|
void single_input(StringRef name, const CPPType &type)
|
|
{
|
|
this->input(name, MFDataType::ForSingle(type));
|
|
}
|
|
template<typename T> void vector_input(StringRef name)
|
|
{
|
|
this->vector_input(name, CPPType::get<T>());
|
|
}
|
|
void vector_input(StringRef name, const CPPType &base_type)
|
|
{
|
|
this->input(name, MFDataType::ForVector(base_type));
|
|
}
|
|
void input(StringRef name, MFDataType data_type)
|
|
{
|
|
data_.param_names.append(name);
|
|
data_.param_types.append(MFParamType(MFParamType::Input, data_type));
|
|
|
|
switch (data_type.category()) {
|
|
case MFDataType::Single:
|
|
data_.param_data_indices.append(virtual_span_count_++);
|
|
break;
|
|
case MFDataType::Vector:
|
|
data_.param_data_indices.append(virtual_array_span_count_++);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Output Param Types */
|
|
|
|
template<typename T> void single_output(StringRef name)
|
|
{
|
|
this->single_output(name, CPPType::get<T>());
|
|
}
|
|
void single_output(StringRef name, const CPPType &type)
|
|
{
|
|
this->output(name, MFDataType::ForSingle(type));
|
|
}
|
|
template<typename T> void vector_output(StringRef name)
|
|
{
|
|
this->vector_output(name, CPPType::get<T>());
|
|
}
|
|
void vector_output(StringRef name, const CPPType &base_type)
|
|
{
|
|
this->output(name, MFDataType::ForVector(base_type));
|
|
}
|
|
void output(StringRef name, MFDataType data_type)
|
|
{
|
|
data_.param_names.append(name);
|
|
data_.param_types.append(MFParamType(MFParamType::Output, data_type));
|
|
|
|
switch (data_type.category()) {
|
|
case MFDataType::Single:
|
|
data_.param_data_indices.append(span_count_++);
|
|
break;
|
|
case MFDataType::Vector:
|
|
data_.param_data_indices.append(vector_array_count_++);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Mutable Param Types */
|
|
|
|
template<typename T> void single_mutable(StringRef name)
|
|
{
|
|
this->single_mutable(name, CPPType::get<T>());
|
|
}
|
|
void single_mutable(StringRef name, const CPPType &type)
|
|
{
|
|
this->mutable_(name, MFDataType::ForSingle(type));
|
|
}
|
|
template<typename T> void vector_mutable(StringRef name)
|
|
{
|
|
this->vector_mutable(name, CPPType::get<T>());
|
|
}
|
|
void vector_mutable(StringRef name, const CPPType &base_type)
|
|
{
|
|
this->mutable_(name, MFDataType::ForVector(base_type));
|
|
}
|
|
void mutable_(StringRef name, MFDataType data_type)
|
|
{
|
|
data_.param_names.append(name);
|
|
data_.param_types.append(MFParamType(MFParamType::Mutable, data_type));
|
|
|
|
switch (data_type.category()) {
|
|
case MFDataType::Single:
|
|
data_.param_data_indices.append(span_count_++);
|
|
break;
|
|
case MFDataType::Vector:
|
|
data_.param_data_indices.append(vector_array_count_++);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Context */
|
|
|
|
/** This indicates that the function accesses the context. This disables optimizations that
|
|
* depend on the fact that the function always performes the same operation. */
|
|
void depends_on_context()
|
|
{
|
|
data_.depends_on_context = true;
|
|
}
|
|
};
|
|
|
|
} // namespace blender::fn
|
|
|
|
#endif /* __FN_MULTI_FUNCTION_SIGNATURE_HH__ */
|