Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
| Show All 10 Lines | |||||
| * | * | ||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| #include "DNA_collection_types.h" | #include "DNA_collection_types.h" | ||||
| #include "BLI_hash.h" | |||||
| #include "BLI_task.hh" | #include "BLI_task.hh" | ||||
| #include "BKE_attribute_math.hh" | |||||
JacquesLucke: Adding that seems unnecessary. | |||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "node_geometry_util.hh" | #include "node_geometry_util.hh" | ||||
| namespace blender::nodes::node_geo_instance_on_points_cc { | namespace blender::nodes::node_geo_instance_on_points_cc { | ||||
| static void node_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| Show All 18 Lines | b.add_input<decl::Vector>(N_("Scale")) | ||||
| .default_value({1.0f, 1.0f, 1.0f}) | .default_value({1.0f, 1.0f, 1.0f}) | ||||
| .subtype(PROP_XYZ) | .subtype(PROP_XYZ) | ||||
| .supports_field() | .supports_field() | ||||
| .description(N_("Scale of the instances")); | .description(N_("Scale of the instances")); | ||||
| b.add_output<decl::Geometry>(N_("Instances")); | b.add_output<decl::Geometry>(N_("Instances")); | ||||
| } | } | ||||
| template<typename T> | |||||
| static void copy_attribute_to_instances(const VArray<T> &src, | |||||
| const IndexMask mask, | |||||
| MutableSpan<T> dst) | |||||
| { | |||||
| for (const int i : mask.index_range()) { | |||||
| dst[i] = src[mask[i]]; | |||||
| } | |||||
| } | |||||
| static void add_instances_from_component(InstancesComponent &dst_component, | static void add_instances_from_component(InstancesComponent &dst_component, | ||||
| const GeometryComponent &src_component, | const GeometryComponent &src_component, | ||||
| const GeometrySet &instance, | const GeometrySet &instance, | ||||
| const GeoNodeExecParams ¶ms) | const GeoNodeExecParams ¶ms) | ||||
| { | { | ||||
| const AttributeDomain domain = ATTR_DOMAIN_POINT; | const AttributeDomain domain = ATTR_DOMAIN_POINT; | ||||
| const int domain_size = src_component.attribute_domain_size(domain); | const int domain_size = src_component.attribute_domain_size(domain); | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 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; | ||||
| } | } | ||||
| }); | }); | ||||
| VArray<int> ids = src_component | /* Copy dynamic attributes to the instances. */ | ||||
| .attribute_try_get_for_read("id", ATTR_DOMAIN_POINT, CD_PROP_INT32) | src_component.attribute_foreach( | ||||
| .typed<int>(); | [&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) { | ||||
| if (ids) { | if (attribute_id.) | ||||
| VArray_Span<int> ids_span{ids}; | GVArray src = dst_component.attribute_get_for_read( | ||||
| MutableSpan<int> dst_ids = dst_component.instance_ids_ensure(); | attribute_id, domain, meta_data.data_type, nullptr); | ||||
| for (const int64_t i : selection.index_range()) { | OutputAttribute dst = dst_component.attribute_try_get_for_output_only( | ||||
| dst_ids[i] = ids_span[selection[i]]; | attribute_id, ATTR_DOMAIN_INSTANCE, meta_data.data_type); | ||||
| } | attribute_math::convert_to_static_type(meta_data.data_type, [&](auto dummy) { | ||||
| } | using T = decltype(dummy); | ||||
| copy_attribute_to_instances( | |||||
| src.typed<T>(), selection, dst.as_span().typed<T>().slice(start_len, select_len)); | |||||
| }); | |||||
| dst.save(); | |||||
| return true; | |||||
| }); | |||||
| 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 56 Lines • Show Last 20 Lines | |||||
Adding that seems unnecessary.