Page MenuHome

boolean_python-0.2.patch

boolean_python-0.2.patch

diff -aur blender-orig/source/blender/blenkernel/BKE_booleanops.h blender/source/blender/blenkernel/BKE_booleanops.h
--- blender-orig/source/blender/blenkernel/BKE_booleanops.h 2005-09-03 19:22:28.000000000 +0200
+++ blender/source/blender/blenkernel/BKE_booleanops.h 2006-02-16 16:49:17.000000000 +0100
@@ -54,6 +54,13 @@
struct Base * base_select,
int op_type
);
+extern int
+NewBooleanMesh2(
+ Object * ob1,
+ Object * ob_select,
+ Object ** ob_new,
+ int int_op_type
+);
struct DispListMesh *NewBooleanMeshDLM(struct Object *ob, struct Object *ob_select, int int_op_type);
@@ -93,7 +100,7 @@
extern
struct Object *
AddNewBlenderMesh(
- struct Base *base
+ struct Object *base
);
extern
diff -aur blender-orig/source/blender/python/api2_2x/doc/Object.py blender/source/blender/python/api2_2x/doc/Object.py
--- blender-orig/source/blender/python/api2_2x/doc/Object.py 2006-01-17 17:32:09.000000000 +0100
+++ blender/source/blender/python/api2_2x/doc/Object.py 2006-02-16 16:52:56.000000000 +0100
@@ -299,6 +299,33 @@
@param fast: If the value is 0, the scene hierarchy will not be updated. Any
other value, or no value at all will update the scene hierarchy.
"""
+
+ def difference(me):
+ """
+ Return a new mesh object which is the boolean difference between this mesh object and me.
+ @type me: Object
+ @param me: mesh object to make the boolean difference.
+ @rtype: Object
+ @return: A new mesh object if success.
+ """
+
+ def union(me):
+ """
+ Return a new mesh object which is the boolean union between this mesh object and me.
+ @type me: Object
+ @param me: mesh object to make the boolean union.
+ @rtype: Object
+ @return: A new mesh object if success.
+ """
+
+ def intersection(me):
+ """
+ Return a new mesh object which is the boolean intersection between this mesh object and me.
+ @type me: Object
+ @param me: mesh object to make the boolean intersection.
+ @rtype: Object
+ @return: A new mesh object if success.
+ """
def getData(name_only=False, mesh=False):
"""
diff -aur blender-orig/source/blender/python/api2_2x/Object.c blender/source/blender/python/api2_2x/Object.c
--- blender-orig/source/blender/python/api2_2x/Object.c 2006-01-17 07:47:48.000000000 +0100
+++ blender/source/blender/python/api2_2x/Object.c 2006-02-17 12:10:00.000000000 +0100
@@ -60,6 +60,7 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_scene.h"
+#include "BKE_booleanops.h"
#include "BIF_editview.h"
#include "BSE_editipo.h"
#include "BSE_edit.h"
@@ -178,6 +179,9 @@
static PyObject *Object_clearIpo( BPy_Object * self );
static PyObject *Object_clrParent( BPy_Object * self, PyObject * args );
static PyObject *Object_clearTrack( BPy_Object * self, PyObject * args );
+static PyObject *Object_intersection( BPy_Object * self, PyObject * other );
+static PyObject *Object_union( BPy_Object * self, PyObject * other );
+static PyObject *Object_difference( BPy_Object * self, PyObject * other );
static PyObject *Object_getData(BPy_Object *self, PyObject *args, PyObject *kwd);
static PyObject *Object_getDeltaLocation( BPy_Object * self );
static PyObject *Object_getDrawMode( BPy_Object * self );
@@ -299,6 +303,12 @@
"Make this object not track another anymore. Optionally specify:\n\
mode\n\t2: Keep object transform\nfast\n\t>0: Don't update scene \
hierarchy (faster)"},
+ {"intersection", ( PyCFunction ) Object_intersection, METH_VARARGS,
+ "return a new NMesh from boolean intersection of 2 Objects"},
+ {"union", ( PyCFunction ) Object_union, METH_VARARGS,
+ "return a new NMesh from boolean union of 2 Objects"},
+ {"difference", ( PyCFunction ) Object_difference, METH_VARARGS,
+ "return a new NMesh from boolean difference of 2 Objects"},
{"getData", ( PyCFunction ) Object_getData, METH_VARARGS | METH_KEYWORDS,
"(name_only = 0, mesh = 0) - Returns the datablock object containing the object's \
data, e.g. Mesh.\n\
@@ -1046,6 +1056,93 @@
return 0;
}
+static PyObject * Object_intersection( BPy_Object * self, PyObject * args ) {
+ Object *ob_new;
+ PyObject *other;
+
+ if( !PyArg_ParseTuple( args, "O", &other ) ) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected an object argument" );
+ }
+ if( !Object_CheckPyObject( ( PyObject * ) other ) ) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "first argument is not of type 'Object'" );
+ }
+
+ if (Object_FromPyObject((BPy_Object*)self)->type != OB_MESH) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "self is not a mesh object" );
+ }
+ if (Object_FromPyObject((BPy_Object*)other)->type != OB_MESH) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "first argument is not a mesh object" );
+ }
+
+ if (!NewBooleanMesh2(Object_FromPyObject((BPy_Object*)other), Object_FromPyObject(self), &ob_new, 1)) {
+ return EXPP_ReturnPyObjError( PyExc_ValueError,
+ "Boolean 'intersection' operation failed" );
+ }
+ return Object_CreatePyObject( ob_new );
+}
+
+static PyObject * Object_union( BPy_Object * self, PyObject * args ) {
+ Object *ob_new;
+ PyObject *other;
+
+ if( !PyArg_ParseTuple( args, "O", &other ) ) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected an object argument" );
+ }
+ if( !Object_CheckPyObject( ( PyObject * ) other ) ) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "first argument is not of type 'Object'" );
+ }
+
+ if (Object_FromPyObject((BPy_Object*)self)->type != OB_MESH) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "self is not a mesh object" );
+ }
+ if (Object_FromPyObject((BPy_Object*)other)->type != OB_MESH) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "first argument is not a mesh object" );
+ }
+
+ if (!NewBooleanMesh2(Object_FromPyObject((BPy_Object*)other), Object_FromPyObject(self), &ob_new, 2)) {
+ return EXPP_ReturnPyObjError( PyExc_ValueError,
+ "Boolean 'union' operation failed" );
+ }
+ return Object_CreatePyObject( ob_new );
+}
+
+static PyObject * Object_difference( BPy_Object * self, PyObject * args ) {
+ Object *ob_new;
+ PyObject *other;
+
+ if( !PyArg_ParseTuple( args, "O", &other ) ) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected an object argument" );
+ }
+ if( !Object_CheckPyObject( ( PyObject * ) other ) ) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "first argument is not of type 'Object'" );
+ }
+
+ if (Object_FromPyObject((BPy_Object*)self)->type != OB_MESH) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "self is not a mesh object" );
+ }
+ if (Object_FromPyObject((BPy_Object*)other)->type != OB_MESH) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "first argument is not a mesh object" );
+ }
+
+ if (!NewBooleanMesh2(Object_FromPyObject((BPy_Object*)other), Object_FromPyObject(self), &ob_new, 3)) {
+ return EXPP_ReturnPyObjError( PyExc_ValueError,
+ "Boolean 'difference' operation failed" );
+ }
+ return Object_CreatePyObject( ob_new );
+}
+
static PyObject *Object_getData( BPy_Object *self, PyObject *args, PyObject *kwd )
{
diff -aur blender-orig/source/blender/src/booleanops.c blender/source/blender/src/booleanops.c
--- blender-orig/source/blender/src/booleanops.c 2006-01-01 16:41:20.000000000 +0100
+++ blender/source/blender/src/booleanops.c 2006-02-16 16:54:03.000000000 +0100
@@ -575,10 +575,45 @@
struct Base * base_select,
int int_op_type
){
- Mesh *me2 = get_mesh(base_select->object);
- Mesh *me = get_mesh(base->object);
+ int status;
+ Object *ob_new = NULL;
+ Base *basen;
+
+ if (status = NewBooleanMesh2(base->object,
+ base_select->object,
+ &ob_new,
+ int_op_type)) {
+
+ if (ob_new) {
+
+ // Now create a new base to add into the linked list of
+ // vase objects.
+
+ basen= MEM_mallocN(sizeof(Base), "duplibase");
+ *basen= *base;
+ BLI_addhead(&G.scene->base, basen); /* addhead: anders oneindige lus */
+ basen->object= ob_new;
+ basen->flag &= ~SELECT;
+
+ DAG_object_flush_update(G.scene, ob_new, OB_RECALC_DATA);
+ } else {
+ printf("Object is NULL \n");
+ }
+ }
+ return status;
+}
+
+ int
+NewBooleanMesh2(
+ Object * ob,
+ Object * ob_select,
+ Object ** ob_new,
+ int int_op_type
+){
+ Mesh *me2 = get_mesh(ob_select);
+ Mesh *me = get_mesh(ob);
Mesh *me_new = NULL;
- Object *ob, *ob_new = NULL;
+ //Object *ob = NULL;
int free_tface1,free_tface2;
float inv_mat[4][4];
@@ -653,7 +688,7 @@
mpd2.user_face_vertex_data_size = sizeof(FaceVertexData);
}
- ob = base->object;
+ //ob = ob1;
// we map the final object back into object 1's (ob)
// local coordinate space. For this we need to compute
@@ -674,12 +709,12 @@
}
BuildMeshDescriptors(
- base->object,
+ ob,
&fd_1,
&vd_1
);
BuildMeshDescriptors(
- base_select->object,
+ ob_select,
&fd_2,
&vd_2
);
@@ -714,22 +749,22 @@
// need to make sure its zeroed
memset (&dlm, 0, sizeof (dlm));
- // Create a new blender mesh object - using 'base' as
+ // Create a new blender mesh object - using 'ob1' as
// a template for the new object.
- ob_new= AddNewBlenderMesh(base);
+ *ob_new= AddNewBlenderMesh(ob);
// get the output descriptors
CSG_OutputFaceDescriptor(bool_op,&fd_o);
CSG_OutputVertexDescriptor(bool_op,&vd_o);
- me_new = ob_new->data;
+ me_new = (*ob_new)->data;
// iterate through results of operation and insert into new object
// see subsurf.c
ConvertCSGDescriptorsToDLM(
&dlm,
- ob_new,
+ *ob_new,
&output_mpd,
&fd_o,
&vd_o,
@@ -782,26 +817,22 @@
FreeMeshDescriptors(&fd_1,&vd_1);
FreeMeshDescriptors(&fd_2,&vd_2);
- if (ob_new) {
- DAG_object_flush_update(G.scene, ob_new, OB_RECALC_DATA);
- }
-
return success;
}
Object *
AddNewBlenderMesh(
- Base *base
+ Object *ob
){
Mesh *old_me;
- Base *basen;
+ //Base *basen;
Object *ob_new;
// now create a new blender object.
// duplicating all the settings from the previous object
// to the new one.
- ob_new= copy_object(base->object);
+ ob_new= copy_object(ob);
// Ok we don't want to use the actual data from the
// last object, the above function incremented the
@@ -809,14 +840,6 @@
old_me= ob_new->data;
old_me->id.us--;
- // Now create a new base to add into the linked list of
- // vase objects.
-
- basen= MEM_mallocN(sizeof(Base), "duplibase");
- *basen= *base;
- BLI_addhead(&G.scene->base, basen); /* addhead: anders oneindige lus */
- basen->object= ob_new;
- basen->flag &= ~SELECT;
// Initialize the mesh data associated with this object.
ob_new->data= add_mesh();

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
45/f3/538fd990c0aabfc16f0eef56d4c6

Event Timeline