2003-04-08 19:54:14 +00:00
|
|
|
/*
|
2004-05-25 10:36:58 +00:00
|
|
|
* $Id$
|
2003-04-08 19:54:14 +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,
|
2004-05-25 10:36:58 +00:00
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2003-04-08 19:54:14 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This is a new part of Blender.
|
|
|
|
|
*
|
2005-02-02 03:38:31 +00:00
|
|
|
* Contributor(s): Willian P. Germano, Campbell Barton, Joilnen B. Leite
|
2003-04-08 19:54:14 +00:00
|
|
|
*
|
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
#include <BDR_drawmesh.h> /* free_realtime_image */
|
2003-05-31 04:43:10 +00:00
|
|
|
#include <BKE_main.h>
|
|
|
|
|
#include <BKE_global.h>
|
|
|
|
|
#include <BKE_library.h>
|
|
|
|
|
#include <BKE_image.h>
|
2004-05-25 10:36:58 +00:00
|
|
|
#include <BIF_drawimage.h>
|
2003-05-31 04:43:10 +00:00
|
|
|
#include <BLI_blenlib.h>
|
2005-02-09 15:53:35 +00:00
|
|
|
#include <DNA_space_types.h> /* FILE_MAXDIR = 160 */
|
2004-09-25 20:30:40 +00:00
|
|
|
#include <IMB_imbuf_types.h> /* for the IB_rect define */
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
#include <BIF_gl.h>
|
2003-05-31 04:43:10 +00:00
|
|
|
#include "gen_utils.h"
|
|
|
|
|
|
2003-04-08 19:54:14 +00:00
|
|
|
#include "Image.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-05-25 10:36:58 +00:00
|
|
|
/* Python BPy_Image defaults: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-05-25 10:36:58 +00:00
|
|
|
#define EXPP_IMAGE_REP 1
|
|
|
|
|
#define EXPP_IMAGE_REP_MIN 1
|
2003-05-31 04:43:10 +00:00
|
|
|
#define EXPP_IMAGE_REP_MAX 16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************/
|
|
|
|
|
/*** The Image Module ***/
|
|
|
|
|
/************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python API function prototypes for the Image module. */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2005-02-09 15:53:35 +00:00
|
|
|
/*static PyObject *M_Image_New( PyObject * self, PyObject * args,
|
|
|
|
|
PyObject * keywords );*/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Image_Get( PyObject * self, PyObject * args );
|
|
|
|
|
static PyObject *M_Image_Load( PyObject * self, PyObject * args );
|
2003-05-31 04:43:10 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* The following string definitions are used for documentation strings. */
|
|
|
|
|
/* In Python these will be written to the console when doing a */
|
|
|
|
|
/* Blender.Image.__doc__ */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static char M_Image_doc[] = "The Blender Image module\n\n";
|
2003-05-31 04:43:10 +00:00
|
|
|
|
2005-02-09 15:53:35 +00:00
|
|
|
/*static char M_Image_New_doc[] =
|
|
|
|
|
"() - return a new Image object -- unimplemented";*/
|
2003-05-31 04:43:10 +00:00
|
|
|
|
|
|
|
|
static char M_Image_Get_doc[] =
|
2004-09-25 20:30:40 +00:00
|
|
|
"(name) - return the image with the name 'name', \
|
2003-05-31 04:43:10 +00:00
|
|
|
returns None if not found.\n If 'name' is not specified, \
|
|
|
|
|
it returns a list of all images in the\ncurrent scene.";
|
|
|
|
|
|
|
|
|
|
static char M_Image_Load_doc[] =
|
2004-09-25 20:30:40 +00:00
|
|
|
"(filename) - return image from file filename as Image Object, \
|
2003-05-31 04:43:10 +00:00
|
|
|
returns None if not found.\n";
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python method structure definition for Blender.Image module: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
struct PyMethodDef M_Image_methods[] = {
|
2005-02-09 15:53:35 +00:00
|
|
|
/*{"New", ( PyCFunction ) M_Image_New, METH_VARARGS | METH_KEYWORDS,
|
|
|
|
|
M_Image_New_doc},*/
|
2004-09-25 20:30:40 +00:00
|
|
|
{"Get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
|
|
|
|
{"get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
|
|
|
|
{"Load", M_Image_Load, METH_VARARGS, M_Image_Load_doc},
|
2004-05-25 10:36:58 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
2003-05-31 04:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2005-02-09 15:53:35 +00:00
|
|
|
/* Function: M_Image_New (unimplemented) */
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python equivalent: Blender.Image.New */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2005-02-09 15:53:35 +00:00
|
|
|
/*static PyObject *M_Image_New( PyObject * self, PyObject * args,
|
|
|
|
|
PyObject * keywords )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2004-05-25 10:36:58 +00:00
|
|
|
return Py_None;
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
2005-02-09 15:53:35 +00:00
|
|
|
*/
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: M_Image_Get */
|
|
|
|
|
/* Python equivalent: Blender.Image.Get */
|
|
|
|
|
/* Description: Receives a string and returns the image object */
|
|
|
|
|
/* whose name matches the string. If no argument is */
|
|
|
|
|
/* passed in, a list of all image names in the */
|
|
|
|
|
/* current scene is returned. */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Image_Get( PyObject * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *name = NULL;
|
2004-05-25 10:36:58 +00:00
|
|
|
Image *img_iter;
|
2003-04-08 19:54:14 +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-04-08 19:54:14 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
img_iter = G.main->image.first;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( name ) { /* (name) - Search image by name */
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
BPy_Image *wanted_image = NULL;
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( ( img_iter ) && ( wanted_image == NULL ) ) {
|
|
|
|
|
if( strcmp( name, img_iter->id.name + 2 ) == 0 ) {
|
|
|
|
|
wanted_image =
|
|
|
|
|
( BPy_Image * )
|
|
|
|
|
PyObject_NEW( BPy_Image, &Image_Type );
|
|
|
|
|
if( wanted_image )
|
|
|
|
|
wanted_image->image = img_iter;
|
2004-05-25 10:36:58 +00:00
|
|
|
}
|
|
|
|
|
img_iter = img_iter->id.next;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( wanted_image == NULL ) { /* Requested image doesn't exist */
|
2004-05-25 10:36:58 +00:00
|
|
|
char error_msg[64];
|
2004-09-25 20:30:40 +00:00
|
|
|
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
|
|
|
|
"Image \"%s\" not found", name );
|
|
|
|
|
return ( EXPP_ReturnPyObjError
|
|
|
|
|
( PyExc_NameError, error_msg ) );
|
2004-05-25 10:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) wanted_image;
|
2003-05-13 01:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
else { /* () - return a list of all images in the scene */
|
2004-05-25 10:36:58 +00:00
|
|
|
int index = 0;
|
|
|
|
|
PyObject *img_list, *pyobj;
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
img_list = PyList_New( BLI_countlist( &( G.main->image ) ) );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( img_list == NULL )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyList" ) );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( img_iter ) {
|
|
|
|
|
pyobj = Image_CreatePyObject( img_iter );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !pyobj )
|
|
|
|
|
return ( EXPP_ReturnPyObjError
|
|
|
|
|
( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyObject" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
PyList_SET_ITEM( img_list, index, pyobj );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
img_iter = img_iter->id.next;
|
|
|
|
|
index++;
|
2003-05-13 01:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( img_list );
|
2003-05-13 01:54:28 +00:00
|
|
|
}
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-13 01:54:28 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: M_Image_Load */
|
|
|
|
|
/* Python equivalent: Blender.Image.Load */
|
|
|
|
|
/* Description: Receives a string and returns the image object */
|
|
|
|
|
/* whose filename matches the string. */
|
2003-05-13 01:54:28 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Image_Load( PyObject * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *fname;
|
|
|
|
|
Image *img_ptr;
|
2004-05-25 10:36:58 +00:00
|
|
|
BPy_Image *img;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "s", &fname ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument" ) );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
img = ( BPy_Image * ) PyObject_NEW( BPy_Image, &Image_Type );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !img )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyObject Image_Type" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
img_ptr = add_image( fname );
|
|
|
|
|
if( !img_ptr )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_IOError,
|
|
|
|
|
"couldn't load image" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
img->image = img_ptr;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) img;
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_Init */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Image_Init( void )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *submodule;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
Image_Type.ob_type = &PyType_Type;
|
2003-06-02 20:15:50 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
submodule =
|
|
|
|
|
Py_InitModule3( "Blender.Image", M_Image_methods,
|
|
|
|
|
M_Image_doc );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( submodule );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-31 04:43:10 +00:00
|
|
|
/************************/
|
|
|
|
|
/*** The Image PyType ***/
|
|
|
|
|
/************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Image methods declarations: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getName( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getFilename( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getSize( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getDepth( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getXRep( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getYRep( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getBindCode( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_setName( BPy_Image * self, PyObject * args );
|
2005-02-09 05:19:24 +00:00
|
|
|
static PyObject *Image_setFilename( BPy_Image * self, PyObject * args );
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_setXRep( BPy_Image * self, PyObject * args );
|
|
|
|
|
static PyObject *Image_setYRep( BPy_Image * self, PyObject * args );
|
|
|
|
|
static PyObject *Image_reload( BPy_Image * self ); /* by Campbell */
|
|
|
|
|
static PyObject *Image_glLoad( BPy_Image * self );
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
static PyObject *Image_glFree( BPy_Image * self );
|
2003-05-31 04:43:10 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Image methods table: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2003-06-28 07:38:21 +00:00
|
|
|
static PyMethodDef BPy_Image_methods[] = {
|
2004-09-25 20:30:40 +00:00
|
|
|
/* name, method, flags, doc */
|
|
|
|
|
{"getName", ( PyCFunction ) Image_getName, METH_NOARGS,
|
|
|
|
|
"() - Return Image object name"},
|
|
|
|
|
{"getFilename", ( PyCFunction ) Image_getFilename, METH_NOARGS,
|
|
|
|
|
"() - Return Image object filename"},
|
|
|
|
|
{"getSize", ( PyCFunction ) Image_getSize, METH_NOARGS,
|
|
|
|
|
"() - Return Image object [width, height] dimension in pixels"},
|
|
|
|
|
{"getDepth", ( PyCFunction ) Image_getDepth, METH_NOARGS,
|
|
|
|
|
"() - Return Image object pixel depth"},
|
|
|
|
|
{"getXRep", ( PyCFunction ) Image_getXRep, METH_NOARGS,
|
|
|
|
|
"() - Return Image object x repetition value"},
|
|
|
|
|
{"getYRep", ( PyCFunction ) Image_getYRep, METH_NOARGS,
|
|
|
|
|
"() - Return Image object y repetition value"},
|
|
|
|
|
{"getBindCode", ( PyCFunction ) Image_getBindCode, METH_NOARGS,
|
|
|
|
|
"() - Return Image object's bind code value"},
|
|
|
|
|
{"reload", ( PyCFunction ) Image_reload, METH_NOARGS,
|
|
|
|
|
"() - Reload the image from the filesystem"},
|
|
|
|
|
{"glLoad", ( PyCFunction ) Image_glLoad, METH_NOARGS,
|
|
|
|
|
"() - Load the image data in OpenGL texture memory.\n\
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
The bindcode (int) is returned."},
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
{"glFree", ( PyCFunction ) Image_glFree, METH_NOARGS,
|
|
|
|
|
"() - Free the image data from OpenGL texture memory only,\n\
|
|
|
|
|
see also image.glLoad()."},
|
2004-09-25 20:30:40 +00:00
|
|
|
{"setName", ( PyCFunction ) Image_setName, METH_VARARGS,
|
|
|
|
|
"(str) - Change Image object name"},
|
2005-02-09 05:19:24 +00:00
|
|
|
{"setFilename", ( PyCFunction ) Image_setFilename, METH_VARARGS,
|
|
|
|
|
"(str) - Change Image file name"},
|
2004-09-25 20:30:40 +00:00
|
|
|
{"setXRep", ( PyCFunction ) Image_setXRep, METH_VARARGS,
|
|
|
|
|
"(int) - Change Image object x repetition value"},
|
|
|
|
|
{"setYRep", ( PyCFunction ) Image_setYRep, METH_VARARGS,
|
|
|
|
|
"(int) - Change Image object y repetition value"},
|
2004-06-06 22:42:51 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
2003-05-31 04:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python Image_Type callback function prototypes: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static void Image_dealloc( BPy_Image * self );
|
|
|
|
|
static int Image_setAttr( BPy_Image * self, char *name, PyObject * v );
|
|
|
|
|
static int Image_compare( BPy_Image * a, BPy_Image * b );
|
|
|
|
|
static PyObject *Image_getAttr( BPy_Image * self, char *name );
|
|
|
|
|
static PyObject *Image_repr( BPy_Image * self );
|
2003-05-31 04:43:10 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python Image_Type structure definition: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyTypeObject Image_Type = {
|
|
|
|
|
PyObject_HEAD_INIT( NULL )
|
|
|
|
|
0, /* ob_size */
|
|
|
|
|
"Blender Image", /* tp_name */
|
|
|
|
|
sizeof( BPy_Image ), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
2004-05-25 10:36:58 +00:00
|
|
|
/* methods */
|
2004-09-25 20:30:40 +00:00
|
|
|
( destructor ) Image_dealloc, /* tp_dealloc */
|
|
|
|
|
0, /* tp_print */
|
|
|
|
|
( getattrfunc ) Image_getAttr, /* tp_getattr */
|
|
|
|
|
( setattrfunc ) Image_setAttr, /* tp_setattr */
|
|
|
|
|
( cmpfunc ) Image_compare, /* tp_compare */
|
|
|
|
|
( reprfunc ) Image_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_Image_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
2005-02-09 15:53:35 +00:00
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* up to tp_del, to avoid a warning */
|
2003-05-31 04:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_dealloc */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Image type. It is */
|
|
|
|
|
/* the destructor function. */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static void Image_dealloc( BPy_Image * self )
|
2003-05-31 04:43:10 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject_DEL( self );
|
2003-05-31 04:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_CreatePyObject */
|
|
|
|
|
/* Description: This function will create a new BPy_Image from an existing */
|
|
|
|
|
/* Blender image structure. */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Image_CreatePyObject( Image * image )
|
2003-05-31 04:43:10 +00:00
|
|
|
{
|
2003-06-28 07:38:21 +00:00
|
|
|
BPy_Image *py_img;
|
2003-05-31 04:43:10 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
py_img = ( BPy_Image * ) PyObject_NEW( BPy_Image, &Image_Type );
|
2003-05-31 04:43:10 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !py_img )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create BPy_Image object" );
|
2003-05-31 04:43:10 +00:00
|
|
|
|
|
|
|
|
py_img->image = image;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) py_img;
|
2003-05-31 04:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_CheckPyObject */
|
2003-05-31 04:43:10 +00:00
|
|
|
/* Description: This function returns true when the given PyObject is of the */
|
2004-09-25 20:30:40 +00:00
|
|
|
/* type Image. Otherwise it will return false. */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
int Image_CheckPyObject( PyObject * pyobj )
|
2003-05-31 04:43:10 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( pyobj->ob_type == &Image_Type );
|
2003-05-31 04:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-23 17:46:06 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_FromPyObject */
|
|
|
|
|
/* Description: Returns the Blender Image associated with this object */
|
2003-11-23 17:46:06 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
Image *Image_FromPyObject( PyObject * pyobj )
|
2003-11-23 17:46:06 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( ( BPy_Image * ) pyobj )->image;
|
2003-11-23 17:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Image methods: */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getName( BPy_Image * self )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyString_FromString( self->image->id.name + 2 );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.name attribute" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getFilename( BPy_Image * self )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyString_FromString( self->image->name );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.filename attribute" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getSize( BPy_Image * self )
|
2003-07-30 21:15:41 +00:00
|
|
|
{
|
|
|
|
|
PyObject *attr;
|
|
|
|
|
Image *image = self->image;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !image->ibuf ) /* if no image data available */
|
|
|
|
|
load_image( image, IB_rect, "", 0 ); /* loading it */
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !image->ibuf ) /* didn't work */
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't load image data in Blender" );
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
attr = Py_BuildValue( "[hh]", image->ibuf->x, image->ibuf->y );
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.size attribute" );
|
2003-07-30 21:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getDepth( BPy_Image * self )
|
2003-07-30 21:15:41 +00:00
|
|
|
{
|
|
|
|
|
PyObject *attr;
|
|
|
|
|
Image *image = self->image;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !image->ibuf ) /* if no image data available */
|
|
|
|
|
load_image( image, IB_rect, "", 0 ); /* loading it */
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !image->ibuf ) /* didn't work */
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't load image data in Blender" );
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
attr = Py_BuildValue( "h", image->ibuf->depth );
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.depth attribute" );
|
2003-07-30 21:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getXRep( BPy_Image * self )
|
2003-07-12 18:02:54 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyInt_FromLong( self->image->xrep );
|
2003-07-12 18:02:54 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-07-12 18:02:54 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.xrep attribute" );
|
2003-07-12 18:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getYRep( BPy_Image * self )
|
2003-07-12 18:02:54 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyInt_FromLong( self->image->yrep );
|
2003-07-12 18:02:54 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2004-05-25 10:36:58 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.yrep attribute" );
|
2004-05-25 10:36:58 +00:00
|
|
|
}
|
2003-07-12 18:02:54 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getBindCode( BPy_Image * self )
|
2004-07-16 06:00:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyLong_FromUnsignedLong( self->image->bindcode );
|
2004-07-16 06:00:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2004-07-16 06:00:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.bindcode attribute" );
|
2004-07-16 06:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_reload( BPy_Image * self )
|
2004-05-25 10:36:58 +00:00
|
|
|
{
|
|
|
|
|
Image *img = self->image;
|
2004-09-25 20:30:40 +00:00
|
|
|
|
|
|
|
|
free_image_buffers( img ); /* force read again */
|
2004-05-25 10:36:58 +00:00
|
|
|
img->ok = 1;
|
2005-02-02 03:38:31 +00:00
|
|
|
if (G.sima) image_changed( G.sima, 0 );
|
2004-09-25 20:30:40 +00:00
|
|
|
|
|
|
|
|
Py_INCREF( Py_None );
|
2004-05-25 10:36:58 +00:00
|
|
|
return Py_None;
|
2003-07-12 18:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
static PyObject *Image_glFree( BPy_Image * self )
|
|
|
|
|
{
|
|
|
|
|
Image *img = self->image;
|
|
|
|
|
|
|
|
|
|
free_realtime_image( img );
|
|
|
|
|
return EXPP_incr_ret( Py_None );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_glLoad( BPy_Image * self )
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
{
|
|
|
|
|
Image *img = self->image;
|
|
|
|
|
unsigned int *bind = &img->bindcode;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( *bind == 0 ) {
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !img->ibuf ) /* if no image data is available */
|
|
|
|
|
load_image( img, IB_rect, "", 0 ); /* loading it */
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !img->ibuf ) /* didn't work */
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't load image data in Blender" );
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
glGenTextures( 1, ( GLuint * ) bind );
|
|
|
|
|
glBindTexture( GL_TEXTURE_2D, *bind );
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, img->ibuf->x,
|
|
|
|
|
img->ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
|
img->ibuf->rect );
|
|
|
|
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
|
|
|
|
GL_LINEAR_MIPMAP_NEAREST );
|
|
|
|
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
|
|
|
|
GL_LINEAR );
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, img->ibuf->x,
|
|
|
|
|
img->ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
|
img->ibuf->rect );
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return PyLong_FromUnsignedLong( img->bindcode );
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_setName( BPy_Image * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-05-25 10:36:58 +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" ) );
|
|
|
|
|
|
|
|
|
|
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
|
|
|
|
|
|
|
|
|
|
rename_id( &self->image->id, buf );
|
2004-05-25 10:36:58 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2004-05-25 10:36:58 +00:00
|
|
|
return Py_None;
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-09 05:19:24 +00:00
|
|
|
static PyObject *Image_setFilename( BPy_Image * self, PyObject * args )
|
|
|
|
|
{
|
|
|
|
|
char *name;
|
2005-02-09 15:53:35 +00:00
|
|
|
int namelen = 0;
|
2005-02-09 05:19:24 +00:00
|
|
|
|
2005-02-09 15:53:35 +00:00
|
|
|
/* max len is FILE_MAXDIR = 160 chars like done in DNA_image_types.h */
|
|
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple( args, "s#", &name, &namelen ) )
|
2005-02-09 05:19:24 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
2005-02-09 15:53:35 +00:00
|
|
|
"expected a string argument" ) );
|
2005-02-09 05:19:24 +00:00
|
|
|
|
2005-02-09 15:53:35 +00:00
|
|
|
if( namelen >= 160)
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"string argument is limited to 160 chars at most" ) );
|
2005-02-09 05:19:24 +00:00
|
|
|
|
2005-02-09 15:53:35 +00:00
|
|
|
PyOS_snprintf( self->image->name, FILE_MAXDIR * sizeof( char ), "%s", name );
|
2005-02-09 05:19:24 +00:00
|
|
|
|
|
|
|
|
Py_INCREF( Py_None );
|
|
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_setXRep( BPy_Image * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-05-25 10:36:58 +00:00
|
|
|
short value;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "h", &value ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int argument in [1,16]" ) );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX )
|
2004-05-25 10:36:58 +00:00
|
|
|
self->image->xrep = value;
|
|
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"expected int argument in [1,16]" ) );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2004-05-25 10:36:58 +00:00
|
|
|
return Py_None;
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_setYRep( BPy_Image * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-05-25 10:36:58 +00:00
|
|
|
short value;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "h", &value ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int argument in [1,16]" ) );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX )
|
2004-05-25 10:36:58 +00:00
|
|
|
self->image->yrep = value;
|
|
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"expected int argument in [1,16]" ) );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2004-05-25 10:36:58 +00:00
|
|
|
return Py_None;
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_getAttr */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Image type. It is */
|
|
|
|
|
/* the function that accesses BPy_Image member variables and */
|
|
|
|
|
/* methods. */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getAttr( BPy_Image * self, char *name )
|
2003-05-08 03:06:46 +00:00
|
|
|
{
|
2004-05-25 10:36:58 +00:00
|
|
|
PyObject *attr = Py_None;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( strcmp( name, "name" ) == 0 )
|
|
|
|
|
attr = PyString_FromString( self->image->id.name + 2 );
|
|
|
|
|
else if( strcmp( name, "filename" ) == 0 )
|
|
|
|
|
attr = PyString_FromString( self->image->name );
|
|
|
|
|
else if( strcmp( name, "size" ) == 0 )
|
|
|
|
|
attr = Image_getSize( self );
|
|
|
|
|
else if( strcmp( name, "depth" ) == 0 )
|
|
|
|
|
attr = Image_getDepth( self );
|
|
|
|
|
else if( strcmp( name, "xrep" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->xrep );
|
|
|
|
|
else if( strcmp( name, "yrep" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->yrep );
|
|
|
|
|
else if( strcmp( name, "bindcode" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->bindcode );
|
2005-01-13 03:04:12 +00:00
|
|
|
else if( strcmp( name, "users" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->id.us );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( strcmp( name, "__members__" ) == 0 )
|
2005-01-13 03:04:12 +00:00
|
|
|
attr = Py_BuildValue( "[s,s,s,s,s,s,s,s]",
|
2004-09-25 20:30:40 +00:00
|
|
|
"name", "filename", "size", "depth",
|
2005-01-13 03:04:12 +00:00
|
|
|
"xrep", "yrep", "bindcode", "users" );
|
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 */
|
2004-05-25 10:36:58 +00:00
|
|
|
|
|
|
|
|
/* not an attribute, search the methods table */
|
2004-09-25 20:30:40 +00:00
|
|
|
return Py_FindMethod( BPy_Image_methods, ( PyObject * ) self, name );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_setAttr */
|
2003-06-28 07:38:21 +00:00
|
|
|
/* Description: This is a callback function for the BPy_Image type. It is the*/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* function that changes Image object members values. If this */
|
|
|
|
|
/* data is linked to a Blender Image, it also gets updated. */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Image_setAttr( BPy_Image * self, char *name, PyObject * value )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *valtuple;
|
2004-05-25 10:36:58 +00:00
|
|
|
PyObject *error = NULL;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
/* We're playing a trick on the Python API users here. Even if they use
|
2003-04-08 19:54:14 +00:00
|
|
|
* Image.member = val instead of Image.setMember(value), we end up using the
|
|
|
|
|
* function anyway, since it already has error checking, clamps to the right
|
|
|
|
|
* interval and updates the Blender Image structure when necessary. */
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
valtuple = Py_BuildValue( "(O)", value ); /*the set* functions expect a tuple */
|
|
|
|
|
|
|
|
|
|
if( !valtuple )
|
|
|
|
|
return EXPP_ReturnIntError( PyExc_MemoryError,
|
|
|
|
|
"ImageSetAttr: couldn't create PyTuple" );
|
|
|
|
|
|
|
|
|
|
if( strcmp( name, "name" ) == 0 )
|
|
|
|
|
error = Image_setName( self, valtuple );
|
2005-02-09 05:19:24 +00:00
|
|
|
if( strcmp( name, "filename" ) == 0 )
|
|
|
|
|
error = Image_setFilename( self, valtuple );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( strcmp( name, "xrep" ) == 0 )
|
|
|
|
|
error = Image_setXRep( self, valtuple );
|
|
|
|
|
else if( strcmp( name, "yrep" ) == 0 )
|
|
|
|
|
error = Image_setYRep( self, valtuple );
|
|
|
|
|
else { /* Error: no such member in the Image object structure */
|
|
|
|
|
Py_DECREF( value );
|
|
|
|
|
Py_DECREF( valtuple );
|
|
|
|
|
return ( EXPP_ReturnIntError( PyExc_KeyError,
|
|
|
|
|
"attribute not found or immutable" ) );
|
2004-05-25 10:36:58 +00:00
|
|
|
}
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( valtuple );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( error != Py_None )
|
|
|
|
|
return -1;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( Py_None ); /* incref'ed by the called set* function */
|
|
|
|
|
return 0; /* normal exit */
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_compare */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Image type. It */
|
|
|
|
|
/* compares two Image_Type objects. Only the "==" and "!=" */
|
|
|
|
|
/* comparisons are meaninful. Returns 0 for equality and -1 if */
|
|
|
|
|
/* they don't point to the same Blender Image struct. */
|
|
|
|
|
/* In Python it becomes 1 if they are equal, 0 otherwise. */
|
2003-05-21 19:58:31 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Image_compare( BPy_Image * a, BPy_Image * b )
|
2003-05-21 19:58:31 +00:00
|
|
|
{
|
|
|
|
|
Image *pa = a->image, *pb = b->image;
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( pa == pb ) ? 0 : -1;
|
2003-05-21 19:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_repr */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Image type. It */
|
|
|
|
|
/* builds a meaninful string to represent image objects. */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_repr( BPy_Image * self )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return PyString_FromFormat( "[Image \"%s\"]",
|
|
|
|
|
self->image->id.name + 2 );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|