diff options
author | Jacques Lucke <jacques@blender.org> | 2020-11-17 17:08:49 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-11-17 17:08:49 +0300 |
commit | 2eb00bd47906f900fc902d6c22941d6746da9eb6 (patch) | |
tree | 12b78db07e6bc02d57721df05ca550deb8c721cb /source/blender | |
parent | d7552814130bc41ac137dc56bcda1f70ceb6a0b0 (diff) |
cleanup
Diffstat (limited to 'source/blender')
5 files changed, 35 insertions, 14 deletions
diff --git a/source/blender/blenkernel/BKE_attribute_accessor.hh b/source/blender/blenkernel/BKE_attribute_accessor.hh index 94e3c692b0b..3cf2fd4f865 100644 --- a/source/blender/blenkernel/BKE_attribute_accessor.hh +++ b/source/blender/blenkernel/BKE_attribute_accessor.hh @@ -80,6 +80,11 @@ template<typename T> class TypedReadAttribute { BLI_assert(attribute_->cpp_type().is<T>()); } + int64_t size() const + { + return attribute_->size(); + } + T operator[](const int64_t index) const { BLI_assert(index < attribute_->size()); @@ -91,6 +96,7 @@ template<typename T> class TypedReadAttribute { }; using FloatReadAttribute = TypedReadAttribute<float>; +using Float3ReadAttribute = TypedReadAttribute<float3>; ReadAttributePtr mesh_attribute_get_for_read(const MeshComponent &mesh_component, const StringRef attribute_name); @@ -101,8 +107,24 @@ ReadAttributePtr mesh_attribute_adapt_domain(const MeshComponent &mesh_component ReadAttributePtr mesh_attribute_get_for_read(const MeshComponent &mesh_component, const StringRef attribute_name, - const AttributeDomain domain, const CPPType &cpp_type, + const AttributeDomain domain, const void *default_value = nullptr); +template<typename T> +TypedReadAttribute<T> mesh_attribute_get_for_read(const MeshComponent &mesh_component, + const StringRef attribute_name, + const AttributeDomain domain, + const T &default_value) +{ + ReadAttributePtr attribute = mesh_attribute_get_for_read( + mesh_component, + attribute_name, + CPPType::get<T>(), + domain, + static_cast<const void *>(&default_value)); + BLI_assert(attribute); + return attribute; +} + } // namespace blender::bke diff --git a/source/blender/blenkernel/intern/attribute_accessor.cc b/source/blender/blenkernel/intern/attribute_accessor.cc index 803de4c50d6..ee1cf2acf36 100644 --- a/source/blender/blenkernel/intern/attribute_accessor.cc +++ b/source/blender/blenkernel/intern/attribute_accessor.cc @@ -314,8 +314,8 @@ static ReadAttributePtr make_default_attribute(const MeshComponent &mesh_compone ReadAttributePtr mesh_attribute_get_for_read(const MeshComponent &mesh_component, const StringRef attribute_name, - const AttributeDomain domain, const CPPType &cpp_type, + const AttributeDomain domain, const void *default_value) { ReadAttributePtr attribute = mesh_attribute_get_for_read(mesh_component, attribute_name); diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh index ad90df01175..46548bfdc77 100644 --- a/source/blender/nodes/NOD_geometry_exec.hh +++ b/source/blender/nodes/NOD_geometry_exec.hh @@ -26,6 +26,7 @@ namespace blender::nodes { +using bke::Float3ReadAttribute; using bke::FloatReadAttribute; using bke::PersistentDataHandleMap; using bke::PersistentObjectHandle; diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc index 94dcf735957..28105613484 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc @@ -112,12 +112,8 @@ static void geo_point_distribute_exec(GeoNodeExecParams params) const MeshComponent &mesh_component = *geometry_set.get_component_for_read<MeshComponent>(); const Mesh *mesh_in = mesh_component.get_for_read(); - const float default_factor = 1.0f; - FloatReadAttribute density_factors = bke::mesh_attribute_get_for_read(mesh_component, - density_attribute, - ATTR_DOMAIN_VERTEX, - CPPType::get<float>(), - &default_factor); + const FloatReadAttribute density_factors = bke::mesh_attribute_get_for_read<float>( + mesh_component, density_attribute, ATTR_DOMAIN_VERTEX, 1.0f); Vector<float3> points = scatter_points_from_mesh(mesh_in, density, density_factors); diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc index 9c4c3dd99b4..441f76435ec 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc @@ -38,15 +38,17 @@ static void geo_point_instance_exec(GeoNodeExecParams params) { GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); - Vector<float3> positions; + Vector<float3> instance_positions; if (geometry_set.has_pointcloud()) { const PointCloud *pointcloud = geometry_set.get_pointcloud_for_read(); - positions.extend((const float3 *)pointcloud->co, pointcloud->totpoint); + instance_positions.extend((const float3 *)pointcloud->co, pointcloud->totpoint); } if (geometry_set.has_mesh()) { - const Mesh *mesh = geometry_set.get_mesh_for_read(); - for (const int i : IndexRange(mesh->totvert)) { - positions.append(mesh->mvert[i].co); + const MeshComponent &mesh_component = *geometry_set.get_component_for_read<MeshComponent>(); + Float3ReadAttribute positions = bke::mesh_attribute_get_for_read<float3>( + mesh_component, "Position", ATTR_DOMAIN_VERTEX, {0, 0, 0}); + for (const int i : IndexRange(positions.size())) { + instance_positions.append(positions[i]); } } @@ -55,7 +57,7 @@ static void geo_point_instance_exec(GeoNodeExecParams params) Object *object = params.handle_map().lookup(object_handle); InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>(); - instances.replace(std::move(positions), object); + instances.replace(std::move(instance_positions), object); params.set_output("Geometry", std::move(geometry_set)); } |