2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* 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
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* 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
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +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 20:39:14 +02:00
|
|
|
#include "render/camera.h"
|
|
|
|
#include "render/graph.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "render/integrator.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 20:39:14 +02:00
|
|
|
#include "render/light.h"
|
|
|
|
#include "render/mesh.h"
|
|
|
|
#include "render/nodes.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "render/object.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 20:39:14 +02:00
|
|
|
#include "render/particles.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "render/scene.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 20:39:14 +02:00
|
|
|
#include "render/shader.h"
|
2011-04-27 11:58:34 +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 20:39:14 +02:00
|
|
|
#include "blender/blender_object_cull.h"
|
|
|
|
#include "blender/blender_sync.h"
|
|
|
|
#include "blender/blender_util.h"
|
2011-04-27 11:58:34 +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 20:39:14 +02:00
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_hash.h"
|
|
|
|
#include "util/util_logging.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Utilities */
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BlenderSync::BKE_object_is_modified(BL::Object &b_ob)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* test if we can instance or if the object is modified */
|
|
|
|
if (b_ob.type() == BL::Object::type_META) {
|
|
|
|
/* multi-user and dupli metaballs are fused, can't instance */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ccl::BKE_object_is_modified(b_ob, b_scene, preview)) {
|
|
|
|
/* modifiers */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* object level material links */
|
|
|
|
BL::Object::material_slots_iterator slot;
|
|
|
|
for (b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot)
|
|
|
|
if (slot->link() == BL::MaterialSlot::link_OBJECT)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BlenderSync::object_is_mesh(BL::Object &b_ob)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BL::ID b_ob_data = b_ob.data();
|
|
|
|
|
|
|
|
if (!b_ob_data) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-17 16:52:14 +01:00
|
|
|
BL::Object::type_enum type = b_ob.type();
|
|
|
|
|
2020-03-17 16:30:48 +01:00
|
|
|
#ifdef WITH_NEW_OBJECT_TYPES
|
|
|
|
if (type == BL::Object::type_VOLUME || type == BL::Object::type_HAIR) {
|
|
|
|
#else
|
2020-03-17 16:52:14 +01:00
|
|
|
if (type == BL::Object::type_VOLUME) {
|
2020-03-17 16:30:48 +01:00
|
|
|
#endif
|
2020-03-17 16:52:14 +01:00
|
|
|
/* Will be exported attached to mesh. */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == BL::Object::type_CURVE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Skip exporting curves without faces, overhead can be
|
|
|
|
* significant if there are many for path animation. */
|
2020-03-17 16:52:14 +01:00
|
|
|
BL::Curve b_curve(b_ob_data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
return (b_curve.bevel_object() || b_curve.extrude() != 0.0f || b_curve.bevel_depth() != 0.0f ||
|
|
|
|
b_curve.dimensions() == BL::Curve::dimensions_2D || b_ob.modifiers.length());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (b_ob_data.is_a(&RNA_Mesh) || b_ob_data.is_a(&RNA_Curve) ||
|
|
|
|
b_ob_data.is_a(&RNA_MetaBall));
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BlenderSync::object_is_light(BL::Object &b_ob)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BL::ID b_ob_data = b_ob.data();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (b_ob_data && b_ob_data.is_a(&RNA_Light));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Object */
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph,
|
|
|
|
BL::ViewLayer &b_view_layer,
|
|
|
|
BL::DepsgraphObjectInstance &b_instance,
|
2015-04-10 18:09:58 +05:00
|
|
|
float motion_time,
|
2020-02-02 13:09:18 +01:00
|
|
|
bool use_particle_hair,
|
2019-08-27 15:47:30 +02:00
|
|
|
bool show_lights,
|
2019-04-17 06:17:24 +02:00
|
|
|
BlenderObjectCulling &culling,
|
2015-04-10 18:09:58 +05:00
|
|
|
bool *use_portal)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const bool is_instance = b_instance.is_instance();
|
|
|
|
BL::Object b_ob = b_instance.object();
|
|
|
|
BL::Object b_parent = is_instance ? b_instance.parent() : b_instance.object();
|
|
|
|
BL::Object b_ob_instance = is_instance ? b_instance.instance_object() : b_ob;
|
|
|
|
const bool motion = motion_time != 0.0f;
|
|
|
|
/*const*/ Transform tfm = get_transform(b_ob.matrix_world());
|
|
|
|
int *persistent_id = NULL;
|
|
|
|
BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id_array;
|
|
|
|
if (is_instance) {
|
|
|
|
persistent_id_array = b_instance.persistent_id();
|
|
|
|
persistent_id = persistent_id_array.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* light is handled separately */
|
|
|
|
if (!motion && object_is_light(b_ob)) {
|
2019-08-27 15:47:30 +02:00
|
|
|
if (!show_lights) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO: don't use lights for excluded layers used as mask layer,
|
|
|
|
* when dynamic overrides are back. */
|
2018-07-25 12:35:27 +02:00
|
|
|
#if 0
|
2019-04-17 08:16:53 +02:00
|
|
|
if (!((layer_flag & view_layer.holdout_layer) && (layer_flag & view_layer.exclude_layer)))
|
2018-07-25 12:35:27 +02:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
|
|
|
sync_light(b_parent,
|
|
|
|
persistent_id,
|
|
|
|
b_ob,
|
|
|
|
b_ob_instance,
|
|
|
|
is_instance ? b_instance.random_id() : 0,
|
|
|
|
tfm,
|
|
|
|
use_portal);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only interested in object that we can create meshes from */
|
|
|
|
if (!object_is_mesh(b_ob)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform object culling. */
|
|
|
|
if (culling.test(scene, b_ob, tfm)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Visibility flags for both parent and child. */
|
|
|
|
PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles");
|
|
|
|
bool use_holdout = get_boolean(cobject, "is_holdout") ||
|
|
|
|
b_parent.holdout_get(PointerRNA_NULL, b_view_layer);
|
|
|
|
uint visibility = object_ray_visibility(b_ob) & PATH_RAY_ALL_VISIBILITY;
|
|
|
|
|
|
|
|
if (b_parent.ptr.data != b_ob.ptr.data) {
|
|
|
|
visibility &= object_ray_visibility(b_parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: make holdout objects on excluded layer invisible for non-camera rays. */
|
2018-07-25 12:35:27 +02:00
|
|
|
#if 0
|
2019-04-17 08:16:53 +02:00
|
|
|
if (use_holdout && (layer_flag & view_layer.exclude_layer)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
visibility &= ~(PATH_RAY_ALL_VISIBILITY - PATH_RAY_CAMERA);
|
|
|
|
}
|
2018-07-25 12:35:27 +02:00
|
|
|
#endif
|
2017-09-29 03:56:14 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Clear camera visibility for indirect only objects. */
|
2019-07-04 17:28:39 +02:00
|
|
|
bool use_indirect_only = !use_holdout &&
|
|
|
|
b_parent.indirect_only_get(PointerRNA_NULL, b_view_layer);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (use_indirect_only) {
|
|
|
|
visibility &= ~PATH_RAY_CAMERA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't export completely invisible objects. */
|
|
|
|
if (visibility == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* key to lookup object */
|
2020-02-02 13:09:18 +01:00
|
|
|
ObjectKey key(b_parent, persistent_id, b_ob_instance, use_particle_hair);
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *object;
|
|
|
|
|
|
|
|
/* motion vector case */
|
|
|
|
if (motion) {
|
|
|
|
object = object_map.find(key);
|
|
|
|
|
|
|
|
if (object && object->use_motion()) {
|
|
|
|
/* Set transform at matching motion time step. */
|
|
|
|
int time_index = object->motion_step(motion_time);
|
|
|
|
if (time_index >= 0) {
|
|
|
|
object->motion[time_index] = tfm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mesh deformation */
|
2020-02-02 12:04:19 +01:00
|
|
|
if (object->geometry)
|
2020-02-02 13:09:18 +01:00
|
|
|
sync_geometry_motion(b_depsgraph, b_ob, object, motion_time, use_particle_hair);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test if we need to sync */
|
|
|
|
bool object_updated = false;
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (object_map.add_or_update(&object, b_ob, b_parent, key))
|
2019-04-17 06:17:24 +02:00
|
|
|
object_updated = true;
|
|
|
|
|
|
|
|
/* mesh sync */
|
2020-02-02 12:04:19 +01:00
|
|
|
object->geometry = sync_geometry(
|
2020-02-02 13:09:18 +01:00
|
|
|
b_depsgraph, b_ob, b_ob_instance, object_updated, use_particle_hair);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* special case not tracked by object update flags */
|
|
|
|
|
|
|
|
/* holdout */
|
|
|
|
if (use_holdout != object->use_holdout) {
|
|
|
|
object->use_holdout = use_holdout;
|
|
|
|
scene->object_manager->tag_update(scene);
|
|
|
|
object_updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibility != object->visibility) {
|
|
|
|
object->visibility = visibility;
|
|
|
|
object_updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_shadow_catcher = get_boolean(cobject, "is_shadow_catcher");
|
|
|
|
if (is_shadow_catcher != object->is_shadow_catcher) {
|
|
|
|
object->is_shadow_catcher = is_shadow_catcher;
|
|
|
|
object_updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sync the asset name for Cryptomatte */
|
|
|
|
BL::Object parent = b_ob.parent();
|
|
|
|
ustring parent_name;
|
|
|
|
if (parent) {
|
|
|
|
while (parent.parent()) {
|
|
|
|
parent = parent.parent();
|
|
|
|
}
|
|
|
|
parent_name = parent.name();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent_name = b_ob.name();
|
|
|
|
}
|
|
|
|
if (object->asset_name != parent_name) {
|
|
|
|
object->asset_name = parent_name;
|
|
|
|
object_updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* object sync
|
|
|
|
* transform comparison should not be needed, but duplis don't work perfect
|
|
|
|
* in the depsgraph and may not signal changes, so this is a workaround */
|
2020-02-02 12:04:19 +01:00
|
|
|
if (object_updated || (object->geometry && object->geometry->need_update) ||
|
|
|
|
tfm != object->tfm) {
|
2019-04-17 06:17:24 +02:00
|
|
|
object->name = b_ob.name().c_str();
|
|
|
|
object->pass_id = b_ob.pass_index();
|
2019-08-22 14:26:09 +02:00
|
|
|
object->color = get_float3(b_ob.color());
|
2019-04-17 06:17:24 +02:00
|
|
|
object->tfm = tfm;
|
|
|
|
object->motion.clear();
|
|
|
|
|
|
|
|
/* motion blur */
|
|
|
|
Scene::MotionType need_motion = scene->need_motion();
|
2020-02-02 12:04:19 +01:00
|
|
|
if (need_motion != Scene::MOTION_NONE && object->geometry) {
|
|
|
|
Geometry *geom = object->geometry;
|
|
|
|
geom->use_motion_blur = false;
|
|
|
|
geom->motion_steps = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
uint motion_steps;
|
|
|
|
|
|
|
|
if (need_motion == Scene::MOTION_BLUR) {
|
2020-02-18 14:02:40 +01:00
|
|
|
motion_steps = object_motion_steps(b_parent, b_ob, Object::MAX_MOTION_STEPS);
|
2020-02-02 12:04:19 +01:00
|
|
|
geom->motion_steps = motion_steps;
|
2019-04-17 06:17:24 +02:00
|
|
|
if (motion_steps && object_use_deform_motion(b_parent, b_ob)) {
|
2020-02-02 12:04:19 +01:00
|
|
|
geom->use_motion_blur = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
motion_steps = 3;
|
2020-02-02 12:04:19 +01:00
|
|
|
geom->motion_steps = motion_steps;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
object->motion.clear();
|
|
|
|
object->motion.resize(motion_steps, transform_empty());
|
|
|
|
|
|
|
|
if (motion_steps) {
|
|
|
|
object->motion[motion_steps / 2] = tfm;
|
|
|
|
|
|
|
|
for (size_t step = 0; step < motion_steps; step++) {
|
|
|
|
motion_times.insert(object->motion_time(step));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dupli texture coordinates and random_id */
|
|
|
|
if (is_instance) {
|
|
|
|
object->dupli_generated = 0.5f * get_float3(b_instance.orco()) -
|
|
|
|
make_float3(0.5f, 0.5f, 0.5f);
|
|
|
|
object->dupli_uv = get_float2(b_instance.uv());
|
|
|
|
object->random_id = b_instance.random_id();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
object->dupli_generated = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
object->dupli_uv = make_float2(0.0f, 0.0f);
|
2019-08-21 20:04:09 +02:00
|
|
|
object->random_id = hash_uint2(hash_string(object->name.c_str()), 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
object->tag_update(scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_instance) {
|
|
|
|
/* Sync possible particle data. */
|
|
|
|
sync_dupli_particle(b_parent, b_instance, object);
|
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Object Loop */
|
|
|
|
|
2019-08-27 15:47:30 +02:00
|
|
|
void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
|
|
|
|
BL::SpaceView3D &b_v3d,
|
|
|
|
float motion_time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* layer data */
|
|
|
|
bool motion = motion_time != 0.0f;
|
|
|
|
|
|
|
|
if (!motion) {
|
|
|
|
/* prepare for sync */
|
|
|
|
light_map.pre_sync();
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry_map.pre_sync();
|
2019-04-17 06:17:24 +02:00
|
|
|
object_map.pre_sync();
|
|
|
|
particle_system_map.pre_sync();
|
|
|
|
motion_times.clear();
|
|
|
|
}
|
|
|
|
else {
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry_motion_synced.clear();
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize culling */
|
|
|
|
BlenderObjectCulling culling(scene, b_scene);
|
|
|
|
|
|
|
|
/* object loop */
|
|
|
|
bool cancel = false;
|
|
|
|
bool use_portal = false;
|
2019-08-27 15:47:30 +02:00
|
|
|
const bool show_lights = BlenderViewportParameters(b_v3d).use_scene_lights;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
BL::ViewLayer b_view_layer = b_depsgraph.view_layer_eval();
|
|
|
|
|
|
|
|
BL::Depsgraph::object_instances_iterator b_instance_iter;
|
|
|
|
for (b_depsgraph.object_instances.begin(b_instance_iter);
|
|
|
|
b_instance_iter != b_depsgraph.object_instances.end() && !cancel;
|
|
|
|
++b_instance_iter) {
|
|
|
|
BL::DepsgraphObjectInstance b_instance = *b_instance_iter;
|
|
|
|
BL::Object b_ob = b_instance.object();
|
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
/* Viewport visibility. */
|
|
|
|
const bool show_in_viewport = !b_v3d || b_ob.visible_in_viewport_get(b_v3d);
|
|
|
|
if (show_in_viewport == false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load per-object culling data. */
|
2019-04-17 06:17:24 +02:00
|
|
|
culling.init_object(scene, b_ob);
|
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
/* Object itself. */
|
|
|
|
if (b_instance.show_self()) {
|
|
|
|
sync_object(b_depsgraph,
|
|
|
|
b_view_layer,
|
|
|
|
b_instance,
|
|
|
|
motion_time,
|
|
|
|
false,
|
|
|
|
show_lights,
|
|
|
|
culling,
|
|
|
|
&use_portal);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
/* Particle hair as separate object. */
|
|
|
|
if (b_instance.show_particles() && object_has_particle_hair(b_ob)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
sync_object(b_depsgraph,
|
|
|
|
b_view_layer,
|
|
|
|
b_instance,
|
|
|
|
motion_time,
|
2020-02-02 13:09:18 +01:00
|
|
|
true,
|
2019-08-27 15:47:30 +02:00
|
|
|
show_lights,
|
2019-04-17 06:17:24 +02:00
|
|
|
culling,
|
|
|
|
&use_portal);
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel = progress.get_cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
progress.set_sync_status("");
|
|
|
|
|
|
|
|
if (!cancel && !motion) {
|
2019-08-27 15:47:30 +02:00
|
|
|
sync_background_light(b_v3d, use_portal);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* handle removed data and modified pointers */
|
|
|
|
if (light_map.post_sync())
|
|
|
|
scene->light_manager->tag_update(scene);
|
2020-02-02 12:04:19 +01:00
|
|
|
if (geometry_map.post_sync())
|
|
|
|
scene->geometry_manager->tag_update(scene);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (object_map.post_sync())
|
|
|
|
scene->object_manager->tag_update(scene);
|
|
|
|
if (particle_system_map.post_sync())
|
|
|
|
scene->particle_system_manager->tag_update(scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (motion)
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry_motion_synced.clear();
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void BlenderSync::sync_motion(BL::RenderSettings &b_render,
|
|
|
|
BL::Depsgraph &b_depsgraph,
|
2019-08-27 15:47:30 +02:00
|
|
|
BL::SpaceView3D &b_v3d,
|
2019-04-17 06:17:24 +02:00
|
|
|
BL::Object &b_override,
|
|
|
|
int width,
|
|
|
|
int height,
|
2015-07-21 15:36:35 +02:00
|
|
|
void **python_thread_state)
|
2012-04-30 12:49:26 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scene->need_motion() == Scene::MOTION_NONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* get camera object here to deal with camera switch */
|
|
|
|
BL::Object b_cam = b_scene.camera();
|
|
|
|
if (b_override)
|
|
|
|
b_cam = b_override;
|
|
|
|
|
|
|
|
Camera prevcam = *(scene->camera);
|
|
|
|
|
|
|
|
int frame_center = b_scene.frame_current();
|
|
|
|
float subframe_center = b_scene.frame_subframe();
|
|
|
|
float frame_center_delta = 0.0f;
|
|
|
|
|
|
|
|
if (scene->need_motion() != Scene::MOTION_PASS &&
|
|
|
|
scene->camera->motion_position != Camera::MOTION_POSITION_CENTER) {
|
|
|
|
float shuttertime = scene->camera->shuttertime;
|
|
|
|
if (scene->camera->motion_position == Camera::MOTION_POSITION_END) {
|
|
|
|
frame_center_delta = -shuttertime * 0.5f;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(scene->camera->motion_position == Camera::MOTION_POSITION_START);
|
|
|
|
frame_center_delta = shuttertime * 0.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
float time = frame_center + subframe_center + frame_center_delta;
|
|
|
|
int frame = (int)floorf(time);
|
|
|
|
float subframe = time - frame;
|
|
|
|
python_thread_state_restore(python_thread_state);
|
|
|
|
b_engine.frame_set(frame, subframe);
|
|
|
|
python_thread_state_save(python_thread_state);
|
|
|
|
sync_camera_motion(b_render, b_cam, width, height, 0.0f);
|
2019-08-27 15:47:30 +02:00
|
|
|
sync_objects(b_depsgraph, b_v3d, 0.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2020-05-19 02:51:27 +02:00
|
|
|
/* Insert motion times from camera. Motion times from other objects
|
|
|
|
* have already been added in a sync_objects call. */
|
|
|
|
uint camera_motion_steps = object_motion_steps(b_cam, b_cam);
|
|
|
|
for (size_t step = 0; step < camera_motion_steps; step++) {
|
|
|
|
motion_times.insert(scene->camera->motion_time(step));
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* note iteration over motion_times set happens in sorted order */
|
|
|
|
foreach (float relative_time, motion_times) {
|
|
|
|
/* center time is already handled. */
|
|
|
|
if (relative_time == 0.0f) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
VLOG(1) << "Synchronizing motion for the relative time " << relative_time << ".";
|
|
|
|
|
|
|
|
/* fixed shutter time to get previous and next frame for motion pass */
|
|
|
|
float shuttertime = scene->motion_shutter_time();
|
|
|
|
|
|
|
|
/* compute frame and subframe time */
|
|
|
|
float time = frame_center + subframe_center + frame_center_delta +
|
|
|
|
relative_time * shuttertime * 0.5f;
|
|
|
|
int frame = (int)floorf(time);
|
|
|
|
float subframe = time - frame;
|
|
|
|
|
|
|
|
/* change frame */
|
|
|
|
python_thread_state_restore(python_thread_state);
|
|
|
|
b_engine.frame_set(frame, subframe);
|
|
|
|
python_thread_state_save(python_thread_state);
|
|
|
|
|
2020-05-19 02:51:27 +02:00
|
|
|
/* Syncs camera motion if relative_time is one of the camera's motion times. */
|
|
|
|
sync_camera_motion(b_render, b_cam, width, height, relative_time);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* sync object */
|
2019-08-27 15:47:30 +02:00
|
|
|
sync_objects(b_depsgraph, b_v3d, relative_time);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we need to set the python thread state again because this
|
|
|
|
* function assumes it is being executed from python and will
|
|
|
|
* try to save the thread state */
|
|
|
|
python_thread_state_restore(python_thread_state);
|
|
|
|
b_engine.frame_set(frame_center, subframe_center);
|
|
|
|
python_thread_state_save(python_thread_state);
|
|
|
|
|
|
|
|
/* tag camera for motion update */
|
|
|
|
if (scene->camera->motion_modified(prevcam))
|
|
|
|
scene->camera->tag_update();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|