Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillian Padovani Germano <wpgermano@gmail.com>2005-03-19 09:24:55 +0300
committerWillian Padovani Germano <wpgermano@gmail.com>2005-03-19 09:24:55 +0300
commita96ed881dc04d0a2ce6ab742f7682042e466b0a7 (patch)
treed5d787dc224d4b7c3f3e3d64a98bef0525d436e9 /source/blender/python/api2_2x
parentcbbe236f9237cd7a942e250493b6c7402300deb7 (diff)
BPython:
- Scripts: fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus. cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu). small updates to help_browser.py script. The above changes are related to this: - Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there. - Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ). - Modules: Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode. NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work). - Bugs fixed: #2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9 Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does. #1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9 Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script"). Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython. - Removed a few warnings here and there and also updated docs.
Diffstat (limited to 'source/blender/python/api2_2x')
-rw-r--r--source/blender/python/api2_2x/Blender.c221
-rw-r--r--source/blender/python/api2_2x/Ipo.c2
-rw-r--r--source/blender/python/api2_2x/NMesh.c115
-rw-r--r--source/blender/python/api2_2x/Sound.c6
-rw-r--r--source/blender/python/api2_2x/Text.c51
-rw-r--r--source/blender/python/api2_2x/Window.c48
-rw-r--r--source/blender/python/api2_2x/doc/API_intro.py85
-rw-r--r--source/blender/python/api2_2x/doc/Blender.py48
-rw-r--r--source/blender/python/api2_2x/doc/NMesh.py53
-rw-r--r--source/blender/python/api2_2x/doc/Window.py14
-rw-r--r--source/blender/python/api2_2x/gen_utils.c8
-rw-r--r--source/blender/python/api2_2x/gen_utils.h3
-rw-r--r--source/blender/python/api2_2x/sceneRender.c102
13 files changed, 530 insertions, 226 deletions
diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c
index 7c93d540ceb..c1ecbdf7ebb 100644
--- a/source/blender/python/api2_2x/Blender.c
+++ b/source/blender/python/api2_2x/Blender.c
@@ -49,6 +49,7 @@
#include <BKE_global.h>
#include <BKE_packedFile.h>
#include <BKE_object.h>
+#include <BKE_text.h>
#include <BPI_script.h>
#include <BSE_headerbuttons.h>
#include <DNA_ID.h>
@@ -60,14 +61,11 @@
#include <BKE_ipo.h>
#include <blendef.h>
-
-
#include "gen_utils.h"
#include "modules.h"
#include "../BPY_extern.h" /* for bpy_gethome() */
#include "../BPY_menus.h" /* to update menus */
-
/**********************************************************/
/* Python API function prototypes for the Blender module. */
/**********************************************************/
@@ -77,11 +75,11 @@ static PyObject *Blender_Redraw( PyObject * self, PyObject * args );
static PyObject *Blender_Quit( PyObject * self );
static PyObject *Blender_Load( PyObject * self, PyObject * args );
static PyObject *Blender_Save( PyObject * self, PyObject * args );
+static PyObject *Blender_Run( PyObject * self, PyObject * args );
static PyObject *Blender_UpdateMenus( PyObject * self);
extern PyObject *Text3d_Init( void ); /* missing in some include */
-
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
@@ -135,6 +133,10 @@ Note 2: only .blend raises an error if file wasn't saved.\n\
\tYou can use Blender.sys.exists(filename) to make sure the file was saved\n\
\twhen writing to one of the other formats.";
+static char Blender_Run_doc[] =
+ "(script) - Run the given Python script.\n\
+(script) - the path to a file or the name of an available Blender Text.";
+
static char Blender_UpdateMenus_doc[] =
"() - Update the menus where scripts are registered. Only needed for\n\
scripts that save other new scripts in the default or user defined folders.";
@@ -149,6 +151,7 @@ static struct PyMethodDef Blender_methods[] = {
{"Quit", ( PyCFunction ) Blender_Quit, METH_NOARGS, Blender_Quit_doc},
{"Load", Blender_Load, METH_VARARGS, Blender_Load_doc},
{"Save", Blender_Save, METH_VARARGS, Blender_Save_doc},
+ {"Run", Blender_Run, METH_VARARGS, Blender_Run_doc},
{"UpdateMenus", ( PyCFunction ) Blender_UpdateMenus, METH_NOARGS,
Blender_UpdateMenus_doc},
{NULL, NULL, 0, NULL}
@@ -196,104 +199,87 @@ static PyObject *Blender_Set( PyObject * self, PyObject * args )
/*****************************************************************************/
static PyObject *Blender_Get( PyObject * self, PyObject * args )
{
- PyObject *object;
- PyObject *dict;
- char *str;
-
- if( !PyArg_ParseTuple( args, "O", &object ) ) {
- /* TODO: Do we need to generate a nice error message here? */
- return ( NULL );
+ PyObject *ret = NULL, *dict = NULL;
+ char *str = NULL;
+
+ if( !PyArg_ParseTuple( args, "s", &str ) )
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected string argument");
+
+ if( StringEqual( str, "curframe" ) )
+ ret = PyInt_FromLong( G.scene->r.cfra );
+ else if( StringEqual( str, "curtime" ) )
+ ret = PyFloat_FromDouble( frame_to_float( G.scene->r.cfra ) );
+ else if( StringEqual( str, "staframe" ) )
+ ret = PyInt_FromLong( G.scene->r.sfra );
+ else if( StringEqual( str, "endframe" ) )
+ ret = PyInt_FromLong( G.scene->r.efra );
+ else if( StringEqual( str, "filename" ) )
+ ret = PyString_FromString( G.sce );
+ else if( StringEqual( str, "homedir" ) ) {
+ char *hdir = bpy_gethome(0);
+ if( BLI_exists( hdir ))
+ ret = PyString_FromString( hdir );
+ else
+ ret = EXPP_incr_ret( Py_None );
}
+ else if( StringEqual( str, "datadir" ) ) {
+ char datadir[FILE_MAXDIR];
+
+ BLI_make_file_string( "/", datadir, bpy_gethome(1), "bpydata/" );
+ if( BLI_exists( datadir ) )
+ ret = PyString_FromString( datadir );
+ else
+ ret = EXPP_incr_ret( Py_None );
+ }
+ else if(StringEqual(str, "udatadir")) {
+ char udatadir[FILE_MAXDIR];
- if( PyString_Check( object ) ) {
- str = PyString_AsString( object );
-
- if( StringEqual( str, "curframe" ) ) {
- return ( PyInt_FromLong( G.scene->r.cfra ) );
- }
- if( StringEqual( str, "curtime" ) ) {
- return ( PyFloat_FromDouble
- ( frame_to_float( G.scene->r.cfra ) ) );
- }
- if( StringEqual( str, "staframe" ) ) {
- return ( PyInt_FromLong( G.scene->r.sfra ) );
- }
- if( StringEqual( str, "endframe" ) ) {
- return ( PyInt_FromLong( G.scene->r.efra ) );
- }
- if( StringEqual( str, "filename" ) ) {
- return ( PyString_FromString( G.sce ) );
- }
- if( StringEqual( str, "homedir" ) ) {
- if( BLI_exists( bpy_gethome() ))
- return PyString_FromString( bpy_gethome() );
- else
- return EXPP_incr_ret( Py_None );
+ if (BLI_exists(U.pythondir)) {
+ BLI_make_file_string("/", udatadir, U.pythondir, "bpydata/");
+ if (BLI_exists(udatadir))
+ ret = PyString_FromString(udatadir);
}
+ if (!ret) ret = EXPP_incr_ret(Py_None);
+ }
+ else if( StringEqual( str, "scriptsdir" ) ) {
+ char *sdir = bpy_gethome(1);
- if( StringEqual( str, "datadir" ) ) {
- char datadir[FILE_MAXDIR];
- BLI_make_file_string( "/", datadir, bpy_gethome( ),
- "bpydata/" );
- if( BLI_exists( datadir ) )
- return PyString_FromString( datadir );
+ if (sdir)
+ ret = PyString_FromString(sdir);
else
- return EXPP_incr_ret( Py_None );
- }
- if( StringEqual( str, "scriptsdir" ) ) {
- char scriptsdir[FILE_MAXDIR];
- BLI_make_file_string( "/", scriptsdir, bpy_gethome( ),
- "scripts/" );
- if( BLI_exists( scriptsdir ) )
- return PyString_FromString( scriptsdir );
- else
- return EXPP_incr_ret( Py_None );
- }
- if( StringEqual( str, "uscriptsdir" ) ) {
+ ret = EXPP_incr_ret( Py_None );
+ }
+ else if( StringEqual( str, "uscriptsdir" ) ) {
if( BLI_exists( U.pythondir ) )
- return PyString_FromString( U.pythondir );
+ ret = PyString_FromString( U.pythondir );
else
- return EXPP_incr_ret( Py_None );
- }
- /* According to the old file (opy_blender.c), the following if
- statement is a quick hack and needs some clean up. */
- if( StringEqual( str, "vrmloptions" ) ) {
- dict = PyDict_New( );
-
- PyDict_SetItemString( dict, "twoside",
- PyInt_FromLong( U.
- vrmlflag &
- USER_VRML_TWOSIDED ) );
-
- PyDict_SetItemString( dict, "layers",
- PyInt_FromLong( U.
- vrmlflag &
- USER_VRML_LAYERS ) );
-
- PyDict_SetItemString( dict, "autoscale",
- PyInt_FromLong( U.
- vrmlflag &
- USER_VRML_AUTOSCALE ) );
-
- return ( dict );
- } /* End 'quick hack' part. */
- if( StringEqual( str, "version" ) ) {
- return ( PyInt_FromLong( G.version ) );
- }
- /* TODO: Do we want to display a usefull message here that the
- requested data is unknown?
- else
- {
- return (EXPP_ReturnPyObjError (..., "message") );
- }
- */
- } else {
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected string argument" ) );
+ ret = EXPP_incr_ret( Py_None );
}
+ /* According to the old file (opy_blender.c), the following if
+ statement is a quick hack and needs some clean up. */
+ else if( StringEqual( str, "vrmloptions" ) ) {
+ ret = PyDict_New( );
+
+ PyDict_SetItemString( dict, "twoside",
+ PyInt_FromLong( U.vrmlflag & USER_VRML_TWOSIDED ) );
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "bad request identifier" ) );
+ PyDict_SetItemString( dict, "layers",
+ PyInt_FromLong( U.vrmlflag & USER_VRML_LAYERS ) );
+
+ PyDict_SetItemString( dict, "autoscale",
+ PyInt_FromLong( U.vrmlflag & USER_VRML_AUTOSCALE ) );
+
+ } /* End 'quick hack' part. */
+ else if(StringEqual( str, "version" ))
+ ret = PyInt_FromLong( G.version );
+ else
+ return EXPP_ReturnPyObjError( PyExc_AttributeError, "unknown attribute" );
+
+ if (ret) return ret;
+ else
+ return EXPP_ReturnPyObjError (PyExc_MemoryError,
+ "could not create pystring!");
}
/*****************************************************************************/
@@ -491,6 +477,47 @@ static PyObject *Blender_Save( PyObject * self, PyObject * args )
return Py_None;
}
+static PyObject *Blender_Run(PyObject *self, PyObject *args)
+{
+ char *fname = NULL;
+ Text *text = NULL;
+ int is_blender_text = 0;
+
+ if (!PyArg_ParseTuple(args, "s", &fname))
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "expected a filename or a Blender Text name as argument");
+
+ if (!BLI_exists(fname)) { /* if there's no such filename ... */
+ text = G.main->text.first; /* try an already existing Blender Text */
+
+ while (text) {
+ if (!strcmp(fname, text->id.name + 2)) break;
+ text = text->id.next;
+ }
+
+ if (!text) {
+ return EXPP_ReturnPyObjError(PyExc_AttributeError,
+ "no such file or Blender text");
+ }
+ else is_blender_text = 1; /* fn is already a Blender Text */
+ }
+
+ else {
+ text = add_text(fname);
+
+ if (!text) {
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "couldn't create Blender Text from given file");
+ }
+ }
+
+ BPY_txt_do_python_Text(text);
+
+ if (!is_blender_text) free_libblock(&G.main->text, text);
+
+ return EXPP_incr_ret(Py_None);
+}
+
static PyObject * Blender_UpdateMenus( PyObject * self )
{
@@ -510,7 +537,7 @@ static PyObject * Blender_UpdateMenus( PyObject * self )
void M_Blender_Init( void )
{
PyObject *module;
- PyObject *dict;
+ PyObject *dict, *smode;
g_blenderdict = NULL;
@@ -519,12 +546,18 @@ void M_Blender_Init( void )
types_InitAll( ); /* set all our pytypes to &PyType_Type */
+ if (G.background)
+ smode = PyString_FromString("background");
+ else
+ smode = PyString_FromString("interactive");
+
dict = PyModule_GetDict( module );
g_blenderdict = dict;
PyDict_SetItemString( dict, "bylink", EXPP_incr_ret_False() );
PyDict_SetItemString( dict, "link", EXPP_incr_ret ( Py_None ) );
PyDict_SetItemString( dict, "event", PyString_FromString( "" ) );
+ PyDict_SetItemString( dict, "mode", smode );
PyDict_SetItemString( dict, "Types", Types_Init( ) );
PyDict_SetItemString( dict, "sys", sys_Init( ) );
diff --git a/source/blender/python/api2_2x/Ipo.c b/source/blender/python/api2_2x/Ipo.c
index 80a0a39ef5f..13f4229df5c 100644
--- a/source/blender/python/api2_2x/Ipo.c
+++ b/source/blender/python/api2_2x/Ipo.c
@@ -1119,7 +1119,7 @@ static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
"blender could not create ipo curve" );
allspace( REMAKEIPO, 0 );
- allqueue( REDRAWIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
/* create a bpy wrapper for the new ipo curve */
return IpoCurve_CreatePyObject( icu );
diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c
index b1173799aa8..583a74e49a5 100644
--- a/source/blender/python/api2_2x/NMesh.c
+++ b/source/blender/python/api2_2x/NMesh.c
@@ -90,10 +90,8 @@
static PyObject *g_nmeshmodule = NULL;
static int unlink_existingMeshData( Mesh * mesh );
-static int convert_NMeshToMesh( Mesh * mesh, BPy_NMesh * nmesh, int store_edges );
-/* <start> */
+static int convert_NMeshToMesh( Mesh *mesh, BPy_NMesh *nmesh, int store_edges );
static PyObject *NMesh_printDebug( PyObject * self );
-/* <end> */
static PyObject *NMesh_addEdge( PyObject * self, PyObject * args );
static PyObject *NMesh_findEdge( PyObject * self, PyObject * args );
static PyObject *NMesh_removeEdge( PyObject * self, PyObject * args );
@@ -103,19 +101,15 @@ static PyObject *NMesh_removeFace( PyObject * self, PyObject * args );
static PyObject *NMesh_addVertGroup( PyObject * self, PyObject * args );
static PyObject *NMesh_removeVertGroup( PyObject * self, PyObject * args );
static PyObject *NMesh_assignVertsToGroup( PyObject * self, PyObject * args );
-static PyObject *NMesh_removeVertsFromGroup( PyObject * self,
- PyObject * args );
+static PyObject *NMesh_removeVertsFromGroup( PyObject * self,PyObject * args );
static PyObject *NMesh_getVertsFromGroup( PyObject * self, PyObject * args );
static PyObject *NMesh_renameVertGroup( PyObject * self, PyObject * args );
static PyObject *NMesh_getVertGroupNames( PyObject * self );
-
-/* <start> */
+static PyObject *NMesh_transform (PyObject *self, PyObject *args);
static char NMesh_printDebug_doc[] =
"print debug info about the mesh.";
-/* <end> */
-
static char NMesh_addEdge_doc[] =
"create an edge between two vertices.\n\
If an edge already exists between those vertices, it is returned.\n\
@@ -243,8 +237,7 @@ static char NMesh_getVertexInfluences_doc[] =
specified by index. The list contains pairs with the \n\
bone name and the weight.";
-
-static char NMesh_update_doc[] = \
+static char NMesh_update_doc[] =
"(recalc_normals = 0, store_edges = 0, vertex_shade = 0) - Updates the Mesh.\n\
Optional arguments: if given and nonzero:\n\
'recalc_normals': normal vectors are recalculated;\n\
@@ -288,14 +281,20 @@ This returns the mesh as used by the object, which\n\
means it contains all deformations and modifications.";
static char M_NMesh_PutRaw_doc[] =
- "(mesh, [name, renormal, store_edges]) - Return a raw mesh to Blender\n\n\
+ "(mesh, name = None, recalc_normals = 1, store_edges = 0]) -\n\
+Return a raw mesh to Blender\n\n\
(mesh) The NMesh object to store\n\
[name] The mesh to replace\n\
-[renormal=1] Flag to control vertex normal recalculation\n\
+[recalc_normals = 1] Flag to control vertex normal recalculation\n\
[store_edges=0] Store edges data in the blender mesh\n\
If the name of a mesh to replace is not given a new\n\
object is created and returned.";
+static char NMesh_transform_doc[] =
+ "(matrix, recalc_normals = 0) - Transform the mesh by the supplied 4x4\n\
+matrix.\n\
+(recalc_normals) - if given and 1 or True, transforming the vertex normals\n\
+is skipped.";
void mesh_update( Mesh * mesh )
@@ -1341,7 +1340,7 @@ static PyObject *NMesh_update( PyObject *self, PyObject *a, PyObject *kwd )
}
if( !during_script( ) && needs_redraw)
- allqueue( REDRAWVIEW3D, 0 );
+ EXPP_allqueue( REDRAWVIEW3D, 0 );
return PyInt_FromLong( 1 );
}
@@ -1579,6 +1578,7 @@ static struct PyMethodDef NMesh_methods[] = {
MethodDef( setMode ),
MethodDef( setMaxSmoothAngle ),
MethodDef( setSubDivLevels ),
+ MethodDef( transform ),
/* METH_NOARGS: function(PyObject *self) */
#undef MethodDef
@@ -2818,7 +2818,7 @@ static PyObject *M_NMesh_PutRaw( PyObject * self, PyObject * args )
mesh_update( mesh );
if( !during_script( ) )
- allqueue( REDRAWVIEW3D, 0 );
+ EXPP_allqueue( REDRAWVIEW3D, 0 );
// @OK...this requires some explanation:
// Materials can be assigned two ways:
@@ -3347,9 +3347,6 @@ static PyObject *NMesh_removeFace( PyObject * self, PyObject * args )
return EXPP_incr_ret( Py_None );
}
-
-/* <start> */
-
static PyObject *NMesh_printDebug( PyObject * self )
{
BPy_NMesh *bmesh=(BPy_NMesh *)self;
@@ -3402,7 +3399,6 @@ static PyObject *NMesh_printDebug( PyObject * self )
return EXPP_incr_ret( Py_None );
}
-/* <end> */
static PyObject *NMesh_addVertGroup( PyObject * self, PyObject * args )
{
char *groupStr;
@@ -3425,7 +3421,7 @@ static PyObject *NMesh_addVertGroup( PyObject * self, PyObject * args )
add_defgroup_name( object, groupStr );
- allqueue( REDRAWBUTSALL, 1 );
+ EXPP_allqueue( REDRAWBUTSALL, 1 );
return EXPP_incr_ret( Py_None );
}
@@ -3461,7 +3457,7 @@ static PyObject *NMesh_removeVertGroup( PyObject * self, PyObject * args )
del_defgroup( object );
- allqueue( REDRAWBUTSALL, 1 );
+ EXPP_allqueue( REDRAWBUTSALL, 1 );
return EXPP_incr_ret( Py_None );
}
@@ -3658,7 +3654,7 @@ static PyObject *NMesh_getVertsFromGroup( PyObject * self, PyObject * args )
int tempInt;
int x;
- listObject = ( void * ) -2054456; //can't use NULL macro because compiler thinks
+ listObject = Py_None; //can't use NULL macro because compiler thinks
//it's a 0 and we need to check 0 index vertex pos
l1 = FALSE;
l2 = FALSE;
@@ -3705,7 +3701,7 @@ static PyObject *NMesh_getVertsFromGroup( PyObject * self, PyObject * args )
count = 0;
- if( listObject == ( void * ) -2054456 ) //do entire group
+ if( listObject == Py_None ) //do entire group
{
for( k = 0; k < ( ( Mesh * ) object->data )->totvert; k++ ) {
dvert = ( ( Mesh * ) object->data )->dvert + k;
@@ -3816,14 +3812,12 @@ static PyObject *NMesh_renameVertGroup( PyObject * self, PyObject * args )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"Couldn't find the expected vertex group" );
- //set name
PyOS_snprintf( defGroup->name, 32, newGr );
unique_vertexgroup_name( defGroup, ( ( BPy_NMesh * ) self )->object );
return EXPP_incr_ret( Py_None );
}
-
static PyObject *NMesh_getVertGroupNames( PyObject * self )
{
bDeformGroup *defGroup;
@@ -3844,3 +3838,74 @@ static PyObject *NMesh_getVertGroupNames( PyObject * self )
return list;
}
+
+static PyObject *NMesh_transform (PyObject *self, PyObject *args)
+{
+ BPy_NMesh *nmesh = ( BPy_NMesh * ) self;
+ BPy_NMVert *mv;
+ PyObject *ob1 = NULL;
+ MatrixObject *mat;
+ float vx, vy, vz;
+ int i, recalc_normals = 0;
+
+ if( !PyArg_ParseTuple( args, "O!|i", &matrix_Type, &ob1, &recalc_normals ) )
+ return ( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected matrix and optionally an int as arguments" ) );
+
+ mat = ( MatrixObject * ) ob1;
+
+ if( mat->colSize != 4 || mat->rowSize != 4 )
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "matrix must be a 4x4 transformation matrix\n"
+ "for example as returned by object.getMatrix()" ) );
+
+ /* loop through all the verts and transform locations by the supplied
+ * matrix */
+ for( i = 0; i < PySequence_Length(nmesh->verts); i++ ) {
+ mv = ( BPy_NMVert * ) PySequence_GetItem( nmesh->verts, i );
+ vx = mv->co[0];
+ vy = mv->co[1];
+ vz = mv->co[2];
+
+ /* Mat4MulVecfl(mat->matrix, mv->co); */
+
+ mv->co[0] = vx*mat->matrix[0][0] + vy*mat->matrix[1][0] +
+ vz*mat->matrix[2][0] + mat->matrix[3][0];
+ mv->co[1] = vx*mat->matrix[0][1] + vy*mat->matrix[1][1] +
+ vz*mat->matrix[2][1] + mat->matrix[3][1];
+ mv->co[2] = vx*mat->matrix[0][2] + vy*mat->matrix[1][2] +
+ vz*mat->matrix[2][2] + mat->matrix[3][2];
+
+ Py_DECREF(mv);
+ }
+
+ if ( recalc_normals ) {
+ /* loop through all the verts and transform normals by the inverse
+ * of the transpose of the supplied matrix */
+ float invmat[4][4];
+
+ if (!Mat4Invert(invmat, mat->matrix))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "given matrix is not invertible");
+
+ for( i = 0; i < PySequence_Length(nmesh->verts); i++ ) {
+ mv = ( BPy_NMVert * ) PySequence_GetItem( nmesh->verts, i );
+ vx = mv->no[0];
+ vy = mv->no[1];
+ vz = mv->no[2];
+ mv->no[0] = vx*invmat[0][0] + vy*invmat[0][1] + vz*invmat[0][2] +
+ invmat[0][3];
+ mv->no[1] = vx*invmat[1][0] + vy*invmat[1][1] + vz*invmat[1][2] +
+ invmat[1][3];
+ mv->no[2] = vx*invmat[2][0] + vy*invmat[2][1] + vz*invmat[2][2] +
+ invmat[2][3];
+ Normalise(mv->no);
+ Py_DECREF(mv);
+ }
+ }
+
+ /* should we alternatively return a list of changed verts (and preserve
+ * the original ones) ? */
+ Py_INCREF( Py_None );
+ return Py_None;
+}
diff --git a/source/blender/python/api2_2x/Sound.c b/source/blender/python/api2_2x/Sound.c
index 86857ee453b..8ba3bd23b81 100644
--- a/source/blender/python/api2_2x/Sound.c
+++ b/source/blender/python/api2_2x/Sound.c
@@ -36,7 +36,7 @@
#include <BKE_sound.h>
#include <BLI_blenlib.h>
#include <BIF_editsound.h>
-#include <BIF_space.h> /* allqueue() */
+#include <BIF_space.h> /* EXPP_allqueue() */
#include "mydevice.h" /* redraw defines */
@@ -427,8 +427,8 @@ static PyObject *Sound_setCurrent( BPy_Sound * self )
}
}
- allqueue( REDRAWSOUND, 0 );
- allqueue( REDRAWBUTSLOGIC, 0 );
+ EXPP_allqueue( REDRAWSOUND, 0 );
+ EXPP_allqueue( REDRAWBUTSLOGIC, 0 );
Py_INCREF( Py_None );
return Py_None;
diff --git a/source/blender/python/api2_2x/Text.c b/source/blender/python/api2_2x/Text.c
index 55304588515..90de9b5bed1 100644
--- a/source/blender/python/api2_2x/Text.c
+++ b/source/blender/python/api2_2x/Text.c
@@ -40,6 +40,7 @@
#include <BIF_drawtext.h>
#include <BKE_text.h>
#include <BLI_blenlib.h>
+#include <DNA_space_types.h>
#include <DNA_text_types.h>
#include "Text.h"
@@ -51,8 +52,7 @@
/*****************************************************************************/
/* Python API function prototypes for the Text module. */
/*****************************************************************************/
-static PyObject *M_Text_New( PyObject * self, PyObject * args,
- PyObject * keywords );
+static PyObject *M_Text_New( PyObject * self, PyObject * args);
static PyObject *M_Text_Get( PyObject * self, PyObject * args );
static PyObject *M_Text_Load( PyObject * self, PyObject * args );
static PyObject *M_Text_unlink( PyObject * self, PyObject * args );
@@ -81,8 +81,7 @@ static char M_Text_unlink_doc[] =
/* Python method structure definition for Blender.Text module: */
/*****************************************************************************/
struct PyMethodDef M_Text_methods[] = {
- {"New", ( PyCFunction ) M_Text_New, METH_VARARGS | METH_KEYWORDS,
- M_Text_New_doc},
+ {"New", M_Text_New, METH_VARARGS, M_Text_New_doc},
{"Get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
{"get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
{"Load", M_Text_Load, METH_VARARGS, M_Text_Load_doc},
@@ -107,10 +106,10 @@ static PyObject *Text_getName( BPy_Text * self );
static PyObject *Text_getFilename( BPy_Text * self );
static PyObject *Text_getNLines( BPy_Text * self );
static PyObject *Text_setName( BPy_Text * self, PyObject * args );
-static PyObject *Text_clear( BPy_Text * self, PyObject * args );
+static PyObject *Text_clear( BPy_Text * self );
static PyObject *Text_write( BPy_Text * self, PyObject * args );
static PyObject *Text_set( BPy_Text * self, PyObject * args );
-static PyObject *Text_asLines( BPy_Text * self, PyObject * args );
+static PyObject *Text_asLines( BPy_Text * self );
/*****************************************************************************/
/* Python BPy_Text methods table: */
@@ -125,13 +124,13 @@ static PyMethodDef BPy_Text_methods[] = {
"() - Return number of lines in text buffer"},
{"setName", ( PyCFunction ) Text_setName, METH_VARARGS,
"(str) - Change Text Object name"},
- {"clear", ( PyCFunction ) Text_clear, METH_VARARGS,
+ {"clear", ( PyCFunction ) Text_clear, METH_NOARGS,
"() - Clear Text buffer"},
{"write", ( PyCFunction ) Text_write, METH_VARARGS,
"(line) - Append string 'str' to Text buffer"},
{"set", ( PyCFunction ) Text_set, METH_VARARGS,
"(name, val) - Set attribute 'name' to value 'val'"},
- {"asLines", ( PyCFunction ) Text_asLines, METH_VARARGS,
+ {"asLines", ( PyCFunction ) Text_asLines, METH_NOARGS,
"() - Return text buffer as a list of lines"},
{NULL, NULL, 0, NULL}
};
@@ -170,14 +169,14 @@ PyTypeObject Text_Type = {
0, 0, 0, 0, 0, 0,
BPy_Text_methods, /* tp_methods */
0, /* tp_members */
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
/*****************************************************************************/
/* Function: M_Text_New */
/* Python equivalent: Blender.Text.New */
/*****************************************************************************/
-static PyObject *M_Text_New( PyObject * self, PyObject * args,
- PyObject * keywords )
+static PyObject *M_Text_New( PyObject * self, PyObject * args)
{
char *name = NULL;
char buf[21];
@@ -249,9 +248,9 @@ static PyObject *M_Text_Get( PyObject * self, PyObject * args )
if( wanted_txt == NULL ) { /* Requested text doesn't exist */
char error_msg[64];
PyOS_snprintf( error_msg, sizeof( error_msg ),
- "Text \"%s\" not found", name );
+ "Text \"%s\" not found", name );
return ( EXPP_ReturnPyObjError
- ( PyExc_NameError, error_msg ) );
+ ( PyExc_NameError, error_msg ) );
}
return wanted_txt;
@@ -293,28 +292,30 @@ static PyObject *M_Text_Get( PyObject * self, PyObject * args )
/*****************************************************************************/
static PyObject *M_Text_Load( PyObject * self, PyObject * args )
{
- char *fname;
- Text *txt_ptr;
- BPy_Text *txt;
+ char *fname = NULL;
+ char fpath[FILE_MAXDIR + FILE_MAXFILE];
+ Text *txt_ptr = NULL;
+ unsigned int maxlen = FILE_MAXDIR + FILE_MAXFILE;
if( !PyArg_ParseTuple( args, "s", &fname ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected string argument" ) );
- txt = ( BPy_Text * ) PyObject_NEW( BPy_Text, &Text_Type );
+ if (strlen(fname) > (maxlen - 1))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "text filename too long");
+ else if (!BLI_exists(fname))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "text file not found");
- if( !txt )
- return EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create PyObject Text_Type" );
+ BLI_strncpy(fpath, fname, maxlen);
- txt_ptr = add_text( fname );
+ txt_ptr = add_text( fpath );
if( !txt_ptr )
return EXPP_ReturnPyObjError( PyExc_IOError,
"couldn't load text" );
- txt->text = txt_ptr;
-
- return ( PyObject * ) txt;
+ return Text_CreatePyObject(txt_ptr);
}
/*****************************************************************************/
@@ -454,7 +455,7 @@ static PyObject *Text_setName( BPy_Text * self, PyObject * args )
return Py_None;
}
-static PyObject *Text_clear( BPy_Text * self, PyObject * args )
+static PyObject *Text_clear( BPy_Text * self)
{
int oldstate;
@@ -514,7 +515,7 @@ static PyObject *Text_write( BPy_Text * self, PyObject * args )
return Py_None;
}
-static PyObject *Text_asLines( BPy_Text * self, PyObject * args )
+static PyObject *Text_asLines( BPy_Text * self )
{
TextLine *line;
PyObject *list, *ob;
diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c
index 9543bdd2034..b8998a943ac 100644
--- a/source/blender/python/api2_2x/Window.c
+++ b/source/blender/python/api2_2x/Window.c
@@ -37,7 +37,7 @@
#include <BDR_editobject.h> /* enter / leave editmode */
#include <BKE_global.h>
#include <BKE_library.h>
-#include <BKE_object.h> /* for during_script() */
+#include <BKE_object.h> /* for during_script() and during_scriptlink() */
#include <BKE_scene.h> /* scene_find_camera() */
#include <BIF_usiblender.h>
#include <BIF_mywindow.h>
@@ -378,7 +378,7 @@ PyObject *M_Window_Redraw( PyObject * self, PyObject * args )
if( wintype < 0 )
redraw_all = 1;
- if( !during_script( ) ) {
+ if( !during_script( ) && !G.background ) {
tempsa = curarea;
sa = G.curscreen->areabase.first;
@@ -432,7 +432,7 @@ static PyObject *M_Window_RedrawAll( PyObject * self, PyObject * args )
/*****************************************************************************/
static PyObject *M_Window_QRedrawAll( PyObject * self, PyObject * args )
{
- allqueue( REDRAWALL, 0 );
+ EXPP_allqueue( REDRAWALL, 0 );
Py_INCREF( Py_None );
return Py_None;
@@ -478,11 +478,20 @@ static PyObject *M_Window_FileSelector( PyObject * self, PyObject * args )
Script *script = NULL;
int startspace = 0;
- if( (!PyArg_ParseTuple( args, "O|ss", &EXPP_FS_PyCallback, &title, &filename ) )
+ if (during_scriptlink())
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "script links can't call the file selector");
+
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "the file selector is not available in background mode");
+
+ if((!PyArg_ParseTuple( args, "O|ss", &EXPP_FS_PyCallback, &title, &filename))
|| (!PyCallable_Check(EXPP_FS_PyCallback)))
return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "\nexpected a callback function (and optionally one or two strings) "
- "as argument(s)" );
+ "\nexpected a callback function (and optionally one or two strings) "
+ "as argument(s)" );
+
Py_XINCREF(EXPP_FS_PyCallback);
/* trick: we move to a spacescript because then the fileselector will properly
@@ -528,12 +537,21 @@ static PyObject *M_Window_ImageSelector( PyObject * self, PyObject * args )
Script *script = NULL;
int startspace = 0;
+ if (during_scriptlink())
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "script links can't call the image selector");
+
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "the image selector is not available in background mode");
+
if( !PyArg_ParseTuple( args, "O|ss", &EXPP_FS_PyCallback, &title, &filename )
|| (!PyCallable_Check(EXPP_FS_PyCallback)))
return ( EXPP_ReturnPyObjError
( PyExc_AttributeError,
"\nexpected a callback function (and optionally one or two strings) "
"as argument(s)" ) );
+
Py_XINCREF(EXPP_FS_PyCallback);
/* trick: we move to a spacescript because then the fileselector will properly
@@ -581,6 +599,10 @@ static PyObject *M_Window_DrawProgressBar( PyObject * self, PyObject * args )
char *info = NULL;
int retval = 0;
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "the progress bar is not available in background mode");
+
if( !PyArg_ParseTuple( args, "fs", &done, &info ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected a float and a string as arguments" ) );
@@ -964,6 +986,10 @@ static PyObject *M_Window_QRead( PyObject * self )
short val = 0;
unsigned short event;
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "QRead is not available in background mode");
+
event = extern_qread( &val );
return Py_BuildValue( "ii", event, val );
@@ -976,6 +1002,10 @@ static PyObject *M_Window_QAdd( PyObject * self, PyObject * args )
short val;
short after = 0;
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "QAdd is not available in background mode");
+
if( !PyArg_ParseTuple( args, "hhh|h", &win, &evt, &val, &after ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected three or four ints as arguments" );
@@ -998,6 +1028,10 @@ static PyObject *M_Window_QHandle( PyObject * self, PyObject * args )
ScrArea *sa = G.curscreen->areabase.first;
ScrArea *oldsa = NULL;
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "QHandle is not available in background mode");
+
if( !PyArg_ParseTuple( args, "h", &win ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected an int as argument" );
@@ -1153,7 +1187,7 @@ static PyObject *M_Window_SetScreen( PyObject * self, PyObject * args )
if( !scr )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "no such screen, check Window.GetScreens() for valid names." );
+ "no such screen, check Window.GetScreens() for valid names" );
return EXPP_incr_ret( Py_None );
}
diff --git a/source/blender/python/api2_2x/doc/API_intro.py b/source/blender/python/api2_2x/doc/API_intro.py
index 1c910711d46..8f4031756f2 100644
--- a/source/blender/python/api2_2x/doc/API_intro.py
+++ b/source/blender/python/api2_2x/doc/API_intro.py
@@ -67,22 +67,29 @@ Introduction:
Scripting and Blender:
======================
-There are four basic ways to execute scripts in Blender:
+These are the basic ways to execute scripts in Blender:
1. They can be loaded or typed as text files in the Text Editor window, then
executed with ALT+P.
- 2. Via command line: 'blender -P <scriptname>' will start Blender and executed
+ 2. Via command line: C{blender -P <scriptname>} will start Blender and execute
the given script. <scriptname> can be a filename in the user's file system or
the name of a text saved in a .blend Blender file:
'blender myfile.blend -P textname'.
- 3. Properly registered scripts can be selected directly from the program's
+ 3. Via command line in I{background mode}: use the '-b' flag (the order is
+ important): C{blender -b <blendfile> -P <scriptname>}. <blendfile> can be any
+ .blend file, including the default .B.blend that is in Blender's home dir
+ L{Blender.Get}('homedir'). In this mode no window will be opened and the
+ program will leave as soon as the script finishes execution.
+ 4. Properly registered scripts can be selected directly from the program's
menus.
- 4. Scriptlinks: these are also loaded or typed in the Text Editor window and
+ 5. Scriptlinks: these are also loaded or typed in the Text Editor window and
can be linked to objects, materials or scenes using the Scriptlink buttons
tab. Script links get executed automatically when their events (ONLOAD,
REDRAW, FRAMECHANGED) are triggered. Normal scripts can create (L{Text}) and
link other scripts to objects and events, see L{Object.Object.addScriptLink},
for example.
+ 6. A script can call another script (that will run in its own context, with
+ its own global dictionary) with the L{Blender.Run} module function.
Registering scripts:
--------------------
@@ -148,6 +155,7 @@ Interaction with users:
program buttons, which stay there accepting user input like any other
Blender window until the user closes them;
- make changes to the 3D View (set visible layer(s), view point, etc);
+ - tell Blender to execute other scripts (see L{Blender.Run}());
- use external Python libraries, if available.
You can read the documentation for the L{Window}, L{Draw} and L{BGL} modules
@@ -161,16 +169,56 @@ Command line mode:
Python was embedded in Blender, so to access bpython modules you need to
run scripts from the program itself: you can't import the Blender module
- into an external Python interpreter. But with "OnLoad" script links, the
- "-b" background mode and additions like the "-P" command line switch,
- L{Blender.Save}, L{Blender.Load}, L{Blender.Quit} and the L{Library} module,
- for many tasks it's possible to control Blender via some automated process
- using scripts. Note that command line scripts are run before Blender
- initializes its windows, so many functions that get or set window related
- attributes (like most in L{Window}) don't work here. If you need those, use
- an ONLOAD script link (see L{Scene.Scene.addScriptLink}) instead -- it's
- also possible to use a command line script to write or set an ONLOAD script
- link.
+ into an external Python interpreter.
+
+ But with "OnLoad" script links, the "-b" background mode and additions like
+ the "-P" command line switch, L{Blender.Save}, L{Blender.Load},
+ L{Blender.Quit} and the L{Library} module, for many tasks it's possible to
+ control Blender via some automated process using scripts. Note that command
+ line scripts are run before Blender initializes its windows (and in '-b' mode
+ no window will be initialized), so many functions that get or set window
+ related attributes (like most in L{Window}) don't work here. If you need
+ those, use an ONLOAD script link (see L{Scene.Scene.addScriptLink}) instead --
+ it's also possible to use a command line script to write or set an ONLOAD
+ script link. Check the L{Blender.mode} module var to know if Blender is being
+ executed in "background" or "interactive" mode.
+
+ Background mode examples::
+
+ # Open Blender in background mode with file 'myfile.blend'
+ # and run the script 'script.py':
+
+ blender -b myfile.blend -P script.py
+
+ # Note: a .blend file is always required. 'script.py' can be a file
+ # in the file system or a Blender Text stored in 'myfile.blend'.
+
+ # Let's assume 'script.py' has code to render the current frame;
+ # this line will set the [s]tart and [e]nd (and so the current) frame to
+ # frame 44 and call the script:
+
+ blender -b myfile.blend -s 44 -e 44 -P script.py
+
+ # Using now a script written to render animations, we set different
+ # start and end frames and then execute this line:
+
+ blender -b myfile.blend -s 1 -e 10 -P script.py
+
+ # Note: we can also set frames and define if we want a single image or
+ # an animation in the script body itself, naturally.
+
+ The rendered pictures will be written to the default render folder, that can
+ also be set via bpython (take a look at L{Render.RenderData}). Their
+ names will be the equivalent frame number followed by the extension of the
+ chosen image type: 0001.png, for example. To rename them to something else,
+ coders can use the C{rename} function in the standard 'os' Python module.
+
+ Reminder: if you just need to render, it's not necessary to have a script.
+ Blender can create stills and animations with its own command line arguments.
+ Example:
+ - a single image at frame 44: blender -b myfile.blend -f 44
+ - an animation from frame 1 to 10: blender -b myfile.blend -s 1 -e 10 -a
+
Demo mode:
----------
@@ -263,7 +311,7 @@ Documenting scripts:
Example::
__author__ = 'Mr. Author'
- __version__ = '1.0 11/11/04'
+ __version__ = '1.0 2005/06/06'
__url__ = ["Author's site, http://somewhere.com",
"Support forum, http://somewhere.com/forum/", "blender", "elysiun"]
__email__ = ["Mr. Author, mrauthor:somewhere*com", "scripts"]
@@ -294,9 +342,10 @@ A note to newbie script writers:
Interpreted languages are known to be much slower than compiled code, but for
many applications the difference is negligible or acceptable. Also, with
- profiling to identify slow areas and well thought optimizations, the speed
- can be I{considerably} improved in many cases. Try some of the best bpython
- scripts to get an idea of what can be done, you may be surprised.
+ profiling (or even simple direct timing with L{Blender.sys.time<Sys.time>}) to
+ identify slow areas and well thought optimizations, the speed can be
+ I{considerably} improved in many cases. Try some of the best bpython scripts
+ to get an idea of what can be done, you may be surprised.
@author: The Blender Python Team
@requires: Blender 2.35 or newer.
diff --git a/source/blender/python/api2_2x/doc/Blender.py b/source/blender/python/api2_2x/doc/Blender.py
index 14ca8e8505d..d22536c24a8 100644
--- a/source/blender/python/api2_2x/doc/Blender.py
+++ b/source/blender/python/api2_2x/doc/Blender.py
@@ -10,10 +10,27 @@
"""
The main Blender module.
-B{New}: L{UpdateMenus}.
+B{New}: L{Run}, L{UpdateMenus}, new options to L{Get}.
Blender
=======
+
+@type bylink: bool
+@var bylink: True if the current script is being executed as a script link.
+@type link: Blender Object or None
+@var link: if this script is a running script link, 'link' points to the
+ linked Object (can be a scene, object (mesh, camera, lamp), material or
+ world). If this is not a script link, 'link' is None.
+@type event: string
+@var event: if this script is a running script link, 'event' tells what
+ kind of link triggered it (ex: OnLoad, FrameChanged, Redraw, etc.).
+@type mode: string
+@var mode: Blender's current mode:
+ - 'interactive': normal mode, with an open window answering to user input;
+ - 'background': Blender was started as 'C{blender -b <blender file>}' and
+ will exit as soon as it finishes rendering or executing a script
+ (ex: 'C{blender -b <blender file> -P <script>}'). Try 'C{blender -h}'
+ for more detailed informations.
"""
def Set (request, data):
@@ -31,21 +48,25 @@ def Get (request):
Retrieve settings from Blender.
@type request: string
@param request: The setting data to be returned:
- - 'curframe': the current animation frame
- - 'curtime' : the current animation time
- - 'staframe': the start frame of the animation
- - 'endframe': the end frame of the animation
- - 'filename': the name of the last file read or written
- - 'homedir': Blender's home dir
+ - 'curframe': the current animation frame.
+ - 'curtime' : the current animation time.
+ - 'staframe': the start frame of the animation.
+ - 'endframe': the end frame of the animation.
+ - 'filename': the name of the last file read or written.
+ - 'homedir': Blender's home dir.
- 'datadir' : the path to the dir where scripts should store and
retrieve their data files, including saved configuration (can
be None, if not found).
+ - 'udatadir': the path to the user defined data dir. This may not be
+ available (is None if not found), but users that define uscriptsdir
+ have a place for their own scripts and script data that won't be
+ erased when a new version of Blender is installed.
- 'scriptsdir': the path to the main dir where scripts are stored
(can be None, if not found).
- 'uscriptsdir': the path to the user defined dir for scripts, see
the paths tab in the User Preferences window in Blender
(can be None, if not found).
- - 'version' : the Blender version number
+ - 'version' : the Blender version number.
@return: The requested data.
"""
@@ -108,6 +129,17 @@ def Save (filename, overwrite = 0):
@note: DXF, STL and Videoscape export only B{selected} meshes.
"""
+def Run (script):
+ """
+ Execute the given script.
+ @type script: string
+ @param script: the name of an available Blender Text (use L{Text.Get}() to
+ get a complete list) or the full pathname to a Python script file in the
+ system.
+ @note: the script is executed in its own context (with its own global
+ dictionary), as if you had called it with ALT+P or chosen from a menu.
+ """
+
def UpdateMenus ():
"""
Update the menus that list registered scripts. This will scan the default
diff --git a/source/blender/python/api2_2x/doc/NMesh.py b/source/blender/python/api2_2x/doc/NMesh.py
index 07c86cbbf55..8b5be59b38f 100644
--- a/source/blender/python/api2_2x/doc/NMesh.py
+++ b/source/blender/python/api2_2x/doc/NMesh.py
@@ -4,7 +4,8 @@
The Blender.NMesh submodule.
B{New}: edges class (L{NMEdge}) and nmesh methods (L{NMesh.addEdge},
-L{NMesh.addEdgesData}, etc.); new optional arguments to L{NMesh.update}.
+L{NMesh.addEdgesData}, etc.); new optional arguments to L{NMesh.update};
+L{NMesh.transform}.
Mesh Data
=========
@@ -154,16 +155,16 @@ def GetRawFromObject(name):
be created.
"""
-def PutRaw(nmesh, name = None, recalculate_normals = 1, store_edges = 0):
+def PutRaw(nmesh, name = None, recalc_normals = 1, store_edges = 0):
"""
Put an NMesh object back in Blender.
@type nmesh: NMesh
@type name: string
- @type recalculate_normals: int
+ @type recalc_normals: int
@type store_edges: int
@param name: The name of the mesh data object in Blender which will receive
this nmesh data. It can be an existing mesh data object or a new one.
- @param recalculate_normals: If non-zero, the vertex normals for the mesh will
+ @param recalc_normals: If non-zero, the vertex normals for the mesh will
be recalculated.
@param store_edges: if non-zero, the edges data are stored
@rtype: None or Object
@@ -339,9 +340,10 @@ class NMesh:
def addEdge(v1, v2):
"""
Create an edge between two vertices.
- If an edge already exists between those vertices, it is returned. (in blender, only zero or one edge can link two vertices).
+ If an edge already exists between those vertices, it is returned.
Created edge is automatically added to edges list.
You can only call this method if mesh has edge data.
+ @note: In Blender only zero or one edge can link two vertices.
@type v1: NMVert
@param v1: the first vertex of the edge.
@type v2: NMVert
@@ -552,8 +554,10 @@ class NMesh:
@param store_edges: if nonzero, then edge data is stored.
@type vertex_shade: int (bool)
@param vertex_shade: if nonzero vertices are colored based on the
- current lighting setup. To use it, be out of edit mode or else
- an error will be returned.
+ current lighting setup, like when there are no vertex colors and no
+ textured faces and a user enters Vertex Paint Mode in Blender (only
+ lamps in visible layers account). To use this functionality, be out of
+ edit mode or else an error will be returned.
@warn: edit mesh and normal mesh are two different structures in Blender,
synchronized upon leaving or entering edit mode. Always remember to
leave edit mode (L{Window.EditMode}) before calling this update
@@ -568,6 +572,41 @@ class NMesh:
L{setMode}) need their display lists updated, too.
"""
+ def transform(matrix, recalc_normals = False):
+ """
+ Transforms the mesh by the specified 4x4 matrix, as returned by
+ L{Object.Object.getMatrix}, though this will work with any invertible 4x4
+ matrix type. Ideal Usage for this is exporting to an external file, where
+ global vertex locations are required for each object.
+ Sometimes external renderers / file formats do not use vertex normals.
+ In this case you can skip transforming the vertex normals by letting
+ the optional parameter recalc_normals as False or 0.
+
+ Example::
+ # This script outputs deformed meshes worldspace vertex locations
+ # for a selected object
+ import Blender
+ from Blender import NMesh, Object
+
+ ob = Object.GetSelected()[0] # Get the first selected object
+ me = NMesh.GetRawFromObject(ob) # Get the objects deformed mesh data
+ me.transform(ob.matrix)
+
+ for v in me.verts:
+ print 'worldspace vert', v.co
+
+ @type matrix: Py_Matrix
+ @param matrix: 4x4 Matrix which can contain location, scale and rotation.
+ @type recalc_normals: int (bool)
+ @param recalc_normals: if True or 1, will only transform vertex locations.
+ @warn: if you call this method and later L{update} the mesh, the new
+ vertex positions will be passed back to Blender, but the object
+ matrix of each object linked to this mesh won't be automatically
+ updated. You need to set the object transformations (rotation,
+ translation and scaling) to identities, then, or the mesh data will
+ be changed ("transformed twice").
+ """
+
def getMode():
"""
Get this mesh's mode flags.
diff --git a/source/blender/python/api2_2x/doc/Window.py b/source/blender/python/api2_2x/doc/Window.py
index e6a81e9afde..0b41a3038c7 100644
--- a/source/blender/python/api2_2x/doc/Window.py
+++ b/source/blender/python/api2_2x/doc/Window.py
@@ -8,8 +8,6 @@ Window
This module provides access to B{Window} functions in Blender.
-B{New}: L{GetPerspMatrix}.
-
Example:
--------
@@ -133,6 +131,11 @@ def FileSelector (callback, title = 'SELECT FILE', filename = '<default>'):
and return from the file selection window.
@type filename: string
@param filename: A filename. This defaults to Blender.Get('filename').
+ @warn: script links are not allowed to call the File / Image Selectors. This
+ is because script links global dictionaries are removed when they finish
+ execution and the File Selector needs the passed callback to stay around.
+ An alternative is calling the File Selector from another script (see
+ L{Blender.Run}).
"""
def ImageSelector (callback, title = 'SELECT IMAGE', filename = '<default>'):
@@ -153,7 +156,12 @@ def ImageSelector (callback, title = 'SELECT IMAGE', filename = '<default>'):
@param title: The string that appears in the button to confirm the selection
and return from the image selection window.
@type filename: string
- @param filename: A filename. This defaults to Blender.Get('filename').
+ @param filename: A filename. This defaults to L{Blender.Get}('filename').
+ @warn: script links are not allowed to call the File / Image Selectors. This
+ is because script links global dictionaries are removed when they finish
+ execution and the File Selector needs the passed callback to stay around.
+ An alternative is calling the File Selector from another script (see
+ L{Blender.Run}).
"""
def DrawProgressBar (done, text):
diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c
index 685adb67b46..b8e8f92b83e 100644
--- a/source/blender/python/api2_2x/gen_utils.c
+++ b/source/blender/python/api2_2x/gen_utils.c
@@ -282,6 +282,14 @@ int EXPP_map_getStrVal( const EXPP_map_pair * map, int ival,
return 0;
}
+/* Redraw wrappers */
+
+/* this queues redraws if we're not in background mode: */
+void EXPP_allqueue(unsigned short event, short val)
+{
+ if (!G.background) allqueue(event, val);
+}
+
/************************************************************************/
/* Scriptlink-related functions, used by scene, object, etc. bpyobjects */
/************************************************************************/
diff --git a/source/blender/python/api2_2x/gen_utils.h b/source/blender/python/api2_2x/gen_utils.h
index 6baf76c9ee5..e2c1dfe82a0 100644
--- a/source/blender/python/api2_2x/gen_utils.h
+++ b/source/blender/python/api2_2x/gen_utils.h
@@ -94,4 +94,7 @@ PyObject *EXPP_getScriptLinks( ScriptLink * slink, PyObject * args,
int EXPP_clearScriptLinks( ScriptLink * slink );
int EXPP_addScriptLink( ScriptLink * slink, PyObject * args, int is_scene );
+/* this queues redraws if we're not in background mode: */
+void EXPP_allqueue(unsigned short event, short val);
+
#endif /* EXPP_gen_utils_h */
diff --git a/source/blender/python/api2_2x/sceneRender.c b/source/blender/python/api2_2x/sceneRender.c
index 70d0c676dcd..f5de8a1c4d5 100644
--- a/source/blender/python/api2_2x/sceneRender.c
+++ b/source/blender/python/api2_2x/sceneRender.c
@@ -43,6 +43,7 @@
#include <mydevice.h>
#include <butspace.h>
#include <BKE_bad_level_calls.h>
+#include <render.h> /* RE_animrender() */
#include "sceneRender.h"
#include "blendef.h"
#include "Scene.h"
@@ -524,6 +525,7 @@ PyTypeObject RenderData_Type = {
0, 0, 0, 0, 0, 0,
BPy_RenderData_methods, /* tp_methods */
0, /* tp_members */
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
//---------------------------------------------------Render Module Init--
PyObject *Render_Init( void )
@@ -639,7 +641,7 @@ static PyObject *M_Render_BitToggleInt( PyObject * args, int setting,
*structure |= setting;
else
*structure &= ~setting;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
@@ -665,7 +667,7 @@ static PyObject *M_Render_BitToggleShort( PyObject * args, short setting,
*structure |= setting;
else
*structure &= ~setting;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
@@ -692,7 +694,7 @@ static PyObject *M_Render_GetSetAttributeFloat( PyObject * args,
}
*structure = property;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
} else
return Py_BuildValue( "f", *structure );
@@ -719,7 +721,7 @@ static PyObject *M_Render_GetSetAttributeShort( PyObject * args,
}
*structure = property;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
} else
return Py_BuildValue( "h", *structure );
@@ -745,7 +747,7 @@ static PyObject *M_Render_GetSetAttributeInt( PyObject * args, int *structure,
}
*structure = property;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
} else
return Py_BuildValue( "i", *structure );
@@ -768,8 +770,8 @@ static void M_Render_DoSizePreset( BPy_RenderData * self, short xsch,
self->renderContext->yparts = yparts;
BLI_init_rctf( &self->renderContext->safety, a, b, c, d );
- allqueue( REDRAWBUTSSCENE, 0 );
- allqueue( REDRAWVIEWCAM, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWVIEWCAM, 0 );
}
//------------------------------------Render Module Function Definitions-
@@ -819,7 +821,7 @@ PyObject *M_Render_SetRenderWinPos( PyObject * self, PyObject * args )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"list contains unknown string\n" );
}
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -828,7 +830,7 @@ PyObject *M_Render_SetRenderWinPos( PyObject * self, PyObject * args )
PyObject *M_Render_EnableDispView( PyObject * self )
{
G.displaymode = R_DISPLAYVIEW;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -837,7 +839,7 @@ PyObject *M_Render_EnableDispView( PyObject * self )
PyObject *M_Render_EnableDispWin( PyObject * self )
{
G.displaymode = R_DISPLAYWIN;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -861,10 +863,28 @@ PyObject *RenderData_Render( BPy_RenderData * self )
{
Scene *oldsce;
- oldsce = G.scene;
- set_scene( self->scene );
- BIF_do_render( 0 );
- set_scene( oldsce );
+ if (!G.background) {
+ oldsce = G.scene;
+ set_scene( self->scene );
+ BIF_do_render( 0 );
+ set_scene( oldsce );
+ }
+
+ else { /* background mode (blender -b file.blend -P script) */
+
+ int end_frame = G.scene->r.efra; /* is of type short currently */
+
+ if (G.scene != self->scene)
+ return EXPP_ReturnPyObjError (PyExc_RuntimeError,
+ "scene to render in bg mode must be the active scene");
+
+ G.scene->r.efra = G.scene->r.sfra;
+
+ RE_animrender(NULL);
+
+ G.scene->r.efra = end_frame;
+ }
+
return EXPP_incr_ret( Py_None );
}
@@ -873,10 +893,22 @@ PyObject *RenderData_RenderAnim( BPy_RenderData * self )
{
Scene *oldsce;
- oldsce = G.scene;
- set_scene( self->scene );
- BIF_do_render( 1 );
- set_scene( oldsce );
+ if (!G.background) {
+ oldsce = G.scene;
+ set_scene( self->scene );
+ BIF_do_render( 1 );
+ set_scene( oldsce );
+ }
+ else { /* background mode (blender -b file.blend -P script) */
+ if (G.scene != self->scene)
+ return EXPP_ReturnPyObjError (PyExc_RuntimeError,
+ "scene to render in bg mode must be the active scene");
+
+ if (G.scene->r.sfra > G.scene->r.efra)
+ return EXPP_ReturnPyObjError (PyExc_RuntimeError,
+ "start frame must be less or equal to end frame");
+ RE_animrender(NULL);
+ }
return EXPP_incr_ret( Py_None );
}
@@ -950,7 +982,7 @@ PyObject *RenderData_SetRenderPath( BPy_RenderData * self, PyObject * args )
"path is too long (SetRenderPath)" ) );
strcpy( self->renderContext->pic, name );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -976,7 +1008,7 @@ PyObject *RenderData_SetBackbufPath( BPy_RenderData * self, PyObject * args )
"path is too long (SetBackbufPath)" ) );
strcpy( self->renderContext->backbuf, name );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
ima = add_image( name );
if( ima ) {
@@ -1014,7 +1046,7 @@ PyObject *RenderData_SetFtypePath( BPy_RenderData * self, PyObject * args )
"path is too long (SetFtypePath)" ) );
strcpy( self->renderContext->ftype, name );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1132,7 +1164,7 @@ PyObject *RenderData_SetOversamplingLevel( BPy_RenderData * self,
"expected 5,8,11, or 16" ) );
self->renderContext->osa = level;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1172,7 +1204,7 @@ PyObject *RenderData_PartsY( BPy_RenderData * self, PyObject * args )
PyObject *RenderData_EnableSky( BPy_RenderData * self )
{
self->renderContext->alphamode = R_ADDSKY;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1181,7 +1213,7 @@ PyObject *RenderData_EnableSky( BPy_RenderData * self )
PyObject *RenderData_EnablePremultiply( BPy_RenderData * self )
{
self->renderContext->alphamode = R_ALPHAPREMUL;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1190,7 +1222,7 @@ PyObject *RenderData_EnablePremultiply( BPy_RenderData * self )
PyObject *RenderData_EnableKey( BPy_RenderData * self )
{
self->renderContext->alphamode = R_ALPHAKEY;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1246,7 +1278,7 @@ PyObject *RenderData_SetRenderWinSize( BPy_RenderData * self, PyObject * args )
"expected 25, 50, 75, or 100" ) );
self->renderContext->size = size;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1328,7 +1360,7 @@ PyObject *RenderData_SetBorder( BPy_RenderData * self, PyObject * args )
self->renderContext->border.xmax = xmax;
self->renderContext->border.ymax = ymax;
- allqueue( REDRAWVIEWCAM, 1 );
+ EXPP_allqueue( REDRAWVIEWCAM, 1 );
return EXPP_incr_ret( Py_None );
}
@@ -1415,7 +1447,7 @@ PyObject *RenderData_SetRenderer( BPy_RenderData * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected INTERN or YAFRAY" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1467,7 +1499,7 @@ PyObject *RenderData_SetImageType( BPy_RenderData * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"unknown constant - see modules dict for help" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1491,7 +1523,7 @@ PyObject *RenderData_FramesPerSec( BPy_RenderData * self, PyObject * args )
PyObject *RenderData_EnableGrayscale( BPy_RenderData * self )
{
self->renderContext->planes = R_PLANESBW;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1500,7 +1532,7 @@ PyObject *RenderData_EnableGrayscale( BPy_RenderData * self )
PyObject *RenderData_EnableRGBColor( BPy_RenderData * self )
{
self->renderContext->planes = R_PLANES24;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1509,7 +1541,7 @@ PyObject *RenderData_EnableRGBColor( BPy_RenderData * self )
PyObject *RenderData_EnableRGBAColor( BPy_RenderData * self )
{
self->renderContext->planes = R_PLANES32;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1583,7 +1615,7 @@ PyObject *RenderData_SizePreset( BPy_RenderData * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"unknown constant - see modules dict for help" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1613,7 +1645,7 @@ PyObject *RenderData_SetYafrayGIQuality( BPy_RenderData * self,
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"unknown constant - see modules dict for help" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1633,7 +1665,7 @@ PyObject *RenderData_SetYafrayGIMethod( BPy_RenderData * self,
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"unknown constant - see modules dict for help" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}