2003-02-26 19:22:24 +00:00
|
|
|
/*
|
2004-09-25 20:30:40 +00:00
|
|
|
* $Id$
|
2003-02-26 19:22:24 +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-06-24 09:43:13 +00:00
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2003-02-26 19:22:24 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This is a new part of Blender.
|
|
|
|
|
*
|
2004-02-29 13:20:34 +00:00
|
|
|
* Contributor(s): Michel Selten, Willian P. Germano, Alex Mole, Joseph Gilbert
|
2003-02-26 19:22:24 +00:00
|
|
|
*
|
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2003-05-17 04:29:49 +00:00
|
|
|
#ifndef EXPP_gen_utils_h
|
|
|
|
|
#define EXPP_gen_utils_h
|
|
|
|
|
|
2003-05-31 04:43:10 +00:00
|
|
|
#include <Python.h>
|
Mathutils update
- also included is some fixes for preprocessor inclues and some clean up of the previous commit
-rewrite and bugfixes
----------------------------------
Here's my changelog:
-fixed Rand() so that it doesn't seed everytime and should generate better random numbers
- changed a few error return types to something more appropriate
- clean up of uninitialized variables & removal of unneccessary objects
- NMesh returns wrapped vectors now
- World returns wrapped matrices now
- Object.getEuler() and Object.getBoundingBox() return Wrapped data when data is present
- Object.getMatrix() returns wrapped data if it's worldspace, 'localspace' returns a new matrix
- Vector, Euler, Mat, Quat, call all now internally wrap object without destroying internal datablocks
- Removed memory allocation (unneeded) from all methods
- Vector's resize methods are only applicable to new vectors not wrapped data.
- Matrix(), Quat(), Euler(), Vector() now accepts ANY sequence list, including tuples, list, or a self object to copy - matrices accept multiple sequences
- Fixed Slerp() so that it now works correctly values are clamped between 0 and 1
- Euler.rotate does internal rotation now
- Slice assignment now works better for all types
- Vector * Vector and Quat * Quat are defined and return the DOT product
- Mat * Vec and Vec * Mat are defined now
- Moved #includes to .c file from headers. Also fixed prototypes in mathutils
- Added new helper functions for incref'ing to genutils
- Major cleanup of header files includes - include Mathutils.h for access to math types
- matrix.toQuat() and .toEuler() now fixed take appropriate matrix sizes
- Matrix() with no parameters now returns an identity matrix by default not a zero matrix
- printf() now prints with 6 digits instead of 4
- printf() now prints output with object descriptor
- Matrices now support [x][y] assignment (e.g. matrix[x][y] = 5.4)
- Matrix[index] = value now expectes a sequence not an integer. This will now set a ROW of the matrix through a sequence. index cannot go above the row size of the matrix.
- slice operations on matrices work with sequences now (rows of the matrix) example: mymatrix[0:2] returns a list of 2 wrapped vectors with access to the matrix data.
- slice assignment will no longer modify the data if the assignment operation fails
- fixed error in matrix * scalar multiplication
- euler.toMatrix(), toQuat() no longer causes "creep" from repeated use
- Wrapped data will generate wrapped objects when toEuler(), toQuat(), toMatrix() is used
- Quats can be created with angle/axis, axis/angle
- 4x4 matrices can be multiplied by 3D vectors (by popular demand :))
- vec *quat / quat * vec is now defined
- vec.magnitude alias for vec.length
- all self, internal methods return a pointer to self now so you can do print vector.internalmethod() or vector.internalmethod().nextmethod() (no more print matrix.inverse() returning 'none')
- these methods have been deprecated (still functioning but suggested to use the corrected functionality):
* CopyVec() - replaced by Vector() functionality
* CopyMat() - replaced by Matrix() functionality
* CopyQuat() - replace by Quaternion() functionality
* CopyEuler() - replaced by Euler() functionality
* RotateEuler() - replaced by Euler.rotate() funtionality
* MatMultVec() - replaced by matrix * vector
* VecMultMat() - replaced by vector * matrix
- New struct containers references to python object data or internally allocated blender data for wrapping
* Explaination here: math structs now function as a 'simple wrapper' or a 'py_object' - data that is created on the fly will now be a 'py_object' with its memory managed by python
* otherwise if the data is returned by blender's G.main then the math object is a 'simple wrapper' and data can be accessed directly from the struct just like other python objects.
2005-07-14 03:34:56 +00:00
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
#include "DNA_scriptlink_types.h"
|
|
|
|
|
#include "DNA_listBase.h"
|
2003-03-15 19:14:16 +00:00
|
|
|
|
2005-09-21 19:48:40 +00:00
|
|
|
#include "constant.h"
|
|
|
|
|
|
2004-02-29 13:20:34 +00:00
|
|
|
#define Py_PI 3.14159265358979323846
|
Mathutils update
- also included is some fixes for preprocessor inclues and some clean up of the previous commit
-rewrite and bugfixes
----------------------------------
Here's my changelog:
-fixed Rand() so that it doesn't seed everytime and should generate better random numbers
- changed a few error return types to something more appropriate
- clean up of uninitialized variables & removal of unneccessary objects
- NMesh returns wrapped vectors now
- World returns wrapped matrices now
- Object.getEuler() and Object.getBoundingBox() return Wrapped data when data is present
- Object.getMatrix() returns wrapped data if it's worldspace, 'localspace' returns a new matrix
- Vector, Euler, Mat, Quat, call all now internally wrap object without destroying internal datablocks
- Removed memory allocation (unneeded) from all methods
- Vector's resize methods are only applicable to new vectors not wrapped data.
- Matrix(), Quat(), Euler(), Vector() now accepts ANY sequence list, including tuples, list, or a self object to copy - matrices accept multiple sequences
- Fixed Slerp() so that it now works correctly values are clamped between 0 and 1
- Euler.rotate does internal rotation now
- Slice assignment now works better for all types
- Vector * Vector and Quat * Quat are defined and return the DOT product
- Mat * Vec and Vec * Mat are defined now
- Moved #includes to .c file from headers. Also fixed prototypes in mathutils
- Added new helper functions for incref'ing to genutils
- Major cleanup of header files includes - include Mathutils.h for access to math types
- matrix.toQuat() and .toEuler() now fixed take appropriate matrix sizes
- Matrix() with no parameters now returns an identity matrix by default not a zero matrix
- printf() now prints with 6 digits instead of 4
- printf() now prints output with object descriptor
- Matrices now support [x][y] assignment (e.g. matrix[x][y] = 5.4)
- Matrix[index] = value now expectes a sequence not an integer. This will now set a ROW of the matrix through a sequence. index cannot go above the row size of the matrix.
- slice operations on matrices work with sequences now (rows of the matrix) example: mymatrix[0:2] returns a list of 2 wrapped vectors with access to the matrix data.
- slice assignment will no longer modify the data if the assignment operation fails
- fixed error in matrix * scalar multiplication
- euler.toMatrix(), toQuat() no longer causes "creep" from repeated use
- Wrapped data will generate wrapped objects when toEuler(), toQuat(), toMatrix() is used
- Quats can be created with angle/axis, axis/angle
- 4x4 matrices can be multiplied by 3D vectors (by popular demand :))
- vec *quat / quat * vec is now defined
- vec.magnitude alias for vec.length
- all self, internal methods return a pointer to self now so you can do print vector.internalmethod() or vector.internalmethod().nextmethod() (no more print matrix.inverse() returning 'none')
- these methods have been deprecated (still functioning but suggested to use the corrected functionality):
* CopyVec() - replaced by Vector() functionality
* CopyMat() - replaced by Matrix() functionality
* CopyQuat() - replace by Quaternion() functionality
* CopyEuler() - replaced by Euler() functionality
* RotateEuler() - replaced by Euler.rotate() funtionality
* MatMultVec() - replaced by matrix * vector
* VecMultMat() - replaced by vector * matrix
- New struct containers references to python object data or internally allocated blender data for wrapping
* Explaination here: math structs now function as a 'simple wrapper' or a 'py_object' - data that is created on the fly will now be a 'py_object' with its memory managed by python
* otherwise if the data is returned by blender's G.main then the math object is a 'simple wrapper' and data can be accessed directly from the struct just like other python objects.
2005-07-14 03:34:56 +00:00
|
|
|
#define Py_WRAP 1024
|
|
|
|
|
#define Py_NEW 2048
|
2004-02-29 13:20:34 +00:00
|
|
|
|
2005-11-22 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
Py_RETURN_NONE
|
|
|
|
|
Python 2.4 macro.
|
|
|
|
|
defined here until we switch to 2.4
|
|
|
|
|
*/
|
|
|
|
|
#ifndef Py_RETURN_NONE
|
|
|
|
|
#define Py_RETURN_NONE Py_INCREF( Py_None ); return Py_None
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-11-22 17:59:49 +00:00
|
|
|
int EXPP_FloatsAreEqual(float A, float B, int floatSteps);
|
|
|
|
|
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
|
|
|
|
|
|
2005-08-17 14:26:00 +00:00
|
|
|
PyObject *EXPP_GetModuleConstant(char *module, char *constant);
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
int StringEqual( const char *string1, const char *string2 );
|
|
|
|
|
char *GetIdName( ID * id );
|
|
|
|
|
ID *GetIdFromList( ListBase * list, char *name );
|
2003-05-17 04:29:49 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *PythonReturnErrorObject( PyObject * type, char *error_msg );
|
|
|
|
|
PyObject *PythonIncRef( PyObject * object );
|
2003-05-17 04:29:49 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
char *event_to_name( short event );
|
2003-05-17 04:29:49 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
float EXPP_ClampFloat( float value, float min, float max );
|
|
|
|
|
int EXPP_ClampInt( int value, int min, int max );
|
2003-05-17 04:29:49 +00:00
|
|
|
|
Mathutils update
- also included is some fixes for preprocessor inclues and some clean up of the previous commit
-rewrite and bugfixes
----------------------------------
Here's my changelog:
-fixed Rand() so that it doesn't seed everytime and should generate better random numbers
- changed a few error return types to something more appropriate
- clean up of uninitialized variables & removal of unneccessary objects
- NMesh returns wrapped vectors now
- World returns wrapped matrices now
- Object.getEuler() and Object.getBoundingBox() return Wrapped data when data is present
- Object.getMatrix() returns wrapped data if it's worldspace, 'localspace' returns a new matrix
- Vector, Euler, Mat, Quat, call all now internally wrap object without destroying internal datablocks
- Removed memory allocation (unneeded) from all methods
- Vector's resize methods are only applicable to new vectors not wrapped data.
- Matrix(), Quat(), Euler(), Vector() now accepts ANY sequence list, including tuples, list, or a self object to copy - matrices accept multiple sequences
- Fixed Slerp() so that it now works correctly values are clamped between 0 and 1
- Euler.rotate does internal rotation now
- Slice assignment now works better for all types
- Vector * Vector and Quat * Quat are defined and return the DOT product
- Mat * Vec and Vec * Mat are defined now
- Moved #includes to .c file from headers. Also fixed prototypes in mathutils
- Added new helper functions for incref'ing to genutils
- Major cleanup of header files includes - include Mathutils.h for access to math types
- matrix.toQuat() and .toEuler() now fixed take appropriate matrix sizes
- Matrix() with no parameters now returns an identity matrix by default not a zero matrix
- printf() now prints with 6 digits instead of 4
- printf() now prints output with object descriptor
- Matrices now support [x][y] assignment (e.g. matrix[x][y] = 5.4)
- Matrix[index] = value now expectes a sequence not an integer. This will now set a ROW of the matrix through a sequence. index cannot go above the row size of the matrix.
- slice operations on matrices work with sequences now (rows of the matrix) example: mymatrix[0:2] returns a list of 2 wrapped vectors with access to the matrix data.
- slice assignment will no longer modify the data if the assignment operation fails
- fixed error in matrix * scalar multiplication
- euler.toMatrix(), toQuat() no longer causes "creep" from repeated use
- Wrapped data will generate wrapped objects when toEuler(), toQuat(), toMatrix() is used
- Quats can be created with angle/axis, axis/angle
- 4x4 matrices can be multiplied by 3D vectors (by popular demand :))
- vec *quat / quat * vec is now defined
- vec.magnitude alias for vec.length
- all self, internal methods return a pointer to self now so you can do print vector.internalmethod() or vector.internalmethod().nextmethod() (no more print matrix.inverse() returning 'none')
- these methods have been deprecated (still functioning but suggested to use the corrected functionality):
* CopyVec() - replaced by Vector() functionality
* CopyMat() - replaced by Matrix() functionality
* CopyQuat() - replace by Quaternion() functionality
* CopyEuler() - replaced by Euler() functionality
* RotateEuler() - replaced by Euler.rotate() funtionality
* MatMultVec() - replaced by matrix * vector
* VecMultMat() - replaced by vector * matrix
- New struct containers references to python object data or internally allocated blender data for wrapping
* Explaination here: math structs now function as a 'simple wrapper' or a 'py_object' - data that is created on the fly will now be a 'py_object' with its memory managed by python
* otherwise if the data is returned by blender's G.main then the math object is a 'simple wrapper' and data can be accessed directly from the struct just like other python objects.
2005-07-14 03:34:56 +00:00
|
|
|
void EXPP_incr2( PyObject * ob1, PyObject * ob2 );
|
|
|
|
|
void EXPP_incr3( PyObject * ob1, PyObject * ob2, PyObject * ob3 );
|
|
|
|
|
void EXPP_decr2( PyObject * ob1, PyObject * ob2 );
|
|
|
|
|
void EXPP_decr3( PyObject * ob1, PyObject * ob2, PyObject * ob3 );
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *EXPP_incr_ret( PyObject * object );
|
2005-02-09 15:53:35 +00:00
|
|
|
PyObject *EXPP_incr_ret_True(void);
|
|
|
|
|
PyObject *EXPP_incr_ret_False(void);
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *EXPP_ReturnPyObjError( PyObject * type, char *error_msg );
|
|
|
|
|
int EXPP_ReturnIntError( PyObject * type, char *error_msg );
|
2003-02-26 19:22:24 +00:00
|
|
|
|
2005-08-17 14:26:00 +00:00
|
|
|
PyObject *EXPP_objError(PyObject *type, const char *format, ...);
|
|
|
|
|
int EXPP_intError(PyObject *type, const char *format, ...);
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
int EXPP_check_sequence_consistency( PyObject * seq, PyTypeObject * against );
|
|
|
|
|
PyObject *EXPP_tuple_repr( PyObject * self, int size );
|
2003-05-17 04:29:49 +00:00
|
|
|
|
2003-11-23 17:46:06 +00:00
|
|
|
/* mapping utilities - see Texture.c for an example of how to use these */
|
|
|
|
|
typedef struct {
|
- 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
|
|
|
const char *sval;
|
|
|
|
|
int ival;
|
2003-11-23 17:46:06 +00:00
|
|
|
} EXPP_map_pair;
|
|
|
|
|
|
|
|
|
|
/* maps must end with a pair that has NULL as sval */
|
2004-09-25 20:30:40 +00:00
|
|
|
int EXPP_map_getIntVal( const EXPP_map_pair * map,
|
|
|
|
|
const char *sval, int *ival );
|
|
|
|
|
int EXPP_map_case_getIntVal( const EXPP_map_pair * map,
|
|
|
|
|
const char *sval, int *ival );
|
|
|
|
|
int EXPP_map_getShortVal( const EXPP_map_pair * map,
|
|
|
|
|
const char *sval, short *ival );
|
|
|
|
|
int EXPP_map_getStrVal( const EXPP_map_pair * map,
|
|
|
|
|
int ival, const char **sval );
|
2004-06-24 09:43:13 +00:00
|
|
|
|
2005-08-27 18:44:56 +00:00
|
|
|
/* clamping and range-checking utilities */
|
|
|
|
|
|
2005-09-21 19:48:40 +00:00
|
|
|
int EXPP_setIValueClamped( PyObject *value, void *param,
|
|
|
|
|
int min, int max, char type );
|
2005-08-27 18:44:56 +00:00
|
|
|
int EXPP_setFloatClamped ( PyObject *value, float *param,
|
|
|
|
|
float min, float max);
|
2005-09-21 19:48:40 +00:00
|
|
|
int EXPP_setIValueRange( PyObject *value, void *param,
|
|
|
|
|
int min, int max, char type );
|
2005-08-27 18:44:56 +00:00
|
|
|
int EXPP_setFloatRange ( PyObject *value, float *param,
|
|
|
|
|
float min, float max);
|
|
|
|
|
|
2005-09-21 19:48:40 +00:00
|
|
|
/* utility routine for PyType attributes setters with module constant */
|
|
|
|
|
|
|
|
|
|
int EXPP_setModuleConstant ( BPy_constant *constant, void *param,
|
|
|
|
|
char type );
|
|
|
|
|
|
|
|
|
|
/* utilities to get/set bits in bitfields */
|
|
|
|
|
|
|
|
|
|
PyObject *EXPP_getBitfield( void *param, int setting, char type );
|
|
|
|
|
int EXPP_setBitfield( PyObject * value, void *param, int setting, char type );
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Procedures to handle older setStuff() methods, which now access
|
|
|
|
|
* a PyType's setter attributes using the tp_getset mechanism.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
PyObject *EXPP_setterWrapper ( PyObject * self, PyObject * args,
|
|
|
|
|
setter func);
|
|
|
|
|
|
|
|
|
|
PyObject *EXPP_setterWrapperTuple ( PyObject * self, PyObject * args,
|
|
|
|
|
setter func);
|
|
|
|
|
|
2004-06-24 09:43:13 +00:00
|
|
|
/* scriplinks-related: */
|
2005-04-21 19:44:52 +00:00
|
|
|
PyObject *EXPP_getScriptLinks(ScriptLink *slink, PyObject *args, int is_scene);
|
|
|
|
|
PyObject *EXPP_addScriptLink(ScriptLink *slink, PyObject *args, int is_scene);
|
|
|
|
|
PyObject *EXPP_clearScriptLinks(ScriptLink *slink, PyObject *args);
|
2003-11-23 17:46:06 +00:00
|
|
|
|
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.
2005-03-19 06:24:55 +00:00
|
|
|
/* this queues redraws if we're not in background mode: */
|
|
|
|
|
void EXPP_allqueue(unsigned short event, short val);
|
|
|
|
|
|
2005-11-30 08:18:06 +00:00
|
|
|
/* helper to keep dictionaries from causing memory leaks */
|
|
|
|
|
int EXPP_dict_set_item_str( PyObject *dict, char *key, PyObject *value);
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
#endif /* EXPP_gen_utils_h */
|
2005-08-27 18:44:56 +00:00
|
|
|
|