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:
authorCampbell Barton <ideasman42@gmail.com>2007-04-05 11:45:11 +0400
committerCampbell Barton <ideasman42@gmail.com>2007-04-05 11:45:11 +0400
commit985fb03478f518282040d36885bbb8cc1dcacfca (patch)
treefeb1d762dc05768853e8bf4f121714a1b9f01f7b /source/blender/python
parent581970a64000e7637c5edfc6dfa852bc354d0cee (diff)
* Changed mesh so all new data is selected (fits in with blender's UI and other areas of Python API), this could break existing scripts that count on new data being unselected (unlikely)
* Added a keyword argument to mesh.transform() - "selected_only" so you can transform the selected verts. this wont break existing scripts. * Documented these changes in epydocs. * used these functions in BPyAddMesh
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/api2_2x/Mesh.c78
-rw-r--r--source/blender/python/api2_2x/doc/Mesh.py7
2 files changed, 56 insertions, 29 deletions
diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c
index 2711c23965d..e32124b47fa 100644
--- a/source/blender/python/api2_2x/Mesh.c
+++ b/source/blender/python/api2_2x/Mesh.c
@@ -1777,7 +1777,8 @@ static PyObject *MVertSeq_extend( BPy_MVertSeq * self, PyObject *args )
/* add the coordinate to the new list */
memcpy( tmpvert->co, co, sizeof(co) );
-
+
+ tmpvert->flag |= SELECT;
/* TODO: anything else which needs to be done when we add a vert? */
/* probably not: NMesh's newvert() doesn't */
++tmpvert;
@@ -2928,7 +2929,7 @@ static PyObject *MEdgeSeq_extend( BPy_MEdgeSeq * self, PyObject *args )
tmpedge->v1 = tmppair->v[1];
tmpedge->v2 = tmppair->v[0];
}
- tmpedge->flag = ME_EDGEDRAW | ME_EDGERENDER;
+ tmpedge->flag = ME_EDGEDRAW | ME_EDGERENDER | SELECT;
mesh->totedge++;
--good_edges;
++tmpedge;
@@ -4969,7 +4970,7 @@ static PyObject *MFaceSeq_extend( BPy_MEdgeSeq * self, PyObject *args,
tmpface->v3 = tmppair->v[index[2]];
tmpface->v4 = tmppair->v[index[3]];
- tmpface->flag = 0;
+ tmpface->flag = ME_FACE_SEL;
if( return_list )
PyList_Append( return_list,
@@ -5807,30 +5808,51 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args )
* WARNING: unlike NMesh, this method ALWAYS changes the original mesh
*/
-static PyObject *Mesh_transform( BPy_Mesh *self, PyObject *args )
+static PyObject *Mesh_transform( BPy_Mesh *self, PyObject *args, PyObject *kwd )
{
Mesh *mesh = self->mesh;
- MVert *mv;
- PyObject *ob1 = NULL;
- MatrixObject *mat;
- 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" ) );
+ MVert *mvert;
+ /*PyObject *pymat = NULL;*/
+ MatrixObject *bpymat=NULL;
+ int i, recalc_normals = 0, selected_only = 0;
- mat = ( MatrixObject * ) ob1;
+ static char *kwlist[] = {"matrix", "recalc_normals", "selected_only", NULL};
+
+ if( !PyArg_ParseTupleAndKeywords(args, kwd, "|O!ii", kwlist,
+ &matrix_Type, &bpymat, &recalc_normals, &selected_only) ) {
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "matrix must be a 4x4 transformation matrix\n"
+ "for example as returned by object.matrixWorld\n"
+ "and optionaly keyword bools, recalc_normals and selected_only\n");
+ }
+
+ if (!bpymat)
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "the first argument must be a matrix or\n"
+ "matrix passed as a keyword argument\n");
+
+
+ /*bpymat = ( MatrixObject * ) pymat;*/
- if( mat->colSize != 4 || mat->rowSize != 4 )
+ if( bpymat->colSize != 4 || bpymat->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 by the supplied matrix */
- mv = mesh->mvert;
- for( i = 0; i < mesh->totvert; i++, mv++ )
- Mat4MulVecfl( (float(*)[4])*mat->matrix, mv->co );
-
+ mvert = mesh->mvert;
+ if (selected_only) {
+ for( i = 0; i < mesh->totvert; i++, mvert++ ) {
+ if (mvert->flag & SELECT) {
+ Mat4MulVecfl( (float(*)[4])*bpymat->matrix, mvert->co );
+ }
+ }
+ } else {
+ for( i = 0; i < mesh->totvert; i++, mvert++ ) {
+ Mat4MulVecfl( (float(*)[4])*bpymat->matrix, mvert->co );
+ }
+ }
+
if( recalc_normals ) {
/* loop through all the verts and transform normals by the inverse
* of the transpose of the supplied matrix */
@@ -5841,7 +5863,7 @@ static PyObject *Mesh_transform( BPy_Mesh *self, PyObject *args )
* affine vectors is 0, but Mat4Invert reports non invertible matrices
*/
- if (!Mat4Invert((float(*)[4])*invmat, (float(*)[4])*mat->matrix))
+ if (!Mat4Invert((float(*)[4])*invmat, (float(*)[4])*bpymat->matrix))
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"given matrix is not invertible");
@@ -5849,18 +5871,18 @@ static PyObject *Mesh_transform( BPy_Mesh *self, PyObject *args )
* since normal is stored as shorts, convert to float
*/
- mv = mesh->mvert;
- for( i = 0; i < mesh->totvert; i++, mv++ ) {
- nx= vec[0] = (float)(mv->no[0] / 32767.0);
- ny= vec[1] = (float)(mv->no[1] / 32767.0);
- nz= vec[2] = (float)(mv->no[2] / 32767.0);
+ mvert = mesh->mvert;
+ for( i = 0; i < mesh->totvert; i++, mvert++ ) {
+ nx= vec[0] = (float)(mvert->no[0] / 32767.0);
+ ny= vec[1] = (float)(mvert->no[1] / 32767.0);
+ nz= vec[2] = (float)(mvert->no[2] / 32767.0);
vec[0] = nx*invmat[0][0] + ny*invmat[0][1] + nz*invmat[0][2];
vec[1] = nx*invmat[1][0] + ny*invmat[1][1] + nz*invmat[1][2];
vec[2] = nx*invmat[2][0] + ny*invmat[2][1] + nz*invmat[2][2];
Normalize( vec );
- mv->no[0] = (short)(vec[0] * 32767.0);
- mv->no[1] = (short)(vec[1] * 32767.0);
- mv->no[2] = (short)(vec[2] * 32767.0);
+ mvert->no[0] = (short)(vec[0] * 32767.0);
+ mvert->no[1] = (short)(vec[1] * 32767.0);
+ mvert->no[2] = (short)(vec[2] * 32767.0);
}
}
@@ -6953,7 +6975,7 @@ static struct PyMethodDef BPy_Mesh_methods[] = {
"Get a mesh by name"},
{"update", (PyCFunction)Mesh_Update, METH_NOARGS,
"Update display lists after changes to mesh"},
- {"transform", (PyCFunction)Mesh_transform, METH_VARARGS,
+ {"transform", (PyCFunction)Mesh_transform, METH_VARARGS | METH_KEYWORDS,
"Applies a transformation matrix to mesh's vertices"},
{"addVertGroup", (PyCFunction)Mesh_addVertGroup, METH_VARARGS,
"Assign vertex group name to the object linked to the mesh"},
diff --git a/source/blender/python/api2_2x/doc/Mesh.py b/source/blender/python/api2_2x/doc/Mesh.py
index 5ee6871558d..a89f075e7f6 100644
--- a/source/blender/python/api2_2x/doc/Mesh.py
+++ b/source/blender/python/api2_2x/doc/Mesh.py
@@ -301,6 +301,7 @@ class MVertSeq:
Append zero or more vertices to the mesh. Unlike L{MEdgeSeq.extend()} and
L{MFaceSeq.extend()} no attempt is made to check for duplicate vertices in
the parameter list, or for vertices already in the mesh.
+ @note: Since Blender 2.44 all new verts are selected.
Example::
import Blender
@@ -405,6 +406,7 @@ class MEdgeSeq:
mesh or with both vertices the same are ignored. If three or four verts
are specified in any sequence, an edge is also created between the first
and last vertices (this is useful when adding faces).
+ @note: Since Blender 2.44 all new edges are selected.
Example::
import Blender
@@ -638,6 +640,7 @@ class MFaceSeq:
in the mesh, or faces which contain the same vertex multiple times are
ignored. Sequences of two vertices are accepted, but no face will be
created.
+ @note: Since Blender 2.44 all new faces are selected.
Example::
import Blender
@@ -824,7 +827,7 @@ class Mesh:
@note: Only returns a valid result for mesh data that has no holes.
"""
- def transform(matrix, recalc_normals = False):
+ def transform(matrix, recalc_normals = False, selected_only=False):
"""
Transforms the mesh by the specified 4x4 matrix (such as returned by
L{Object.Object.getMatrix}). The matrix should be invertible.
@@ -853,6 +856,8 @@ class Mesh:
@param matrix: 4x4 Matrix which can contain location, scale and rotation.
@type recalc_normals: int
@param recalc_normals: if True or 1, also transform vertex normals.
+ @type selected_only: int
+ @param selected_only: if True or 1, only the selected verts will be transformed.
@warn: unlike L{NMesh.transform()<NMesh.NMesh.transform>}, this method
I{will immediately modify the mesh data} when it is used. If you
transform the mesh using the object's matrix to get the vertices'