[Bf-blender-cvs] [940853850fb] cycles_procedural_api: use the Node::set API to set the Mesh data from another Mesh in the Blender exporter
Kévin Dietrich
noreply at git.blender.org
Tue Sep 22 14:14:46 CEST 2020
Commit: 940853850fbd70f32140a6af1796a13bcea2c242
Author: Kévin Dietrich
Date: Mon Sep 21 18:09:31 2020 +0200
Branches: cycles_procedural_api
https://developer.blender.org/rB940853850fbd70f32140a6af1796a13bcea2c242
use the Node::set API to set the Mesh data from another Mesh in the
Blender exporter
===================================================================
M intern/cycles/blender/blender_mesh.cpp
M intern/cycles/graph/node.cpp
M intern/cycles/graph/node.h
===================================================================
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 6d13848513e..865a470b437 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -1023,39 +1023,52 @@ void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph,
return;
}
- mesh->clear();
- mesh->set_used_shaders(used_shaders);
- mesh->set_time_stamp(b_depsgraph.scene().frame_current());
+ Mesh new_mesh;
+ new_mesh.set_used_shaders(used_shaders);
if (view_layer.use_surfaces) {
/* Adaptive subdivision setup. Not for baking since that requires
* exact mapping to the Blender mesh. */
if (!scene->bake_manager->get_baking()) {
- mesh->set_subdivision_type(object_subdivision_type(b_ob, preview, experimental));
+ new_mesh.set_subdivision_type(object_subdivision_type(b_ob, preview, experimental));
}
/* For some reason, meshes do not need this... */
- bool need_undeformed = mesh->need_attribute(scene, ATTR_STD_GENERATED);
+ bool need_undeformed = new_mesh.need_attribute(scene, ATTR_STD_GENERATED);
BL::Mesh b_mesh = object_to_mesh(
- b_data, b_ob, b_depsgraph, need_undeformed, mesh->get_subdivision_type());
+ b_data, b_ob, b_depsgraph, need_undeformed, new_mesh.get_subdivision_type());
if (b_mesh) {
/* Sync mesh itself. */
- if (mesh->get_subdivision_type() != Mesh::SUBDIVISION_NONE)
+ if (new_mesh.get_subdivision_type() != Mesh::SUBDIVISION_NONE)
create_subd_mesh(
- scene, mesh, b_ob, b_mesh, mesh->get_used_shaders(), dicing_rate, max_subdivisions);
+ scene, &new_mesh, b_ob, b_mesh, new_mesh.get_used_shaders(), dicing_rate, max_subdivisions);
else
- create_mesh(scene, mesh, b_mesh, mesh->get_used_shaders(), false);
+ create_mesh(scene, &new_mesh, b_mesh, new_mesh.get_used_shaders(), false);
free_object_to_mesh(b_data, b_ob, b_mesh);
}
}
/* cached velocities (e.g. from alembic archive) */
- sync_mesh_cached_velocities(b_ob, scene, mesh);
+ sync_mesh_cached_velocities(b_ob, scene, &new_mesh);
/* mesh fluid motion mantaflow */
- sync_mesh_fluid_motion(b_ob, scene, mesh);
+ sync_mesh_fluid_motion(b_ob, scene, &new_mesh);
+
+ for (const SocketType &socket : new_mesh.type->inputs) {
+ mesh->set_value(socket, new_mesh, socket);
+ }
+
+ foreach (Attribute &attr, new_mesh.attributes.attributes) {
+ mesh->attributes.attributes.push_back(std::move(attr));
+ }
+
+ foreach (Attribute &attr, new_mesh.subd_attributes.attributes) {
+ mesh->subd_attributes.attributes.push_back(std::move(attr));
+ }
+
+ mesh->set_time_stamp(b_depsgraph.scene().frame_current());
/* tag update */
bool rebuild = (mesh->triangles_is_modified()) ||
diff --git a/intern/cycles/graph/node.cpp b/intern/cycles/graph/node.cpp
index 4206f1769ea..2e8fd90c3d8 100644
--- a/intern/cycles/graph/node.cpp
+++ b/intern/cycles/graph/node.cpp
@@ -332,6 +332,17 @@ static void copy_array(const Node *node,
*dst = *src;
}
+template<typename T>
+static void steal_array(const Node *node,
+ const SocketType &socket,
+ const Node *other,
+ const SocketType &other_socket)
+{
+ array<T> *src = (array<T> *)(((char *)other) + other_socket.struct_offset);
+ array<T> *dst = (array<T> *)(((char *)node) + socket.struct_offset);
+ dst->steal_data(*src);
+}
+
void Node::copy_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
{
assert(socket.type == other_socket.type);
@@ -383,6 +394,86 @@ void Node::copy_value(const SocketType &socket, const Node &other, const SocketT
}
}
+void Node::set_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:
+ 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;
+ }
+ }
+}
+
template<typename T>
static bool is_array_equal(const Node *node, const Node *other, const SocketType &socket)
{
diff --git a/intern/cycles/graph/node.h b/intern/cycles/graph/node.h
index 81834f2f04d..a46baf1588e 100644
--- a/intern/cycles/graph/node.h
+++ b/intern/cycles/graph/node.h
@@ -140,6 +140,7 @@ struct Node {
void set_default_value(const SocketType &input);
bool equals_value(const Node &other, const SocketType &input) const;
void copy_value(const SocketType &input, const Node &other, const SocketType &other_input);
+ void set_value(const SocketType &input, const Node &other, const SocketType &other_input);
/* equals */
bool equals(const Node &other) const;
More information about the Bf-blender-cvs
mailing list