Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/pointcloud.cpp
| Show All 31 Lines | static void fill_generic_attribute(BL::PointCloud &b_pointcloud, | ||||
| const GetValueAtIndex &get_value_at_index) | const GetValueAtIndex &get_value_at_index) | ||||
| { | { | ||||
| const int num_points = b_pointcloud.points.length(); | const int num_points = b_pointcloud.points.length(); | ||||
| for (int i = 0; i < num_points; i++) { | for (int i = 0; i < num_points; i++) { | ||||
| data[i] = get_value_at_index(i); | data[i] = get_value_at_index(i); | ||||
| } | } | ||||
| } | } | ||||
| static void copy_attributes(PointCloud *pointcloud, BL::PointCloud b_pointcloud) | static void attr_create_motion(PointCloud *pointcloud, | ||||
| BL::Attribute &b_attribute, | |||||
| const float motion_scale) | |||||
| { | |||||
| if (!(b_attribute.domain() == BL::Attribute::domain_POINT) && | |||||
| (b_attribute.data_type() == BL::Attribute::data_type_FLOAT_VECTOR)) { | |||||
| return; | |||||
| } | |||||
| BL::FloatVectorAttribute b_vector_attribute(b_attribute); | |||||
| const int num_points = pointcloud->get_points().size(); | |||||
| /* Find or add attribute */ | |||||
| float3 *P = &pointcloud->get_points()[0]; | |||||
| Attribute *attr_mP = pointcloud->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | |||||
| if (!attr_mP) { | |||||
| attr_mP = pointcloud->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION); | |||||
| } | |||||
| /* Only export previous and next frame, we don't have any in between data. */ | |||||
| float motion_times[2] = {-1.0f, 1.0f}; | |||||
| for (int step = 0; step < 2; step++) { | |||||
| const float relative_time = motion_times[step] * 0.5f * motion_scale; | |||||
| float3 *mP = attr_mP->data_float3() + step * num_points; | |||||
| for (int i = 0; i < num_points; i++) { | |||||
| mP[i] = P[i] + get_float3(b_vector_attribute.data[i].vector()) * relative_time; | |||||
| } | |||||
| } | |||||
| } | |||||
| static void copy_attributes(PointCloud *pointcloud, | |||||
| BL::PointCloud b_pointcloud, | |||||
| const bool need_motion, | |||||
| const float motion_scale) | |||||
| { | { | ||||
| AttributeSet &attributes = pointcloud->attributes; | AttributeSet &attributes = pointcloud->attributes; | ||||
| static const ustring u_velocity("velocity"); | |||||
| for (BL::Attribute &b_attribute : b_pointcloud.attributes) { | for (BL::Attribute &b_attribute : b_pointcloud.attributes) { | ||||
| const ustring name{b_attribute.name().c_str()}; | const ustring name{b_attribute.name().c_str()}; | ||||
| if (need_motion && name == u_velocity) { | |||||
| attr_create_motion(pointcloud, b_attribute, motion_scale); | |||||
| } | |||||
| if (attributes.find(name)) { | if (attributes.find(name)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| const AttributeElement element = ATTR_ELEMENT_VERTEX; | const AttributeElement element = ATTR_ELEMENT_VERTEX; | ||||
| const BL::Attribute::data_type_enum b_data_type = b_attribute.data_type(); | const BL::Attribute::data_type_enum b_data_type = b_attribute.data_type(); | ||||
| switch (b_data_type) { | switch (b_data_type) { | ||||
| case BL::Attribute::data_type_FLOAT: { | case BL::Attribute::data_type_FLOAT: { | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | switch (b_data_type) { | ||||
| } | } | ||||
| default: | default: | ||||
| /* Not supported. */ | /* Not supported. */ | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void export_pointcloud(Scene *scene, PointCloud *pointcloud, BL::PointCloud b_pointcloud) | static void export_pointcloud(Scene *scene, | ||||
| PointCloud *pointcloud, | |||||
| BL::PointCloud b_pointcloud, | |||||
| const bool need_motion, | |||||
| const float motion_scale) | |||||
| { | { | ||||
| /* TODO: optimize so we can straight memcpy arrays from Blender? */ | /* TODO: optimize so we can straight memcpy arrays from Blender? */ | ||||
| /* Add requested attributes. */ | /* Add requested attributes. */ | ||||
| Attribute *attr_random = NULL; | Attribute *attr_random = NULL; | ||||
| if (pointcloud->need_attribute(scene, ATTR_STD_POINT_RANDOM)) { | if (pointcloud->need_attribute(scene, ATTR_STD_POINT_RANDOM)) { | ||||
| attr_random = pointcloud->attributes.add(ATTR_STD_POINT_RANDOM); | attr_random = pointcloud->attributes.add(ATTR_STD_POINT_RANDOM); | ||||
| } | } | ||||
| Show All 13 Lines | for (b_pointcloud.points.begin(b_point_iter); b_point_iter != b_pointcloud.points.end(); | ||||
| /* Random number per point. */ | /* Random number per point. */ | ||||
| if (attr_random != NULL) { | if (attr_random != NULL) { | ||||
| attr_random->add(hash_uint2_to_float(b_point.index(), 0)); | attr_random->add(hash_uint2_to_float(b_point.index(), 0)); | ||||
| } | } | ||||
| } | } | ||||
| /* Export attributes */ | /* Export attributes */ | ||||
| copy_attributes(pointcloud, b_pointcloud); | copy_attributes(pointcloud, b_pointcloud, need_motion, motion_scale); | ||||
| } | } | ||||
| static void export_pointcloud_motion(PointCloud *pointcloud, | static void export_pointcloud_motion(PointCloud *pointcloud, | ||||
| BL::PointCloud b_pointcloud, | BL::PointCloud b_pointcloud, | ||||
| int motion_step) | int motion_step) | ||||
| { | { | ||||
| /* Find or add attribute. */ | /* Find or add attribute. */ | ||||
| Attribute *attr_mP = pointcloud->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | Attribute *attr_mP = pointcloud->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | ||||
| Show All 35 Lines | else if (motion_step > 0) { | ||||
| * they had no motion, but we need them anyway now. */ | * they had no motion, but we need them anyway now. */ | ||||
| for (int step = 0; step < motion_step; step++) { | for (int step = 0; step < motion_step; step++) { | ||||
| pointcloud->copy_center_to_motion_step(step); | pointcloud->copy_center_to_motion_step(step); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Export attributes */ | /* Export attributes */ | ||||
| copy_attributes(pointcloud, b_pointcloud); | copy_attributes(pointcloud, b_pointcloud, false, 0.0f); | ||||
| } | } | ||||
| void BlenderSync::sync_pointcloud(PointCloud *pointcloud, BObjectInfo &b_ob_info) | void BlenderSync::sync_pointcloud(PointCloud *pointcloud, BObjectInfo &b_ob_info) | ||||
| { | { | ||||
| size_t old_numpoints = pointcloud->num_points(); | size_t old_numpoints = pointcloud->num_points(); | ||||
| array<Node *> used_shaders = pointcloud->get_used_shaders(); | array<Node *> used_shaders = pointcloud->get_used_shaders(); | ||||
| PointCloud new_pointcloud; | PointCloud new_pointcloud; | ||||
| new_pointcloud.set_used_shaders(used_shaders); | new_pointcloud.set_used_shaders(used_shaders); | ||||
| /* TODO: add option to filter out points in the view layer. */ | /* TODO: add option to filter out points in the view layer. */ | ||||
| BL::PointCloud b_pointcloud(b_ob_info.object_data); | BL::PointCloud b_pointcloud(b_ob_info.object_data); | ||||
| export_pointcloud(scene, &new_pointcloud, b_pointcloud); | /* Motion blur attribute is relative to seconds, we need it relative to frames. */ | ||||
| const bool need_motion = object_need_motion_attribute(b_ob_info, scene); | |||||
| const float motion_scale = (need_motion) ? | |||||
| scene->motion_shutter_time() / | |||||
| (b_scene.render().fps() / b_scene.render().fps_base()) : | |||||
| 0.0f; | |||||
| export_pointcloud(scene, &new_pointcloud, b_pointcloud, need_motion, motion_scale); | |||||
| /* update original sockets */ | /* update original sockets */ | ||||
| for (const SocketType &socket : new_pointcloud.type->inputs) { | for (const SocketType &socket : new_pointcloud.type->inputs) { | ||||
| /* Those sockets are updated in sync_object, so do not modify them. */ | /* Those sockets are updated in sync_object, so do not modify them. */ | ||||
| if (socket.name == "use_motion_blur" || socket.name == "motion_steps" || | if (socket.name == "use_motion_blur" || socket.name == "motion_steps" || | ||||
| socket.name == "used_shaders") { | socket.name == "used_shaders") { | ||||
| continue; | continue; | ||||
| } | } | ||||
| Show All 35 Lines | |||||