Blender V5.3
blender/curves.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include <optional>
6
8#include "blender/sync.h"
9#include "blender/util.h"
10
11#include "scene/attribute.h"
12#include "scene/camera.h"
13#include "scene/curves.h"
14#include "scene/hair.h"
15#include "scene/object.h"
16#include "scene/scene.h"
17
18#include "util/color.h"
19
20#include "util/hash.h"
21#include "util/log.h"
22
23#include "DNA_meshdata_types.h"
24#include "DNA_modifier_types.h"
25#include "DNA_particle_types.h"
26
27#include "BLI_listbase.hh"
28#include "BLI_math_matrix_c.hh"
29#include "BLI_math_vector_c.hh"
30
31#include "BKE_attribute.hh"
32#include "BKE_curves.hh"
33#include "BKE_customdata.hh"
35#include "BKE_particle.h"
36
37namespace blender {
38struct ModifierData;
39}
40
42
44
46
47static float shaperadius(const float shape, const float root, const float tip, const float time)
48{
49 assert(time >= 0.0f);
50 assert(time <= 1.0f);
51 float radius = 1.0f - time;
52
53 if (shape != 0.0f) {
54 if (shape < 0.0f) {
55 radius = powf(radius, 1.0f + shape);
56 }
57 else {
58 radius = powf(radius, 1.0f / (1.0f - shape));
59 }
60 }
61 return (radius * (root - tip)) + tip;
62}
63
64/* curve functions */
65
66static bool ObtainCacheParticleData(Hair *hair,
67 const blender::Mesh *b_mesh,
68 const blender::Object *b_ob,
69 ParticleCurveData *CData,
70 bool background)
71{
72 int curvenum = 0;
73 int keyno = 0;
74
75 if (!(hair && b_mesh && b_ob && CData)) {
76 return false;
77 }
78
79 const Transform tfm = get_transform(b_ob->object_to_world());
80 const Transform itfm = transform_inverse(tfm);
81
82 for (const blender::ModifierData &b_mod : b_ob->modifiers) {
84 (background ? ((b_mod.mode & blender::eModifierMode_Render) != 0) :
85 ((b_mod.mode & blender::eModifierMode_Realtime) != 0)))
86 {
87 const auto *psmd = reinterpret_cast<const blender::ParticleSystemModifierData *>(&b_mod);
88 blender::ParticleSystem *b_psys = psmd->psys;
89 blender::ParticleSettings *b_part = b_psys->part;
90
91 if ((b_part->ren_as == blender::PART_DRAW_PATH) && (b_part->type == blender::PART_HAIR)) {
92 const int shader = clamp(b_part->omat - 1, 0, hair->get_used_shaders().size() - 1);
93 const int display_step = background ? b_part->ren_step : b_part->draw_step;
94 const int totparts = b_psys->totpart;
95 const int totchild = background ?
96 b_psys->totchild :
97 (int)((float)b_psys->totchild * (float)b_part->disp / 100.0f);
98 int totcurves = totchild;
99
100 if (b_part->childtype == 0 || totchild == 0) {
101 totcurves += totparts;
102 }
103
104 if (totcurves == 0) {
105 continue;
106 }
107
108 int ren_step = (1 << display_step) + 1;
109 if (b_part->kink == blender::PART_KINK_SPIRAL) {
110 ren_step += b_part->kink_extra_steps;
111 }
112
113 CData->psys_firstcurve.push_back_slow(curvenum);
114 CData->psys_curvenum.push_back_slow(totcurves);
115 CData->psys_shader.push_back_slow(shader);
116
117 const float radius = b_part->rad_scale * 0.5f;
118
119 CData->psys_rootradius.push_back_slow(radius * b_part->rad_root);
120 CData->psys_tipradius.push_back_slow(radius * b_part->rad_tip);
121 CData->psys_shape.push_back_slow(b_part->shape);
123 0);
124
125 int pa_no = 0;
126 if (!(b_part->childtype == 0) && totchild != 0) {
127 pa_no = totparts;
128 }
129
130 const int num_add = (totparts + totchild - pa_no);
131 CData->curve_firstkey.reserve(CData->curve_firstkey.size() + num_add);
132 CData->curve_keynum.reserve(CData->curve_keynum.size() + num_add);
133 CData->curve_length.reserve(CData->curve_length.size() + num_add);
134 CData->curvekey_co.reserve(CData->curvekey_co.size() + num_add * ren_step);
135 CData->curvekey_time.reserve(CData->curvekey_time.size() + num_add * ren_step);
136
137 for (; pa_no < totparts + totchild; pa_no++) {
138 int keynum = 0;
139 CData->curve_firstkey.push_back_slow(keyno);
140
141 float curve_length = 0.0f;
142 float3 prev_co_world = zero_float3();
143 float3 prev_co_object = zero_float3();
144 for (int step_no = 0; step_no < ren_step; step_no++) {
145 float3 co_world = prev_co_world;
146 BKE_particle_co_hair(b_psys, b_ob, pa_no, step_no, &co_world.x);
147 const float3 co_object = transform_point(&itfm, co_world);
148 if (step_no > 0) {
149 const float step_length = len(co_object - prev_co_object);
150 curve_length += step_length;
151 }
152 CData->curvekey_co.push_back_slow(co_object);
153 CData->curvekey_time.push_back_slow(curve_length);
154 prev_co_object = co_object;
155 prev_co_world = co_world;
156 keynum++;
157 }
158 keyno += keynum;
159
160 CData->curve_keynum.push_back_slow(keynum);
161 CData->curve_length.push_back_slow(curve_length);
162 curvenum++;
163 }
164 }
165 }
166 }
167
168 return true;
169}
170
171static bool ObtainCacheParticleUV(Hair *hair,
172 const blender::Mesh *b_mesh,
173 const blender::Object *b_ob,
174 ParticleCurveData *CData,
175 bool background,
176 const int uv_num)
177{
178 if (!(hair && b_mesh && b_ob && CData)) {
179 return false;
180 }
181
182 CData->curve_uv.clear();
183
184 for (blender::ModifierData &b_mod : b_ob->modifiers) {
186 (background ? ((b_mod.mode & blender::eModifierMode_Render) != 0) :
187 ((b_mod.mode & blender::eModifierMode_Realtime) != 0)))
188 {
189 auto *psmd = reinterpret_cast<blender::ParticleSystemModifierData *>(&b_mod);
190 blender::ParticleSystem *b_psys = psmd->psys;
191 blender::ParticleSettings *b_part = b_psys->part;
192
193 if ((b_part->ren_as == blender::PART_DRAW_PATH) && (b_part->type == blender::PART_HAIR)) {
194 const int totparts = b_psys->totpart;
195 const int totchild = background ?
196 b_psys->totchild :
197 (int)((float)b_psys->totchild * (float)b_part->disp / 100.0f);
198 int totcurves = totchild;
199
200 if (b_part->childtype == 0 || totchild == 0) {
201 totcurves += totparts;
202 }
203
204 if (totcurves == 0) {
205 continue;
206 }
207
208 int pa_no = 0;
209 if (!(b_part->childtype == 0) && totchild != 0) {
210 pa_no = totparts;
211 }
212
213 const int num_add = (totparts + totchild - pa_no);
214 CData->curve_uv.reserve(CData->curve_uv.size() + num_add);
215
217 b_psys->totpart);
218 auto *b_pa = b_psys_particles.begin();
219 for (; pa_no < totparts + totchild; pa_no++) {
220 /* Add UVs */
221 float2 uv = zero_float2();
222 BKE_particle_uv_on_emitter(b_psys, nullptr, psmd, b_pa, pa_no, uv_num, &uv.x);
223 CData->curve_uv.push_back_slow(uv);
224
225 if (pa_no < totparts && b_pa != b_psys_particles.end()) {
226 ++b_pa;
227 }
228 }
229 }
230 }
231 }
232
233 return true;
234}
235
237 const blender::Mesh *b_mesh,
238 const blender::Object *b_ob,
239 ParticleCurveData *CData,
240 bool background,
241 const int vcol_num)
242{
243 if (!(hair && b_mesh && b_ob && CData)) {
244 return false;
245 }
246
247 CData->curve_vcol.clear();
248
249 for (blender::ModifierData &b_mod : b_ob->modifiers) {
251 (background ? ((b_mod.mode & blender::eModifierMode_Render) != 0) :
252 ((b_mod.mode & blender::eModifierMode_Realtime) != 0)))
253 {
254 auto *psmd = reinterpret_cast<blender::ParticleSystemModifierData *>(&b_mod);
255 blender::ParticleSystem *b_psys = psmd->psys;
256 blender::ParticleSettings *b_part = b_psys->part;
257
258 if ((b_part->ren_as == blender::PART_DRAW_PATH) && (b_part->type == blender::PART_HAIR)) {
259 const int totparts = b_psys->totpart;
260 const int totchild = background ?
261 b_psys->totchild :
262 (int)((float)b_psys->totchild * (float)b_part->disp / 100.0f);
263 int totcurves = totchild;
264
265 if (b_part->childtype == 0 || totchild == 0) {
266 totcurves += totparts;
267 }
268
269 if (totcurves == 0) {
270 continue;
271 }
272
273 int pa_no = 0;
274 if (!(b_part->childtype == 0) && totchild != 0) {
275 pa_no = totparts;
276 }
277
278 const int num_add = (totparts + totchild - pa_no);
279 CData->curve_vcol.reserve(CData->curve_vcol.size() + num_add);
280
282 b_psys->totpart);
283 auto *b_pa = b_psys_particles.begin();
284 for (; pa_no < totparts + totchild; pa_no++) {
285 /* Add vertex colors */
286 float4 vcol = make_float4(0.0f, 0.0f, 0.0f, 1.0f);
287 BKE_particle_mcol_on_emitter(b_psys, nullptr, psmd, b_pa, pa_no, vcol_num, &vcol.x);
288 CData->curve_vcol.push_back_slow(vcol);
289
290 if (pa_no < totparts && b_pa != b_psys_particles.end()) {
291 ++b_pa;
292 }
293 }
294 }
295 }
296 }
297
298 return true;
299}
300
301static void ExportCurveSegments(Scene *scene, Hair *hair, ParticleCurveData *CData)
302{
303 int num_keys = 0;
304 int num_curves = 0;
305
306 if (hair->num_curves()) {
307 return;
308 }
309
310 /* compute and reserve size of arrays */
311 for (int sys = 0; sys < CData->psys_firstcurve.size(); sys++) {
312 for (int curve = CData->psys_firstcurve[sys];
313 curve < CData->psys_firstcurve[sys] + CData->psys_curvenum[sys];
314 curve++)
315 {
316 num_keys += CData->curve_keynum[curve];
317 num_curves++;
318 }
319 }
320
321 hair->resize_curves(hair->num_curves() + num_curves, hair->num_keys() + num_keys);
322
323 packed_normal *attr_normal = nullptr;
324 float *attr_intercept = nullptr;
325 float *attr_length = nullptr;
326 float *attr_random = nullptr;
327
328 if (hair->need_attribute(scene, ATTR_STD_VERTEX_NORMAL)) {
330 }
331 if (hair->need_attribute(scene, ATTR_STD_CURVE_INTERCEPT)) {
332 attr_intercept = hair->attributes.add(ATTR_STD_CURVE_INTERCEPT)->data_for_write<float>();
333 }
334 if (hair->need_attribute(scene, ATTR_STD_CURVE_LENGTH)) {
335 attr_length = hair->attributes.add(ATTR_STD_CURVE_LENGTH)->data_for_write<float>();
336 }
337 if (hair->need_attribute(scene, ATTR_STD_CURVE_RANDOM)) {
338 attr_random = hair->attributes.add(ATTR_STD_CURVE_RANDOM)->data_for_write<float>();
339 }
340
341 int *curve_first_key = hair->get_curve_first_key().data();
342 int *curve_shader = hair->get_curve_shader().data();
343
344 packed_float3 *curve_keys = hair->get_position_for_write();
345 float *curve_radius = hair->get_radius_for_write();
346
347 num_keys = 0;
348 num_curves = 0;
349
350 /* actually export */
351 for (int sys = 0; sys < CData->psys_firstcurve.size(); sys++) {
352 for (int curve = CData->psys_firstcurve[sys];
353 curve < CData->psys_firstcurve[sys] + CData->psys_curvenum[sys];
354 curve++)
355 {
356 curve_first_key[num_curves] = num_keys;
357
358 for (int curvekey = CData->curve_firstkey[curve];
359 curvekey < CData->curve_firstkey[curve] + CData->curve_keynum[curve];
360 curvekey++)
361 {
362 const float3 ickey_loc = CData->curvekey_co[curvekey];
363 const float curve_time = CData->curvekey_time[curvekey];
364 const float curve_length = CData->curve_length[curve];
365 const float time = (curve_length > 0.0f) ? curve_time / curve_length : 0.0f;
366 float radius = shaperadius(
367 CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], time);
368 if (CData->psys_closetip[sys] &&
369 (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1))
370 {
371 radius = 0.0f;
372 }
373 curve_keys[num_keys] = ickey_loc;
374 curve_radius[num_keys] = radius;
375 if (attr_intercept) {
376 attr_intercept[num_keys] = time;
377 }
378
379 if (attr_normal) {
380 /* NOTE: the geometry normals are not computed for legacy particle hairs. This hair
381 * system is expected to be deprecated. */
382 attr_normal[num_keys] = packed_normal(make_float3(0.0f, 0.0f, 0.0f));
383 }
384
385 num_keys++;
386 }
387
388 if (attr_length != nullptr) {
389 attr_length[num_curves] = CData->curve_length[curve];
390 }
391
392 if (attr_random != nullptr) {
393 attr_random[num_curves] = hash_uint2_to_float(num_curves, 0);
394 }
395
396 curve_shader[num_curves] = CData->psys_shader[sys];
397
398 num_curves++;
399 }
400 }
401
402 hair->tag_position_modified();
403 hair->tag_radius_modified();
404 hair->tag_curve_first_key_modified();
405 hair->tag_curve_shader_modified();
406
407 /* check allocation */
408 if ((hair->num_keys() != num_keys) || (hair->num_curves() != num_curves)) {
409 LOG_ERROR << "Hair memory allocation failed, clearing data.";
410 hair->clear(true);
411 }
412}
413
415 const int sys,
416 const int curve,
417 const int curvekey)
418{
419 const float3 ickey_loc = CData->curvekey_co[curvekey];
420 const float curve_time = CData->curvekey_time[curvekey];
421 const float curve_length = CData->curve_length[curve];
422 const float time = (curve_length > 0.0f) ? curve_time / curve_length : 0.0f;
423 float radius = shaperadius(
424 CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], time);
425
426 if (CData->psys_closetip[sys] &&
427 (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1))
428 {
429 radius = 0.0f;
430 }
431
432 /* curve motion keys store both position and radius in float4 */
433 float4 mP = make_float4(ickey_loc);
434 mP.w = radius;
435 return mP;
436}
437
439 const int sys,
440 const int curve,
441 const float step)
442{
443 assert(step >= 0.0f);
444 assert(step <= 1.0f);
445 const int first_curve_key = CData->curve_firstkey[curve];
446 const float curve_key_f = step * (CData->curve_keynum[curve] - 1);
447 int curvekey = (int)floorf(curve_key_f);
448 const float remainder = curve_key_f - curvekey;
449 if (remainder == 0.0f) {
450 return CurveSegmentMotionCV(CData, sys, curve, first_curve_key + curvekey);
451 }
452 int curvekey2 = curvekey + 1;
453 if (curvekey2 >= (CData->curve_keynum[curve] - 1)) {
454 curvekey2 = (CData->curve_keynum[curve] - 1);
455 curvekey = curvekey2 - 1;
456 }
457 const float4 mP = CurveSegmentMotionCV(CData, sys, curve, first_curve_key + curvekey);
458 const float4 mP2 = CurveSegmentMotionCV(CData, sys, curve, first_curve_key + curvekey2);
459 return mix(mP, mP2, remainder);
460}
461
463 const int motion_step,
464 const int num_motion_keys,
465 bool have_motion)
466{
468 Attribute *attr_R = hair->attributes.find(ATTR_STD_RADIUS);
469 const int num_keys = hair->num_keys();
470
471 if (num_motion_keys != num_keys || !have_motion) {
472 /* No motion or hair "topology" changed, remove motion steps. */
473 if (num_motion_keys != num_keys) {
474 LOG_DEBUG << "Hair topology changed, removing motion attribute.";
475 }
476 attr_P->remove_motion();
477 attr_R->remove_motion();
478 }
479 else if (motion_step > 0) {
480 /* Motion, fill up previous steps that we might have skipped because
481 * they had no motion, but we need them anyway now. */
482 for (int step = 1; step <= motion_step; step++) {
484 std::copy_n(hair->get_position(), num_keys, mP);
485
486 float *mR = attr_R->data_for_write<float>(step);
487 std::copy_n(hair->get_radius(), num_keys, mR);
488 }
489 }
490}
491
492static void ExportCurveSegmentsMotion(Hair *hair, ParticleCurveData *CData, const int motion_step)
493{
494 /* Set motion steps on position and radius attributes. */
496 Attribute *attr_R = hair->attributes.find(ATTR_STD_RADIUS);
497 bool new_attribute = false;
498
499 if (!attr_P->has_motion()) {
500 attr_P->add_motion(hair);
501 attr_R->add_motion(hair);
502 new_attribute = true;
503 }
504
505 /* export motion vectors for curve keys */
506 const int attr_step = motion_step + 1;
507 packed_float3 *mP = attr_P->data_for_write<packed_float3>(attr_step);
508 float *mR = attr_R->data_for_write<float>(attr_step);
509 bool have_motion = false;
510 int i = 0;
511 int num_curves = 0;
512 const int num_keys = hair->num_keys();
513
514 for (int sys = 0; sys < CData->psys_firstcurve.size(); sys++) {
515 for (int curve = CData->psys_firstcurve[sys];
516 curve < CData->psys_firstcurve[sys] + CData->psys_curvenum[sys];
517 curve++)
518 {
519 /* Curve lengths may not match! Curves can be clipped. */
520 const int curve_key_end = (num_curves + 1 < (int)hair->get_curve_first_key().size() ?
521 hair->get_curve_first_key()[num_curves + 1] :
522 num_keys);
523 const int num_center_curve_keys = curve_key_end - hair->get_curve_first_key()[num_curves];
524 const int is_num_keys_different = CData->curve_keynum[curve] - num_center_curve_keys;
525
526 if (!is_num_keys_different) {
527 for (int curvekey = CData->curve_firstkey[curve];
528 curvekey < CData->curve_firstkey[curve] + CData->curve_keynum[curve];
529 curvekey++)
530 {
531 if (i < num_keys) {
532 const float4 cv = CurveSegmentMotionCV(CData, sys, curve, curvekey);
533 mP[i] = make_float3(cv);
534 mR[i] = cv.w;
535 if (!have_motion) {
536 /* unlike mesh coordinates, these tend to be slightly different
537 * between frames due to particle transforms into/out of object
538 * space, so we use an epsilon to detect actual changes */
539 float4 curve_key = make_float4(hair->get_position()[i]);
540 curve_key.w = hair->get_radius()[i];
541 if (len_squared(cv - curve_key) > 1e-5f * 1e-5f) {
542 have_motion = true;
543 }
544 }
545 }
546 i++;
547 }
548 }
549 else {
550 /* Number of keys has changed. Generate an interpolated version
551 * to preserve motion blur. */
552 const float step_size = num_center_curve_keys > 1 ? 1.0f / (num_center_curve_keys - 1) :
553 0.0f;
554 for (int step_index = 0; step_index < num_center_curve_keys; ++step_index) {
555 const float step = step_index * step_size;
556 const float4 cv = LerpCurveSegmentMotionCV(CData, sys, curve, step);
557 mP[i] = make_float3(cv);
558 mR[i] = cv.w;
559 i++;
560 }
561 have_motion = true;
562 }
563 num_curves++;
564 }
565 }
566
567 /* Keys without a matching curve keep the center position. */
568 if (i < num_keys) {
569 std::copy_n(hair->get_position() + i, num_keys - i, mP + i);
570 std::copy_n(hair->get_radius() + i, num_keys - i, mR + i);
571 }
572
573 /* In case of new attribute, we verify if there really was any motion. */
574 if (new_attribute) {
575 export_hair_motion_validate_attribute(hair, motion_step, i, have_motion);
576 }
577}
578
579/* Hair Curve Sync */
580
581bool BlenderSync::object_has_particle_hair(blender::Object *b_ob)
582{
583 /* Test if the object has a particle modifier with hair. */
584 for (blender::ModifierData &b_mod : b_ob->modifiers) {
586 (preview ? ((b_mod.mode & blender::eModifierMode_Realtime) != 0) :
587 ((b_mod.mode & blender::eModifierMode_Render) != 0)))
588 {
589 auto *psmd = reinterpret_cast<blender::ParticleSystemModifierData *>(&b_mod);
590 blender::ParticleSystem *b_psys = psmd->psys;
591 blender::ParticleSettings *b_part = b_psys->part;
592
593 if ((b_part->ren_as == blender::PART_DRAW_PATH) && (b_part->type == blender::PART_HAIR)) {
594 return true;
595 }
596 }
597 }
598
599 return false;
600}
601
602/* Old particle hair. */
603void BlenderSync::sync_particle_hair(Hair *hair,
604 const blender::Mesh &b_mesh,
605 BObjectInfo &b_ob_info,
606 bool motion,
607 const int motion_step)
608{
609 if (!b_ob_info.is_real_object_data()) {
610 return;
611 }
612 const blender::Object &b_ob = *b_ob_info.real_object;
613
614 /* obtain general settings */
616 return;
617 }
618
619 /* Extract particle hair data - should be combined with connecting to mesh later. */
620
621 ParticleCurveData CData;
622
623 ObtainCacheParticleData(hair, &b_mesh, &b_ob, &CData, !preview);
624
625 /* add hair geometry */
626 if (motion) {
627 ExportCurveSegmentsMotion(hair, &CData, motion_step);
628 }
629 else {
630 ExportCurveSegments(scene, hair, &CData);
631 }
632
633 /* generated coordinates from first key. we should ideally get this from
634 * blender to handle deforming objects */
635 if (!motion) {
636 if (hair->need_attribute(scene, ATTR_STD_GENERATED)) {
637 float3 loc;
638 float3 size;
639 mesh_texture_space(b_mesh, loc, size);
640
641 Attribute *attr_generated = hair->attributes.add(ATTR_STD_GENERATED);
642 packed_float3 *generated = attr_generated->data_for_write<packed_float3>();
643
644 for (size_t i = 0; i < hair->num_curves(); i++) {
645 const float3 co = hair->get_position()[hair->get_curve(i).first_key];
646 generated[i] = co * size - loc;
647 }
648 }
649 }
650
651 /* create vertex color attributes */
652 if (!motion) {
653 blender::Vector<blender::StringRef> vcol_names;
654 b_mesh.attributes().foreach_attribute([&](const blender::bke::AttributeIter &iter) {
656 return;
657 }
659 return;
660 }
661 vcol_names.append(iter.name);
662 });
663
664 for (const int vcol_num : vcol_names.index_range()) {
665 const ustring name = ustring(std::string_view(vcol_names[vcol_num]));
666 if (!hair->need_attribute(scene, name)) {
667 continue;
668 }
669
670 ObtainCacheParticleVcol(hair, &b_mesh, &b_ob, &CData, !preview, vcol_num);
671
672 Attribute *attr_vcol = hair->attributes.add(name, TypeRGBA, ATTR_ELEMENT_CURVE);
673
674 float4 *fdata = attr_vcol->data_for_write<float4>();
675
676 if (fdata) {
677 size_t i = 0;
678
679 /* Encode vertex color using the sRGB curve. */
680 for (size_t curve = 0; curve < CData.curve_vcol.size(); curve++) {
681 fdata[i++] = color_srgb_to_linear_v4(CData.curve_vcol[curve]);
682 }
683 }
684 }
685 }
686
687 /* create UV attributes */
688 if (!motion) {
689 const blender::VectorSet<blender::StringRefNull> uv_names = b_mesh.uv_map_names();
690 const ustring default_name = ustring(std::string_view(b_mesh.default_uv_map_name()));
691 for (const int uv_num : uv_names.index_range()) {
692 const ustring name = ustring(std::string_view(uv_names[uv_num]));
693 const bool active_render = name == default_name;
694 const AttributeStandard std = (active_render) ? ATTR_STD_UV : ATTR_STD_NONE;
695
696 /* UV map */
697 if (hair->need_attribute(scene, name) || hair->need_attribute(scene, std)) {
698 Attribute *attr_uv;
699
700 ObtainCacheParticleUV(hair, &b_mesh, &b_ob, &CData, !preview, uv_num);
701
702 if (active_render) {
703 attr_uv = hair->attributes.add(std, name);
704 }
705 else {
706 attr_uv = hair->attributes.add(name, TypeFloat2, ATTR_ELEMENT_CURVE);
707 }
708
709 float2 *uv = attr_uv->data_for_write<float2>();
710
711 if (uv) {
712 size_t i = 0;
713
714 for (size_t curve = 0; curve < CData.curve_uv.size(); curve++) {
715 uv[i++] = CData.curve_uv[curve];
716 }
717 }
718 }
719 }
720 }
721
722 hair->curve_shape = scene->params.hair_shape;
723}
724
727 const float motion_scale)
728{
729 const int num_curve_keys = hair->num_keys();
730
731 /* Override motion steps to fixed number. */
732 hair->set_motion_steps(3);
733
734 /* Set motion steps on position attribute. Radius doesn't change for
735 * velocity-based motion. */
737 attr_P->add_motion(hair);
738 const packed_float3 *P = hair->get_position();
739
740 /* Only export previous and next frame, we don't have any in between data. */
741 const float motion_times[2] = {-1.0f, 1.0f};
742 for (int step = 1; step <= 2; step++) {
743 const float relative_time = motion_times[step - 1] * 0.5f * motion_scale;
745
746 for (int i = 0; i < num_curve_keys; i++) {
747 mP[i] = float3(P[i]) + make_float3(src[i][0], src[i][1], src[i][2]) * relative_time;
748 }
749 }
750}
751
753{
754 switch (b_domain) {
757 break;
759 return ATTR_ELEMENT_CURVE;
760 break;
761 default:
762 assert(false);
763 return ATTR_ELEMENT_NONE;
764 }
765}
766
767static void attr_create_generic(Scene *scene,
768 Hair *hair,
769 const blender::bke::CurvesGeometry &b_curves,
770 const bool need_motion,
771 const float motion_scale)
772{
773 const blender::bke::AttributeAccessor b_attributes = b_curves.attributes();
774
775 AttributeSet &attributes = hair->attributes;
776 static const ustring u_velocity("velocity");
777 const bool need_uv = hair->need_attribute(scene, ATTR_STD_UV);
778 bool have_uv = false;
779
780 b_attributes.foreach_attribute([&](const blender::bke::AttributeIter &iter) {
781 const ustring name{std::string_view(iter.name)};
782
783 const blender::bke::AttrDomain b_domain = iter.domain;
784 const blender::bke::AttrType b_data_type = iter.data_type;
785
786 if (need_motion && name == u_velocity) {
787 const blender::VArraySpan b_attr = *iter.get<blender::float3>(
789 attr_create_motion_from_velocity(hair, b_attr, motion_scale);
790 return;
791 }
792
793 /* Weak, use first float2 attribute as standard UV. */
794 if (need_uv && !have_uv && b_data_type == blender::bke::AttrType::Float2 &&
796 {
797 Attribute *attr = attributes.add(ATTR_STD_UV, name);
798
799 const blender::VArraySpan b_attr = *iter.get<blender::float2>();
800
801 static_assert(sizeof(blender::float2) == sizeof(float2));
802 const blender::Span src = b_attr.cast<float2>();
803 std::copy(src.begin(), src.end(), attr->data_for_write<float2>());
804 have_uv = true;
805 return;
806 }
807
808 if (!hair->need_attribute(scene, name)) {
809 return;
810 }
811 if (attributes.find(name)) {
812 return;
813 }
814
815 const blender::bke::GAttributeReader b_attr = iter.get();
816
817 blender::bke::attribute_math::to_static_type(b_attr.varray.type(), [&]<typename BlenderT>() {
818 using Converter = typename ccl::AttributeConverter<BlenderT>;
819 using CyclesT = typename Converter::CyclesT;
820 if constexpr (!std::is_void_v<CyclesT>) {
821 const blender::VArray<BlenderT> src_varray = b_attr.varray.typed<BlenderT>();
822 const blender::CommonVArrayInfo info = b_attr.varray.common_info();
823
824 if (info.type == blender::CommonVArrayInfo::Type::Single) {
825 const auto &single_value = *static_cast<const BlenderT *>(info.data);
826 Attribute *attr = attributes.add(name, Converter::type_desc, ATTR_ELEMENT_MESH);
827 CyclesT *data = reinterpret_cast<CyclesT *>(attr->data_for_write());
828 *data = Converter::convert(single_value);
829 return;
830 }
831
832 const AttributeElement element = blender_domain_to_attr_element(b_attr.domain);
833 if constexpr (Converter::layout_compatible) {
834 if (src_varray.is_span() && b_attr.sharing_info) {
835 attributes.add_shared(name,
836 Converter::type_desc,
837 element,
838 info.data,
839 src_varray.size(),
840 b_attr.sharing_info);
841 return;
842 }
843 }
844
845 Attribute *attr = attributes.add(name, Converter::type_desc, element);
846 CyclesT *data = reinterpret_cast<CyclesT *>(attr->data_for_write());
847
848 const blender::VArraySpan src = src_varray;
849 for (const int i : src.index_range()) {
850 data[i] = Converter::convert(src[i]);
851 }
852 }
853 });
854 });
855}
856
858 const blender::Span<float> b_radius,
859 const int index)
860{
861 float4 mP = make_float4(
862 b_positions[index][0], b_positions[index][1], b_positions[index][2], 0.0f);
863 mP.w = b_radius.is_empty() ? 0.005f : b_radius[index];
864 return mP;
865}
866
868 const blender::Span<float> b_radius,
869 const int first_point_index,
870 const int num_points,
871 const float step)
872{
873 const float curve_t = step * (num_points - 1);
874 const int point_a = clamp((int)curve_t, 0, num_points - 1);
875 const int point_b = min(point_a + 1, num_points - 1);
876 const float t = curve_t - (float)point_a;
877 return mix(curve_point_as_float4(b_positions, b_radius, first_point_index + point_a),
878 curve_point_as_float4(b_positions, b_radius, first_point_index + point_b),
879 t);
880}
881
882static void export_hair_curves(Scene *scene,
883 Hair *hair,
884 const blender::bke::CurvesGeometry &b_curves,
885 const bool need_motion,
886 const float motion_scale)
887{
888 const blender::Span<blender::float3> positions = b_curves.positions();
889 const blender::OffsetIndices points_by_curve = b_curves.points_by_curve();
890 const blender::bke::AttributeAccessor b_attributes = b_curves.attributes();
891
892 hair->resize_curves(points_by_curve.size(), positions.size());
893
894 /* Sync positions, sharing with Blender when possible. */
896 hair->attributes,
898 b_attributes.lookup<blender::float3>("position", blender::bke::AttrDomain::Point),
899 positions.size());
900 hair->tag_position_modified();
901
902 /* Sync radius, sharing with Blender when possible, or filling default. */
904 hair->attributes,
906 b_attributes.lookup<float>("radius", blender::bke::AttrDomain::Point),
907 positions.size()))
908 {
909 hair->tag_radius_modified();
910 }
911 else {
912 float *curve_radius = hair->get_radius_for_write();
913 std::fill(curve_radius, curve_radius + positions.size(), 0.005f);
914 }
915
916 int *curve_first_key = hair->get_curve_first_key().data();
917 int *curve_shader = hair->get_curve_shader().data();
918
919 /* Add requested attributes. */
920 float *attr_intercept = nullptr;
921 float *attr_length = nullptr;
922
923 if (hair->need_attribute(scene, ATTR_STD_VERTEX_NORMAL)) {
924 /* Get geometry normals. */
925 packed_normal *attr_normal =
927 vector<blender::float3> point_normals(positions.size());
929 b_curves, {point_normals.data(), int64_t(point_normals.size())});
930 for (const int i : positions.index_range()) {
931 attr_normal[i] = packed_normal(
932 make_float3(point_normals[i][0], point_normals[i][1], point_normals[i][2]));
933 }
934 }
935
936 if (hair->need_attribute(scene, ATTR_STD_CURVE_INTERCEPT)) {
937 attr_intercept = hair->attributes.add(ATTR_STD_CURVE_INTERCEPT)->data_for_write<float>();
938 }
939 if (hair->need_attribute(scene, ATTR_STD_CURVE_LENGTH)) {
940 attr_length = hair->attributes.add(ATTR_STD_CURVE_LENGTH)->data_for_write<float>();
941 }
942 if (hair->need_attribute(scene, ATTR_STD_CURVE_RANDOM)) {
943 float *attr_random = hair->attributes.add(ATTR_STD_CURVE_RANDOM)->data_for_write<float>();
944 for (const int i : points_by_curve.index_range()) {
945 attr_random[i] = hash_uint2_to_float(i, 0);
946 }
947 }
948
949 std::copy(points_by_curve.data().data(),
950 points_by_curve.data().data() + points_by_curve.size(),
951 curve_first_key);
952 std::fill(curve_shader, curve_shader + points_by_curve.size(), 0);
953
954 /* Compute per-curve length and per-point intercept along the curve. */
955 if (attr_length || attr_intercept) {
956 for (const int curve : points_by_curve.index_range()) {
957 const blender::IndexRange points = points_by_curve[curve];
958
959 float3 prev_co = zero_float3();
960 float length = 0.0f;
961
962 for (const int point : points) {
963 const float3 co = make_float3(
964 positions[point][0], positions[point][1], positions[point][2]);
965
966 if (point != points.first()) {
967 length += len(co - prev_co);
968 }
969 prev_co = co;
970
971 if (attr_intercept) {
972 attr_intercept[point] = length;
973 }
974 }
975
976 /* Normalized 0..1 attribute along curve. */
977 if (attr_intercept && length > 0.0f) {
978 for (const int point : points.drop_front(1)) {
979 attr_intercept[point] /= length;
980 }
981 }
982
983 /* Curve length. */
984 if (attr_length) {
985 attr_length[curve] = length;
986 }
987 }
988 }
989
990 attr_create_generic(scene, hair, b_curves, need_motion, motion_scale);
991}
992
993static bool hair_topology_matches(const Hair *hair, const blender::bke::CurvesGeometry &b_curves)
994{
995 const blender::OffsetIndices points_by_curve = b_curves.points_by_curve();
996 if (size_t(b_curves.points_num()) != hair->num_keys() ||
997 size_t(points_by_curve.size()) != hair->num_curves())
998 {
999 return false;
1000 }
1001 for (const int i : points_by_curve.index_range()) {
1002 if (points_by_curve[i].size() != hair->get_curve(i).num_keys) {
1003 return false;
1004 }
1005 }
1006 return true;
1007}
1008
1010 const blender::bke::CurvesGeometry &b_curves,
1011 const int motion_step)
1012{
1013 /* Set motion steps on position and radius attributes. */
1014 Attribute *attr_P = hair->attributes.find(ATTR_STD_POSITION);
1015 Attribute *attr_R = hair->attributes.find(ATTR_STD_RADIUS);
1016 bool new_attribute = false;
1017
1018 if (!attr_P->has_motion()) {
1019 attr_P->add_motion(hair);
1020 attr_R->add_motion(hair);
1021 new_attribute = true;
1022 }
1023
1024 const size_t num_keys = hair->num_keys();
1025 const int attr_step = motion_step + 1;
1026 const blender::bke::AttributeAccessor b_attributes = b_curves.attributes();
1027
1028 bool have_motion = false;
1029 int num_motion_keys = 0;
1030
1031 if (hair_topology_matches(hair, b_curves)) {
1032 /* Fast path: topology unchanged, sync the whole step from Blender, sharing
1033 * the buffer when possible. */
1035 *attr_P,
1036 attr_step,
1037 b_attributes.lookup<blender::float3>("position", blender::bke::AttrDomain::Point));
1039 *attr_R,
1040 attr_step,
1041 b_attributes.lookup<float>("radius", blender::bke::AttrDomain::Point)))
1042 {
1043 float *mR = attr_R->data_for_write<float>(attr_step);
1044 std::fill(mR, mR + num_keys, 0.005f);
1045 }
1046
1047 /* If a buffer is shared from Blender and unchanged across frames, the
1048 * pointer matches the center step's, so the memcmp is skipped. */
1049 const packed_float3 *motion_P = attr_P->data<packed_float3>(attr_step);
1050 const packed_float3 *center_P = hair->get_position();
1051 const float *motion_R = attr_R->data<float>(attr_step);
1052 const float *center_R = hair->get_radius();
1053 have_motion = (motion_P != center_P &&
1054 std::memcmp(motion_P, center_P, num_keys * sizeof(packed_float3)) != 0) ||
1055 (motion_R != center_R &&
1056 std::memcmp(motion_R, center_R, num_keys * sizeof(float)) != 0);
1057 num_motion_keys = num_keys;
1058 }
1059 else {
1060 /* Slow path: topology has changed, copy with per-curve interpolation.
1061 * Keys without a matching curve keep the center position. */
1062 hair->copy_center_to_motion_step(motion_step);
1063
1064 const size_t num_curves = hair->num_curves();
1065 packed_float3 *mP = attr_P->data_for_write<packed_float3>(attr_step);
1066 float *mR = attr_R->data_for_write<float>(attr_step);
1067 int curve_index = 0;
1068
1069 const blender::Span<blender::float3> b_positions = b_curves.positions();
1070 const blender::OffsetIndices points_by_curve = b_curves.points_by_curve();
1071 const blender::VArraySpan b_radius = *b_attributes.lookup<float>(
1073
1074 for (const int i : points_by_curve.index_range()) {
1075 const blender::IndexRange points = points_by_curve[i];
1076 if (curve_index >= num_curves) {
1077 break;
1078 }
1079
1080 const Hair::Curve curve = hair->get_curve(curve_index);
1081 curve_index++;
1082
1083 if (points.size() == curve.num_keys) {
1084 /* Number of keys matches. */
1085 for (const int i : points.index_range()) {
1086 const int point = points[i];
1087
1088 if (num_motion_keys < num_keys) {
1089 const float4 cv = curve_point_as_float4(b_positions, b_radius, point);
1090 mP[num_motion_keys] = make_float3(cv);
1091 mR[num_motion_keys] = cv.w;
1092
1093 if (!have_motion) {
1094 float4 curve_key = make_float4(hair->get_position()[num_motion_keys]);
1095 curve_key.w = hair->get_radius()[num_motion_keys];
1096 have_motion = !(cv == curve_key);
1097 }
1098 num_motion_keys++;
1099 }
1100 }
1101 }
1102 else {
1103 /* Number of keys has changed. Generate an interpolated version
1104 * to preserve motion blur. */
1105 const float step_size = curve.num_keys > 1 ? 1.0f / (curve.num_keys - 1) : 0.0f;
1106 for (int i = 0; i < curve.num_keys; i++) {
1107 const float step = i * step_size;
1109 b_positions, b_radius, points.start(), points.size(), step);
1110 mP[num_motion_keys] = make_float3(cv);
1111 mR[num_motion_keys] = cv.w;
1112 num_motion_keys++;
1113 }
1114 have_motion = true;
1115 }
1116 }
1117 }
1118
1119 /* In case of new attribute, verify if there really was any motion. */
1120 if (new_attribute) {
1121 export_hair_motion_validate_attribute(hair, motion_step, num_motion_keys, have_motion);
1122 }
1123}
1124
1125/* Hair object. */
1126void BlenderSync::sync_hair(Hair *hair, BObjectInfo &b_ob_info, bool motion, const int motion_step)
1127{
1128 /* Motion blur attribute is relative to seconds, we need it relative to frames. */
1129 const bool need_motion = object_need_motion_attribute(b_ob_info, scene);
1130 const float motion_scale = (need_motion) ? scene->motion_shutter_time() /
1131 (b_scene->r.frs_sec / b_scene->r.frs_sec_base) :
1132 0.0f;
1133
1134 /* Convert Blender hair to Cycles curves. */
1135 const blender::bke::CurvesGeometry &b_curves(
1136 blender::id_cast<const blender::Curves *>(b_ob_info.object_data)->geometry.wrap());
1137 if (motion) {
1138 export_hair_curves_motion(hair, b_curves, motion_step);
1139 }
1140 else {
1141 export_hair_curves(scene, hair, b_curves, need_motion, motion_scale);
1142 }
1143
1144 const blender::VArray<int8_t> b_types = b_curves.curve_types();
1145 /* This does not handle cases where the curve type is not the same across all curves */
1146 if (!b_types.is_empty() && b_types[0] == blender::CURVE_TYPE_POLY) {
1148 }
1149 else {
1150 hair->curve_shape = scene->params.hair_shape;
1151 }
1152}
1153
1154void BlenderSync::sync_hair(BObjectInfo &b_ob_info, Hair *hair)
1155{
1156 /* make a copy of the shaders as the caller in the main thread still need them for syncing the
1157 * attributes */
1158 array<Node *> used_shaders = hair->get_used_shaders();
1159
1160 Hair new_hair;
1161 new_hair.set_used_shaders(used_shaders);
1162
1163 if (view_layer.use_hair) {
1164 if (b_ob_info.object_data->id_type() == blender::ID_CV) {
1165 /* Hair object. */
1166 sync_hair(&new_hair, b_ob_info, false);
1167 }
1168 else {
1169 /* Particle hair. */
1170 blender::Mesh *b_mesh = object_to_mesh(b_ob_info);
1171
1172 if (b_mesh) {
1173 sync_particle_hair(&new_hair, *b_mesh, b_ob_info, false);
1174 free_object_to_mesh(b_ob_info, *b_mesh);
1175 }
1176 }
1177
1178 if (scene->need_motion() == Scene::MOTION_PASS_INTERACTIVE &&
1179 hair->num_keys() == new_hair.num_keys())
1180 {
1181 new_hair.set_motion_steps(2);
1182
1183 Attribute *attr_P = hair->attributes.find(ATTR_STD_POSITION);
1184 Attribute *new_attr_P = new_hair.attributes.find(ATTR_STD_POSITION);
1185 if (attr_P->has_motion()) {
1186 new_attr_P->take_motion_from(*attr_P);
1187 }
1188 else {
1189 new_attr_P->add_motion(&new_hair);
1190 new_hair.copy_center_to_motion_step(0);
1191 }
1192 }
1193 }
1194
1195 /* update original sockets */
1196
1197 for (const SocketType &socket : new_hair.type->inputs) {
1198 /* Those sockets are updated in sync_object, so do not modify them. */
1199 if (socket.name == "use_motion_blur" || socket.name == "used_shaders") {
1200 continue;
1201 }
1202 hair->set_value(socket, new_hair, socket);
1203 }
1204
1205 hair->attributes.update(std::move(new_hair.attributes));
1206
1207 hair->curve_shape = new_hair.curve_shape;
1208
1209 /* tag update */
1210
1211 /* Compares curve_keys rather than strands in order to handle quick hair
1212 * adjustments in dynamic BVH - other methods could probably do this better. */
1213 const bool rebuild = (hair->position_is_modified() || hair->radius_is_modified());
1214
1215 hair->tag_update(scene, rebuild);
1216}
1217
1218void BlenderSync::sync_hair_motion(BObjectInfo &b_ob_info, Hair *hair, const int motion_step)
1219{
1220 /* Skip if nothing exported. */
1221 if (hair->num_keys() == 0) {
1222 return;
1223 }
1224
1225 /* Export deformed coordinates. */
1226 if (ccl::BKE_object_is_deform_modified(b_ob_info, *b_scene, preview)) {
1227 if (b_ob_info.object_data->id_type() == blender::ID_CV) {
1228 /* Hair object. */
1229 sync_hair(hair, b_ob_info, true, motion_step);
1230 return;
1231 }
1232
1233 /* Particle hair. */
1234 blender::Mesh *b_mesh = object_to_mesh(b_ob_info);
1235 if (b_mesh) {
1236 sync_particle_hair(hair, *b_mesh, b_ob_info, true, motion_step);
1237 free_object_to_mesh(b_ob_info, *b_mesh);
1238 return;
1239 }
1240 }
1241
1242 /* No deformation on this frame, copy coordinates if other frames did have it. */
1243 hair->copy_center_to_motion_step(motion_step);
1244}
1245
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
blender::float3 packed_float3
bool sync_attribute_from_blender(AttributeSet &attributes, const AttributeStandard std, const blender::bke::AttributeReader< BlenderT > &b_reader, const int size)
bool sync_attribute_motion_step_from_blender(Attribute &attr, const int motion_step, const blender::bke::AttributeReader< BlenderT > &b_reader)
static void ExportCurveSegmentsMotion(Hair *hair, ParticleCurveData *CData, const int motion_step)
static void ExportCurveSegments(Scene *scene, Hair *hair, ParticleCurveData *CData)
static void export_hair_curves_motion(Hair *hair, const blender::bke::CurvesGeometry &b_curves, const int motion_step)
static float4 LerpCurveSegmentMotionCV(ParticleCurveData *CData, const int sys, const int curve, const float step)
static AttributeElement blender_domain_to_attr_element(const blender::bke::AttrDomain b_domain)
static void export_hair_curves(Scene *scene, Hair *hair, const blender::bke::CurvesGeometry &b_curves, const bool need_motion, const float motion_scale)
static float4 curve_point_as_float4(const blender::Span< blender::float3 > b_positions, const blender::Span< float > b_radius, const int index)
static float shaperadius(const float shape, const float root, const float tip, const float time)
static float4 CurveSegmentMotionCV(ParticleCurveData *CData, const int sys, const int curve, const int curvekey)
static void attr_create_motion_from_velocity(Hair *hair, const blender::Span< blender::float3 > src, const float motion_scale)
static bool ObtainCacheParticleData(Hair *hair, const blender::Mesh *b_mesh, const blender::Object *b_ob, ParticleCurveData *CData, bool background)
static float4 interpolate_curve_points(const blender::Span< blender::float3 > b_positions, const blender::Span< float > b_radius, const int first_point_index, const int num_points, const float step)
static void export_hair_motion_validate_attribute(Hair *hair, const int motion_step, const int num_motion_keys, bool have_motion)
static bool ObtainCacheParticleUV(Hair *hair, const blender::Mesh *b_mesh, const blender::Object *b_ob, ParticleCurveData *CData, bool background, const int uv_num)
static void attr_create_generic(Scene *scene, Hair *hair, const blender::bke::CurvesGeometry &b_curves, const bool need_motion, const float motion_scale)
static bool hair_topology_matches(const Hair *hair, const blender::bke::CurvesGeometry &b_curves)
static bool ObtainCacheParticleVcol(Hair *hair, const blender::Mesh *b_mesh, const blender::Object *b_ob, ParticleCurveData *CData, bool background, const int vcol_num)
long long int int64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void update(AttributeSet &&new_attributes)
Attribute * find(ustring name) const
Attribute * add(ustring name, const TypeDesc type, AttributeElement element)
void take_motion_from(Attribute &other)
const T * data(const int step=0) const
T * data_for_write(const int step=0)
bool has_motion() const
void add_motion(const Geometry *geom)
void remove_motion()
bool radius_is_modified() const
void tag_position_modified()
const packed_float3 * get_position() const
void tag_update(Scene *scene, bool rebuild)
float * get_radius_for_write()
bool position_is_modified() const
const float * get_radius() const
AttributeSet attributes
bool need_attribute(const Scene *scene, AttributeStandard std)
void tag_radius_modified()
packed_float3 * get_position_for_write()
Definition hair.h:13
Curve get_curve(const size_t i) const
Definition hair.h:94
size_t num_curves() const
Definition hair.h:109
void copy_center_to_motion_step(const int motion_step)
Definition hair.cpp:271
void resize_curves(const int numcurves, const int numkeys)
Definition hair.cpp:248
CurveShapeType curve_shape
Definition hair.h:77
void clear(bool preserve_shaders=false) override
Definition hair.cpp:260
size_t num_keys() const
Definition hair.h:103
array< int > curve_firstkey
array< bool > psys_closetip
array< float > psys_tipradius
array< int > psys_shader
array< float > curve_length
array< float4 > curve_vcol
array< float > curvekey_time
array< float > psys_rootradius
array< int > psys_firstcurve
array< int > psys_curvenum
array< float2 > curve_uv
array< float > psys_shape
array< int > curve_keynum
array< float3 > curvekey_co
Definition scene.h:133
@ MOTION_PASS_INTERACTIVE
Definition scene.h:207
size_t size() const
void reserve(const size_t newcapacity)
void push_back_slow(const T &t)
constexpr int64_t first() const
constexpr int64_t size() const
constexpr int64_t start() const
constexpr IndexRange index_range() const
constexpr IndexRange drop_front(int64_t n) const
constexpr T * end() const
Definition BLI_span.hh:554
constexpr T * begin() const
Definition BLI_span.hh:550
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
IndexRange index_range() const
void append(const T &value)
IndexRange index_range() const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
GAttributeReader lookup(const StringRef name) const
GAttributeReader get() const
AttributeAccessor attributes() const
Span< float3 > positions() const
OffsetIndices< int > points_by_curve() const
Span< NewT > constexpr cast() const
ccl_device float4 color_srgb_to_linear_v4(const float4 c)
Definition color.h:335
#define powf(x, y)
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
float hash_uint2_to_float(uint kx, uint ky)
#define assert(assertion)
#define index(i)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
constexpr T clamp(T, U, U) RET
float length(VecOp< float, D >) RET
VecBase< float, 2 > float2
VecBase< float, 4 > float4
VecBase< float, 3 > float3
float3 transform_point(float3x3 mat, float3 point)
@ CURVE_THICK_LINEAR
AttributeElement
@ ATTR_ELEMENT_NONE
@ ATTR_ELEMENT_CURVE_KEY
@ ATTR_ELEMENT_CURVE
AttributeStandard
@ ATTR_STD_CURVE_INTERCEPT
@ ATTR_STD_UV
@ ATTR_STD_VERTEX_NORMAL
@ ATTR_STD_NONE
@ ATTR_STD_CURVE_RANDOM
@ ATTR_STD_POSITION
@ ATTR_STD_GENERATED
@ ATTR_STD_RADIUS
@ ATTR_STD_CURVE_LENGTH
#define LOG_DEBUG
Definition log.h:107
#define LOG_ERROR
Definition log.h:101
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline dual1 len_squared(const ccl_private dual< T > &a)
Definition math_dual.h:273
CCL_NAMESPACE_BEGIN ccl_device_inline float2 zero_float2()
Definition math_float2.h:13
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
void to_static_type(const CPPType &cpp_type, Fn &&fn)
void curves_normals_point_domain_calc(const CurvesGeometry &curves, MutableSpan< float3 > normals)
int size(const AssetLibraryReference *library_reference)
BMesh Iterators.
@ eModifierType_ParticleSystem
VecBase< float, 2 > float2
@ OB_MODE_PARTICLE_EDIT
VecBase< float, 3 > float3
#define mix
#define floorf
#define make_float4
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
bool is_real_object_data() const
blender::ID * object_data
blender::Object * real_object
int first_key
Definition hair.h:19
int num_keys
Definition hair.h:20
vector< SocketType, std::allocator< SocketType > > inputs
Definition node_type.h:131
const NodeType * type
Definition graph/node.h:179
void set_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
ustring name
Definition node_type.h:84
ListBaseT< ModifierData > modifiers
float x
float x
Definition sky_math.h:136
float x
Definition sky_math.h:225
float w
Definition sky_math.h:225
packed_normal()=default
ccl_device_inline Transform transform_inverse(const Transform tfm)
Definition transform.h:563