Lattice.c was looping through all lattice data to check that it wasnt removed.

No other BPyModules do this and zero user lattices are kept so this check is not needed.

removed lattice.applyDeform(), this called object_apply_deform, which only gave a message to use modifiers.

changed the example in epydocs to apply the lattice using modifiers.
This commit is contained in:
2006-10-09 06:19:27 +00:00
parent 27dc45ba24
commit 0933418617
2 changed files with 29 additions and 145 deletions

View File

@@ -97,7 +97,6 @@ static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args );
static PyObject *Lattice_getMode( BPy_Lattice * self );
static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args );
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args );
static PyObject *Lattice_applyDeform( BPy_Lattice * self, PyObject *args );
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args );
static PyObject *Lattice_copy( BPy_Lattice * self );
@@ -136,14 +135,6 @@ static char Lattice_setPoint_doc[] =
static char Lattice_getPoint_doc[] =
"(str) - Get the coordinates of a point on the lattice";
static char Lattice_applyDeform_doc[] =
"(force = False) - Apply the new lattice deformation to children\n\n\
(force = False) - if given and True, children of mesh type are not ignored.\n\
Meshes are treated differently in Blender, deformation is stored directly in\n\
their vertices when first redrawn (ex: with Blender.Redraw) after getting a\n\
Lattice parent, without needing this method (except for command line bg\n\
mode). If forced, the deformation will be applied over any previous one(s).";
static char Lattice_insertKey_doc[] =
"(str) - Set a new key for the lattice at specified frame";
@@ -177,8 +168,6 @@ static PyMethodDef BPy_Lattice_methods[] = {
Lattice_setPoint_doc},
{"getPoint", ( PyCFunction ) Lattice_getPoint, METH_VARARGS,
Lattice_getPoint_doc},
{"applyDeform", ( PyCFunction ) Lattice_applyDeform, METH_VARARGS,
Lattice_applyDeform_doc},
{"insertKey", ( PyCFunction ) Lattice_insertKey, METH_VARARGS,
Lattice_insertKey_doc},
{"__copy__", ( PyCFunction ) Lattice_copy, METH_NOARGS,
@@ -223,9 +212,6 @@ PyTypeObject Lattice_Type = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
static int Lattice_InLatList( BPy_Lattice * self );
static int Lattice_IsLinkedToObject( BPy_Lattice * self );
//***************************************************************************
// Function: Lattice_CreatePyObject
@@ -700,50 +686,6 @@ static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args )
return Py_BuildValue( "[f,f,f]", bp->vec[0], bp->vec[1], bp->vec[2] );
}
//This function will not do anything if there are no children
static PyObject *Lattice_applyDeform( BPy_Lattice * self, PyObject *args )
{
//Object* ob; unused
Base *base;
Object *par = NULL;
int forced = 0;
if( !Lattice_IsLinkedToObject( self ) )
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"Lattice must be linked to an object to apply it's deformation!" ) );
if( !PyArg_ParseTuple( args, "|i", &forced ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected nothing or True or False argument" ) );
/* deform children */
base = FIRSTBASE;
while( base ) {
par = base->object->parent;
if( par != NULL ) { /* check/assign if ob has parent */
/* meshes have their mverts deformed, others ob types use displist,
* so we're not doing meshes here (unless forced), or else they get
* deformed twice, since parenting a Lattice to an object and redrawing
* already applies lattice deformation. 'forced' is useful for
* command line background mode, when no redraws occur and so this
* method is needed. Or for users who actually want to apply the
* deformation n times. */
if((self->Lattice == par->data)) {
/* I do not know what to do with this function
* at the moment given the changing modifier system.
* Calling into the modifier system in the first place
* isn't great... -zr
*/
object_apply_deform(base->object);
}
}
base = base->next;
}
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args )
{
Lattice *lt;
@@ -815,11 +757,7 @@ static void Lattice_dealloc( BPy_Lattice * self )
static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name )
{
PyObject *attr = Py_None;
if( !self->Lattice || !Lattice_InLatList( self ) )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"Lattice was already deleted!" );
if( strcmp( name, "name" ) == 0 )
attr = PyString_FromString( self->Lattice->id.name + 2 );
else if( strcmp( name, "width" ) == 0 )
@@ -902,10 +840,6 @@ static int Lattice_setAttr( BPy_Lattice * self, char *name, PyObject * value )
PyObject *valtuple;
PyObject *error = NULL;
if( !self->Lattice || !Lattice_InLatList( self ) )
return EXPP_ReturnIntError( PyExc_RuntimeError,
"Lattice was already deleted!" );
valtuple = Py_BuildValue( "(O)", value ); // the set* functions expect a tuple
if( !valtuple )
@@ -942,44 +876,9 @@ static int Lattice_compare( BPy_Lattice * a, BPy_Lattice * b )
//***************************************************************************
static PyObject *Lattice_repr( BPy_Lattice * self )
{
if( self->Lattice && Lattice_InLatList( self ) )
if( self->Lattice )
return PyString_FromFormat( "[Lattice \"%s\"]",
self->Lattice->id.name + 2 );
else
return PyString_FromString( "[Lattice <deleted>]" );
}
//***************************************************************************
// Function: Internal Lattice functions
//***************************************************************************
// Internal function to confirm if a Lattice wasn't unlinked from main.
static int Lattice_InLatList( BPy_Lattice * self )
{
Lattice *lat_iter = G.main->latt.first;
while( lat_iter ) {
if( self->Lattice == lat_iter )
return 1; // ok, still linked
lat_iter = lat_iter->id.next;
}
// uh-oh, it was already deleted
self->Lattice = NULL; // so we invalidate the pointer
return 0;
}
// Internal function to confirm if a Lattice has an object it's linked to.
static int Lattice_IsLinkedToObject( BPy_Lattice * self )
{
//check to see if lattice is linked to an object
Object *ob = G.main->object.first;
while( ob ) {
if( ob->type == OB_LATTICE ) {
if( self->Lattice == ob->data ) {
return 1;
}
}
ob = ob->id.next;
}
return 0;
}

View File

@@ -9,34 +9,38 @@ Lattice Object
This module provides access to B{Lattice} object in Blender.
Example::
import Blender
from Blender import Lattice
from Blender.Lattice import *
from Blender import Object
from Blender import Scene
import Blender
from Blender import Lattice, Object, Scene, Modifier
myOb = Object.New('Lattice')
myLat = Lattice.New()
myLat.setPartitions(5,5,5)
myLat.setKeyTypes(LINEAR, CARDINAL, BSPLINE)
myLat.setMode(OUTSIDE)
# Make new lattice data
ob_lattice = Object.New('Lattice')
lattice_data = Lattice.New()
lattice_data.setPartitions(5,5,5)
lattice_data.setKeyTypes(Lattice.LINEAR, Lattice.CARDINAL, Lattice.BSPLINE)
lattice_data.setMode(Lattice.OUTSIDE)
for y in range(125):
vec = myLat.getPoint(y)
co1 = vec[0] + vec[0] / 5
co2 = vec[1] - vec[2] * 0.3
co3 = vec[2] * 3
myLat.setPoint(y,[co1,co2,co3])
for y in range(125):
vec = lattice_data.getPoint(y)
co1 = vec[0] + vec[0] / 5
co2 = vec[1] - vec[2] * 0.3
co3 = vec[2] * 3
lattice_data.setPoint(y,[co1,co2,co3])
myOb.link(myLat)
mySphere = Object.Get('Sphere')
myOb.makeParent([mySphere])
# Link the data to an object
ob_lattice.link(lattice_data)
myLat.applyDeform()
# Get an object to deform with this lattice
mySphere = Object.Get('Sphere')
sc = Scene.getCurrent()
sc.link(myOb)
Blender.Redraw()
scn = Scene.getCurrent()
scn.link(ob_lattice)
# Apply lattice modifier
mod= mySphere.modifiers.append(Modifier.Type.LATTICE)
mod[Modifier.Settings.OBJECT] = ob_lattice
mySphere.makeDisplayList()
Blender.Redraw()
"""
def New (name = None):
@@ -172,24 +176,6 @@ class Lattice:
@param position: The x,y,z coordinates that you want the point to be: [x,y,z]
"""
def applyDeform(force = False):
"""
@type force: bool
@param force: if True, meshes are not ignored.
Applies the current Lattice deformation to any child objects that have this
Lattice as the parent.
@note: simply parenting to a Lattice and redrawing the screen is enough to
get the deformation done, this applyDeform method is useful when the
script won't call a redraw, like in command line background (GUI-less)
mode.
@note: by default, this method doesn't apply deformations to meshes. This
is because unlike other kinds of objects, meshes store lattice
deformation directly in their vertices and calling this applyDeform
method will apply the deformation a second time, giving double
deformation, which can be a feature (set force = True if you want it) or
much probably an undesired effect.
"""
def getKey():
"""
Returns the L{Key.Key} object associated with this Lattice.
@@ -211,7 +197,6 @@ class Lattice:
myLat.setPoint(y,[co1,co2,co3])
w = (z + 1) * 10
myLat.insertKey(w)
myLat.applyDeform()
@type frame: int
@param frame: the frame at which the Lattice will be set as a keyframe