diff options
author | Campbell Barton <ideasman42@gmail.com> | 2006-08-13 05:51:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2006-08-13 05:51:47 +0400 |
commit | 515fe83f97c37cdf920e1e2fb1ad3479cb8d781c (patch) | |
tree | 78ea12ce65783de5d546d1f35fb5287a0096e489 /source | |
parent | f27acb2e7c4eaf8121cc1ba419f820e699812d30 (diff) |
added __copy__ to mesh and object types, fixed a monor bug in setTexMesh and made Mesh.c use G.totMesh properly.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/api2_2x/Mesh.c | 31 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 23 |
2 files changed, 50 insertions, 4 deletions
diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 2bf24d99fbe..5600989ff4a 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -6437,6 +6437,29 @@ static PyObject *Mesh_fill( BPy_Mesh * self ) return Mesh_Tools( self, MESH_TOOL_FILL, NULL ); } + +/* + * "__copy__" return a copy of the mesh + */ + +static PyObject *Mesh_copy( BPy_Mesh * self ) +{ + BPy_Mesh *obj; + + obj = (BPy_Mesh *)PyObject_NEW( BPy_Mesh, &Mesh_Type ); + + if( !obj ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "PyObject_New() failed" ); + + obj->mesh = copy_mesh( self->mesh ); + obj->mesh->id.us= 0; + obj->object = NULL; + obj->new = 1; + return (PyObject *)obj; +} + + static struct PyMethodDef BPy_Mesh_methods[] = { {"calcNormals", (PyCFunction)Mesh_calcNormals, METH_NOARGS, "all recalculate vertex normals"}, @@ -6486,6 +6509,10 @@ static struct PyMethodDef BPy_Mesh_methods[] = { "Removes duplicates from selected vertices (experimental)"}, {"recalcNormals", (PyCFunction)Mesh_recalcNormals, METH_VARARGS, "Recalculates inside or outside normals (experimental)"}, + + /* python standard class functions */ + {"__copy__", (PyCFunction)Mesh_copy, METH_NOARGS, + "Return a copy of the mesh"}, {NULL, NULL, 0, NULL} }; @@ -6976,7 +7003,7 @@ static int Mesh_setTexMesh( BPy_Mesh * self, PyObject * arg ) /*This is a mesh so it needs to be added */ self->mesh->texcomesh= blen_obj->mesh; self->mesh->texcomesh->id.us++; - blen_obj->new==0; + blen_obj->new= 0; } return 0; } @@ -7296,7 +7323,6 @@ static PyObject *M_Mesh_New( PyObject * self_unused, PyObject * args ) "FATAL: could not create mesh object" ); } mesh->id.us = 0; - G.totmesh++; PyOS_snprintf( buf, sizeof( buf ), "%s", name ); rename_id( &mesh->id, buf ); @@ -7563,6 +7589,7 @@ PyObject *Mesh_CreatePyObject( Mesh * me, Object *obj ) nmesh->mesh = me; nmesh->object = obj; nmesh->new = 0; + G.totmesh++; return ( PyObject * ) nmesh; } diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 7fd32319515..8581288fe44 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -323,6 +323,7 @@ static PyObject *Object_setSBStiffQuads( BPy_Object * self, PyObject * args ); static PyObject *Object_insertShapeKey(BPy_Object * self); static PyObject *Object_copyNLA( BPy_Object * self, PyObject * args ); static PyObject *Object_convertActionToStrip( BPy_Object * self ); +static PyObject *Object_copy(BPy_Object * self); /* __copy__ */ /*****************************************************************************/ /* Python BPy_Object methods table: */ @@ -645,8 +646,10 @@ works only if self and the object specified are of the same type."}, METH_VARARGS, "() - Delete all scriptlinks from this object.\n" "([s1<,s2,s3...>]) - Delete specified scriptlinks from this object."}, - {"insertShapeKey", ( PyCFunction ) Object_insertShapeKey, - METH_NOARGS, "() - Insert a Shape Key in the current object"}, + {"insertShapeKey", ( PyCFunction ) Object_insertShapeKey, METH_NOARGS, + "() - Insert a Shape Key in the current object"}, + {"__copy__", ( PyCFunction ) Object_copy, METH_NOARGS, + "() - Return a copy of this object."}, {NULL, NULL, 0, NULL} }; @@ -3397,6 +3400,22 @@ static PyObject *Object_insertShapeKey(BPy_Object * self) return Py_None; } +/* __copy__() */ +static PyObject *Object_copy(BPy_Object * self) +{ + /* copy_object never returns NULL */ + struct Object *object= copy_object( self->object ); + object->id.us= 0; /*is 1 by default, not sure why */ + + /* Create a Python object from it. */ + return Object_CreatePyObject( object ); + + + + +} + + /*****************************************************************************/ /* Function: Object_CreatePyObject */ /* Description: This function will create a new BlenObject from an existing */ |