diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2020-11-04 13:17:38 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2020-11-04 15:03:33 +0300 |
commit | 31a620b9420cab6292b0aa1ea21c9dd1cf70b8bc (patch) | |
tree | 76cf425e110fe1c78930e54f3b56d24e1485877a /intern/cycles/blender/blender_object.cpp | |
parent | a4a848d01b26ad094dabe0e935dd698847ac8f16 (diff) |
Cycles API: encapsulate Node socket members
This encapsulates Node socket members behind a set of specific methods;
as such it is no longer possible to directly access Node class members
from exporters and parts of Cycles.
The methods are defined via the NODE_SOCKET_API macros in `graph/
node.h`, and are for getting or setting a specific socket's value, as
well as querying or modifying the state of its update flag.
The setters will check whether the value has changed and tag the socket
as modified appropriately. This will let us know how a Node has changed
and what to update, which is the first concrete step toward a more
granular scene update system.
Since the setters will tag the Node sockets as modified when passed
different data, this patch also removes the various modified methods
on Nodes in favor of Node::is_modified which checks the sockets'
update flags status.
Reviewed By: brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D8544
Diffstat (limited to 'intern/cycles/blender/blender_object.cpp')
-rw-r--r-- | intern/cycles/blender/blender_object.cpp | 110 |
1 files changed, 49 insertions, 61 deletions
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 5e99759fdac..4a70cbbf41f 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -199,11 +199,13 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph, /* Set transform at matching motion time step. */ int time_index = object->motion_step(motion_time); if (time_index >= 0) { - object->motion[time_index] = tfm; + array<Transform> motion = object->get_motion(); + motion[time_index] = tfm; + object->set_motion(motion); } /* mesh deformation */ - if (object->geometry) + if (object->get_geometry()) sync_geometry_motion(b_depsgraph, b_ob_instance, object, @@ -225,12 +227,13 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph, /* b_ob is owned by the iterator and will go out of scope at the end of the block. * b_ob_instance is the original object and will remain valid for deferred geometry * sync. */ - object->geometry = sync_geometry(b_depsgraph, - b_ob_instance, - b_ob_instance, - object_updated, - use_particle_hair, - object_geom_task_pool); + Geometry *geometry = sync_geometry(b_depsgraph, + b_ob_instance, + b_ob_instance, + object_updated, + use_particle_hair, + object_geom_task_pool); + object->set_geometry(geometry); /* special case not tracked by object update flags */ @@ -239,28 +242,18 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph, } /* holdout */ - if (use_holdout != object->use_holdout) { - object->use_holdout = use_holdout; + object->set_use_holdout(use_holdout); + if (object->use_holdout_is_modified()) { scene->object_manager->tag_update(scene); - object_updated = true; } - if (visibility != object->visibility) { - object->visibility = visibility; - object_updated = true; - } + object->set_visibility(visibility); 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; - } + object->set_is_shadow_catcher(is_shadow_catcher); float shadow_terminator_offset = get_float(cobject, "shadow_terminator_offset"); - if (shadow_terminator_offset != object->shadow_terminator_offset) { - object->shadow_terminator_offset = shadow_terminator_offset; - object_updated = true; - } + object->set_shadow_terminator_offset(shadow_terminator_offset); /* sync the asset name for Cryptomatte */ BL::Object parent = b_ob.parent(); @@ -274,48 +267,49 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph, else { parent_name = b_ob.name(); } - if (object->asset_name != parent_name) { - object->asset_name = parent_name; - object_updated = true; - } + object->set_asset_name(parent_name); /* 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 */ - if (object_updated || (object->geometry && object->geometry->need_update) || - tfm != object->tfm) { + if (object->is_modified() || object_updated || + (object->get_geometry() && object->get_geometry()->is_modified()) || + tfm != object->get_tfm()) { object->name = b_ob.name().c_str(); - object->pass_id = b_ob.pass_index(); - object->color = get_float3(b_ob.color()); - object->tfm = tfm; - object->motion.clear(); + object->set_pass_id(b_ob.pass_index()); + object->set_color(get_float3(b_ob.color())); + object->set_tfm(tfm); + array<Transform> motion; + object->set_motion(motion); /* motion blur */ Scene::MotionType need_motion = scene->need_motion(); - if (need_motion != Scene::MOTION_NONE && object->geometry) { - Geometry *geom = object->geometry; - geom->use_motion_blur = false; - geom->motion_steps = 0; + if (need_motion != Scene::MOTION_NONE && object->get_geometry()) { + Geometry *geom = object->get_geometry(); + geom->set_use_motion_blur(false); + geom->set_motion_steps(0); uint motion_steps; if (need_motion == Scene::MOTION_BLUR) { motion_steps = object_motion_steps(b_parent, b_ob, Object::MAX_MOTION_STEPS); - geom->motion_steps = motion_steps; + geom->set_motion_steps(motion_steps); if (motion_steps && object_use_deform_motion(b_parent, b_ob)) { - geom->use_motion_blur = true; + geom->set_use_motion_blur(true); } } else { motion_steps = 3; - geom->motion_steps = motion_steps; + geom->set_motion_steps(motion_steps); } - object->motion.clear(); - object->motion.resize(motion_steps, transform_empty()); + motion.resize(motion_steps, transform_empty()); if (motion_steps) { - object->motion[motion_steps / 2] = tfm; + motion[motion_steps / 2] = tfm; + + /* update motion socket before trying to access object->motion_time */ + object->set_motion(motion); for (size_t step = 0; step < motion_steps; step++) { motion_times.insert(object->motion_time(step)); @@ -325,15 +319,15 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph, /* 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(); + object->set_dupli_generated(0.5f * get_float3(b_instance.orco()) - + make_float3(0.5f, 0.5f, 0.5f)); + object->set_dupli_uv(get_float2(b_instance.uv())); + object->set_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); - object->random_id = hash_uint2(hash_string(object->name.c_str()), 0); + object->set_dupli_generated(make_float3(0.0f, 0.0f, 0.0f)); + object->set_dupli_uv(make_float2(0.0f, 0.0f)); + object->set_random_id(hash_uint2(hash_string(object->name.c_str()), 0)); } object->tag_update(scene); @@ -421,7 +415,7 @@ static float4 lookup_instance_property(BL::DepsgraphObjectInstance &b_instance, bool BlenderSync::sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object) { /* Find which attributes are needed. */ - AttributeRequestSet requests = object->geometry->needed_attributes(); + AttributeRequestSet requests = object->get_geometry()->needed_attributes(); /* Delete attributes that became unnecessary. */ vector<ParamValue> &attributes = object->attributes; @@ -591,20 +585,18 @@ void BlenderSync::sync_motion(BL::RenderSettings &b_render, 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) { + scene->camera->get_motion_position() != Camera::MOTION_POSITION_CENTER) { + float shuttertime = scene->camera->get_shuttertime(); + if (scene->camera->get_motion_position() == Camera::MOTION_POSITION_END) { frame_center_delta = -shuttertime * 0.5f; } else { - assert(scene->camera->motion_position == Camera::MOTION_POSITION_START); + assert(scene->camera->get_motion_position() == Camera::MOTION_POSITION_START); frame_center_delta = shuttertime * 0.5f; } @@ -665,10 +657,6 @@ void BlenderSync::sync_motion(BL::RenderSettings &b_render, 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(); } CCL_NAMESPACE_END |