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:
authorCampbell Barton <ideasman42@gmail.com>2006-01-03 05:35:45 +0300
committerCampbell Barton <ideasman42@gmail.com>2006-01-03 05:35:45 +0300
commit5f48930a7514922efe7cebda971bd758e3d6b8cf (patch)
tree90dadc6353fa88e37d4693f8e2a4ccfcfc7f874f /source/blender
parent80f903ed73878c42b005069c2453c2737275a845 (diff)
Moved Object.Join() into a function of an object.
eg. ret_val = ob.join(objects) Now it dosent depend on the current selection, or change the selection context. Made respective join_* functions return 0 if the join was not mode, 1 when it workes.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/include/BDR_editcurve.h2
-rw-r--r--source/blender/include/BIF_editarmature.h2
-rw-r--r--source/blender/include/BIF_meshtools.h2
-rw-r--r--source/blender/python/api2_2x/Object.c194
-rw-r--r--source/blender/python/api2_2x/doc/Object.py18
-rw-r--r--source/blender/src/editarmature.c6
-rw-r--r--source/blender/src/editcurve.c10
-rw-r--r--source/blender/src/meshtools.c17
8 files changed, 158 insertions, 93 deletions
diff --git a/source/blender/include/BDR_editcurve.h b/source/blender/include/BDR_editcurve.h
index 9355eebb85d..9cddad4bf67 100644
--- a/source/blender/include/BDR_editcurve.h
+++ b/source/blender/include/BDR_editcurve.h
@@ -81,7 +81,7 @@ void selectrow_nurb(void);
void adduplicate_nurb(void);
void delNurb(void);
void nurb_set_smooth(short event);
-void join_curve(int type);
+int join_curve(int type);
struct Nurb *addNurbprim(int type, int stype, int newname);
void default_curve_ipo(struct Curve *cu);
void add_primitiveCurve(int stype);
diff --git a/source/blender/include/BIF_editarmature.h b/source/blender/include/BIF_editarmature.h
index baf215a4ce2..c8220fabe33 100644
--- a/source/blender/include/BIF_editarmature.h
+++ b/source/blender/include/BIF_editarmature.h
@@ -87,7 +87,7 @@ void subdivide_armature(void);
void free_editArmature(void);
-void join_armature(void);
+int join_armature(void);
void load_editArmature(void);
void make_bone_parent(void);
diff --git a/source/blender/include/BIF_meshtools.h b/source/blender/include/BIF_meshtools.h
index b5f5a91c50c..a0ee42081bd 100644
--- a/source/blender/include/BIF_meshtools.h
+++ b/source/blender/include/BIF_meshtools.h
@@ -35,7 +35,7 @@
struct Object;
-extern void join_mesh(void);
+extern int join_mesh(void);
extern void fasterdraw(void);
extern void slowerdraw(void);
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c
index 10d9370383a..ea37c4b0eec 100644
--- a/source/blender/python/api2_2x/Object.c
+++ b/source/blender/python/api2_2x/Object.c
@@ -115,7 +115,6 @@ static PyObject *M_Object_New( PyObject * self, PyObject * args );
PyObject *M_Object_Get( PyObject * self, PyObject * args );
static PyObject *M_Object_GetSelected( PyObject * self );
static PyObject *M_Object_Duplicate( PyObject * self, PyObject * args, PyObject *kwd);
-static PyObject *M_Object_Join( PyObject * self );
/* HELPER FUNCTION FOR PARENTING */
static PyObject *internal_makeParent(Object *parent, PyObject *py_child, int partype, int noninverse, int fast, int v1, int v2, int v3);
@@ -144,8 +143,6 @@ The active object is the first in the list, if visible";
char M_Object_Duplicate_doc[] =
"(linked) - Duplicate all selected, visible objects in the current scene";
-char M_Object_Join_doc[] =
- "() - Join all selected objects matching the active objects type.";
/*****************************************************************************/
/* Python method structure definition for Blender.Object module: */
@@ -159,8 +156,6 @@ struct PyMethodDef M_Object_methods[] = {
M_Object_GetSelected_doc},
{"Duplicate", ( PyCFunction ) M_Object_Duplicate, METH_VARARGS | METH_KEYWORDS,
M_Object_Duplicate_doc},
- {"Join", ( PyCFunction ) M_Object_Join, METH_VARARGS,
- M_Object_Join_doc},
{NULL, NULL, 0, NULL}
};
@@ -198,6 +193,7 @@ static PyObject *Object_isSelected( BPy_Object * self );
static PyObject *Object_makeDisplayList( BPy_Object * self );
static PyObject *Object_link( BPy_Object * self, PyObject * args );
static PyObject *Object_makeParent( BPy_Object * self, PyObject * args );
+static PyObject *Object_join( BPy_Object * self, PyObject * args );
static PyObject *Object_makeParentDeform( BPy_Object * self, PyObject * args );
static PyObject *Object_makeParentVertex( BPy_Object * self, PyObject * args );
static PyObject *Object_materialUsage( void );
@@ -463,6 +459,8 @@ mode:\n\t0: make parent with inverse\n\t1: without inverse\n\
fast:\n\t0: update scene hierarchy automatically\n\t\
don't update scene hierarchy (faster). In this case, you must\n\t\
explicitely update the Scene hierarchy."},
+ {"join", ( PyCFunction ) Object_join, METH_VARARGS,
+ "(object_list) - Joins the objects in object list of the same type, into this object."},
{"makeParentDeform", ( PyCFunction ) Object_makeParentDeform, METH_VARARGS,
"Makes the object the deformation parent of the objects provided in the \n\
argument which must be a list of valid Objects. Optional extra arguments:\n\
@@ -854,73 +852,6 @@ static PyObject *M_Object_Duplicate( PyObject * self, PyObject * args, PyObject
/*****************************************************************************/
-/* Function: M_Object_Join */
-/* Python equivalent: Blender.Object.Join */
-/*****************************************************************************/
-static PyObject *M_Object_Join( PyObject * self )
-{
- Base *base;
- Object *ob= OBACT;
- Mesh *me;
- int totvert=0, haskey=0;
-
- if( G.obedit )
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "can't join objects while in edit mode" );
-
- /* Replicate some of the mesh joining code, should realy spare a baselist loop and communicate
- with join_mesh(), will fix later, this will do for now */
- if (ob->type==OB_MESH) {
- /* count */
- base= FIRSTBASE;
- while(base) {
- if TESTBASELIB(base) {
- if(base->object->type==OB_MESH) {
- me= base->object->data;
- totvert+= me->totvert;
-
- if(me->key) {
- haskey= 1;
- break;
- }
- }
- }
- base= base->next;
- }
-
- if(haskey) {
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Can't join meshes with vertex keys" );
-
- }
-
- if(totvert==0)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Can't join meshes, there are no verts to join" );
- if (totvert>MESH_MAX_VERTS)
- return EXPP_ReturnPyObjError(PyExc_RuntimeError,
- "Can't join meshes, there are too many verts for 1 mesh." );
- }
-
-
- /* Do the actial joining now we know everythings OK. */
- if (ob) {
- if(ob->type == OB_MESH) {
- join_mesh();
- } else if(ob->type == OB_CURVE) {
- join_curve(OB_CURVE);
- } else if(ob->type == OB_SURF) {
- join_curve(OB_SURF);
- } else if(ob->type == OB_ARMATURE) {
- join_armature ();
- }
- }
-
- Py_RETURN_NONE;
-}
-
-
-/*****************************************************************************/
/* Function: initObject */
/*****************************************************************************/
PyObject *Object_Init( void )
@@ -1875,6 +1806,125 @@ static PyObject *Object_makeParent( BPy_Object * self, PyObject * args )
return EXPP_incr_ret( Py_None );
}
+
+static PyObject *Object_join( BPy_Object * self, PyObject * args )
+{
+ PyObject *list;
+ PyObject *py_child;
+ Object *parent;
+ Object *child;
+ Scene *temp_scene;
+ Scene *orig_scene;
+ Base *temp_base;
+ short type;
+ int i, ok=0, ret_value=0, list_length=0;
+
+ /* cant join in editmode */
+ if( G.obedit )
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "can't join objects while in edit mode" );
+
+ /* Check if the arguments passed to makeParent are valid. */
+ if( !PyArg_ParseTuple( args, "O", &list ) )
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "expected a list of objects and one or two integers as arguments" ) );
+
+ if( !PySequence_Check( list ) )
+ return ( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a list of objects" ) );
+
+ list_length = PySequence_Length( list ); /* if there are no objects to join then exit silently */
+
+ if( !list_length )
+ return EXPP_incr_ret( Py_None );
+
+
+ parent = ( Object * ) self->object;
+ type = parent->type;
+
+ if (type==OB_MESH || type==OB_MESH || type==OB_CURVE || type==OB_SURF || type==OB_ARMATURE);
+ else
+ return ( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "Base object is not a type blender can join" ) );
+
+ temp_scene = add_scene( "Scene" ); /* make the new scene */
+ temp_scene->lay= 2097151; /* all layers on */
+
+ /* Check if the PyObject passed in list is a Blender object. */
+ for( i = 0; i < list_length; i++ ) {
+ child = NULL;
+ py_child = PySequence_GetItem( list, i );
+ if( !Object_CheckPyObject( py_child ) ) {
+ /* Cleanup */
+ free_libblock( &G.main->scene, temp_scene );
+ return ( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a list of objects, one or more of the list items is not a Blender Object." ) );
+ } else {
+ /* List item is an object, is it the same type? */
+ child = ( Object * ) Object_FromPyObject( py_child );
+ if (parent->type == child->type) {
+ ok =1;
+ /* Add a new base, then link the base to the temp_scene */
+ temp_base = MEM_callocN( sizeof( Base ), "pynewbase" );
+ /*we know these types are the same, link to the temp scene for joining*/
+ temp_base->object = child; /* link object to the new base */
+ temp_base->flag |= SELECT;
+ temp_base->lay = 1; /*1 layer on */
+
+ BLI_addhead( &temp_scene->base, temp_base ); /* finally, link new base to scene */
+ /*child->id.us += 1;*/ /*Would useually increase user count but in this case its ok not to */
+ } else {
+ child->id.us -= 1; /* python object user oddness */
+ }
+
+ }
+ }
+
+ orig_scene = G.scene; /* backup our scene */
+
+ /* Add the main object into the temp_scene */
+ temp_base = MEM_callocN( sizeof( Base ), "pynewbase" );
+ temp_base->object = parent; /* link object to the new base */
+ temp_base->flag |= SELECT;
+ temp_base->lay = 1; /*1 layer on */
+ BLI_addhead( &temp_scene->base, temp_base ); /* finally, link new base to scene */
+ parent->id.us += 1;
+
+ /* all objects in the scene, set it active and the active object */
+ set_scene( temp_scene );
+ set_active_base( temp_base );
+
+ /* Do the joining now we know everythings OK. */
+ if(type == OB_MESH)
+ ret_value = join_mesh();
+ else if(type == OB_CURVE)
+ ret_value = join_curve(OB_CURVE);
+ else if(type == OB_SURF)
+ ret_value = join_curve(OB_SURF);
+ else if(type == OB_ARMATURE)
+ ret_value = join_armature ();
+ /* May use for correcting object user counts */
+ /*
+ if (!ret_value) {
+ temp_base = temp_scene->base.first;
+ while( base ) {
+ object = base->object;
+ object->id.us +=1
+ base = base->next;
+ }
+ }*/
+
+
+ /* remove old scene */
+ set_scene( orig_scene );
+ free_libblock( &G.main->scene, temp_scene );
+
+ if (!ok) /* no objects were of the correct type, return 0 */
+ return ( PyInt_FromLong(0) );
+
+ return ( PyInt_FromLong(ret_value) );
+}
+
static PyObject *internal_makeParent(Object *parent, PyObject *py_child,
int partype, /* parenting type */
int noninverse, int fast, /* parenting arguments */
diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py
index c5978a5d97e..dac594d9259 100644
--- a/source/blender/python/api2_2x/doc/Object.py
+++ b/source/blender/python/api2_2x/doc/Object.py
@@ -156,7 +156,7 @@ def Duplicate (mesh=0, surface=0, curve=0, text=0, metaball=0, armature=0, lamp=
activeObject.LocX += 1
Blender.Redraw()
"""
-
+'''
def Join ():
"""
Joins selected objects on visible layers from Blenders current scene.
@@ -168,7 +168,7 @@ def Join ():
@note: The join may be unsucsessfull because of the selection or object types and no error raised.
Checking if the number of selected objects has changed is a way to know the join worked.
"""
-
+'''
class Object:
"""
@@ -560,6 +560,20 @@ class Object:
unlinked object will result in an error.
"""
+ def join(objects):
+ """
+ Uses the object as a base for all of the objects in the provided list to join into.
+
+ @type objects: Sequence of Blender Object
+ @param objects: A list of objects matching the objects type.
+ @note: Objects in the list will not be removed, to avoid duplicate data you may want to remove them manualy after joining.
+ @note: Join modifies the object in place so that other objects are joined into it. no new object or data is created.
+ @note: Join will only work for object types Mesh, Armature, Curve and Surface, an error will be raised if the object is not of this type.
+ @note: objects in the list will be ignored if they to not match the base object.
+ @rtype: int
+ @return: 0 is returned if the join is not successfull, otherwise 1 will be returned.
+ """
+
def makeParentDeform(objects, noninverse = 0, fast = 0):
"""
Makes the object the deformation parent of the objects provided in the argument
diff --git a/source/blender/src/editarmature.c b/source/blender/src/editarmature.c
index 6983f19093b..d80f603aa28 100644
--- a/source/blender/src/editarmature.c
+++ b/source/blender/src/editarmature.c
@@ -349,7 +349,7 @@ void apply_rot_armature (Object *ob, float mat[3][3])
}
}
-void join_armature(void)
+int join_armature(void)
{
Object *ob;
Base *base, *nextbase;
@@ -361,7 +361,7 @@ void join_armature(void)
/* if(G.obedit) return; */ /* Alredy checked in join_menu() */
ob= OBACT;
- if(ob->type!=OB_ARMATURE) return;
+ if(ob->type!=OB_ARMATURE) return 0;
/* Put the active armature into editmode and join the bones from the other one*/
@@ -431,7 +431,7 @@ void join_armature(void)
exit_editmode(1);
allqueue(REDRAWVIEW3D, 0);
allqueue(REDRAWOOPS, 0);
-
+ return 1;
}
/* **************** END tools on Editmode Armature **************** */
diff --git a/source/blender/src/editcurve.c b/source/blender/src/editcurve.c
index fe09c3cc2ad..b660836f9d2 100644
--- a/source/blender/src/editcurve.c
+++ b/source/blender/src/editcurve.c
@@ -3275,7 +3275,7 @@ void nurb_set_smooth(short event)
else if(event==0) BIF_undo_push("Set Solid");
}
-void join_curve(int type)
+int join_curve(int type)
{
Base *base, *nextb;
Object *ob;
@@ -3287,11 +3287,9 @@ void join_curve(int type)
float imat[4][4], cmat[4][4];
int a;
- /* if(G.obedit) return; */ /* Alredy checked in join_menu() */
-
ob= OBACT;
- if(ob->type!=type) return;
- if(ob->lay & G.vd->lay); else return;
+ if(ob->type!=type) return 0;
+ if(ob->lay & G.vd->lay); else return 0;
tempbase.first= tempbase.last= 0;
/* trasnform all selected curves inverse in obact */
@@ -3353,7 +3351,7 @@ void join_curve(int type)
allqueue(REDRAWVIEW3D, 0);
allqueue(REDRAWBUTSEDIT, 0);
BIF_undo_push("Join");
-
+ return 1;
}
diff --git a/source/blender/src/meshtools.c b/source/blender/src/meshtools.c
index 8211bcaf8af..09d9f8bb5bf 100644
--- a/source/blender/src/meshtools.c
+++ b/source/blender/src/meshtools.c
@@ -34,7 +34,7 @@
meshtools.c: no editmode, tools operating on meshes
-void join_mesh(void);
+int join_mesh(void);
void fasterdraw(void);
void slowerdraw(void);
@@ -115,7 +115,9 @@ static int testSelected_TfaceMesh(void)
return 0;
}
-void join_mesh(void)
+/* join selected meshes into the active mesh, context sensitive
+return 0 if no join is made (error) and 1 of the join is done */
+int join_mesh(void)
{
Base *base, *nextb;
Object *ob;
@@ -132,10 +134,10 @@ void join_mesh(void)
bDeformGroup *dg, *odg;
MDeformVert *dvert, *dvertmain;
- if(G.obedit) return;
+ if(G.obedit) return 0;
ob= OBACT;
- if(!ob || ob->type!=OB_MESH) return;
+ if(!ob || ob->type!=OB_MESH) return 0;
/* count */
base= FIRSTBASE;
@@ -159,12 +161,12 @@ void join_mesh(void)
if(haskey) {
error("Can't join meshes with vertex keys");
- return;
+ return 0;
}
/* that way the active object is always selected */
- if(ok==0) return;
+ if(ok==0) return 0;
- if(totvert==0 || totvert>MESH_MAX_VERTS) return;
+ if(totvert==0 || totvert>MESH_MAX_VERTS) return 0;
@@ -438,6 +440,7 @@ void join_mesh(void)
allqueue(REDRAWBUTSSHADING, 0);
BIF_undo_push("Join Mesh");
+ return 1;
}