2011-10-24 23:32:24 +00:00
|
|
|
/*
|
2009-03-02 02:21:18 +00:00
|
|
|
* ***** 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,
|
2012-02-11 04:16:17 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-03-02 02:21:18 +00:00
|
|
|
*
|
|
|
|
* 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 "MEM_guardedalloc.h"
|
|
|
|
|
2012-02-19 22:17:30 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
2009-03-02 02:21:18 +00:00
|
|
|
#include "DNA_object_types.h"
|
2012-02-11 10:15:11 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2009-03-02 02:21:18 +00:00
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2009-11-23 14:41:22 +00:00
|
|
|
#include "BLI_math.h"
|
2009-03-02 02:21:18 +00:00
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_library.h"
|
2009-11-06 12:59:58 +00:00
|
|
|
#include "BKE_key.h"
|
2009-03-02 02:21:18 +00:00
|
|
|
#include "BKE_mesh.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 "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "ED_mesh.h"
|
|
|
|
#include "ED_util.h"
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
void EDBM_RecalcNormals(BMEditMesh *em)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_normals_update(em->bm);
|
2009-05-18 14:55:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 00:20:50 +00:00
|
|
|
void EDBM_ClearMesh(BMEditMesh *em)
|
|
|
|
{
|
2012-02-10 18:09:19 +00:00
|
|
|
/* clear bmesh */
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_clear(em->bm);
|
2011-11-08 00:20:50 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
/* free derived meshes */
|
2011-11-08 00:20:50 +00:00
|
|
|
if (em->derivedCage) {
|
|
|
|
em->derivedCage->needsFree = 1;
|
|
|
|
em->derivedCage->release(em->derivedCage);
|
|
|
|
}
|
|
|
|
if (em->derivedFinal && em->derivedFinal != em->derivedCage) {
|
|
|
|
em->derivedFinal->needsFree = 1;
|
|
|
|
em->derivedFinal->release(em->derivedFinal);
|
|
|
|
}
|
|
|
|
|
|
|
|
em->derivedCage = em->derivedFinal = NULL;
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
/* free tesselation data */
|
2011-11-08 00:20:50 +00:00
|
|
|
em->tottri = 0;
|
|
|
|
if (em->looptris)
|
|
|
|
MEM_freeN(em->looptris);
|
|
|
|
}
|
|
|
|
|
2009-05-18 14:55:34 +00:00
|
|
|
void EDBM_stats_update(BMEditMesh *em)
|
|
|
|
{
|
2012-02-07 13:54:16 +00:00
|
|
|
const char iter_types[3] = {BM_VERTS_OF_MESH,
|
|
|
|
BM_EDGES_OF_MESH,
|
|
|
|
BM_FACES_OF_MESH};
|
|
|
|
|
2009-05-18 14:55:34 +00:00
|
|
|
BMIter iter;
|
|
|
|
BMHeader *ele;
|
|
|
|
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;
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2012-02-12 10:51:45 +00:00
|
|
|
ele = BM_iter_new(&iter, em->bm, iter_types[i], NULL);
|
|
|
|
for ( ; ele; ele = BM_iter_step(&iter)) {
|
|
|
|
if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) {
|
2011-11-16 17:09:41 +00:00
|
|
|
(*tots[i])++;
|
2009-05-18 14:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-27 06:19:40 +00:00
|
|
|
int EDBM_InitOpf(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const char *fmt, ...)
|
2009-05-28 04:41:02 +00:00
|
|
|
{
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
if (!BMO_op_vinitf(bm, bmop, fmt, list)) {
|
2012-02-20 01:52:35 +00:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Parse error in %s", __func__);
|
2009-05-28 04:41:02 +00:00
|
|
|
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);
|
2009-11-06 12:59:58 +00:00
|
|
|
|
|
|
|
return 1;
|
2009-05-28 04:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
/* returns 0 on error, 1 on success. executes and finishes a bmesh operator */
|
2012-02-07 13:54:16 +00:00
|
|
|
int EDBM_FinishOp(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const int report)
|
2011-11-07 09:02:10 +00:00
|
|
|
{
|
2011-05-07 02:48:14 +00:00
|
|
|
const char *errmsg;
|
2009-05-28 04:41:02 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BMO_op_finish(em->bm, bmop);
|
2009-05-28 04:41:02 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
if (BMO_error_get(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;
|
2011-09-16 14:28:23 +00:00
|
|
|
BMEdit_RecalcTesselation(em);
|
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;
|
2012-02-05 15:55:28 +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;
|
|
|
|
}
|
|
|
|
|
2011-02-27 06:19:40 +00:00
|
|
|
int EDBM_CallOpf(BMEditMesh *em, wmOperator *op, const 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);
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
if (!BMO_op_vinitf(bm, &bmop, fmt, list)) {
|
2012-02-20 01:52:35 +00:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Parse error in %s", __func__);
|
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
|
|
|
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
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BMO_op_exec(bm, &bmop);
|
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
|
|
|
|
|
|
|
va_end(list);
|
2012-02-07 13:54:16 +00:00
|
|
|
return EDBM_FinishOp(em, &bmop, op, TRUE);
|
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
|
|
|
}
|
|
|
|
|
2011-02-27 06:19:40 +00:00
|
|
|
int EDBM_CallAndSelectOpf(BMEditMesh *em, wmOperator *op, const char *selectslot, const char *fmt, ...)
|
2010-01-28 00:45:30 +00:00
|
|
|
{
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
BMOperator bmop;
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
if (!BMO_op_vinitf(bm, &bmop, fmt, list)) {
|
2012-02-20 01:52:35 +00:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Parse error in %s", __func__);
|
2010-01-28 00:45:30 +00:00
|
|
|
va_end(list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!em->emcopy)
|
|
|
|
em->emcopy = BMEdit_Copy(em);
|
|
|
|
em->emcopyusers++;
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BMO_op_exec(bm, &bmop);
|
2012-02-16 19:33:46 +00:00
|
|
|
|
|
|
|
BM_mesh_elem_flag_disable_all(em->bm, BM_VERT|BM_EDGE|BM_FACE, BM_ELEM_SELECT);
|
|
|
|
|
2012-02-12 18:43:59 +00:00
|
|
|
BMO_slot_buffer_hflag_enable(em->bm, &bmop, selectslot, BM_ELEM_SELECT, BM_ALL);
|
2010-01-28 00:45:30 +00:00
|
|
|
|
|
|
|
va_end(list);
|
2012-02-07 13:54:16 +00:00
|
|
|
return EDBM_FinishOp(em, &bmop, op, TRUE);
|
2010-01-28 00:45:30 +00:00
|
|
|
}
|
|
|
|
|
2011-02-27 06:19:40 +00:00
|
|
|
int EDBM_CallOpfSilent(BMEditMesh *em, const 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);
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
if (!BMO_op_vinitf(bm, &bmop, fmt, list)) {
|
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
|
|
|
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
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BMO_op_exec(bm, &bmop);
|
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
|
|
|
|
|
|
|
va_end(list);
|
2012-02-07 13:54:16 +00:00
|
|
|
return EDBM_FinishOp(em, &bmop, NULL, FALSE);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 14:47:37 +00:00
|
|
|
void EDBM_selectmode_to_scene(bContext *C)
|
2010-03-09 04:32:40 +00:00
|
|
|
{
|
2011-10-15 14:47:37 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
2012-02-10 18:09:19 +00:00
|
|
|
BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh;
|
2010-03-09 04:32:40 +00:00
|
|
|
|
|
|
|
if (!em)
|
|
|
|
return;
|
|
|
|
|
|
|
|
scene->toolsettings->selectmode = em->selectmode;
|
2011-10-15 14:47:37 +00:00
|
|
|
|
|
|
|
/* Request redraw of header buttons (to show new select mode) */
|
|
|
|
WM_event_add_notifier(C, NC_SCENE|ND_TOOLSETTINGS, scene);
|
2010-03-09 04:32:40 +00:00
|
|
|
}
|
|
|
|
|
2011-05-07 02:48:14 +00:00
|
|
|
void EDBM_MakeEditBMesh(ToolSettings *ts, Scene *UNUSED(scene), Object *ob)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
BMesh *bm;
|
|
|
|
|
2009-05-26 04:17:47 +00:00
|
|
|
if (!me->mpoly && me->totface) {
|
2011-09-24 12:13:13 +00:00
|
|
|
fprintf(stderr, "%s: bmesh conversion issue! may lose lots of geometry! (bmesh internal error)\n", __func__);
|
2010-01-28 00:45:30 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
/* BMESH_TODO need to write smarter code here */
|
2011-09-12 02:23:30 +00:00
|
|
|
bm = BKE_mesh_to_bmesh(me, ob);
|
2012-02-05 15:55:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-09-12 02:23:30 +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
|
|
|
|
2011-10-30 02:15:32 +00:00
|
|
|
if (me->edit_btmesh) {
|
|
|
|
/* this happens when switching shape keys */
|
|
|
|
BMEdit_Free(me->edit_btmesh);
|
|
|
|
MEM_freeN(me->edit_btmesh);
|
|
|
|
}
|
|
|
|
|
2012-01-22 22:20:20 +00:00
|
|
|
/* currently executing operators re-tesselates, so we can avoid doing here
|
|
|
|
* but at some point it may need to be added back. */
|
|
|
|
#if 0
|
2012-01-22 21:12:18 +00:00
|
|
|
me->edit_btmesh = BMEdit_Create(bm, TRUE);
|
2012-01-22 22:20:20 +00:00
|
|
|
#else
|
|
|
|
me->edit_btmesh = BMEdit_Create(bm, FALSE);
|
|
|
|
#endif
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
me->edit_btmesh->selectmode = me->edit_btmesh->bm->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;
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BMO_op_callf(bm, "object_load_bmesh scene=%p object=%p", scene, ob);
|
2012-02-20 00:18:35 +00:00
|
|
|
|
|
|
|
#ifdef USE_TESSFACE_DEFAULT
|
|
|
|
BKE_mesh_tessface_calc(me);
|
|
|
|
#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;
|
2012-02-10 18:09:19 +00:00
|
|
|
int i = 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
tm->vert_index = MEM_mallocN(sizeof(void **) * tm->bm->totvert, "tm->vert_index");
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
ele = BM_iter_new(&iter, tm->bm, BM_VERTS_OF_MESH, NULL);
|
|
|
|
for ( ; ele; ele = BM_iter_step(&iter)) {
|
2009-05-16 16:18:08 +00:00
|
|
|
tm->vert_index[i++] = ele;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foredge) {
|
|
|
|
BMIter iter;
|
2009-05-18 08:46:04 +00:00
|
|
|
BMEdge *ele;
|
2012-02-10 18:09:19 +00:00
|
|
|
int i = 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
tm->edge_index = MEM_mallocN(sizeof(void **) * tm->bm->totedge, "tm->edge_index");
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
ele = BM_iter_new(&iter, tm->bm, BM_EDGES_OF_MESH, NULL);
|
|
|
|
for ( ; ele; ele = BM_iter_step(&iter)) {
|
2009-05-16 16:18:08 +00:00
|
|
|
tm->edge_index[i++] = ele;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forface) {
|
|
|
|
BMIter iter;
|
2009-05-18 08:46:04 +00:00
|
|
|
BMFace *ele;
|
2012-02-10 18:09:19 +00:00
|
|
|
int i = 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
tm->face_index = MEM_mallocN(sizeof(void **) * tm->bm->totface, "tm->face_index");
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
ele = BM_iter_new(&iter, tm->bm, BM_FACES_OF_MESH, NULL);
|
|
|
|
for ( ; ele; ele = BM_iter_step(&iter)) {
|
2009-05-16 16:18:08 +00:00
|
|
|
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
|
|
|
{
|
2011-04-17 04:12:53 +00:00
|
|
|
return tm->vert_index && index < tm->bm->totvert ?tm->vert_index[index]:NULL;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-04-17 04:12:53 +00:00
|
|
|
return tm->edge_index && index < tm->bm->totedge ?tm->edge_index[index]:NULL;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-02-10 18:09:19 +00:00
|
|
|
return (tm->face_index && index < tm->bm->totface && index >= 0) ? tm->face_index[index] : NULL;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 06:16:21 +00:00
|
|
|
void EDBM_selectmode_flush_ex(BMEditMesh *em, int selectmode)
|
2009-08-05 02:34:54 +00:00
|
|
|
{
|
|
|
|
em->bm->selectmode = selectmode;
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_select_mode_flush(em->bm);
|
2009-08-05 02:34:54 +00:00
|
|
|
em->bm->selectmode = em->selectmode;
|
|
|
|
}
|
|
|
|
|
2012-02-10 06:16:21 +00:00
|
|
|
void EDBM_selectmode_flush(BMEditMesh *em)
|
|
|
|
{
|
|
|
|
EDBM_selectmode_flush_ex(em, em->selectmode);
|
|
|
|
}
|
|
|
|
|
2012-02-10 03:03:42 +00:00
|
|
|
void EDBM_deselect_flush(BMEditMesh *em)
|
2009-09-16 17:43:09 +00:00
|
|
|
{
|
2012-02-10 03:03:42 +00:00
|
|
|
/* function below doesnt use. just do this to keep the values in sync */
|
|
|
|
em->bm->selectmode = em->selectmode;
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_deselect_flush(em->bm);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-10 03:03:42 +00:00
|
|
|
void EDBM_select_flush(BMEditMesh *em)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-02-10 03:03:42 +00:00
|
|
|
/* function below doesnt use. just do this to keep the values in sync */
|
2009-05-18 10:29:37 +00:00
|
|
|
em->bm->selectmode = em->selectmode;
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_select_flush(em->bm);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 09:39:47 +00:00
|
|
|
void EDBM_select_more(BMEditMesh *em)
|
2009-08-06 05:06:55 +00:00
|
|
|
{
|
|
|
|
BMOperator bmop;
|
2012-02-20 01:52:35 +00:00
|
|
|
int use_faces = em->selectmode > SCE_SELECT_EDGE;
|
2009-08-06 05:06:55 +00:00
|
|
|
|
2012-02-13 05:59:14 +00:00
|
|
|
BMO_op_initf(em->bm, &bmop,
|
2012-02-20 01:52:35 +00:00
|
|
|
"regionextend geom=%hvef constrict=%i use_faces=%b",
|
|
|
|
BM_ELEM_SELECT, FALSE, use_faces);
|
2012-02-12 10:51:45 +00:00
|
|
|
BMO_op_exec(em->bm, &bmop);
|
2012-02-12 18:43:59 +00:00
|
|
|
BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_ELEM_SELECT, BM_ALL);
|
2012-02-12 10:51:45 +00:00
|
|
|
BMO_op_finish(em->bm, &bmop);
|
2009-08-06 05:06:55 +00:00
|
|
|
|
2012-02-10 06:16:21 +00:00
|
|
|
EDBM_selectmode_flush(em);
|
2009-08-06 05:06:55 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 09:39:47 +00:00
|
|
|
void EDBM_select_less(BMEditMesh *em)
|
2009-08-06 05:06:55 +00:00
|
|
|
{
|
|
|
|
BMOperator bmop;
|
2012-02-20 01:52:35 +00:00
|
|
|
int use_faces = em->selectmode > SCE_SELECT_EDGE;
|
2009-08-06 05:06:55 +00:00
|
|
|
|
2012-02-13 05:59:14 +00:00
|
|
|
BMO_op_initf(em->bm, &bmop,
|
2012-02-20 01:52:35 +00:00
|
|
|
"regionextend geom=%hvef constrict=%i use_faces=%b",
|
|
|
|
BM_ELEM_SELECT, FALSE, use_faces);
|
2012-02-12 10:51:45 +00:00
|
|
|
BMO_op_exec(em->bm, &bmop);
|
2012-02-12 18:43:59 +00:00
|
|
|
BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_ELEM_SELECT, BM_ALL);
|
2012-02-12 10:51:45 +00:00
|
|
|
BMO_op_finish(em->bm, &bmop);
|
2009-08-06 05:06:55 +00:00
|
|
|
|
2012-02-10 06:16:21 +00:00
|
|
|
EDBM_selectmode_flush(em);
|
2009-08-06 05:06:55 +00:00
|
|
|
}
|
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;
|
2012-02-12 10:51:45 +00:00
|
|
|
BMFace *efa = BM_active_face_get(em->bm, FALSE);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
ese->next = ese->prev = NULL;
|
|
|
|
|
|
|
|
if (ese_last) {
|
2011-11-01 14:36:23 +00:00
|
|
|
if (ese_last->htype == 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;
|
2012-02-05 15:55:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-05-16 16:18:08 +00:00
|
|
|
ese->data = ese_last->data;
|
|
|
|
}
|
2011-11-01 14:36:23 +00:00
|
|
|
ese->htype = BM_FACE;
|
|
|
|
}
|
|
|
|
else {
|
2009-05-16 16:18:08 +00:00
|
|
|
ese->data = ese_last->data;
|
2011-11-01 14:36:23 +00:00
|
|
|
ese->htype = ese_last->htype;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2011-11-01 14:36:23 +00:00
|
|
|
}
|
|
|
|
else if (efa) { /* no */
|
2012-02-10 18:09:19 +00:00
|
|
|
ese->data = (void *)efa;
|
|
|
|
ese->htype = BM_FACE;
|
2011-11-01 14:36:23 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-05-16 16:18:08 +00:00
|
|
|
ese->data = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-02-12 18:43:59 +00:00
|
|
|
void EDBM_flag_disable_all(BMEditMesh *em, const char hflag)
|
2009-05-18 08:46:04 +00:00
|
|
|
{
|
2012-02-13 06:59:25 +00:00
|
|
|
BM_mesh_elem_flag_disable_all(em->bm, BM_VERT|BM_EDGE|BM_FACE, hflag);
|
2009-05-18 08:46:04 +00:00
|
|
|
}
|
|
|
|
|
2012-02-12 18:43:59 +00:00
|
|
|
void EDBM_flag_enable_all(BMEditMesh *em, const char hflag)
|
2009-05-18 10:29:37 +00:00
|
|
|
{
|
2012-02-13 06:59:25 +00:00
|
|
|
BM_mesh_elem_flag_enable_all(em->bm, BM_VERT|BM_EDGE|BM_FACE, hflag);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2009-05-18 14:55:34 +00:00
|
|
|
|
|
|
|
/**************-------------- Undo ------------*****************/
|
|
|
|
|
|
|
|
/* for callbacks */
|
|
|
|
|
|
|
|
static void *getEditMesh(bContext *C)
|
|
|
|
{
|
2012-02-10 18:09:19 +00:00
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
|
|
|
if (obedit && obedit->type == OB_MESH) {
|
|
|
|
Mesh *me = obedit->data;
|
2009-05-18 14:55:34 +00:00
|
|
|
return me->edit_btmesh;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-10 06:08:52 +00:00
|
|
|
typedef struct undomesh {
|
|
|
|
Mesh me;
|
|
|
|
int selectmode;
|
2012-02-10 18:09:19 +00:00
|
|
|
char obname[MAX_ID_NAME - 2];
|
2009-09-10 06:08:52 +00:00
|
|
|
} undomesh;
|
|
|
|
|
2012-02-10 18:09:19 +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;
|
2011-03-29 05:48:18 +00:00
|
|
|
|
2012-01-23 23:53:21 +00:00
|
|
|
undomesh *um = MEM_callocN(sizeof(undomesh), "undo Mesh");
|
2012-02-10 18:09:19 +00:00
|
|
|
BLI_strncpy(um->obname, em->bm->ob->id.name + 2, sizeof(um->obname));
|
2009-11-02 06:33:16 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
/* make sure shape keys work */
|
2012-01-23 23:53:21 +00:00
|
|
|
um->me.key = obme->key ? copy_key_nolib(obme->key) : NULL;
|
2009-09-10 06:08:52 +00:00
|
|
|
|
2011-12-11 05:05:37 +00:00
|
|
|
#ifdef BMESH_EM_UNDO_RECALC_TESSFACE_WORKAROUND
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
/* we recalc the tesselation here, to avoid seeding calls to
|
|
|
|
* BMEdit_RecalcTesselation throughout the code. */
|
2009-09-10 06:08:52 +00:00
|
|
|
BMEdit_RecalcTesselation(em);
|
|
|
|
|
2011-12-11 05:05:37 +00:00
|
|
|
#endif
|
|
|
|
|
2012-02-20 01:52:35 +00:00
|
|
|
BMO_op_callf(em->bm, "bmesh_to_mesh mesh=%p notesselation=%b", &um->me, TRUE);
|
2012-01-23 23:53:21 +00:00
|
|
|
um->selectmode = em->selectmode;
|
2009-05-18 14:55:34 +00:00
|
|
|
|
2012-01-23 23:53:21 +00:00
|
|
|
return um;
|
2009-05-18 14:55:34 +00:00
|
|
|
}
|
|
|
|
|
2011-05-07 02:48:14 +00:00
|
|
|
static void undoMesh_to_editbtMesh(void *umv, void *emv, void *UNUSED(obdata))
|
2009-05-18 14:55:34 +00:00
|
|
|
{
|
2009-09-10 06:08:52 +00:00
|
|
|
BMEditMesh *em = emv, *em2;
|
2011-03-29 05:48:18 +00:00
|
|
|
Object *ob;
|
2012-01-23 23:53:21 +00:00
|
|
|
undomesh *um = umv;
|
2009-09-10 06:08:52 +00:00
|
|
|
BMesh *bm;
|
2012-02-20 01:52:35 +00:00
|
|
|
|
|
|
|
/* BMESH_TODO - its possible the name wont be found right?, should fallback */
|
2012-02-10 18:09:19 +00:00
|
|
|
ob = (Object *)find_id("OB", um->obname);
|
2011-03-29 05:48:18 +00:00
|
|
|
ob->shapenr = em->bm->shapenr;
|
2009-11-02 16:01:24 +00:00
|
|
|
|
2009-09-10 06:08:52 +00:00
|
|
|
BMEdit_Free(em);
|
|
|
|
|
2012-02-12 17:44:10 +00:00
|
|
|
bm = BM_mesh_create(ob, bm_mesh_allocsize_default);
|
2012-02-20 01:52:35 +00:00
|
|
|
BMO_op_callf(bm, "mesh_to_bmesh mesh=%p object=%p set_shapekey=%b", &um->me, ob, FALSE);
|
2009-05-18 14:55:34 +00:00
|
|
|
|
2012-01-22 21:12:18 +00:00
|
|
|
em2 = BMEdit_Create(bm, TRUE);
|
2009-09-10 06:08:52 +00:00
|
|
|
*em = *em2;
|
|
|
|
|
2012-01-23 23:53:21 +00:00
|
|
|
em->selectmode = um->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)
|
|
|
|
{
|
2012-02-10 18:09:19 +00:00
|
|
|
if (((Mesh *)umv)->key) {
|
|
|
|
free_key(((Mesh *)umv)->key);
|
|
|
|
MEM_freeN(((Mesh *)umv)->key);
|
2011-05-12 18:33:10 +00:00
|
|
|
}
|
|
|
|
|
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 */
|
2011-02-27 06:19:40 +00:00
|
|
|
void undo_push_mesh(bContext *C, const char *name)
|
2009-05-18 14:55:34 +00:00
|
|
|
{
|
|
|
|
undo_editmode_push(C, name, getEditMesh, free_undo, undoMesh_to_editbtMesh, editbtMesh_to_undoMesh, NULL);
|
|
|
|
}
|
2009-07-21 08:39:58 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
/* write comment here */
|
2009-07-21 08:39:58 +00:00
|
|
|
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;
|
2011-09-07 06:49:20 +00:00
|
|
|
/* MTexPoly *tf; */ /* UNUSED */
|
2009-07-21 08:39:58 +00:00
|
|
|
MLoopUV *luv;
|
|
|
|
unsigned int a;
|
|
|
|
int totverts, i, totuv;
|
|
|
|
|
|
|
|
if (do_face_idx_array)
|
|
|
|
EDBM_init_index_arrays(em, 0, 0, 1);
|
2011-11-01 12:51:38 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(em->bm, BM_VERT);
|
2009-07-21 08:39:58 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
totverts = em->bm->totvert;
|
2009-07-21 08:39:58 +00:00
|
|
|
totuv = 0;
|
|
|
|
|
|
|
|
/* generate UvMapVert array */
|
|
|
|
BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
|
2012-02-12 10:51:45 +00:00
|
|
|
if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT)))
|
2009-07-21 08:39:58 +00:00
|
|
|
totuv += efa->len;
|
|
|
|
}
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
if (totuv == 0) {
|
2009-07-21 08:39:58 +00:00
|
|
|
if (do_face_idx_array)
|
|
|
|
EDBM_free_index_arrays(em);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-02-10 18:09:19 +00:00
|
|
|
vmap = (UvVertMap *)MEM_callocN(sizeof(*vmap), "UvVertMap");
|
2009-07-21 08:39:58 +00:00
|
|
|
if (!vmap) {
|
|
|
|
if (do_face_idx_array)
|
|
|
|
EDBM_free_index_arrays(em);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
vmap->vert = (UvMapVert **)MEM_callocN(sizeof(*vmap->vert)*totverts, "UvMapVert_pt");
|
|
|
|
buf = vmap->buf = (UvMapVert *)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvMapVert");
|
2009-07-21 08:39:58 +00:00
|
|
|
|
|
|
|
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) {
|
2012-02-12 10:51:45 +00:00
|
|
|
if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT))) {
|
2009-07-21 08:39:58 +00:00
|
|
|
i = 0;
|
|
|
|
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
|
2012-02-10 18:09:19 +00:00
|
|
|
buf->tfindex = i;
|
|
|
|
buf->f = a;
|
2009-07-21 08:39:58 +00:00
|
|
|
buf->separate = 0;
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
buf->next = vmap->vert[BM_elem_index_get(l->v)];
|
|
|
|
vmap->vert[BM_elem_index_get(l->v)] = buf;
|
2009-07-21 08:39:58 +00:00
|
|
|
|
|
|
|
buf++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sort individual uvs for each vert */
|
|
|
|
a = 0;
|
|
|
|
BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
|
2012-02-10 18:09:19 +00:00
|
|
|
UvMapVert *newvlist = NULL, *vlist = vmap->vert[a];
|
2009-07-21 08:39:58 +00:00
|
|
|
UvMapVert *iterv, *v, *lastv, *next;
|
|
|
|
float *uv, *uv2, uvdiff[2];
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
while (vlist) {
|
|
|
|
v = vlist;
|
|
|
|
vlist = vlist->next;
|
|
|
|
v->next = newvlist;
|
|
|
|
newvlist = v;
|
2009-07-21 08:39:58 +00:00
|
|
|
|
|
|
|
efa = EDBM_get_face_for_index(em, v->f);
|
2011-09-07 06:49:20 +00:00
|
|
|
/* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
|
2009-07-21 08:39:58 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, v->tfindex);
|
2009-07-21 08:39:58 +00:00
|
|
|
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
|
2012-02-10 18:09:19 +00:00
|
|
|
uv = luv->uv;
|
2009-07-21 08:39:58 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
lastv = NULL;
|
|
|
|
iterv = vlist;
|
2009-07-21 08:39:58 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
while (iterv) {
|
|
|
|
next = iterv->next;
|
2009-07-21 08:39:58 +00:00
|
|
|
efa = EDBM_get_face_for_index(em, iterv->f);
|
2011-09-07 06:49:20 +00:00
|
|
|
/* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
|
2009-07-21 08:39:58 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex);
|
2009-07-21 08:39:58 +00:00
|
|
|
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
|
2012-02-10 18:09:19 +00:00
|
|
|
uv2 = luv->uv;
|
2009-07-21 08:39:58 +00:00
|
|
|
|
2009-11-23 14:41:22 +00:00
|
|
|
sub_v2_v2v2(uvdiff, uv2, uv);
|
2009-07-21 08:39:58 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
if (fabs(uvdiff[0]) < limit[0] && fabs(uvdiff[1]) < limit[1]) {
|
|
|
|
if (lastv) lastv->next = next;
|
|
|
|
else vlist = next;
|
|
|
|
iterv->next = newvlist;
|
|
|
|
newvlist = iterv;
|
2009-07-21 08:39:58 +00:00
|
|
|
}
|
|
|
|
else
|
2012-02-10 18:09:19 +00:00
|
|
|
lastv = iterv;
|
2009-07-21 08:39:58 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
iterv = next;
|
2009-07-21 08:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newvlist->separate = 1;
|
|
|
|
}
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
vmap->vert[a] = newvlist;
|
2009-07-21 08:39:58 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2012-01-17 21:08:25 +00:00
|
|
|
/* from editmesh_lib.c in trunk */
|
2012-02-06 19:25:12 +00:00
|
|
|
|
2012-01-17 21:08:25 +00:00
|
|
|
|
|
|
|
/* A specialized vert map used by stitch operator */
|
2012-02-06 19:25:12 +00:00
|
|
|
UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_islands)
|
2012-01-17 21:08:25 +00:00
|
|
|
{
|
2012-02-06 19:25:12 +00:00
|
|
|
BMVert *ev;
|
|
|
|
BMFace *efa;
|
|
|
|
BMLoop *l;
|
|
|
|
BMIter iter, liter;
|
|
|
|
/* vars from original func */
|
|
|
|
UvElementMap *element_map;
|
|
|
|
UvElement *buf;
|
|
|
|
UvElement *islandbuf;
|
2012-02-14 00:55:01 +00:00
|
|
|
/* island number for faces */
|
2012-02-14 00:35:29 +00:00
|
|
|
int *island_number;
|
2012-02-06 19:25:12 +00:00
|
|
|
|
|
|
|
MLoopUV *luv;
|
|
|
|
int totverts, i, totuv, j, nislands = 0, islandbufsize = 0;
|
|
|
|
|
|
|
|
unsigned int *map;
|
|
|
|
BMFace **stack;
|
|
|
|
int stacksize = 0;
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
|
2012-02-06 19:25:12 +00:00
|
|
|
|
|
|
|
totverts = em->bm->totvert;
|
|
|
|
totuv = 0;
|
|
|
|
|
2012-02-14 00:35:29 +00:00
|
|
|
island_number = MEM_mallocN(sizeof(*stack)*em->bm->totface, "uv_island_number_face");
|
|
|
|
if (!island_number) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-06 19:25:12 +00:00
|
|
|
/* generate UvElement array */
|
|
|
|
BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
|
2012-02-12 10:51:45 +00:00
|
|
|
if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT)))
|
2012-02-06 19:25:12 +00:00
|
|
|
totuv += efa->len;
|
|
|
|
}
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
if (totuv == 0) {
|
2012-02-14 00:35:29 +00:00
|
|
|
MEM_freeN(island_number);
|
2012-02-06 19:25:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-02-10 18:09:19 +00:00
|
|
|
element_map = (UvElementMap *)MEM_callocN(sizeof(*element_map), "UvElementMap");
|
2012-02-06 19:25:12 +00:00
|
|
|
if (!element_map) {
|
2012-02-14 00:35:29 +00:00
|
|
|
MEM_freeN(island_number);
|
2012-02-06 19:25:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-02-06 21:00:50 +00:00
|
|
|
element_map->totalUVs = totuv;
|
2012-02-10 18:09:19 +00:00
|
|
|
element_map->vert = (UvElement **)MEM_callocN(sizeof(*element_map->vert) * totverts, "UvElementVerts");
|
|
|
|
buf = element_map->buf = (UvElement *)MEM_callocN(sizeof(*element_map->buf) * totuv, "UvElement");
|
2012-02-06 19:25:12 +00:00
|
|
|
|
|
|
|
if (!element_map->vert || !element_map->buf) {
|
|
|
|
EDBM_free_uv_element_map(element_map);
|
2012-02-14 00:35:29 +00:00
|
|
|
MEM_freeN(island_number);
|
2012-02-06 19:25:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-14 00:35:29 +00:00
|
|
|
j = 0;
|
2012-02-06 19:25:12 +00:00
|
|
|
BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
|
2012-02-14 00:35:29 +00:00
|
|
|
island_number[j++] = INVALID_ISLAND;
|
2012-02-12 10:51:45 +00:00
|
|
|
if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT))) {
|
2012-02-06 19:25:12 +00:00
|
|
|
i = 0;
|
|
|
|
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
|
|
|
|
buf->tfindex = i;
|
|
|
|
buf->face = efa;
|
|
|
|
buf->separate = 0;
|
|
|
|
buf->island = INVALID_ISLAND;
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
buf->next = element_map->vert[BM_elem_index_get(l->v)];
|
|
|
|
element_map->vert[BM_elem_index_get(l->v)] = buf;
|
2012-02-06 19:25:12 +00:00
|
|
|
|
|
|
|
buf++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sort individual uvs for each vert */
|
|
|
|
i = 0;
|
|
|
|
BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
|
2012-02-10 18:09:19 +00:00
|
|
|
UvElement *newvlist = NULL, *vlist = element_map->vert[i];
|
2012-02-06 19:25:12 +00:00
|
|
|
UvElement *iterv, *v, *lastv, *next;
|
|
|
|
float *uv, *uv2, uvdiff[2];
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
while (vlist) {
|
|
|
|
v = vlist;
|
|
|
|
vlist = vlist->next;
|
|
|
|
v->next = newvlist;
|
|
|
|
newvlist = v;
|
2012-02-06 19:25:12 +00:00
|
|
|
|
|
|
|
efa = v->face;
|
|
|
|
/* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, v->tfindex);
|
2012-02-06 19:25:12 +00:00
|
|
|
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
|
|
|
|
uv = luv->uv;
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
lastv = NULL;
|
|
|
|
iterv = vlist;
|
2012-02-06 19:25:12 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
while (iterv) {
|
|
|
|
next = iterv->next;
|
2012-02-06 19:25:12 +00:00
|
|
|
efa = iterv->face;
|
|
|
|
/* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex);
|
2012-02-06 19:25:12 +00:00
|
|
|
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
|
|
|
|
uv2 = luv->uv;
|
|
|
|
|
|
|
|
sub_v2_v2v2(uvdiff, uv2, uv);
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
if (fabsf(uvdiff[0]) < STD_UV_CONNECT_LIMIT && fabsf(uvdiff[1]) < STD_UV_CONNECT_LIMIT) {
|
|
|
|
if (lastv) lastv->next = next;
|
|
|
|
else vlist = next;
|
|
|
|
iterv->next = newvlist;
|
|
|
|
newvlist = iterv;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastv = iterv;
|
2012-02-06 19:25:12 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
iterv = next;
|
2012-02-06 19:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newvlist->separate = 1;
|
|
|
|
}
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
element_map->vert[i] = newvlist;
|
2012-02-06 19:25:12 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2012-02-05 15:55:28 +00:00
|
|
|
if (do_islands) {
|
2012-02-10 18:09:19 +00:00
|
|
|
/* map holds the map from current vmap->buf to the new, sorted map */
|
2012-01-17 21:08:25 +00:00
|
|
|
map = MEM_mallocN(sizeof(*map)*totuv, "uvelement_remap");
|
2012-02-06 19:25:12 +00:00
|
|
|
stack = MEM_mallocN(sizeof(*stack)*em->bm->totface, "uv_island_face_stack");
|
2012-01-17 21:08:25 +00:00
|
|
|
islandbuf = MEM_callocN(sizeof(*islandbuf)*totuv, "uvelement_island_buffer");
|
|
|
|
|
2012-02-14 00:55:01 +00:00
|
|
|
/* at this point, every UvElement in vert points to a UvElement sharing the same vertex. Now we should sort uv's in islands. */
|
2012-02-10 18:09:19 +00:00
|
|
|
for (i = 0; i < totuv; i++) {
|
2012-02-06 19:25:12 +00:00
|
|
|
if (element_map->buf[i].island == INVALID_ISLAND) {
|
|
|
|
element_map->buf[i].island = nislands;
|
|
|
|
stack[0] = element_map->buf[i].face;
|
2012-02-12 10:51:45 +00:00
|
|
|
island_number[BM_elem_index_get(stack[0])] = nislands;
|
2012-02-10 18:09:19 +00:00
|
|
|
stacksize = 1;
|
2012-01-17 21:08:25 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
while (stacksize > 0) {
|
2012-01-17 21:08:25 +00:00
|
|
|
efa = stack[--stacksize];
|
|
|
|
|
2012-02-06 19:25:12 +00:00
|
|
|
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
|
2012-02-12 10:51:45 +00:00
|
|
|
UvElement *element, *initelement = element_map->vert[BM_elem_index_get(l->v)];
|
2012-01-17 21:08:25 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
for (element = initelement; element; element = element->next) {
|
2012-02-05 15:55:28 +00:00
|
|
|
if (element->separate)
|
2012-01-17 21:08:25 +00:00
|
|
|
initelement = element;
|
|
|
|
|
2012-02-05 15:55:28 +00:00
|
|
|
if (element->face == efa) {
|
2012-01-17 21:08:25 +00:00
|
|
|
/* found the uv corresponding to our face and vertex. Now fill it to the buffer */
|
|
|
|
element->island = nislands;
|
2012-02-06 19:25:12 +00:00
|
|
|
map[element - element_map->buf] = islandbufsize;
|
2012-01-17 21:08:25 +00:00
|
|
|
islandbuf[islandbufsize].tfindex = element->tfindex;
|
|
|
|
islandbuf[islandbufsize].face = element->face;
|
|
|
|
islandbuf[islandbufsize].separate = element->separate;
|
|
|
|
islandbuf[islandbufsize].island = nislands;
|
|
|
|
islandbufsize++;
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
for (element = initelement; element; element = element->next) {
|
2012-02-05 15:55:28 +00:00
|
|
|
if (element->separate && element != initelement)
|
2012-01-17 21:08:25 +00:00
|
|
|
break;
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
if (island_number[BM_elem_index_get(element->face)] == INVALID_ISLAND) {
|
2012-01-17 21:08:25 +00:00
|
|
|
stack[stacksize++] = element->face;
|
2012-02-12 10:51:45 +00:00
|
|
|
island_number[BM_elem_index_get(element->face)] = nislands;
|
2012-01-17 21:08:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nislands++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remap */
|
2012-02-10 18:09:19 +00:00
|
|
|
for (i = 0; i < em->bm->totvert; i++) {
|
2012-01-17 21:08:25 +00:00
|
|
|
/* important since we may do selection only. Some of these may be NULL */
|
2012-02-10 18:09:19 +00:00
|
|
|
if (element_map->vert[i])
|
2012-02-06 19:25:12 +00:00
|
|
|
element_map->vert[i] = &islandbuf[map[element_map->vert[i] - element_map->buf]];
|
2012-01-17 21:08:25 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 19:25:12 +00:00
|
|
|
element_map->islandIndices = MEM_callocN(sizeof(*element_map->islandIndices)*nislands,"UvElementMap_island_indices");
|
2012-02-10 18:09:19 +00:00
|
|
|
if (!element_map->islandIndices) {
|
2012-01-17 21:08:25 +00:00
|
|
|
MEM_freeN(islandbuf);
|
|
|
|
MEM_freeN(stack);
|
|
|
|
MEM_freeN(map);
|
2012-02-06 19:25:12 +00:00
|
|
|
EDBM_free_uv_element_map(element_map);
|
|
|
|
MEM_freeN(island_number);
|
2012-01-17 21:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
j = 0;
|
2012-02-10 18:09:19 +00:00
|
|
|
for (i = 0; i < totuv; i++) {
|
2012-02-06 19:25:12 +00:00
|
|
|
UvElement *element = element_map->buf[i].next;
|
2012-02-05 15:55:28 +00:00
|
|
|
if (element == NULL)
|
2012-01-17 21:08:25 +00:00
|
|
|
islandbuf[map[i]].next = NULL;
|
|
|
|
else
|
2012-02-06 19:25:12 +00:00
|
|
|
islandbuf[map[i]].next = &islandbuf[map[element - element_map->buf]];
|
2012-01-17 21:08:25 +00:00
|
|
|
|
2012-02-05 15:55:28 +00:00
|
|
|
if (islandbuf[i].island != j) {
|
2012-01-17 21:08:25 +00:00
|
|
|
j++;
|
2012-02-06 19:25:12 +00:00
|
|
|
element_map->islandIndices[j] = i;
|
2012-01-17 21:08:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 19:25:12 +00:00
|
|
|
MEM_freeN(element_map->buf);
|
2012-01-17 21:08:25 +00:00
|
|
|
|
2012-02-06 19:25:12 +00:00
|
|
|
element_map->buf = islandbuf;
|
|
|
|
element_map->totalIslands = nislands;
|
2012-01-17 21:08:25 +00:00
|
|
|
MEM_freeN(stack);
|
|
|
|
MEM_freeN(map);
|
|
|
|
}
|
2012-02-14 00:35:29 +00:00
|
|
|
MEM_freeN(island_number);
|
2012-01-17 21:08:25 +00:00
|
|
|
|
2012-02-06 19:25:12 +00:00
|
|
|
return element_map;
|
2012-01-17 21:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UvMapVert *EM_get_uv_map_vert(UvVertMap *vmap, unsigned int v)
|
|
|
|
{
|
|
|
|
return vmap->vert[v];
|
|
|
|
}
|
|
|
|
|
2009-07-21 08:39:58 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 19:25:12 +00:00
|
|
|
void EDBM_free_uv_element_map(UvElementMap *element_map)
|
2012-01-17 21:08:25 +00:00
|
|
|
{
|
2012-02-06 19:25:12 +00:00
|
|
|
if (element_map) {
|
|
|
|
if (element_map->vert) MEM_freeN(element_map->vert);
|
|
|
|
if (element_map->buf) MEM_freeN(element_map->buf);
|
|
|
|
if (element_map->islandIndices) MEM_freeN(element_map->islandIndices);
|
|
|
|
MEM_freeN(element_map);
|
2012-01-17 21:08:25 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-21 08:39:58 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2012-02-05 15:55:28 +00:00
|
|
|
if (!EDBM_texFaceCheck(em))
|
2009-07-21 08:39:58 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
efa = BM_active_face_get(em->bm, sloppy);
|
2009-07-21 08:39:58 +00:00
|
|
|
|
|
|
|
if (efa) {
|
2012-02-10 18:09:19 +00:00
|
|
|
if (act_efa) *act_efa = efa;
|
2009-07-21 08:39:58 +00:00
|
|
|
return CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
|
|
|
|
}
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
if (act_efa) *act_efa = NULL;
|
2009-07-21 08:39:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* can we edit UV's for this mesh?*/
|
|
|
|
int EDBM_texFaceCheck(BMEditMesh *em)
|
|
|
|
{
|
|
|
|
/* some of these checks could be a touch overkill */
|
2010-01-28 00:45:30 +00:00
|
|
|
return em && em->bm->totface && CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY) &&
|
2011-02-23 08:12:27 +00:00
|
|
|
CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV);
|
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);
|
|
|
|
}
|
|
|
|
|
2011-12-20 22:01:11 +00:00
|
|
|
static BMVert *cache_mirr_intptr_as_bmvert(intptr_t *index_lookup, int index)
|
|
|
|
{
|
2012-02-10 18:09:19 +00:00
|
|
|
intptr_t eve_i = index_lookup[index];
|
2011-12-20 22:01:11 +00:00
|
|
|
return (eve_i == -1) ? NULL : (BMVert *)eve_i;
|
|
|
|
}
|
|
|
|
|
2011-10-26 07:41:56 +00:00
|
|
|
/* BM_SEARCH_MAXDIST is too big, copied from 2.6x MOC_THRESH, should become a
|
|
|
|
* preference */
|
|
|
|
#define BM_SEARCH_MAXDIST_MIRR 0.00002f
|
2011-10-28 06:23:12 +00:00
|
|
|
#define BM_CD_LAYER_ID "__mirror_index"
|
2011-11-01 05:43:35 +00:00
|
|
|
void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select)
|
2010-03-11 05:30:01 +00:00
|
|
|
{
|
2011-10-25 16:17:26 +00:00
|
|
|
Mesh *me = em->me;
|
2011-12-21 00:09:44 +00:00
|
|
|
BMesh *bm = em->bm;
|
2010-03-11 05:30:01 +00:00
|
|
|
BMIter iter;
|
|
|
|
BMVert *v;
|
2011-11-16 17:09:41 +00:00
|
|
|
int li, topo = 0;
|
2011-10-25 16:17:26 +00:00
|
|
|
|
2011-12-20 22:01:11 +00:00
|
|
|
/* one or the other is used depending if topo is enabled */
|
2012-02-10 18:09:19 +00:00
|
|
|
BMBVHTree *tree = NULL;
|
|
|
|
MirrTopoStore_t mesh_topo_store = {NULL, -1, -1, -1};
|
2011-12-20 22:01:11 +00:00
|
|
|
|
2011-10-25 16:17:26 +00:00
|
|
|
if (me && (me->editflag & ME_EDIT_MIRROR_TOPO)) {
|
|
|
|
topo = 1;
|
|
|
|
}
|
2010-03-11 05:30:01 +00:00
|
|
|
|
|
|
|
if (!em->vert_index) {
|
|
|
|
EDBM_init_index_arrays(em, 1, 0, 0);
|
|
|
|
em->mirr_free_arrays = 1;
|
|
|
|
}
|
|
|
|
|
2011-12-21 00:09:44 +00:00
|
|
|
if (!CustomData_get_layer_named(&bm->vdata, CD_PROP_INT, BM_CD_LAYER_ID)) {
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_data_layer_add_named(bm, &bm->vdata, CD_PROP_INT, BM_CD_LAYER_ID);
|
2010-03-11 05:30:01 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
li = CustomData_get_named_layer_index(&bm->vdata, CD_PROP_INT, BM_CD_LAYER_ID);
|
2011-10-28 06:23:12 +00:00
|
|
|
|
2011-12-21 00:09:44 +00:00
|
|
|
bm->vdata.layers[li].flag |= CD_FLAG_TEMPORARY;
|
2010-03-11 05:30:01 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2011-10-26 10:04:10 +00:00
|
|
|
|
2011-12-20 22:01:11 +00:00
|
|
|
if (topo) {
|
|
|
|
ED_mesh_mirrtopo_init(me, -1, &mesh_topo_store, TRUE);
|
|
|
|
}
|
|
|
|
else {
|
2012-02-10 18:09:19 +00:00
|
|
|
tree = BMBVH_NewBVH(em, 0, NULL, NULL);
|
2011-12-20 22:01:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-21 00:09:44 +00:00
|
|
|
BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) {
|
2011-10-26 07:41:56 +00:00
|
|
|
|
2011-12-21 00:09:44 +00:00
|
|
|
/* temporary for testing, check for selection */
|
2012-02-12 10:51:45 +00:00
|
|
|
if (use_select && !BM_elem_flag_test(v, BM_ELEM_SELECT)) {
|
2011-12-21 00:09:44 +00:00
|
|
|
/* do nothing */
|
2011-10-26 07:41:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-12-21 00:09:44 +00:00
|
|
|
BMVert *mirr;
|
|
|
|
int *idx = CustomData_bmesh_get_layer_n(&bm->vdata, v->head.data, li);
|
|
|
|
|
|
|
|
if (topo) {
|
2012-02-12 10:51:45 +00:00
|
|
|
mirr = cache_mirr_intptr_as_bmvert(mesh_topo_store.index_lookup, BM_elem_index_get(v));
|
2011-12-21 00:09:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
float co[3] = {-v->co[0], v->co[1], v->co[2]};
|
2012-02-10 18:09:19 +00:00
|
|
|
mirr = BMBVH_FindClosestVert(tree, co, BM_SEARCH_MAXDIST_MIRR);
|
2011-12-21 00:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mirr && mirr != v) {
|
2012-02-12 10:51:45 +00:00
|
|
|
*idx = BM_elem_index_get(mirr);
|
2011-12-21 00:09:44 +00:00
|
|
|
idx = CustomData_bmesh_get_layer_n(&bm->vdata, mirr->head.data, li);
|
2012-02-12 10:51:45 +00:00
|
|
|
*idx = BM_elem_index_get(v);
|
2011-12-21 00:09:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*idx = -1;
|
|
|
|
}
|
2011-10-26 07:41:56 +00:00
|
|
|
}
|
2011-12-21 00:09:44 +00:00
|
|
|
|
2010-03-11 05:30:01 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 22:01:11 +00:00
|
|
|
|
|
|
|
if (topo) {
|
|
|
|
ED_mesh_mirrtopo_free(&mesh_topo_store);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BMBVH_FreeBVH(tree);
|
|
|
|
}
|
2011-10-28 06:23:12 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
em->mirror_cdlayer = li;
|
2010-03-11 05:30:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BMVert *EDBM_GetMirrorVert(BMEditMesh *em, BMVert *v)
|
|
|
|
{
|
|
|
|
int *mirr = CustomData_bmesh_get_layer_n(&em->bm->vdata, v->head.data, em->mirror_cdlayer);
|
2011-10-28 06:23:12 +00:00
|
|
|
|
|
|
|
BLI_assert(em->mirror_cdlayer != -1); /* invalid use */
|
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
if (mirr && *mirr >= 0 && *mirr < em->bm->totvert) {
|
2010-03-11 05:30:01 +00:00
|
|
|
if (!em->vert_index) {
|
|
|
|
printf("err: should only be called between "
|
2012-02-10 18:09:19 +00:00
|
|
|
"EDBM_CacheMirrorVerts and EDBM_EndMirrorCache");
|
2010-03-11 05:30:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return em->vert_index[*mirr];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-01 05:43:35 +00:00
|
|
|
void EDBM_ClearMirrorVert(BMEditMesh *em, BMVert *v)
|
|
|
|
{
|
|
|
|
int *mirr = CustomData_bmesh_get_layer_n(&em->bm->vdata, v->head.data, em->mirror_cdlayer);
|
|
|
|
|
|
|
|
BLI_assert(em->mirror_cdlayer != -1); /* invalid use */
|
|
|
|
|
|
|
|
if (mirr) {
|
2012-02-10 18:09:19 +00:00
|
|
|
*mirr = -1;
|
2011-11-01 05:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-11 05:30:01 +00:00
|
|
|
void EDBM_EndMirrorCache(BMEditMesh *em)
|
|
|
|
{
|
|
|
|
if (em->mirr_free_arrays) {
|
|
|
|
MEM_freeN(em->vert_index);
|
|
|
|
em->vert_index = NULL;
|
|
|
|
}
|
2011-10-28 06:23:12 +00:00
|
|
|
|
2012-02-10 18:09:19 +00:00
|
|
|
em->mirror_cdlayer = -1;
|
2010-03-11 05:30:01 +00:00
|
|
|
}
|
2011-10-26 07:41:56 +00:00
|
|
|
|
|
|
|
void EDBM_ApplyMirrorCache(BMEditMesh *em, const int sel_from, const int sel_to)
|
|
|
|
{
|
|
|
|
BMIter iter;
|
|
|
|
BMVert *v;
|
|
|
|
|
|
|
|
BLI_assert(em->vert_index != NULL);
|
|
|
|
|
|
|
|
BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
|
2012-02-12 10:51:45 +00:00
|
|
|
if (BM_elem_flag_test(v, BM_ELEM_SELECT) == sel_from) {
|
2012-02-10 18:09:19 +00:00
|
|
|
BMVert *mirr = EDBM_GetMirrorVert(em, v);
|
2011-10-26 07:41:56 +00:00
|
|
|
if (mirr) {
|
2012-02-12 10:51:45 +00:00
|
|
|
if (BM_elem_flag_test(mirr, BM_ELEM_SELECT) == sel_to) {
|
2011-10-26 07:41:56 +00:00
|
|
|
copy_v3_v3(mirr->co, v->co);
|
|
|
|
mirr->co[0] *= -1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|