41 bool BlenderSync::BKE_object_is_modified(
BL::Object &b_ob)
44 if (b_ob.type() == BL::Object::type_META) {
54 for (BL::MaterialSlot &b_slot : b_ob.material_slots) {
55 if (b_slot.link() == BL::MaterialSlot::link_OBJECT) {
64 bool BlenderSync::object_is_geometry(
BL::Object &b_ob)
66 BL::ID b_ob_data = b_ob.data();
72 BL::Object::type_enum
type = b_ob.type();
74 if (
type == BL::Object::type_VOLUME ||
type == BL::Object::type_HAIR) {
78 else if (
type == BL::Object::type_CURVE) {
83 return (b_curve.bevel_object() || b_curve.extrude() != 0.0f || b_curve.bevel_depth() != 0.0f ||
84 b_curve.dimensions() == BL::Curve::dimensions_2D || b_ob.modifiers.length());
92 bool BlenderSync::object_is_light(
BL::Object &b_ob)
94 BL::ID b_ob_data = b_ob.data();
96 return (b_ob_data && b_ob_data.is_a(&
RNA_Light));
104 object->set_motion(motion);
111 Geometry *geom =
object->get_geometry();
113 int motion_steps = 0;
114 bool use_motion_blur =
false;
119 use_motion_blur =
true;
126 geom->set_use_motion_blur(use_motion_blur);
127 geom->set_motion_steps(motion_steps);
132 motion[motion_steps / 2] =
object->get_tfm();
135 object->set_motion(motion);
137 for (
size_t step = 0; step < motion_steps; step++) {
145 BL::DepsgraphObjectInstance &b_instance,
147 bool use_particle_hair,
153 const bool is_instance = b_instance.is_instance();
155 BL::Object b_parent = is_instance ? b_instance.
parent() : b_instance.object();
156 BL::Object b_ob_instance = is_instance ? b_instance.instance_object() : b_ob;
157 const bool motion = motion_time != 0.0f;
159 int *persistent_id =
NULL;
160 BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id_array;
162 persistent_id_array = b_instance.persistent_id();
163 persistent_id = persistent_id_array.data;
167 if (!motion && object_is_light(b_ob)) {
175 if (!((layer_flag & view_layer.holdout_layer) && (layer_flag & view_layer.exclude_layer)))
182 is_instance ? b_instance.random_id() : 0,
191 if (!object_is_geometry(b_ob)) {
196 if (culling.
test(scene, b_ob, tfm)) {
202 bool use_holdout =
get_boolean(cobject,
"is_holdout") ||
206 if (b_parent.ptr.data != b_ob.ptr.data) {
212 if (use_holdout && (layer_flag & view_layer.exclude_layer)) {
218 bool use_indirect_only = !use_holdout &&
220 if (use_indirect_only) {
225 if (visibility == 0) {
231 TaskPool *object_geom_task_pool = (is_instance) ?
NULL : geom_task_pool;
234 ObjectKey key(b_parent, persistent_id, b_ob_instance, use_particle_hair);
239 object = object_map.
find(key);
244 if (time_index >= 0) {
246 motion[time_index] = tfm;
247 object->set_motion(motion);
251 if (object->get_geometry())
252 sync_geometry_motion(b_depsgraph,
257 object_geom_task_pool);
264 bool object_updated = object_map.
add_or_update(&
object, b_ob, b_parent, key) ||
265 (tfm !=
object->get_tfm());
271 Geometry *geometry = sync_geometry(b_depsgraph,
276 object_geom_task_pool);
277 object->set_geometry(geometry);
281 if (sync_object_attributes(b_instance,
object)) {
282 object_updated =
true;
286 object->set_use_holdout(use_holdout);
288 object->set_visibility(visibility);
290 bool is_shadow_catcher =
get_boolean(cobject,
"is_shadow_catcher");
291 object->set_is_shadow_catcher(is_shadow_catcher);
293 float shadow_terminator_offset =
get_float(cobject,
"shadow_terminator_offset");
294 object->set_shadow_terminator_offset(shadow_terminator_offset);
300 while (parent.parent()) {
303 parent_name = parent.
name();
306 parent_name = b_ob.name();
308 object->set_asset_name(parent_name);
314 (object->get_geometry() && object->get_geometry()->
is_modified())) {
315 object->name = b_ob.name().c_str();
316 object->set_pass_id(b_ob.pass_index());
318 object->set_tfm(tfm);
322 object->set_dupli_generated(0.5f *
get_float3(b_instance.orco()) -
324 object->set_dupli_uv(
get_float2(b_instance.uv()));
325 object->set_random_id(b_instance.random_id());
333 object->tag_update(scene);
336 sync_object_motion_init(b_parent, b_ob,
object);
340 sync_dupli_particle(b_parent, b_instance,
object);
390 string idprop_name =
string_printf(
"[\"%s\"]", name.c_str());
394 if (use_instancer && b_instance.is_instance()) {
411 BL::ID b_data = b_ob.data();
421 bool BlenderSync::sync_object_attributes(BL::DepsgraphObjectInstance &b_instance,
Object *
object)
428 bool changed =
false;
430 for (
int i = attributes.size() - 1; i >= 0; i--) {
431 if (!requests.
find(attributes[i].name())) {
432 attributes.erase(attributes.begin() + i);
439 ustring name = req.
name;
441 std::string real_name;
444 if (
type != BL::ShaderNodeAttribute::attribute_type_GEOMETRY) {
445 bool use_instancer = (
type == BL::ShaderNodeAttribute::attribute_type_INSTANCER);
449 ParamValue *param =
NULL;
451 for (
size_t i = 0; i < attributes.size(); i++) {
452 if (attributes[i].name() == name) {
453 param = &attributes[i];
459 ParamValue new_param(name, TypeDesc::TypeFloat4, 1, &value);
460 assert(new_param.datasize() ==
sizeof(value));
464 attributes.push_back(new_param);
466 else if (memcmp(param->data(), &value,
sizeof(value)) != 0) {
479 BL::SpaceView3D &b_v3d,
486 bool motion = motion_time != 0.0f;
494 motion_times.clear();
497 geometry_motion_synced.clear();
505 bool use_portal =
false;
509 BL::Depsgraph::object_instances_iterator b_instance_iter;
511 for (b_depsgraph.object_instances.begin(b_instance_iter);
512 b_instance_iter != b_depsgraph.object_instances.end() && !cancel;
514 BL::DepsgraphObjectInstance b_instance = *b_instance_iter;
518 const bool show_in_viewport = !b_v3d || b_ob.visible_in_viewport_get(b_v3d);
519 if (show_in_viewport ==
false) {
529 const bool sync_hair = b_instance.show_particles() && object_has_particle_hair(b_ob);
532 if (b_instance.show_self()) {
533 sync_object(b_depsgraph,
541 sync_hair ?
NULL : &geom_task_pool);
546 sync_object(b_depsgraph,
564 if (!cancel && !motion) {
565 sync_background_light(b_v3d, use_portal);
575 geometry_motion_synced.clear();
578 void BlenderSync::sync_motion(BL::RenderSettings &b_render,
580 BL::SpaceView3D &b_v3d,
584 void **python_thread_state)
594 int frame_center = b_scene.frame_current();
595 float subframe_center = b_scene.frame_subframe();
596 float frame_center_delta = 0.0f;
600 float shuttertime = scene->
camera->get_shuttertime();
602 frame_center_delta = -shuttertime * 0.5f;
606 frame_center_delta = shuttertime * 0.5f;
609 float time = frame_center + subframe_center + frame_center_delta;
611 float subframe =
time - frame;
613 b_engine.frame_set(frame, subframe);
616 sync_camera_motion(b_render, b_cam,
width,
height, 0.0f);
618 sync_objects(b_depsgraph, b_v3d);
625 for (
size_t step = 0; step < camera_motion_steps; step++) {
631 foreach (
float relative_time, motion_times) {
633 if (relative_time == 0.0f) {
637 VLOG(1) <<
"Synchronizing motion for the relative time " << relative_time <<
".";
643 float time = frame_center + subframe_center + frame_center_delta +
644 relative_time * shuttertime * 0.5f;
646 float subframe =
time - frame;
650 b_engine.frame_set(frame, subframe);
654 sync_camera_motion(b_render, b_cam,
width,
height, relative_time);
657 sync_objects(b_depsgraph, b_v3d, relative_time);
664 b_engine.frame_set(frame_center, subframe_center);
int BKE_object_is_modified(struct Scene *scene, struct Object *ob)
struct Depsgraph Depsgraph
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 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
_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 height
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)
void python_thread_state_restore(void **python_thread_state)
void python_thread_state_save(void **python_thread_state)
BlenderAttributeType blender_attribute_name_split_type(ustring name, string *r_real_name)
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)
CCL_NAMESPACE_BEGIN typedef BL::ShaderNodeAttribute::attribute_type_enum BlenderAttributeType
static float2 get_float2(const BL::Array< float, 2 > &array)
static Transform get_transform(const BL::Array< float, 16 > &array)
static bool object_use_deform_motion(BL::Object &b_parent, BL::Object &b_ob)
vector< AttributeRequest > requests
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)
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
#define make_float4(x, y, z, w)
#define make_float3(x, y, z)
@ PATH_RAY_ALL_VISIBILITY
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)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
int motion_step(float time) const
static const uint MAX_MOTION_STEPS
float motion_time(int step) const
float motion_shutter_time()
void wait_work(Summary *stats=NULL)
static uint hash_string(const char *str)
ccl_device_inline uint hash_uint2(uint kx, uint ky)
ccl_device_inline float2 zero_float2()
ccl_device_inline float3 zero_float3()
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)