2020-02-02 13:09:18 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2011-2013 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
#include "render/curves.h"
|
|
|
|
|
#include "render/hair.h"
|
2020-02-02 13:09:18 +01:00
|
|
|
#include "render/mesh.h"
|
|
|
|
|
#include "render/object.h"
|
2020-08-19 15:46:50 +02:00
|
|
|
#include "render/volume.h"
|
2020-02-02 13:09:18 +01:00
|
|
|
|
|
|
|
|
#include "blender/blender_sync.h"
|
|
|
|
|
#include "blender/blender_util.h"
|
|
|
|
|
|
2020-03-11 17:59:32 +01:00
|
|
|
#include "util/util_foreach.h"
|
2020-10-21 16:38:36 +02:00
|
|
|
#include "util/util_task.h"
|
2020-03-11 17:59:32 +01:00
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2020-08-19 15:46:50 +02:00
|
|
|
static Geometry::Type determine_geom_type(BL::Object &b_ob, bool use_particle_hair)
|
|
|
|
|
{
|
|
|
|
|
if (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) {
|
|
|
|
|
return Geometry::HAIR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b_ob.type() == BL::Object::type_VOLUME || object_fluid_gas_domain_find(b_ob)) {
|
|
|
|
|
return Geometry::VOLUME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Geometry::MESH;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
|
|
|
|
|
BL::Object &b_ob,
|
|
|
|
|
BL::Object &b_ob_instance,
|
|
|
|
|
bool object_updated,
|
2020-10-21 16:38:36 +02:00
|
|
|
bool use_particle_hair,
|
|
|
|
|
TaskPool *task_pool)
|
2020-02-02 13:09:18 +01:00
|
|
|
{
|
|
|
|
|
/* Test if we can instance or if the object is modified. */
|
|
|
|
|
BL::ID b_ob_data = b_ob.data();
|
|
|
|
|
BL::ID b_key_id = (BKE_object_is_modified(b_ob)) ? b_ob_instance : b_ob_data;
|
|
|
|
|
BL::Material material_override = view_layer.material_override;
|
2020-03-17 16:52:14 +01:00
|
|
|
Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume :
|
|
|
|
|
scene->default_surface;
|
2020-08-19 15:46:50 +02:00
|
|
|
Geometry::Type geom_type = determine_geom_type(b_ob, use_particle_hair);
|
2020-10-26 12:15:52 +01:00
|
|
|
GeometryKey key(b_key_id.ptr.data, geom_type);
|
2020-02-02 13:09:18 +01:00
|
|
|
|
|
|
|
|
/* Find shader indices. */
|
2020-10-27 11:40:42 +01:00
|
|
|
vector<Shader *> used_shaders;
|
2020-02-02 13:09:18 +01:00
|
|
|
|
|
|
|
|
BL::Object::material_slots_iterator slot;
|
|
|
|
|
for (b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) {
|
|
|
|
|
if (material_override) {
|
|
|
|
|
find_shader(material_override, used_shaders, default_shader);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BL::ID b_material(slot->material());
|
|
|
|
|
find_shader(b_material, used_shaders, default_shader);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (used_shaders.size() == 0) {
|
|
|
|
|
if (material_override)
|
|
|
|
|
find_shader(material_override, used_shaders, default_shader);
|
|
|
|
|
else
|
2020-10-27 11:40:42 +01:00
|
|
|
used_shaders.push_back(default_shader);
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-21 16:38:36 +02:00
|
|
|
/* Ensure we only sync instanced geometry once. */
|
2020-02-02 12:04:19 +01:00
|
|
|
Geometry *geom = geometry_map.find(key);
|
2020-10-21 16:38:36 +02:00
|
|
|
if (geom) {
|
|
|
|
|
if (geometry_synced.find(geom) != geometry_synced.end()) {
|
|
|
|
|
return geom;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Test if we need to sync. */
|
2020-02-02 12:04:19 +01:00
|
|
|
bool sync = true;
|
|
|
|
|
if (geom == NULL) {
|
|
|
|
|
/* Add new geometry if it did not exist yet. */
|
|
|
|
|
if (geom_type == Geometry::HAIR) {
|
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
|
|
|
geom = scene->create_node<Hair>();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2020-08-19 15:46:50 +02:00
|
|
|
else if (geom_type == Geometry::VOLUME) {
|
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
|
|
|
geom = scene->create_node<Volume>();
|
2020-08-19 15:46:50 +02:00
|
|
|
}
|
2020-02-02 12:04:19 +01:00
|
|
|
else {
|
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
|
|
|
geom = scene->create_node<Mesh>();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
|
|
|
|
geometry_map.add(key, geom);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Test if we need to update existing geometry. */
|
|
|
|
|
sync = geometry_map.update(geom, b_key_id);
|
|
|
|
|
}
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (!sync) {
|
|
|
|
|
/* If transform was applied to geometry, need full update. */
|
|
|
|
|
if (object_updated && geom->transform_applied) {
|
2020-02-02 13:09:18 +01:00
|
|
|
;
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
|
|
|
|
/* Test if shaders changed, these can be object level so geometry
|
2020-02-02 13:09:18 +01:00
|
|
|
* does not get tagged for recalc. */
|
2020-10-27 11:40:42 +01:00
|
|
|
else if (geom->used_shaders != used_shaders) {
|
2020-02-02 13:09:18 +01:00
|
|
|
;
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2020-02-02 13:09:18 +01:00
|
|
|
else {
|
|
|
|
|
/* Even if not tagged for recalc, we may need to sync anyway
|
2020-02-02 12:04:19 +01:00
|
|
|
* because the shader needs different geometry attributes. */
|
2020-02-02 13:09:18 +01:00
|
|
|
bool attribute_recalc = false;
|
|
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
foreach (Shader *shader, geom->used_shaders) {
|
2020-02-02 12:04:19 +01:00
|
|
|
if (shader->need_update_geometry) {
|
2020-02-02 13:09:18 +01:00
|
|
|
attribute_recalc = true;
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (!attribute_recalc) {
|
|
|
|
|
return geom;
|
|
|
|
|
}
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry_synced.insert(geom);
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
geom->name = ustring(b_ob_data.name().c_str());
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2020-10-21 16:38:36 +02:00
|
|
|
auto sync_func = [=]() mutable {
|
|
|
|
|
if (progress.get_cancel())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
progress.set_sync_status("Synchronizing object", b_ob.name());
|
|
|
|
|
|
|
|
|
|
if (geom_type == Geometry::HAIR) {
|
|
|
|
|
Hair *hair = static_cast<Hair *>(geom);
|
|
|
|
|
sync_hair(b_depsgraph, b_ob, hair, used_shaders);
|
|
|
|
|
}
|
|
|
|
|
else if (geom_type == Geometry::VOLUME) {
|
|
|
|
|
Volume *volume = static_cast<Volume *>(geom);
|
|
|
|
|
sync_volume(b_ob, volume, used_shaders);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
|
|
|
|
sync_mesh(b_depsgraph, b_ob, mesh, used_shaders);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Defer the actual geometry sync to the task_pool for multithreading */
|
|
|
|
|
if (task_pool) {
|
|
|
|
|
task_pool->push(sync_func);
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2020-10-21 16:38:36 +02:00
|
|
|
sync_func();
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
return geom;
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSync::sync_geometry_motion(BL::Depsgraph &b_depsgraph,
|
|
|
|
|
BL::Object &b_ob,
|
|
|
|
|
Object *object,
|
|
|
|
|
float motion_time,
|
2020-10-21 16:38:36 +02:00
|
|
|
bool use_particle_hair,
|
|
|
|
|
TaskPool *task_pool)
|
2020-02-02 13:09:18 +01:00
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
/* Ensure we only sync instanced geometry once. */
|
2020-10-27 11:40:42 +01:00
|
|
|
Geometry *geom = object->geometry;
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (geometry_motion_synced.find(geom) != geometry_motion_synced.end())
|
2020-02-02 13:09:18 +01:00
|
|
|
return;
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry_motion_synced.insert(geom);
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
/* Ensure we only motion sync geometry that also had geometry synced, to avoid
|
2020-02-02 13:09:18 +01:00
|
|
|
* unnecessary work and to ensure that its attributes were clear. */
|
2020-02-02 12:04:19 +01:00
|
|
|
if (geometry_synced.find(geom) == geometry_synced.end())
|
2020-02-02 13:09:18 +01:00
|
|
|
return;
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
/* Find time matching motion step required by geometry. */
|
|
|
|
|
int motion_step = geom->motion_step(motion_time);
|
2020-02-02 13:09:18 +01:00
|
|
|
if (motion_step < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 16:38:36 +02:00
|
|
|
auto sync_func = [=]() mutable {
|
|
|
|
|
if (progress.get_cancel())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) {
|
|
|
|
|
Hair *hair = static_cast<Hair *>(geom);
|
|
|
|
|
sync_hair_motion(b_depsgraph, b_ob, hair, motion_step);
|
|
|
|
|
}
|
|
|
|
|
else if (b_ob.type() == BL::Object::type_VOLUME || object_fluid_gas_domain_find(b_ob)) {
|
|
|
|
|
/* No volume motion blur support yet. */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
|
|
|
|
sync_mesh_motion(b_depsgraph, b_ob, mesh, motion_step);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Defer the actual geometry sync to the task_pool for multithreading */
|
|
|
|
|
if (task_pool) {
|
|
|
|
|
task_pool->push(sync_func);
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2020-10-21 16:38:36 +02:00
|
|
|
sync_func();
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|