2003-11-13 04:00:59 +00:00
|
|
|
/*
|
2004-09-18 18:47:03 +00:00
|
|
|
* $Id$
|
2003-11-13 04:00:59 +00:00
|
|
|
*
|
|
|
|
|
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version. The Blender
|
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
|
* about this.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This is a new part of Blender.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Joseph Gilbert
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2005-07-18 03:50:37 +00:00
|
|
|
#include "Lattice.h" /*This must come first*/
|
|
|
|
|
|
2005-07-19 02:36:21 +00:00
|
|
|
#include "BKE_utildefines.h"
|
2005-07-18 03:50:37 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_library.h"
|
|
|
|
|
#include "BKE_lattice.h"
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_key_types.h"
|
2005-07-19 02:36:21 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2005-07-18 03:50:37 +00:00
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "BIF_editkey.h"
|
- added data arguments to deformer modifiers, in case someone wants
to write one that is based on geometry (and not just vertex position)
- added editmode versions of modifier deform/apply calls and flag
to tag modifiers that support editmode
- added isFinalCalc param to applyModifier, basically a switch to let
subsurf know if it is calc'ng orco or not (so it can deal with cache
appropriately). This is kinda hacky and perhaps I can come up with
a better solution (its also a waste to do a complete subdivide just
to get vertex locations).
- changed ccgsubsurf to not preallocate hash's to be approximately correct
size... this was probably not a big performance savings but means that
the order of faces returned by the iterator can vary after the first
call, this messes up orco calculation so dropped for time being.
- minor bug fix, meshes with only key didn't get vertex normals correctly
calc'd
- updated editmesh derivedmesh to support auxiliary locations
- changed mesh_calc_modifiers to alloc deformVerts on demand
- added editmesh_calc_modifiers for calculating editmesh cage and final
derivedmesh's
- bug fix, update shadedisplist to always calc colors (even if totvert==0)
- changed load_editMesh and make_edge to build me->medge even if totedge==0
(incremental subsurf checks this)
todo: add drawFacesTex for ccgderivedmesh
So, modifiers in editmode are back (which means auto-mirror
in edit mode works now) although still not finished. Currently
no cage is computed, the cage is always the base mesh (in
other words, Optimal edge style editing is off), and the final
mesh currently includes all modifiers that work in edit mode
(including lattice and curve). At some point there will be toggles
for which modifiers affect the final/cage editmode derivedmesh's.
Also, very nice new feature is that incremental subsurf in object
mode returns a ccgderivedmesh object instead of copying to a new
displistmesh. This can make a *huge* speed difference, and is very
nice for working with deformed armatures (esp. with only small
per frame changes).
2005-07-22 07:37:15 +00:00
|
|
|
#include "BIF_editdeform.h"
|
2006-03-24 21:56:29 +00:00
|
|
|
#include "BIF_space.h"
|
2004-10-07 19:25:40 +00:00
|
|
|
#include "blendef.h"
|
|
|
|
|
#include "gen_utils.h"
|
|
|
|
|
|
2005-09-09 01:31:10 +00:00
|
|
|
#include "Key.h"
|
2004-10-07 19:25:40 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* 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}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python BPy_Lattice methods declarations: */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
static PyObject *Lattice_getName( BPy_Lattice * self );
|
|
|
|
|
static PyObject *Lattice_setName( BPy_Lattice * self, PyObject * args );
|
|
|
|
|
static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args );
|
2005-09-09 01:31:10 +00:00
|
|
|
static PyObject *Lattice_getPartitions( BPy_Lattice * self );
|
|
|
|
|
static PyObject *Lattice_getKey( BPy_Lattice * self );
|
2004-10-07 19:25:40 +00:00
|
|
|
static PyObject *Lattice_setKeyTypes( BPy_Lattice * self, PyObject * args );
|
2005-09-09 01:31:10 +00:00
|
|
|
static PyObject *Lattice_getKeyTypes( BPy_Lattice * self );
|
2004-10-07 19:25:40 +00:00
|
|
|
static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args );
|
2005-09-09 01:31:10 +00:00
|
|
|
static PyObject *Lattice_getMode( BPy_Lattice * self );
|
2004-10-07 19:25:40 +00:00
|
|
|
static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args );
|
|
|
|
|
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args );
|
|
|
|
|
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args );
|
2006-08-16 14:06:24 +00:00
|
|
|
static PyObject *Lattice_copy( BPy_Lattice * self );
|
2004-10-07 19:25:40 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* 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_getName_doc[] = "() - Return Lattice Object name";
|
|
|
|
|
|
|
|
|
|
static char Lattice_setName_doc[] = "(str) - Change Lattice Object name";
|
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
2005-09-09 01:31:10 +00:00
|
|
|
static char Lattice_getKey_doc[] =
|
|
|
|
|
"() - Get the Key object attached to this Lattice";
|
|
|
|
|
|
2004-10-07 19:25:40 +00:00
|
|
|
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";
|
|
|
|
|
|
2006-08-16 14:06:24 +00:00
|
|
|
static char Lattice_copy_doc[] =
|
|
|
|
|
"() - Return a copy of the lattice.";
|
|
|
|
|
|
2004-10-07 19:25:40 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python BPy_Lattice methods table: */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
static PyMethodDef BPy_Lattice_methods[] = {
|
|
|
|
|
/* name, method, flags, doc */
|
|
|
|
|
{"getName", ( PyCFunction ) Lattice_getName, METH_NOARGS,
|
|
|
|
|
Lattice_getName_doc},
|
|
|
|
|
{"setName", ( PyCFunction ) Lattice_setName, METH_VARARGS,
|
|
|
|
|
Lattice_setName_doc},
|
|
|
|
|
{"setPartitions", ( PyCFunction ) Lattice_setPartitions, METH_VARARGS,
|
|
|
|
|
Lattice_setPartitions_doc},
|
|
|
|
|
{"getPartitions", ( PyCFunction ) Lattice_getPartitions, METH_NOARGS,
|
|
|
|
|
Lattice_getPartitions_doc},
|
2005-09-09 01:31:10 +00:00
|
|
|
{"getKey", ( PyCFunction ) Lattice_getKey, METH_NOARGS,
|
|
|
|
|
Lattice_getKey_doc},
|
2004-10-07 19:25:40 +00:00
|
|
|
{"setKeyTypes", ( PyCFunction ) Lattice_setKeyTypes, METH_VARARGS,
|
|
|
|
|
Lattice_setKeyTypes_doc},
|
|
|
|
|
{"getKeyTypes", ( PyCFunction ) Lattice_getKeyTypes, METH_NOARGS,
|
|
|
|
|
Lattice_getKeyTypes_doc},
|
|
|
|
|
{"setMode", ( PyCFunction ) Lattice_setMode, METH_VARARGS,
|
|
|
|
|
Lattice_setMode_doc},
|
|
|
|
|
{"getMode", ( PyCFunction ) Lattice_getMode, METH_NOARGS,
|
|
|
|
|
Lattice_getMode_doc},
|
|
|
|
|
{"setPoint", ( PyCFunction ) Lattice_setPoint, METH_VARARGS,
|
|
|
|
|
Lattice_setPoint_doc},
|
|
|
|
|
{"getPoint", ( PyCFunction ) Lattice_getPoint, METH_VARARGS,
|
|
|
|
|
Lattice_getPoint_doc},
|
|
|
|
|
{"insertKey", ( PyCFunction ) Lattice_insertKey, METH_VARARGS,
|
|
|
|
|
Lattice_insertKey_doc},
|
2006-08-16 14:06:24 +00:00
|
|
|
{"__copy__", ( PyCFunction ) Lattice_copy, METH_NOARGS,
|
|
|
|
|
Lattice_copy_doc},
|
2004-10-07 19:25:40 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python Lattice_Type callback function prototypes: */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
static void Lattice_dealloc( BPy_Lattice * self );
|
|
|
|
|
static int Lattice_setAttr( BPy_Lattice * self, char *name, PyObject * v );
|
|
|
|
|
static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name );
|
|
|
|
|
static PyObject *Lattice_repr( BPy_Lattice * self );
|
2006-10-06 16:48:28 +00:00
|
|
|
static int Lattice_compare( BPy_Lattice * a, BPy_Lattice * b );
|
2004-10-07 19:25:40 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python Lattice_Type structure definition: */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
PyTypeObject Lattice_Type = {
|
|
|
|
|
PyObject_HEAD_INIT( NULL )
|
|
|
|
|
0, /* ob_size */
|
|
|
|
|
"Blender Lattice", /* tp_name */
|
|
|
|
|
sizeof( BPy_Lattice ), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
|
/* methods */
|
|
|
|
|
( destructor ) Lattice_dealloc, /* tp_dealloc */
|
|
|
|
|
0, /* tp_print */
|
|
|
|
|
( getattrfunc ) Lattice_getAttr, /* tp_getattr */
|
|
|
|
|
( setattrfunc ) Lattice_setAttr, /* tp_setattr */
|
2006-10-06 16:48:28 +00:00
|
|
|
( cmpfunc ) Lattice_compare, /* tp_compare */
|
2004-10-07 19:25:40 +00:00
|
|
|
( reprfunc ) Lattice_repr, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_as_hash */
|
|
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, /* tp_doc */
|
|
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
|
BPy_Lattice_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
2005-05-20 05:14:03 +00:00
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
2004-10-07 19:25:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: Lattice_CreatePyObject
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Lattice_CreatePyObject( Lattice * lt )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
BPy_Lattice *pyLat;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
pyLat = ( BPy_Lattice * ) PyObject_NEW( BPy_Lattice, &Lattice_Type );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !pyLat )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create BPy_Lattice PyObject" );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
pyLat->Lattice = lt;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) pyLat;
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: Lattice_FromPyObject
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *Lattice_FromPyObject( PyObject * pyobj )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( ( BPy_Lattice * ) pyobj )->Lattice;
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: Lattice_CheckPyObject
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
int Lattice_CheckPyObject( PyObject * pyobj )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( pyobj->ob_type == &Lattice_Type );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
2004-09-25 20:30:40 +00:00
|
|
|
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: M_Lattice_New
|
|
|
|
|
// Python equivalent: Blender.Lattice.New
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Lattice_New( PyObject * self, PyObject * args )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
char *name = NULL;
|
|
|
|
|
char buf[21];
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *bl_Lattice; // blender Lattice object
|
|
|
|
|
PyObject *py_Lattice; // python wrapper
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
|
|
|
|
"expected string and int arguments (or nothing)" );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
bl_Lattice = add_lattice( );
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->id.us = 0;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( bl_Lattice )
|
|
|
|
|
py_Lattice = Lattice_CreatePyObject( bl_Lattice );
|
2003-11-13 04:00:59 +00:00
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't create Lattice Object in Blender" );
|
|
|
|
|
if( !py_Lattice )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create Lattice Object wrapper" );
|
|
|
|
|
|
|
|
|
|
if( name ) {
|
|
|
|
|
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
|
|
|
|
|
rename_id( &bl_Lattice->id, buf );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return py_Lattice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: M_Lattice_Get
|
|
|
|
|
// Python equivalent: Blender.Lattice.Get
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Lattice_Get( PyObject * self, PyObject * args )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *name = NULL;
|
|
|
|
|
Lattice *lat_iter;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument (or nothing)" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
lat_iter = G.main->latt.first;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( name ) { /* (name) - Search Lattice by name */
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *wanted_lat = NULL;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( ( lat_iter ) && ( wanted_lat == NULL ) ) {
|
|
|
|
|
if( strcmp( name, lat_iter->id.name + 2 ) == 0 ) {
|
|
|
|
|
wanted_lat =
|
|
|
|
|
Lattice_CreatePyObject( lat_iter );
|
|
|
|
|
}
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
lat_iter = lat_iter->id.next;
|
|
|
|
|
}
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
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 ) );
|
|
|
|
|
}
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return wanted_lat;
|
|
|
|
|
}
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
else { /* () - return a list of all Lattices in the scene */
|
|
|
|
|
int index = 0;
|
|
|
|
|
PyObject *latlist, *pyobj;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
latlist = PyList_New( BLI_countlist( &( G.main->latt ) ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( latlist == NULL )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyList" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( lat_iter ) {
|
|
|
|
|
pyobj = Lattice_CreatePyObject( lat_iter );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !pyobj )
|
|
|
|
|
return ( EXPP_ReturnPyObjError
|
|
|
|
|
( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyString" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
PyList_SET_ITEM( latlist, index, pyobj );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
lat_iter = lat_iter->id.next;
|
|
|
|
|
index++;
|
|
|
|
|
}
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( latlist );
|
|
|
|
|
}
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
2004-09-25 20:30:40 +00:00
|
|
|
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: Lattice_Init
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Lattice_Init( void )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *mod =
|
|
|
|
|
Py_InitModule3( "Blender.Lattice", M_Lattice_methods,
|
|
|
|
|
M_Lattice_doc );
|
|
|
|
|
PyObject *dict = PyModule_GetDict( mod );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
Lattice_Type.ob_type = &PyType_Type;
|
|
|
|
|
|
|
|
|
|
//Module dictionary
|
2005-11-30 08:18:06 +00:00
|
|
|
#define EXPP_ADDCONST(x) EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(LT_##x))
|
2004-09-25 20:30:40 +00:00
|
|
|
EXPP_ADDCONST( GRID );
|
|
|
|
|
EXPP_ADDCONST( OUTSIDE );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
#undef EXPP_ADDCONST
|
2005-11-30 08:18:06 +00:00
|
|
|
#define EXPP_ADDCONST(x) EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(KEY_##x))
|
2004-09-25 20:30:40 +00:00
|
|
|
EXPP_ADDCONST( LINEAR );
|
|
|
|
|
EXPP_ADDCONST( CARDINAL );
|
|
|
|
|
EXPP_ADDCONST( BSPLINE );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( mod );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Python BPy_Lattice methods:
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_getName( BPy_Lattice * self )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyString_FromString( self->Lattice->id.name + 2 );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Lattice.name attribute" );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_setName( BPy_Lattice * self, PyObject * args )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
char *name;
|
|
|
|
|
char buf[21];
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "s", &name ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
rename_id( &self->Lattice->id, buf );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2003-11-13 04:00:59 +00:00
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
int x = 0;
|
|
|
|
|
int y = 0;
|
|
|
|
|
int z = 0;
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *bl_Lattice;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int,int,int argument" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
bl_Lattice = self->Lattice;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( x < 2 || y < 2 || z < 2 )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"partition values must be 2 or greater" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2005-08-15 10:30:53 +00:00
|
|
|
resizelattice(bl_Lattice, x, y, z, NULL);
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2003-11-13 04:00:59 +00:00
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-09 01:31:10 +00:00
|
|
|
static PyObject *Lattice_getPartitions( BPy_Lattice * self )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *bl_Lattice;
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice = self->Lattice;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return Py_BuildValue( "[i,i,i]", ( int ) bl_Lattice->pntsu,
|
|
|
|
|
( int ) bl_Lattice->pntsv,
|
|
|
|
|
( int ) bl_Lattice->pntsw );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
2004-09-25 20:30:40 +00:00
|
|
|
|
2005-09-09 01:31:10 +00:00
|
|
|
static PyObject *Lattice_getKey( BPy_Lattice * self )
|
|
|
|
|
{
|
|
|
|
|
Key *key = self->Lattice->key;
|
|
|
|
|
|
|
|
|
|
if (key)
|
|
|
|
|
return Key_CreatePyObject(key);
|
|
|
|
|
else {
|
|
|
|
|
return EXPP_incr_ret(Py_None);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *Lattice_getKeyTypes( BPy_Lattice * self )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *bl_Lattice;
|
2003-11-13 04:00:59 +00:00
|
|
|
char *linear = "linear";
|
|
|
|
|
char *cardinal = "cardinal";
|
|
|
|
|
char *bspline = "bspline";
|
|
|
|
|
char *s_x = NULL, *s_y = NULL, *s_z = NULL;
|
|
|
|
|
|
|
|
|
|
bl_Lattice = self->Lattice;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( ( bl_Lattice->typeu ) == KEY_LINEAR )
|
2003-11-13 04:00:59 +00:00
|
|
|
s_x = linear;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( ( bl_Lattice->typeu ) == KEY_CARDINAL )
|
2003-11-13 04:00:59 +00:00
|
|
|
s_x = cardinal;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( ( bl_Lattice->typeu ) == KEY_BSPLINE )
|
2003-11-13 04:00:59 +00:00
|
|
|
s_x = bspline;
|
|
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"bad key type..." );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( ( bl_Lattice->typev ) == KEY_LINEAR )
|
2003-11-13 04:00:59 +00:00
|
|
|
s_y = linear;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( ( bl_Lattice->typev ) == KEY_CARDINAL )
|
2003-11-13 04:00:59 +00:00
|
|
|
s_y = cardinal;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( ( bl_Lattice->typev ) == KEY_BSPLINE )
|
2005-11-23 23:43:02 +00:00
|
|
|
s_y = bspline;
|
2003-11-13 04:00:59 +00:00
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"bad key type..." );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( ( bl_Lattice->typew ) == KEY_LINEAR )
|
2003-11-13 04:00:59 +00:00
|
|
|
s_z = linear;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( ( bl_Lattice->typew ) == KEY_CARDINAL )
|
2003-11-13 04:00:59 +00:00
|
|
|
s_z = cardinal;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( ( bl_Lattice->typew ) == KEY_BSPLINE )
|
2003-11-13 04:00:59 +00:00
|
|
|
s_z = bspline;
|
|
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"bad key type..." );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
/* we made sure no s_[xyz] is NULL */
|
2004-09-25 20:30:40 +00:00
|
|
|
return Py_BuildValue( "[s,s,s]", s_x, s_y, s_z );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_setKeyTypes( BPy_Lattice * self, PyObject * args )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
int x;
|
|
|
|
|
int y;
|
|
|
|
|
int z;
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *bl_Lattice;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int,int,int argument" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
bl_Lattice = self->Lattice;
|
2004-09-25 20:30:40 +00:00
|
|
|
|
|
|
|
|
if( x == KEY_LINEAR )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->typeu = KEY_LINEAR;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( x == KEY_CARDINAL )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->typeu = KEY_CARDINAL;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( x == KEY_BSPLINE )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->typeu = KEY_BSPLINE;
|
|
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"type must be LINEAR, CARDINAL OR BSPLINE" );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( y == KEY_LINEAR )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->typev = KEY_LINEAR;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( y == KEY_CARDINAL )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->typev = KEY_CARDINAL;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( y == KEY_BSPLINE )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->typev = KEY_BSPLINE;
|
|
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"type must be LINEAR, CARDINAL OR BSPLINE" );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( z == KEY_LINEAR )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->typew = KEY_LINEAR;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( z == KEY_CARDINAL )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->typew = KEY_CARDINAL;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( z == KEY_BSPLINE )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->typew = KEY_BSPLINE;
|
|
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"type must be LINEAR, CARDINAL OR BSPLINE" );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2003-11-13 04:00:59 +00:00
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
short type;
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *bl_Lattice;
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice = self->Lattice;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "h", &type ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( type == LT_GRID )
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->flag = LT_GRID;
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( type == LT_OUTSIDE ) {
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice->flag = LT_OUTSIDE + LT_GRID;
|
2004-09-25 20:30:40 +00:00
|
|
|
outside_lattice( bl_Lattice );
|
|
|
|
|
} else
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"type must be either GRID or OUTSIDE" );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2003-11-13 04:00:59 +00:00
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-09 01:31:10 +00:00
|
|
|
static PyObject *Lattice_getMode( BPy_Lattice * self )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
char type[24];
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *bl_Lattice;
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice = self->Lattice;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( bl_Lattice->flag & LT_GRID )
|
|
|
|
|
sprintf( type, "Grid" );
|
|
|
|
|
else if( bl_Lattice->flag & LT_OUTSIDE )
|
|
|
|
|
sprintf( type, "Outside" );
|
2003-11-13 04:00:59 +00:00
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"bad mode type..." );
|
|
|
|
|
|
2006-09-30 14:14:49 +00:00
|
|
|
return PyString_FromString( type );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
BPoint *bp, *bpoint;
|
|
|
|
|
short size;
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *bl_Lattice;
|
2003-11-13 04:00:59 +00:00
|
|
|
int index, x;
|
|
|
|
|
float tempInt;
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *listObject;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple
|
|
|
|
|
( args, "iO!", &index, &PyList_Type, &listObject ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError
|
|
|
|
|
( PyExc_TypeError, "expected int & list argument" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyList_Check( listObject ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"2nd parameter should be a python list" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !( PyList_Size( listObject ) == 3 ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"Please pass 3 parameters in the list [x,y,z]" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
//init
|
2004-09-25 20:30:40 +00:00
|
|
|
bp = 0;
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice = self->Lattice;
|
|
|
|
|
|
|
|
|
|
//get bpoints
|
2004-09-25 20:30:40 +00:00
|
|
|
bp = bl_Lattice->def;
|
|
|
|
|
|
|
|
|
|
if( bp == 0 )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
|
|
|
|
"no lattice points!" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
//calculate size of lattice
|
2004-09-25 20:30:40 +00:00
|
|
|
size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
|
|
|
|
|
|
|
|
|
|
if( index < 0 || index > size )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"index outside of lattice size!" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
//get the bpoint
|
2004-09-25 20:30:40 +00:00
|
|
|
while( index ) {
|
2003-11-13 04:00:59 +00:00
|
|
|
index--;
|
|
|
|
|
bp++;
|
|
|
|
|
}
|
|
|
|
|
bpoint = bp;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
for( x = 0; x < PyList_Size( listObject ); x++ ) {
|
|
|
|
|
if( !
|
|
|
|
|
( PyArg_Parse
|
|
|
|
|
( ( PyList_GetItem( listObject, x ) ), "f",
|
|
|
|
|
&tempInt ) ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"python list integer not parseable" );
|
2003-11-13 04:00:59 +00:00
|
|
|
bpoint->vec[x] = tempInt;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2003-11-13 04:00:59 +00:00
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
BPoint *bp, *bpoint;
|
|
|
|
|
short size;
|
2004-09-25 20:30:40 +00:00
|
|
|
Lattice *bl_Lattice;
|
2003-11-13 04:00:59 +00:00
|
|
|
int index;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "i", &index ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int argument" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
//init
|
2004-09-25 20:30:40 +00:00
|
|
|
bp = 0;
|
2003-11-13 04:00:59 +00:00
|
|
|
bl_Lattice = self->Lattice;
|
|
|
|
|
|
|
|
|
|
//get bpoints
|
2004-09-25 20:30:40 +00:00
|
|
|
bp = bl_Lattice->def;
|
|
|
|
|
|
|
|
|
|
if( bp == 0 )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
|
|
|
|
"no lattice points!" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
//calculate size of lattice
|
2004-09-25 20:30:40 +00:00
|
|
|
size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
|
|
|
|
|
|
|
|
|
|
if( index < 0 || index > size )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"index outside of lattice size!" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
//get the bpoint
|
2004-09-25 20:30:40 +00:00
|
|
|
while( index ) {
|
2003-11-13 04:00:59 +00:00
|
|
|
index--;
|
|
|
|
|
bp++;
|
|
|
|
|
}
|
|
|
|
|
bpoint = bp;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( bpoint == 0 )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"bpoint does not exist" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return Py_BuildValue( "[f,f,f]", bp->vec[0], bp->vec[1], bp->vec[2] );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
Lattice *lt;
|
2003-11-13 17:24:47 +00:00
|
|
|
int frame = -1, oldfra = -1;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "i", &frame ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int argument" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
lt = self->Lattice;
|
|
|
|
|
|
|
|
|
|
//set the current frame
|
2004-09-25 20:30:40 +00:00
|
|
|
if( frame > 0 ) {
|
2005-03-31 18:49:52 +00:00
|
|
|
frame = EXPP_ClampInt( frame, 1, MAXFRAME );
|
2003-11-13 04:00:59 +00:00
|
|
|
oldfra = G.scene->r.cfra;
|
2006-05-07 08:23:51 +00:00
|
|
|
G.scene->r.cfra = (int)frame;
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
2004-09-25 20:30:40 +00:00
|
|
|
// else just use current frame, then
|
|
|
|
|
// return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
|
|
|
|
// "frame value has to be greater than 0"));
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2005-09-26 15:34:21 +00:00
|
|
|
//insert a keybock for the lattice (1=relative)
|
|
|
|
|
insert_lattkey( lt , 1);
|
2006-03-24 21:56:29 +00:00
|
|
|
allspace(REMAKEIPO, 0);
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( frame > 0 )
|
2006-05-07 08:23:51 +00:00
|
|
|
G.scene->r.cfra = (int)oldfra;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2003-11-13 04:00:59 +00:00
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-16 14:06:24 +00:00
|
|
|
static PyObject *Lattice_copy( BPy_Lattice * self )
|
|
|
|
|
{
|
|
|
|
|
Lattice *bl_Lattice; // blender Lattice object
|
|
|
|
|
PyObject *py_Lattice; // python wrapper
|
|
|
|
|
|
|
|
|
|
bl_Lattice = copy_lattice( self->Lattice );
|
|
|
|
|
bl_Lattice->id.us = 0;
|
|
|
|
|
|
|
|
|
|
if( bl_Lattice )
|
|
|
|
|
py_Lattice = Lattice_CreatePyObject( bl_Lattice );
|
|
|
|
|
else
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't create Lattice Object in Blender" );
|
|
|
|
|
if( !py_Lattice )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create Lattice Object wrapper" );
|
|
|
|
|
|
|
|
|
|
return py_Lattice;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: Lattice_dealloc
|
|
|
|
|
// Description: This is a callback function for the BPy_Lattice type. It is
|
|
|
|
|
// the destructor function.
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
static void Lattice_dealloc( BPy_Lattice * self )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject_DEL( self );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: Lattice_getAttr
|
|
|
|
|
// Description: This is a callback function for the BPy_Lattice type. It is
|
|
|
|
|
// the function that accesses BPy_Lattice member variables and
|
|
|
|
|
// methods.
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
|
|
|
|
PyObject *attr = Py_None;
|
2006-10-09 06:19:27 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( strcmp( name, "name" ) == 0 )
|
|
|
|
|
attr = PyString_FromString( self->Lattice->id.name + 2 );
|
|
|
|
|
else if( strcmp( name, "width" ) == 0 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyInt_FromLong( self->Lattice->pntsu );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( strcmp( name, "height" ) == 0 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyInt_FromLong( self->Lattice->pntsv );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( strcmp( name, "depth" ) == 0 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyInt_FromLong( self->Lattice->pntsw );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( strcmp( name, "widthType" ) == 0 ) {
|
|
|
|
|
if( self->Lattice->typeu == 0 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Linear" );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( self->Lattice->typeu == 1 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Cardinal" );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( self->Lattice->typeu == 2 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Bspline" );
|
2003-11-13 04:00:59 +00:00
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"bad widthType..." );
|
|
|
|
|
} else if( strcmp( name, "heightType" ) == 0 ) {
|
|
|
|
|
if( self->Lattice->typev == 0 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Linear" );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( self->Lattice->typev == 1 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Cardinal" );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( self->Lattice->typev == 2 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Bspline" );
|
2003-11-13 04:00:59 +00:00
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"bad widthType..." );
|
|
|
|
|
} else if( strcmp( name, "depthType" ) == 0 ) {
|
|
|
|
|
if( self->Lattice->typew == 0 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Linear" );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( self->Lattice->typew == 1 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Cardinal" );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( self->Lattice->typew == 2 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Bspline" );
|
2003-11-13 04:00:59 +00:00
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"bad widthType..." );
|
|
|
|
|
} else if( strcmp( name, "mode" ) == 0 ) {
|
|
|
|
|
if( self->Lattice->flag == 1 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Grid" );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( self->Lattice->flag == 3 )
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyString_FromString( "Outside" );
|
2003-11-13 04:00:59 +00:00
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"bad mode..." );
|
|
|
|
|
} else if( strcmp( name, "latSize" ) == 0 ) {
|
2006-09-30 14:14:49 +00:00
|
|
|
attr = PyInt_FromLong( self->Lattice->pntsu *
|
2004-09-25 20:30:40 +00:00
|
|
|
self->Lattice->pntsv *
|
|
|
|
|
self->Lattice->pntsw );
|
2005-01-13 03:04:12 +00:00
|
|
|
} else if( strcmp( name, "users" ) == 0 ) {
|
|
|
|
|
attr = PyInt_FromLong( self->Lattice->id.us );
|
2005-09-09 01:31:10 +00:00
|
|
|
} else if( strcmp( name, "key" ) == 0 ) {
|
|
|
|
|
return Lattice_getKey(self);
|
2004-09-25 20:30:40 +00:00
|
|
|
} else if( strcmp( name, "__members__" ) == 0 )
|
2005-09-09 01:31:10 +00:00
|
|
|
attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s]", "name", "width",
|
2004-09-25 20:30:40 +00:00
|
|
|
"height", "depth", "widthType",
|
|
|
|
|
"heightType", "depthType", "mode",
|
2005-09-09 01:31:10 +00:00
|
|
|
"latSize", "users", "key" );
|
2005-01-13 03:04:12 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !attr )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyObject" ) );
|
|
|
|
|
|
|
|
|
|
if( attr != Py_None )
|
|
|
|
|
return attr; // attribute found, return its value
|
2003-11-13 04:00:59 +00:00
|
|
|
|
|
|
|
|
// not an attribute, search the methods table
|
2004-09-25 20:30:40 +00:00
|
|
|
return Py_FindMethod( BPy_Lattice_methods, ( PyObject * ) self, name );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: Lattice_setAttr
|
|
|
|
|
// Description: This is a callback function for the BPy_Lattice type. It is the
|
|
|
|
|
// function that changes Lattice Data members values. If this
|
|
|
|
|
// data is linked to a Blender Lattice, it also gets updated.
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Lattice_setAttr( BPy_Lattice * self, char *name, PyObject * value )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *valtuple;
|
2003-11-13 04:00:59 +00:00
|
|
|
PyObject *error = NULL;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
valtuple = Py_BuildValue( "(O)", value ); // the set* functions expect a tuple
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !valtuple )
|
|
|
|
|
return EXPP_ReturnIntError( PyExc_MemoryError,
|
|
|
|
|
"LatticeSetAttr: couldn't create PyTuple" );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( strcmp( name, "name" ) == 0 )
|
|
|
|
|
error = Lattice_setName( self, valtuple );
|
|
|
|
|
else { // Error: no such member in the Lattice Data structure
|
2005-06-17 05:10:14 +00:00
|
|
|
/*Py_DECREF( value ); borrowed reference, no need to decref */
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( valtuple );
|
|
|
|
|
return ( EXPP_ReturnIntError( PyExc_KeyError,
|
|
|
|
|
"attribute not found or immutable" ) );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( valtuple );
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( error != Py_None )
|
|
|
|
|
return -1;
|
2003-11-13 04:00:59 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return 0; // normal exit
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-06 16:48:28 +00:00
|
|
|
|
|
|
|
|
static int Lattice_compare( BPy_Lattice * a, BPy_Lattice * b )
|
|
|
|
|
{
|
|
|
|
|
return ( a->Lattice == b->Lattice ) ? 0 : -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
// Function: Lattice_repr
|
|
|
|
|
// Description: This is a callback function for the BPy_Lattice type. It
|
|
|
|
|
// builds a meaninful string to represent Lattice objects.
|
2003-11-13 04:00:59 +00:00
|
|
|
//***************************************************************************
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Lattice_repr( BPy_Lattice * self )
|
2003-11-13 04:00:59 +00:00
|
|
|
{
|
2006-10-09 06:19:27 +00:00
|
|
|
if( self->Lattice )
|
2004-09-25 20:30:40 +00:00
|
|
|
return PyString_FromFormat( "[Lattice \"%s\"]",
|
|
|
|
|
self->Lattice->id.name + 2 );
|
2003-11-13 04:00:59 +00:00
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return PyString_FromString( "[Lattice <deleted>]" );
|
2003-11-13 04:00:59 +00:00
|
|
|
}
|