Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
| Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | static void add_instances_from_component(InstancesComponent &dst_component, | ||||
| const int start_len = dst_component.instances_amount(); | const int start_len = dst_component.instances_amount(); | ||||
| const int select_len = selection.index_range().size(); | const int select_len = selection.index_range().size(); | ||||
| dst_component.resize(start_len + select_len); | dst_component.resize(start_len + select_len); | ||||
| MutableSpan<int> dst_handles = dst_component.instance_reference_handles().slice(start_len, | MutableSpan<int> dst_handles = dst_component.instance_reference_handles().slice(start_len, | ||||
| select_len); | select_len); | ||||
| MutableSpan<float4x4> dst_transforms = dst_component.instance_transforms().slice(start_len, | MutableSpan<float4x4> dst_transforms = dst_component.instance_transforms().slice(start_len, | ||||
| select_len); | select_len); | ||||
| MutableSpan<int> dst_stable_ids = dst_component.instance_ids().slice(start_len, select_len); | |||||
| FieldEvaluator field_evaluator{field_context, domain_size}; | FieldEvaluator field_evaluator{field_context, domain_size}; | ||||
| const VArray<bool> *pick_instance = nullptr; | const VArray<bool> *pick_instance = nullptr; | ||||
| const VArray<int> *indices = nullptr; | const VArray<int> *indices = nullptr; | ||||
| const VArray<float3> *rotations = nullptr; | const VArray<float3> *rotations = nullptr; | ||||
| const VArray<float3> *scales = nullptr; | const VArray<float3> *scales = nullptr; | ||||
| /* The evaluator could use the component's stable IDs as a destination directly, but only the | /* The evaluator could use the component's stable IDs as a destination directly, but only the | ||||
| * selected indices should be copied. */ | * selected indices should be copied. */ | ||||
| GVArray_Typed<int> stable_ids = src_component.attribute_get_for_read("id", ATTR_DOMAIN_POINT, 0); | |||||
| field_evaluator.add(params.get_input<Field<bool>>("Pick Instance"), &pick_instance); | field_evaluator.add(params.get_input<Field<bool>>("Pick Instance"), &pick_instance); | ||||
| field_evaluator.add(params.get_input<Field<int>>("Instance Index"), &indices); | field_evaluator.add(params.get_input<Field<int>>("Instance Index"), &indices); | ||||
| field_evaluator.add(params.get_input<Field<float3>>("Rotation"), &rotations); | field_evaluator.add(params.get_input<Field<float3>>("Rotation"), &rotations); | ||||
| field_evaluator.add(params.get_input<Field<float3>>("Scale"), &scales); | field_evaluator.add(params.get_input<Field<float3>>("Scale"), &scales); | ||||
| field_evaluator.evaluate(); | field_evaluator.evaluate(); | ||||
| GVArray_Typed<float3> positions = src_component.attribute_get_for_read<float3>( | GVArray_Typed<float3> positions = src_component.attribute_get_for_read<float3>( | ||||
| "position", domain, {0, 0, 0}); | "position", domain, {0, 0, 0}); | ||||
| Show All 16 Lines | static void add_instances_from_component(InstancesComponent &dst_component, | ||||
| const int full_instance_handle = dst_component.add_reference(instance); | const int full_instance_handle = dst_component.add_reference(instance); | ||||
| /* Add this reference last, because it is the most likely one to be removed later on. */ | /* Add this reference last, because it is the most likely one to be removed later on. */ | ||||
| const int empty_reference_handle = dst_component.add_reference(InstanceReference()); | const int empty_reference_handle = dst_component.add_reference(InstanceReference()); | ||||
| threading::parallel_for(selection.index_range(), 1024, [&](IndexRange selection_range) { | threading::parallel_for(selection.index_range(), 1024, [&](IndexRange selection_range) { | ||||
| for (const int range_i : selection_range) { | for (const int range_i : selection_range) { | ||||
| const int64_t i = selection[range_i]; | const int64_t i = selection[range_i]; | ||||
| dst_stable_ids[range_i] = (*stable_ids)[i]; | |||||
| /* Compute base transform for every instances. */ | /* Compute base transform for every instances. */ | ||||
| float4x4 &dst_transform = dst_transforms[range_i]; | float4x4 &dst_transform = dst_transforms[range_i]; | ||||
| dst_transform = float4x4::from_loc_eul_scale( | dst_transform = float4x4::from_loc_eul_scale( | ||||
| positions[i], rotations->get(i), scales->get(i)); | positions[i], rotations->get(i), scales->get(i)); | ||||
| /* Reference that will be used by this new instance. */ | /* Reference that will be used by this new instance. */ | ||||
| int dst_handle = empty_reference_handle; | int dst_handle = empty_reference_handle; | ||||
| Show All 21 Lines | for (const int range_i : selection_range) { | ||||
| /* Use entire source geometry as instance. */ | /* Use entire source geometry as instance. */ | ||||
| dst_handle = full_instance_handle; | dst_handle = full_instance_handle; | ||||
| } | } | ||||
| /* Set properties of new instance. */ | /* Set properties of new instance. */ | ||||
| dst_handles[range_i] = dst_handle; | dst_handles[range_i] = dst_handle; | ||||
| } | } | ||||
| }); | }); | ||||
| GVArrayPtr id_attribute = src_component.attribute_try_get_for_read( | |||||
| "id", ATTR_DOMAIN_POINT, CD_PROP_INT32); | |||||
| if (id_attribute) { | |||||
| GVArray_Typed<int> ids{*id_attribute}; | |||||
| VArray_Span<int> ids_span{ids}; | |||||
| MutableSpan<int> dst_ids = dst_component.instance_ids_ensure(); | |||||
| for (const int64_t i : selection.index_range()) { | |||||
| dst_ids[i] = ids_span[selection[i]]; | |||||
| } | |||||
| } | |||||
| if (pick_instance->is_single()) { | if (pick_instance->is_single()) { | ||||
| if (pick_instance->get_internal_single()) { | if (pick_instance->get_internal_single()) { | ||||
| if (instance.has_realized_data()) { | if (instance.has_realized_data()) { | ||||
| params.error_message_add( | params.error_message_add( | ||||
| NodeWarningType::Info, | NodeWarningType::Info, | ||||
| TIP_("Realized geometry is not used when pick instances is true")); | TIP_("Realized geometry is not used when pick instances is true")); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines | |||||