2009-06-02 07:40:32 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
#include "BKE_customdata.h"
|
|
|
|
|
#include "DNA_listBase.h"
|
|
|
|
|
#include "DNA_customdata_types.h"
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_DerivedMesh.h"
|
|
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_editVert.h"
|
|
|
|
|
#include "mesh_intern.h"
|
|
|
|
|
#include "ED_mesh.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_arithb.h"
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_edgehash.h"
|
|
|
|
|
|
|
|
|
|
#include "bmesh.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* UTILS.C
|
|
|
|
|
*
|
|
|
|
|
* utility bmesh operators, e.g. transform,
|
|
|
|
|
* translate, rotate, scale, etc.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2009-06-18 03:04:27 +00:00
|
|
|
void bmesh_makevert_exec(BMesh *bm, BMOperator *op) {
|
|
|
|
|
float vec[3];
|
|
|
|
|
|
|
|
|
|
BMO_Get_Vec(op, "co", vec);
|
|
|
|
|
|
|
|
|
|
BMO_SetFlag(bm, BM_Make_Vert(bm, vec, NULL), 1);
|
|
|
|
|
BMO_Flag_To_Slot(bm, op, "newvertout", 1, BM_VERT);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-02 07:40:32 +00:00
|
|
|
void bmesh_transform_exec(BMesh *bm, BMOperator *op) {
|
|
|
|
|
BMOIter iter;
|
|
|
|
|
BMVert *v;
|
|
|
|
|
float mat[4][4];
|
|
|
|
|
|
|
|
|
|
BMO_Get_Mat4(op, "mat", mat);
|
|
|
|
|
|
2009-06-23 05:35:49 +00:00
|
|
|
BMO_ITER(v, &iter, bm, op, "verts", BM_VERT) {
|
2009-06-02 07:40:32 +00:00
|
|
|
Mat4MulVecfl(mat, v->co);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*this operator calls the transform operator, which
|
|
|
|
|
is a little complex, but makes it easier to make
|
|
|
|
|
sure the transform op is working, since initially
|
|
|
|
|
only this one will be used.*/
|
|
|
|
|
void bmesh_translate_exec(BMesh *bm, BMOperator *op) {
|
|
|
|
|
float mat[4][4], vec[3];
|
|
|
|
|
|
2009-06-18 02:05:56 +00:00
|
|
|
BMO_Get_Vec(op, "vec", vec);
|
2009-06-02 07:40:32 +00:00
|
|
|
|
|
|
|
|
Mat4One(mat);
|
|
|
|
|
VECCOPY(mat[3], vec);
|
|
|
|
|
|
|
|
|
|
BMO_CallOpf(bm, "transform mat=%m4 verts=%s", mat, op, "verts");
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-18 02:05:56 +00:00
|
|
|
void bmesh_rotate_exec(BMesh *bm, BMOperator *op) {
|
2009-07-26 14:58:31 +00:00
|
|
|
float vec[3];
|
2009-06-18 02:05:56 +00:00
|
|
|
|
|
|
|
|
BMO_Get_Vec(op, "cent", vec);
|
|
|
|
|
|
|
|
|
|
/*there has to be a proper matrix way to do this, but
|
|
|
|
|
this is how editmesh did it and I'm too tired to think
|
|
|
|
|
through the math right now.*/
|
|
|
|
|
VecMulf(vec, -1);
|
|
|
|
|
BMO_CallOpf(bm, "translate verts=%s vec=%v", op, "verts", vec);
|
|
|
|
|
|
|
|
|
|
BMO_CallOpf(bm, "transform mat=%s verts=%s", op, "mat", op, "verts");
|
|
|
|
|
|
|
|
|
|
VecMulf(vec, -1);
|
|
|
|
|
BMO_CallOpf(bm, "translate verts=%s vec=%v", op, "verts", vec);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-22 02:57:40 +00:00
|
|
|
void bmesh_reversefaces_exec(BMesh *bm, BMOperator *op) {
|
2009-07-26 14:58:31 +00:00
|
|
|
BMOIter siter;
|
2009-07-22 02:57:40 +00:00
|
|
|
BMFace *f;
|
|
|
|
|
|
2009-07-26 14:58:31 +00:00
|
|
|
BMO_ITER(f, &siter, bm, op, "faces", BM_FACE) {
|
2009-07-22 02:57:40 +00:00
|
|
|
BM_flip_normal(bm, f);
|
|
|
|
|
}
|
2009-07-26 14:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void bmesh_edgerotate_exec(BMesh *bm, BMOperator *op) {
|
|
|
|
|
BMOIter siter;
|
|
|
|
|
BMEdge *e, *e2;
|
|
|
|
|
int ccw = BMO_Get_Int(op, "ccw");
|
|
|
|
|
|
|
|
|
|
BMO_ITER(e, &siter, bm, op, "edges", BM_EDGE) {
|
|
|
|
|
if (!(e2 = BM_Rotate_Edge(bm, e, ccw))) {
|
|
|
|
|
BMO_RaiseError(bm, op, BMERR_INVALID_SELECTION, "Could not rotate edge");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BMO_SetFlag(bm, e2, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BMO_Flag_To_Slot(bm, op, "edgeout", 1, BM_EDGE);
|
|
|
|
|
}
|