2009-03-02 02:21:18 +00:00
|
|
|
/* $Id: bmeshutils.c
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL 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.
|
|
|
|
*
|
|
|
|
* 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,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2004 by Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): Joseph Eagar
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
Created a printf-style method of calling operators. I did this to cut down on duplicated
code, and also because calling operators was such a pain. The basic form of the format
is "opname %[code]", where each % matches to an argument.
The codes are fairly simple:
d - int
i - int
f - float
h[v/e/f] - all verts/edges/faces with a certain header flag.
f[v/e/f] - all verts/edges/faces with a certain flag.
For example:
EDBM_CallOpf(em, op, "dissolveverts %hv", BM_SELECT)
will call the dissolve verts operator.
The relevent functions are:
//calls a bmesh operator, doing necassary conversions and error reporting.
int EDBM_CallOpf(EditMesh *em, struct wmOperator *op, char *fmt, ...);
//execute an operator
int BMO_CallOpf(BMesh *bm, char *fmt, ...);
//initializes but doesn't execute an op.
int BMO_InitOpf(BMesh *bm, BMOperator *op, char *fmt, ...);
//vlist version of above.
int BMO_VInitOpf(BMesh *bm, BMOperator *op, char *fmt, va_list vlist);
Note this system is dependant on getting the slot codes from the argument
order. I'd like to make it better, possibly pass in slot names, but that'd
mean actually giving the slots names (which I can do, but wanted to discuss with
Briggs and others what I have now first).
2009-03-02 04:08:24 +00:00
|
|
|
#include <stdarg.h>
|
2009-03-02 02:21:18 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "PIL_time.h"
|
|
|
|
|
|
|
|
#include "BLO_sys_types.h" // for intptr_t support
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
#include "DNA_key_types.h"
|
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
|
|
|
|
#include "RNA_types.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_arithb.h"
|
|
|
|
#include "BLI_editVert.h"
|
|
|
|
#include "BLI_rand.h"
|
|
|
|
#include "BLI_ghash.h"
|
|
|
|
#include "BLI_linklist.h"
|
|
|
|
#include "BLI_heap.h"
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_customdata.h"
|
|
|
|
#include "BKE_depsgraph.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
#include "BKE_object.h"
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
#include "BKE_bmesh.h"
|
|
|
|
#include "BKE_report.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
#include "BKE_tessmesh.h"
|
2009-03-02 02:21:18 +00:00
|
|
|
|
|
|
|
#include "BIF_gl.h"
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "ED_mesh.h"
|
|
|
|
#include "ED_view3d.h"
|
|
|
|
#include "ED_util.h"
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
|
|
|
#include "mesh_intern.h"
|
|
|
|
#include "bmesh.h"
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
void EDBM_RecalcNormals(BMEditMesh *em)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2009-05-18 14:55:34 +00:00
|
|
|
BM_Compute_Normals(em->bm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EDBM_stats_update(BMEditMesh *em)
|
|
|
|
{
|
|
|
|
BMIter iter;
|
|
|
|
BMHeader *ele;
|
|
|
|
int types[3] = {BM_VERTS_OF_MESH, BM_EDGES_OF_MESH, BM_FACES_OF_MESH};
|
|
|
|
int *tots[3];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
tots[0] = &em->bm->totvertsel;
|
|
|
|
tots[1] = &em->bm->totedgesel;
|
|
|
|
tots[2] = &em->bm->totfacesel;
|
|
|
|
|
|
|
|
em->bm->totvertsel = em->bm->totedgesel = em->bm->totfacesel = 0;
|
|
|
|
|
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
ele = BMIter_New(&iter, em->bm, types[i], NULL);
|
|
|
|
for ( ; ele; ele=BMIter_Step(&iter)) {
|
|
|
|
if (BM_TestHFlag(ele, BM_SELECT)) {
|
|
|
|
*tots[i]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*this function is defunct, dead*/
|
2009-03-06 06:06:14 +00:00
|
|
|
void EDBM_Tesselate(EditMesh *em)
|
|
|
|
{
|
|
|
|
EditMesh *em2;
|
|
|
|
EditFace *efa;
|
|
|
|
BMesh *bm;
|
|
|
|
int found=0;
|
|
|
|
|
|
|
|
for (efa=em->faces.first; efa; efa=efa->next) {
|
|
|
|
if ((efa->e1->h & EM_FGON) || (efa->e2->h & EM_FGON) ||
|
|
|
|
(efa->e3->h & EM_FGON) || (efa->e4&&(efa->e4->h&EM_FGON)))
|
|
|
|
{
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
bm = editmesh_to_bmesh(em);
|
|
|
|
em2 = bmesh_to_editmesh(bm);
|
|
|
|
set_editMesh(em, em2);
|
|
|
|
|
|
|
|
MEM_freeN(em2);
|
|
|
|
BM_Free_Mesh(bm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 04:41:02 +00:00
|
|
|
int EDBM_InitOpf(BMEditMesh *em, BMOperator *bmop, wmOperator *op, char *fmt, ...)
|
|
|
|
{
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (!BMO_VInitOpf(bm, bmop, fmt, list)) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR,
|
|
|
|
"Parse error in EDBM_CallOpf");
|
|
|
|
va_end(list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-18 07:11:55 +00:00
|
|
|
em->emcopy = BMEdit_Copy(em);
|
|
|
|
|
2009-05-28 04:41:02 +00:00
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*returns 0 on error, 1 on success. executes and finishes a bmesh operator*/
|
|
|
|
int EDBM_FinishOp(BMEditMesh *em, BMOperator *bmop, wmOperator *op, int report) {
|
|
|
|
char *errmsg;
|
|
|
|
|
|
|
|
BMO_Finish_Op(em->bm, bmop);
|
|
|
|
|
|
|
|
if (BMO_GetError(em->bm, &errmsg, NULL)) {
|
2009-06-18 07:11:55 +00:00
|
|
|
BMEditMesh *emcopy = em->emcopy;
|
2009-05-28 04:41:02 +00:00
|
|
|
|
|
|
|
if (report) BKE_report(op->reports, RPT_ERROR, errmsg);
|
2009-06-18 07:11:55 +00:00
|
|
|
|
|
|
|
BMEdit_Free(em);
|
|
|
|
*em = *emcopy;
|
2009-06-18 07:15:17 +00:00
|
|
|
|
|
|
|
MEM_freeN(emcopy);
|
2009-05-28 04:41:02 +00:00
|
|
|
return 0;
|
2009-06-18 07:11:55 +00:00
|
|
|
} else {
|
|
|
|
BMEdit_Free(em->emcopy);
|
|
|
|
MEM_freeN(em->emcopy);
|
|
|
|
em->emcopy = NULL;
|
2009-05-28 04:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-19 00:33:54 +00:00
|
|
|
int EDBM_CallOpf(BMEditMesh *em, wmOperator *op, char *fmt, ...)
|
Created a printf-style method of calling operators. I did this to cut down on duplicated
code, and also because calling operators was such a pain. The basic form of the format
is "opname %[code]", where each % matches to an argument.
The codes are fairly simple:
d - int
i - int
f - float
h[v/e/f] - all verts/edges/faces with a certain header flag.
f[v/e/f] - all verts/edges/faces with a certain flag.
For example:
EDBM_CallOpf(em, op, "dissolveverts %hv", BM_SELECT)
will call the dissolve verts operator.
The relevent functions are:
//calls a bmesh operator, doing necassary conversions and error reporting.
int EDBM_CallOpf(EditMesh *em, struct wmOperator *op, char *fmt, ...);
//execute an operator
int BMO_CallOpf(BMesh *bm, char *fmt, ...);
//initializes but doesn't execute an op.
int BMO_InitOpf(BMesh *bm, BMOperator *op, char *fmt, ...);
//vlist version of above.
int BMO_VInitOpf(BMesh *bm, BMOperator *op, char *fmt, va_list vlist);
Note this system is dependant on getting the slot codes from the argument
order. I'd like to make it better, possibly pass in slot names, but that'd
mean actually giving the slots names (which I can do, but wanted to discuss with
Briggs and others what I have now first).
2009-03-02 04:08:24 +00:00
|
|
|
{
|
2009-05-19 00:33:54 +00:00
|
|
|
BMesh *bm = em->bm;
|
Created a printf-style method of calling operators. I did this to cut down on duplicated
code, and also because calling operators was such a pain. The basic form of the format
is "opname %[code]", where each % matches to an argument.
The codes are fairly simple:
d - int
i - int
f - float
h[v/e/f] - all verts/edges/faces with a certain header flag.
f[v/e/f] - all verts/edges/faces with a certain flag.
For example:
EDBM_CallOpf(em, op, "dissolveverts %hv", BM_SELECT)
will call the dissolve verts operator.
The relevent functions are:
//calls a bmesh operator, doing necassary conversions and error reporting.
int EDBM_CallOpf(EditMesh *em, struct wmOperator *op, char *fmt, ...);
//execute an operator
int BMO_CallOpf(BMesh *bm, char *fmt, ...);
//initializes but doesn't execute an op.
int BMO_InitOpf(BMesh *bm, BMOperator *op, char *fmt, ...);
//vlist version of above.
int BMO_VInitOpf(BMesh *bm, BMOperator *op, char *fmt, va_list vlist);
Note this system is dependant on getting the slot codes from the argument
order. I'd like to make it better, possibly pass in slot names, but that'd
mean actually giving the slots names (which I can do, but wanted to discuss with
Briggs and others what I have now first).
2009-03-02 04:08:24 +00:00
|
|
|
BMOperator bmop;
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (!BMO_VInitOpf(bm, &bmop, fmt, list)) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR,
|
|
|
|
"Parse error in EDBM_CallOpf");
|
|
|
|
va_end(list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-18 07:11:55 +00:00
|
|
|
em->emcopy = BMEdit_Copy(em);
|
|
|
|
|
Created a printf-style method of calling operators. I did this to cut down on duplicated
code, and also because calling operators was such a pain. The basic form of the format
is "opname %[code]", where each % matches to an argument.
The codes are fairly simple:
d - int
i - int
f - float
h[v/e/f] - all verts/edges/faces with a certain header flag.
f[v/e/f] - all verts/edges/faces with a certain flag.
For example:
EDBM_CallOpf(em, op, "dissolveverts %hv", BM_SELECT)
will call the dissolve verts operator.
The relevent functions are:
//calls a bmesh operator, doing necassary conversions and error reporting.
int EDBM_CallOpf(EditMesh *em, struct wmOperator *op, char *fmt, ...);
//execute an operator
int BMO_CallOpf(BMesh *bm, char *fmt, ...);
//initializes but doesn't execute an op.
int BMO_InitOpf(BMesh *bm, BMOperator *op, char *fmt, ...);
//vlist version of above.
int BMO_VInitOpf(BMesh *bm, BMOperator *op, char *fmt, va_list vlist);
Note this system is dependant on getting the slot codes from the argument
order. I'd like to make it better, possibly pass in slot names, but that'd
mean actually giving the slots names (which I can do, but wanted to discuss with
Briggs and others what I have now first).
2009-03-02 04:08:24 +00:00
|
|
|
BMO_Exec_Op(bm, &bmop);
|
|
|
|
|
|
|
|
va_end(list);
|
2009-06-18 07:11:55 +00:00
|
|
|
return EDBM_FinishOp(em, &bmop, op, 1);
|
Printf-style method of calling operations now take a modified format string,
like so:
[opname] [slotname]=%[format code]
Before it was relying on the input format codes being in the same proper
order as the slots, which seemed like a potential maintainance nightmare to
me. Also the flags for creating buffers from bmop flags or header flags,
now support additional modifiers for combining vert/edge/face inputs.
E.g. %hfvef would accept all geometry with a header flag, and
%fef would accept edges and faces with a certain bmop flag set.
Example from the UI code:
if (!EDBM_CallOpf(em, op, "del geom=%hf context=%d", BM_SELECT, DEL_ONLYFACES))
return OPERATOR_CANCELLED;
(remember EDBM_CallOpf is the UI wrapper for this that does conversion,
error reporting, etc).
On todo is cleaning up/splitting bmesh_operators.h,
since it's kindof a mesh right now. I'm thinking of adding the slot
names in comments next to the slot ids, but I definitely would have to
clean up bmesh_operators.h first, or it'd just be too chaotic for me.
BTW, the operator API should now have enough meta info to wrap with
a scripting language, not that it matters since that's not happening till
much much later.
Also hopefully corrected some SConscripts, fix mostly provided by Elia Sarti,
though I also copied some SConscripts from 2.5 (not sure if doing
so was especially helpful).
Finally, I refactored a few places to use the new operator calling api,
as an example of how this is beneficial.
2009-03-04 08:21:10 +00:00
|
|
|
}
|
|
|
|
|
2009-05-19 00:33:54 +00:00
|
|
|
int EDBM_CallOpfSilent(BMEditMesh *em, char *fmt, ...)
|
Printf-style method of calling operations now take a modified format string,
like so:
[opname] [slotname]=%[format code]
Before it was relying on the input format codes being in the same proper
order as the slots, which seemed like a potential maintainance nightmare to
me. Also the flags for creating buffers from bmop flags or header flags,
now support additional modifiers for combining vert/edge/face inputs.
E.g. %hfvef would accept all geometry with a header flag, and
%fef would accept edges and faces with a certain bmop flag set.
Example from the UI code:
if (!EDBM_CallOpf(em, op, "del geom=%hf context=%d", BM_SELECT, DEL_ONLYFACES))
return OPERATOR_CANCELLED;
(remember EDBM_CallOpf is the UI wrapper for this that does conversion,
error reporting, etc).
On todo is cleaning up/splitting bmesh_operators.h,
since it's kindof a mesh right now. I'm thinking of adding the slot
names in comments next to the slot ids, but I definitely would have to
clean up bmesh_operators.h first, or it'd just be too chaotic for me.
BTW, the operator API should now have enough meta info to wrap with
a scripting language, not that it matters since that's not happening till
much much later.
Also hopefully corrected some SConscripts, fix mostly provided by Elia Sarti,
though I also copied some SConscripts from 2.5 (not sure if doing
so was especially helpful).
Finally, I refactored a few places to use the new operator calling api,
as an example of how this is beneficial.
2009-03-04 08:21:10 +00:00
|
|
|
{
|
2009-05-19 00:33:54 +00:00
|
|
|
BMesh *bm = em->bm;
|
Printf-style method of calling operations now take a modified format string,
like so:
[opname] [slotname]=%[format code]
Before it was relying on the input format codes being in the same proper
order as the slots, which seemed like a potential maintainance nightmare to
me. Also the flags for creating buffers from bmop flags or header flags,
now support additional modifiers for combining vert/edge/face inputs.
E.g. %hfvef would accept all geometry with a header flag, and
%fef would accept edges and faces with a certain bmop flag set.
Example from the UI code:
if (!EDBM_CallOpf(em, op, "del geom=%hf context=%d", BM_SELECT, DEL_ONLYFACES))
return OPERATOR_CANCELLED;
(remember EDBM_CallOpf is the UI wrapper for this that does conversion,
error reporting, etc).
On todo is cleaning up/splitting bmesh_operators.h,
since it's kindof a mesh right now. I'm thinking of adding the slot
names in comments next to the slot ids, but I definitely would have to
clean up bmesh_operators.h first, or it'd just be too chaotic for me.
BTW, the operator API should now have enough meta info to wrap with
a scripting language, not that it matters since that's not happening till
much much later.
Also hopefully corrected some SConscripts, fix mostly provided by Elia Sarti,
though I also copied some SConscripts from 2.5 (not sure if doing
so was especially helpful).
Finally, I refactored a few places to use the new operator calling api,
as an example of how this is beneficial.
2009-03-04 08:21:10 +00:00
|
|
|
BMOperator bmop;
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (!BMO_VInitOpf(bm, &bmop, fmt, list)) {
|
|
|
|
va_end(list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-18 07:11:55 +00:00
|
|
|
em->emcopy = BMEdit_Copy(em);
|
|
|
|
|
Printf-style method of calling operations now take a modified format string,
like so:
[opname] [slotname]=%[format code]
Before it was relying on the input format codes being in the same proper
order as the slots, which seemed like a potential maintainance nightmare to
me. Also the flags for creating buffers from bmop flags or header flags,
now support additional modifiers for combining vert/edge/face inputs.
E.g. %hfvef would accept all geometry with a header flag, and
%fef would accept edges and faces with a certain bmop flag set.
Example from the UI code:
if (!EDBM_CallOpf(em, op, "del geom=%hf context=%d", BM_SELECT, DEL_ONLYFACES))
return OPERATOR_CANCELLED;
(remember EDBM_CallOpf is the UI wrapper for this that does conversion,
error reporting, etc).
On todo is cleaning up/splitting bmesh_operators.h,
since it's kindof a mesh right now. I'm thinking of adding the slot
names in comments next to the slot ids, but I definitely would have to
clean up bmesh_operators.h first, or it'd just be too chaotic for me.
BTW, the operator API should now have enough meta info to wrap with
a scripting language, not that it matters since that's not happening till
much much later.
Also hopefully corrected some SConscripts, fix mostly provided by Elia Sarti,
though I also copied some SConscripts from 2.5 (not sure if doing
so was especially helpful).
Finally, I refactored a few places to use the new operator calling api,
as an example of how this is beneficial.
2009-03-04 08:21:10 +00:00
|
|
|
BMO_Exec_Op(bm, &bmop);
|
|
|
|
|
|
|
|
va_end(list);
|
2009-06-18 07:11:55 +00:00
|
|
|
return EDBM_FinishOp(em, &bmop, NULL, 0);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EDBM_MakeEditBMesh(Scene *scene, Object *ob)
|
|
|
|
{
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
EditMesh *em;
|
|
|
|
BMesh *bm;
|
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
if (!me->mpoly && me->totface) {
|
|
|
|
em = make_editMesh(scene, ob);
|
|
|
|
bm = editmesh_to_bmesh(em);
|
|
|
|
|
|
|
|
free_editMesh(em);
|
|
|
|
} else {
|
|
|
|
bm = BKE_mesh_to_bmesh(me);
|
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
me->edit_btmesh = BMEdit_Create(bm);
|
2009-07-16 06:27:37 +00:00
|
|
|
me->edit_btmesh->selectmode = scene->toolsettings->selectmode;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EDBM_LoadEditBMesh(Scene *scene, Object *ob)
|
|
|
|
{
|
|
|
|
Mesh *me = ob->data;
|
2009-05-26 04:17:47 +00:00
|
|
|
BMesh *bm = me->edit_btmesh->bm;
|
|
|
|
|
|
|
|
BMO_CallOpf(bm, "object_load_bmesh scene=%p object=%p", scene, ob);
|
|
|
|
|
|
|
|
#if 0
|
2009-05-16 16:18:08 +00:00
|
|
|
EditMesh *em = bmesh_to_editmesh(me->edit_btmesh->bm);
|
|
|
|
|
|
|
|
load_editMesh(scene, ob, em);
|
|
|
|
free_editMesh(em);
|
2009-05-18 15:53:30 +00:00
|
|
|
MEM_freeN(em);
|
2009-05-26 04:17:47 +00:00
|
|
|
#endif
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
void EDBM_FreeEditBMesh(BMEditMesh *tm)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2009-05-26 04:17:47 +00:00
|
|
|
BMEdit_Free(tm);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
void EDBM_init_index_arrays(BMEditMesh *tm, int forvert, int foredge, int forface)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2009-05-18 15:53:30 +00:00
|
|
|
EDBM_free_index_arrays(tm);
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
if (forvert) {
|
|
|
|
BMIter iter;
|
|
|
|
BMVert *ele;
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
tm->vert_index = MEM_mallocN(sizeof(void**)*tm->bm->totvert, "tm->vert_index");
|
|
|
|
|
|
|
|
ele = BMIter_New(&iter, tm->bm, BM_VERTS_OF_MESH, NULL);
|
|
|
|
for ( ; ele; ele=BMIter_Step(&iter)) {
|
|
|
|
tm->vert_index[i++] = ele;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foredge) {
|
|
|
|
BMIter iter;
|
2009-05-18 08:46:04 +00:00
|
|
|
BMEdge *ele;
|
2009-05-16 16:18:08 +00:00
|
|
|
int i=0;
|
|
|
|
|
|
|
|
tm->edge_index = MEM_mallocN(sizeof(void**)*tm->bm->totedge, "tm->edge_index");
|
|
|
|
|
|
|
|
ele = BMIter_New(&iter, tm->bm, BM_EDGES_OF_MESH, NULL);
|
|
|
|
for ( ; ele; ele=BMIter_Step(&iter)) {
|
|
|
|
tm->edge_index[i++] = ele;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forface) {
|
|
|
|
BMIter iter;
|
2009-05-18 08:46:04 +00:00
|
|
|
BMFace *ele;
|
2009-05-16 16:18:08 +00:00
|
|
|
int i=0;
|
|
|
|
|
|
|
|
tm->face_index = MEM_mallocN(sizeof(void**)*tm->bm->totface, "tm->face_index");
|
|
|
|
|
|
|
|
ele = BMIter_New(&iter, tm->bm, BM_FACES_OF_MESH, NULL);
|
|
|
|
for ( ; ele; ele=BMIter_Step(&iter)) {
|
|
|
|
tm->face_index[i++] = ele;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
void EDBM_free_index_arrays(BMEditMesh *tm)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
if (tm->vert_index) {
|
|
|
|
MEM_freeN(tm->vert_index);
|
|
|
|
tm->vert_index = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tm->edge_index) {
|
|
|
|
MEM_freeN(tm->edge_index);
|
|
|
|
tm->edge_index = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tm->face_index) {
|
|
|
|
MEM_freeN(tm->face_index);
|
|
|
|
tm->face_index = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
BMVert *EDBM_get_vert_for_index(BMEditMesh *tm, int index)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
return tm->vert_index?tm->vert_index[index]:NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
BMEdge *EDBM_get_edge_for_index(BMEditMesh *tm, int index)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
return tm->edge_index?tm->edge_index[index]:NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
BMFace *EDBM_get_face_for_index(BMEditMesh *tm, int index)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
return tm->face_index?tm->face_index[index]:NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this replaces the active flag used in uv/face mode */
|
2009-05-18 08:46:04 +00:00
|
|
|
void EDBM_set_actFace(BMEditMesh *em, BMFace *efa)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2009-06-12 14:02:37 +00:00
|
|
|
em->bm->act_face = efa;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
BMFace *EDBM_get_actFace(BMEditMesh *em, int sloppy)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2009-06-12 14:02:37 +00:00
|
|
|
if (em->bm->act_face) {
|
|
|
|
return em->bm->act_face;
|
2009-05-16 16:18:08 +00:00
|
|
|
} else if (sloppy) {
|
|
|
|
BMFace *efa= NULL;
|
|
|
|
BMEditSelection *ese;
|
|
|
|
|
|
|
|
ese = em->selected.last;
|
|
|
|
for (; ese; ese=ese->prev){
|
2009-05-18 10:29:37 +00:00
|
|
|
if(ese->type == BM_FACE) {
|
2009-05-16 16:18:08 +00:00
|
|
|
efa = (BMFace *)ese->data;
|
|
|
|
|
|
|
|
if (BM_TestHFlag(efa, BM_HIDDEN)) efa= NULL;
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (efa==NULL) {
|
|
|
|
BMIter iter;
|
|
|
|
efa = BMIter_New(&iter, em->bm, BM_FACES_OF_MESH, NULL);
|
|
|
|
for ( ; efa; efa=BMIter_Step(&iter)) {
|
|
|
|
if (BM_TestHFlag(efa, BM_SELECT))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return efa; /* can still be null */
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
void EDBM_selectmode_flush(BMEditMesh *em)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2009-05-18 10:29:37 +00:00
|
|
|
em->bm->selectmode = em->selectmode;
|
|
|
|
BM_SelectMode_Flush(em->bm);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
int EDBM_get_actSelection(BMEditMesh *em, BMEditSelection *ese)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2009-05-18 10:29:37 +00:00
|
|
|
BMEditSelection *ese_last = em->selected.last;
|
|
|
|
BMFace *efa = EDBM_get_actFace(em, 0);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
ese->next = ese->prev = NULL;
|
|
|
|
|
|
|
|
if (ese_last) {
|
2009-05-18 10:29:37 +00:00
|
|
|
if (ese_last->type == BM_FACE) { /* if there is an active face, use it over the last selected face */
|
2009-05-16 16:18:08 +00:00
|
|
|
if (efa) {
|
|
|
|
ese->data = (void *)efa;
|
|
|
|
} else {
|
|
|
|
ese->data = ese_last->data;
|
|
|
|
}
|
2009-05-18 10:29:37 +00:00
|
|
|
ese->type = BM_FACE;
|
2009-05-16 16:18:08 +00:00
|
|
|
} else {
|
|
|
|
ese->data = ese_last->data;
|
|
|
|
ese->type = ese_last->type;
|
|
|
|
}
|
|
|
|
} else if (efa) { /* no */
|
|
|
|
ese->data = (void *)efa;
|
2009-05-18 10:29:37 +00:00
|
|
|
ese->type = BM_FACE;
|
2009-05-16 16:18:08 +00:00
|
|
|
} else {
|
|
|
|
ese->data = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
void EDBM_clear_flag_all(BMEditMesh *em, int flag)
|
|
|
|
{
|
|
|
|
BMIter iter;
|
|
|
|
BMHeader *ele;
|
|
|
|
int i, type;
|
|
|
|
|
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
type = BM_VERTS_OF_MESH;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
type = BM_EDGES_OF_MESH;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
type = BM_FACES_OF_MESH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ele = BMIter_New(&iter, em->bm, type, NULL);
|
|
|
|
for ( ; ele; ele=BMIter_Step(&iter)) {
|
2009-05-18 14:55:34 +00:00
|
|
|
if (flag & BM_SELECT) BM_Select(em->bm, ele, 0);
|
2009-05-18 08:46:04 +00:00
|
|
|
BM_ClearHFlag(ele, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 10:29:37 +00:00
|
|
|
|
2009-05-28 04:41:02 +00:00
|
|
|
void EDBM_set_flag_all(BMEditMesh *em, int flag)
|
2009-05-18 10:29:37 +00:00
|
|
|
{
|
|
|
|
BMIter iter;
|
2009-05-28 04:41:02 +00:00
|
|
|
BMHeader *ele;
|
|
|
|
int i, type;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-05-28 04:41:02 +00:00
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
type = BM_VERTS_OF_MESH;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
type = BM_EDGES_OF_MESH;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
type = BM_FACES_OF_MESH;
|
|
|
|
break;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2009-05-28 04:41:02 +00:00
|
|
|
ele = BMIter_New(&iter, em->bm, type, NULL);
|
|
|
|
for ( ; ele; ele=BMIter_Step(&iter)) {
|
|
|
|
if (flag & BM_SELECT) BM_Select(em->bm, ele, 1);
|
|
|
|
BM_SetHFlag(ele, flag);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-18 14:55:34 +00:00
|
|
|
|
|
|
|
/**************-------------- Undo ------------*****************/
|
|
|
|
|
|
|
|
/* for callbacks */
|
|
|
|
|
|
|
|
static void *getEditMesh(bContext *C)
|
|
|
|
{
|
|
|
|
Object *obedit= CTX_data_edit_object(C);
|
|
|
|
if(obedit && obedit->type==OB_MESH) {
|
|
|
|
Mesh *me= obedit->data;
|
|
|
|
return me->edit_btmesh;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*undo simply makes copies of a bmesh*/
|
|
|
|
static void *editbtMesh_to_undoMesh(void *emv)
|
|
|
|
{
|
|
|
|
/*we recalc the tesselation here, to avoid seeding calls to
|
2009-05-26 04:17:47 +00:00
|
|
|
BMEdit_RecalcTesselation throughout the code.*/
|
|
|
|
BMEdit_RecalcTesselation(emv);
|
2009-05-18 14:55:34 +00:00
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
return BMEdit_Copy(emv);
|
2009-05-18 14:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void undoMesh_to_editbtMesh(void *umv, void *emv)
|
|
|
|
{
|
|
|
|
BMEditMesh *bm1 = umv, *bm2 = emv;
|
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
BMEdit_Free(bm2);
|
2009-05-18 14:55:34 +00:00
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
*bm2 = *BMEdit_Copy(bm1);
|
2009-05-18 14:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void free_undo(void *umv)
|
|
|
|
{
|
|
|
|
BMEditMesh *em = umv;
|
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
BMEdit_Free(em);
|
2009-05-18 14:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* and this is all the undo system needs to know */
|
|
|
|
void undo_push_mesh(bContext *C, char *name)
|
|
|
|
{
|
|
|
|
undo_editmode_push(C, name, getEditMesh, free_undo, undoMesh_to_editbtMesh, editbtMesh_to_undoMesh, NULL);
|
|
|
|
}
|