18 template<
typename TypeInCycles,
typename GetValueAtIndex>
21 const GetValueAtIndex &get_value_at_index)
23 const int num_points = b_pointcloud.points.length();
24 for (
int i = 0; i < num_points; i++) {
25 data[i] = get_value_at_index(i);
31 const float motion_scale)
33 if (!(b_attribute.domain() == BL::Attribute::domain_POINT) &&
34 (b_attribute.data_type() == BL::Attribute::data_type_FLOAT_VECTOR)) {
38 BL::FloatVectorAttribute b_vector_attribute(b_attribute);
39 const int num_points = pointcloud->get_points().size();
42 float3 *
P = &pointcloud->get_points()[0];
50 float motion_times[2] = {-1.0f, 1.0f};
51 for (
int step = 0; step < 2; step++) {
52 const float relative_time = motion_times[step] * 0.5f * motion_scale;
55 for (
int i = 0; i < num_points; i++) {
56 mP[i] =
P[i] +
get_float3(b_vector_attribute.data[i].vector()) * relative_time;
63 const bool need_motion,
64 const float motion_scale)
67 static const ustring u_velocity(
"velocity");
69 const ustring name{b_attribute.name().c_str()};
71 if (need_motion && name == u_velocity) {
75 if (attributes.
find(name)) {
80 const BL::Attribute::data_type_enum b_data_type = b_attribute.data_type();
81 switch (b_data_type) {
82 case BL::Attribute::data_type_FLOAT: {
83 BL::FloatAttribute b_float_attribute{b_attribute};
87 b_pointcloud,
data, [&](
int i) {
return b_float_attribute.data[i].value(); });
90 case BL::Attribute::data_type_BOOLEAN: {
91 BL::BoolAttribute b_bool_attribute{b_attribute};
95 b_pointcloud,
data, [&](
int i) {
return (
float)b_bool_attribute.data[i].value(); });
98 case BL::Attribute::data_type_INT: {
99 BL::IntAttribute b_int_attribute{b_attribute};
103 b_pointcloud,
data, [&](
int i) {
return (
float)b_int_attribute.data[i].value(); });
106 case BL::Attribute::data_type_FLOAT_VECTOR: {
107 BL::FloatVectorAttribute b_vector_attribute{b_attribute};
111 BL::Array<float, 3>
v = b_vector_attribute.data[i].vector();
116 case BL::Attribute::data_type_FLOAT_COLOR: {
117 BL::FloatColorAttribute b_color_attribute{b_attribute};
121 BL::Array<float, 4>
v = b_color_attribute.data[i].color();
126 case BL::Attribute::data_type_FLOAT2: {
127 BL::Float2Attribute b_float2_attribute{b_attribute};
131 BL::Array<float, 2>
v = b_float2_attribute.data[i].vector();
146 if (b_attribute.name() !=
"radius") {
149 if (b_attribute.data_type() != BL::Attribute::data_type_FLOAT) {
152 return BL::FloatAttribute{b_attribute};
160 if (b_attribute.name() !=
"position") {
163 if (b_attribute.data_type() != BL::Attribute::data_type_FLOAT_VECTOR) {
166 return BL::FloatVectorAttribute{b_attribute};
170 return BL::FloatVectorAttribute{b_pointcloud.attributes[0]};
176 const bool need_motion,
177 const float motion_scale)
188 const int num_points = b_pointcloud.points.length();
189 pointcloud->
reserve(num_points);
195 for (
int i = 0; i < num_points; i++) {
197 const float radius = b_attr_radius ? b_attr_radius->data[i].value() : 0.0f;
201 if (attr_random !=
NULL) {
216 bool new_attribute =
false;
220 new_attribute =
true;
224 const int num_points = pointcloud->
num_points();
226 bool have_motion =
false;
227 const array<float3> &pointcloud_points = pointcloud->get_points();
229 const int b_points_num = b_pointcloud.points.length();
233 for (
int i = 0; i <
std::min(num_points, b_points_num); i++) {
235 const float radius = b_attr_radius ? b_attr_radius->data[i].value() : 0.0f;
239 have_motion = have_motion || (
P != pointcloud_points[i]);
244 if (b_points_num != num_points || !have_motion) {
247 else if (motion_step > 0) {
250 for (
int step = 0; step < motion_step; step++) {
262 size_t old_numpoints = pointcloud->
num_points();
267 new_pointcloud.set_used_shaders(used_shaders);
273 const float motion_scale = (need_motion) ?
275 (b_scene.render().fps() / b_scene.render().fps_base()) :
277 export_pointcloud(scene, &new_pointcloud, b_pointcloud, need_motion, motion_scale);
282 if (socket.
name ==
"use_motion_blur" || socket.
name ==
"motion_steps" ||
283 socket.
name ==
"used_shaders") {
286 pointcloud->
set_value(socket, new_pointcloud, socket);
295 const bool rebuild = (pointcloud && old_numpoints != pointcloud->
num_points());
299 void BlenderSync::sync_pointcloud_motion(
PointCloud *pointcloud,
int BKE_object_is_deform_modified(struct Scene *scene, struct Object *ob)
struct PointCloud PointCloud
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Attribute
static void export_pointcloud_motion(PointCloud *pointcloud, BL::PointCloud b_pointcloud, int motion_step)
static std::optional< BL::FloatAttribute > find_radius_attribute(BL::PointCloud b_pointcloud)
static BL::FloatVectorAttribute find_position_attribute(BL::PointCloud b_pointcloud)
static void export_pointcloud(Scene *scene, PointCloud *pointcloud, BL::PointCloud b_pointcloud, const bool need_motion, const float motion_scale)
static CCL_NAMESPACE_BEGIN void fill_generic_attribute(BL::PointCloud &b_pointcloud, TypeInCycles *data, const GetValueAtIndex &get_value_at_index)
static void copy_attributes(PointCloud *pointcloud, BL::PointCloud b_pointcloud, const bool need_motion, const float motion_scale)
static void attr_create_motion(PointCloud *pointcloud, BL::Attribute &b_attribute, const float motion_scale)
ATTR_WARN_UNUSED_RESULT const void * element
ATTR_WARN_UNUSED_RESULT const BMVert * v
Attribute * add(ustring name, TypeDesc type, AttributeElement element)
list< Attribute > attributes
Attribute * find(ustring name) const
void remove(ustring name)
void clear(bool preserve_voxel_data=false)
bool need_attribute(Scene *scene, AttributeStandard std)
void tag_update(Scene *scene, bool rebuild)
#define CCL_NAMESPACE_END
static float3 get_float3(const BL::Array< float, 2 > &array)
static bool object_need_motion_attribute(BObjectInfo &b_ob_info, Scene *scene)
ccl_device_inline float hash_uint2_to_float(uint kx, uint ky)
@ ATTR_STD_MOTION_VERTEX_POSITION
static constexpr TypeDesc TypeRGBA(TypeDesc::FLOAT, TypeDesc::VEC4, TypeDesc::COLOR)
CCL_NAMESPACE_BEGIN static constexpr OIIO_NAMESPACE_USING TypeDesc TypeFloat2(TypeDesc::FLOAT, TypeDesc::VEC2)
vector< SocketType, std::allocator< SocketType > > inputs
void set_value(const SocketType &input, const Node &other, const SocketType &other_input)
void reserve(int numpoints)
size_t num_points() const
void copy_center_to_motion_step(const int motion_step)
void add_point(float3 loc, float radius, int shader=0)
float motion_shutter_time()