Cleanup: Simplify mesh and point cloud conversion
Since mesh positions are stored as a generic attribute, the attribute doesn't need special handling here.
This commit is contained in:
parent
328772f2d9
commit
9facc5067a
|
@ -212,7 +212,7 @@ void BKE_mesh_to_curve(struct Main *bmain,
|
|||
struct Depsgraph *depsgraph,
|
||||
struct Scene *scene,
|
||||
struct Object *ob);
|
||||
void BKE_pointcloud_from_mesh(struct Mesh *me, struct PointCloud *pointcloud);
|
||||
void BKE_pointcloud_from_mesh(const struct Mesh *me, struct PointCloud *pointcloud);
|
||||
void BKE_mesh_to_pointcloud(struct Main *bmain,
|
||||
struct Depsgraph *depsgraph,
|
||||
struct Scene *scene,
|
||||
|
|
|
@ -627,29 +627,11 @@ void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene * /*scene*/, Obj
|
|||
}
|
||||
}
|
||||
|
||||
void BKE_pointcloud_from_mesh(Mesh *me, PointCloud *pointcloud)
|
||||
void BKE_pointcloud_from_mesh(const Mesh *me, PointCloud *pointcloud)
|
||||
{
|
||||
using namespace blender;
|
||||
|
||||
BLI_assert(me != nullptr);
|
||||
/* The pointcloud should only contain the position attribute, otherwise more attributes would
|
||||
* need to be initialized below. */
|
||||
BLI_assert(pointcloud->attributes().all_ids().size() == 1);
|
||||
CustomData_realloc(&pointcloud->pdata, pointcloud->totpoint, me->totvert);
|
||||
CustomData_free(&pointcloud->pdata, pointcloud->totpoint);
|
||||
pointcloud->totpoint = me->totvert;
|
||||
|
||||
/* Copy over all attributes. */
|
||||
CustomData_merge(&me->vdata, &pointcloud->pdata, CD_MASK_PROP_ALL, CD_DUPLICATE, me->totvert);
|
||||
|
||||
bke::AttributeAccessor mesh_attributes = me->attributes();
|
||||
bke::MutableAttributeAccessor point_attributes = pointcloud->attributes_for_write();
|
||||
|
||||
const VArray<float3> vert_positions = mesh_attributes.lookup_or_default<float3>(
|
||||
"position", ATTR_DOMAIN_POINT, float3(0));
|
||||
bke::SpanAttributeWriter<float3> point_positions =
|
||||
point_attributes.lookup_or_add_for_write_only_span<float3>("position", ATTR_DOMAIN_POINT);
|
||||
vert_positions.materialize(point_positions.span);
|
||||
point_positions.finish();
|
||||
}
|
||||
|
||||
void BKE_mesh_to_pointcloud(Main *bmain, Depsgraph *depsgraph, Scene * /*scene*/, Object *ob)
|
||||
|
@ -675,10 +657,7 @@ void BKE_mesh_to_pointcloud(Main *bmain, Depsgraph *depsgraph, Scene * /*scene*/
|
|||
|
||||
void BKE_mesh_from_pointcloud(const PointCloud *pointcloud, Mesh *me)
|
||||
{
|
||||
BLI_assert(pointcloud != nullptr);
|
||||
|
||||
me->totvert = pointcloud->totpoint;
|
||||
|
||||
CustomData_merge(
|
||||
&pointcloud->pdata, &me->vdata, CD_MASK_PROP_ALL, CD_DUPLICATE, pointcloud->totpoint);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue