Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Oeser <info@graphics-engineer.com>2020-04-09 19:49:40 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2020-09-17 23:39:57 +0300
commit39de0b79fd635ed67e8b1816c32199177d7f9f07 (patch)
treeb2838abd1c39d3c17e08438740c40c95c33a94f1 /source/blender/editors/object/object_add.c
parent9ee588cd4af881f3432fddce3044e90bad4e30f6 (diff)
Pointclouds: support mesh <-> pointcloud in convert operator
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 Differential Revision: https://developer.blender.org/D7391
Diffstat (limited to 'source/blender/editors/object/object_add.c')
-rw-r--r--source/blender/editors/object/object_add.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index fa1d147dc5e..fe68195409f 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -41,6 +41,7 @@
#include "DNA_object_fluidsim_types.h"
#include "DNA_object_force_types.h"
#include "DNA_object_types.h"
+#include "DNA_pointcloud_types.h"
#include "DNA_scene_types.h"
#include "DNA_vfont_types.h"
@@ -2328,8 +2329,15 @@ void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
static const EnumPropertyItem convert_target_items[] = {
{OB_CURVE, "CURVE", ICON_OUTLINER_OB_CURVE, "Curve from Mesh/Text", ""},
+#ifdef WITH_PARTICLE_NODES
+ {OB_MESH, "MESH", ICON_OUTLINER_OB_MESH, "Mesh from Curve/Meta/Surf/Text/Pointcloud", ""},
+#else
{OB_MESH, "MESH", ICON_OUTLINER_OB_MESH, "Mesh from Curve/Meta/Surf/Text", ""},
+#endif
{OB_GPENCIL, "GPENCIL", ICON_OUTLINER_OB_GREASEPENCIL, "Grease Pencil from Curve/Mesh", ""},
+#ifdef WITH_PARTICLE_NODES
+ {OB_POINTCLOUD, "POINTCLOUD", ICON_OUTLINER_OB_POINTCLOUD, "Pointcloud from Mesh", ""},
+#endif
{0, NULL, 0, NULL, NULL},
};
@@ -2467,6 +2475,7 @@ static int object_convert_exec(bContext *C, wmOperator *op)
MetaBall *mb;
Mesh *me;
Object *ob_gpencil = NULL;
+ PointCloud *pointcloud;
const short target = RNA_enum_get(op->ptr, "target");
bool keep_original = RNA_boolean_get(op->ptr, "keep_original");
@@ -2636,6 +2645,31 @@ static int object_convert_exec(bContext *C, wmOperator *op)
}
ob_gpencil->actcol = actcol;
}
+ else if (ob->type == OB_MESH && target == OB_POINTCLOUD) {
+ ob->flag |= OB_DONE;
+
+ if (keep_original) {
+ basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
+ newob = basen->object;
+
+ /* decrement original mesh's usage count */
+ me = newob->data;
+ id_us_min(&me->id);
+
+ /* make a new copy of the mesh */
+ newob->data = BKE_mesh_copy(bmain, me);
+ }
+ else {
+ newob = ob;
+ }
+
+ BKE_mesh_to_pointcloud(bmain, depsgraph, scene, newob);
+
+ if (newob->type == OB_POINTCLOUD) {
+ BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
+ ED_rigidbody_object_remove(bmain, scene, newob);
+ }
+ }
else if (ob->type == OB_MESH) {
ob->flag |= OB_DONE;
@@ -2821,6 +2855,31 @@ static int object_convert_exec(bContext *C, wmOperator *op)
mballConverted = 1;
}
}
+ else if (ob->type == OB_POINTCLOUD && target == OB_MESH) {
+ ob->flag |= OB_DONE;
+
+ if (keep_original) {
+ basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
+ newob = basen->object;
+
+ /* decrement original pointclouds's usage count */
+ pointcloud = newob->data;
+ id_us_min(&pointcloud->id);
+
+ /* make a new copy of the pointcloud */
+ newob->data = BKE_pointcloud_copy(bmain, pointcloud);
+ }
+ else {
+ newob = ob;
+ }
+
+ BKE_pointcloud_to_mesh(bmain, depsgraph, scene, newob);
+
+ if (newob->type == OB_MESH) {
+ BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
+ ED_rigidbody_object_remove(bmain, scene, newob);
+ }
+ }
else {
continue;
}