Page MenuHome

Pointclouds: mesh <-> pointcloud support in convert operator
ClosedPublic

Authored by Philipp Oeser (lichtwerk) on Apr 9 2020, 11:36 PM.

Details

Summary

Just converts verts to points and vice versa.
Materials and Attribute layers are preserved (so for example if you set
custom radii on the pointcloud, convert to mesh, then convert back to
pointcloud, this will be preserved).

Also not add a Radius layer by default (it is still added and
filled when adding a pointcloud object from the menu), a global Radius
property that will be used if there is no radius attribute can be added
later. A Radius attribute can also be added in the pointcloud data
properties (and filled via python).

This will also add a new utility function that copies materials between
datablocks: BKE_id_materials_copy

ref T75717

Diff Detail

Repository
rB Blender

Event Timeline

Philipp Oeser (lichtwerk) requested review of this revision.Apr 9 2020, 11:36 PM
Philipp Oeser (lichtwerk) created this revision.

Still need to write the TODO task for pointclouds (like T68981: New hair object type for hair), this was just to get going...
Should of course add the usual Curve/Meta/Surf/Text as well.
And then the other way around: points to mesh [I assume this could use the vdb-based particle meshing from D4960 as a guide?]

I think the convert operator should do a basic conversion between points and mesh vertices.

For more advanced things like voxel meshing or evenly distributing points over a mesh, there should be modifiers.

source/blender/editors/object/object_add.c
2338

Add #ifdef WITH_NEW_OBJECT_TYPES around this.

  • add poincloud -> mesh conversion
  • handle materials
  • hide behind WITH_NEW_OBJECT_TYPES
Philipp Oeser (lichtwerk) retitled this revision from Pointclouds: very basic mesh -> pointcloud convert operator to Pointclouds: very basic mesh <-> pointcloud support in convert operator.Apr 17 2020, 12:06 PM
Philipp Oeser (lichtwerk) edited the summary of this revision. (Show Details)
Philipp Oeser (lichtwerk) marked an inline comment as done.
source/blender/blenkernel/intern/mesh_convert.c
909

{ on new line.

920

I would change the code so that no radius attribute is added by default. Then it doesn't need to be filled here.

Later we can add a global radius property that will be used if there is no radius attribute.

  • rebase on master
  • no need to hide behind WITH_NEW_OBJECT_TYPES anymore
  • address review comments (style, also remove adding CD_RADIUS layer by default)
Philipp Oeser (lichtwerk) marked 2 inline comments as done.Wed, Sep 9, 4:20 PM
source/blender/blenkernel/intern/mesh_convert.c
947

Remove this, otherwise we'll likely forget about it.

957–965

All CD_MASK_PROP_ALL properties should be copied over.

And then the Position attribute should be changed to a mesh vertex.

979–985

Copying materials between datablocks should be a utility function, rather than the code being duplicated.

source/blender/blenkernel/intern/object.c
1290–1293

Wrap this in a new function like BKE_pointcloud_add_default(), keep pointcloud specific code as much as possible in pointcloud.c.

address review comments

Philipp Oeser (lichtwerk) marked 4 inline comments as done.Fri, Sep 11, 3:58 PM
Philipp Oeser (lichtwerk) retitled this revision from Pointclouds: very basic mesh <-> pointcloud support in convert operator to Pointclouds: mesh <-> pointcloud support in convert operator.
Philipp Oeser (lichtwerk) edited the summary of this revision. (Show Details)
Brecht Van Lommel (brecht) requested changes to this revision.Tue, Sep 15, 5:42 PM
Brecht Van Lommel (brecht) added inline comments.
source/blender/blenkernel/BKE_pointcloud.h
41

BKE_pointcloud_random does not have to be in the API.

source/blender/blenkernel/intern/mesh_convert.c
915

Update pointers after CustomData_merge.

980

This deletes all float3 layers, not just the position layer.

This revision now requires changes to proceed.Tue, Sep 15, 5:42 PM
  • rebase on master
  • make pointcloud_random non-public
  • update customdata pointers after CustomData_merge
Philipp Oeser (lichtwerk) marked 2 inline comments as done.Wed, Sep 16, 11:55 AM
Philipp Oeser (lichtwerk) added inline comments.
source/blender/blenkernel/intern/mesh_convert.c
980

Other CD_PROP_FLOAT3 survive here, it should only delete the one specified with layer_idx (and that one we get specifically with the POINTCLOUD_ATTR_POSITION name)?

Tested adding a Velocity and a custom Vector layer on a pointcloud, and they survive converting to mesh and back to pointcloud.

One minor comment to address, I think you can fix that and commit directly.

source/blender/blenkernel/intern/mesh_convert.c
980

You're right, I missed the layer_idx.

source/blender/editors/object/object_add.c
2338

This needs #ifdef WITH_PARTICLE_NODES again now.

This revision is now accepted and ready to land.Wed, Sep 16, 3:48 PM
source/blender/editors/object/object_add.c
2338

Looks like this would need the following as well?

1
2
3diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt
4index be6c0658b1f..a1f8061c9f7 100644
5--- a/source/blender/editors/object/CMakeLists.txt
6+++ b/source/blender/editors/object/CMakeLists.txt
7@@ -86,4 +86,9 @@ if(WITH_INTERNATIONAL)
8 add_definitions(-DWITH_INTERNATIONAL)
9 endif()
10
11+if(WITH_EXPERIMENTAL_FEATURES)
12+ add_definitions(-DWITH_PARTICLE_NODES)
13+ add_definitions(-DWITH_HAIR_NODES)
14+endif()
15+
16 blender_add_lib(bf_editor_object "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")

Should I also check U.experimental.use_new_particle_system?

source/blender/editors/object/object_add.c
2338

Correct.

I don't think it's worth checking U.experimental.use_new_particle_system, strictly speaking we should, but the code would be non-trivial and this code won't be compiled in official releases anyway.