2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2016-05-07 19:47:37 +02:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "graph/node.h"
|
|
|
|
|
#include "graph/node_type.h"
|
2016-05-07 19:47:37 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/md5.h"
|
|
|
|
|
#include "util/param.h"
|
|
|
|
|
#include "util/transform.h"
|
2016-05-07 19:47:37 +02:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
/* Node Type */
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
NodeOwner::~NodeOwner() = default;
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
|
2016-05-07 19:47:37 +02:00
|
|
|
Node::Node(const NodeType *type_, ustring name_) : name(name_), type(type_)
|
|
|
|
|
{
|
|
|
|
|
assert(type);
|
|
|
|
|
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
owner = nullptr;
|
2020-11-09 14:05:18 +01:00
|
|
|
tag_modified();
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
|
2016-05-07 19:47:37 +02:00
|
|
|
/* assign non-empty name, convenient for debugging */
|
|
|
|
|
if (name.empty()) {
|
|
|
|
|
name = type->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* initialize default values */
|
2024-12-26 19:41:25 +01:00
|
|
|
for (const SocketType &socket : type->inputs) {
|
2016-05-29 11:20:10 +02:00
|
|
|
set_default_value(socket);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
Node::~Node() {}
|
2016-05-07 19:47:37 +02:00
|
|
|
|
2016-05-22 19:42:45 +02:00
|
|
|
#ifndef NDEBUG
|
2016-05-07 19:47:37 +02:00
|
|
|
static bool is_socket_float3(const SocketType &socket)
|
|
|
|
|
{
|
|
|
|
|
return socket.type == SocketType::COLOR || socket.type == SocketType::POINT ||
|
|
|
|
|
socket.type == SocketType::VECTOR || socket.type == SocketType::NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool is_socket_array_float3(const SocketType &socket)
|
|
|
|
|
{
|
|
|
|
|
return socket.type == SocketType::COLOR_ARRAY || socket.type == SocketType::POINT_ARRAY ||
|
|
|
|
|
socket.type == SocketType::VECTOR_ARRAY || socket.type == SocketType::NORMAL_ARRAY;
|
|
|
|
|
}
|
2016-05-22 19:42:45 +02:00
|
|
|
#endif
|
2016-05-07 19:47:37 +02:00
|
|
|
|
|
|
|
|
/* set values */
|
|
|
|
|
void Node::set(const SocketType &input, bool value)
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::BOOLEAN);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Node::set(const SocketType &input, const int value)
|
2016-05-07 19:47:37 +02:00
|
|
|
{
|
|
|
|
|
assert((input.type == SocketType::INT || input.type == SocketType::ENUM));
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Node::set(const SocketType &input, const uint value)
|
2016-06-12 17:12:25 +02:00
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::UINT);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-06-12 17:12:25 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Node::set(const SocketType &input, const uint64_t value)
|
2023-05-24 13:36:13 +02:00
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::UINT64);
|
|
|
|
|
set_if_different(input, value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Node::set(const SocketType &input, const float value)
|
2016-05-07 19:47:37 +02:00
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::FLOAT);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Node::set(const SocketType &input, const float2 value)
|
2016-05-07 19:47:37 +02:00
|
|
|
{
|
2020-10-09 00:04:48 +02:00
|
|
|
assert(input.type == SocketType::POINT2);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Node::set(const SocketType &input, const float3 value)
|
2016-05-07 19:47:37 +02:00
|
|
|
{
|
|
|
|
|
assert(is_socket_float3(input));
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-08 00:28:21 +02:00
|
|
|
void Node::set(const SocketType &input, const char *value)
|
|
|
|
|
{
|
|
|
|
|
set(input, ustring(value));
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 19:47:37 +02:00
|
|
|
void Node::set(const SocketType &input, ustring value)
|
|
|
|
|
{
|
|
|
|
|
if (input.type == SocketType::STRING) {
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
else if (input.type == SocketType::ENUM) {
|
|
|
|
|
const NodeEnum &enm = *input.enum_values;
|
|
|
|
|
if (enm.exists(value)) {
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, enm[value]);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set(const SocketType &input, const Transform &value)
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::TRANSFORM);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set(const SocketType &input, Node *value)
|
|
|
|
|
{
|
2020-05-12 10:57:04 +02:00
|
|
|
assert(input.type == SocketType::NODE);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set array values */
|
|
|
|
|
void Node::set(const SocketType &input, array<bool> &value)
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::BOOLEAN_ARRAY);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set(const SocketType &input, array<int> &value)
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::INT_ARRAY);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set(const SocketType &input, array<float> &value)
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::FLOAT_ARRAY);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set(const SocketType &input, array<float2> &value)
|
|
|
|
|
{
|
2020-10-09 00:04:48 +02:00
|
|
|
assert(input.type == SocketType::POINT2_ARRAY);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set(const SocketType &input, array<float3> &value)
|
|
|
|
|
{
|
|
|
|
|
assert(is_socket_array_float3(input));
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set(const SocketType &input, array<ustring> &value)
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::STRING_ARRAY);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set(const SocketType &input, array<Transform> &value)
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::TRANSFORM_ARRAY);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set(const SocketType &input, array<Node *> &value)
|
|
|
|
|
{
|
2020-10-09 00:04:48 +02:00
|
|
|
assert(input.type == SocketType::NODE_ARRAY);
|
2020-09-22 14:47:10 +02:00
|
|
|
set_if_different(input, value);
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get values */
|
|
|
|
|
bool Node::get_bool(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::BOOLEAN);
|
|
|
|
|
return get_socket_value<bool>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Node::get_int(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::INT || input.type == SocketType::ENUM);
|
|
|
|
|
return get_socket_value<int>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-12 17:12:25 +02:00
|
|
|
uint Node::get_uint(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::UINT);
|
|
|
|
|
return get_socket_value<uint>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-24 13:36:13 +02:00
|
|
|
uint64_t Node::get_uint64(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::UINT64);
|
|
|
|
|
return get_socket_value<uint64_t>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 19:47:37 +02:00
|
|
|
float Node::get_float(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::FLOAT);
|
|
|
|
|
return get_socket_value<float>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float2 Node::get_float2(const SocketType &input) const
|
|
|
|
|
{
|
2020-05-12 10:57:04 +02:00
|
|
|
assert(input.type == SocketType::POINT2);
|
2016-05-07 19:47:37 +02:00
|
|
|
return get_socket_value<float2>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float3 Node::get_float3(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(is_socket_float3(input));
|
|
|
|
|
return get_socket_value<float3>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ustring Node::get_string(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
if (input.type == SocketType::STRING) {
|
|
|
|
|
return get_socket_value<ustring>(this, input);
|
|
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (input.type == SocketType::ENUM) {
|
2016-05-07 19:47:37 +02:00
|
|
|
const NodeEnum &enm = *input.enum_values;
|
2024-12-29 17:32:00 +01:00
|
|
|
const int intvalue = get_socket_value<int>(this, input);
|
2016-05-07 19:47:37 +02:00
|
|
|
return (enm.exists(intvalue)) ? enm[intvalue] : ustring();
|
|
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
assert(0);
|
|
|
|
|
return ustring();
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Transform Node::get_transform(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::TRANSFORM);
|
|
|
|
|
return get_socket_value<Transform>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node *Node::get_node(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::NODE);
|
|
|
|
|
return get_socket_value<Node *>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get array values */
|
|
|
|
|
const array<bool> &Node::get_bool_array(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::BOOLEAN_ARRAY);
|
|
|
|
|
return get_socket_value<array<bool>>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const array<int> &Node::get_int_array(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::INT_ARRAY);
|
|
|
|
|
return get_socket_value<array<int>>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const array<float> &Node::get_float_array(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::FLOAT_ARRAY);
|
|
|
|
|
return get_socket_value<array<float>>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const array<float2> &Node::get_float2_array(const SocketType &input) const
|
|
|
|
|
{
|
2020-05-12 10:57:04 +02:00
|
|
|
assert(input.type == SocketType::POINT2_ARRAY);
|
2016-05-07 19:47:37 +02:00
|
|
|
return get_socket_value<array<float2>>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const array<float3> &Node::get_float3_array(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(is_socket_array_float3(input));
|
|
|
|
|
return get_socket_value<array<float3>>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const array<ustring> &Node::get_string_array(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::STRING_ARRAY);
|
|
|
|
|
return get_socket_value<array<ustring>>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const array<Transform> &Node::get_transform_array(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::TRANSFORM_ARRAY);
|
|
|
|
|
return get_socket_value<array<Transform>>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const array<Node *> &Node::get_node_array(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
assert(input.type == SocketType::NODE_ARRAY);
|
|
|
|
|
return get_socket_value<array<Node *>>(this, input);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-29 11:20:10 +02:00
|
|
|
/* generic value operations */
|
|
|
|
|
|
2016-05-07 19:47:37 +02:00
|
|
|
bool Node::has_default_value(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
const void *src = input.default_value;
|
|
|
|
|
void *dst = &get_socket_value<char>(this, input);
|
|
|
|
|
return memcmp(dst, src, input.size()) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
void Node::set_default_value(const SocketType &input)
|
2016-05-29 11:20:10 +02:00
|
|
|
{
|
2024-12-26 17:53:59 +01:00
|
|
|
const void *src = input.default_value;
|
|
|
|
|
void *dst = ((char *)this) + input.struct_offset;
|
|
|
|
|
if (input.size() > 0) {
|
|
|
|
|
memcpy(dst, src, input.size());
|
2019-06-21 16:24:56 +02:00
|
|
|
}
|
2016-05-29 11:20:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
static void copy_array(const Node *node,
|
|
|
|
|
const SocketType &socket,
|
|
|
|
|
const Node *other,
|
|
|
|
|
const SocketType &other_socket)
|
|
|
|
|
{
|
|
|
|
|
const array<T> *src = (const array<T> *)(((char *)other) + other_socket.struct_offset);
|
|
|
|
|
array<T> *dst = (array<T> *)(((char *)node) + socket.struct_offset);
|
|
|
|
|
*dst = *src;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-29 11:20:10 +02:00
|
|
|
void Node::copy_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
|
|
|
|
|
{
|
|
|
|
|
assert(socket.type == other_socket.type);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-29 11:20:10 +02:00
|
|
|
if (socket.is_array()) {
|
|
|
|
|
switch (socket.type) {
|
|
|
|
|
case SocketType::BOOLEAN_ARRAY:
|
|
|
|
|
copy_array<bool>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::FLOAT_ARRAY:
|
|
|
|
|
copy_array<float>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::INT_ARRAY:
|
|
|
|
|
copy_array<int>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::COLOR_ARRAY:
|
|
|
|
|
copy_array<float3>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
2018-02-15 18:13:07 +01:00
|
|
|
case SocketType::VECTOR_ARRAY:
|
2016-05-29 11:20:10 +02:00
|
|
|
copy_array<float3>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::POINT_ARRAY:
|
|
|
|
|
copy_array<float3>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::NORMAL_ARRAY:
|
|
|
|
|
copy_array<float3>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::POINT2_ARRAY:
|
|
|
|
|
copy_array<float2>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::STRING_ARRAY:
|
|
|
|
|
copy_array<ustring>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::TRANSFORM_ARRAY:
|
|
|
|
|
copy_array<Transform>(this, socket, &other, other_socket);
|
|
|
|
|
break;
|
2021-05-02 02:23:34 +02:00
|
|
|
case SocketType::NODE_ARRAY: {
|
2016-05-29 11:20:10 +02:00
|
|
|
copy_array<void *>(this, socket, &other, other_socket);
|
2021-05-02 02:23:34 +02:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const array<Node *> &node_array = get_socket_value<array<Node *>>(this, socket);
|
2021-05-02 02:23:34 +02:00
|
|
|
|
2021-05-03 04:42:39 +02:00
|
|
|
for (Node *node : node_array) {
|
2021-05-02 02:23:34 +02:00
|
|
|
node->reference();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-29 11:20:10 +02:00
|
|
|
break;
|
2021-05-02 02:23:34 +02:00
|
|
|
}
|
2016-05-29 11:20:10 +02:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2016-05-29 11:20:10 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-05-29 11:20:10 +02:00
|
|
|
else {
|
|
|
|
|
const void *src = ((char *)&other) + other_socket.struct_offset;
|
|
|
|
|
void *dst = ((char *)this) + socket.struct_offset;
|
|
|
|
|
memcpy(dst, src, socket.size());
|
2021-05-02 02:23:34 +02:00
|
|
|
|
|
|
|
|
if (socket.type == SocketType::NODE) {
|
|
|
|
|
Node *node = get_socket_value<Node *>(this, socket);
|
|
|
|
|
|
|
|
|
|
if (node) {
|
|
|
|
|
node->reference();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-29 11:20:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
void Node::set_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
|
|
|
|
|
{
|
|
|
|
|
assert(socket.type == other_socket.type);
|
|
|
|
|
(void)other_socket;
|
|
|
|
|
|
|
|
|
|
if (socket.is_array()) {
|
|
|
|
|
switch (socket.type) {
|
|
|
|
|
case SocketType::BOOLEAN_ARRAY:
|
|
|
|
|
set(socket, get_socket_value<array<bool>>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::FLOAT_ARRAY:
|
|
|
|
|
set(socket, get_socket_value<array<float>>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::INT_ARRAY:
|
|
|
|
|
set(socket, get_socket_value<array<int>>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::COLOR_ARRAY:
|
|
|
|
|
case SocketType::VECTOR_ARRAY:
|
|
|
|
|
case SocketType::POINT_ARRAY:
|
|
|
|
|
case SocketType::NORMAL_ARRAY:
|
|
|
|
|
set(socket, get_socket_value<array<float3>>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::POINT2_ARRAY:
|
|
|
|
|
set(socket, get_socket_value<array<float2>>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::STRING_ARRAY:
|
|
|
|
|
set(socket, get_socket_value<array<ustring>>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::TRANSFORM_ARRAY:
|
|
|
|
|
set(socket, get_socket_value<array<Transform>>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::NODE_ARRAY:
|
|
|
|
|
set(socket, get_socket_value<array<Node *>>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
switch (socket.type) {
|
|
|
|
|
case SocketType::BOOLEAN:
|
|
|
|
|
set(socket, get_socket_value<bool>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::FLOAT:
|
|
|
|
|
set(socket, get_socket_value<float>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::INT:
|
|
|
|
|
set(socket, get_socket_value<int>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::UINT:
|
|
|
|
|
set(socket, get_socket_value<uint>(&other, socket));
|
|
|
|
|
break;
|
2023-05-24 13:36:13 +02:00
|
|
|
case SocketType::UINT64:
|
|
|
|
|
set(socket, get_socket_value<uint64_t>(&other, socket));
|
|
|
|
|
break;
|
2020-11-04 11:17:38 +01:00
|
|
|
case SocketType::COLOR:
|
|
|
|
|
case SocketType::VECTOR:
|
|
|
|
|
case SocketType::POINT:
|
|
|
|
|
case SocketType::NORMAL:
|
|
|
|
|
set(socket, get_socket_value<float3>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::POINT2:
|
|
|
|
|
set(socket, get_socket_value<float2>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::STRING:
|
|
|
|
|
set(socket, get_socket_value<ustring>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::ENUM:
|
|
|
|
|
set(socket, get_socket_value<int>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::TRANSFORM:
|
|
|
|
|
set(socket, get_socket_value<Transform>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::NODE:
|
|
|
|
|
set(socket, get_socket_value<Node *>(&other, socket));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 19:47:37 +02:00
|
|
|
template<typename T>
|
|
|
|
|
static bool is_array_equal(const Node *node, const Node *other, const SocketType &socket)
|
|
|
|
|
{
|
|
|
|
|
const array<T> *a = (const array<T> *)(((char *)node) + socket.struct_offset);
|
|
|
|
|
const array<T> *b = (const array<T> *)(((char *)other) + socket.struct_offset);
|
|
|
|
|
return *a == *b;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 15:28:34 +01:00
|
|
|
template<typename T>
|
|
|
|
|
static bool is_value_equal(const Node *node, const Node *other, const SocketType &socket)
|
|
|
|
|
{
|
|
|
|
|
const T *a = (const T *)(((char *)node) + socket.struct_offset);
|
|
|
|
|
const T *b = (const T *)(((char *)other) + socket.struct_offset);
|
|
|
|
|
return *a == *b;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-29 11:20:10 +02:00
|
|
|
bool Node::equals_value(const Node &other, const SocketType &socket) const
|
|
|
|
|
{
|
2018-02-15 18:13:07 +01:00
|
|
|
switch (socket.type) {
|
|
|
|
|
case SocketType::BOOLEAN:
|
|
|
|
|
return is_value_equal<bool>(this, &other, socket);
|
|
|
|
|
case SocketType::FLOAT:
|
|
|
|
|
return is_value_equal<float>(this, &other, socket);
|
|
|
|
|
case SocketType::INT:
|
|
|
|
|
return is_value_equal<int>(this, &other, socket);
|
|
|
|
|
case SocketType::UINT:
|
|
|
|
|
return is_value_equal<uint>(this, &other, socket);
|
2023-05-24 13:36:13 +02:00
|
|
|
case SocketType::UINT64:
|
|
|
|
|
return is_value_equal<uint64_t>(this, &other, socket);
|
2018-02-15 18:13:07 +01:00
|
|
|
case SocketType::COLOR:
|
|
|
|
|
return is_value_equal<float3>(this, &other, socket);
|
|
|
|
|
case SocketType::VECTOR:
|
|
|
|
|
return is_value_equal<float3>(this, &other, socket);
|
|
|
|
|
case SocketType::POINT:
|
|
|
|
|
return is_value_equal<float3>(this, &other, socket);
|
|
|
|
|
case SocketType::NORMAL:
|
|
|
|
|
return is_value_equal<float3>(this, &other, socket);
|
|
|
|
|
case SocketType::POINT2:
|
|
|
|
|
return is_value_equal<float2>(this, &other, socket);
|
|
|
|
|
case SocketType::CLOSURE:
|
|
|
|
|
return true;
|
|
|
|
|
case SocketType::STRING:
|
|
|
|
|
return is_value_equal<ustring>(this, &other, socket);
|
|
|
|
|
case SocketType::ENUM:
|
|
|
|
|
return is_value_equal<int>(this, &other, socket);
|
|
|
|
|
case SocketType::TRANSFORM:
|
|
|
|
|
return is_value_equal<Transform>(this, &other, socket);
|
|
|
|
|
case SocketType::NODE:
|
|
|
|
|
return is_value_equal<void *>(this, &other, socket);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-15 18:13:07 +01:00
|
|
|
case SocketType::BOOLEAN_ARRAY:
|
|
|
|
|
return is_array_equal<bool>(this, &other, socket);
|
|
|
|
|
case SocketType::FLOAT_ARRAY:
|
|
|
|
|
return is_array_equal<float>(this, &other, socket);
|
|
|
|
|
case SocketType::INT_ARRAY:
|
|
|
|
|
return is_array_equal<int>(this, &other, socket);
|
|
|
|
|
case SocketType::COLOR_ARRAY:
|
|
|
|
|
return is_array_equal<float3>(this, &other, socket);
|
|
|
|
|
case SocketType::VECTOR_ARRAY:
|
|
|
|
|
return is_array_equal<float3>(this, &other, socket);
|
|
|
|
|
case SocketType::POINT_ARRAY:
|
|
|
|
|
return is_array_equal<float3>(this, &other, socket);
|
|
|
|
|
case SocketType::NORMAL_ARRAY:
|
|
|
|
|
return is_array_equal<float3>(this, &other, socket);
|
|
|
|
|
case SocketType::POINT2_ARRAY:
|
|
|
|
|
return is_array_equal<float2>(this, &other, socket);
|
|
|
|
|
case SocketType::STRING_ARRAY:
|
|
|
|
|
return is_array_equal<ustring>(this, &other, socket);
|
|
|
|
|
case SocketType::TRANSFORM_ARRAY:
|
|
|
|
|
return is_array_equal<Transform>(this, &other, socket);
|
|
|
|
|
case SocketType::NODE_ARRAY:
|
|
|
|
|
return is_array_equal<void *>(this, &other, socket);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-15 18:13:07 +01:00
|
|
|
case SocketType::UNDEFINED:
|
2023-05-24 13:36:13 +02:00
|
|
|
case SocketType::NUM_TYPES:
|
2018-02-15 18:13:07 +01:00
|
|
|
return true;
|
2016-05-29 11:20:10 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-15 18:13:07 +01:00
|
|
|
return true;
|
2016-05-29 11:20:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* equals */
|
|
|
|
|
|
|
|
|
|
bool Node::equals(const Node &other) const
|
2016-05-07 19:47:37 +02:00
|
|
|
{
|
|
|
|
|
assert(type == other.type);
|
|
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (const SocketType &socket : type->inputs) {
|
2023-09-17 09:01:48 +10:00
|
|
|
if (!equals_value(other, socket)) {
|
2016-05-29 11:20:10 +02:00
|
|
|
return false;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-29 11:20:10 +02:00
|
|
|
return true;
|
2016-05-07 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
2018-01-24 20:19:48 +01:00
|
|
|
/* Hash */
|
|
|
|
|
|
2018-07-27 11:40:44 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
template<typename T> void value_hash(const Node *node, const SocketType &socket, MD5Hash &md5)
|
2018-02-15 15:28:34 +01:00
|
|
|
{
|
|
|
|
|
md5.append(((uint8_t *)node) + socket.struct_offset, socket.size());
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-27 11:40:44 +02:00
|
|
|
void float3_hash(const Node *node, const SocketType &socket, MD5Hash &md5)
|
2018-02-15 15:28:34 +01:00
|
|
|
{
|
|
|
|
|
/* Don't compare 4th element used for padding. */
|
|
|
|
|
md5.append(((uint8_t *)node) + socket.struct_offset, sizeof(float) * 3);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-27 11:40:44 +02:00
|
|
|
template<typename T> void array_hash(const Node *node, const SocketType &socket, MD5Hash &md5)
|
2018-02-15 15:28:34 +01:00
|
|
|
{
|
|
|
|
|
const array<T> &a = *(const array<T> *)(((char *)node) + socket.struct_offset);
|
2018-08-24 14:36:18 +02:00
|
|
|
for (size_t i = 0; i < a.size(); i++) {
|
2018-02-15 15:28:34 +01:00
|
|
|
md5.append((uint8_t *)&a[i], sizeof(T));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-27 11:40:44 +02:00
|
|
|
void float3_array_hash(const Node *node, const SocketType &socket, MD5Hash &md5)
|
2018-02-15 15:28:34 +01:00
|
|
|
{
|
|
|
|
|
/* Don't compare 4th element used for padding. */
|
|
|
|
|
const array<float3> &a = *(const array<float3> *)(((char *)node) + socket.struct_offset);
|
2018-08-24 14:36:18 +02:00
|
|
|
for (size_t i = 0; i < a.size(); i++) {
|
2018-02-15 15:28:34 +01:00
|
|
|
md5.append((uint8_t *)&a[i], sizeof(float) * 3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-27 11:40:44 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
2018-01-24 20:19:48 +01:00
|
|
|
void Node::hash(MD5Hash &md5)
|
|
|
|
|
{
|
|
|
|
|
md5.append(type->name.string());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (const SocketType &socket : type->inputs) {
|
2018-01-24 20:19:48 +01:00
|
|
|
md5.append(socket.name.string());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-15 18:13:07 +01:00
|
|
|
switch (socket.type) {
|
|
|
|
|
case SocketType::BOOLEAN:
|
|
|
|
|
value_hash<bool>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::FLOAT:
|
|
|
|
|
value_hash<float>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::INT:
|
|
|
|
|
value_hash<int>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::UINT:
|
|
|
|
|
value_hash<uint>(this, socket, md5);
|
|
|
|
|
break;
|
2023-05-24 13:36:13 +02:00
|
|
|
case SocketType::UINT64:
|
|
|
|
|
value_hash<uint64_t>(this, socket, md5);
|
|
|
|
|
break;
|
2018-02-15 18:13:07 +01:00
|
|
|
case SocketType::COLOR:
|
|
|
|
|
float3_hash(this, socket, md5);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2018-07-27 11:40:44 +02:00
|
|
|
case SocketType::VECTOR:
|
2018-02-15 18:13:07 +01:00
|
|
|
float3_hash(this, socket, md5);
|
|
|
|
|
break;
|
2018-07-27 11:40:44 +02:00
|
|
|
case SocketType::POINT:
|
2018-02-15 18:13:07 +01:00
|
|
|
float3_hash(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::NORMAL:
|
|
|
|
|
float3_hash(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::POINT2:
|
|
|
|
|
value_hash<float2>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::CLOSURE:
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::STRING:
|
|
|
|
|
value_hash<ustring>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::ENUM:
|
|
|
|
|
value_hash<int>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::TRANSFORM:
|
|
|
|
|
value_hash<Transform>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::NODE:
|
|
|
|
|
value_hash<void *>(this, socket, md5);
|
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-15 18:13:07 +01:00
|
|
|
case SocketType::BOOLEAN_ARRAY:
|
|
|
|
|
array_hash<bool>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::FLOAT_ARRAY:
|
|
|
|
|
array_hash<float>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::INT_ARRAY:
|
|
|
|
|
array_hash<int>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::COLOR_ARRAY:
|
|
|
|
|
float3_array_hash(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::VECTOR_ARRAY:
|
|
|
|
|
float3_array_hash(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::POINT_ARRAY:
|
|
|
|
|
float3_array_hash(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::NORMAL_ARRAY:
|
|
|
|
|
float3_array_hash(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::POINT2_ARRAY:
|
|
|
|
|
array_hash<float2>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::STRING_ARRAY:
|
|
|
|
|
array_hash<ustring>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::TRANSFORM_ARRAY:
|
|
|
|
|
array_hash<Transform>(this, socket, md5);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::NODE_ARRAY:
|
|
|
|
|
array_hash<void *>(this, socket, md5);
|
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-15 18:13:07 +01:00
|
|
|
case SocketType::UNDEFINED:
|
2023-05-24 13:36:13 +02:00
|
|
|
case SocketType::NUM_TYPES:
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2018-01-24 20:19:48 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-01-24 20:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-27 11:40:44 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
template<typename T> size_t array_size_in_bytes(const Node *node, const SocketType &socket)
|
|
|
|
|
{
|
|
|
|
|
const array<T> &a = *(const array<T> *)(((char *)node) + socket.struct_offset);
|
|
|
|
|
return a.size() * sizeof(T);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
size_t Node::get_total_size_in_bytes() const
|
|
|
|
|
{
|
|
|
|
|
size_t total_size = 0;
|
2024-12-26 19:41:25 +01:00
|
|
|
for (const SocketType &socket : type->inputs) {
|
2018-07-27 11:40:44 +02:00
|
|
|
switch (socket.type) {
|
|
|
|
|
case SocketType::BOOLEAN:
|
|
|
|
|
case SocketType::FLOAT:
|
|
|
|
|
case SocketType::INT:
|
|
|
|
|
case SocketType::UINT:
|
2023-05-24 13:36:13 +02:00
|
|
|
case SocketType::UINT64:
|
2018-07-27 11:40:44 +02:00
|
|
|
case SocketType::COLOR:
|
|
|
|
|
case SocketType::VECTOR:
|
|
|
|
|
case SocketType::POINT:
|
|
|
|
|
case SocketType::NORMAL:
|
|
|
|
|
case SocketType::POINT2:
|
|
|
|
|
case SocketType::CLOSURE:
|
|
|
|
|
case SocketType::STRING:
|
|
|
|
|
case SocketType::ENUM:
|
|
|
|
|
case SocketType::TRANSFORM:
|
|
|
|
|
case SocketType::NODE:
|
|
|
|
|
total_size += socket.size();
|
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-27 11:40:44 +02:00
|
|
|
case SocketType::BOOLEAN_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<bool>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::FLOAT_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<float>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::INT_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<int>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::COLOR_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<float3>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::VECTOR_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<float3>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::POINT_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<float3>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::NORMAL_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<float3>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::POINT2_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<float2>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::STRING_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<ustring>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::TRANSFORM_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<Transform>(this, socket);
|
|
|
|
|
break;
|
|
|
|
|
case SocketType::NODE_ARRAY:
|
|
|
|
|
total_size += array_size_in_bytes<void *>(this, socket);
|
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-27 11:40:44 +02:00
|
|
|
case SocketType::UNDEFINED:
|
2023-05-24 13:36:13 +02:00
|
|
|
case SocketType::NUM_TYPES:
|
2018-07-27 11:40:44 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return total_size;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-03 09:02:00 +01:00
|
|
|
bool Node::is_a(const NodeType *type_)
|
|
|
|
|
{
|
|
|
|
|
for (const NodeType *base = type; base; base = base->base) {
|
|
|
|
|
if (base == type_) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
const NodeOwner *Node::get_owner() const
|
|
|
|
|
{
|
|
|
|
|
return owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::set_owner(const NodeOwner *owner_)
|
|
|
|
|
{
|
2020-09-01 11:45:22 +02:00
|
|
|
assert(owner_);
|
|
|
|
|
owner = owner_;
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-02 02:23:34 +02:00
|
|
|
void Node::dereference_all_used_nodes()
|
|
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (const SocketType &socket : type->inputs) {
|
2021-05-02 02:23:34 +02:00
|
|
|
if (socket.type == SocketType::NODE) {
|
|
|
|
|
Node *node = get_socket_value<Node *>(this, socket);
|
|
|
|
|
|
|
|
|
|
if (node) {
|
|
|
|
|
node->dereference();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (socket.type == SocketType::NODE_ARRAY) {
|
|
|
|
|
const array<Node *> &nodes = get_socket_value<array<Node *>>(this, socket);
|
|
|
|
|
|
|
|
|
|
for (Node *node : nodes) {
|
|
|
|
|
node->dereference();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 14:47:10 +02:00
|
|
|
bool Node::socket_is_modified(const SocketType &input) const
|
|
|
|
|
{
|
|
|
|
|
return (socket_modified & input.modified_flag_bit) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
bool Node::is_modified() const
|
2020-09-22 14:47:10 +02:00
|
|
|
{
|
|
|
|
|
return socket_modified != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::tag_modified()
|
|
|
|
|
{
|
2020-11-09 14:05:18 +01:00
|
|
|
socket_modified = ~0ull;
|
2020-09-22 14:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::clear_modified()
|
|
|
|
|
{
|
|
|
|
|
socket_modified = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T> void Node::set_if_different(const SocketType &input, T value)
|
|
|
|
|
{
|
|
|
|
|
if (get_socket_value<T>(this, input) == value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_socket_value<T>(this, input) = value;
|
|
|
|
|
socket_modified |= input.modified_flag_bit;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 02:23:34 +02:00
|
|
|
void Node::set_if_different(const SocketType &input, Node *value)
|
|
|
|
|
{
|
|
|
|
|
if (get_socket_value<Node *>(this, input) == value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node *old_node = get_socket_value<Node *>(this, input);
|
|
|
|
|
if (old_node) {
|
|
|
|
|
old_node->dereference();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
|
value->reference();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_socket_value<Node *>(this, input) = value;
|
|
|
|
|
socket_modified |= input.modified_flag_bit;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 14:47:10 +02:00
|
|
|
template<typename T> void Node::set_if_different(const SocketType &input, array<T> &value)
|
|
|
|
|
{
|
|
|
|
|
if (!socket_is_modified(input)) {
|
|
|
|
|
if (get_socket_value<array<T>>(this, input) == value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_socket_value<array<T>>(this, input).steal_data(value);
|
|
|
|
|
socket_modified |= input.modified_flag_bit;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 02:23:34 +02:00
|
|
|
void Node::set_if_different(const SocketType &input, array<Node *> &value)
|
|
|
|
|
{
|
|
|
|
|
if (!socket_is_modified(input)) {
|
|
|
|
|
if (get_socket_value<array<Node *>>(this, input) == value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const array<Node *> &old_nodes = get_socket_value<array<Node *>>(this, input);
|
2021-05-02 02:23:34 +02:00
|
|
|
for (Node *old_node : old_nodes) {
|
|
|
|
|
old_node->dereference();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Node *new_node : value) {
|
|
|
|
|
new_node->reference();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_socket_value<array<Node *>>(this, input).steal_data(value);
|
|
|
|
|
socket_modified |= input.modified_flag_bit;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 14:47:10 +02:00
|
|
|
void Node::print_modified_sockets() const
|
|
|
|
|
{
|
|
|
|
|
printf("Node : %s\n", name.c_str());
|
2024-12-26 17:53:59 +01:00
|
|
|
for (const auto &socket : type->inputs) {
|
2020-09-22 14:47:10 +02:00
|
|
|
if (socket_is_modified(socket)) {
|
|
|
|
|
printf("-- socket modified : %s\n", socket.name.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 19:47:37 +02:00
|
|
|
CCL_NAMESPACE_END
|