2016-05-07 17:47:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011-2016 Blender Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
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 18:39:14 +00:00
|
|
|
#include "graph/node.h"
|
|
|
|
#include "graph/node_type.h"
|
2016-05-07 17:47:37 +00: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 18:39:14 +00:00
|
|
|
#include "util/util_foreach.h"
|
2018-01-24 19:19:48 +00:00
|
|
|
#include "util/util_md5.h"
|
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 18:39:14 +00:00
|
|
|
#include "util/util_param.h"
|
|
|
|
#include "util/util_transform.h"
|
2016-05-07 17:47:37 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Node 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 21:20:51 +00:00
|
|
|
NodeOwner::~NodeOwner()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
Node::Node(const NodeType *type_, ustring name_) : name(name_), type(type_)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(type);
|
2016-05-07 17:47:37 +00:00
|
|
|
|
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 21:20:51 +00:00
|
|
|
owner = nullptr;
|
2020-11-09 13:05:18 +00: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 21:20:51 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
/* assign non-empty name, convenient for debugging */
|
|
|
|
if (name.empty()) {
|
|
|
|
name = type->name;
|
|
|
|
}
|
2016-05-07 17:47:37 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
/* initialize default values */
|
|
|
|
foreach (const SocketType &socket, type->inputs) {
|
|
|
|
set_default_value(socket);
|
|
|
|
}
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node::~Node()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-22 17:42:45 +00:00
|
|
|
#ifndef NDEBUG
|
2019-04-17 04:17:24 +00:00
|
|
|
static bool is_socket_float3(const SocketType &socket)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
return socket.type == SocketType::COLOR || socket.type == SocketType::POINT ||
|
|
|
|
socket.type == SocketType::VECTOR || socket.type == SocketType::NORMAL;
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
static bool is_socket_array_float3(const SocketType &socket)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
return socket.type == SocketType::COLOR_ARRAY || socket.type == SocketType::POINT_ARRAY ||
|
|
|
|
socket.type == SocketType::VECTOR_ARRAY || socket.type == SocketType::NORMAL_ARRAY;
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
2016-05-22 17:42:45 +00:00
|
|
|
#endif
|
2016-05-07 17:47:37 +00:00
|
|
|
|
|
|
|
/* set values */
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, bool value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::BOOLEAN);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, int value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert((input.type == SocketType::INT || input.type == SocketType::ENUM));
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, uint value)
|
2016-06-12 15:12:25 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::UINT);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-06-12 15:12:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, float value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::FLOAT);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, float2 value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2020-10-08 22:04:48 +00:00
|
|
|
assert(input.type == SocketType::POINT2);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, float3 value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(is_socket_float3(input));
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, const char *value)
|
2016-05-07 22:28:21 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
set(input, ustring(value));
|
2016-05-07 22:28:21 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, ustring value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
if (input.type == SocketType::STRING) {
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
else if (input.type == SocketType::ENUM) {
|
|
|
|
const NodeEnum &enm = *input.enum_values;
|
|
|
|
if (enm.exists(value)) {
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, enm[value]);
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(0);
|
|
|
|
}
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, const Transform &value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::TRANSFORM);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, Node *value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2020-05-12 08:57:04 +00:00
|
|
|
assert(input.type == SocketType::NODE);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set array values */
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, array<bool> &value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::BOOLEAN_ARRAY);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, array<int> &value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::INT_ARRAY);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, array<float> &value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::FLOAT_ARRAY);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, array<float2> &value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2020-10-08 22:04:48 +00:00
|
|
|
assert(input.type == SocketType::POINT2_ARRAY);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, array<float3> &value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(is_socket_array_float3(input));
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, array<ustring> &value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::STRING_ARRAY);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, array<Transform> &value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::TRANSFORM_ARRAY);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set(const SocketType &input, array<Node *> &value)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2020-10-08 22:04:48 +00:00
|
|
|
assert(input.type == SocketType::NODE_ARRAY);
|
2020-09-22 12:47:10 +00:00
|
|
|
set_if_different(input, value);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get values */
|
2019-04-17 04:17:24 +00:00
|
|
|
bool Node::get_bool(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::BOOLEAN);
|
|
|
|
return get_socket_value<bool>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
int Node::get_int(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::INT || input.type == SocketType::ENUM);
|
|
|
|
return get_socket_value<int>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
uint Node::get_uint(const SocketType &input) const
|
2016-06-12 15:12:25 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::UINT);
|
|
|
|
return get_socket_value<uint>(this, input);
|
2016-06-12 15:12:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
float Node::get_float(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::FLOAT);
|
|
|
|
return get_socket_value<float>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
float2 Node::get_float2(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2020-05-12 08:57:04 +00:00
|
|
|
assert(input.type == SocketType::POINT2);
|
2019-04-17 04:17:24 +00:00
|
|
|
return get_socket_value<float2>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
float3 Node::get_float3(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(is_socket_float3(input));
|
|
|
|
return get_socket_value<float3>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
ustring Node::get_string(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
if (input.type == SocketType::STRING) {
|
|
|
|
return get_socket_value<ustring>(this, input);
|
|
|
|
}
|
|
|
|
else if (input.type == SocketType::ENUM) {
|
|
|
|
const NodeEnum &enm = *input.enum_values;
|
|
|
|
int intvalue = get_socket_value<int>(this, input);
|
|
|
|
return (enm.exists(intvalue)) ? enm[intvalue] : ustring();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(0);
|
|
|
|
return ustring();
|
|
|
|
}
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
Transform Node::get_transform(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::TRANSFORM);
|
|
|
|
return get_socket_value<Transform>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
Node *Node::get_node(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::NODE);
|
|
|
|
return get_socket_value<Node *>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get array values */
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<bool> &Node::get_bool_array(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::BOOLEAN_ARRAY);
|
|
|
|
return get_socket_value<array<bool>>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<int> &Node::get_int_array(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::INT_ARRAY);
|
|
|
|
return get_socket_value<array<int>>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<float> &Node::get_float_array(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::FLOAT_ARRAY);
|
|
|
|
return get_socket_value<array<float>>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<float2> &Node::get_float2_array(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2020-05-12 08:57:04 +00:00
|
|
|
assert(input.type == SocketType::POINT2_ARRAY);
|
2019-04-17 04:17:24 +00:00
|
|
|
return get_socket_value<array<float2>>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<float3> &Node::get_float3_array(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(is_socket_array_float3(input));
|
|
|
|
return get_socket_value<array<float3>>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<ustring> &Node::get_string_array(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::STRING_ARRAY);
|
|
|
|
return get_socket_value<array<ustring>>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<Transform> &Node::get_transform_array(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::TRANSFORM_ARRAY);
|
|
|
|
return get_socket_value<array<Transform>>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<Node *> &Node::get_node_array(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(input.type == SocketType::NODE_ARRAY);
|
|
|
|
return get_socket_value<array<Node *>>(this, input);
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 09:20:10 +00:00
|
|
|
/* generic value operations */
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
bool Node::has_default_value(const SocketType &input) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
const void *src = input.default_value;
|
|
|
|
void *dst = &get_socket_value<char>(this, input);
|
|
|
|
return memcmp(dst, src, input.size()) == 0;
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::set_default_value(const SocketType &socket)
|
2016-05-29 09:20:10 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
const void *src = socket.default_value;
|
|
|
|
void *dst = ((char *)this) + socket.struct_offset;
|
2019-06-21 14:24:56 +00:00
|
|
|
if (socket.size() > 0) {
|
|
|
|
memcpy(dst, src, socket.size());
|
|
|
|
}
|
2016-05-29 09:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2019-04-17 04:17:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::copy_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
|
|
|
|
{
|
|
|
|
assert(socket.type == other_socket.type);
|
|
|
|
|
|
|
|
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;
|
|
|
|
case SocketType::VECTOR_ARRAY:
|
|
|
|
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 00:23:34 +00:00
|
|
|
case SocketType::NODE_ARRAY: {
|
2019-04-17 04:17:24 +00:00
|
|
|
copy_array<void *>(this, socket, &other, other_socket);
|
2021-05-02 00:23:34 +00:00
|
|
|
|
|
|
|
array<Node *> &node_array = get_socket_value<array<Node *>>(this, socket);
|
|
|
|
|
2021-05-03 02:42:39 +00:00
|
|
|
for (Node *node : node_array) {
|
2021-05-02 00:23:34 +00:00
|
|
|
node->reference();
|
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
break;
|
2021-05-02 00:23:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 00:23:34 +00:00
|
|
|
|
|
|
|
if (socket.type == SocketType::NODE) {
|
|
|
|
Node *node = get_socket_value<Node *>(this, socket);
|
|
|
|
|
|
|
|
if (node) {
|
|
|
|
node->reference();
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
2016-05-29 09:20:10 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 10:17:38 +00: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;
|
|
|
|
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 17:47:37 +00:00
|
|
|
template<typename T>
|
2019-04-17 04:17:24 +00:00
|
|
|
static bool is_array_equal(const Node *node, const Node *other, const SocketType &socket)
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
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;
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:28:34 +00:00
|
|
|
template<typename T>
|
2019-04-17 04:17:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Node::equals_value(const Node &other, const SocketType &socket) const
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
case SocketType::UNDEFINED:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-05-29 09:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* equals */
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
bool Node::equals(const Node &other) const
|
2016-05-07 17:47:37 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(type == other.type);
|
2016-05-07 17:47:37 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
foreach (const SocketType &socket, type->inputs) {
|
|
|
|
if (!equals_value(other, socket))
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-07 17:47:37 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
return true;
|
2016-05-07 17:47:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 19:19:48 +00:00
|
|
|
/* Hash */
|
|
|
|
|
2018-07-27 09:40:44 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
template<typename T> void value_hash(const Node *node, const SocketType &socket, MD5Hash &md5)
|
2018-02-15 14:28:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
md5.append(((uint8_t *)node) + socket.struct_offset, socket.size());
|
2018-02-15 14:28:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void float3_hash(const Node *node, const SocketType &socket, MD5Hash &md5)
|
2018-02-15 14:28:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
/* Don't compare 4th element used for padding. */
|
|
|
|
md5.append(((uint8_t *)node) + socket.struct_offset, sizeof(float) * 3);
|
2018-02-15 14:28:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
template<typename T> void array_hash(const Node *node, const SocketType &socket, MD5Hash &md5)
|
2018-02-15 14:28:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<T> &a = *(const array<T> *)(((char *)node) + socket.struct_offset);
|
|
|
|
for (size_t i = 0; i < a.size(); i++) {
|
|
|
|
md5.append((uint8_t *)&a[i], sizeof(T));
|
|
|
|
}
|
2018-02-15 14:28:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void float3_array_hash(const Node *node, const SocketType &socket, MD5Hash &md5)
|
2018-02-15 14:28:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
/* Don't compare 4th element used for padding. */
|
|
|
|
const array<float3> &a = *(const array<float3> *)(((char *)node) + socket.struct_offset);
|
|
|
|
for (size_t i = 0; i < a.size(); i++) {
|
|
|
|
md5.append((uint8_t *)&a[i], sizeof(float) * 3);
|
|
|
|
}
|
2018-02-15 14:28:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 09:40:44 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void Node::hash(MD5Hash &md5)
|
|
|
|
{
|
|
|
|
md5.append(type->name.string());
|
|
|
|
|
|
|
|
foreach (const SocketType &socket, type->inputs) {
|
|
|
|
md5.append(socket.name.string());
|
|
|
|
|
|
|
|
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;
|
|
|
|
case SocketType::COLOR:
|
|
|
|
float3_hash(this, socket, md5);
|
|
|
|
break;
|
|
|
|
case SocketType::VECTOR:
|
|
|
|
float3_hash(this, socket, md5);
|
|
|
|
break;
|
|
|
|
case SocketType::POINT:
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case SocketType::UNDEFINED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-01-24 19:19:48 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 09:40:44 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
template<typename T> size_t array_size_in_bytes(const Node *node, const SocketType &socket)
|
2018-07-27 09:40:44 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
const array<T> &a = *(const array<T> *)(((char *)node) + socket.struct_offset);
|
|
|
|
return a.size() * sizeof(T);
|
2018-07-27 09:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
size_t Node::get_total_size_in_bytes() const
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
size_t total_size = 0;
|
|
|
|
foreach (const SocketType &socket, type->inputs) {
|
|
|
|
switch (socket.type) {
|
|
|
|
case SocketType::BOOLEAN:
|
|
|
|
case SocketType::FLOAT:
|
|
|
|
case SocketType::INT:
|
|
|
|
case SocketType::UINT:
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case SocketType::UNDEFINED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return total_size;
|
2018-07-27 09:40:44 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 08:02:00 +00: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 21:20:51 +00:00
|
|
|
const NodeOwner *Node::get_owner() const
|
|
|
|
{
|
|
|
|
return owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::set_owner(const NodeOwner *owner_)
|
|
|
|
{
|
2020-09-01 09:45:22 +00: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 21:20:51 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 00:23:34 +00:00
|
|
|
void Node::dereference_all_used_nodes()
|
|
|
|
{
|
|
|
|
foreach (const SocketType &socket, type->inputs) {
|
|
|
|
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 12:47:10 +00:00
|
|
|
bool Node::socket_is_modified(const SocketType &input) const
|
|
|
|
{
|
|
|
|
return (socket_modified & input.modified_flag_bit) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Node::is_modified()
|
|
|
|
{
|
|
|
|
return socket_modified != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::tag_modified()
|
|
|
|
{
|
2020-11-09 13:05:18 +00:00
|
|
|
socket_modified = ~0ull;
|
2020-09-22 12:47:10 +00: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 00:23:34 +00: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 12:47:10 +00: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 00:23:34 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
array<Node *> &old_nodes = get_socket_value<array<Node *>>(this, input);
|
|
|
|
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 12:47:10 +00:00
|
|
|
void Node::print_modified_sockets() const
|
|
|
|
{
|
|
|
|
printf("Node : %s\n", name.c_str());
|
|
|
|
for (auto &socket : type->inputs) {
|
|
|
|
if (socket_is_modified(socket)) {
|
|
|
|
printf("-- socket modified : %s\n", socket.name.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-07 17:47:37 +00:00
|
|
|
CCL_NAMESPACE_END
|