[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11133] branches/pyapi_devel/source/ blender/python/api2_2x: Lattice refactor to make modifying point locations similar to meshes
Campbell Barton
cbarton at metavr.com
Sat Jun 30 07:58:30 CEST 2007
Revision: 11133
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11133
Author: campbellbarton
Date: 2007-06-30 07:58:30 +0200 (Sat, 30 Jun 2007)
Log Message:
-----------
Lattice refactor to make modifying point locations similar to meshes
for p in lattice.points:
if p.sel:
print p.co
Lattice vectors also update when used so you cant write to an invalid pointer.
Modified Paths:
--------------
branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
branches/pyapi_devel/source/blender/python/api2_2x/Lattice.c
branches/pyapi_devel/source/blender/python/api2_2x/Lattice.h
branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
branches/pyapi_devel/source/blender/python/api2_2x/vector.c
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Blender.c 2007-06-30 03:26:18 UTC (rev 11132)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Blender.c 2007-06-30 05:58:30 UTC (rev 11133)
@@ -955,7 +955,7 @@
PyDict_SetItemString(dict, "Image", Image_Init());
PyDict_SetItemString(dict, "Key", Key_Init());
PyDict_SetItemString(dict, "Lamp", Lamp_Init());
- PyDict_SetItemString(dict, "Lattice", Lattice_Init());
+ Lattice_Init();
PyDict_SetItemString(dict, "Library", oldLibrary_Init());
PyDict_SetItemString(dict, "Material", Material_Init());
PyDict_SetItemString(dict, "Mesh", Mesh_Init());
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Lattice.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Lattice.c 2007-06-30 03:26:18 UTC (rev 11132)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Lattice.c 2007-06-30 05:58:30 UTC (rev 11133)
@@ -50,70 +50,24 @@
#include "blendef.h"
#include "gen_utils.h"
#include "gen_library.h"
+#include "vector.h"
#include "Key.h"
+static BPoint * LPoint_get_pointer( BPy_LPoint * self );
+static PyObject *LPoint_CreatePyObject( BPy_Lattice *bpylat, int i );
+
/*****************************************************************************/
/* Python API function prototypes for the Lattice module. */
/*****************************************************************************/
-static PyObject *M_Lattice_New( PyObject * self, PyObject * args );
-static PyObject *M_Lattice_Get( PyObject * self, PyObject * args );
/*****************************************************************************/
-/* Lattice Module strings */
-/* The following string definitions are used for documentation strings. */
-/* In Python these will be written to the console when doing a */
-/* Blender.Lattice.__doc__ */
-/*****************************************************************************/
-static char M_Lattice_doc[] = "The Blender Lattice module\n\n";
-
-static char M_Lattice_New_doc[] = "() - return a new Lattice object";
-
-static char M_Lattice_Get_doc[] = "() - geta a Lattice from blender";
-
-/*****************************************************************************/
-/* Python method structure definition for Blender.Lattice module: */
-/*****************************************************************************/
-struct PyMethodDef M_Lattice_methods[] = {
- {"New", ( PyCFunction ) M_Lattice_New, METH_VARARGS,
- M_Lattice_New_doc},
- {"Get", ( PyCFunction ) M_Lattice_Get, METH_VARARGS,
- M_Lattice_Get_doc},
- {NULL, NULL, 0, NULL}
-};
-
-
-/*****************************************************************************/
/* Lattice Strings */
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.Lattice.__doc__ */
/*****************************************************************************/
-static char Lattice_setPartitions_doc[] =
- "(str) - Set the number of Partitions in x,y,z";
-static char Lattice_getPartitions_doc[] =
- "(str) - Get the number of Partitions in x,y,z";
-
-static char Lattice_getKey_doc[] =
- "() - Get the Key object attached to this Lattice";
-
-static char Lattice_setKeyTypes_doc[] =
- "(str) - Set the key types for x,y,z dimensions";
-
-static char Lattice_getKeyTypes_doc[] =
- "(str) - Get the key types for x,y,z dimensions";
-
-static char Lattice_setMode_doc[] = "(str) - Make an outside or grid lattice";
-
-static char Lattice_getMode_doc[] = "(str) - Get lattice mode type";
-
-static char Lattice_setPoint_doc[] =
- "(str) - Set the coordinates of a point on the lattice";
-
-static char Lattice_getPoint_doc[] =
- "(str) - Get the coordinates of a point on the lattice";
-
static char Lattice_insertKey_doc[] =
"(str) - Set a new key for the lattice at specified frame";
@@ -121,24 +75,6 @@
"() - Return a copy of the lattice.";
//***************************************************************************
-// Function: Lattice_CreatePyObject
-//***************************************************************************
-PyObject *Lattice_CreatePyObject( Lattice * lt )
-{
- BPy_Lattice *pyLat;
-
- pyLat = ( BPy_Lattice * ) PyObject_NEW( BPy_Lattice, &Lattice_Type );
-
- if( !pyLat )
- return EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create BPy_Lattice PyObject" );
-
- pyLat->lattice = lt;
-
- return ( PyObject * ) pyLat;
-}
-
-//***************************************************************************
// Function: Lattice_FromPyObject
//***************************************************************************
@@ -148,167 +84,23 @@
}
//***************************************************************************
-// Function: M_Lattice_New
-// Python equivalent: Blender.Lattice.New
+// Function: Lattice_CreatePyObject
//***************************************************************************
-static PyObject *M_Lattice_New( PyObject * self, PyObject * args )
+PyObject *Lattice_CreatePyObject( Lattice * lt )
{
- char *name = NULL;
- Lattice *bl_Lattice; // blender Lattice object
- PyObject *py_Lattice; // python wrapper
+ BPy_Lattice *pyLat;
- if( !PyArg_ParseTuple( args, "|s", &name ) )
- return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected string and int arguments (or nothing)" );
+ pyLat = ( BPy_Lattice * ) PyObject_NEW( BPy_Lattice, &Lattice_Type );
- bl_Lattice = add_lattice( "Lattice" );
-
- if( bl_Lattice ) {
- bl_Lattice->id.us = 0;
- py_Lattice = Lattice_CreatePyObject( bl_Lattice );
- } else
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't create Lattice Object in Blender" );
- if( !py_Lattice )
+ if( !pyLat )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create Lattice Object wrapper" );
+ "couldn't create BPy_Lattice PyObject" );
- if( name )
- rename_id( &bl_Lattice->id, name );
+ pyLat->lattice = lt;
- return py_Lattice;
+ return ( PyObject * ) pyLat;
}
-//***************************************************************************
-// Function: M_Lattice_Get
-// Python equivalent: Blender.Lattice.Get
-//***************************************************************************
-static PyObject *M_Lattice_Get( PyObject * self, PyObject * args )
-{
- char *name = NULL;
- Lattice *lat_iter;
-
- if( !PyArg_ParseTuple( args, "|s", &name ) )
- return ( EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected string argument (or nothing)" ) );
-
- lat_iter = G.main->latt.first;
-
- if( name ) { /* (name) - Search Lattice by name */
-
- PyObject *wanted_lat = NULL;
-
- while( ( lat_iter ) && ( wanted_lat == NULL ) ) {
- if( strcmp( name, lat_iter->id.name + 2 ) == 0 ) {
- wanted_lat =
- Lattice_CreatePyObject( lat_iter );
- }
-
- lat_iter = lat_iter->id.next;
- }
-
- if( wanted_lat == NULL ) { /* Requested Lattice doesn't exist */
- char error_msg[64];
- PyOS_snprintf( error_msg, sizeof( error_msg ),
- "Lattice \"%s\" not found", name );
- return ( EXPP_ReturnPyObjError
- ( PyExc_NameError, error_msg ) );
- }
-
- return wanted_lat;
- }
-
- else { /* () - return a list of all Lattices in the scene */
- int index = 0;
- PyObject *latlist, *pyobj;
-
- latlist = PyList_New( BLI_countlist( &( G.main->latt ) ) );
-
- if( latlist == NULL )
- return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create PyList" ) );
-
- while( lat_iter ) {
- pyobj = Lattice_CreatePyObject( lat_iter );
-
- if( !pyobj ) {
- Py_DECREF(latlist);
- return ( EXPP_ReturnPyObjError
- ( PyExc_MemoryError,
- "couldn't create PyString" ) );
- }
- PyList_SET_ITEM( latlist, index, pyobj );
-
- lat_iter = lat_iter->id.next;
- index++;
- }
-
- return ( latlist );
- }
-}
-
-//***************************************************************************
-// Function: Lattice_Init
-//***************************************************************************
-PyObject *Lattice_Init( void )
-{
- PyObject *mod;
- PyObject *dict;
-
- if( PyType_Ready( &Lattice_Type ) < 0 )
- return NULL;
-
- mod = Py_InitModule3( "Blender.Lattice", M_Lattice_methods,
- M_Lattice_doc );
-
- dict = PyModule_GetDict( mod );
-
- //Module dictionary
-#define EXPP_ADDCONST(x) EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(LT_##x))
- EXPP_ADDCONST( GRID );
- EXPP_ADDCONST( OUTSIDE );
-
-#undef EXPP_ADDCONST
-#define EXPP_ADDCONST(x) EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(KEY_##x))
- EXPP_ADDCONST( LINEAR );
- EXPP_ADDCONST( CARDINAL );
- EXPP_ADDCONST( BSPLINE );
-
- return ( mod );
-}
-
-static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args )
-{
- int x = 0;
- int y = 0;
- int z = 0;
- Lattice *bl_Lattice;
-
- if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
- return ( EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected int,int,int argument" ) );
-
- bl_Lattice = self->lattice;
-
- if( x < 2 || y < 2 || z < 2 )
- return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "partition values must be 2 or greater" ) );
-
- resizelattice(bl_Lattice, x, y, z, NULL);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *Lattice_getPartitions( BPy_Lattice * self )
-{
- Lattice *bl_Lattice;
- bl_Lattice = self->lattice;
-
- return Py_BuildValue( "[i,i,i]", ( int ) bl_Lattice->pntsu,
- ( int ) bl_Lattice->pntsv,
- ( int ) bl_Lattice->pntsw );
-}
-
static PyObject *Lattice_getKey( BPy_Lattice * self )
{
Key *key = self->lattice->key;
@@ -319,228 +111,24 @@
Py_RETURN_NONE;
}
-static PyObject *Lattice_getKeyTypes( BPy_Lattice * self )
+static PyObject *Lattice_setOutside( BPy_Lattice * self, PyObject * value )
{
- Lattice *bl_Lattice;
- char *linear = "linear";
- char *cardinal = "cardinal";
- char *bspline = "bspline";
- char *s_x = NULL, *s_y = NULL, *s_z = NULL;
-
- bl_Lattice = self->lattice;
-
- if( ( bl_Lattice->typeu ) == KEY_LINEAR )
- s_x = linear;
- else if( ( bl_Lattice->typeu ) == KEY_CARDINAL )
- s_x = cardinal;
- else if( ( bl_Lattice->typeu ) == KEY_BSPLINE )
- s_x = bspline;
- else
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "bad key type..." );
-
- if( ( bl_Lattice->typev ) == KEY_LINEAR )
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list