Commit: ff98475fccd98a45ba044821363042ee005c7ba7
Author: Martin Felke
Date:   Mon Apr 8 21:54:42 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rBff98475fccd98a45ba044821363042ee005c7ba7

yay, multi-object volume CSG finally operational :)

===================================================================

M       intern/openvdb/intern/openvdb_level_set.cc
M       intern/openvdb/intern/openvdb_level_set.h
M       intern/openvdb/openvdb_capi.cc
M       release/scripts/startup/bl_ui/properties_data_modifier.py
M       source/blender/blenkernel/intern/modifier.c
M       source/blender/editors/object/object_intern.h
M       source/blender/editors/object/object_modifier.c
M       source/blender/editors/object/object_ops.c
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/makesrna/RNA_access.h
M       source/blender/makesrna/intern/rna_modifier.c
M       source/blender/modifiers/intern/MOD_remesh.c

===================================================================

diff --git a/intern/openvdb/intern/openvdb_level_set.cc 
b/intern/openvdb/intern/openvdb_level_set.cc
index bd2772f027c..280b008f369 100644
--- a/intern/openvdb/intern/openvdb_level_set.cc
+++ b/intern/openvdb/intern/openvdb_level_set.cc
@@ -117,27 +117,24 @@ void 
OpenVDBLevelSet::OpenVDB_level_set_filter(OpenVDBLevelSet_FilterType filter
                break;
        }
 }
-void OpenVDBLevelSet::OpenVDB_CSG_operation(openvdb::FloatGrid::Ptr gridOut, 
openvdb::FloatGrid::Ptr gridA, openvdb::FloatGrid::Ptr gridB,
-                                                  OpenVDBLevelSet_CSGOperation 
operation)
+openvdb::FloatGrid::Ptr 
OpenVDBLevelSet::OpenVDB_CSG_operation(openvdb::FloatGrid::Ptr gridA, 
openvdb::FloatGrid::Ptr gridB, OpenVDBLevelSet_CSGOperation operation)
 {
        openvdb::FloatGrid::Ptr gridA_copy = gridA->deepCopy();
        openvdb::FloatGrid::Ptr gridB_copy = gridB->deepCopy();
 
        switch (operation) {
                case OPENVDB_LEVELSET_CSG_UNION:
-                       openvdb::tools::csgUnion(*gridA, *gridB);
+                       openvdb::tools::csgUnion(*gridA_copy, *gridB_copy);
                break;
                case OPENVDB_LEVELSET_CSG_DIFFERENCE:
-                       openvdb::tools::csgDifference(*gridA, *gridB);
+                       openvdb::tools::csgDifference(*gridA_copy, *gridB_copy);
                break;
                case OPENVDB_LEVELSET_CSG_INTERSECTION:
-                       openvdb::tools::csgIntersection(*gridA, *gridB);
+                       openvdb::tools::csgIntersection(*gridA_copy, 
*gridB_copy);
                break;
        }
 
-       gridOut = gridA->deepCopy();
-       gridA = gridA_copy->deepCopy();
-       gridB = gridB_copy->deepCopy();
+       return gridA_copy;
 }
 
 openvdb::FloatGrid::Ptr OpenVDBLevelSet::OpenVDB_level_set_get_grid(){
diff --git a/intern/openvdb/intern/openvdb_level_set.h 
b/intern/openvdb/intern/openvdb_level_set.h
index 64e717484b8..a4779bd1308 100644
--- a/intern/openvdb/intern/openvdb_level_set.h
+++ b/intern/openvdb/intern/openvdb_level_set.h
@@ -49,7 +49,7 @@ public:
                                                        const double isovalue, 
const double adaptivity, const bool relax_disoriented_triangles);
        void OpenVDB_volume_to_mesh(struct OpenVDBVolumeToMeshData *mesh, const 
double isovalue, const double adaptivity, const bool 
relax_disoriented_triangles);
        void OpenVDB_level_set_filter(OpenVDBLevelSet_FilterType filter_type, 
int width, int iterations, int filter_bias);
-       void OpenVDB_CSG_operation(openvdb::FloatGrid::Ptr gridOut, 
openvdb::FloatGrid::Ptr gridA, openvdb::FloatGrid::Ptr gridB,
+       openvdb::FloatGrid::Ptr OpenVDB_CSG_operation(openvdb::FloatGrid::Ptr 
gridA, openvdb::FloatGrid::Ptr gridB,
                                                   OpenVDBLevelSet_CSGOperation 
operation);
 };
 
diff --git a/intern/openvdb/openvdb_capi.cc b/intern/openvdb/openvdb_capi.cc
index 12d7ec88c57..08057faccf2 100644
--- a/intern/openvdb/openvdb_capi.cc
+++ b/intern/openvdb/openvdb_capi.cc
@@ -298,8 +298,10 @@ void OpenVDBLevelSet_filter(struct OpenVDBLevelSet 
*level_set, OpenVDBLevelSet_F
 void OpenVDBLevelSet_CSG_operation(struct OpenVDBLevelSet *out, struct 
OpenVDBLevelSet *gridA, struct OpenVDBLevelSet *gridB,
                                                                   
OpenVDBLevelSet_CSGOperation operation)
 {
-       out->OpenVDB_CSG_operation(out->OpenVDB_level_set_get_grid(), 
gridA->OpenVDB_level_set_get_grid(),
-                                                          
gridB->OpenVDB_level_set_get_grid(), operation);
+       openvdb::FloatGrid::Ptr grid = 
out->OpenVDB_CSG_operation(gridA->OpenVDB_level_set_get_grid(),
+                                                                 
gridB->OpenVDB_level_set_get_grid(),
+                                                                 operation);
+       out->OpenVDB_level_set_set_grid(grid);
 }
 
 void OpenVDBLevelSet_set_transform(struct OpenVDBLevelSet *level_set, float* 
transform)
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 2414c775866..5233744dd3d 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1204,8 +1204,6 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
             layout.prop(md, "sharpness")
 
         if md.mode == 'VOXEL':
-            #layout.prop(md, "object")
-            #layout.prop(md, "operation")
             col = layout.column(align=True)
             col.prop(md, "voxel_size")
             col.prop(md, "isovalue")
@@ -1221,6 +1219,19 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
             layout.prop(md, "smooth_normals")
             layout.prop(md, "relax_triangles")
             layout.prop(md, "reproject_vertex_paint")
+            layout.label(text="CSG Operands")
+            layout.operator("remesh.csg_add", text="+")
+            for i,csg in enumerate(md.csg_operands):
+                box = layout.box()
+                row = box.row(align=True)
+                row.prop(csg, "enabled", text="")
+                row.prop(csg, "object", text="")
+                row.prop(csg, "operation", text="")
+                row = box.row(align=True)
+                row.prop(csg, "voxel_size")
+                row.operator("remesh.csg_remove", text="-").index = i
+                row.operator("remesh.csg_move_up", text="", 
icon="TRIA_UP").index = i
+                row.operator("remesh.csg_move_down", text="", 
icon="TRIA_DOWN").index = i
         else:
             layout.prop(md, "use_smooth_shade")
             layout.prop(md, "use_remove_disconnected")
diff --git a/source/blender/blenkernel/intern/modifier.c 
b/source/blender/blenkernel/intern/modifier.c
index fe955ced5f5..c6d1a4043a0 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -157,6 +157,18 @@ void modifier_free_ex(ModifierData *md, const int flag)
                        mti->foreachObjectLink(md, NULL, 
(ObjectWalkFunc)modifier_free_data_id_us_cb, NULL);
                }
        }
+#if 0
+       if (md->type == eModifierType_Remesh)
+       {
+               if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0){
+                       /* is this a regular free ? */
+                       RemeshModifierData *rmd = (RemeshModifierData*)md;
+                       if (rmd->shared) {
+                               //MEM_freeN(rmd->shared);
+                       }
+               }
+       }
+#endif
 
        if (mti->freeData) mti->freeData(md);
        if (md->error) MEM_freeN(md->error);
diff --git a/source/blender/editors/object/object_intern.h 
b/source/blender/editors/object/object_intern.h
index ca72e694564..1b1547f7d62 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -282,4 +282,9 @@ void OBJECT_OT_remesh(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_to_loop_colors(struct wmOperatorType *ot);
 void OBJECT_OT_loop_to_vertex_colors(struct wmOperatorType *ot);
 
+void REMESH_OT_csg_add(struct wmOperatorType *ot);
+void REMESH_OT_csg_remove(struct wmOperatorType *ot);
+void REMESH_OT_csg_move_up(struct wmOperatorType *ot);
+void REMESH_OT_csg_move_down(struct wmOperatorType *ot);
+
 #endif /* __OBJECT_INTERN_H__ */
diff --git a/source/blender/editors/object/object_modifier.c 
b/source/blender/editors/object/object_modifier.c
index c3a562df037..60080090050 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2404,3 +2404,202 @@ void OBJECT_OT_surfacedeform_bind(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
        edit_modifier_properties(ot);
 }
+
+static bool remesh_csg_poll(bContext *C)
+{
+       return edit_modifier_poll_generic(C, &RNA_RemeshModifier, 0);
+}
+
+static int remesh_csg_add_exec(bContext *C, wmOperator *op)
+{
+       Object *ob = ED_object_active_context(C);
+       RemeshModifierData *rmd = (RemeshModifierData 
*)edit_modifier_property_get(op, ob, eModifierType_Remesh);
+
+       if (rmd == NULL) {
+               return OPERATOR_CANCELLED;
+       }
+
+       CSGVolume_Object *vcob = MEM_callocN(sizeof(CSGVolume_Object), "vcob");
+       vcob->voxel_size = 0.1f;
+       vcob->flag |= MOD_REMESH_CSG_OBJECT_ENABLED;
+       BLI_addtail(&rmd->csg_operands, vcob);
+
+       DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | 
ID_RECALC_COPY_ON_WRITE);
+       WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+
+       return OPERATOR_FINISHED;
+}
+
+static int remesh_csg_add_invoke(bContext *C, wmOperator *op, const wmEvent 
*UNUSED(event))
+{
+       if (edit_modifier_invoke_properties(C, op))
+               return remesh_csg_add_exec(C, op);
+       else
+               return OPERATOR_CANCELLED;
+}
+
+void REMESH_OT_csg_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Add CSG Object";
+       ot->description = "Add CSG Object to remesh modifier";
+       ot->idname = "REMESH_OT_csg_add";
+
+       /* api callbacks */
+       ot->poll = remesh_csg_poll;
+       ot->invoke = remesh_csg_add_invoke;
+       ot->exec = remesh_csg_add_exec;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+       edit_modifier_properties(ot);
+}
+
+static int remesh_csg_remove_exec(bContext *C, wmOperator *op)
+{
+       Object *ob = ED_object_active_context(C);
+       RemeshModifierData *rmd = (RemeshModifierData 
*)edit_modifier_property_get(op, ob, eModifierType_Remesh);
+       int index = RNA_int_get(op->ptr, "index");
+
+       if (rmd == NULL) {
+               return OPERATOR_CANCELLED;
+       }
+
+       CSGVolume_Object* vcob = 
(CSGVolume_Object*)BLI_findlink(&rmd->csg_operands, index);
+       if (vcob) {
+               BLI_remlink(&rmd->csg_operands, vcob);
+       }
+
+       DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | 
ID_RECALC_COPY_ON_WRITE);
+       WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+
+       return OPERATOR_FINISHED;
+}
+
+
+static int remesh_csg_remove_invoke(bContext *C, wmOperator *op, const wmEvent 
*UNUSED(event))
+{
+       if (edit_modifier_invoke_properties(C, op))
+               return remesh_csg_remove_exec(C, op);
+       else
+               return OPERATOR_CANCELLED;
+}
+
+void REMESH_OT_csg_remove(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Remove CSG Object";
+       ot->description = "Remove CSG Object at index";
+       ot->idname = "REMESH_OT_csg_remove";
+
+       /* api callbacks */
+       ot->poll = remesh_csg_poll;
+       ot->invoke = remesh_csg_remove_invoke;
+       ot->exec = remesh_csg_remove_exec;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+       edit_modifier_properties(ot);
+
+       RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Index of the 
Object to remove", 0, INT_MAX);
+}
+
+static int remesh_csg_move_up_exec(bContext *C, wmOperator *op)
+{
+       Object *ob = ED_object_active_context(C);
+       RemeshModifierData *rmd = (RemeshModifierData 
*)edit_modifier_property_get(op, ob, eModifierType_Remesh);
+       int index = RNA_int_get(op->ptr, "index");
+
+       if (rmd == NULL

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to