30 bool BlenderSync::BKE_object_is_modified(
BL::Object &b_ob)
33 if (b_ob.type() == BL::Object::type_META) {
43 for (BL::MaterialSlot &b_slot : b_ob.material_slots) {
44 if (b_slot.link() == BL::MaterialSlot::link_OBJECT) {
53 bool BlenderSync::object_is_geometry(
BObjectInfo &b_ob_info)
63 if (
type == BL::Object::type_VOLUME ||
type == BL::Object::type_CURVES ||
64 type == BL::Object::type_POINTCLOUD) {
71 if (
type == BL::Object::type_META) {
75 return b_ob_data.is_a(&RNA_Mesh);
78 bool BlenderSync::object_can_have_geometry(
BL::Object &b_ob)
80 BL::Object::type_enum
type = b_ob.type();
82 case BL::Object::type_MESH:
83 case BL::Object::type_CURVE:
84 case BL::Object::type_SURFACE:
85 case BL::Object::type_META:
86 case BL::Object::type_FONT:
87 case BL::Object::type_CURVES:
88 case BL::Object::type_POINTCLOUD:
89 case BL::Object::type_VOLUME:
96 bool BlenderSync::object_is_light(
BL::Object &b_ob)
98 BL::ID b_ob_data = b_ob.data();
100 return (b_ob_data && b_ob_data.is_a(&RNA_Light));
108 object->set_motion(motion);
110 Geometry *geom =
object->get_geometry();
115 int motion_steps = 0;
116 bool use_motion_blur =
false;
122 use_motion_blur =
true;
129 geom->set_use_motion_blur(use_motion_blur);
130 geom->set_motion_steps(motion_steps);
135 motion[motion_steps / 2] =
object->get_tfm();
138 object->set_motion(motion);
140 for (
size_t step = 0; step < motion_steps; step++) {
148 BL::DepsgraphObjectInstance &b_instance,
150 bool use_particle_hair,
156 const bool is_instance = b_instance.is_instance();
158 BL::Object b_parent = is_instance ? b_instance.
parent() : b_instance.object();
159 BObjectInfo b_ob_info{b_ob, is_instance ? b_instance.instance_object() : b_ob, b_ob.data()};
160 const bool motion = motion_time != 0.0f;
162 int *persistent_id =
NULL;
163 BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id_array;
165 persistent_id_array = b_instance.persistent_id();
166 persistent_id = persistent_id_array.data;
175 if (!motion && object_is_light(b_ob)) {
183 if (!((layer_flag & view_layer.holdout_layer) && (layer_flag & view_layer.exclude_layer)))
189 is_instance ? b_instance.random_id() : 0,
198 if (!object_is_geometry(b_ob_info)) {
203 if (culling.
test(scene, b_ob, tfm)) {
209 bool use_holdout = b_parent.holdout_get(
PointerRNA_NULL, b_view_layer);
212 if (b_parent.ptr.data != b_ob.ptr.data) {
218 if (use_holdout && (layer_flag & view_layer.exclude_layer)) {
224 bool use_indirect_only = !use_holdout &&
226 if (use_indirect_only) {
231 if (visibility == 0) {
237 TaskPool *object_geom_task_pool = (is_instance) ?
NULL : geom_task_pool;
245 object = object_map.
find(key);
250 if (time_index >= 0) {
252 motion[time_index] = tfm;
253 object->set_motion(motion);
257 if (object->get_geometry())
258 sync_geometry_motion(
259 b_depsgraph, b_ob_info,
object, motion_time, use_particle_hair, object_geom_task_pool);
266 bool object_updated = object_map.
add_or_update(&
object, b_ob, b_parent, key) ||
267 (tfm !=
object->get_tfm());
271 b_depsgraph, b_ob_info, object_updated, use_particle_hair, object_geom_task_pool);
272 object->set_geometry(geometry);
276 if (sync_object_attributes(b_instance,
object)) {
277 object_updated =
true;
281 object->set_use_holdout(use_holdout);
283 object->set_visibility(visibility);
285 object->set_is_shadow_catcher(b_ob.is_shadow_catcher() || b_parent.is_shadow_catcher());
287 float shadow_terminator_shading_offset =
get_float(cobject,
"shadow_terminator_offset");
288 object->set_shadow_terminator_shading_offset(shadow_terminator_shading_offset);
290 float shadow_terminator_geometry_offset =
get_float(cobject,
291 "shadow_terminator_geometry_offset");
292 object->set_shadow_terminator_geometry_offset(shadow_terminator_geometry_offset);
294 float ao_distance =
get_float(cobject,
"ao_distance");
295 if (ao_distance == 0.0f && b_parent.ptr.data != b_ob.ptr.data) {
297 ao_distance =
get_float(cparent,
"ao_distance");
299 object->set_ao_distance(ao_distance);
301 bool is_caustics_caster =
get_boolean(cobject,
"is_caustics_caster");
302 object->set_is_caustics_caster(is_caustics_caster);
304 bool is_caustics_receiver =
get_boolean(cobject,
"is_caustics_receiver");
305 object->set_is_caustics_receiver(is_caustics_receiver);
311 while (parent.parent()) {
314 parent_name = parent.
name();
317 parent_name = b_ob.name();
319 object->set_asset_name(parent_name);
325 (object->get_geometry() && object->get_geometry()->
is_modified())) {
326 object->name = b_ob.name().c_str();
327 object->set_pass_id(b_ob.pass_index());
331 object->set_tfm(tfm);
335 object->set_dupli_generated(0.5f *
get_float3(b_instance.orco()) -
337 object->set_dupli_uv(
get_float2(b_instance.uv()));
338 object->set_random_id(b_instance.random_id());
347 object->set_lightgroup(ustring(b_ob.lightgroup()));
349 object->tag_update(scene);
352 sync_object_motion_init(b_parent, b_ob,
object);
356 sync_dupli_particle(b_parent, b_instance,
object);
406 string idprop_name =
string_printf(
"[\"%s\"]", name.c_str());
410 if (use_instancer && b_instance.is_instance()) {
427 BL::ID b_data = b_ob.data();
437 bool BlenderSync::sync_object_attributes(BL::DepsgraphObjectInstance &b_instance,
Object *
object)
444 bool changed =
false;
446 for (
int i = attributes.size() - 1; i >= 0; i--) {
447 if (!requests.
find(attributes[i].name())) {
448 attributes.erase(attributes.begin() + i);
455 ustring name = req.
name;
457 std::string real_name;
460 if (
type != BL::ShaderNodeAttribute::attribute_type_GEOMETRY) {
461 bool use_instancer = (
type == BL::ShaderNodeAttribute::attribute_type_INSTANCER);
465 ParamValue *param =
NULL;
467 for (
size_t i = 0; i < attributes.size(); i++) {
468 if (attributes[i].name() == name) {
469 param = &attributes[i];
475 ParamValue new_param(name, TypeDesc::TypeFloat4, 1, &value);
476 assert(new_param.datasize() ==
sizeof(value));
480 attributes.push_back(new_param);
482 else if (memcmp(param->data(), &value,
sizeof(value)) != 0) {
494 void BlenderSync::sync_procedural(
BL::Object &b_ob,
495 BL::MeshSequenceCacheModifier &b_mesh_cache,
496 bool has_subdivision_modifier)
500 void *cache_file_key = cache_file.ptr.data;
502 AlembicProcedural *procedural =
static_cast<AlembicProcedural *
>(
503 procedural_map.
find(cache_file_key));
505 if (procedural ==
nullptr) {
506 procedural = scene->
create_node<AlembicProcedural>();
507 procedural_map.
add(cache_file_key, procedural);
510 procedural_map.
used(procedural);
513 float current_frame =
static_cast<float>(b_scene.frame_current());
514 if (cache_file.override_frame()) {
515 current_frame = cache_file.frame();
518 if (!cache_file.override_frame()) {
519 procedural->set_start_frame(
static_cast<float>(b_scene.frame_start()));
520 procedural->set_end_frame(
static_cast<float>(b_scene.frame_end()));
523 procedural->set_frame(current_frame);
524 procedural->set_frame_rate(b_scene.render().fps() / b_scene.render().fps_base());
525 procedural->set_frame_offset(cache_file.frame_offset());
528 procedural->set_filepath(ustring(absolute_path));
532 if (layer.hide_layer()) {
539 procedural->set_layers(layers);
541 procedural->set_scale(cache_file.scale());
543 procedural->set_use_prefetch(cache_file.use_prefetch());
544 procedural->set_prefetch_cache_size(cache_file.prefetch_cache_size());
547 ustring object_path = ustring(b_mesh_cache.object_path());
549 AlembicObject *abc_object = procedural->get_or_create_object(object_path);
552 abc_object->set_used_shaders(used_shaders);
555 const float subd_dicing_rate =
max(0.1f,
RNA_float_get(&cobj,
"dicing_rate") * dicing_rate);
556 abc_object->set_subd_dicing_rate(subd_dicing_rate);
557 abc_object->set_subd_max_level(max_subdivisions);
559 abc_object->set_ignore_subdivision(!has_subdivision_modifier);
561 if (abc_object->is_modified() || procedural->is_modified()) {
562 procedural->tag_update(scene);
567 (
void)has_subdivision_modifier;
572 BL::SpaceView3D &b_v3d,
579 bool motion = motion_time != 0.0f;
588 motion_times.clear();
591 geometry_motion_synced.clear();
593 instance_geometries_by_object.clear();
600 bool use_portal =
false;
604 BL::Depsgraph::object_instances_iterator b_instance_iter;
606 for (b_depsgraph.object_instances.begin(b_instance_iter);
607 b_instance_iter != b_depsgraph.object_instances.end() && !cancel;
609 BL::DepsgraphObjectInstance b_instance = *b_instance_iter;
613 const bool show_in_viewport = !b_v3d || b_ob.visible_in_viewport_get(b_v3d);
614 if (show_in_viewport ==
false) {
624 const bool sync_hair = b_instance.show_particles() && object_has_particle_hair(b_ob);
627 if (b_instance.show_self()) {
629 bool use_procedural =
false;
630 bool has_subdivision_modifier =
false;
636 use_procedural = b_mesh_cache && b_mesh_cache.cache_file().use_render_procedural();
639 if (use_procedural) {
643 sync_procedural(b_ob, b_mesh_cache, has_subdivision_modifier);
649 sync_object(b_depsgraph,
657 sync_hair ?
NULL : &geom_task_pool);
663 sync_object(b_depsgraph,
681 if (!cancel && !motion) {
682 sync_background_light(b_v3d, use_portal);
695 geometry_motion_synced.clear();
698 void BlenderSync::sync_motion(BL::RenderSettings &b_render,
700 BL::SpaceView3D &b_v3d,
704 void **python_thread_state)
714 int frame_center = b_scene.frame_current();
715 float subframe_center = b_scene.frame_subframe();
716 float frame_center_delta = 0.0f;
720 float shuttertime = scene->
camera->get_shuttertime();
722 frame_center_delta = -shuttertime * 0.5f;
726 frame_center_delta = shuttertime * 0.5f;
729 float time = frame_center + subframe_center + frame_center_delta;
731 float subframe =
time - frame;
733 b_engine.frame_set(frame, subframe);
736 sync_camera_motion(b_render, b_cam,
width,
height, 0.0f);
738 sync_objects(b_depsgraph, b_v3d);
745 for (
size_t step = 0; step < camera_motion_steps; step++) {
751 geometry_motion_attribute_synced.clear();
754 geometry_motion_attribute_synced.insert(geom);
759 foreach (
float relative_time, motion_times) {
761 if (relative_time == 0.0f) {
765 VLOG_WORK <<
"Synchronizing motion for the relative time " << relative_time <<
".";
771 float time = frame_center + subframe_center + frame_center_delta +
772 relative_time * shuttertime * 0.5f;
774 float subframe =
time - frame;
778 b_engine.frame_set(frame, subframe);
782 sync_camera_motion(b_render, b_cam,
width,
height, relative_time);
785 sync_objects(b_depsgraph, b_v3d, relative_time);
788 geometry_motion_attribute_synced.clear();
794 b_engine.frame_set(frame_center, subframe_center);
int BKE_object_is_modified(struct Scene *scene, struct Object *ob)
struct Depsgraph Depsgraph
struct CacheFile CacheFile
struct CacheFileLayer CacheFileLayer
struct ViewLayer ViewLayer
struct ParticleSystem ParticleSystem
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
static float4 lookup_instance_property(BL::DepsgraphObjectInstance &b_instance, const string &name, bool use_instancer)
static bool lookup_property(BL::ID b_id, const string &name, float4 *r_value)
BlenderAttributeType blender_attribute_name_split_type(ustring name, string *r_real_name)
vector< AttributeRequest > requests
Attribute * find(ustring name) const
void init_object(Scene *scene, BL::Object &b_ob)
bool test(Scene *scene, BL::Object &b_ob, Transform &tfm)
void set_sync_status(const string &status_, const string &substatus_="")
T * resize(size_t newsize)
void push_back_slow(const T &t)
void add(const K &key, T *data)
bool add_or_update(T **r_data, const BL::ID &id)
T * find(const BL::ID &id)
void post_sync(bool do_delete=true)
#define CCL_NAMESPACE_END
static uint object_ray_visibility(BL::Object &b_ob)
static uint object_motion_steps(BL::Object &b_parent, BL::Object &b_ob, const int max_steps=INT_MAX)
static float get_float(PointerRNA &ptr, const char *name)
static bool get_boolean(PointerRNA &ptr, const char *name)
static float3 get_float3(const BL::Array< float, 2 > &array)
static string blender_absolute_path(BL::BlendData &b_data, BL::ID &b_id, const string &path)
static float2 get_float2(const BL::Array< float, 2 > &array)
static Transform get_transform(const BL::Array< float, 16 > &array)
static BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob, bool *has_subdivision_modifier)
static bool object_use_deform_motion(BL::Object &b_parent, BL::Object &b_ob)
BL::ShaderNodeAttribute::attribute_type_enum BlenderAttributeType
SyclQueue void void size_t num_bytes void
static uint hash_string(const char *str)
ccl_device_inline uint hash_uint2(uint kx, uint ky)
ccl_device_inline float3 object_color(KernelGlobals kg, int object)
@ ATTR_STD_MOTION_VERTEX_POSITION
@ PATH_RAY_ALL_VISIBILITY
ccl_device_inline float2 zero_float2()
ccl_device_inline float3 zero_float3()
ccl_device_inline float4 zero_float4()
void python_thread_state_restore(void **python_thread_state)
void python_thread_state_save(void **python_thread_state)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
PropertyType RNA_property_type(PropertyRNA *prop)
const PointerRNA PointerRNA_NULL
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
float RNA_float_get(PointerRNA *ptr, const char *name)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
bool is_real_object_data() const
int motion_step(float time) const
static const uint MAX_MOTION_STEPS
float motion_time(int step) const
T * create_node(Args &&...args)
vector< Geometry * > geometry
MotionType need_motion() const
float motion_shutter_time()
void wait_work(Summary *stats=NULL)