forked from bartvdbraak/blender
Arnaure.Get() now raises an error when the name dosnt exist. added warning in docs.
Image - added img.fields, img.fields_odd, img.antialias, also updated the docs. replaced Py_BuildValue with faster list creation for getPixel functions.
This commit is contained in:
parent
080ecf33c1
commit
ed47053fa6
@ -1270,7 +1270,11 @@ static PyObject *M_Armature_Get(PyObject * self, PyObject * args)
|
||||
if (data != NULL){
|
||||
return PyArmature_FromArmature(data); //*new*
|
||||
}else{
|
||||
return EXPP_incr_ret(Py_None);
|
||||
char buffer[128];
|
||||
PyOS_snprintf( buffer, sizeof(buffer),
|
||||
"Armature \"%s\" not found", name);
|
||||
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
||||
buffer );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -378,14 +378,19 @@ static PyObject *M_Image_Load( PyObject * self, PyObject * args )
|
||||
static PyObject *Image_getPixelF( BPy_Image * self, PyObject * args )
|
||||
{
|
||||
|
||||
PyObject *attr;
|
||||
PyObject *attr = PyList_New(4);
|
||||
ImBuf *ibuf= BKE_image_get_ibuf(self->image, NULL);
|
||||
char *pixel; /* image data */
|
||||
int index; /* offset into image data */
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int pixel_size = 4; /* each pixel is 4 x 8-bits packed in unsigned int */
|
||||
int i;
|
||||
|
||||
if (!attr)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't allocate memory for color list" );
|
||||
|
||||
if( !PyArg_ParseTuple( args, "ii", &x, &y ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected 2 integers" );
|
||||
@ -412,17 +417,10 @@ static PyObject *Image_getPixelF( BPy_Image * self, PyObject * args )
|
||||
index = ( x + y * ibuf->x ) * pixel_size;
|
||||
|
||||
pixel = ( char * ) ibuf->rect;
|
||||
attr = Py_BuildValue( "[f,f,f,f]",
|
||||
( ( float ) pixel[index] ) / 255.0,
|
||||
( ( float ) pixel[index + 1] ) / 255.0,
|
||||
( ( float ) pixel[index + 2] ) / 255.0,
|
||||
( ( float ) pixel[index + 3] / 255.0 ) );
|
||||
|
||||
if( attr ) /* normal return */
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't get pixel colors" );
|
||||
for (i=0; i<4; i++) {
|
||||
PyList_SetItem( attr, i, PyFloat_FromDouble( ( ( double ) pixel[index+i] ) / 255.0 ));
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
|
||||
|
||||
@ -435,14 +433,19 @@ static PyObject *Image_getPixelF( BPy_Image * self, PyObject * args )
|
||||
|
||||
static PyObject *Image_getPixelI( BPy_Image * self, PyObject * args )
|
||||
{
|
||||
PyObject *attr;
|
||||
PyObject *attr = PyList_New(4);
|
||||
ImBuf *ibuf= BKE_image_get_ibuf(self->image, NULL);
|
||||
char *pixel; /* image data */
|
||||
int index; /* offset into image data */
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int pixel_size = 4; /* each pixel is 4 x 8-bits packed in unsigned int */
|
||||
int i;
|
||||
|
||||
if (!attr)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't allocate memory for color list" );
|
||||
|
||||
if( !PyArg_ParseTuple( args, "ii", &x, &y ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected 2 integers" );
|
||||
@ -467,18 +470,12 @@ static PyObject *Image_getPixelI( BPy_Image * self, PyObject * args )
|
||||
*/
|
||||
|
||||
index = ( x + y * ibuf->x ) * pixel_size;
|
||||
|
||||
pixel = ( char * ) ibuf->rect;
|
||||
attr = Py_BuildValue( "[i,i,i,i]",
|
||||
pixel[index],
|
||||
pixel[index + 1],
|
||||
pixel[index + 2], pixel[index + 3] );
|
||||
|
||||
if( attr ) /* normal return */
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't get pixel colors" );
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
PyList_SetItem( attr, i, PyInt_FromLong( pixel[index+i] ));
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
|
||||
|
||||
@ -831,19 +828,20 @@ static PyObject *Image_getFilename( BPy_Image * self )
|
||||
static PyObject *Image_getSize( BPy_Image * self )
|
||||
{
|
||||
ImBuf *ibuf= BKE_image_get_ibuf(self->image, NULL);
|
||||
PyObject *attr;
|
||||
PyObject *attr = PyList_New(2);
|
||||
|
||||
if( !ibuf ) /* didn't work */
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't load image data in Blender" );
|
||||
|
||||
attr = Py_BuildValue( "[hh]", ibuf->x, ibuf->y );
|
||||
|
||||
if( attr )
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
if( !attr )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't get Image.size attribute" );
|
||||
|
||||
PyList_SetItem( attr, 0, PyInt_FromLong(ibuf->x));
|
||||
PyList_SetItem( attr, 1, PyInt_FromLong(ibuf->y));
|
||||
return attr;
|
||||
|
||||
|
||||
}
|
||||
|
||||
static PyObject *Image_getDepth( BPy_Image * self )
|
||||
@ -1143,25 +1141,37 @@ static PyObject *Image_getAttr( BPy_Image * self, char *name )
|
||||
else if( strcmp( name, "speed" ) == 0 )
|
||||
attr = PyInt_FromLong( self->image->animspeed );
|
||||
else if( strcmp( name, "packed" ) == 0 ) {
|
||||
if (self->image->packedfile)
|
||||
attr = EXPP_incr_ret_True();
|
||||
else
|
||||
attr = EXPP_incr_ret_False();
|
||||
if (self->image->packedfile) attr = Py_True;
|
||||
else attr = Py_False;
|
||||
EXPP_incr_ret(attr);
|
||||
} else if( strcmp( name, "has_data" ) == 0 ) {
|
||||
if (self->image->ibufs.first)
|
||||
attr = EXPP_incr_ret_True();
|
||||
else
|
||||
attr = EXPP_incr_ret_False();
|
||||
if (self->image->ibufs.first) attr = Py_True;
|
||||
else attr = Py_False;
|
||||
EXPP_incr_ret(attr);
|
||||
} else if( strcmp( name, "fields" ) == 0 ) {
|
||||
if (self->image->flag & IMA_FIELDS) attr = Py_True;
|
||||
else attr = Py_False;
|
||||
EXPP_incr_ret(attr);
|
||||
} else if( strcmp( name, "fields_odd" ) == 0 ) {
|
||||
if (self->image->flag & IMA_STD_FIELD) attr = Py_True;
|
||||
else attr = Py_False;
|
||||
EXPP_incr_ret(attr);
|
||||
} else if( strcmp( name, "antialias" ) == 0 ) {
|
||||
if (self->image->flag & IMA_ANTIALI) attr = Py_True;
|
||||
else attr = Py_False;
|
||||
EXPP_incr_ret(attr);
|
||||
|
||||
} else if( strcmp( name, "bindcode" ) == 0 )
|
||||
attr = PyInt_FromLong( self->image->bindcode );
|
||||
else if( strcmp( name, "users" ) == 0 )
|
||||
attr = PyInt_FromLong( self->image->id.us );
|
||||
else if( strcmp( name, "__members__" ) == 0 )
|
||||
attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s,s]",
|
||||
attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]",
|
||||
"name", "filename", "size", "depth",
|
||||
"xrep", "yrep", "start", "end",
|
||||
"speed", "packed", "has_data"
|
||||
"bindcode", "users" );
|
||||
"fields", "odd", "antialias",
|
||||
"bindcode", "users" );
|
||||
|
||||
if( !attr )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
@ -1210,7 +1220,38 @@ static int Image_setAttr( BPy_Image * self, char *name, PyObject * value )
|
||||
error = Image_setEnd( self, valtuple );
|
||||
else if( strcmp( name, "speed" ) == 0 )
|
||||
error = Image_setSpeed( self, valtuple );
|
||||
else { /* Error: no such member in the Image object structure */
|
||||
|
||||
else if( strcmp( name, "fields" ) == 0 ) {
|
||||
int param = PyObject_IsTrue( value );
|
||||
if( param == -1 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected true/false argument" );
|
||||
|
||||
if (param) self->image->flag |= IMA_FIELDS;
|
||||
else self->image->flag &= ~IMA_FIELDS;
|
||||
Py_INCREF( Py_None );
|
||||
error = Py_None;
|
||||
} else if( strcmp( name, "fields_odd" ) == 0 ) {
|
||||
int param = PyObject_IsTrue( value );
|
||||
if( param == -1 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected true/false argument" );
|
||||
|
||||
if (param) self->image->flag |= IMA_STD_FIELD;
|
||||
else self->image->flag &= ~IMA_STD_FIELD;
|
||||
Py_INCREF( Py_None );
|
||||
error = Py_None;
|
||||
} else if( strcmp( name, "antialias" ) == 0 ) {
|
||||
int param = PyObject_IsTrue( value );
|
||||
if( param == -1 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected true/false argument" );
|
||||
|
||||
if (param) self->image->flag |= IMA_ANTIALI;
|
||||
else self->image->flag &= ~IMA_ANTIALI;
|
||||
Py_INCREF( Py_None );
|
||||
error = Py_None;
|
||||
} else { /* Error: no such member in the Image object structure */
|
||||
/*Py_DECREF( value ); borrowed ref, no need to decref */
|
||||
Py_DECREF( valtuple );
|
||||
return ( EXPP_ReturnIntError( PyExc_KeyError,
|
||||
|
@ -12,21 +12,21 @@ example.
|
||||
|
||||
Example::
|
||||
import Blender
|
||||
from Blender import Armature as A
|
||||
from Blender import Armature
|
||||
from Blender.Mathutils import *
|
||||
#
|
||||
arms = A.Get()
|
||||
arms = Armature.Get()
|
||||
for arm in arms.values():
|
||||
arm.drawType = A.STICK #set the draw type
|
||||
arm.drawType = Armature.STICK #set the draw type
|
||||
arm.makeEditable() #enter editmode
|
||||
|
||||
#generating new editbone
|
||||
eb = A.Editbone()
|
||||
eb = Armature.Editbone()
|
||||
eb.roll = 10
|
||||
eb.parent = arm.bones['Bone.003']
|
||||
eb.head = Vector(1,1,1)
|
||||
eb.tail = Vector(0,0,1)
|
||||
eb.options = [A.HINGE, A.CONNECTED]
|
||||
eb.options = [Armature.HINGE, Armature.CONNECTED]
|
||||
|
||||
#add the bone
|
||||
arm.bones['myNewBone'] = eb
|
||||
@ -48,15 +48,16 @@ Example::
|
||||
from Blender import *
|
||||
def test_arm():
|
||||
scn= Scene.GetCurrent()
|
||||
arm_ob= scn.getActiveObject()
|
||||
arm_ob= scn.objects.active
|
||||
|
||||
if not arm_ob or arm_ob.getType() != 'Armature':
|
||||
if not arm_ob or arm_ob.type != 'Armature':
|
||||
Draw.PupMenu('not an armature object')
|
||||
return
|
||||
|
||||
# Deselect all
|
||||
for ob in scn.getChildren():
|
||||
ob.sel= 0
|
||||
for ob in scn.objects:
|
||||
if ob != arm_ob:
|
||||
ob.sel= 0
|
||||
|
||||
arm_mat= arm_ob.matrixWorld
|
||||
|
||||
@ -67,14 +68,8 @@ Example::
|
||||
bone_mat= bone.matrix['ARMATURESPACE']
|
||||
bone_mat_world= bone_mat*arm_mat
|
||||
|
||||
ob_empty= Object.New('Empty', bone.name)
|
||||
scn.link(ob_empty)
|
||||
ob_empty= scn.objects.new('Empty')
|
||||
ob_empty.setMatrix(bone_mat_world)
|
||||
ob_empty.sel= 1
|
||||
|
||||
# Select then de-select keeps us active
|
||||
arm_ob.sel= 1
|
||||
arm_ob.sel= 0
|
||||
|
||||
test_arm()
|
||||
|
||||
@ -114,6 +109,8 @@ def Get (name = None):
|
||||
- (name): The Armature object with the given I{name};
|
||||
- (name, name, ...): A list of Armature objects
|
||||
- (): A list with all Armature objects in the current scene.
|
||||
@warning: a string argument for an armature that dosnt exist in 2.42 will return None.
|
||||
later versions raise a value error.
|
||||
"""
|
||||
|
||||
def New (name = None):
|
||||
|
@ -75,20 +75,38 @@ class Image:
|
||||
image's ID Properties.
|
||||
@type properties: L{IDGroup<IDProp.IDGroup>}
|
||||
@ivar name: The name of this Image object.
|
||||
@type name: string
|
||||
@ivar filename: The filename (path) to the image file loaded into this Image
|
||||
object.
|
||||
@type filename: string
|
||||
@ivar size: The [width, height] dimensions of the image (in pixels).
|
||||
@ivar depth: The pixel depth of the image.
|
||||
@type size: list
|
||||
@ivar depth: The pixel depth of the image. [8, 16, 18, 24, 32]
|
||||
@type depth: int
|
||||
@ivar xrep: Texture tiling: the number of repetitions in the x (horizontal)
|
||||
axis.
|
||||
axis. [1, 16].
|
||||
@ivar yrep: Texture tiling: the number of repetitions in the y (vertical)
|
||||
axis.
|
||||
axis [1, 16].
|
||||
@type xrep: int
|
||||
@type yrep: int
|
||||
@ivar start: Texture's animation start frame [0, 128].
|
||||
@type start: int
|
||||
@ivar end: Texture's animation end frame [0, 128].
|
||||
@type end: int
|
||||
@ivar speed: Texture's animation speed [1, 100].
|
||||
@ivar packed: Boolean, True when the Texture is packed (readonly).
|
||||
@ivar has_data: Boolean, True when the image has pixel data (readonly).
|
||||
@type speed: int
|
||||
@ivar packed: True when the Texture is packed (readonly).
|
||||
@type packed: boolean
|
||||
@ivar has_data: True when the image has pixel data (readonly).
|
||||
@type has_data: boolean
|
||||
@ivar fields: enable or disable the fields option for this image.
|
||||
@type fields: boolean
|
||||
@ivar fields_odd: enable or disable the odd fields option for this image.
|
||||
@type fields_odd: boolean
|
||||
@ivar antialias: enable or disable the antialias option for this image.
|
||||
@type antialias: boolean
|
||||
@ivar bindcode: Texture's bind code (readonly).
|
||||
@type bindcode: int
|
||||
"""
|
||||
|
||||
def getName():
|
||||
|
Loading…
Reference in New Issue
Block a user