2011-10-24 23:32:24 +00:00
|
|
|
/*
|
2009-05-16 16:18:08 +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,
|
2011-12-02 03:18:34 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-05-16 16:18:08 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
/** \file blender/blenkernel/intern/editderivedmesh.c
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*/
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-12-07 04:27:40 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "GL/glew.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-05-09 04:06:48 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_edgehash.h"
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "BLI_math.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-12-15 15:59:25 +00:00
|
|
|
#include "BKE_pbvh.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_mesh.h"
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "BKE_paint.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
|
2012-03-02 12:09:49 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "GPU_buffers.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
#include "GPU_draw.h"
|
|
|
|
|
#include "GPU_extensions.h"
|
|
|
|
|
#include "GPU_material.h"
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
/* bmesh */
|
|
|
|
|
#include "BKE_tessmesh.h"
|
|
|
|
|
#include "BLI_array.h"
|
|
|
|
|
#include "BLI_scanfill.h"
|
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
#include "bmesh.h"
|
2011-12-02 03:18:34 +00:00
|
|
|
/* end bmesh */
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-09-17 12:25:51 +00:00
|
|
|
extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */
|
|
|
|
|
|
|
|
|
|
|
2012-03-20 22:56:26 +00:00
|
|
|
BMEditMesh *BMEdit_Create(BMesh *bm, int do_tessellate)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-12-12 05:27:52 +00:00
|
|
|
BMEditMesh *em = MEM_callocN(sizeof(BMEditMesh), __func__);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
em->bm = bm;
|
2012-03-20 22:56:26 +00:00
|
|
|
if (do_tessellate) {
|
2012-12-12 05:27:52 +00:00
|
|
|
BMEdit_RecalcTessellation(em);
|
2012-01-22 21:12:18 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
return em;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
BMEditMesh *BMEdit_Copy(BMEditMesh *em)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-12-12 05:27:52 +00:00
|
|
|
BMEditMesh *em_copy = MEM_callocN(sizeof(BMEditMesh), __func__);
|
|
|
|
|
*em_copy = *em;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
em_copy->derivedCage = em_copy->derivedFinal = NULL;
|
2011-09-16 14:28:23 +00:00
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
em_copy->bm = BM_mesh_copy(em->bm);
|
2011-09-16 14:28:23 +00:00
|
|
|
|
2012-03-03 20:19:11 +00:00
|
|
|
/* The tessellation is NOT calculated on the copy here,
|
|
|
|
|
* because currently all the callers of this function use
|
|
|
|
|
* it to make a backup copy of the BMEditMesh to restore
|
|
|
|
|
* it in the case of errors in an operation. For perf
|
|
|
|
|
* reasons, in that case it makes more sense to do the
|
|
|
|
|
* tessellation only when/if that copy ends up getting
|
|
|
|
|
* used.*/
|
2012-12-12 05:27:52 +00:00
|
|
|
em_copy->looptris = NULL;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
em_copy->vert_index = NULL;
|
|
|
|
|
em_copy->edge_index = NULL;
|
|
|
|
|
em_copy->face_index = NULL;
|
2009-05-19 00:33:54 +00:00
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
return em_copy;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
static void BMEdit_RecalcTessellation_intern(BMEditMesh *em)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2011-11-18 16:06:20 +00:00
|
|
|
/* use this to avoid locking pthread for _every_ polygon
|
|
|
|
|
* and calling the fill function */
|
|
|
|
|
#define USE_TESSFACE_SPEEDUP
|
|
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
BMesh *bm = em->bm;
|
2012-12-27 04:18:22 +00:00
|
|
|
|
|
|
|
|
/* this assumes all faces can be scan-filled, which isn't always true,
|
|
|
|
|
* worst case we over alloc a little which is acceptable */
|
|
|
|
|
const int looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
|
|
|
|
|
const int looptris_tot_prev_alloc = em->looptris ? (MEM_allocN_len(em->looptris) / sizeof(*em->looptris)) : 0;
|
|
|
|
|
|
|
|
|
|
BMLoop *(*looptris)[3];
|
2012-12-21 07:24:31 +00:00
|
|
|
BMIter iter;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMFace *efa;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMLoop *l;
|
2012-12-21 07:24:31 +00:00
|
|
|
int i = 0;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-04-16 06:48:57 +00:00
|
|
|
ScanFillContext sf_ctx;
|
|
|
|
|
|
2012-01-23 13:25:06 +00:00
|
|
|
#if 0
|
|
|
|
|
/* note, we could be clever and re-use this array but would need to ensure
|
|
|
|
|
* its realloced at some point, for now just free it */
|
2012-12-12 05:27:52 +00:00
|
|
|
if (em->looptris) MEM_freeN(em->looptris);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
/* Use em->tottri when set, this means no reallocs while transforming,
|
2012-01-23 13:25:06 +00:00
|
|
|
* (unless scanfill fails), otherwise... */
|
|
|
|
|
/* allocate the length of totfaces, avoid many small reallocs,
|
|
|
|
|
* if all faces are tri's it will be correct, quads == 2x allocs */
|
2012-12-12 05:27:52 +00:00
|
|
|
BLI_array_reserve(looptris, (em->tottri && em->tottri < bm->totface * 3) ? em->tottri : bm->totface);
|
2012-01-23 13:25:06 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
/* this means no reallocs for quad dominant models, for */
|
2012-12-27 04:18:22 +00:00
|
|
|
if ((em->looptris != NULL) &&
|
|
|
|
|
/* (em->tottri >= looptris_tot)) */
|
|
|
|
|
/* check against alloc'd size incase we over alloc'd a little */
|
|
|
|
|
((looptris_tot_prev_alloc >= looptris_tot) && (looptris_tot_prev_alloc <= looptris_tot * 2)))
|
2012-01-23 13:25:06 +00:00
|
|
|
{
|
2012-12-12 05:27:52 +00:00
|
|
|
looptris = em->looptris;
|
2012-01-23 13:25:06 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-12-12 05:27:52 +00:00
|
|
|
if (em->looptris) MEM_freeN(em->looptris);
|
2012-12-27 04:18:22 +00:00
|
|
|
looptris = MEM_mallocN(sizeof(*looptris) * looptris_tot, __func__);
|
2012-01-23 13:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
|
2012-08-17 14:43:20 +00:00
|
|
|
/* don't consider two-edged faces */
|
2012-09-19 08:09:22 +00:00
|
|
|
if (UNLIKELY(efa->len < 3)) {
|
2011-11-18 16:06:20 +00:00
|
|
|
/* do nothing */
|
2009-07-26 13:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-18 16:06:20 +00:00
|
|
|
#ifdef USE_TESSFACE_SPEEDUP
|
2009-07-26 13:12:55 +00:00
|
|
|
|
2011-11-18 16:06:20 +00:00
|
|
|
/* no need to ensure the loop order, we know its ok */
|
2009-05-23 16:53:03 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
else if (efa->len == 3) {
|
2012-12-21 07:24:31 +00:00
|
|
|
#if 0
|
|
|
|
|
int j;
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, j) {
|
2011-11-18 16:06:20 +00:00
|
|
|
looptris[i][j] = l;
|
2009-07-26 13:12:55 +00:00
|
|
|
}
|
2011-11-18 16:06:20 +00:00
|
|
|
i += 1;
|
2012-12-21 07:24:31 +00:00
|
|
|
#else
|
|
|
|
|
/* more cryptic but faster */
|
2012-12-27 06:39:27 +00:00
|
|
|
BMLoop **l_ptr = looptris[i++];
|
|
|
|
|
l_ptr[0] = l = BM_FACE_FIRST_LOOP(efa);
|
|
|
|
|
l_ptr[1] = l = l->next;
|
|
|
|
|
l_ptr[2] = l->next;
|
2012-12-21 07:24:31 +00:00
|
|
|
#endif
|
2011-11-18 16:06:20 +00:00
|
|
|
}
|
2012-05-13 14:47:53 +00:00
|
|
|
else if (efa->len == 4) {
|
2012-12-21 07:24:31 +00:00
|
|
|
#if 0
|
2011-11-18 16:06:20 +00:00
|
|
|
BMLoop *ltmp[4];
|
2012-12-21 07:24:31 +00:00
|
|
|
int j;
|
2012-04-28 15:14:16 +00:00
|
|
|
BLI_array_grow_items(looptris, 2);
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, j) {
|
2011-11-18 16:06:20 +00:00
|
|
|
ltmp[j] = l;
|
2009-05-23 16:53:03 +00:00
|
|
|
}
|
2009-07-26 13:12:55 +00:00
|
|
|
|
2011-11-18 16:06:20 +00:00
|
|
|
looptris[i][0] = ltmp[0];
|
|
|
|
|
looptris[i][1] = ltmp[1];
|
|
|
|
|
looptris[i][2] = ltmp[2];
|
|
|
|
|
i += 1;
|
|
|
|
|
|
|
|
|
|
looptris[i][0] = ltmp[0];
|
|
|
|
|
looptris[i][1] = ltmp[2];
|
|
|
|
|
looptris[i][2] = ltmp[3];
|
2009-07-26 13:12:55 +00:00
|
|
|
i += 1;
|
2012-12-21 07:24:31 +00:00
|
|
|
#else
|
|
|
|
|
/* more cryptic but faster */
|
2012-12-27 06:39:27 +00:00
|
|
|
BMLoop **l_ptr_a = looptris[i++];
|
|
|
|
|
BMLoop **l_ptr_b = looptris[i++];
|
|
|
|
|
(l_ptr_a[0] = l_ptr_b[0] = l = BM_FACE_FIRST_LOOP(efa));
|
|
|
|
|
(l_ptr_a[1] = l = l->next);
|
|
|
|
|
(l_ptr_a[2] = l_ptr_b[1] = l = l->next);
|
|
|
|
|
( l_ptr_b[2] = l->next);
|
2012-12-21 07:24:31 +00:00
|
|
|
#endif
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2009-07-26 13:12:55 +00:00
|
|
|
|
2011-11-18 16:06:20 +00:00
|
|
|
#endif /* USE_TESSFACE_SPEEDUP */
|
|
|
|
|
|
|
|
|
|
else {
|
2012-12-21 07:24:31 +00:00
|
|
|
int j;
|
|
|
|
|
BMLoop *l_iter;
|
|
|
|
|
BMLoop *l_first;
|
|
|
|
|
|
2012-12-03 08:11:04 +00:00
|
|
|
ScanFillVert *sf_vert, *sf_vert_last = NULL, *sf_vert_first = NULL;
|
2012-03-04 11:58:55 +00:00
|
|
|
/* ScanFillEdge *e; */ /* UNUSED */
|
2012-05-13 14:47:53 +00:00
|
|
|
ScanFillFace *sf_tri;
|
2012-12-27 06:39:27 +00:00
|
|
|
int totfilltri;
|
2011-11-18 16:06:20 +00:00
|
|
|
|
2012-05-05 00:23:55 +00:00
|
|
|
BLI_scanfill_begin(&sf_ctx);
|
2012-05-13 14:47:53 +00:00
|
|
|
|
|
|
|
|
/* scanfill time */
|
2012-12-21 07:24:31 +00:00
|
|
|
j = 0;
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
|
|
|
|
|
do {
|
|
|
|
|
sf_vert = BLI_scanfill_vert_add(&sf_ctx, l_iter->v->co);
|
|
|
|
|
sf_vert->tmp.p = l_iter;
|
2011-11-18 16:06:20 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
if (sf_vert_last) {
|
|
|
|
|
/* e = */ BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert);
|
2011-11-18 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
sf_vert_last = sf_vert;
|
2012-12-21 07:24:31 +00:00
|
|
|
if (sf_vert_first == NULL) {
|
|
|
|
|
sf_vert_first = sf_vert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*mark order */
|
|
|
|
|
BM_elem_index_set(l_iter, j++); /* set_loop */
|
|
|
|
|
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
2011-11-18 16:06:20 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
/* complete the loop */
|
|
|
|
|
BLI_scanfill_edge_add(&sf_ctx, sf_vert_first, sf_vert);
|
2011-11-18 16:06:20 +00:00
|
|
|
|
2012-12-27 06:39:27 +00:00
|
|
|
totfilltri = BLI_scanfill_calc_ex(&sf_ctx, 0, efa->no);
|
|
|
|
|
BLI_assert(totfilltri <= efa->len - 2);
|
2011-11-18 16:06:20 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next) {
|
2012-12-27 06:39:27 +00:00
|
|
|
BMLoop **l_ptr = looptris[i++];
|
2012-05-13 14:47:53 +00:00
|
|
|
BMLoop *l1 = sf_tri->v1->tmp.p;
|
|
|
|
|
BMLoop *l2 = sf_tri->v2->tmp.p;
|
|
|
|
|
BMLoop *l3 = sf_tri->v3->tmp.p;
|
2011-11-18 16:06:20 +00:00
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop *, l1, l2); }
|
|
|
|
|
if (BM_elem_index_get(l2) > BM_elem_index_get(l3)) { SWAP(BMLoop *, l2, l3); }
|
|
|
|
|
if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop *, l1, l2); }
|
2011-11-18 16:06:20 +00:00
|
|
|
|
2012-12-27 06:39:27 +00:00
|
|
|
l_ptr[0] = l1;
|
|
|
|
|
l_ptr[1] = l2;
|
|
|
|
|
l_ptr[2] = l3;
|
2011-11-18 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:23:55 +00:00
|
|
|
BLI_scanfill_end(&sf_ctx);
|
2011-11-18 16:06:20 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 05:27:52 +00:00
|
|
|
em->tottri = i;
|
|
|
|
|
em->looptris = looptris;
|
2011-11-18 16:06:20 +00:00
|
|
|
|
2012-12-27 04:18:22 +00:00
|
|
|
BLI_assert(em->tottri <= looptris_tot);
|
|
|
|
|
|
2011-11-18 16:06:20 +00:00
|
|
|
#undef USE_TESSFACE_SPEEDUP
|
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-02 16:05:54 +00:00
|
|
|
void BMEdit_RecalcTessellation(BMEditMesh *em)
|
2009-06-23 05:35:49 +00:00
|
|
|
{
|
2012-03-02 16:05:54 +00:00
|
|
|
BMEdit_RecalcTessellation_intern(em);
|
2011-06-01 19:47:21 +00:00
|
|
|
|
2012-01-20 13:53:47 +00:00
|
|
|
/* commented because editbmesh_build_data() ensures we get tessfaces */
|
|
|
|
|
#if 0
|
2011-06-01 19:47:21 +00:00
|
|
|
if (em->derivedFinal && em->derivedFinal == em->derivedCage) {
|
2012-03-02 16:05:54 +00:00
|
|
|
if (em->derivedFinal->recalcTessellation)
|
|
|
|
|
em->derivedFinal->recalcTessellation(em->derivedFinal);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else if (em->derivedFinal) {
|
2012-03-02 16:05:54 +00:00
|
|
|
if (em->derivedCage->recalcTessellation)
|
|
|
|
|
em->derivedCage->recalcTessellation(em->derivedCage);
|
|
|
|
|
if (em->derivedFinal->recalcTessellation)
|
|
|
|
|
em->derivedFinal->recalcTessellation(em->derivedFinal);
|
2009-06-23 05:35:49 +00:00
|
|
|
}
|
2012-01-20 13:53:47 +00:00
|
|
|
#endif
|
2009-06-23 05:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-30 21:30:07 +00:00
|
|
|
void BMEdit_UpdateLinkedCustomData(BMEditMesh *em)
|
|
|
|
|
{
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
int act;
|
|
|
|
|
|
|
|
|
|
if (CustomData_has_layer(&bm->pdata, CD_MTEXPOLY)) {
|
|
|
|
|
act = CustomData_get_active_layer(&bm->pdata, CD_MTEXPOLY);
|
|
|
|
|
CustomData_set_layer_active(&bm->ldata, CD_MLOOPUV, act);
|
|
|
|
|
|
|
|
|
|
act = CustomData_get_render_layer(&bm->pdata, CD_MTEXPOLY);
|
|
|
|
|
CustomData_set_layer_render(&bm->ldata, CD_MLOOPUV, act);
|
|
|
|
|
|
|
|
|
|
act = CustomData_get_clone_layer(&bm->pdata, CD_MTEXPOLY);
|
|
|
|
|
CustomData_set_layer_clone(&bm->ldata, CD_MLOOPUV, act);
|
|
|
|
|
|
2010-01-05 22:33:41 +00:00
|
|
|
act = CustomData_get_stencil_layer(&bm->pdata, CD_MTEXPOLY);
|
|
|
|
|
CustomData_set_layer_stencil(&bm->ldata, CD_MLOOPUV, act);
|
2009-08-30 21:30:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
/*does not free the BMEditMesh struct itself*/
|
2009-05-26 04:17:47 +00:00
|
|
|
void BMEdit_Free(BMEditMesh *em)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2011-12-02 03:18:34 +00:00
|
|
|
if (em->derivedFinal) {
|
2012-05-12 19:18:02 +00:00
|
|
|
if (em->derivedFinal != em->derivedCage) {
|
|
|
|
|
em->derivedFinal->needsFree = 1;
|
2009-05-16 16:18:08 +00:00
|
|
|
em->derivedFinal->release(em->derivedFinal);
|
|
|
|
|
}
|
2012-05-12 19:18:02 +00:00
|
|
|
em->derivedFinal = NULL;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
if (em->derivedCage) {
|
2012-05-12 19:18:02 +00:00
|
|
|
em->derivedCage->needsFree = 1;
|
2009-05-16 16:18:08 +00:00
|
|
|
em->derivedCage->release(em->derivedCage);
|
2012-05-12 19:18:02 +00:00
|
|
|
em->derivedCage = NULL;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (em->looptris) MEM_freeN(em->looptris);
|
2009-05-18 15:53:30 +00:00
|
|
|
|
|
|
|
|
if (em->vert_index) MEM_freeN(em->vert_index);
|
|
|
|
|
if (em->edge_index) MEM_freeN(em->edge_index);
|
|
|
|
|
if (em->face_index) MEM_freeN(em->face_index);
|
2009-05-26 04:17:47 +00:00
|
|
|
|
2011-03-29 05:48:18 +00:00
|
|
|
if (em->bm)
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_free(em->bm);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-03 20:19:11 +00:00
|
|
|
* ok, basic design:
|
|
|
|
|
*
|
|
|
|
|
* the bmesh derivedmesh exposes the mesh as triangles. it stores pointers
|
|
|
|
|
* to three loops per triangle. the derivedmesh stores a cache of tessellations
|
|
|
|
|
* for each face. this cache will smartly update as needed (though at first
|
|
|
|
|
* it'll simply be more brute force). keeping track of face/edge counts may
|
|
|
|
|
* be a small problbm.
|
|
|
|
|
*
|
|
|
|
|
* this won't be the most efficient thing, considering that internal edges and
|
|
|
|
|
* faces of tessellations are exposed. looking up an edge by index in particular
|
|
|
|
|
* is likely to be a little slow.
|
|
|
|
|
*/
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
typedef struct EditDerivedBMesh {
|
|
|
|
|
DerivedMesh dm;
|
|
|
|
|
|
|
|
|
|
Object *ob;
|
2009-05-18 08:46:04 +00:00
|
|
|
BMEditMesh *tc;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
float (*vertexCos)[3];
|
|
|
|
|
float (*vertexNos)[3];
|
2012-01-24 19:37:18 +00:00
|
|
|
float (*polyNos)[3];
|
2009-06-23 05:35:49 +00:00
|
|
|
|
2012-02-19 01:51:36 +00:00
|
|
|
/* private variables, for number of verts/edges/faces
|
2012-08-17 14:43:20 +00:00
|
|
|
* within the above hash/table members */
|
2009-06-23 05:35:49 +00:00
|
|
|
int tv, te, tf;
|
2009-05-16 16:18:08 +00:00
|
|
|
} EditDerivedBMesh;
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_calcNormals(DerivedMesh *UNUSED(dm))
|
2011-11-13 15:13:59 +00:00
|
|
|
{
|
|
|
|
|
/* Nothing to do: normals are already calculated and stored on the
|
2012-03-03 20:19:11 +00:00
|
|
|
* BMVerts and BMFaces */
|
2011-11-13 15:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-02 16:05:54 +00:00
|
|
|
static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm))
|
2009-06-23 05:35:49 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
/* do nothing */
|
2009-06-23 05:35:49 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_foreachMappedVert(DerivedMesh *dm,
|
|
|
|
|
void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]),
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMVert *eve;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
if (bmdm->vertexCos) {
|
|
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH, i) {
|
2009-05-16 16:18:08 +00:00
|
|
|
func(userData, i, bmdm->vertexCos[i], bmdm->vertexNos[i], NULL);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH, i) {
|
2009-05-16 16:18:08 +00:00
|
|
|
func(userData, i, eve->co, eve->no, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_foreachMappedEdge(DerivedMesh *dm,
|
|
|
|
|
void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]),
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMEdge *eed;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
if (bmdm->vertexCos) {
|
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
|
2011-12-02 03:18:34 +00:00
|
|
|
func(userData, i,
|
2012-05-12 19:18:02 +00:00
|
|
|
bmdm->vertexCos[BM_elem_index_get(eed->v1)],
|
|
|
|
|
bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
|
2012-05-13 14:47:53 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
|
2009-05-16 16:18:08 +00:00
|
|
|
func(userData, i, eed->v1->co, eed->v2->co);
|
2012-05-13 14:47:53 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawMappedEdges(DerivedMesh *dm,
|
|
|
|
|
DMSetDrawOptions setDrawOptions,
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMEdge *eed;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
if (bmdm->vertexCos) {
|
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
|
2012-03-08 06:47:05 +00:00
|
|
|
if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
|
2012-02-12 10:51:45 +00:00
|
|
|
glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
|
|
|
|
|
glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
glEnd();
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2009-05-16 16:18:08 +00:00
|
|
|
glBegin(GL_LINES);
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
|
2012-03-08 06:47:05 +00:00
|
|
|
if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
|
2009-05-16 16:18:08 +00:00
|
|
|
glVertex3fv(eed->v1->co);
|
|
|
|
|
glVertex3fv(eed->v2->co);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawEdges(DerivedMesh *dm,
|
|
|
|
|
int UNUSED(drawLooseEdges),
|
|
|
|
|
int UNUSED(drawAllEdges))
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2011-12-02 03:18:34 +00:00
|
|
|
emDM_drawMappedEdges(dm, NULL, NULL);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawMappedEdgesInterp(DerivedMesh *dm,
|
|
|
|
|
DMSetDrawOptions setDrawOptions,
|
|
|
|
|
DMSetDrawInterpOptions setDrawInterpOptions,
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMEdge *eed;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (bmdm->vertexCos) {
|
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
|
2012-03-08 06:47:05 +00:00
|
|
|
if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
|
2009-05-16 16:18:08 +00:00
|
|
|
setDrawInterpOptions(userData, i, 0.0);
|
2012-02-12 10:51:45 +00:00
|
|
|
glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
|
2009-05-16 16:18:08 +00:00
|
|
|
setDrawInterpOptions(userData, i, 1.0);
|
2012-02-12 10:51:45 +00:00
|
|
|
glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
glEnd();
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2009-05-16 16:18:08 +00:00
|
|
|
glBegin(GL_LINES);
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, bmdm->tc->bm, BM_EDGES_OF_MESH, i) {
|
2012-03-08 06:47:05 +00:00
|
|
|
if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
|
2009-05-16 16:18:08 +00:00
|
|
|
setDrawInterpOptions(userData, i, 0.0);
|
|
|
|
|
glVertex3fv(eed->v1->co);
|
|
|
|
|
setDrawInterpOptions(userData, i, 1.0);
|
|
|
|
|
glVertex3fv(eed->v2->co);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_drawUVEdges(DerivedMesh *dm)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2011-02-27 06:19:40 +00:00
|
|
|
BMEditMesh *em = bmdm->tc;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *efa;
|
2011-02-27 06:19:40 +00:00
|
|
|
BMIter iter;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
|
2011-02-27 06:19:40 +00:00
|
|
|
BMIter liter;
|
|
|
|
|
BMLoop *l;
|
|
|
|
|
MLoopUV *lastluv = NULL, *firstluv = NULL;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
|
2011-02-27 06:19:40 +00:00
|
|
|
continue;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
|
2011-02-27 06:19:40 +00:00
|
|
|
MLoopUV *luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2011-02-27 06:19:40 +00:00
|
|
|
if (luv) {
|
2011-12-02 03:18:34 +00:00
|
|
|
if (lastluv)
|
2011-02-27 06:19:40 +00:00
|
|
|
glVertex2fv(luv->uv);
|
|
|
|
|
glVertex2fv(luv->uv);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2011-02-27 06:19:40 +00:00
|
|
|
lastluv = luv;
|
2011-12-02 03:18:34 +00:00
|
|
|
if (!firstluv)
|
2011-02-27 06:19:40 +00:00
|
|
|
firstluv = luv;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2011-02-27 06:19:40 +00:00
|
|
|
if (lastluv) {
|
|
|
|
|
glVertex2fv(lastluv->uv);
|
|
|
|
|
glVertex2fv(firstluv->uv);
|
|
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
static void emDM__calcFaceCent(BMFace *efa, float cent[3], float (*vertexCos)[3])
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-13 14:47:53 +00:00
|
|
|
BMIter liter;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMLoop *l;
|
|
|
|
|
int tot = 0;
|
2011-11-07 09:02:10 +00:00
|
|
|
|
|
|
|
|
zero_v3(cent);
|
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
/*simple (and stupid) median (average) based method :/ */
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
if (vertexCos) {
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
|
2012-02-12 10:51:45 +00:00
|
|
|
add_v3_v3(cent, vertexCos[BM_elem_index_get(l->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
tot++;
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
|
2011-11-07 09:02:10 +00:00
|
|
|
add_v3_v3(cent, l->v->co);
|
2009-07-24 10:43:58 +00:00
|
|
|
tot++;
|
|
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
if (tot == 0) return;
|
|
|
|
|
mul_v3_fl(cent, 1.0f / (float)tot);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_foreachMappedFaceCenter(DerivedMesh *dm,
|
|
|
|
|
void (*func)(void *userData, int index, const float co[3], const float no[3]),
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2012-01-24 19:37:18 +00:00
|
|
|
float (*polyNos)[3] = NULL;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *efa;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
float cent[3];
|
|
|
|
|
int i;
|
|
|
|
|
|
2012-01-24 19:37:18 +00:00
|
|
|
/* ensure for face center calculation */
|
2009-05-16 16:18:08 +00:00
|
|
|
if (bmdm->vertexCos) {
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT);
|
2012-01-24 19:37:18 +00:00
|
|
|
polyNos = bmdm->polyNos;
|
|
|
|
|
|
|
|
|
|
BLI_assert(polyNos != NULL);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
BM_ITER_MESH_INDEX (efa, &iter, bmdm->tc->bm, BM_FACES_OF_MESH, i) {
|
2012-05-13 14:47:53 +00:00
|
|
|
emDM__calcFaceCent(efa, cent, bmdm->vertexCos);
|
2012-01-24 19:37:18 +00:00
|
|
|
func(userData, i, cent, polyNos ? polyNos[i] : efa->no);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawMappedFaces(DerivedMesh *dm,
|
|
|
|
|
DMSetDrawOptions setDrawOptions,
|
|
|
|
|
DMSetMaterial setMaterial,
|
|
|
|
|
DMCompareDrawOptions compareDrawOptions,
|
|
|
|
|
void *userData,
|
|
|
|
|
DMDrawFlag flag)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *efa;
|
2012-05-03 21:19:31 +00:00
|
|
|
struct BMLoop *(*looptris)[3] = bmdm->tc->looptris;
|
|
|
|
|
const int tottri = bmdm->tc->tottri;
|
|
|
|
|
const int lasttri = tottri - 1; /* compare agasint this a lot */
|
2012-03-08 06:47:05 +00:00
|
|
|
DMDrawOption draw_option;
|
|
|
|
|
int i, flush;
|
2012-05-03 21:19:31 +00:00
|
|
|
const int skip_normals = !glIsEnabled(GL_LIGHTING); /* could be passed as an arg */
|
2011-09-11 13:23:30 +00:00
|
|
|
|
|
|
|
|
/* GL_ZERO is used to detect if drawing has started or not */
|
2012-05-03 21:19:31 +00:00
|
|
|
GLenum poly_prev = GL_ZERO;
|
|
|
|
|
GLenum shade_prev = GL_ZERO;
|
2011-09-11 13:23:30 +00:00
|
|
|
|
2011-08-30 00:23:11 +00:00
|
|
|
(void)setMaterial; /* UNUSED */
|
|
|
|
|
|
|
|
|
|
/* currently unused -- each original face is handled separately */
|
|
|
|
|
(void)compareDrawOptions;
|
2011-05-09 14:32:55 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
if (bmdm->vertexCos) {
|
2011-09-11 13:23:30 +00:00
|
|
|
/* add direct access */
|
2012-05-03 21:19:31 +00:00
|
|
|
float (*vertexCos)[3] = bmdm->vertexCos;
|
|
|
|
|
float (*vertexNos)[3] = bmdm->vertexNos;
|
|
|
|
|
float (*polyNos)[3] = bmdm->polyNos;
|
2012-05-27 19:40:36 +00:00
|
|
|
// int *triPolyMap = bmdm->triPolyMap;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT | BM_FACE);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
for (i = 0; i < tottri; i++) {
|
2011-12-10 05:38:00 +00:00
|
|
|
BMLoop **l = looptris[i];
|
2009-05-16 16:18:08 +00:00
|
|
|
int drawSmooth;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
efa = l[0]->f;
|
2012-05-03 21:19:31 +00:00
|
|
|
drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-03-08 06:47:05 +00:00
|
|
|
draw_option = (!setDrawOptions ?
|
2012-05-12 19:18:02 +00:00
|
|
|
DM_DRAW_OPTION_NORMAL :
|
|
|
|
|
setDrawOptions(userData, BM_elem_index_get(efa)));
|
2012-03-08 06:47:05 +00:00
|
|
|
if (draw_option != DM_DRAW_OPTION_SKIP) {
|
2012-05-03 21:19:31 +00:00
|
|
|
const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */
|
2012-03-08 06:47:05 +00:00
|
|
|
if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */
|
2011-09-11 13:23:30 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
if (poly_prev != GL_ZERO) glEnd();
|
2012-05-03 21:19:31 +00:00
|
|
|
poly_prev = GL_ZERO; /* force glBegin */
|
2011-09-11 13:23:30 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
glEnable(GL_POLYGON_STIPPLE);
|
|
|
|
|
glPolygonStipple(stipple_quarttone);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
|
|
|
|
|
if (skip_normals) {
|
|
|
|
|
if (poly_type != poly_prev) {
|
|
|
|
|
if (poly_prev != GL_ZERO) glEnd();
|
2012-05-03 21:19:31 +00:00
|
|
|
glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
2012-02-12 10:51:45 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(l[0]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(l[1]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(l[2]->v)]);
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-03 21:19:31 +00:00
|
|
|
const GLenum shade_type = drawSmooth ? GL_SMOOTH : GL_FLAT;
|
2011-09-11 13:23:30 +00:00
|
|
|
if (shade_type != shade_prev) {
|
2011-12-02 03:18:34 +00:00
|
|
|
if (poly_prev != GL_ZERO) glEnd();
|
2012-05-03 21:19:31 +00:00
|
|
|
glShadeModel((shade_prev = shade_type)); /* same as below but switch shading */
|
|
|
|
|
glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
if (poly_type != poly_prev) {
|
|
|
|
|
if (poly_prev != GL_ZERO) glEnd();
|
2012-05-03 21:19:31 +00:00
|
|
|
glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!drawSmooth) {
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(polyNos[BM_elem_index_get(efa)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(l[0]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(l[1]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(l[2]->v)]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(l[0]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(l[0]->v)]);
|
|
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(l[1]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(l[1]->v)]);
|
|
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(l[2]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(l[2]->v)]);
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
flush = (draw_option == DM_DRAW_OPTION_STIPPLE);
|
2011-12-10 05:38:00 +00:00
|
|
|
if (!skip_normals && !flush && (i != lasttri))
|
2012-05-12 19:18:02 +00:00
|
|
|
flush |= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */
|
2011-12-09 11:46:48 +00:00
|
|
|
|
|
|
|
|
if (flush) {
|
2011-09-11 13:23:30 +00:00
|
|
|
glEnd();
|
2012-05-03 21:19:31 +00:00
|
|
|
poly_prev = GL_ZERO; /* force glBegin */
|
2011-09-11 13:23:30 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
glDisable(GL_POLYGON_STIPPLE);
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_FACE);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
for (i = 0; i < tottri; i++) {
|
2011-12-10 05:38:00 +00:00
|
|
|
BMLoop **l = looptris[i];
|
2009-05-16 16:18:08 +00:00
|
|
|
int drawSmooth;
|
|
|
|
|
|
|
|
|
|
efa = l[0]->f;
|
2012-05-12 19:18:02 +00:00
|
|
|
drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-03-08 06:47:05 +00:00
|
|
|
draw_option = (!setDrawOptions ?
|
2012-05-12 19:18:02 +00:00
|
|
|
DM_DRAW_OPTION_NORMAL :
|
|
|
|
|
setDrawOptions(userData, BM_elem_index_get(efa)));
|
2012-03-08 06:47:05 +00:00
|
|
|
if (draw_option != DM_DRAW_OPTION_SKIP) {
|
2012-05-03 21:19:31 +00:00
|
|
|
const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */
|
2012-03-08 06:47:05 +00:00
|
|
|
if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */
|
2011-09-11 13:23:30 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
if (poly_prev != GL_ZERO) glEnd();
|
2012-05-03 21:19:31 +00:00
|
|
|
poly_prev = GL_ZERO; /* force glBegin */
|
2011-09-11 13:23:30 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
glEnable(GL_POLYGON_STIPPLE);
|
|
|
|
|
glPolygonStipple(stipple_quarttone);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
|
|
|
|
|
if (skip_normals) {
|
|
|
|
|
if (poly_type != poly_prev) {
|
|
|
|
|
if (poly_prev != GL_ZERO) glEnd();
|
2012-05-03 21:19:31 +00:00
|
|
|
glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
glVertex3fv(l[0]->v->co);
|
|
|
|
|
glVertex3fv(l[1]->v->co);
|
|
|
|
|
glVertex3fv(l[2]->v->co);
|
|
|
|
|
}
|
2011-09-11 13:23:30 +00:00
|
|
|
else {
|
2012-05-03 21:19:31 +00:00
|
|
|
const GLenum shade_type = drawSmooth ? GL_SMOOTH : GL_FLAT;
|
2011-09-11 13:23:30 +00:00
|
|
|
if (shade_type != shade_prev) {
|
2011-12-02 03:18:34 +00:00
|
|
|
if (poly_prev != GL_ZERO) glEnd();
|
2012-05-03 21:19:31 +00:00
|
|
|
glShadeModel((shade_prev = shade_type)); /* same as below but switch shading */
|
|
|
|
|
glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
if (poly_type != poly_prev) {
|
|
|
|
|
if (poly_prev != GL_ZERO) glEnd();
|
2012-05-03 21:19:31 +00:00
|
|
|
glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!drawSmooth) {
|
|
|
|
|
glNormal3fv(efa->no);
|
|
|
|
|
glVertex3fv(l[0]->v->co);
|
|
|
|
|
glVertex3fv(l[1]->v->co);
|
|
|
|
|
glVertex3fv(l[2]->v->co);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-09-11 13:23:30 +00:00
|
|
|
glNormal3fv(l[0]->v->no);
|
|
|
|
|
glVertex3fv(l[0]->v->co);
|
|
|
|
|
glNormal3fv(l[1]->v->no);
|
|
|
|
|
glVertex3fv(l[1]->v->co);
|
|
|
|
|
glNormal3fv(l[2]->v->no);
|
|
|
|
|
glVertex3fv(l[2]->v->co);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
flush = (draw_option == DM_DRAW_OPTION_STIPPLE);
|
2011-12-10 05:38:00 +00:00
|
|
|
if (!skip_normals && !flush && (i != lasttri)) {
|
2012-05-03 21:19:31 +00:00
|
|
|
flush |= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */
|
2011-12-10 05:38:00 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2011-12-09 11:46:48 +00:00
|
|
|
if (flush) {
|
2011-09-11 13:23:30 +00:00
|
|
|
glEnd();
|
2012-05-12 19:18:02 +00:00
|
|
|
poly_prev = GL_ZERO; /* force glBegin */
|
2011-09-11 13:23:30 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
glDisable(GL_POLYGON_STIPPLE);
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-11 13:23:30 +00:00
|
|
|
|
|
|
|
|
/* if non zero we know a face was rendered */
|
2011-12-02 03:18:34 +00:00
|
|
|
if (poly_prev != GL_ZERO) glEnd();
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void bmdm_get_tri_tex(BMesh *bm, BMLoop **ls, MLoopUV *luv[3], MLoopCol *lcol[3],
|
2012-05-03 21:19:31 +00:00
|
|
|
int has_uv, int has_col)
|
2009-07-24 10:43:58 +00:00
|
|
|
{
|
2011-12-02 03:18:34 +00:00
|
|
|
if (has_uv) {
|
2009-07-24 10:43:58 +00:00
|
|
|
luv[0] = CustomData_bmesh_get(&bm->ldata, ls[0]->head.data, CD_MLOOPUV);
|
|
|
|
|
luv[1] = CustomData_bmesh_get(&bm->ldata, ls[1]->head.data, CD_MLOOPUV);
|
|
|
|
|
luv[2] = CustomData_bmesh_get(&bm->ldata, ls[2]->head.data, CD_MLOOPUV);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (has_col) {
|
|
|
|
|
lcol[0] = CustomData_bmesh_get(&bm->ldata, ls[0]->head.data, CD_MLOOPCOL);
|
|
|
|
|
lcol[1] = CustomData_bmesh_get(&bm->ldata, ls[1]->head.data, CD_MLOOPCOL);
|
|
|
|
|
lcol[2] = CustomData_bmesh_get(&bm->ldata, ls[2]->head.data, CD_MLOOPCOL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawFacesTex_common(DerivedMesh *dm,
|
|
|
|
|
DMSetDrawOptionsTex drawParams,
|
|
|
|
|
DMSetDrawOptions drawParamsMapped,
|
|
|
|
|
DMCompareDrawOptions compareDrawOptions,
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-07-24 10:43:58 +00:00
|
|
|
BMEditMesh *em = bmdm->tc;
|
2012-05-03 21:19:31 +00:00
|
|
|
BMesh *bm = bmdm->tc->bm;
|
|
|
|
|
float (*vertexCos)[3] = bmdm->vertexCos;
|
|
|
|
|
float (*vertexNos)[3] = bmdm->vertexNos;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *efa;
|
2011-05-09 04:06:48 +00:00
|
|
|
MLoopUV *luv[3], dummyluv = {{0}};
|
2012-03-06 21:21:22 +00:00
|
|
|
MLoopCol *lcol[3] = {NULL}, dummylcol = {0};
|
2009-07-24 10:43:58 +00:00
|
|
|
int i, has_vcol = CustomData_has_layer(&bm->ldata, CD_MLOOPCOL);
|
|
|
|
|
int has_uv = CustomData_has_layer(&bm->pdata, CD_MTEXPOLY);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2011-12-02 01:01:07 +00:00
|
|
|
(void) compareDrawOptions;
|
|
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
luv[0] = luv[1] = luv[2] = &dummyluv;
|
|
|
|
|
|
2012-03-17 20:39:28 +00:00
|
|
|
dummylcol.r = dummylcol.g = dummylcol.b = dummylcol.a = 255;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
/* always use smooth shading even for flat faces, else vertex colors wont interpolate */
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
2011-11-16 12:38:40 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_FACE);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
if (vertexCos) {
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2011-11-16 12:38:40 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
for (i = 0; i < em->tottri; i++) {
|
2009-07-24 10:43:58 +00:00
|
|
|
BMLoop **ls = em->looptris[i];
|
2012-05-03 21:19:31 +00:00
|
|
|
MTexPoly *tp = has_uv ? CustomData_bmesh_get(&bm->pdata, ls[0]->f->head.data, CD_MTEXPOLY) : NULL;
|
2011-05-09 04:06:48 +00:00
|
|
|
MTFace mtf = {{{0}}};
|
2012-05-27 19:40:36 +00:00
|
|
|
/*unsigned char *cp = NULL;*/ /*UNUSED*/
|
2012-05-03 21:19:31 +00:00
|
|
|
int drawSmooth = BM_elem_flag_test(ls[0]->f, BM_ELEM_SMOOTH);
|
2012-03-08 06:47:05 +00:00
|
|
|
DMDrawOption draw_option;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
efa = ls[0]->f;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
if (has_uv) {
|
2012-02-08 09:02:10 +00:00
|
|
|
ME_MTEXFACE_CPY(&mtf, tp);
|
2009-07-24 10:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
if (drawParams)
|
2012-05-03 21:19:31 +00:00
|
|
|
draw_option = drawParams(&mtf, has_vcol, efa->mat_nr);
|
2011-12-02 03:18:34 +00:00
|
|
|
else if (drawParamsMapped)
|
2012-05-03 21:19:31 +00:00
|
|
|
draw_option = drawParamsMapped(userData, BM_elem_index_get(efa));
|
2009-05-16 16:18:08 +00:00
|
|
|
else
|
2012-05-03 21:19:31 +00:00
|
|
|
draw_option = DM_DRAW_OPTION_NORMAL;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-03-08 06:47:05 +00:00
|
|
|
if (draw_option != DM_DRAW_OPTION_SKIP) {
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-05-01 15:59:28 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
2009-05-16 16:18:08 +00:00
|
|
|
if (!drawSmooth) {
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
glTexCoord2fv(luv[0]->uv);
|
2012-03-06 21:21:22 +00:00
|
|
|
if (lcol[0])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2012-02-12 10:51:45 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ls[0]->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
|
|
|
|
glTexCoord2fv(luv[1]->uv);
|
2012-03-06 21:21:22 +00:00
|
|
|
if (lcol[1])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2012-02-12 10:51:45 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ls[1]->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
|
|
|
|
glTexCoord2fv(luv[2]->uv);
|
2012-03-06 21:21:22 +00:00
|
|
|
if (lcol[2])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2012-02-12 10:51:45 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ls[2]->v)]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2009-07-24 10:43:58 +00:00
|
|
|
bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
glTexCoord2fv(luv[0]->uv);
|
2012-03-06 21:21:22 +00:00
|
|
|
if (lcol[0])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ls[0]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ls[0]->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
|
|
|
|
glTexCoord2fv(luv[1]->uv);
|
2012-03-06 21:21:22 +00:00
|
|
|
if (lcol[1])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ls[1]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ls[1]->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
|
|
|
|
glTexCoord2fv(luv[2]->uv);
|
2012-03-06 21:21:22 +00:00
|
|
|
if (lcol[2])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ls[2]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ls[2]->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
}
|
2012-05-01 15:59:28 +00:00
|
|
|
glEnd();
|
2009-07-24 10:43:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2011-11-16 12:38:40 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
for (i = 0; i < em->tottri; i++) {
|
2009-07-24 10:43:58 +00:00
|
|
|
BMLoop **ls = em->looptris[i];
|
2012-05-03 21:19:31 +00:00
|
|
|
MTexPoly *tp = has_uv ? CustomData_bmesh_get(&bm->pdata, ls[0]->f->head.data, CD_MTEXPOLY) : NULL;
|
2011-05-09 04:06:48 +00:00
|
|
|
MTFace mtf = {{{0}}};
|
2012-05-27 19:40:36 +00:00
|
|
|
/*unsigned char *cp = NULL;*/ /*UNUSED*/
|
2012-05-03 21:19:31 +00:00
|
|
|
int drawSmooth = BM_elem_flag_test(ls[0]->f, BM_ELEM_SMOOTH);
|
2012-03-08 06:47:05 +00:00
|
|
|
DMDrawOption draw_option;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
efa = ls[0]->f;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
if (has_uv) {
|
2012-02-08 09:02:10 +00:00
|
|
|
ME_MTEXFACE_CPY(&mtf, tp);
|
2009-07-24 10:43:58 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
if (drawParams)
|
2012-05-03 21:19:31 +00:00
|
|
|
draw_option = drawParams(&mtf, has_vcol, efa->mat_nr);
|
2011-12-02 03:18:34 +00:00
|
|
|
else if (drawParamsMapped)
|
2012-05-03 21:19:31 +00:00
|
|
|
draw_option = drawParamsMapped(userData, BM_elem_index_get(efa));
|
2009-07-24 10:43:58 +00:00
|
|
|
else
|
2012-05-03 21:19:31 +00:00
|
|
|
draw_option = DM_DRAW_OPTION_NORMAL;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-03-08 06:47:05 +00:00
|
|
|
if (draw_option != DM_DRAW_OPTION_SKIP) {
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
if (!drawSmooth) {
|
|
|
|
|
glNormal3fv(efa->no);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-10-07 21:19:58 +00:00
|
|
|
if (luv[0])
|
|
|
|
|
glTexCoord2fv(luv[0]->uv);
|
|
|
|
|
if (lcol[0])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2009-07-24 10:43:58 +00:00
|
|
|
glVertex3fv(ls[0]->v->co);
|
|
|
|
|
|
2009-10-07 21:19:58 +00:00
|
|
|
if (luv[1])
|
|
|
|
|
glTexCoord2fv(luv[1]->uv);
|
|
|
|
|
if (lcol[1])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2009-07-24 10:43:58 +00:00
|
|
|
glVertex3fv(ls[1]->v->co);
|
|
|
|
|
|
2009-10-07 21:19:58 +00:00
|
|
|
if (luv[2])
|
|
|
|
|
glTexCoord2fv(luv[2]->uv);
|
|
|
|
|
if (lcol[2])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2009-07-24 10:43:58 +00:00
|
|
|
glVertex3fv(ls[2]->v->co);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2009-07-24 10:43:58 +00:00
|
|
|
bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-10-07 21:19:58 +00:00
|
|
|
if (luv[0])
|
|
|
|
|
glTexCoord2fv(luv[0]->uv);
|
|
|
|
|
if (lcol[0])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2009-07-24 10:43:58 +00:00
|
|
|
glNormal3fv(ls[0]->v->no);
|
2009-07-25 14:13:26 +00:00
|
|
|
glVertex3fv(ls[0]->v->co);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
2009-10-07 21:19:58 +00:00
|
|
|
if (luv[1])
|
|
|
|
|
glTexCoord2fv(luv[1]->uv);
|
|
|
|
|
if (lcol[1])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2009-07-24 10:43:58 +00:00
|
|
|
glNormal3fv(ls[1]->v->no);
|
2009-07-25 14:13:26 +00:00
|
|
|
glVertex3fv(ls[1]->v->co);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
2009-10-07 21:19:58 +00:00
|
|
|
if (luv[2])
|
|
|
|
|
glTexCoord2fv(luv[2]->uv);
|
|
|
|
|
if (lcol[2])
|
2012-03-17 20:39:28 +00:00
|
|
|
glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2009-07-24 10:43:58 +00:00
|
|
|
glNormal3fv(ls[2]->v->no);
|
2009-07-25 14:13:26 +00:00
|
|
|
glVertex3fv(ls[2]->v->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-24 10:43:58 +00:00
|
|
|
}
|
2012-02-19 03:10:11 +00:00
|
|
|
|
|
|
|
|
glShadeModel(GL_FLAT);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawFacesTex(DerivedMesh *dm,
|
|
|
|
|
DMSetDrawOptionsTex setDrawOptions,
|
|
|
|
|
DMCompareDrawOptions compareDrawOptions,
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2011-12-02 03:18:34 +00:00
|
|
|
emDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawMappedFacesTex(DerivedMesh *dm,
|
|
|
|
|
DMSetDrawOptions setDrawOptions,
|
|
|
|
|
DMCompareDrawOptions compareDrawOptions,
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2011-12-02 03:18:34 +00:00
|
|
|
emDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
|
|
|
|
|
DMSetMaterial setMaterial,
|
|
|
|
|
DMSetDrawOptions setDrawOptions,
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->tc->bm;
|
2011-05-10 17:01:26 +00:00
|
|
|
BMEditMesh *em = bmdm->tc;
|
2012-05-03 21:19:31 +00:00
|
|
|
float (*vertexCos)[3] = bmdm->vertexCos;
|
|
|
|
|
float (*vertexNos)[3] = bmdm->vertexNos;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *efa;
|
2011-05-10 17:01:26 +00:00
|
|
|
BMLoop **ltri;
|
2009-05-16 16:18:08 +00:00
|
|
|
DMVertexAttribs attribs;
|
|
|
|
|
GPUVertexAttribs gattribs;
|
2011-09-23 05:59:37 +00:00
|
|
|
|
2012-05-19 13:28:19 +00:00
|
|
|
int i, b, matnr, new_matnr, do_draw;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-19 13:28:19 +00:00
|
|
|
do_draw = FALSE;
|
2009-05-16 16:18:08 +00:00
|
|
|
matnr = -1;
|
|
|
|
|
|
|
|
|
|
memset(&attribs, 0, sizeof(attribs));
|
|
|
|
|
|
|
|
|
|
/* always use smooth shading even for flat faces, else vertex colors wont interpolate */
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-13 16:05:10 +00:00
|
|
|
#define PASSATTRIB(loop, eve, vert) { \
|
2012-05-12 19:18:02 +00:00
|
|
|
if (attribs.totorco) { \
|
|
|
|
|
float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \
|
|
|
|
|
glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \
|
|
|
|
|
} \
|
|
|
|
|
for (b = 0; b < attribs.tottface; b++) { \
|
2012-05-13 16:05:10 +00:00
|
|
|
MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \
|
|
|
|
|
CD_MLOOPUV, b); \
|
2012-05-12 19:18:02 +00:00
|
|
|
glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \
|
|
|
|
|
} \
|
|
|
|
|
for (b = 0; b < attribs.totmcol; b++) { \
|
2012-05-13 16:05:10 +00:00
|
|
|
MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \
|
|
|
|
|
CD_MLOOPCOL, b); \
|
2012-05-12 19:18:02 +00:00
|
|
|
GLubyte _col[4]; \
|
2012-05-13 16:05:10 +00:00
|
|
|
_col[0] = _cp->b; _col[1] = _cp->g; _col[2] = _cp->r; _col[3] = _cp->a; \
|
2012-05-12 19:18:02 +00:00
|
|
|
glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \
|
|
|
|
|
} \
|
|
|
|
|
if (attribs.tottang) { \
|
2012-05-13 16:05:10 +00:00
|
|
|
float *tang = attribs.tang.array[i * 4 + vert]; \
|
2012-05-12 19:18:02 +00:00
|
|
|
glVertexAttrib3fvARB(attribs.tang.gl_index, tang); \
|
|
|
|
|
} \
|
2012-05-17 07:59:25 +00:00
|
|
|
} (void)0
|
2011-12-02 03:18:34 +00:00
|
|
|
|
|
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
for (i = 0, ltri = em->looptris[0]; i < em->tottri; i++, ltri += 3) {
|
2011-05-10 17:01:26 +00:00
|
|
|
int drawSmooth;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-05-10 17:01:26 +00:00
|
|
|
efa = ltri[0]->f;
|
2012-05-03 21:19:31 +00:00
|
|
|
drawSmooth = BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-03-08 06:47:05 +00:00
|
|
|
if (setDrawOptions && (setDrawOptions(userData, BM_elem_index_get(efa)) == DM_DRAW_OPTION_SKIP))
|
2009-05-16 16:18:08 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
new_matnr = efa->mat_nr + 1;
|
2011-12-02 03:18:34 +00:00
|
|
|
if (new_matnr != matnr) {
|
2012-05-19 13:28:19 +00:00
|
|
|
do_draw = setMaterial(matnr = new_matnr, &gattribs);
|
|
|
|
|
if (do_draw)
|
2009-05-16 16:18:08 +00:00
|
|
|
DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-19 13:28:19 +00:00
|
|
|
if (do_draw) {
|
2011-05-10 17:01:26 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
2009-05-16 16:18:08 +00:00
|
|
|
if (!drawSmooth) {
|
2012-02-12 10:51:45 +00:00
|
|
|
if (vertexCos) glNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
|
2011-05-10 17:01:26 +00:00
|
|
|
else glNormal3fv(efa->no);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-05-10 17:01:26 +00:00
|
|
|
PASSATTRIB(ltri[0], ltri[0]->v, 0);
|
2012-02-12 10:51:45 +00:00
|
|
|
if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
|
2011-05-10 17:01:26 +00:00
|
|
|
else glVertex3fv(ltri[0]->v->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-05-10 17:01:26 +00:00
|
|
|
PASSATTRIB(ltri[1], ltri[1]->v, 1);
|
2012-02-12 10:51:45 +00:00
|
|
|
if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
|
2011-05-10 17:01:26 +00:00
|
|
|
else glVertex3fv(ltri[1]->v->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-05-10 17:01:26 +00:00
|
|
|
PASSATTRIB(ltri[2], ltri[2]->v, 2);
|
2012-02-12 10:51:45 +00:00
|
|
|
if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
|
2011-05-10 17:01:26 +00:00
|
|
|
else glVertex3fv(ltri[2]->v->co);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-05-10 17:01:26 +00:00
|
|
|
PASSATTRIB(ltri[0], ltri[0]->v, 0);
|
2011-12-02 03:18:34 +00:00
|
|
|
if (vertexCos) {
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-05-10 17:01:26 +00:00
|
|
|
glNormal3fv(ltri[0]->v->no);
|
|
|
|
|
glVertex3fv(ltri[0]->v->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-10 17:01:26 +00:00
|
|
|
PASSATTRIB(ltri[1], ltri[1]->v, 1);
|
2011-12-02 03:18:34 +00:00
|
|
|
if (vertexCos) {
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-05-10 17:01:26 +00:00
|
|
|
glNormal3fv(ltri[1]->v->no);
|
|
|
|
|
glVertex3fv(ltri[1]->v->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-10 17:01:26 +00:00
|
|
|
PASSATTRIB(ltri[2], ltri[2]->v, 2);
|
2011-12-02 03:18:34 +00:00
|
|
|
if (vertexCos) {
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-05-10 17:01:26 +00:00
|
|
|
glNormal3fv(ltri[2]->v->no);
|
|
|
|
|
glVertex3fv(ltri[2]->v->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-10 03:40:02 +00:00
|
|
|
#undef PASSATTRIB
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawFacesGLSL(DerivedMesh *dm,
|
|
|
|
|
int (*setMaterial)(int, void *attribs))
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
|
dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
static void emDM_drawMappedFacesMat(DerivedMesh *dm,
|
|
|
|
|
void (*setMaterial)(void *userData, int, void *attribs),
|
|
|
|
|
int (*setFace)(void *userData, int index), void *userData)
|
2011-11-10 03:05:11 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->tc->bm;
|
2011-11-10 03:40:02 +00:00
|
|
|
BMEditMesh *em = bmdm->tc;
|
2012-05-03 21:19:31 +00:00
|
|
|
float (*vertexCos)[3] = bmdm->vertexCos;
|
|
|
|
|
float (*vertexNos)[3] = bmdm->vertexNos;
|
2011-11-10 03:40:02 +00:00
|
|
|
BMFace *efa;
|
|
|
|
|
BMLoop **ltri;
|
2012-05-03 21:19:31 +00:00
|
|
|
DMVertexAttribs attribs = {{{0}}};
|
2011-11-10 03:05:11 +00:00
|
|
|
GPUVertexAttribs gattribs;
|
2011-11-16 17:09:41 +00:00
|
|
|
int i, b, matnr, new_matnr;
|
2011-11-10 03:05:11 +00:00
|
|
|
|
|
|
|
|
matnr = -1;
|
|
|
|
|
|
|
|
|
|
/* always use smooth shading even for flat faces, else vertex colors wont interpolate */
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE);
|
2011-11-10 03:05:11 +00:00
|
|
|
|
2012-05-13 16:05:10 +00:00
|
|
|
#define PASSATTRIB(loop, eve, vert) { \
|
2012-05-12 19:18:02 +00:00
|
|
|
if (attribs.totorco) { \
|
|
|
|
|
float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \
|
|
|
|
|
if (attribs.orco.gl_texco) \
|
|
|
|
|
glTexCoord3fv(orco); \
|
|
|
|
|
else \
|
|
|
|
|
glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \
|
|
|
|
|
} \
|
|
|
|
|
for (b = 0; b < attribs.tottface; b++) { \
|
2012-05-13 16:05:10 +00:00
|
|
|
MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \
|
|
|
|
|
CD_MLOOPUV, b); \
|
2012-05-12 19:18:02 +00:00
|
|
|
if (attribs.tface[b].gl_texco) \
|
|
|
|
|
glTexCoord2fv(_luv->uv); \
|
|
|
|
|
else \
|
|
|
|
|
glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \
|
|
|
|
|
} \
|
|
|
|
|
for (b = 0; b < attribs.totmcol; b++) { \
|
2012-05-13 16:05:10 +00:00
|
|
|
MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, \
|
|
|
|
|
CD_MLOOPCOL, b); \
|
2012-05-12 19:18:02 +00:00
|
|
|
GLubyte _col[4]; \
|
2012-05-13 16:05:10 +00:00
|
|
|
_col[0] = _cp->b; _col[1] = _cp->g; _col[2] = _cp->r; _col[3] = _cp->a; \
|
2012-05-12 19:18:02 +00:00
|
|
|
glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \
|
|
|
|
|
} \
|
|
|
|
|
if (attribs.tottang) { \
|
2012-05-13 16:05:10 +00:00
|
|
|
float *tang = attribs.tang.array[i * 4 + vert]; \
|
2012-05-12 19:18:02 +00:00
|
|
|
glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \
|
|
|
|
|
} \
|
2012-05-17 07:59:25 +00:00
|
|
|
} (void)0
|
2011-11-10 03:05:11 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
for (i = 0, ltri = em->looptris[0]; i < em->tottri; i++, ltri += 3) {
|
2011-11-17 06:08:58 +00:00
|
|
|
int drawSmooth;
|
2011-11-10 03:40:02 +00:00
|
|
|
|
|
|
|
|
efa = ltri[0]->f;
|
2012-02-12 10:51:45 +00:00
|
|
|
drawSmooth = BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
|
2011-11-10 03:05:11 +00:00
|
|
|
|
|
|
|
|
/* face hiding */
|
2012-02-12 10:51:45 +00:00
|
|
|
if (setFace && !setFace(userData, BM_elem_index_get(efa)))
|
2011-11-10 03:05:11 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* material */
|
|
|
|
|
new_matnr = efa->mat_nr + 1;
|
2011-12-02 03:18:34 +00:00
|
|
|
if (new_matnr != matnr) {
|
2011-11-10 03:05:11 +00:00
|
|
|
setMaterial(userData, matnr = new_matnr, &gattribs);
|
|
|
|
|
DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* face */
|
2011-11-10 03:40:02 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
2011-11-10 03:05:11 +00:00
|
|
|
if (!drawSmooth) {
|
2012-02-12 10:51:45 +00:00
|
|
|
if (vertexCos) glNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
|
2011-11-10 03:40:02 +00:00
|
|
|
else glNormal3fv(efa->no);
|
2011-11-10 03:05:11 +00:00
|
|
|
|
2011-11-10 03:40:02 +00:00
|
|
|
PASSATTRIB(ltri[0], ltri[0]->v, 0);
|
2012-02-12 10:51:45 +00:00
|
|
|
if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
|
2011-11-10 03:40:02 +00:00
|
|
|
else glVertex3fv(ltri[0]->v->co);
|
2011-11-10 03:05:11 +00:00
|
|
|
|
2011-11-10 03:40:02 +00:00
|
|
|
PASSATTRIB(ltri[1], ltri[1]->v, 1);
|
2012-02-12 10:51:45 +00:00
|
|
|
if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
|
2011-11-10 03:40:02 +00:00
|
|
|
else glVertex3fv(ltri[1]->v->co);
|
2011-11-10 03:05:11 +00:00
|
|
|
|
2011-11-10 03:40:02 +00:00
|
|
|
PASSATTRIB(ltri[2], ltri[2]->v, 2);
|
2012-02-12 10:51:45 +00:00
|
|
|
if (vertexCos) glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
|
2011-11-10 03:40:02 +00:00
|
|
|
else glVertex3fv(ltri[2]->v->co);
|
2011-11-10 03:05:11 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-11-10 03:40:02 +00:00
|
|
|
PASSATTRIB(ltri[0], ltri[0]->v, 0);
|
2011-12-02 03:18:34 +00:00
|
|
|
if (vertexCos) {
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
|
2011-11-10 03:05:11 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-11-10 03:40:02 +00:00
|
|
|
glNormal3fv(ltri[0]->v->no);
|
|
|
|
|
glVertex3fv(ltri[0]->v->co);
|
2011-11-10 03:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-10 03:40:02 +00:00
|
|
|
PASSATTRIB(ltri[1], ltri[1]->v, 1);
|
2011-12-02 03:18:34 +00:00
|
|
|
if (vertexCos) {
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
|
2011-11-10 03:05:11 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-11-10 03:40:02 +00:00
|
|
|
glNormal3fv(ltri[1]->v->no);
|
|
|
|
|
glVertex3fv(ltri[1]->v->co);
|
2011-11-10 03:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-10 03:40:02 +00:00
|
|
|
PASSATTRIB(ltri[2], ltri[2]->v, 2);
|
2011-12-02 03:18:34 +00:00
|
|
|
if (vertexCos) {
|
2012-02-12 10:51:45 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
|
2011-11-10 03:05:11 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-11-10 03:40:02 +00:00
|
|
|
glNormal3fv(ltri[2]->v->no);
|
|
|
|
|
glVertex3fv(ltri[2]->v->co);
|
2011-11-10 03:05:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
|
|
|
|
#undef PASSATTRIB
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMVert *eve;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
|
|
|
|
|
2010-07-14 22:06:10 +00:00
|
|
|
if (bmdm->tc->bm->totvert) {
|
2012-05-03 21:19:31 +00:00
|
|
|
if (bmdm->vertexCos) {
|
|
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH, i) {
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(min_r, max_r, bmdm->vertexCos[i]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BM_ITER_MESH (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH) {
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(min_r, max_r, eve->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-23 20:18:09 +00:00
|
|
|
zero_v3(min_r);
|
|
|
|
|
zero_v3(max_r);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumVerts(DerivedMesh *dm)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
return bmdm->tc->bm->totvert;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumEdges(DerivedMesh *dm)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
return bmdm->tc->bm->totedge;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumTessFaces(DerivedMesh *dm)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
return bmdm->tc->tottri;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumLoops(DerivedMesh *dm)
|
2011-11-30 18:03:56 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2011-11-30 18:03:56 +00:00
|
|
|
return bmdm->tc->bm->totloop;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumPolys(DerivedMesh *dm)
|
2009-06-23 05:35:49 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-06-23 05:35:49 +00:00
|
|
|
return bmdm->tc->bm->totface;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 22:06:10 +00:00
|
|
|
static int bmvert_to_mvert(BMesh *bm, BMVert *ev, MVert *vert_r)
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
{
|
2011-09-12 05:51:35 +00:00
|
|
|
copy_v3_v3(vert_r->co, ev->co);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
|
2011-12-01 01:41:56 +00:00
|
|
|
normal_float_to_short_v3(vert_r->no, ev->no);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
vert_r->flag = BM_vert_flag_to_mflag(ev);
|
2010-07-14 22:06:10 +00:00
|
|
|
|
|
|
|
|
if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) {
|
2012-05-12 19:18:02 +00:00
|
|
|
vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, ev, CD_BWEIGHT) * 255.0f);
|
2010-07-14 22:06:10 +00:00
|
|
|
}
|
2010-07-19 04:44:37 +00:00
|
|
|
|
|
|
|
|
return 1;
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_getVert(DerivedMesh *dm, int index, MVert *vert_r)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMVert *ev;
|
|
|
|
|
|
2012-02-19 01:51:36 +00:00
|
|
|
if (index < 0 || index >= bmdm->tv) {
|
2011-12-02 03:18:34 +00:00
|
|
|
printf("error in emDM_getVert.\n");
|
2009-05-16 16:18:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-27 04:46:52 +00:00
|
|
|
// ev = EDBM_vert_at_index(bmdm->tc, index);
|
2012-02-19 01:51:36 +00:00
|
|
|
ev = BM_vert_at_index(bmdm->tc->bm, index); /* warning, does list loop, _not_ ideal */
|
|
|
|
|
|
|
|
|
|
bmvert_to_mvert(bmdm->tc->bm, ev, vert_r);
|
2012-04-21 12:51:47 +00:00
|
|
|
if (bmdm->vertexCos)
|
2012-04-17 13:07:13 +00:00
|
|
|
copy_v3_v3(vert_r->co, bmdm->vertexCos[index]);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2012-02-19 01:51:36 +00:00
|
|
|
BMesh *bm = bmdm->tc->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMEdge *e;
|
|
|
|
|
|
2012-02-19 01:51:36 +00:00
|
|
|
if (index < 0 || index >= bmdm->te) {
|
2011-12-02 03:18:34 +00:00
|
|
|
printf("error in emDM_getEdge.\n");
|
2009-06-23 05:35:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-27 04:46:52 +00:00
|
|
|
// e = EDBM_edge_at_index(bmdm->tc, index);
|
2012-02-19 01:51:36 +00:00
|
|
|
e = BM_edge_at_index(bmdm->tc->bm, index); /* warning, does list loop, _not_ ideal */
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2010-07-14 22:06:10 +00:00
|
|
|
if (CustomData_has_layer(&bm->edata, CD_BWEIGHT)) {
|
2012-05-12 19:18:02 +00:00
|
|
|
edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_BWEIGHT) * 255.0f);
|
2010-07-14 22:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CustomData_has_layer(&bm->edata, CD_CREASE)) {
|
2012-05-12 19:18:02 +00:00
|
|
|
edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_CREASE) * 255.0f);
|
2010-07-14 22:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
edge_r->flag = BM_edge_flag_to_mflag(e);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
edge_r->v1 = BM_elem_index_get(e->v1);
|
|
|
|
|
edge_r->v2 = BM_elem_index_get(e->v2);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_getTessFace(DerivedMesh *dm, int index, MFace *face_r)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *ef;
|
|
|
|
|
BMLoop **l;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-02-19 01:51:36 +00:00
|
|
|
if (index < 0 || index >= bmdm->tf) {
|
2011-12-02 03:18:34 +00:00
|
|
|
printf("error in emDM_getTessFace.\n");
|
2009-06-23 05:35:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-19 01:51:36 +00:00
|
|
|
l = bmdm->tc->looptris[index];
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
ef = l[0]->f;
|
|
|
|
|
|
|
|
|
|
face_r->mat_nr = (unsigned char) ef->mat_nr;
|
2012-02-12 10:51:45 +00:00
|
|
|
face_r->flag = BM_face_flag_to_mflag(ef);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
face_r->v1 = BM_elem_index_get(l[0]->v);
|
|
|
|
|
face_r->v2 = BM_elem_index_get(l[1]->v);
|
|
|
|
|
face_r->v3 = BM_elem_index_get(l[2]->v);
|
2009-05-16 16:18:08 +00:00
|
|
|
face_r->v4 = 0;
|
|
|
|
|
|
|
|
|
|
test_index_face(face_r, NULL, 0, 3);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-04-17 13:07:13 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->tc->bm;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMVert *eve;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMIter iter;
|
2012-05-13 14:47:53 +00:00
|
|
|
const int has_bweight = CustomData_has_layer(&bm->vdata, CD_BWEIGHT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
if (bmdm->vertexCos) {
|
|
|
|
|
int i;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
copy_v3_v3(vert_r->co, bmdm->vertexCos[i]);
|
|
|
|
|
normal_float_to_short_v3(vert_r->no, eve->no);
|
|
|
|
|
vert_r->flag = BM_vert_flag_to_mflag(eve);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
if (has_bweight) {
|
|
|
|
|
vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT) * 255.0f);
|
|
|
|
|
}
|
|
|
|
|
vert_r++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
|
|
|
|
|
copy_v3_v3(vert_r->co, eve->co);
|
|
|
|
|
normal_float_to_short_v3(vert_r->no, eve->no);
|
|
|
|
|
vert_r->flag = BM_vert_flag_to_mflag(eve);
|
2010-07-14 22:06:10 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
if (has_bweight) {
|
|
|
|
|
vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT) * 255.0f);
|
|
|
|
|
}
|
|
|
|
|
vert_r++;
|
2010-07-14 22:06:10 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_copyEdgeArray(DerivedMesh *dm, MEdge *edge_r)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
|
BMesh *bm = ((EditDerivedBMesh *)dm)->tc->bm;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMEdge *eed;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMIter iter;
|
2012-05-13 14:47:53 +00:00
|
|
|
const int has_bweight = CustomData_has_layer(&bm->edata, CD_BWEIGHT);
|
|
|
|
|
const int has_crease = CustomData_has_layer(&bm->edata, CD_CREASE);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
|
2011-03-27 03:29:27 +00:00
|
|
|
if (has_bweight) {
|
2012-05-13 14:47:53 +00:00
|
|
|
edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, eed, CD_BWEIGHT) * 255.0f);
|
2010-07-14 22:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-27 03:29:27 +00:00
|
|
|
if (has_crease) {
|
2012-05-13 14:47:53 +00:00
|
|
|
edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, eed, CD_CREASE) * 255.0f);
|
2010-07-14 22:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
edge_r->flag = BM_edge_flag_to_mflag(eed);
|
|
|
|
|
|
|
|
|
|
edge_r->v1 = BM_elem_index_get(eed->v1);
|
|
|
|
|
edge_r->v2 = BM_elem_index_get(eed->v2);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
edge_r++;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_copyTessFaceArray(DerivedMesh *dm, MFace *face_r)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2012-02-19 01:51:36 +00:00
|
|
|
BMesh *bm = bmdm->tc->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *ef;
|
|
|
|
|
BMLoop **l;
|
|
|
|
|
int i;
|
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
for (i = 0; i < bmdm->tc->tottri; i++, face_r++) {
|
2009-05-16 16:18:08 +00:00
|
|
|
l = bmdm->tc->looptris[i];
|
|
|
|
|
ef = l[0]->f;
|
|
|
|
|
|
|
|
|
|
face_r->mat_nr = (unsigned char) ef->mat_nr;
|
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
face_r->flag = BM_face_flag_to_mflag(ef);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
face_r->v1 = BM_elem_index_get(l[0]->v);
|
|
|
|
|
face_r->v2 = BM_elem_index_get(l[1]->v);
|
|
|
|
|
face_r->v3 = BM_elem_index_get(l[2]->v);
|
2009-05-16 16:18:08 +00:00
|
|
|
face_r->v4 = 0;
|
|
|
|
|
|
|
|
|
|
test_index_face(face_r, NULL, 0, 3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_copyLoopArray(DerivedMesh *dm, MLoop *loop_r)
|
2011-06-14 03:16:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->tc->bm;
|
2011-06-14 03:16:08 +00:00
|
|
|
BMIter iter, liter;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMFace *efa;
|
2011-06-14 03:16:08 +00:00
|
|
|
BMLoop *l;
|
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT | BM_EDGE);
|
2011-06-14 03:16:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
|
|
|
|
|
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
|
2012-02-12 10:51:45 +00:00
|
|
|
loop_r->v = BM_elem_index_get(l->v);
|
|
|
|
|
loop_r->e = BM_elem_index_get(l->e);
|
2011-09-02 10:43:16 +00:00
|
|
|
loop_r++;
|
2011-06-14 03:16:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_copyPolyArray(DerivedMesh *dm, MPoly *poly_r)
|
2011-06-14 03:16:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->tc->bm;
|
2011-07-03 17:07:07 +00:00
|
|
|
BMIter iter;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMFace *efa;
|
2011-09-26 05:10:37 +00:00
|
|
|
int i;
|
2011-06-14 03:16:08 +00:00
|
|
|
|
2011-09-26 05:10:37 +00:00
|
|
|
i = 0;
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
|
|
|
|
|
poly_r->flag = BM_face_flag_to_mflag(efa);
|
2011-09-26 05:10:37 +00:00
|
|
|
poly_r->loopstart = i;
|
2012-05-13 14:47:53 +00:00
|
|
|
poly_r->totloop = efa->len;
|
|
|
|
|
poly_r->mat_nr = efa->mat_nr;
|
2011-06-14 03:16:08 +00:00
|
|
|
|
2011-09-02 10:43:16 +00:00
|
|
|
poly_r++;
|
2012-05-13 14:47:53 +00:00
|
|
|
i += efa->len;
|
2011-06-14 03:16:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void *emDM_getTessFaceDataArray(DerivedMesh *dm, int type)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->tc->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
void *datalayer;
|
|
|
|
|
|
2009-08-15 17:31:28 +00:00
|
|
|
datalayer = DM_get_tessface_data_layer(dm, type);
|
2011-12-02 03:18:34 +00:00
|
|
|
if (datalayer)
|
2009-05-16 16:18:08 +00:00
|
|
|
return datalayer;
|
|
|
|
|
|
2012-04-16 04:17:33 +00:00
|
|
|
/* layers are store per face for editmesh, we convert to a temporary
|
2009-05-16 16:18:08 +00:00
|
|
|
* data layer array in the derivedmesh when these are requested */
|
2011-12-02 03:18:34 +00:00
|
|
|
if (type == CD_MTFACE || type == CD_MCOL) {
|
2012-04-16 04:17:33 +00:00
|
|
|
const int type_from = (type == CD_MTFACE) ? CD_MTEXPOLY : CD_MLOOPCOL;
|
|
|
|
|
int index;
|
|
|
|
|
char *data, *bmdata;
|
|
|
|
|
index = CustomData_get_layer_index(&bm->pdata, type_from);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
if (index != -1) {
|
2011-09-07 06:49:20 +00:00
|
|
|
/* offset = bm->pdata.layers[index].offset; */ /* UNUSED */
|
2012-04-16 04:17:33 +00:00
|
|
|
const int size = CustomData_sizeof(type);
|
|
|
|
|
int i, j;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-08-15 17:31:28 +00:00
|
|
|
DM_add_tessface_layer(dm, type, CD_CALLOC, NULL);
|
2009-05-16 16:18:08 +00:00
|
|
|
index = CustomData_get_layer_index(&dm->faceData, type);
|
|
|
|
|
dm->faceData.layers[index].flag |= CD_FLAG_TEMPORARY;
|
|
|
|
|
|
2009-08-15 17:31:28 +00:00
|
|
|
data = datalayer = DM_get_tessface_data_layer(dm, type);
|
2012-04-16 04:17:33 +00:00
|
|
|
|
|
|
|
|
if (type == CD_MTFACE) {
|
|
|
|
|
for (i = 0; i < bmdm->tc->tottri; i++, data += size) {
|
|
|
|
|
BMFace *efa = bmdm->tc->looptris[i][0]->f;
|
|
|
|
|
bmdata = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
|
|
|
|
|
ME_MTEXFACE_CPY(((MTFace *)data), ((MTexPoly *)bmdata));
|
|
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
|
bmdata = CustomData_bmesh_get(&bm->ldata, bmdm->tc->looptris[i][j]->head.data, CD_MLOOPUV);
|
|
|
|
|
copy_v2_v2(((MTFace *)data)->uv[j], ((MLoopUV *)bmdata)->uv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (i = 0; i < bmdm->tc->tottri; i++, data += size) {
|
|
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
|
bmdata = CustomData_bmesh_get(&bm->ldata, bmdm->tc->looptris[i][j]->head.data, CD_MLOOPCOL);
|
|
|
|
|
MESH_MLOOPCOL_TO_MCOL(((MLoopCol *)bmdata), (((MCol *)data) + j));
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return datalayer;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_getVertCos(DerivedMesh *dm, float (*cos_r)[3])
|
2011-05-09 22:16:31 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *emdm = (EditDerivedBMesh *)dm;
|
2011-05-09 22:16:31 +00:00
|
|
|
BMVert *eve;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
2011-05-10 23:48:09 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
if (emdm->vertexCos) {
|
|
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, emdm->tc->bm, BM_VERTS_OF_MESH, i) {
|
2011-05-09 22:16:31 +00:00
|
|
|
copy_v3_v3(cos_r[i], emdm->vertexCos[i]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, emdm->tc->bm, BM_VERTS_OF_MESH, i) {
|
2011-05-09 22:16:31 +00:00
|
|
|
copy_v3_v3(cos_r[i], eve->co);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_release(DerivedMesh *dm)
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
if (DM_release(dm)) {
|
|
|
|
|
if (bmdm->vertexCos) {
|
|
|
|
|
MEM_freeN(bmdm->vertexCos);
|
|
|
|
|
MEM_freeN(bmdm->vertexNos);
|
2012-01-24 19:37:18 +00:00
|
|
|
MEM_freeN(bmdm->polyNos);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
MEM_freeN(bmdm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-11 02:14:43 +00:00
|
|
|
static CustomData *bmDm_getVertDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
|
|
|
|
return &bmdm->tc->bm->vdata;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-11 02:14:43 +00:00
|
|
|
static CustomData *bmDm_getEdgeDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
|
|
|
|
return &bmdm->tc->bm->edata;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-11 02:14:43 +00:00
|
|
|
static CustomData *bmDm_getTessFaceDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
2011-05-10 17:01:26 +00:00
|
|
|
return &bmdm->dm.faceData;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-11 02:14:43 +00:00
|
|
|
static CustomData *bmDm_getLoopDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
|
|
|
|
return &bmdm->tc->bm->ldata;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 13:01:51 +00:00
|
|
|
static CustomData *bmDm_getPolyDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
|
|
|
|
return &bmdm->tc->bm->pdata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
DerivedMesh *getEditDerivedBMesh(BMEditMesh *em,
|
|
|
|
|
Object *UNUSED(ob),
|
|
|
|
|
float (*vertexCos)[3])
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2011-09-12 02:44:17 +00:00
|
|
|
EditDerivedBMesh *bmdm = MEM_callocN(sizeof(*bmdm), __func__);
|
2009-05-16 16:18:08 +00:00
|
|
|
BMesh *bm = em->bm;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
bmdm->tc = em;
|
|
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
DM_init((DerivedMesh *)bmdm, DM_TYPE_EDITBMESH, em->bm->totvert,
|
|
|
|
|
em->bm->totedge, em->tottri, em->bm->totloop, em->bm->totface);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
|
|
|
|
bmdm->dm.getVertCos = emDM_getVertCos;
|
|
|
|
|
bmdm->dm.getMinMax = emDM_getMinMax;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-08-18 20:05:08 +00:00
|
|
|
bmdm->dm.getVertDataLayout = bmDm_getVertDataLayout;
|
|
|
|
|
bmdm->dm.getEdgeDataLayout = bmDm_getEdgeDataLayout;
|
|
|
|
|
bmdm->dm.getTessFaceDataLayout = bmDm_getTessFaceDataLayout;
|
|
|
|
|
bmdm->dm.getLoopDataLayout = bmDm_getLoopDataLayout;
|
2011-11-29 13:01:51 +00:00
|
|
|
bmdm->dm.getPolyDataLayout = bmDm_getPolyDataLayout;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
bmdm->dm.getNumVerts = emDM_getNumVerts;
|
|
|
|
|
bmdm->dm.getNumEdges = emDM_getNumEdges;
|
|
|
|
|
bmdm->dm.getNumTessFaces = emDM_getNumTessFaces;
|
|
|
|
|
bmdm->dm.getNumLoops = emDM_getNumLoops;
|
|
|
|
|
bmdm->dm.getNumPolys = emDM_getNumPolys;
|
|
|
|
|
|
|
|
|
|
bmdm->dm.getVert = emDM_getVert;
|
|
|
|
|
bmdm->dm.getEdge = emDM_getEdge;
|
|
|
|
|
bmdm->dm.getTessFace = emDM_getTessFace;
|
|
|
|
|
bmdm->dm.copyVertArray = emDM_copyVertArray;
|
|
|
|
|
bmdm->dm.copyEdgeArray = emDM_copyEdgeArray;
|
|
|
|
|
bmdm->dm.copyTessFaceArray = emDM_copyTessFaceArray;
|
|
|
|
|
bmdm->dm.copyLoopArray = emDM_copyLoopArray;
|
|
|
|
|
bmdm->dm.copyPolyArray = emDM_copyPolyArray;
|
|
|
|
|
|
|
|
|
|
bmdm->dm.getTessFaceDataArray = emDM_getTessFaceDataArray;
|
|
|
|
|
|
|
|
|
|
bmdm->dm.calcNormals = emDM_calcNormals;
|
2012-03-02 16:05:54 +00:00
|
|
|
bmdm->dm.recalcTessellation = emDM_recalcTessellation;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
|
|
|
|
bmdm->dm.foreachMappedVert = emDM_foreachMappedVert;
|
|
|
|
|
bmdm->dm.foreachMappedEdge = emDM_foreachMappedEdge;
|
|
|
|
|
bmdm->dm.foreachMappedFaceCenter = emDM_foreachMappedFaceCenter;
|
|
|
|
|
|
|
|
|
|
bmdm->dm.drawEdges = emDM_drawEdges;
|
|
|
|
|
bmdm->dm.drawMappedEdges = emDM_drawMappedEdges;
|
|
|
|
|
bmdm->dm.drawMappedEdgesInterp = emDM_drawMappedEdgesInterp;
|
|
|
|
|
bmdm->dm.drawMappedFaces = emDM_drawMappedFaces;
|
|
|
|
|
bmdm->dm.drawMappedFacesTex = emDM_drawMappedFacesTex;
|
|
|
|
|
bmdm->dm.drawMappedFacesGLSL = emDM_drawMappedFacesGLSL;
|
|
|
|
|
bmdm->dm.drawMappedFacesMat = emDM_drawMappedFacesMat;
|
|
|
|
|
bmdm->dm.drawFacesTex = emDM_drawFacesTex;
|
|
|
|
|
bmdm->dm.drawFacesGLSL = emDM_drawFacesGLSL;
|
|
|
|
|
bmdm->dm.drawUVEdges = emDM_drawUVEdges;
|
|
|
|
|
|
|
|
|
|
bmdm->dm.release = emDM_release;
|
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
bmdm->vertexCos = vertexCos;
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
if (CustomData_has_layer(&bm->vdata, CD_MDEFORMVERT)) {
|
2009-05-16 16:18:08 +00:00
|
|
|
BMIter iter;
|
|
|
|
|
BMVert *eve;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
DM_add_vert_layer(&bmdm->dm, CD_MDEFORMVERT, CD_CALLOC, NULL);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH, i) {
|
2009-05-16 16:18:08 +00:00
|
|
|
DM_set_vert_data(&bmdm->dm, i, CD_MDEFORMVERT,
|
2012-05-12 19:18:02 +00:00
|
|
|
CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MDEFORMVERT));
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-22 15:29:27 +00:00
|
|
|
if (CustomData_has_layer(&bm->vdata, CD_MVERT_SKIN)) {
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMVert *eve;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
DM_add_vert_layer(&bmdm->dm, CD_MVERT_SKIN, CD_CALLOC, NULL);
|
|
|
|
|
|
|
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
DM_set_vert_data(&bmdm->dm, i, CD_MVERT_SKIN,
|
2012-06-06 14:48:39 +00:00
|
|
|
CustomData_bmesh_get(&bm->vdata, eve->head.data,
|
|
|
|
|
CD_MVERT_SKIN));
|
2012-05-22 15:29:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
if (vertexCos) {
|
2012-01-24 19:37:18 +00:00
|
|
|
BMFace *efa;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMVert *eve;
|
2012-01-24 19:37:18 +00:00
|
|
|
BMIter fiter;
|
|
|
|
|
BMIter viter;
|
2009-05-16 16:18:08 +00:00
|
|
|
int i;
|
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2011-11-16 12:38:40 +00:00
|
|
|
|
|
|
|
|
bmdm->vertexNos = MEM_callocN(sizeof(*bmdm->vertexNos) * bm->totvert, "bmdm_vno");
|
2012-05-12 19:18:02 +00:00
|
|
|
bmdm->polyNos = MEM_mallocN(sizeof(*bmdm->polyNos) * bm->totface, "bmdm_pno");
|
2012-01-24 19:37:18 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_elem_index_set(efa, i); /* set_inline */
|
2012-03-11 15:27:08 +00:00
|
|
|
BM_face_normal_update_vcos(bm, efa, bmdm->polyNos[i], (float const (*)[3])vertexCos);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2012-01-24 19:37:18 +00:00
|
|
|
bm->elem_index_dirty &= ~BM_FACE;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &viter, bm, BM_VERTS_OF_MESH, i) {
|
2009-05-16 16:18:08 +00:00
|
|
|
float *no = bmdm->vertexNos[i];
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (efa, &fiter, eve, BM_FACES_OF_VERT) {
|
2012-02-12 10:51:45 +00:00
|
|
|
add_v3_v3(no, bmdm->polyNos[BM_elem_index_get(efa)]);
|
2012-01-24 19:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
/* following Mesh convention; we use vertex coordinate itself
|
|
|
|
|
* for normal in this case */
|
2012-05-03 21:19:31 +00:00
|
|
|
if (normalize_v3(no) == 0.0f) {
|
2011-09-12 05:51:35 +00:00
|
|
|
copy_v3_v3(no, vertexCos[i]);
|
2009-11-23 14:41:22 +00:00
|
|
|
normalize_v3(no);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
return (DerivedMesh *)bmdm;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2012-03-02 12:09:49 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Return the BMEditMesh for a given object
|
|
|
|
|
*
|
|
|
|
|
* \note this function assumes this is a mesh object,
|
|
|
|
|
* don't add NULL data check here. caller must do that
|
|
|
|
|
*/
|
|
|
|
|
BMEditMesh *BMEdit_FromObject(Object *ob)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
2012-09-10 03:42:29 +00:00
|
|
|
/* sanity check */
|
2012-09-10 03:34:43 +00:00
|
|
|
#ifndef NDEBUG
|
2012-09-10 03:42:29 +00:00
|
|
|
if (((Mesh *)ob->data)->edit_btmesh) {
|
|
|
|
|
BLI_assert(((Mesh *)ob->data)->edit_btmesh->ob == ob);
|
|
|
|
|
}
|
2012-09-10 03:34:43 +00:00
|
|
|
#endif
|
2012-03-08 00:23:28 +00:00
|
|
|
return ((Mesh *)ob->data)->edit_btmesh;
|
2012-03-02 12:09:49 +00:00
|
|
|
}
|