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"
|
2009-09-17 23:05:33 +00:00
|
|
|
#include "BLI_array.h"
|
2009-03-02 02:21:18 +00:00
|
|
|
|
|
|
|
#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-09-09 06:28:58 +00:00
|
|
|
|
|
|
|
if (!em->emcopy)
|
|
|
|
em->emcopy = BMEdit_Copy(em);
|
|
|
|
em->emcopyusers++;
|
2009-06-18 07:11:55 +00:00
|
|
|
|
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-09-09 06:28:58 +00:00
|
|
|
em->emcopyusers = 0;
|
|
|
|
em->emcopy = NULL;
|
2009-05-28 04:41:02 +00:00
|
|
|
return 0;
|
2009-06-18 07:11:55 +00:00
|
|
|
} else {
|
2009-09-09 06:28:58 +00:00
|
|
|
em->emcopyusers--;
|
|
|
|
if (em->emcopyusers < 0) {
|
|
|
|
printf("warning: em->emcopyusers was less then zero.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (em->emcopyusers <= 0) {
|
|
|
|
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-09-09 06:28:58 +00:00
|
|
|
if (!em->emcopy)
|
|
|
|
em->emcopy = BMEdit_Copy(em);
|
|
|
|
em->emcopyusers++;
|
2009-06-18 07:11:55 +00:00
|
|
|
|
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-09-09 06:28:58 +00:00
|
|
|
if (!em->emcopy)
|
|
|
|
em->emcopy = BMEdit_Copy(em);
|
|
|
|
em->emcopyusers++;
|
2009-06-18 07:11:55 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
void EDBM_MakeEditBMesh(ToolSettings *ts, Scene *scene, Object *ob)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
EditMesh *em;
|
|
|
|
BMesh *bm;
|
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
if (!me->mpoly && me->totface) {
|
2009-11-01 00:06:53 +00:00
|
|
|
printf("yeek!! bmesh conversion issue! may lose shapekeys!\n");
|
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
em = make_editMesh(scene, ob);
|
|
|
|
bm = editmesh_to_bmesh(em);
|
|
|
|
|
|
|
|
free_editMesh(em);
|
|
|
|
} else {
|
2009-11-01 00:06:53 +00:00
|
|
|
bm = BKE_mesh_to_bmesh(me, ob);
|
2009-05-26 04:17:47 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
me->edit_btmesh = BMEdit_Create(bm);
|
2009-09-16 17:43:09 +00:00
|
|
|
me->edit_btmesh->selectmode = ts->selectmode;
|
2009-11-02 06:33:16 +00:00
|
|
|
me->edit_btmesh->me = me;
|
|
|
|
me->edit_btmesh->ob = ob;
|
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);
|
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;
|
|
|
|
|
2009-07-17 10:54:00 +00:00
|
|
|
ese = em->bm->selected.last;
|
2009-05-16 16:18:08 +00:00
|
|
|
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-08-05 02:34:54 +00:00
|
|
|
void EDBM_select_flush(BMEditMesh *em, int selectmode)
|
|
|
|
{
|
|
|
|
em->bm->selectmode = selectmode;
|
|
|
|
BM_SelectMode_Flush(em->bm);
|
|
|
|
em->bm->selectmode = em->selectmode;
|
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/*BMESH_TODO*/
|
|
|
|
void EDBM_deselect_flush(BMEditMesh *em)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-08-06 05:06:55 +00:00
|
|
|
/*EDBM_select_[more/less] are api functions, I think the uv editor
|
|
|
|
uses them? though the select more/less ops themselves do not.*/
|
|
|
|
void EDBM_select_more(BMEditMesh *em)
|
|
|
|
{
|
|
|
|
BMOperator bmop;
|
|
|
|
int usefaces = em->selectmode > SCE_SELECT_EDGE;
|
|
|
|
|
|
|
|
BMO_InitOpf(em->bm, &bmop,
|
|
|
|
"regionextend geom=%hvef constrict=%d usefaces=%d",
|
|
|
|
BM_SELECT, 0, usefaces);
|
|
|
|
BMO_Exec_Op(em->bm, &bmop);
|
Brought Extrude all the way back. The contextual menu works,
as does only edges and individual faces extrude (individual vert
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator. I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well. To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
2009-08-11 07:49:35 +00:00
|
|
|
BMO_HeaderFlag_Buffer(em->bm, &bmop, "geomout", BM_SELECT, BM_ALL);
|
2009-08-06 05:06:55 +00:00
|
|
|
BMO_Finish_Op(em->bm, &bmop);
|
|
|
|
|
|
|
|
EDBM_selectmode_flush(em);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EDBM_select_less(BMEditMesh *em)
|
|
|
|
{
|
|
|
|
BMOperator bmop;
|
|
|
|
int usefaces = em->selectmode > SCE_SELECT_EDGE;
|
|
|
|
|
|
|
|
BMO_InitOpf(em->bm, &bmop,
|
|
|
|
"regionextend geom=%hvef constrict=%d usefaces=%d",
|
|
|
|
BM_SELECT, 0, usefaces);
|
|
|
|
BMO_Exec_Op(em->bm, &bmop);
|
Brought Extrude all the way back. The contextual menu works,
as does only edges and individual faces extrude (individual vert
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator. I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well. To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
2009-08-11 07:49:35 +00:00
|
|
|
BMO_HeaderFlag_Buffer(em->bm, &bmop, "geomout", BM_SELECT, BM_ALL);
|
2009-08-06 05:06:55 +00:00
|
|
|
BMO_Finish_Op(em->bm, &bmop);
|
|
|
|
|
|
|
|
EDBM_selectmode_flush(em);
|
|
|
|
}
|
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-07-17 10:54:00 +00:00
|
|
|
BMEditSelection *ese_last = em->bm->selected.last;
|
2009-05-18 10:29:37 +00:00
|
|
|
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;
|
|
|
|
|
2009-09-04 01:28:06 +00:00
|
|
|
if (flag & BM_SELECT)
|
|
|
|
BM_clear_selection_history(em->bm);
|
|
|
|
|
2009-05-18 08:46:04 +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-08-05 02:34:54 +00:00
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
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-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-08-05 02:34:54 +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;
|
|
|
|
}
|
|
|
|
|
2009-09-10 06:08:52 +00:00
|
|
|
typedef struct undomesh {
|
|
|
|
Mesh me;
|
|
|
|
int selectmode;
|
|
|
|
} undomesh;
|
|
|
|
|
2009-05-18 14:55:34 +00:00
|
|
|
/*undo simply makes copies of a bmesh*/
|
2009-11-02 16:01:24 +00:00
|
|
|
static void *editbtMesh_to_undoMesh(void *emv, void *obdata)
|
2009-05-18 14:55:34 +00:00
|
|
|
{
|
2009-09-10 06:08:52 +00:00
|
|
|
BMEditMesh *em = emv;
|
2009-11-02 16:01:24 +00:00
|
|
|
Mesh *obme = obdata;
|
2009-09-10 06:08:52 +00:00
|
|
|
undomesh *me = MEM_callocN(sizeof(undomesh), "undo Mesh");
|
2009-11-02 06:33:16 +00:00
|
|
|
|
|
|
|
/*make sure shape keys work*/
|
2009-11-02 16:01:24 +00:00
|
|
|
me->me.key = obme->key ? copy_key_nolib(obme->key) : NULL;
|
2009-09-10 06:08:52 +00:00
|
|
|
|
2009-05-18 14:55:34 +00:00
|
|
|
/*we recalc the tesselation here, to avoid seeding calls to
|
2009-05-26 04:17:47 +00:00
|
|
|
BMEdit_RecalcTesselation throughout the code.*/
|
2009-09-10 06:08:52 +00:00
|
|
|
BMEdit_RecalcTesselation(em);
|
|
|
|
|
|
|
|
BMO_CallOpf(em->bm, "bmesh_to_mesh meshptr=%p notesselation=%i", me, 1);
|
|
|
|
me->selectmode = em->selectmode;
|
2009-05-18 14:55:34 +00:00
|
|
|
|
2009-09-10 06:08:52 +00:00
|
|
|
return me;
|
2009-05-18 14:55:34 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 16:01:24 +00:00
|
|
|
static void undoMesh_to_editbtMesh(void *umv, void *emv, void *obdata)
|
2009-05-18 14:55:34 +00:00
|
|
|
{
|
2009-09-10 06:08:52 +00:00
|
|
|
BMEditMesh *em = emv, *em2;
|
2009-11-02 16:01:24 +00:00
|
|
|
Object ob = {0,};
|
2009-09-10 06:08:52 +00:00
|
|
|
undomesh *me = umv;
|
|
|
|
BMesh *bm;
|
|
|
|
int allocsize[4] = {512, 512, 2048, 512};
|
|
|
|
|
2009-11-02 16:01:24 +00:00
|
|
|
ob.data = me;
|
|
|
|
ob.type = OB_MESH;
|
|
|
|
ob.shapenr = em->bm->shapenr;
|
|
|
|
|
2009-09-10 06:08:52 +00:00
|
|
|
BMEdit_Free(em);
|
|
|
|
|
|
|
|
bm = BM_Make_Mesh(allocsize);
|
2009-11-02 16:01:24 +00:00
|
|
|
BMO_CallOpf(bm, "mesh_to_bmesh mesh=%p object=%p", me, &ob);
|
2009-05-18 14:55:34 +00:00
|
|
|
|
2009-09-10 06:08:52 +00:00
|
|
|
em2 = BMEdit_Create(bm);
|
|
|
|
*em = *em2;
|
|
|
|
|
|
|
|
em->selectmode = me->selectmode;
|
2009-05-18 14:55:34 +00:00
|
|
|
|
2009-09-10 06:08:52 +00:00
|
|
|
MEM_freeN(em2);
|
2009-05-18 14:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void free_undo(void *umv)
|
|
|
|
{
|
2009-09-10 06:08:52 +00:00
|
|
|
free_mesh(umv, 0);
|
|
|
|
MEM_freeN(umv);
|
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);
|
|
|
|
}
|
2009-07-21 08:39:58 +00:00
|
|
|
|
|
|
|
/*write comment here*/
|
|
|
|
UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_array, float *limit)
|
|
|
|
{
|
|
|
|
BMVert *ev;
|
|
|
|
BMFace *efa;
|
|
|
|
BMLoop *l;
|
|
|
|
BMIter iter, liter;
|
|
|
|
/* vars from original func */
|
|
|
|
UvVertMap *vmap;
|
|
|
|
UvMapVert *buf;
|
|
|
|
MTexPoly *tf;
|
|
|
|
MLoopUV *luv;
|
|
|
|
unsigned int a;
|
|
|
|
int totverts, i, totuv;
|
|
|
|
|
|
|
|
if (do_face_idx_array)
|
|
|
|
EDBM_init_index_arrays(em, 0, 0, 1);
|
|
|
|
|
|
|
|
/* we need the vert */
|
|
|
|
totverts=0;
|
|
|
|
BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
|
|
|
|
BMINDEX_SET(ev, totverts);
|
|
|
|
totverts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
totuv = 0;
|
|
|
|
|
|
|
|
/* generate UvMapVert array */
|
|
|
|
BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
|
|
|
|
if(!selected || ((!BM_TestHFlag(efa, BM_HIDDEN)) && BM_TestHFlag(efa, BM_SELECT)))
|
|
|
|
totuv += efa->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(totuv==0) {
|
|
|
|
if (do_face_idx_array)
|
|
|
|
EDBM_free_index_arrays(em);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
vmap= (UvVertMap*)MEM_callocN(sizeof(*vmap), "UvVertMap");
|
|
|
|
if (!vmap) {
|
|
|
|
if (do_face_idx_array)
|
|
|
|
EDBM_free_index_arrays(em);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
vmap->vert= (UvMapVert**)MEM_callocN(sizeof(*vmap->vert)*totverts, "UvMapVert*");
|
|
|
|
buf= vmap->buf= (UvMapVert*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvMapVert");
|
|
|
|
|
|
|
|
if (!vmap->vert || !vmap->buf) {
|
|
|
|
free_uv_vert_map(vmap);
|
|
|
|
if (do_face_idx_array)
|
|
|
|
EDBM_free_index_arrays(em);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = 0;
|
|
|
|
BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
|
|
|
|
if(!selected || ((!BM_TestHFlag(efa, BM_HIDDEN)) && BM_TestHFlag(efa, BM_SELECT))) {
|
|
|
|
i = 0;
|
|
|
|
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
|
|
|
|
buf->tfindex= i;
|
|
|
|
buf->f= a;
|
|
|
|
buf->separate = 0;
|
|
|
|
|
2009-07-24 07:39:41 +00:00
|
|
|
buf->next= vmap->vert[BMINDEX_GET(l->v)];
|
2009-07-21 08:39:58 +00:00
|
|
|
vmap->vert[BMINDEX_GET(l->v)]= buf;
|
|
|
|
|
|
|
|
buf++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sort individual uvs for each vert */
|
|
|
|
a = 0;
|
|
|
|
BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
|
|
|
|
UvMapVert *newvlist= NULL, *vlist=vmap->vert[a];
|
|
|
|
UvMapVert *iterv, *v, *lastv, *next;
|
|
|
|
float *uv, *uv2, uvdiff[2];
|
|
|
|
|
|
|
|
while(vlist) {
|
|
|
|
v= vlist;
|
|
|
|
vlist= vlist->next;
|
|
|
|
v->next= newvlist;
|
|
|
|
newvlist= v;
|
|
|
|
|
|
|
|
efa = EDBM_get_face_for_index(em, v->f);
|
|
|
|
tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
|
|
|
|
|
|
|
|
l = BMIter_AtIndex(em->bm, BM_LOOPS_OF_FACE, efa, v->tfindex);
|
|
|
|
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
|
|
|
|
uv = luv->uv;
|
|
|
|
|
|
|
|
lastv= NULL;
|
|
|
|
iterv= vlist;
|
|
|
|
|
|
|
|
while(iterv) {
|
|
|
|
next= iterv->next;
|
|
|
|
efa = EDBM_get_face_for_index(em, iterv->f);
|
|
|
|
tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
|
|
|
|
|
|
|
|
l = BMIter_AtIndex(em->bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex);
|
|
|
|
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
|
|
|
|
uv2 = luv->uv;
|
|
|
|
|
|
|
|
Vec2Subf(uvdiff, uv2, uv);
|
|
|
|
|
|
|
|
if(fabs(uv[0]-uv2[0]) < limit[0] && fabs(uv[1]-uv2[1]) < limit[1]) {
|
|
|
|
if(lastv) lastv->next= next;
|
|
|
|
else vlist= next;
|
|
|
|
iterv->next= newvlist;
|
|
|
|
newvlist= iterv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
lastv=iterv;
|
|
|
|
|
|
|
|
iterv= next;
|
|
|
|
}
|
|
|
|
|
|
|
|
newvlist->separate = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vmap->vert[a]= newvlist;
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_face_idx_array)
|
|
|
|
EDBM_free_index_arrays(em);
|
|
|
|
|
|
|
|
return vmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UvMapVert *EDBM_get_uv_map_vert(UvVertMap *vmap, unsigned int v)
|
|
|
|
{
|
|
|
|
return vmap->vert[v];
|
|
|
|
}
|
|
|
|
|
|
|
|
void EDBM_free_uv_vert_map(UvVertMap *vmap)
|
|
|
|
{
|
|
|
|
if (vmap) {
|
|
|
|
if (vmap->vert) MEM_freeN(vmap->vert);
|
|
|
|
if (vmap->buf) MEM_freeN(vmap->buf);
|
|
|
|
MEM_freeN(vmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* last_sel, use em->act_face otherwise get the last selected face in the editselections
|
|
|
|
* at the moment, last_sel is mainly useful for gaking sure the space image dosnt flicker */
|
|
|
|
MTexPoly *EDBM_get_active_mtexpoly(BMEditMesh *em, BMFace **act_efa, int sloppy)
|
|
|
|
{
|
|
|
|
BMFace *efa = NULL;
|
|
|
|
|
|
|
|
if(!EDBM_texFaceCheck(em))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
efa = EDBM_get_actFace(em, sloppy);
|
|
|
|
|
|
|
|
if (efa) {
|
|
|
|
if (act_efa) *act_efa = efa;
|
|
|
|
return CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (act_efa) *act_efa= NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* can we edit UV's for this mesh?*/
|
|
|
|
int EDBM_texFaceCheck(BMEditMesh *em)
|
|
|
|
{
|
|
|
|
/* some of these checks could be a touch overkill */
|
|
|
|
return em && em->bm->totface && CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY);
|
2009-07-21 11:48:58 +00:00
|
|
|
}
|
2009-08-28 10:17:31 +00:00
|
|
|
|
|
|
|
int EDBM_vertColorCheck(BMEditMesh *em)
|
|
|
|
{
|
|
|
|
/* some of these checks could be a touch overkill */
|
|
|
|
return em && em->bm->totface && CustomData_has_layer(&em->bm->ldata, CD_MLOOPCOL);
|
|
|
|
}
|
|
|
|
|