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
|
2013-04-16 05:46:17 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
2011-12-02 03:18:34 +00:00
|
|
|
*/
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "GL/glew.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "BLI_math.h"
|
2013-04-17 09:27:23 +00:00
|
|
|
#include "BLI_jitter.h"
|
2013-04-18 17:23:02 +00:00
|
|
|
#include "BLI_bitmap.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
|
#include "BKE_mesh.h"
|
2013-04-16 05:46:17 +00:00
|
|
|
#include "BKE_editmesh.h"
|
2013-04-17 09:27:23 +00:00
|
|
|
#include "BKE_editmesh_bvh.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-03-02 12:09:49 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
2013-04-17 09:27:23 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2011-12-02 03:18:34 +00:00
|
|
|
#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"
|
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
#include "GPU_extensions.h"
|
|
|
|
|
|
2011-09-17 12:25:51 +00:00
|
|
|
extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */
|
|
|
|
|
|
2013-04-13 20:20:21 +00:00
|
|
|
static void bmdm_get_tri_colpreview(BMLoop *ls[3], MLoopCol *lcol[3], unsigned char(*color_vert_array)[4]);
|
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
typedef struct EditDerivedBMesh {
|
|
|
|
|
DerivedMesh dm;
|
|
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
BMEditMesh *em;
|
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-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;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
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) {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, 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 {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, 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;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
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) {
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, 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 {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, 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;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
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) {
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, 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);
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, 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;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMEdge *eed;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (bmdm->vertexCos) {
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, 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);
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, 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;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
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);
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH (efa, &iter, 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) {
|
2013-04-13 20:58:49 +00:00
|
|
|
MLoopUV *luv = CustomData_bmesh_get(&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;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
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) {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_mesh_elem_index_ensure(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
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (efa, &iter, 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;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMEditMesh *em = bmdm->em;
|
2013-04-13 20:20:21 +00:00
|
|
|
BMesh *bm = em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *efa;
|
2013-04-13 20:31:52 +00:00
|
|
|
struct BMLoop *(*looptris)[3] = bmdm->em->looptris;
|
|
|
|
|
const int tottri = bmdm->em->tottri;
|
2012-05-03 21:19:31 +00:00
|
|
|
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
|
|
|
|
2013-04-13 20:20:21 +00:00
|
|
|
MLoopCol *lcol[3] = {NULL} /* , dummylcol = {0} */;
|
2013-04-18 17:09:56 +00:00
|
|
|
unsigned char(*color_vert_array)[4] = em->derivedVertColor;
|
|
|
|
|
unsigned char(*color_face_array)[4] = em->derivedFaceColor;
|
2013-04-13 20:20:21 +00:00
|
|
|
bool has_vcol_preview = (color_vert_array != NULL) && !skip_normals;
|
2013-04-17 09:27:23 +00:00
|
|
|
bool has_fcol_preview = (color_face_array != NULL) && !skip_normals;
|
2013-04-13 20:20:21 +00:00
|
|
|
bool has_vcol_any = has_vcol_preview;
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:20:21 +00:00
|
|
|
/* call again below is ok */
|
|
|
|
|
if (has_vcol_preview) {
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
if (has_fcol_preview) {
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_FACE);
|
|
|
|
|
}
|
|
|
|
|
if (has_vcol_preview || has_fcol_preview) {
|
2013-04-13 20:20:21 +00:00
|
|
|
flag |= DM_DRAW_ALWAYS_SMOOTH;
|
|
|
|
|
glDisable(GL_LIGHTING); /* grr */
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_mesh_elem_index_ensure(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++) {
|
2013-04-13 17:57:11 +00:00
|
|
|
BMLoop **ltri = looptris[i];
|
2009-05-16 16:18:08 +00:00
|
|
|
int drawSmooth;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
efa = ltri[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
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
|
|
|
|
|
else if (has_fcol_preview) glColor3ubv((const GLubyte *)&(color_face_array[BM_elem_index_get(efa)]));
|
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
|
|
|
}
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[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)]);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[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 {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_mesh_elem_index_ensure(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++) {
|
2013-04-13 17:57:11 +00:00
|
|
|
BMLoop **ltri = looptris[i];
|
2009-05-16 16:18:08 +00:00
|
|
|
int drawSmooth;
|
|
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
efa = ltri[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
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
|
|
|
|
|
else if (has_fcol_preview) glColor3ubv((const GLubyte *)&(color_face_array[BM_elem_index_get(efa)]));
|
2013-04-13 20:20:21 +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
|
|
|
}
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(ltri[0]->v->co);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(ltri[1]->v->co);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(ltri[2]->v->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
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);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(ltri[0]->v->co);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(ltri[1]->v->co);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(ltri[2]->v->co);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(ltri[0]->v->no);
|
|
|
|
|
glVertex3fv(ltri[0]->v->co);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(ltri[1]->v->no);
|
|
|
|
|
glVertex3fv(ltri[1]->v->co);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(ltri[2]->v->no);
|
|
|
|
|
glVertex3fv(ltri[2]->v->co);
|
2011-09-11 13:23:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
static void bmdm_get_tri_uv(BMLoop *ltri[3], MLoopUV *luv[3], const int cd_loop_uv_offset)
|
2009-07-24 10:43:58 +00:00
|
|
|
{
|
2013-04-13 17:57:11 +00:00
|
|
|
luv[0] = BM_ELEM_CD_GET_VOID_P(ltri[0], cd_loop_uv_offset);
|
|
|
|
|
luv[1] = BM_ELEM_CD_GET_VOID_P(ltri[1], cd_loop_uv_offset);
|
|
|
|
|
luv[2] = BM_ELEM_CD_GET_VOID_P(ltri[2], cd_loop_uv_offset);
|
2013-01-10 12:07:01 +00:00
|
|
|
}
|
2009-07-24 10:43:58 +00:00
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
static void bmdm_get_tri_col(BMLoop *ltri[3], MLoopCol *lcol[3], const int cd_loop_color_offset)
|
2013-01-10 12:07:01 +00:00
|
|
|
{
|
2013-04-13 17:57:11 +00:00
|
|
|
lcol[0] = BM_ELEM_CD_GET_VOID_P(ltri[0], cd_loop_color_offset);
|
|
|
|
|
lcol[1] = BM_ELEM_CD_GET_VOID_P(ltri[1], cd_loop_color_offset);
|
|
|
|
|
lcol[2] = BM_ELEM_CD_GET_VOID_P(ltri[2], cd_loop_color_offset);
|
2009-07-24 10:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:20:21 +00:00
|
|
|
static void bmdm_get_tri_colpreview(BMLoop *ls[3], MLoopCol *lcol[3], unsigned char(*color_vert_array)[4])
|
|
|
|
|
{
|
|
|
|
|
lcol[0] = (MLoopCol *)color_vert_array[BM_elem_index_get(ls[0]->v)];
|
|
|
|
|
lcol[1] = (MLoopCol *)color_vert_array[BM_elem_index_get(ls[1]->v)];
|
|
|
|
|
lcol[2] = (MLoopCol *)color_vert_array[BM_elem_index_get(ls[2]->v)];
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMEditMesh *em = bmdm->em;
|
|
|
|
|
BMesh *bm = em->bm;
|
2013-04-13 17:57:11 +00:00
|
|
|
struct BMLoop *(*looptris)[3] = em->looptris;
|
2012-05-03 21:19:31 +00:00
|
|
|
float (*vertexCos)[3] = bmdm->vertexCos;
|
|
|
|
|
float (*vertexNos)[3] = bmdm->vertexNos;
|
2013-04-13 18:11:27 +00:00
|
|
|
float (*polyNos)[3] = bmdm->polyNos;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *efa;
|
2011-05-09 04:06:48 +00:00
|
|
|
MLoopUV *luv[3], dummyluv = {{0}};
|
2013-01-10 12:07:01 +00:00
|
|
|
MLoopCol *lcol[3] = {NULL} /* , dummylcol = {0} */;
|
2013-01-11 01:41:27 +00:00
|
|
|
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
|
|
|
|
|
const int cd_loop_color_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPCOL);
|
|
|
|
|
const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY);
|
2013-04-18 17:09:56 +00:00
|
|
|
unsigned char(*color_vert_array)[4] = em->derivedVertColor;
|
2013-01-10 12:07:01 +00:00
|
|
|
bool has_uv = (cd_loop_uv_offset != -1);
|
2013-04-13 20:20:21 +00:00
|
|
|
bool has_vcol_preview = (color_vert_array != NULL);
|
|
|
|
|
bool has_vcol = (cd_loop_color_offset != -1) && (has_vcol_preview == false);
|
|
|
|
|
bool has_vcol_any = (has_vcol_preview || has_vcol);
|
2013-01-10 12:07:01 +00:00
|
|
|
int i;
|
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;
|
|
|
|
|
|
2013-01-10 12:07:01 +00:00
|
|
|
// dummylcol.r = dummylcol.g = dummylcol.b = dummylcol.a = 255; /* UNUSED */
|
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
|
|
|
|
2013-04-13 20:20:21 +00:00
|
|
|
/* call again below is ok */
|
|
|
|
|
if (has_vcol_preview) {
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
|
|
|
|
}
|
|
|
|
|
|
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++) {
|
2013-04-13 17:57:11 +00:00
|
|
|
BMLoop **ltri = looptris[i];
|
|
|
|
|
MTexPoly *tp = (cd_poly_tex_offset != -1) ? BM_ELEM_CD_GET_VOID_P(ltri[0]->f, cd_poly_tex_offset) : 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*/
|
2013-04-13 17:57:11 +00:00
|
|
|
int drawSmooth = BM_elem_flag_test(ltri[0]->f, BM_ELEM_SMOOTH);
|
2012-03-08 06:47:05 +00:00
|
|
|
DMDrawOption draw_option;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
efa = ltri[0]->f;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-01-10 12:07:01 +00:00
|
|
|
if (cd_poly_tex_offset != -1) {
|
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
|
|
|
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_uv) bmdm_get_tri_uv(ltri, luv, cd_loop_uv_offset);
|
|
|
|
|
if (has_vcol) bmdm_get_tri_col(ltri, lcol, cd_loop_color_offset);
|
|
|
|
|
else if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
|
2013-04-13 18:11:27 +00:00
|
|
|
|
2012-05-01 15:59:28 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
2009-05-16 16:18:08 +00:00
|
|
|
if (!drawSmooth) {
|
2013-04-13 18:11:27 +00:00
|
|
|
glNormal3fv(polyNos[BM_elem_index_get(efa)]);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-07-24 10:43:58 +00:00
|
|
|
glTexCoord2fv(luv[0]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
|
|
|
|
glTexCoord2fv(luv[1]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
|
|
|
|
glTexCoord2fv(luv[2]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2009-07-24 10:43:58 +00:00
|
|
|
glTexCoord2fv(luv[0]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
|
|
|
|
glTexCoord2fv(luv[1]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
|
|
|
|
glTexCoord2fv(luv[2]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
|
|
|
|
|
glVertex3fv(vertexCos[BM_elem_index_get(ltri[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++) {
|
2013-04-13 17:57:11 +00:00
|
|
|
BMLoop **ltri = looptris[i];
|
|
|
|
|
MTexPoly *tp = (cd_poly_tex_offset != -1) ? BM_ELEM_CD_GET_VOID_P(ltri[0]->f, cd_poly_tex_offset) : 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*/
|
2013-04-13 17:57:11 +00:00
|
|
|
int drawSmooth = BM_elem_flag_test(ltri[0]->f, BM_ELEM_SMOOTH);
|
2012-03-08 06:47:05 +00:00
|
|
|
DMDrawOption draw_option;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
efa = ltri[0]->f;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-01-10 12:07:01 +00:00
|
|
|
if (cd_poly_tex_offset != -1) {
|
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)
|
2013-04-13 17:57:11 +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
|
|
|
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_uv) bmdm_get_tri_uv(ltri, luv, cd_loop_uv_offset);
|
|
|
|
|
if (has_vcol) bmdm_get_tri_col(ltri, lcol, cd_loop_color_offset);
|
|
|
|
|
else if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
|
2013-04-13 18:11:27 +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
|
|
|
|
2013-01-10 12:07:01 +00:00
|
|
|
glTexCoord2fv(luv[0]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(ltri[0]->v->co);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
2013-01-10 12:07:01 +00:00
|
|
|
glTexCoord2fv(luv[1]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(ltri[1]->v->co);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
2013-01-10 12:07:01 +00:00
|
|
|
glTexCoord2fv(luv[2]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glVertex3fv(ltri[2]->v->co);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-01-10 12:07:01 +00:00
|
|
|
glTexCoord2fv(luv[0]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[0]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(ltri[0]->v->no);
|
|
|
|
|
glVertex3fv(ltri[0]->v->co);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
2013-01-10 12:07:01 +00:00
|
|
|
glTexCoord2fv(luv[1]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[1]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(ltri[1]->v->no);
|
|
|
|
|
glVertex3fv(ltri[1]->v->co);
|
2009-07-24 10:43:58 +00:00
|
|
|
|
2013-01-10 12:07:01 +00:00
|
|
|
glTexCoord2fv(luv[2]->uv);
|
2013-04-13 20:20:21 +00:00
|
|
|
if (has_vcol_any) glColor3ubv((const GLubyte *)&(lcol[2]->r));
|
2013-04-13 17:57:11 +00:00
|
|
|
glNormal3fv(ltri[2]->v->no);
|
|
|
|
|
glVertex3fv(ltri[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
|
|
|
}
|
|
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
/**
|
|
|
|
|
* \note
|
|
|
|
|
*
|
|
|
|
|
* For UV's:
|
|
|
|
|
* const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset);
|
|
|
|
|
*
|
|
|
|
|
* This is intentionally different to calling:
|
|
|
|
|
* CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPUV, i);
|
|
|
|
|
*
|
|
|
|
|
* ... because the material may use layer names to select different UV's
|
|
|
|
|
* see: [#34378]
|
|
|
|
|
*/
|
|
|
|
|
static void emdm_pass_attrib_vertex_glsl(DMVertexAttribs *attribs, BMLoop *loop, int index_in_face)
|
2013-02-23 05:36:15 +00:00
|
|
|
{
|
2013-02-23 06:56:10 +00:00
|
|
|
BMVert *eve = loop->v;
|
2013-02-23 05:36:15 +00:00
|
|
|
int i;
|
2013-02-23 06:56:10 +00:00
|
|
|
|
2013-02-23 05:36:15 +00:00
|
|
|
if (attribs->totorco) {
|
2013-02-23 06:56:10 +00:00
|
|
|
const float *orco = attribs->orco.array[BM_elem_index_get(eve)];
|
2013-02-23 05:36:15 +00:00
|
|
|
glVertexAttrib3fvARB(attribs->orco.gl_index, orco);
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < attribs->tottface; i++) {
|
2013-02-23 06:56:10 +00:00
|
|
|
const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset);
|
|
|
|
|
glVertexAttrib2fvARB(attribs->tface[i].gl_index, luv->uv);
|
2013-02-23 05:36:15 +00:00
|
|
|
}
|
|
|
|
|
for (i = 0; i < attribs->totmcol; i++) {
|
2013-02-23 06:56:10 +00:00
|
|
|
const MLoopCol *cp = BM_ELEM_CD_GET_VOID_P(loop, attribs->mcol[i].em_offset);
|
|
|
|
|
GLubyte col[4];
|
|
|
|
|
col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
|
|
|
|
|
glVertexAttrib4ubvARB(attribs->mcol[i].gl_index, col);
|
2013-02-23 05:36:15 +00:00
|
|
|
}
|
|
|
|
|
if (attribs->tottang) {
|
2013-02-23 06:56:10 +00:00
|
|
|
const float *tang = attribs->tang.array[i * 4 + index_in_face];
|
2013-02-23 05:36:15 +00:00
|
|
|
glVertexAttrib3fvARB(attribs->tang.gl_index, tang);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMEditMesh *em = bmdm->em;
|
|
|
|
|
BMesh *bm = em->bm;
|
2013-04-13 17:57:11 +00:00
|
|
|
struct BMLoop *(*looptris)[3] = em->looptris;
|
2012-05-03 21:19:31 +00:00
|
|
|
float (*vertexCos)[3] = bmdm->vertexCos;
|
|
|
|
|
float (*vertexNos)[3] = bmdm->vertexNos;
|
2013-04-13 18:11:27 +00:00
|
|
|
float (*polyNos)[3] = bmdm->polyNos;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *efa;
|
|
|
|
|
DMVertexAttribs attribs;
|
|
|
|
|
GPUVertexAttribs gattribs;
|
2011-09-23 05:59:37 +00:00
|
|
|
|
2013-02-23 05:36:15 +00:00
|
|
|
int i, 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
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
for (i = 0; i < em->tottri; i++) {
|
|
|
|
|
BMLoop **ltri = looptris[i];
|
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) {
|
2013-04-13 18:11:27 +00:00
|
|
|
if (vertexCos) glNormal3fv(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
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_glsl(&attribs, ltri[0], 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
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_glsl(&attribs, ltri[1], 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
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_glsl(&attribs, ltri[2], 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 {
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_glsl(&attribs, ltri[0], 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
|
|
|
}
|
|
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_glsl(&attribs, ltri[1], 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
|
|
|
}
|
|
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_glsl(&attribs, ltri[2], 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
/* emdm_pass_attrib_vertex_glsl's note about em_offset use applies here */
|
|
|
|
|
static void emdm_pass_attrib_vertex_mat(DMVertexAttribs *attribs, BMLoop *loop, int index_in_face)
|
2013-02-23 05:36:15 +00:00
|
|
|
{
|
2013-02-23 06:56:10 +00:00
|
|
|
BMVert *eve = loop->v;
|
2013-02-23 05:36:15 +00:00
|
|
|
int i;
|
2013-02-23 06:56:10 +00:00
|
|
|
|
2013-02-23 05:36:15 +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 (i = 0; i < attribs->tottface; i++) {
|
2013-02-23 06:56:10 +00:00
|
|
|
const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset);
|
2013-02-23 05:36:15 +00:00
|
|
|
if (attribs->tface[i].gl_texco)
|
2013-02-23 06:56:10 +00:00
|
|
|
glTexCoord2fv(luv->uv);
|
2013-02-23 05:36:15 +00:00
|
|
|
else
|
2013-02-23 06:56:10 +00:00
|
|
|
glVertexAttrib2fvARB(attribs->tface[i].gl_index, luv->uv);
|
2013-02-23 05:36:15 +00:00
|
|
|
}
|
|
|
|
|
for (i = 0; i < attribs->totmcol; i++) {
|
2013-02-23 06:56:10 +00:00
|
|
|
const MLoopCol *cp = BM_ELEM_CD_GET_VOID_P(loop, attribs->mcol[i].em_offset);
|
|
|
|
|
GLubyte col[4];
|
|
|
|
|
col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
|
|
|
|
|
glVertexAttrib4ubvARB(attribs->mcol[i].gl_index, col);
|
2013-02-23 05:36:15 +00:00
|
|
|
}
|
|
|
|
|
if (attribs->tottang) {
|
2013-02-23 06:56:10 +00:00
|
|
|
float *tang = attribs->tang.array[i * 4 + index_in_face];
|
2013-02-23 05:36:15 +00:00
|
|
|
glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMEditMesh *em = bmdm->em;
|
|
|
|
|
BMesh *bm = em->bm;
|
2013-04-13 17:57:11 +00:00
|
|
|
struct BMLoop *(*looptris)[3] = em->looptris;
|
2012-05-03 21:19:31 +00:00
|
|
|
float (*vertexCos)[3] = bmdm->vertexCos;
|
|
|
|
|
float (*vertexNos)[3] = bmdm->vertexNos;
|
2013-04-13 18:11:27 +00:00
|
|
|
float (*polyNos)[3] = bmdm->polyNos;
|
2011-11-10 03:40:02 +00:00
|
|
|
BMFace *efa;
|
2012-05-03 21:19:31 +00:00
|
|
|
DMVertexAttribs attribs = {{{0}}};
|
2011-11-10 03:05:11 +00:00
|
|
|
GPUVertexAttribs gattribs;
|
2013-02-23 05:36:15 +00:00
|
|
|
int i, 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
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
for (i = 0; i < em->tottri; i++) {
|
|
|
|
|
BMLoop **ltri = looptris[i];
|
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) {
|
2013-04-13 18:11:27 +00:00
|
|
|
if (vertexCos) glNormal3fv(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
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_mat(&attribs, ltri[0], 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
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_mat(&attribs, ltri[1], 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
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_mat(&attribs, ltri[2], 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 {
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_mat(&attribs, ltri[0], 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
|
|
|
}
|
|
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_mat(&attribs, ltri[1], 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
|
|
|
}
|
|
|
|
|
|
2013-02-23 06:56:10 +00:00
|
|
|
emdm_pass_attrib_vertex_mat(&attribs, ltri[2], 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getMinMax(DerivedMesh *dm, float r_min[3], float r_max[3])
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMVert *eve;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
if (bm->totvert) {
|
2012-05-03 21:19:31 +00:00
|
|
|
if (bmdm->vertexCos) {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
minmax_v3v3_v3(r_min, r_max, bmdm->vertexCos[i]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
|
|
|
|
|
minmax_v3v3_v3(r_min, r_max, eve->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:58:49 +00:00
|
|
|
zero_v3(r_min);
|
|
|
|
|
zero_v3(r_max);
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->bm->totvert;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->bm->totedge;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->tottri;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->bm->totloop;
|
2011-11-30 18:03:56 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->bm->totface;
|
2009-06-23 05:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static int bmvert_to_mvert(BMesh *bm, BMVert *ev, MVert *r_vert)
|
(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
|
|
|
{
|
2013-01-09 18:20:11 +00:00
|
|
|
float *f;
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
copy_v3_v3(r_vert->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
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
normal_float_to_short_v3(r_vert->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
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert->flag = BM_vert_flag_to_mflag(ev);
|
2010-07-14 22:06:10 +00:00
|
|
|
|
2013-01-09 18:20:11 +00:00
|
|
|
if ((f = CustomData_bmesh_get(&bm->vdata, ev->head.data, CD_BWEIGHT))) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert->bweight = (unsigned char)((*f) * 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
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getVert(DerivedMesh *dm, int index, MVert *r_vert)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMVert *ev;
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
if (UNLIKELY(index < 0 || index >= bm->totvert)) {
|
2013-04-13 20:40:34 +00:00
|
|
|
BLI_assert(!"error in emDM_getVert");
|
2009-05-16 16:18:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
ev = bmdm->em->vert_index[index]; /* should be EDBM_vert_at_index() */
|
2013-04-13 20:58:49 +00:00
|
|
|
// ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */
|
2012-02-19 01:51:36 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
bmvert_to_mvert(bm, ev, r_vert);
|
2012-04-21 12:51:47 +00:00
|
|
|
if (bmdm->vertexCos)
|
2013-04-13 20:58:49 +00:00
|
|
|
copy_v3_v3(r_vert->co, bmdm->vertexCos[index]);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *r_edge)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMEdge *e;
|
2013-01-09 18:20:11 +00:00
|
|
|
float *f;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
if (UNLIKELY(index < 0 || index >= bm->totedge)) {
|
2013-04-13 20:40:34 +00:00
|
|
|
BLI_assert(!"error in emDM_getEdge");
|
2009-06-23 05:35:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
e = bmdm->em->edge_index[index]; /* should be EDBM_edge_at_index() */
|
2013-04-13 20:58:49 +00:00
|
|
|
// e = BM_edge_at_index(bm, index); /* warning, does list loop, _not_ ideal */
|
2010-07-14 22:06:10 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->flag = BM_edge_flag_to_mflag(e);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->v1 = BM_elem_index_get(e->v1);
|
|
|
|
|
r_edge->v2 = BM_elem_index_get(e->v2);
|
2013-01-09 18:20:11 +00:00
|
|
|
|
|
|
|
|
if ((f = CustomData_bmesh_get(&bm->edata, e->head.data, CD_BWEIGHT))) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->bweight = (unsigned char)((*f) * 255.0f);
|
2013-01-09 18:20:11 +00:00
|
|
|
}
|
|
|
|
|
if ((f = CustomData_bmesh_get(&bm->edata, e->head.data, CD_CREASE))) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->crease = (unsigned char)((*f) * 255.0f);
|
2013-01-09 18:20:11 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getTessFace(DerivedMesh *dm, int index, MFace *r_face)
|
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;
|
2013-04-13 17:57:11 +00:00
|
|
|
BMLoop **ltri;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 20:40:34 +00:00
|
|
|
if (UNLIKELY(index < 0 || index >= bmdm->em->tottri)) {
|
|
|
|
|
BLI_assert(!"error in emDM_getTessFace");
|
2009-06-23 05:35:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
ltri = bmdm->em->looptris[index];
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
ef = ltri[0]->f;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->mat_nr = (unsigned char) ef->mat_nr;
|
|
|
|
|
r_face->flag = BM_face_flag_to_mflag(ef);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->v1 = BM_elem_index_get(ltri[0]->v);
|
|
|
|
|
r_face->v2 = BM_elem_index_get(ltri[1]->v);
|
|
|
|
|
r_face->v3 = BM_elem_index_get(ltri[2]->v);
|
|
|
|
|
r_face->v4 = 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
test_index_face(r_face, NULL, 0, 3);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyVertArray(DerivedMesh *dm, MVert *r_vert)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-04-17 13:07:13 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMVert *eve;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMIter iter;
|
2013-01-10 04:43:31 +00:00
|
|
|
const int cd_vert_bweight_offset = CustomData_get_offset(&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) {
|
2013-04-13 20:58:49 +00:00
|
|
|
copy_v3_v3(r_vert->co, bmdm->vertexCos[i]);
|
|
|
|
|
normal_float_to_short_v3(r_vert->no, eve->no);
|
|
|
|
|
r_vert->flag = BM_vert_flag_to_mflag(eve);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert->bweight = (cd_vert_bweight_offset != -1) ? BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset) : 0;
|
2013-01-10 04:43:31 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert++;
|
2012-05-13 14:47:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
|
2013-04-13 20:58:49 +00:00
|
|
|
copy_v3_v3(r_vert->co, eve->co);
|
|
|
|
|
normal_float_to_short_v3(r_vert->no, eve->no);
|
|
|
|
|
r_vert->flag = BM_vert_flag_to_mflag(eve);
|
2010-07-14 22:06:10 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert->bweight = (cd_vert_bweight_offset != -1) ? BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset) : 0;
|
2013-01-10 04:43:31 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert++;
|
2010-07-14 22:06:10 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyEdgeArray(DerivedMesh *dm, MEdge *r_edge)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = ((EditDerivedBMesh *)dm)->em->bm;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMEdge *eed;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMIter iter;
|
2013-01-10 04:43:31 +00:00
|
|
|
|
|
|
|
|
const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
|
|
|
|
|
const int cd_edge_crease_offset = CustomData_get_offset(&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) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->v1 = BM_elem_index_get(eed->v1);
|
|
|
|
|
r_edge->v2 = BM_elem_index_get(eed->v2);
|
2010-07-14 22:06:10 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->flag = BM_edge_flag_to_mflag(eed);
|
2012-05-13 14:47:53 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->crease = (cd_edge_crease_offset != -1) ? BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_crease_offset) : 0;
|
|
|
|
|
r_edge->bweight = (cd_edge_bweight_offset != -1) ? BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_bweight_offset) : 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge++;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyTessFaceArray(DerivedMesh *dm, MFace *r_face)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
struct BMLoop *(*looptris)[3] = bmdm->em->looptris;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *ef;
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
for (i = 0; i < bmdm->em->tottri; i++, r_face++) {
|
2013-04-13 17:57:11 +00:00
|
|
|
BMLoop **ltri = looptris[i];
|
|
|
|
|
ef = ltri[0]->f;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->mat_nr = (unsigned char) ef->mat_nr;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->flag = BM_face_flag_to_mflag(ef);
|
|
|
|
|
r_face->edcode = 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->v1 = BM_elem_index_get(ltri[0]->v);
|
|
|
|
|
r_face->v2 = BM_elem_index_get(ltri[1]->v);
|
|
|
|
|
r_face->v3 = BM_elem_index_get(ltri[2]->v);
|
|
|
|
|
r_face->v4 = 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
test_index_face(r_face, NULL, 0, 3);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyLoopArray(DerivedMesh *dm, MLoop *r_loop)
|
2011-06-14 03:16:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->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) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_loop->v = BM_elem_index_get(l->v);
|
|
|
|
|
r_loop->e = BM_elem_index_get(l->e);
|
|
|
|
|
r_loop++;
|
2011-06-14 03:16:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyPolyArray(DerivedMesh *dm, MPoly *r_poly)
|
2011-06-14 03:16:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->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) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_poly->flag = BM_face_flag_to_mflag(efa);
|
|
|
|
|
r_poly->loopstart = i;
|
|
|
|
|
r_poly->totloop = efa->len;
|
|
|
|
|
r_poly->mat_nr = efa->mat_nr;
|
2011-06-14 03:16:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_poly++;
|
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;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->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) {
|
2013-04-13 20:31:52 +00:00
|
|
|
for (i = 0; i < bmdm->em->tottri; i++, data += size) {
|
|
|
|
|
BMFace *efa = bmdm->em->looptris[i][0]->f;
|
2012-04-16 04:17:33 +00:00
|
|
|
bmdata = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
|
|
|
|
|
ME_MTEXFACE_CPY(((MTFace *)data), ((MTexPoly *)bmdata));
|
|
|
|
|
for (j = 0; j < 3; j++) {
|
2013-04-13 20:31:52 +00:00
|
|
|
bmdata = CustomData_bmesh_get(&bm->ldata, bmdm->em->looptris[i][j]->head.data, CD_MLOOPUV);
|
2012-04-16 04:17:33 +00:00
|
|
|
copy_v2_v2(((MTFace *)data)->uv[j], ((MLoopUV *)bmdata)->uv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:31:52 +00:00
|
|
|
for (i = 0; i < bmdm->em->tottri; i++, data += size) {
|
2012-04-16 04:17:33 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2013-04-13 20:31:52 +00:00
|
|
|
bmdata = CustomData_bmesh_get(&bm->ldata, bmdm->em->looptris[i][j]->head.data, CD_MLOOPCOL);
|
2012-04-16 04:17:33 +00:00
|
|
|
MESH_MLOOPCOL_TO_MCOL(((MLoopCol *)bmdata), (((MCol *)data) + j));
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return datalayer;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getVertCos(DerivedMesh *dm, float (*r_cos)[3])
|
2011-05-09 22:16:31 +00:00
|
|
|
{
|
2013-04-13 20:58:49 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->em->bm;
|
2011-05-09 22:16:31 +00:00
|
|
|
BMVert *eve;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
2011-05-10 23:48:09 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
if (bmdm->vertexCos) {
|
|
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
copy_v3_v3(r_cos[i], bmdm->vertexCos[i]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
copy_v3_v3(r_cos[i], eve->co);
|
2011-05-09 22:16:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return &bmdm->em->bm->vdata;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return &bmdm->em->bm->edata;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return &bmdm->em->bm->ldata;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return &bmdm->em->bm->pdata;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
bmdm->em = em;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
DM_init((DerivedMesh *)bmdm, DM_TYPE_EDITBMESH, bm->totvert,
|
|
|
|
|
bm->totedge, em->tottri, bm->totloop, bm->totface);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-01-10 04:43:31 +00:00
|
|
|
/* could also get from the objects mesh directly */
|
|
|
|
|
bmdm->dm.cd_flag = BM_mesh_cd_flag_from_bmesh(bm);
|
|
|
|
|
|
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
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, 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);
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
2012-05-22 15:29:27 +00:00
|
|
|
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
|
|
|
}
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* StatVis Functions */
|
|
|
|
|
|
|
|
|
|
static void axis_from_enum_v3(float v[3], const char axis)
|
|
|
|
|
{
|
|
|
|
|
zero_v3(v);
|
|
|
|
|
if (axis < 3) v[axis] = 1.0f;
|
|
|
|
|
else v[axis - 3] = -1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void statvis_calc_overhang(
|
|
|
|
|
BMEditMesh *em,
|
2013-04-18 04:24:18 +00:00
|
|
|
const float (*polyNos)[3],
|
2013-04-17 09:27:23 +00:00
|
|
|
/* values for calculating */
|
|
|
|
|
const float min, const float max, const char axis,
|
|
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_face_colors)[4])
|
|
|
|
|
{
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
BMFace *f;
|
|
|
|
|
float dir[3];
|
|
|
|
|
int index;
|
|
|
|
|
const float minmax_irange = 1.0f / (max - min);
|
|
|
|
|
|
|
|
|
|
/* fallback */
|
|
|
|
|
const char col_fallback[4] = {64, 64, 64, 255};
|
|
|
|
|
|
|
|
|
|
BLI_assert(min <= max);
|
|
|
|
|
|
|
|
|
|
axis_from_enum_v3(dir, axis);
|
|
|
|
|
|
2013-04-17 23:30:19 +00:00
|
|
|
if (LIKELY(em->ob)) {
|
|
|
|
|
mul_transposed_mat3_m4_v3(em->ob->obmat, dir);
|
|
|
|
|
normalize_v3(dir);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
/* now convert into global space */
|
|
|
|
|
BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, index) {
|
|
|
|
|
float fac = angle_normalized_v3v3(polyNos ? polyNos[index] : f->no, dir) / (float)M_PI;
|
|
|
|
|
|
|
|
|
|
/* remap */
|
|
|
|
|
if (fac >= min && fac <= max) {
|
|
|
|
|
float fcol[3];
|
|
|
|
|
fac = (fac - min) * minmax_irange;
|
|
|
|
|
fac = 1.0f - fac;
|
|
|
|
|
CLAMP(fac, 0.0f, 1.0f);
|
|
|
|
|
weight_to_rgb(fcol, fac);
|
|
|
|
|
rgb_float_to_uchar(r_face_colors[index], fcol);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v4_v4_char((char *)r_face_colors[index], (const char *)col_fallback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* so we can use jitter values for face interpolation */
|
|
|
|
|
static void uv_from_jitter_v2(float uv[2])
|
|
|
|
|
{
|
|
|
|
|
uv[0] += 0.5f;
|
|
|
|
|
uv[1] += 0.5f;
|
|
|
|
|
if (uv[0] + uv[1] > 1.0f) {
|
|
|
|
|
uv[0] = 1.0f - uv[0];
|
|
|
|
|
uv[1] = 1.0f - uv[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLAMP(uv[0], 0.0f, 1.0f);
|
|
|
|
|
CLAMP(uv[1], 0.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void statvis_calc_thickness(
|
|
|
|
|
BMEditMesh *em,
|
2013-04-18 04:24:18 +00:00
|
|
|
const float (*vertexCos)[3],
|
2013-04-17 09:27:23 +00:00
|
|
|
/* values for calculating */
|
|
|
|
|
const float min, const float max, const int samples,
|
|
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_face_colors)[4])
|
|
|
|
|
{
|
2013-04-18 17:23:02 +00:00
|
|
|
const float eps_offset = 0.00001f;
|
2013-04-17 09:27:23 +00:00
|
|
|
float *face_dists = (float *)r_face_colors; /* cheating */
|
|
|
|
|
const bool use_jit = samples < 32;
|
|
|
|
|
float jit_ofs[32][2];
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
const int tottri = em->tottri;
|
|
|
|
|
const float minmax_irange = 1.0f / (max - min);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
struct BMLoop *(*looptris)[3] = em->looptris;
|
|
|
|
|
|
|
|
|
|
/* fallback */
|
|
|
|
|
const char col_fallback[4] = {64, 64, 64, 255};
|
|
|
|
|
|
|
|
|
|
struct BMBVHTree *bmtree;
|
|
|
|
|
|
|
|
|
|
BLI_assert(min <= max);
|
|
|
|
|
|
|
|
|
|
fill_vn_fl(face_dists, em->bm->totface, max);
|
|
|
|
|
|
|
|
|
|
if (use_jit) {
|
|
|
|
|
int j;
|
|
|
|
|
BLI_assert(samples < 32);
|
|
|
|
|
BLI_jitter_init(jit_ofs[0], samples);
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < samples; j++) {
|
|
|
|
|
uv_from_jitter_v2(jit_ofs[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_FACE);
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 01:20:04 +00:00
|
|
|
bmtree = BKE_bmbvh_new(em, 0, vertexCos, false);
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < tottri; i++) {
|
|
|
|
|
BMFace *f_hit;
|
|
|
|
|
BMLoop **ltri = looptris[i];
|
|
|
|
|
const int index = BM_elem_index_get(ltri[0]->f);
|
|
|
|
|
const float *cos[3];
|
|
|
|
|
float ray_co[3];
|
|
|
|
|
float ray_no[3];
|
|
|
|
|
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
cos[0] = vertexCos[BM_elem_index_get(ltri[0]->v)];
|
|
|
|
|
cos[1] = vertexCos[BM_elem_index_get(ltri[1]->v)];
|
2013-04-17 23:30:19 +00:00
|
|
|
cos[2] = vertexCos[BM_elem_index_get(ltri[2]->v)];
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cos[0] = ltri[0]->v->co;
|
|
|
|
|
cos[1] = ltri[1]->v->co;
|
|
|
|
|
cos[2] = ltri[2]->v->co;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
normal_tri_v3(ray_no, cos[2], cos[1], cos[0]);
|
|
|
|
|
|
2013-04-20 16:29:37 +00:00
|
|
|
#define FACE_RAY_TEST_ANGLE \
|
|
|
|
|
f_hit = BKE_bmbvh_ray_cast(bmtree, ray_co, ray_no, \
|
|
|
|
|
&dist, NULL, NULL); \
|
2013-04-20 16:49:02 +00:00
|
|
|
if (f_hit && dist < face_dists[index]) { \
|
2013-04-20 16:29:37 +00:00
|
|
|
float angle_fac = fabsf(dot_v3v3(ltri[0]->f->no, f_hit->no)); \
|
|
|
|
|
angle_fac = 1.0f - angle_fac; \
|
|
|
|
|
angle_fac = angle_fac * angle_fac * angle_fac; \
|
|
|
|
|
angle_fac = 1.0f - angle_fac; \
|
|
|
|
|
dist /= angle_fac; \
|
|
|
|
|
if (dist < face_dists[index]) { \
|
|
|
|
|
face_dists[index] = dist; \
|
|
|
|
|
} \
|
|
|
|
|
} (void)0
|
|
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
if (use_jit) {
|
|
|
|
|
int j;
|
|
|
|
|
for (j = 0; j < samples; j++) {
|
2013-04-20 16:29:37 +00:00
|
|
|
float dist = face_dists[index];
|
2013-04-17 09:27:23 +00:00
|
|
|
interp_v3_v3v3v3_uv(ray_co, cos[0], cos[1], cos[2], jit_ofs[j]);
|
|
|
|
|
madd_v3_v3fl(ray_co, ray_no, eps_offset);
|
|
|
|
|
|
2013-04-20 16:29:37 +00:00
|
|
|
FACE_RAY_TEST_ANGLE;
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-04-20 16:29:37 +00:00
|
|
|
float dist = face_dists[index];
|
2013-04-17 09:27:23 +00:00
|
|
|
mid_v3_v3v3v3(ray_co, cos[0], cos[1], cos[2]);
|
|
|
|
|
madd_v3_v3fl(ray_co, ray_no, eps_offset);
|
|
|
|
|
|
2013-04-20 16:29:37 +00:00
|
|
|
FACE_RAY_TEST_ANGLE;
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_bmbvh_free(bmtree);
|
|
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
/* convert floats into color! */
|
|
|
|
|
for (i = 0; i < bm->totface; i++) {
|
|
|
|
|
float fac = face_dists[i];
|
|
|
|
|
|
|
|
|
|
/* important not '<=' */
|
|
|
|
|
if (fac < max) {
|
|
|
|
|
float fcol[3];
|
|
|
|
|
fac = (fac - min) * minmax_irange;
|
|
|
|
|
fac = 1.0f - fac;
|
|
|
|
|
CLAMP(fac, 0.0f, 1.0f);
|
|
|
|
|
weight_to_rgb(fcol, fac);
|
|
|
|
|
rgb_float_to_uchar(r_face_colors[i], fcol);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v4_v4_char((char *)r_face_colors[i], (const char *)col_fallback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void statvis_calc_intersect(
|
|
|
|
|
BMEditMesh *em,
|
2013-04-18 04:24:18 +00:00
|
|
|
const float (*vertexCos)[3],
|
2013-04-17 09:27:23 +00:00
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_face_colors)[4])
|
|
|
|
|
{
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
BMEdge *e;
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
|
|
/* fallback */
|
|
|
|
|
// const char col_fallback[4] = {64, 64, 64, 255};
|
|
|
|
|
|
|
|
|
|
struct BMBVHTree *bmtree;
|
|
|
|
|
|
|
|
|
|
memset(r_face_colors, 64, sizeof(int) * em->bm->totface);
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_FACE);
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 01:20:04 +00:00
|
|
|
bmtree = BKE_bmbvh_new(em, 0, vertexCos, false);
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
|
|
|
|
BMFace *f_hit;
|
|
|
|
|
float cos[2][3];
|
|
|
|
|
float cos_mid[3];
|
|
|
|
|
float ray_no[3];
|
|
|
|
|
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
copy_v3_v3(cos[0], vertexCos[BM_elem_index_get(e->v1)]);
|
|
|
|
|
copy_v3_v3(cos[1], vertexCos[BM_elem_index_get(e->v2)]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v3_v3(cos[0], e->v1->co);
|
|
|
|
|
copy_v3_v3(cos[1], e->v2->co);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mid_v3_v3v3(cos_mid, cos[0], cos[1]);
|
|
|
|
|
sub_v3_v3v3(ray_no, cos[1], cos[0]);
|
|
|
|
|
|
|
|
|
|
f_hit = BKE_bmbvh_find_face_segment(bmtree, cos[0], cos[1],
|
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (f_hit) {
|
|
|
|
|
BMLoop *l_iter, *l_first;
|
|
|
|
|
float fcol[3];
|
|
|
|
|
|
|
|
|
|
index = BM_elem_index_get(f_hit);
|
|
|
|
|
weight_to_rgb(fcol, 1.0f);
|
|
|
|
|
rgb_float_to_uchar(r_face_colors[index], fcol);
|
|
|
|
|
|
|
|
|
|
l_iter = l_first = e->l;
|
|
|
|
|
do {
|
|
|
|
|
index = BM_elem_index_get(l_iter->f);
|
|
|
|
|
weight_to_rgb(fcol, 1.0f);
|
|
|
|
|
rgb_float_to_uchar(r_face_colors[index], fcol);
|
|
|
|
|
} while ((l_iter = l_iter->radial_next) != l_first);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_bmbvh_free(bmtree);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 04:24:18 +00:00
|
|
|
static void statvis_calc_distort(
|
|
|
|
|
BMEditMesh *em,
|
|
|
|
|
const float (*vertexCos)[3],
|
|
|
|
|
/* values for calculating */
|
|
|
|
|
const float min, const float max,
|
|
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_face_colors)[4])
|
|
|
|
|
{
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
BMFace *f;
|
|
|
|
|
float f_no[3];
|
|
|
|
|
int index;
|
|
|
|
|
const float minmax_irange = 1.0f / (max - min);
|
|
|
|
|
|
|
|
|
|
/* fallback */
|
|
|
|
|
const char col_fallback[4] = {64, 64, 64, 255};
|
|
|
|
|
|
|
|
|
|
/* now convert into global space */
|
|
|
|
|
BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, index) {
|
|
|
|
|
float fac;
|
|
|
|
|
|
|
|
|
|
if (f->len == 3) {
|
|
|
|
|
fac = -1.0f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BMLoop *l_iter, *l_first;
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
BM_face_normal_update_vcos(bm, f, f_no, vertexCos);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v3_v3(f_no, f->no);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fac = 0.0f;
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
|
do {
|
|
|
|
|
float no_corner[3];
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
normal_tri_v3(no_corner,
|
|
|
|
|
vertexCos[BM_elem_index_get(l_iter->prev->v)],
|
|
|
|
|
vertexCos[BM_elem_index_get(l_iter->v)],
|
|
|
|
|
vertexCos[BM_elem_index_get(l_iter->next->v)]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BM_loop_calc_face_normal(l_iter, no_corner);
|
|
|
|
|
}
|
2013-04-18 09:12:06 +00:00
|
|
|
/* simple way to detect (what is most likely) concave */
|
|
|
|
|
if (dot_v3v3(f_no, no_corner) < 0.0f) {
|
|
|
|
|
negate_v3(no_corner);
|
|
|
|
|
}
|
2013-04-18 04:24:18 +00:00
|
|
|
fac = max_ff(fac, angle_normalized_v3v3(f_no, no_corner));
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
2013-04-18 09:12:06 +00:00
|
|
|
fac *= 2.0f;
|
2013-04-18 04:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remap */
|
|
|
|
|
if (fac >= min) {
|
|
|
|
|
float fcol[3];
|
|
|
|
|
fac = (fac - min) * minmax_irange;
|
|
|
|
|
CLAMP(fac, 0.0f, 1.0f);
|
|
|
|
|
weight_to_rgb(fcol, fac);
|
|
|
|
|
rgb_float_to_uchar(r_face_colors[index], fcol);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v4_v4_char((char *)r_face_colors[index], (const char *)col_fallback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 17:09:56 +00:00
|
|
|
static void statvis_calc_sharp(
|
|
|
|
|
BMEditMesh *em,
|
|
|
|
|
const float (*vertexCos)[3],
|
|
|
|
|
/* values for calculating */
|
|
|
|
|
const float min, const float max,
|
|
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_vert_colors)[4])
|
|
|
|
|
{
|
|
|
|
|
float *vert_angles = (float *)r_vert_colors; /* cheating */
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
BMEdge *e;
|
|
|
|
|
//float f_no[3];
|
|
|
|
|
const float minmax_irange = 1.0f / (max - min);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* fallback */
|
|
|
|
|
const char col_fallback[4] = {64, 64, 64, 255};
|
|
|
|
|
|
|
|
|
|
(void)vertexCos; /* TODO */
|
|
|
|
|
|
|
|
|
|
fill_vn_fl(vert_angles, em->bm->totvert, -M_PI);
|
|
|
|
|
|
|
|
|
|
/* first assign float values to verts */
|
|
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
|
|
|
|
float angle = BM_edge_calc_face_angle_signed(e);
|
|
|
|
|
float *col1 = &vert_angles[BM_elem_index_get(e->v1)];
|
|
|
|
|
float *col2 = &vert_angles[BM_elem_index_get(e->v2)];
|
|
|
|
|
*col1 = max_ff(*col1, angle);
|
|
|
|
|
*col2 = max_ff(*col2, angle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* convert floats into color! */
|
|
|
|
|
for (i = 0; i < bm->totvert; i++) {
|
|
|
|
|
float fac = vert_angles[i];
|
|
|
|
|
|
|
|
|
|
/* important not '<=' */
|
|
|
|
|
if (fac > min) {
|
|
|
|
|
float fcol[3];
|
|
|
|
|
fac = (fac - min) * minmax_irange;
|
|
|
|
|
CLAMP(fac, 0.0f, 1.0f);
|
|
|
|
|
weight_to_rgb(fcol, fac);
|
|
|
|
|
rgb_float_to_uchar(r_vert_colors[i], fcol);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v4_v4_char((char *)r_vert_colors[i], (const char *)col_fallback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
void BKE_editmesh_statvis_calc(BMEditMesh *em, DerivedMesh *dm,
|
2013-04-18 17:09:56 +00:00
|
|
|
MeshStatVis *statvis)
|
2013-04-17 09:27:23 +00:00
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BLI_assert(dm == NULL || dm->type == DM_TYPE_EDITBMESH);
|
|
|
|
|
|
|
|
|
|
switch (statvis->type) {
|
|
|
|
|
case SCE_STATVIS_OVERHANG:
|
2013-04-17 23:30:19 +00:00
|
|
|
{
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_editmesh_color_ensure(em, BM_FACE);
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis_calc_overhang(
|
2013-04-18 04:24:18 +00:00
|
|
|
em, bmdm ? (const float (*)[3])bmdm->polyNos : NULL,
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis->overhang_min / (float)M_PI,
|
|
|
|
|
statvis->overhang_max / (float)M_PI,
|
|
|
|
|
statvis->overhang_axis,
|
2013-04-18 17:09:56 +00:00
|
|
|
em->derivedFaceColor);
|
2013-04-17 09:27:23 +00:00
|
|
|
break;
|
2013-04-17 23:30:19 +00:00
|
|
|
}
|
2013-04-17 09:27:23 +00:00
|
|
|
case SCE_STATVIS_THICKNESS:
|
2013-04-17 23:30:19 +00:00
|
|
|
{
|
|
|
|
|
const float scale = 1.0f / mat4_to_scale(em->ob->obmat);
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_editmesh_color_ensure(em, BM_FACE);
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis_calc_thickness(
|
2013-04-18 04:24:18 +00:00
|
|
|
em, bmdm ? (const float (*)[3])bmdm->vertexCos : NULL,
|
2013-04-17 23:30:19 +00:00
|
|
|
statvis->thickness_min * scale,
|
|
|
|
|
statvis->thickness_max * scale,
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis->thickness_samples,
|
2013-04-18 17:09:56 +00:00
|
|
|
em->derivedFaceColor);
|
2013-04-17 09:27:23 +00:00
|
|
|
break;
|
2013-04-17 23:30:19 +00:00
|
|
|
}
|
2013-04-17 09:27:23 +00:00
|
|
|
case SCE_STATVIS_INTERSECT:
|
2013-04-17 23:30:19 +00:00
|
|
|
{
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_editmesh_color_ensure(em, BM_FACE);
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis_calc_intersect(
|
2013-04-18 04:24:18 +00:00
|
|
|
em, bmdm ? (const float (*)[3])bmdm->vertexCos : NULL,
|
2013-04-18 17:09:56 +00:00
|
|
|
em->derivedFaceColor);
|
2013-04-17 09:27:23 +00:00
|
|
|
break;
|
2013-04-17 23:30:19 +00:00
|
|
|
}
|
2013-04-18 04:24:18 +00:00
|
|
|
case SCE_STATVIS_DISTORT:
|
|
|
|
|
{
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_editmesh_color_ensure(em, BM_FACE);
|
2013-04-18 04:24:18 +00:00
|
|
|
statvis_calc_distort(
|
|
|
|
|
em, bmdm ? (const float (*)[3])bmdm->vertexCos : NULL,
|
2013-04-18 09:12:06 +00:00
|
|
|
statvis->distort_min,
|
|
|
|
|
statvis->distort_max,
|
2013-04-18 17:09:56 +00:00
|
|
|
em->derivedFaceColor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SCE_STATVIS_SHARP:
|
|
|
|
|
{
|
|
|
|
|
BKE_editmesh_color_ensure(em, BM_VERT);
|
|
|
|
|
statvis_calc_sharp(
|
|
|
|
|
em, bmdm ? (const float (*)[3])bmdm->vertexCos : NULL,
|
|
|
|
|
statvis->sharp_min,
|
|
|
|
|
statvis->sharp_max,
|
|
|
|
|
/* in this case they are vertex colors */
|
|
|
|
|
em->derivedVertColor);
|
2013-04-18 04:24:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-04-18 01:20:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* Editmesh Vert Coords */
|
|
|
|
|
|
|
|
|
|
struct CageUserData {
|
|
|
|
|
int totvert;
|
|
|
|
|
float (*cos_cage)[3];
|
|
|
|
|
BLI_bitmap visit_bitmap;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void cage_mapped_verts_callback(void *userData, int index, const float co[3],
|
|
|
|
|
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
|
|
|
|
|
{
|
|
|
|
|
struct CageUserData *data = userData;
|
|
|
|
|
|
|
|
|
|
if ((index >= 0 && index < data->totvert) && (!BLI_BITMAP_GET(data->visit_bitmap, index))) {
|
|
|
|
|
BLI_BITMAP_SET(data->visit_bitmap, index);
|
|
|
|
|
copy_v3_v3(data->cos_cage[index], co);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float (*BKE_editmesh_vertexCos_get(BMEditMesh *em, Scene *scene, int *r_numVerts))[3]
|
|
|
|
|
{
|
|
|
|
|
DerivedMesh *cage, *final;
|
|
|
|
|
BLI_bitmap visit_bitmap;
|
|
|
|
|
struct CageUserData data;
|
|
|
|
|
float (*cos_cage)[3];
|
|
|
|
|
|
|
|
|
|
cage = editbmesh_get_derived_cage_and_final(scene, em->ob, em, &final, CD_MASK_BAREMESH);
|
|
|
|
|
cos_cage = MEM_callocN(sizeof(*cos_cage) * em->bm->totvert, "bmbvh cos_cage");
|
|
|
|
|
|
|
|
|
|
/* when initializing cage verts, we only want the first cage coordinate for each vertex,
|
|
|
|
|
* so that e.g. mirror or array use original vertex coordinates and not mirrored or duplicate */
|
|
|
|
|
visit_bitmap = BLI_BITMAP_NEW(em->bm->totvert, __func__);
|
|
|
|
|
|
|
|
|
|
data.totvert = em->bm->totvert;
|
|
|
|
|
data.cos_cage = cos_cage;
|
|
|
|
|
data.visit_bitmap = visit_bitmap;
|
|
|
|
|
|
|
|
|
|
cage->foreachMappedVert(cage, cage_mapped_verts_callback, &data);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(visit_bitmap);
|
|
|
|
|
|
|
|
|
|
if (r_numVerts) {
|
|
|
|
|
*r_numVerts = em->bm->totvert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cos_cage;
|
|
|
|
|
}
|