Blender V5.3
geometry_fields.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_array_utils.hh"
10#include "BLI_generic_array.hh"
12
13#include "BKE_attribute.hh"
14#include "BKE_curves.hh"
16#include "BKE_geometry_set.hh"
17#include "BKE_grease_pencil.hh"
18#include "BKE_instances.hh"
19#include "BKE_mesh.hh"
20
21#include "DNA_mesh_types.h"
23
24#include "BLT_translation.hh"
25
26#include <fmt/format.h>
27
28namespace blender {
29
30namespace bke {
31
33 : mesh_(mesh), domain_(domain)
34{
35 BLI_assert(mesh.attributes().domain_supported(domain_));
36}
37
39 : curves_(curves), domain_(domain)
40{
41 BLI_assert(curves.attributes().domain_supported(domain));
42}
43
49
51 const IndexMask &mask,
52 ResourceScope &scope) const
53{
54 if (const CurvesFieldInput *curves_field_input = dynamic_cast<const CurvesFieldInput *>(
55 &field_input))
56 {
57 if (const bke::greasepencil::Drawing *drawing = this->grease_pencil().get_eval_drawing(
58 this->grease_pencil().layer(this->layer_index())))
59 {
60 if (drawing->strokes().attributes().domain_supported(this->domain())) {
61 const CurvesFieldContext context{drawing->strokes(), this->domain()};
62 return curves_field_input->get_varray_for_context(context, mask, scope);
63 }
64 }
65 return {};
66 }
67 return field_input.get_varray_for_context(*this, mask, scope);
68}
69
71 const AttrDomain domain)
72 : geometry_(other.geometry_),
73 type_(other.type_),
74 domain_(domain),
75 curves_id_(other.curves_id_),
76 grease_pencil_layer_index_(other.grease_pencil_layer_index_)
77{
78}
79
96
98 const AttrDomain domain)
99 : type_(component.type()), domain_(domain)
100{
101 switch (component.type()) {
102 case GeometryComponent::Type::Mesh: {
103 const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
104 geometry_ = mesh_component.get();
105 break;
106 }
108 const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
109 const Curves *curves = curve_component.get();
110 geometry_ = curves ? &curves->geometry.wrap() : nullptr;
111 curves_id_ = curve_component.get();
112 break;
113 }
115 const PointCloudComponent &pointcloud_component = static_cast<const PointCloudComponent &>(
116 component);
117 geometry_ = pointcloud_component.get();
118 break;
119 }
121 const GreasePencilComponent &grease_pencil_component =
122 static_cast<const GreasePencilComponent &>(component);
123 geometry_ = grease_pencil_component.get();
124 /* Need to use another constructor for other domains. */
125 BLI_assert(domain == AttrDomain::Layer);
126 break;
127 }
129 const InstancesComponent &instances_component = static_cast<const InstancesComponent &>(
130 component);
131 geometry_ = instances_component.get();
132 break;
133 }
137 break;
138 }
139}
140
150 : geometry_(&curves_id.geometry.wrap()),
152 domain_(domain),
153 curves_id_(&curves_id)
154{
155}
157 : geometry_(&points), type_(GeometryComponent::Type::PointCloud), domain_(AttrDomain::Point)
158{
159}
167 const AttrDomain domain,
168 const int layer_index)
169 : geometry_(&grease_pencil),
171 domain_(domain),
172 grease_pencil_layer_index_(layer_index)
173{
174}
181
182std::optional<AttributeAccessor> GeometryFieldContext::attributes() const
183{
184 if (const Mesh *mesh = this->mesh()) {
185 return mesh->attributes();
186 }
187 if (const CurvesGeometry *curves = this->curves()) {
188 return curves->attributes();
189 }
190 if (const PointCloud *pointcloud = this->pointcloud()) {
191 return pointcloud->attributes();
192 }
193 if (const GreasePencil *grease_pencil = this->grease_pencil()) {
194 if (domain_ == AttrDomain::Layer) {
195 return grease_pencil->attributes();
196 }
197 if (const greasepencil::Drawing *drawing = grease_pencil->get_eval_drawing(
198 grease_pencil->layer(grease_pencil_layer_index_)))
199 {
200 return drawing->strokes().attributes();
201 }
202 }
203 if (const Instances *instances = this->instances()) {
204 return instances->attributes();
205 }
206 return {};
207}
208
210{
211 return this->type() == GeometryComponent::Type::Mesh ? static_cast<const Mesh *>(geometry_) :
212 nullptr;
213}
215{
216 return this->type() == GeometryComponent::Type::Curve ?
217 static_cast<const CurvesGeometry *>(geometry_) :
218 nullptr;
219}
221{
222 return this->type() == GeometryComponent::Type::PointCloud ?
223 static_cast<const PointCloud *>(geometry_) :
224 nullptr;
225}
227{
229 static_cast<const GreasePencil *>(geometry_) :
230 nullptr;
231}
233{
236 {
237 return nullptr;
238 }
239 return this->grease_pencil()->get_eval_drawing(
240 this->grease_pencil()->layer(this->grease_pencil_layer_index_));
241}
243{
244 if (const CurvesGeometry *curves = this->curves()) {
245 return curves;
246 }
247 if (const greasepencil::Drawing *drawing = this->grease_pencil_layer_drawing()) {
248 return &drawing->strokes();
249 }
250 return nullptr;
251}
253{
254 return curves_id_;
255}
257{
258 return this->type() == GeometryComponent::Type::Instance ?
259 static_cast<const Instances *>(geometry_) :
260 nullptr;
261}
262
263static std::optional<GeometryFieldContext> try_get_geometry_field_context(
264 const fn::FieldContext &context)
265{
266 if (const GeometryFieldContext *geometry_context = dynamic_cast<const GeometryFieldContext *>(
267 &context))
268 {
269 return *geometry_context;
270 }
271 if (const MeshFieldContext *mesh_context = dynamic_cast<const MeshFieldContext *>(&context)) {
272 return GeometryFieldContext(mesh_context->mesh(), mesh_context->domain());
273 }
274 if (const CurvesFieldContext *curve_context = dynamic_cast<const CurvesFieldContext *>(&context))
275 {
276 if (const Curves *curves_id = curve_context->curves_id()) {
277 return GeometryFieldContext(*curves_id, curve_context->domain());
278 }
279 return GeometryFieldContext(curve_context->curves(), curve_context->domain());
280 }
281 if (const PointCloudFieldContext *point_context = dynamic_cast<const PointCloudFieldContext *>(
282 &context))
283 {
284 return GeometryFieldContext(point_context->pointcloud());
285 }
286 if (const GreasePencilFieldContext *grease_pencil_context =
287 dynamic_cast<const GreasePencilFieldContext *>(&context))
288 {
289 return GeometryFieldContext(grease_pencil_context->grease_pencil());
290 }
291 if (const GreasePencilLayerFieldContext *grease_pencil_context =
292 dynamic_cast<const GreasePencilLayerFieldContext *>(&context))
293 {
294 return GeometryFieldContext(grease_pencil_context->grease_pencil(),
295 grease_pencil_context->domain(),
296 grease_pencil_context->layer_index());
297 }
298 if (const InstancesFieldContext *instances_context = dynamic_cast<const InstancesFieldContext *>(
299 &context))
300 {
301 return GeometryFieldContext(instances_context->instances());
302 }
303 return std::nullopt;
304}
305
307 const IndexMask &mask,
308 ResourceScope & /*scope*/) const
309{
310 if (const std::optional<GeometryFieldContext> geometry_context = try_get_geometry_field_context(
311 context))
312 {
313 return this->get_varray_for_context(*geometry_context, mask);
314 }
315 return {};
316}
317
318std::optional<AttrDomain> GeometryFieldInput::preferred_domain(
319 const GeometryComponent & /*component*/) const
320{
321 return std::nullopt;
322}
323
329
331 const IndexMask &mask,
332 ResourceScope & /*scope*/) const
333{
334 if (const GeometryFieldContext *geometry_context = dynamic_cast<const GeometryFieldContext *>(
335 &context))
336 {
337 if (const Mesh *mesh = geometry_context->mesh()) {
338 return this->get_varray_for_context(*mesh, geometry_context->domain(), mask);
339 }
340 }
341 if (const MeshFieldContext *mesh_context = dynamic_cast<const MeshFieldContext *>(&context)) {
342 return this->get_varray_for_context(mesh_context->mesh(), mesh_context->domain(), mask);
343 }
344 return {};
345}
346
347std::optional<AttrDomain> MeshFieldInput::preferred_domain(const Mesh & /*mesh*/) const
348{
349 return std::nullopt;
350}
351
356
358 const IndexMask &mask,
359 ResourceScope & /*scope*/) const
360{
361 if (const GeometryFieldContext *geometry_context = dynamic_cast<const GeometryFieldContext *>(
362 &context))
363 {
364 if (const CurvesGeometry *curves = geometry_context->curves_or_strokes()) {
365 return this->get_varray_for_context(*curves, geometry_context->domain(), mask);
366 }
367 }
368 if (const CurvesFieldContext *curves_context = dynamic_cast<const CurvesFieldContext *>(
369 &context))
370 {
371 return this->get_varray_for_context(curves_context->curves(), curves_context->domain(), mask);
372 }
373 return {};
374}
375
376std::optional<AttrDomain> CurvesFieldInput::preferred_domain(
377 const CurvesGeometry & /*curves*/) const
378{
379 return std::nullopt;
380}
381
383 const IndexMask &mask,
384 ResourceScope & /*scope*/) const
385{
386 if (const GeometryFieldContext *geometry_context = dynamic_cast<const GeometryFieldContext *>(
387 &context))
388 {
389 if (const PointCloud *pointcloud = geometry_context->pointcloud()) {
390 return this->get_varray_for_context(*pointcloud, mask);
391 }
392 }
393 if (const PointCloudFieldContext *point_context = dynamic_cast<const PointCloudFieldContext *>(
394 &context))
395 {
396 return this->get_varray_for_context(point_context->pointcloud(), mask);
397 }
398 return {};
399}
400
402 const IndexMask &mask,
403 ResourceScope & /*scope*/) const
404{
405 if (const GeometryFieldContext *geometry_context = dynamic_cast<const GeometryFieldContext *>(
406 &context))
407 {
408 if (const Instances *instances = geometry_context->instances()) {
409 return this->get_varray_for_context(*instances, mask);
410 }
411 }
412 if (const InstancesFieldContext *instances_context = dynamic_cast<const InstancesFieldContext *>(
413 &context))
414 {
415 return this->get_varray_for_context(instances_context->instances(), mask);
416 }
417 return {};
418}
419
421 const IndexMask & /*mask*/) const
422{
424 const AttrDomain domain = context.domain();
425 if (const GreasePencil *grease_pencil = context.grease_pencil()) {
426 const AttributeAccessor layer_attributes = grease_pencil->attributes();
427 if (domain == AttrDomain::Layer) {
428 return *layer_attributes.lookup(name_, data_type);
429 }
431 const int layer_index = context.grease_pencil_layer_index();
432 const AttributeAccessor curves_attributes = *context.attributes();
433 if (const GAttributeReader reader = curves_attributes.lookup(name_, domain, data_type)) {
434 return *reader;
435 }
436 /* Lookup attribute on the layer domain if it does not exist on points or curves. */
437 if (const GAttributeReader reader = layer_attributes.lookup(name_)) {
438 const CPPType &cpp_type = reader.varray.type();
440 BLI_SCOPED_DEFER([&]() { cpp_type.destruct(value); });
441 reader.varray.get_to_uninitialized(layer_index, value);
442 const int domain_size = curves_attributes.domain_size(domain);
443 return GVArray::from_single(cpp_type, domain_size, value);
444 }
445 }
446 }
447 else if (context.domain() == bke::AttrDomain::Instance && name_ == "position") {
448 /* Special case for "position" which is no longer an attribute on instances. */
449 return bke::instance_position_varray(*context.instances());
450 }
451 else if (auto attributes = context.attributes()) {
452 return *attributes->lookup(name_, domain, data_type);
453 }
454
455 return {};
456}
457
459 const IndexMask & /*mask*/) const
460{
461 const AttrDomain domain = context.domain();
462 if (context.type() == GeometryComponent::Type::GreasePencil) {
463 const AttributeAccessor layer_attributes = context.grease_pencil()->attributes();
464 if (context.domain() == AttrDomain::Layer) {
465 const bool exists = layer_attributes.contains(name_);
466 const int domain_size = layer_attributes.domain_size(AttrDomain::Layer);
467 return VArray<bool>::from_single(exists, domain_size);
468 }
469 const greasepencil::Drawing *drawing = context.grease_pencil_layer_drawing();
470 const AttributeAccessor curve_attributes = drawing->strokes().attributes();
471 const bool exists = layer_attributes.contains(name_) || curve_attributes.contains(name_);
472 const int domain_size = curve_attributes.domain_size(domain);
473 return VArray<bool>::from_single(exists, domain_size);
474 }
475 const bool exists = context.attributes()->contains(name_);
476 const int domain_size = context.attributes()->domain_size(domain);
477 return VArray<bool>::from_single(exists, domain_size);
478}
479
481 fn::FieldHashDeep & /*deep_hash_cache*/) const
482{
483 static constexpr int8_t id = 0;
484 hash.add(&id);
485 hash.data.extend(Span(name_.data(), name_.size()).cast<std::byte>());
486}
487
493
495{
496 if (socket_inspection_name_) {
497 return *socket_inspection_name_;
498 }
499 return fmt::format(fmt::runtime(TIP_("\"{}\" attribute from geometry")), name_);
500}
501
503 fn::FieldHashDeep & /*deep_hash_cache*/) const
504{
505 hash.data.extend(Span(name_.data(), name_.size()).cast<std::byte>());
506 hash.add(type_);
507}
508
510 const GeometryComponent &component) const
511{
512 const std::optional<AttributeAccessor> attributes = component.attributes();
513 if (!attributes.has_value()) {
514 return std::nullopt;
515 }
516 const std::optional<AttributeMetaData> meta_data = attributes->lookup_meta_data(name_);
517 if (!meta_data.has_value()) {
518 return std::nullopt;
519 }
520 return meta_data->domain;
521}
522
524{
525 const std::optional<AttributeAccessor> attributes = component.attributes();
526 if (!attributes.has_value()) {
528 }
529 const std::optional<AttributeMetaData> meta_data = attributes->lookup_meta_data(name_);
530 if (!meta_data.has_value()) {
532 }
533 return NativeFieldDomain(NativeFieldDomain::Domain{meta_data->domain});
534}
535
537{
538 switch (domain) {
541 return "id";
542 default:
543 return "";
544 }
545}
546
548 const IndexMask &mask) const
549{
550
551 const StringRef name = get_random_id_attribute_name(context.domain());
552 if (auto attributes = context.attributes()) {
553 if (GVArray attribute = *attributes->lookup<int>(name, context.domain())) {
554 return attribute;
555 }
556 }
557
558 /* Use the index as the fallback if no random ID attribute exists. */
560}
561
563{
564 return TIP_("ID / Index");
565}
566
568 fn::FieldHashDeep & /*deep_hash_cache*/) const
569{
570 static constexpr int8_t id = 0;
571 hash.add(&id);
572}
573
575{
577 static const fn::Field<int> field_ref = fn::Field<int>::from_non_owning_ref(field);
578 return field_ref;
579}
580
582 const bke::GeometryFieldContext &context, const IndexMask &mask) const
583{
584 using namespace bke::greasepencil;
585 const AttrDomain domain = context.domain();
587 return {};
588 }
589
590 const GreasePencil &grease_pencil = *context.grease_pencil();
591 if (!context.grease_pencil()) {
592 return {};
593 }
594
595 auto layer_is_selected = [selection_name = StringRef(layer_name_),
597 size = mask.min_array_size()](const int layer_i) {
598 if (layer_i < 0 || layer_i >= grease_pencil.layers().size()) {
599 return false;
600 }
601 const Layer &layer = grease_pencil.layer(layer_i);
602 return layer.name() == selection_name;
603 };
604
606 const int layer_i = context.grease_pencil_layer_index();
607 const bool selected = layer_is_selected(layer_i);
608 return VArray<bool>::from_single(selected, mask.min_array_size());
609 }
610
611 return VArray<bool>::from_func(mask.min_array_size(), layer_is_selected);
612}
613
615 fn::FieldHashDeep & /*deep_hash_cache*/) const
616{
617 hash.data.extend(Span(layer_name_.data(), layer_name_.size()).cast<std::byte>());
618 hash.add(type_);
619}
620
622 const bke::GeometryComponent & /*component*/) const
623{
624 return AttrDomain::Layer;
625}
626
628 fn::GField value_field,
629 AttrDomain value_field_domain)
630 : bke::GeometryFieldInput(value_field.cpp_type(), "Evaluate at Index"),
631 index_field_(std::move(index_field)),
632 value_field_(std::move(value_field)),
633 value_field_domain_(value_field_domain)
634{
635}
636
638 const IndexMask &mask) const
639{
640 const std::optional<AttributeAccessor> attributes = context.attributes();
641 if (!attributes) {
642 return {};
643 }
644
645 const bke::GeometryFieldContext value_context{context, value_field_domain_};
646 fn::FieldEvaluator value_evaluator{value_context, attributes->domain_size(value_field_domain_)};
647 value_evaluator.add(value_field_);
648 value_evaluator.evaluate();
649 const GVArray &values = value_evaluator.get_evaluated(0);
650
651 fn::FieldEvaluator index_evaluator{context, &mask};
652 index_evaluator.add(index_field_);
653 index_evaluator.evaluate();
654 const VArraySpan<int> indices = index_evaluator.get_evaluated<int>(0);
655
656 GArray<> dst_array(values.type(), mask.min_array_size());
657 IndexMaskMemory memory;
658 const IndexMask valid_mask = array_utils::indices_in_range(
659 mask, indices, values.index_range(), memory);
660 bke::attribute_math::gather(values, indices, valid_mask, dst_array);
661 dst_array.type().value_initialize_indices(dst_array.data(), valid_mask.complement(mask, memory));
662 return GVArray::from_garray(std::move(dst_array));
663}
664
666 fn::FieldHashDeep &deep_hash_cache) const
667{
668 static constexpr int8_t id = 0;
669 hash.add(&id);
670 hash.add(type_);
671 hash.add(deep_hash_cache.ensure(index_field_));
672 hash.add(deep_hash_cache.ensure(value_field_));
673 hash.add(value_field_domain_);
674}
675
677 const GeometryComponent::Type type,
678 const AttrDomain domain)
679{
680 if (!geometry.has(type)) {
681 return false;
682 }
683 const GeometryComponent &component = *geometry.get_component(type);
684 return component.attribute_domain_size(domain) != 0;
685}
686
688 const AttrDomain domain)
689{
690 /* Choose the other component based on a consistent order, rather than some more complicated
691 * heuristic. This is the same order visible in the spreadsheet and used in the ray-cast node. */
692 static const Array<GeometryComponent::Type> supported_types = {
698 for (const GeometryComponent::Type src_type : supported_types) {
699 if (component_is_available(geometry, src_type, domain)) {
700 return geometry.get_component(src_type);
701 }
702 }
703
704 return nullptr;
705}
706
708 fn::GField src_field,
709 const AttrDomain domain)
710 : src_geometry_(std::move(geometry)), src_field_(std::move(src_field)), domain_(domain)
711{
712 src_geometry_.ensure_owns_direct_data();
713
714 mf::SignatureBuilder builder{"Sample Index", signature_};
715 builder.single_input<int>("Index");
716 builder.single_output("Value", src_field_.cpp_type());
717 this->set_signature(&signature_);
718}
719
721{
722 mutex_.ensure([&]() {
723 const GeometryComponent *component = find_source_component(src_geometry_, domain_);
724 if (component == nullptr) {
725 return;
726 }
727 const int domain_num = component->attribute_domain_size(domain_);
728 geometry_context_.emplace(GeometryFieldContext(*component, domain_));
729 evaluator_ = std::make_unique<fn::FieldEvaluator>(*geometry_context_, domain_num);
730 evaluator_->add(src_field_);
731 evaluator_->evaluate();
732 src_data_ = &evaluator_->get_evaluated(0);
733 });
734}
735
737 mf::Params params,
738 mf::Context /*context*/) const
739{
740 const VArraySpan<int> indices = params.readonly_single_input<int>(0, "Index");
741 GMutableSpan dst = params.uninitialized_single_output(1, "Value");
742
743 const CPPType &type = dst.type();
744 if (src_data_ == nullptr) {
745 type.value_initialize_indices(dst.data(), mask);
746 return;
747 }
748
749 IndexMaskMemory memory;
750 const IndexMask valid_mask = array_utils::indices_in_range(
751 mask, indices, src_data_->index_range(), memory);
752 bke::attribute_math::gather(*src_data_, indices, valid_mask, dst);
753 dst.type().value_initialize_indices(dst.data(), valid_mask.complement(mask, memory));
754}
755
757{
758 static constexpr int8_t id = 0;
759 hash.add(&id);
760 hash.add(find_source_component(src_geometry_, domain_));
761 hash.add(domain_);
762 fn::FieldHashDeep field_hash;
763 hash.add(field_hash.ensure(src_field_));
764}
765
767 : bke::GeometryFieldInput(field.cpp_type(), "Evaluate on Domain"),
768 src_field_(std::move(field)),
769 src_domain_(domain)
770{
771}
772
774 const IndexMask & /*mask*/) const
775{
776 const AttrDomain dst_domain = context.domain();
777 const int dst_domain_size = context.attributes()->domain_size(dst_domain);
778 const CPPType &cpp_type = src_field_.cpp_type();
779
780 if (context.type() == GeometryComponent::Type::GreasePencil &&
781 (src_domain_ == AttrDomain::Layer) != (dst_domain == AttrDomain::Layer))
782 {
783 /* Evaluate field just for the current layer. */
784 if (src_domain_ == AttrDomain::Layer) {
785 const bke::GeometryFieldContext src_domain_context{context, AttrDomain::Layer};
786 const int layer_index = context.grease_pencil_layer_index();
787
788 const IndexMask single_layer_mask = IndexRange(layer_index, 1);
789 fn::FieldEvaluator value_evaluator{src_domain_context, &single_layer_mask};
790 value_evaluator.add(src_field_);
791 value_evaluator.evaluate();
792
793 const GVArray &values = value_evaluator.get_evaluated(0);
794
796 BLI_SCOPED_DEFER([&]() { cpp_type.destruct(value); });
797 values.get_to_uninitialized(layer_index, value);
798 return GVArray::from_single(cpp_type, dst_domain_size, value);
799 }
800 /* We don't adapt from curve to layer domain currently. */
801 return GVArray::from_single_default(cpp_type, dst_domain_size);
802 }
803
804 const bke::AttributeAccessor attributes = *context.attributes();
805
806 const bke::GeometryFieldContext other_domain_context{context, src_domain_};
807 const int64_t src_domain_size = attributes.domain_size(src_domain_);
808 GArray<> values(cpp_type, src_domain_size);
809 fn::FieldEvaluator value_evaluator{other_domain_context, src_domain_size};
810 value_evaluator.add_with_destination(src_field_, values.as_mutable_span());
811 value_evaluator.evaluate();
812 return attributes.adapt_domain(GVArray::from_garray(std::move(values)), src_domain_, dst_domain);
813}
814
816 fn::FieldHashDeep &deep_hash_cache) const
817{
818 static constexpr int8_t id = 0;
819 hash.add(&id);
820 hash.add(deep_hash_cache.ensure(src_field_));
821 hash.add(src_domain_);
822}
823
825{
826 fn(src_field_);
827}
828
830 const GeometryComponent & /*component*/) const
831{
832 return src_domain_;
833}
834
836 const GeometryComponent & /*component*/) const
837{
838 return bke::NativeFieldDomain::Domain{src_domain_};
839}
840
841} // namespace bke
842
843/* -------------------------------------------------------------------- */
846
847namespace bke {
848
850 const IndexMask &mask) const
851{
852 if (const Mesh *mesh = context.mesh()) {
853 return mesh_normals_varray(
854 *mesh, mask, context.domain(), legacy_corner_normals_, true_normals_);
855 }
856 if (const CurvesGeometry *curves = context.curves_or_strokes()) {
857 return curve_normals_varray(*curves, context.domain());
858 }
859 return {};
860}
861
863{
864 return true_normals_ ? TIP_("True Normal") : TIP_("Normal");
865}
866
868 fn::FieldHashDeep & /*deep_hash_cache*/) const
869{
870 static constexpr int8_t id = 0;
871 hash.add(&id);
872 hash.add(legacy_corner_normals_);
873 hash.add(true_normals_);
874}
875
877{
878 switch (component.type()) {
880 if (const Mesh *mesh = static_cast<const MeshComponent &>(component).get()) {
881 switch (mesh->normals_domain()) {
888 }
889 }
890 break;
891 }
894 default:
896 }
898}
899
901{
903 static const fn::Field<float3> field_ref = fn::Field<float3>::from_non_owning_ref(field);
904 return field_ref;
905}
906
907static std::optional<StringRefNull> try_get_field_direct_attribute_id(const fn::GField &any_field)
908{
909 if (const auto *attribute_input = any_field.get_input_if<AttributeFieldInput>()) {
910 return attribute_input->attribute_name();
911 }
912 return {};
913}
914
915static bool attribute_kind_matches(const AttributeMetaData meta_data,
916 const AttrDomain domain,
917 const bke::AttrType data_type)
918{
919 return meta_data.domain == domain && meta_data.data_type == data_type;
920}
921
927 const StringRef id_to_create,
928 const AttrDomain domain,
929 const fn::GField &field)
930{
931 const std::optional<StringRef> field_id = try_get_field_direct_attribute_id(field);
932 if (!field_id) {
933 return false;
934 }
935 const std::optional<AttributeMetaData> meta_data = attributes.lookup_meta_data(*field_id);
936 if (!meta_data) {
937 return false;
938 }
939 const bke::AttrType data_type = bke::cpp_type_to_attribute_type(field.cpp_type());
940 if (!attribute_kind_matches(*meta_data, domain, data_type)) {
941 /* Avoid costly domain and type interpolation, which would make sharing impossible. */
942 return false;
943 }
944 const GAttributeReader attribute = attributes.lookup(*field_id, domain, data_type);
945 if (!attribute.sharing_info || !attribute.varray.is_span()) {
946 return false;
947 }
948 const AttributeInitShared init(attribute.varray.get_internal_span().data(),
949 *attribute.sharing_info);
950 return attributes.add_override(id_to_create, domain, data_type, init);
951}
952
954 const CommonVArrayInfo &varray_info)
955{
956 if (varray_info.type != CommonVArrayInfo::Type::Span) {
957 return false;
958 }
959 const CommonVArrayInfo attribute_info = attribute.varray.common_info();
960 if (attribute_info.type != CommonVArrayInfo::Type::Span) {
961 return false;
962 }
963 return varray_info.data == attribute_info.data;
964}
965
967 const StringRef name,
968 const GPointer value)
969{
970 return attributes.assign_data(name, AttributeInitValue(value));
971}
972
974 const AttrDomain domain,
975 const int domain_size,
976 const StringRef name,
977 const CPPType &type,
978 const bke::AttrType data_type,
979 void *buffer)
980{
981 /* NOTE: It's unnecessary to fill the values for elements that will be selected and also set
982 * during field evaluation. A future optimization could evaluate the selection separately and use
983 * its inverse here. */
984
985 if (attributes.is_builtin(name)) {
986 if (const GPointer value = attributes.get_builtin_default(name)) {
987 type.fill_construct_n(value.get(), buffer, domain_size);
988 return;
989 }
990 }
991 if (const GAttributeReader old_attribute = attributes.lookup(name, domain, data_type)) {
992 old_attribute.varray.materialize(buffer);
993 return;
994 }
995 type.fill_construct_n(type.default_value(), buffer, domain_size);
996}
997
999 const fn::FieldContext &field_context,
1000 const Span<StringRef> names,
1001 const AttrDomain domain,
1002 const fn::Field<bool> &selection,
1003 const Span<fn::GField> fields)
1004{
1005 BLI_assert(names.size() == fields.size());
1006 const int domain_size = attributes.domain_size(domain);
1007 if (domain_size == 0) {
1008 bool all_added = true;
1009 for (const int i : names.index_range()) {
1010 const bke::AttrType data_type = bke::cpp_type_to_attribute_type(fields[i].cpp_type());
1011 all_added &= attributes.add(names[i], domain, data_type, AttributeInitConstruct{});
1012 }
1013 return all_added;
1014 }
1015
1016 fn::FieldEvaluator evaluator{field_context, domain_size};
1017 evaluator.set_selection(selection);
1018
1019 const bool selection_is_full = !selection.depends_on_input() &&
1020 fn::evaluate_constant_field(selection);
1021
1022 struct StoreResult {
1023 int input_index;
1024 int evaluator_index;
1025 };
1026 Vector<StoreResult> results_to_store;
1027
1028 ResourceScope scope;
1029
1030 struct AddResult {
1031 int input_index;
1032 struct Single {
1033 void *value;
1034 };
1035 struct Array {
1037 };
1038 std::variant<Single, Array> new_data;
1039 };
1040 Vector<AddResult> results_to_add;
1041
1042 bool success = true;
1043
1044 for (const int input_index : names.index_range()) {
1045 const StringRef name = names[input_index];
1046 const CPPType &type = fields[input_index].cpp_type();
1047 const bke::AttrType data_type = bke::cpp_type_to_attribute_type(type);
1048
1049 /* Avoid adding or writing to builtin attributes with an incorrect type or domain. */
1050 if (const std::optional<AttributeDomainAndType> meta_data =
1051 attributes.get_builtin_domain_and_type(name))
1052 {
1053 if (*meta_data != AttributeDomainAndType{domain, data_type}) {
1054 success = false;
1055 continue;
1056 }
1057 }
1058
1059 const AttributeValidator validator = attributes.lookup_validator(name);
1060 const fn::GField field = validator.validate_field_if_necessary(fields[input_index]);
1061
1062 if (!validator && selection_is_full) {
1063 if (try_add_shared_field_attribute(attributes, name, domain, field)) {
1064 continue;
1065 }
1066 }
1067
1068 /* We are writing to an attribute that exists already with the correct domain and type. */
1069 if (const GAttributeReader dst = attributes.lookup(name)) {
1070 if (dst.domain == domain && dst.varray.type() == field.cpp_type()) {
1071 const int evaluator_index = evaluator.add(field);
1072 results_to_store.append({input_index, evaluator_index});
1073 continue;
1074 }
1075 }
1076
1077 if (field.depends_on_input() || !selection_is_full) {
1078 /* Could avoid allocating a new buffer if:
1079 * - The field does not depend on that attribute (we can't easily check for that yet). */
1080 auto *data = new ImplicitSharedValue<GArray<>>(type, domain_size, NoInitialization());
1081 void *buffer = data->data.data();
1082 if (!selection_is_full) {
1083 initialize_new_data(attributes, domain, domain_size, name, type, data_type, buffer);
1084 }
1085
1086 GMutableSpan dst(type, buffer, domain_size);
1087 evaluator.add_with_destination(field, dst);
1088 results_to_add.append({input_index, AddResult::Array{ImplicitSharingPtr(data)}});
1089 }
1090 else {
1091 void *value = scope.allocate_owned(field.cpp_type());
1092 fn::evaluate_constant_field(field, value);
1093 results_to_add.append({input_index, AddResult::Single{value}});
1094 }
1095 }
1096
1097 evaluator.evaluate();
1098 const IndexMask &mask = evaluator.get_evaluated_selection_as_mask();
1099
1100 for (const StoreResult &result : results_to_store) {
1101 const StringRef name = names[result.input_index];
1102 const GVArray &result_data = evaluator.get_evaluated(result.evaluator_index);
1103 const CommonVArrayInfo info = result_data.common_info();
1104 if (selection_is_full) {
1106 if (try_assign_single_value(attributes, name, GPointer(result_data.type(), info.data))) {
1107 continue;
1108 }
1109 }
1110 }
1111 const GAttributeReader dst = attributes.lookup(name);
1112 if (!attribute_data_matches_varray(dst, info)) {
1113 GSpanAttributeWriter dst_mut = attributes.lookup_for_write_span(name);
1114 array_utils::copy(result_data, mask, dst_mut.span);
1115 dst_mut.finish();
1116 }
1117 }
1118
1119 for (AddResult &result : results_to_add) {
1120 const StringRef name = names[result.input_index];
1121 attributes.remove(name);
1122 const CPPType &type = fields[result.input_index].cpp_type();
1123 const bke::AttrType data_type = bke::cpp_type_to_attribute_type(type);
1124 if (auto *array = std::get_if<AddResult::Array>(&result.new_data)) {
1126 if (!attributes.add(name, domain, data_type, AttributeInitShared(data.data.data(), data))) {
1127 /* If the name corresponds to a builtin attribute, removing the attribute might fail if
1128 * it's required, adding the attribute might fail if the domain or type is incorrect. */
1129 success = false;
1130 }
1131 }
1132 else {
1133 const auto value = std::get<AddResult::Single>(result.new_data);
1134 const AttributeInitValue init(GPointer(type, value.value));
1135 if (!attributes.add(name, domain, data_type, init)) {
1136 success = false;
1137 }
1138 }
1139 }
1140
1141 return success;
1142}
1143
1145 const Span<StringRef> names,
1146 const AttrDomain domain,
1147 const fn::Field<bool> &selection,
1148 const Span<fn::GField> fields)
1149{
1150 const GeometryComponent::Type component_type = component.type();
1151 if (component_type == GeometryComponent::Type::GreasePencil &&
1153 {
1154 /* Capture the field on every layer individually. */
1155 auto &grease_pencil_component = static_cast<GreasePencilComponent &>(component);
1156 GreasePencil *grease_pencil = grease_pencil_component.get_for_write();
1157 if (grease_pencil == nullptr) {
1158 return false;
1159 }
1160 bool any_success = false;
1161 threading::parallel_for(grease_pencil->layers().index_range(), 8, [&](const IndexRange range) {
1162 for (const int layer_index : range) {
1163 if (greasepencil::Drawing *drawing = grease_pencil->get_eval_drawing(
1164 grease_pencil->layer(layer_index)))
1165 {
1166 const GeometryFieldContext field_context{*grease_pencil, domain, layer_index};
1167 const bool success = try_capture_fields_on_geometry(
1168 drawing->strokes_for_write().attributes_for_write(),
1169 field_context,
1170 names,
1171 domain,
1172 selection,
1173 fields);
1174 if (success & !any_success) {
1175 any_success = true;
1176 }
1177 }
1178 }
1179 });
1180 return any_success;
1181 }
1182 if (component_type == GeometryComponent::Type::GreasePencil && domain != AttrDomain::Layer) {
1183 /* The remaining code only handles the layer domain for grease pencil geometries. */
1184 return false;
1185 }
1186
1187 MutableAttributeAccessor attributes = *component.attributes_for_write();
1188 const GeometryFieldContext field_context{component, domain};
1190 attributes, field_context, names, domain, selection, fields);
1191}
1192
1194 const Span<StringRef> names,
1195 const AttrDomain domain,
1196 const Span<fn::GField> fields)
1197{
1198 const fn::Field<bool> selection = fn::Field<bool>(true);
1199 return try_capture_fields_on_geometry(component, names, domain, selection, fields);
1200}
1201
1202std::optional<AttrDomain> try_detect_native_field_domain(const GeometryComponent &component,
1203 const fn::GField &field)
1204{
1205 const fn::FieldInputsPtr &field_inputs = field.field_inputs();
1206 if (!field_inputs) {
1207 return std::nullopt;
1208 }
1210 for (const fn::FieldInput &field_input : field_inputs->inputs) {
1211 if (const auto *input = dynamic_cast<const GeometryFieldInput *>(&field_input)) {
1212 const NativeFieldDomain domain_info = input->native_domain_info(component);
1213 if (std::holds_alternative<NativeFieldDomain::None>(domain_info.variant)) {
1214 return std::nullopt;
1215 }
1216 if (const auto *value = std::get_if<NativeFieldDomain::Domain>(&domain_info.variant)) {
1217 domains.add(value->domain);
1218 }
1219 }
1220 if (component.type() == GeometryComponent::Type::Mesh) {
1221 if (const Mesh *mesh = static_cast<const MeshComponent &>(component).get()) {
1222 if (const auto *input = dynamic_cast<const MeshFieldInput *>(&field_input)) {
1223 const NativeFieldDomain domain_info = input->native_domain_info(*mesh);
1224 if (std::holds_alternative<NativeFieldDomain::None>(domain_info.variant)) {
1225 return std::nullopt;
1226 }
1227 if (const auto *value = std::get_if<NativeFieldDomain::Domain>(&domain_info.variant)) {
1228 domains.add(value->domain);
1229 }
1230 }
1231 }
1232 }
1233 return std::nullopt;
1234 }
1235 if (domains.size() != 1) {
1236 /* Any combination of domains means there is no particular native domain. */
1237 return std::nullopt;
1238 }
1239 return domains[0];
1240}
1241
1242std::optional<AttrDomain> try_detect_field_domain(const GeometryComponent &component,
1243 const fn::GField &field)
1244{
1245 const GeometryComponent::Type component_type = component.type();
1246 if (component_type == GeometryComponent::Type::PointCloud) {
1247 return AttrDomain::Point;
1248 }
1249 if (component_type == GeometryComponent::Type::GreasePencil) {
1250 return AttrDomain::Layer;
1251 }
1252 if (component_type == GeometryComponent::Type::Instance) {
1253 return AttrDomain::Instance;
1254 }
1255 const fn::FieldInputsPtr &field_inputs = field.field_inputs();
1256 if (!field_inputs) {
1257 return std::nullopt;
1258 }
1259 std::optional<AttrDomain> output_domain;
1260 auto handle_domain = [&](const std::optional<AttrDomain> domain) {
1261 if (!domain.has_value()) {
1262 return false;
1263 }
1264 if (output_domain.has_value()) {
1265 if (*output_domain != *domain) {
1266 return false;
1267 }
1268 return true;
1269 }
1270 output_domain = domain;
1271 return true;
1272 };
1273 if (component_type == GeometryComponent::Type::Mesh) {
1274 const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
1275 const Mesh *mesh = mesh_component.get();
1276 if (mesh == nullptr) {
1277 return std::nullopt;
1278 }
1279 for (const fn::FieldInput &field_input : field_inputs->inputs) {
1280 if (const auto *geometry_field_input = dynamic_cast<const GeometryFieldInput *>(
1281 &field_input))
1282 {
1283 if (!handle_domain(geometry_field_input->preferred_domain(component))) {
1284 return std::nullopt;
1285 }
1286 }
1287 else if (const auto *mesh_field_input = dynamic_cast<const MeshFieldInput *>(&field_input)) {
1288 if (!handle_domain(mesh_field_input->preferred_domain(*mesh))) {
1289 return std::nullopt;
1290 }
1291 }
1292 else {
1293 return std::nullopt;
1294 }
1295 }
1296 }
1297 if (component_type == GeometryComponent::Type::Curve) {
1298 const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
1299 const Curves *curves = curve_component.get();
1300 if (curves == nullptr) {
1301 return std::nullopt;
1302 }
1303 for (const fn::FieldInput &field_input : field_inputs->inputs) {
1304 if (const auto *geometry_field_input = dynamic_cast<const GeometryFieldInput *>(
1305 &field_input))
1306 {
1307 if (!handle_domain(geometry_field_input->preferred_domain(component))) {
1308 return std::nullopt;
1309 }
1310 }
1311 else if (const auto *curves_field_input = dynamic_cast<const CurvesFieldInput *>(
1312 &field_input))
1313 {
1314 if (!handle_domain(curves_field_input->preferred_domain(curves->geometry.wrap()))) {
1315 return std::nullopt;
1316 }
1317 }
1318 else {
1319 return std::nullopt;
1320 }
1321 }
1322 }
1323 return output_domain;
1324}
1325
1326} // namespace bke
1327
1329
1330} // namespace blender
Low-level operations for curves.
Low-level operations for grease pencil.
#define BUFFER_FOR_CPP_TYPE_VALUE(type, variable_name)
#define BLI_SCOPED_DEFER(function_to_defer)
#define TIP_(msgid)
#define BLI_assert_unreachable()
#define ELEM(...)
void value_initialize_indices(void *ptr, const IndexMask &mask) const
void fill_construct_n(const void *value, void *dst, int64_t n) const
void destruct(void *ptr) const
const void * default_value() const
GMutableSpan as_mutable_span()
GPointer()=default
CommonVArrayInfo common_info() const
void get_to_uninitialized(int64_t index, void *r_value) const
static GVArray from_single_default(const CPPType &type, int64_t size)
static GVArray from_garray(GArray<> array)
static GVArray from_single(const CPPType &type, int64_t size, const void *value)
constexpr IndexRange()=default
void * allocate_owned(const CPPType &type)
constexpr Span()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr StringRef()
static VArray from_single(T value, const int64_t size)
static VArray from_func(const int64_t size, GetFunc get_func)
bool add(const Key &key)
int64_t size() const
void append(const T &value)
AttributeValidator lookup_validator(const StringRef name) const
std::optional< AttributeDomainAndType > get_builtin_domain_and_type(const StringRef name) const
bool contains(StringRef name) const
GVArray adapt_domain(const GVArray &varray, const AttrDomain from_domain, const AttrDomain to_domain) const
std::optional< AttributeMetaData > lookup_meta_data(StringRef name) const
GAttributeReader lookup(const StringRef name) const
int domain_size(const AttrDomain domain) const
GPointer get_builtin_default(const StringRef name) const
bool is_builtin(const StringRef name) const
GVArray get_varray_for_context(const bke::GeometryFieldContext &context, const IndexMask &mask) const final
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const override
NativeFieldDomain native_domain_info(const GeometryComponent &component) const override
NativeFieldDomain native_domain_info(const GeometryComponent &component) const override
GVArray get_varray_for_context(const GeometryFieldContext &context, const IndexMask &mask) const override
std::string socket_inspection_name() const override
std::optional< AttrDomain > preferred_domain(const GeometryComponent &component) const override
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const override
CurvesFieldContext(const CurvesGeometry &curves, AttrDomain domain)
GVArray get_varray_for_context(const fn::FieldContext &context, const IndexMask &mask, ResourceScope &scope) const override
virtual std::optional< AttrDomain > preferred_domain(const CurvesGeometry &curves) const
AttributeAccessor attributes() const
GVArray get_varray_for_context(const bke::GeometryFieldContext &context, const IndexMask &mask) const final
EvaluateAtIndexInput(fn::Field< int > index_field, fn::GField value_field, AttrDomain value_field_domain)
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const override
std::optional< AttrDomain > preferred_domain(const GeometryComponent &) const override
NativeFieldDomain native_domain_info(const GeometryComponent &) const override
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const override
EvaluateOnDomainInput(fn::GField field, AttrDomain domain)
GVArray get_varray_for_context(const bke::GeometryFieldContext &context, const IndexMask &) const final
void foreach_recursive_field(FunctionRef< void(const fn::GField &)> fn) const override
int attribute_domain_size(AttrDomain domain) const
virtual std::optional< AttributeAccessor > attributes() const
const CurvesGeometry * curves() const
std::optional< AttributeAccessor > attributes() const
const Instances * instances() const
const PointCloud * pointcloud() const
GeometryFieldContext(const GeometryFieldContext &other, AttrDomain domain)
const greasepencil::Drawing * grease_pencil_layer_drawing() const
const GreasePencil * grease_pencil() const
const CurvesGeometry * curves_or_strokes() const
GeometryComponent::Type type() const
GVArray get_varray_for_context(const fn::FieldContext &context, const IndexMask &mask, ResourceScope &scope) const override
virtual std::optional< AttrDomain > preferred_domain(const GeometryComponent &component) const
virtual NativeFieldDomain native_domain_info(const GeometryComponent &component) const
GVArray get_varray_for_input(const fn::FieldInput &field_input, const IndexMask &mask, ResourceScope &scope) const override
static const fn::Field< int > & get_field()
GVArray get_varray_for_context(const GeometryFieldContext &context, const IndexMask &mask) const override
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const override
std::string socket_inspection_name() const override
GVArray get_varray_for_context(const fn::FieldContext &context, const IndexMask &mask, ResourceScope &scope) const override
bke::AttributeAccessor attributes() const
Definition instances.cc:68
MeshFieldContext(const Mesh &mesh, AttrDomain domain)
virtual std::optional< AttrDomain > preferred_domain(const Mesh &mesh) const
virtual NativeFieldDomain native_domain_info(const Mesh &mesh) const
GVArray get_varray_for_context(const fn::FieldContext &context, const IndexMask &mask, ResourceScope &scope) const override
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
bool assign_data(const StringRef name, const AttributeInit &initializer)
bool add_override(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_for_write_span(StringRef name)
std::optional< AttrDomain > preferred_domain(const GeometryComponent &component) const override
GVArray get_varray_for_context(const bke::GeometryFieldContext &context, const IndexMask &mask) const final
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const override
GVArray get_varray_for_context(const GeometryFieldContext &context, const IndexMask &mask) const override
static const fn::Field< float3 > & get_field()
NativeFieldDomain native_domain_info(const GeometryComponent &component) const override
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const override
std::string socket_inspection_name() const override
GVArray get_varray_for_context(const fn::FieldContext &context, const IndexMask &mask, ResourceScope &scope) const override
SampleIndexFunction(GeometrySet geometry, fn::GField src_field, AttrDomain domain)
static const GeometryComponent * find_source_component(const GeometrySet &geometry, AttrDomain domain)
void prepare_for_execution() const override
void hash_unique(UniqueHashBytes &hash) const override
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
const bke::CurvesGeometry & strokes() const
constexpr IndexRange index_range() const
A running instance of the engine.
void set_selection(Field< bool > selection)
int add(GField field, GVArray *varray_ptr)
IndexMask get_evaluated_selection_as_mask() const
int add_with_destination(GField field, GVMutableArray dst)
const GVArray & get_evaluated(const int field_index) const
uint64_t hash() const
Definition field.cc:185
const CPPType * type_
Definition FN_field.hh:341
const CPPType & cpp_type() const
Definition FN_field.hh:559
virtual GVArray get_varray_for_context(const FieldContext &context, const IndexMask &mask, ResourceScope &scope) const =0
static Field from_non_owning_ref(const Field &field)
Definition FN_field.hh:477
bool depends_on_input() const
Definition FN_field.hh:513
static Field from_input(Args &&...args)
bool depends_on_input() const
Definition FN_field.hh:614
const FieldInputsPtr & field_inputs() const
Definition field.cc:504
const InputT * get_input_if() const
Definition FN_field.hh:623
const CPPType & cpp_type() const
Definition FN_field.hh:518
static GVArray get_index_varray(const IndexMask &mask)
Definition field.cc:536
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
#define attribute(slot)
#define layer
IndexMask indices_in_range(const IndexMask &universe, Span< int > values, IndexRange range, LinearAllocator<> &memory)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
std::optional< AttrDomain > try_detect_native_field_domain(const GeometryComponent &component, const fn::GField &field)
static bool try_assign_single_value(MutableAttributeAccessor &attributes, const StringRef name, const GPointer value)
std::optional< AttrDomain > try_detect_field_domain(const GeometryComponent &component, const fn::GField &field)
bool try_capture_fields_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, Span< StringRef > names, AttrDomain domain, const fn::Field< bool > &selection, Span< fn::GField > fields)
static std::optional< GeometryFieldContext > try_get_geometry_field_context(const fn::FieldContext &context)
VArray< float3 > curve_normals_varray(const CurvesGeometry &curves, AttrDomain domain)
static std::optional< StringRefNull > try_get_field_direct_attribute_id(const fn::GField &any_field)
VArray< float3 > mesh_normals_varray(const Mesh &mesh, const IndexMask &mask, AttrDomain domain, bool no_corner_normals=false, bool true_normals=false)
static bool attribute_data_matches_varray(const GAttributeReader &attribute, const CommonVArrayInfo &varray_info)
VArray< float3 > instance_position_varray(const Instances &instances)
Definition instances.cc:544
static bool try_add_shared_field_attribute(MutableAttributeAccessor attributes, const StringRef id_to_create, const AttrDomain domain, const fn::GField &field)
static void initialize_new_data(MutableAttributeAccessor &attributes, const AttrDomain domain, const int domain_size, const StringRef name, const CPPType &type, const bke::AttrType data_type, void *buffer)
static bool component_is_available(const GeometrySet &geometry, const GeometryComponent::Type type, const AttrDomain domain)
static bool attribute_kind_matches(const AttributeMetaData meta_data, const AttrDomain domain, const bke::AttrType data_type)
static StringRef get_random_id_attribute_name(const AttrDomain domain)
AttrType cpp_type_to_attribute_type(const CPPType &type)
ImplicitSharingPtr< FieldInputs > FieldInputsPtr
Definition FN_field.hh:45
void evaluate_constant_field(const GField &field, void *r_value)
BLI_INLINE Texture * wrap(MTLTexture *texture)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
BMesh const char void * data
signed char int8_t
Definition BKE_text.h:76
#define hash
Definition noise_c.cc:156
fn::GField validate_field_if_necessary(const fn::GField &field) const
std::variant< None, Domain, Constant > variant
UniqueHash ensure(const GFieldRef &field)
Definition field.cc:113