24 const float motion_scale)
26 const int num_points = pointcloud->get_points().size();
29 pointcloud->set_motion_steps(3);
32 float3 *
P = pointcloud->get_points().data();
33 float *radius = pointcloud->get_radius().data();
41 const float motion_times[2] = {-1.0f, 1.0f};
43 const float relative_time = motion_times[
step] * 0.5f * motion_scale;
46 for (
int i = 0;
i < num_points;
i++) {
48 make_float3(b_attribute[
i][0], b_attribute[
i][1], b_attribute[
i][2]) *
56 const ::PointCloud &b_pointcloud,
57 const bool need_motion,
58 const float motion_scale)
66 static const ustring u_velocity(
"velocity");
68 const ustring
name{std::string_view(iter.
name)};
70 if (need_motion &&
name == u_velocity) {
81 using BlenderT = decltype(dummy);
82 using Converter = typename ccl::AttributeConverter<BlenderT>;
83 using CyclesT = typename Converter::CyclesT;
84 if constexpr (!std::is_void_v<CyclesT>) {
85 Attribute *attr = attributes.add(name, Converter::type_desc, ATTR_ELEMENT_VERTEX);
86 CyclesT *data = reinterpret_cast<CyclesT *>(attr->data());
88 const blender::VArraySpan src = b_attr.varray.typed<BlenderT>();
89 for (const int i : src.index_range()) {
90 data[i] = Converter::convert(src[i]);
99 const ::PointCloud &b_pointcloud,
100 const bool need_motion,
101 const float motion_scale)
109 float3 *points = pointcloud->get_points().data();
112 points[
i] =
make_float3(b_positions[
i][0], b_positions[
i][1], b_positions[
i][2]);
115 float *radius = pointcloud->get_radius().data();
117 std::copy(b_radius.
data(), b_radius.
data() + b_positions.
size(), radius);
120 std::fill(radius, radius + b_positions.
size(), 0.01f);
123 int *shader = pointcloud->get_shader().data();
124 std::fill(shader, shader + b_positions.
size(), 0);
138 const ::PointCloud &b_pointcloud,
139 const int motion_step)
143 bool new_attribute =
false;
147 new_attribute =
true;
150 const int num_points = pointcloud->
num_points();
155 bool have_motion =
false;
156 const array<float3> &pointcloud_points = pointcloud->get_points();
164 const float radius = b_radius.
is_empty() ? 0.01f : b_radius[
i];
166 have_motion = have_motion || (
P != pointcloud_points[
i]);
171 if (b_positions.
size() != num_points || !have_motion) {
174 else if (motion_step > 0) {
189 const size_t old_numpoints = pointcloud->
num_points();
191 array<Node *> used_shaders = pointcloud->get_used_shaders();
194 new_pointcloud.set_used_shaders(used_shaders);
197 const BL::PointCloud b_pointcloud(b_ob_info.
object_data);
200 const float motion_scale = (need_motion) ?
201 scene->motion_shutter_time() /
202 (b_scene.render().fps() / b_scene.render().fps_base()) :
206 *
static_cast<const ::
PointCloud *
>(b_pointcloud.ptr.data),
213 for (
const SocketType &socket : new_pointcloud.
type->
inputs) {
215 if (socket.
name ==
"use_motion_blur" || socket.
name ==
"used_shaders") {
218 pointcloud->
set_value(socket, new_pointcloud, socket);
224 const bool rebuild = (pointcloud && old_numpoints != pointcloud->
num_points());
228void BlenderSync::sync_pointcloud_motion(
PointCloud *pointcloud,
230 const int motion_step)
238 if (ccl::BKE_object_is_deform_modified(b_ob_info, b_scene, preview)) {
240 const BL::PointCloud b_pointcloud(b_ob_info.
object_data);
242 pointcloud, *
static_cast<const ::
PointCloud *
>(b_pointcloud.ptr.data), motion_step);
struct PointCloud PointCloud
static void export_pointcloud(Scene *scene, PointCloud *pointcloud, const ::PointCloud &b_pointcloud, const bool need_motion, const float motion_scale)
static void export_pointcloud_motion(PointCloud *pointcloud, const ::PointCloud &b_pointcloud, const int motion_step)
static void copy_attributes(PointCloud *pointcloud, const ::PointCloud &b_pointcloud, const bool need_motion, const float motion_scale)
static CCL_NAMESPACE_BEGIN void attr_create_motion_from_velocity(PointCloud *pointcloud, const blender::Span< blender::float3 > b_attribute, const float motion_scale)
BMesh const char void * data
void update(AttributeSet &&new_attributes)
Attribute * find(ustring name) const
Attribute * add(ustring name, const TypeDesc type, AttributeElement element)
void remove(ustring name)
void tag_update(Scene *scene, bool rebuild)
bool need_attribute(Scene *scene, AttributeStandard std)
const CPPType & type() const
constexpr const T * data() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
int domain_size(const AttrDomain domain) const
GAttributeReader get() const
static bool object_need_motion_attribute(BObjectInfo &b_ob_info, Scene *scene)
#define CCL_NAMESPACE_END
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline float hash_uint2_to_float(const uint kx, const uint ky)
@ ATTR_STD_MOTION_VERTEX_POSITION
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
VecBase< float, 3 > float3
vector< SocketType, std::allocator< SocketType > > inputs
void set_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
void resize(const int numpoints)
size_t num_points() const
void copy_center_to_motion_step(const int motion_step)