2009-01-07 15:17:58 +00:00
|
|
|
/**
|
|
|
|
|
* bmesh.h jan 2007
|
|
|
|
|
*
|
2009-03-08 15:02:49 +00:00
|
|
|
* BMesh API.
|
2009-01-07 15:17:58 +00:00
|
|
|
*
|
|
|
|
|
* $Id: BKE_bmesh.h,v 1.00 2007/01/17 17:42:01 Briggs Exp $
|
|
|
|
|
*
|
|
|
|
|
* ***** 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. The Blender
|
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
|
* about this.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2004 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Geoffrey Bantle, Levi Schooley.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2009-03-08 15:02:49 +00:00
|
|
|
#ifndef BMESH_H
|
|
|
|
|
#define BMESH_H
|
2009-01-07 15:17:58 +00:00
|
|
|
|
|
|
|
|
#include "DNA_listBase.h"
|
|
|
|
|
#include "DNA_customdata_types.h"
|
|
|
|
|
#include "BLI_mempool.h"
|
|
|
|
|
#include "BKE_customdata.h"
|
|
|
|
|
|
2009-03-14 02:52:16 +00:00
|
|
|
/*
|
|
|
|
|
short introduction:
|
|
|
|
|
|
|
|
|
|
the bmesh structure is a boundary representation, supporting non-manifold
|
|
|
|
|
locally modifiable topology. the API is designed to allow clean, maintainable
|
|
|
|
|
code, that never (or almost never) directly inspects the underlying structure.
|
|
|
|
|
|
|
|
|
|
The API includes iterators, including many useful topological iterators;
|
|
|
|
|
walkers, which walk over a mesh, without the risk of hitting the recursion
|
|
|
|
|
limit; operators, which are logical, reusable mesh modules; topological
|
2009-03-14 13:16:35 +00:00
|
|
|
modification functions (like split face, join faces, etc), which are used for
|
|
|
|
|
topological manipulations; and some (not yet finished) geometric utility
|
|
|
|
|
functions.
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
some definitions:
|
|
|
|
|
|
|
|
|
|
tool flags: private flags for tools. each operator has it's own private
|
|
|
|
|
tool flag "layer", which it can use to flag elements.
|
|
|
|
|
tool flags are also used by various other parts of the api.
|
|
|
|
|
header flags: stores persistent flags, such as selection state, hide state,
|
|
|
|
|
etc. be careful of touching these.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-01-07 15:17:58 +00:00
|
|
|
/*forward declarations*/
|
|
|
|
|
struct BMVert;
|
|
|
|
|
struct BMEdge;
|
|
|
|
|
struct BMFace;
|
|
|
|
|
struct BMLoop;
|
2009-03-14 02:52:16 +00:00
|
|
|
struct EditMesh;
|
|
|
|
|
struct BMOperator;
|
2009-01-07 15:17:58 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* BMHeader
|
|
|
|
|
*
|
|
|
|
|
* All mesh elements begin with a BMHeader. This structure
|
|
|
|
|
* hold several types of data
|
|
|
|
|
*
|
|
|
|
|
* 1: The type of the element (vert, edge, loop or face)
|
|
|
|
|
* 2: Persistant flags/markings (sharp, seam, select, hidden, ect)
|
|
|
|
|
* 3: Unique ID in the bmesh.
|
|
|
|
|
* 4: some elements for internal record keeping.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*BMHeader->type*/
|
|
|
|
|
#define BM_VERT 1
|
|
|
|
|
#define BM_EDGE 2
|
|
|
|
|
#define BM_FACE 4
|
|
|
|
|
#define BM_LOOP 8
|
|
|
|
|
#define BM_ALL BM_VERT | BM_EDGE | BM_FACE | BM_LOOP
|
|
|
|
|
|
|
|
|
|
/*BMHeader->flag*/
|
|
|
|
|
#define BM_SELECT (1<<0)
|
|
|
|
|
|
|
|
|
|
#define BM_SEAM (1<<1)
|
|
|
|
|
#define BM_FGON (1<<2)
|
|
|
|
|
#define BM_HIDDEN (1<<3)
|
|
|
|
|
#define BM_SHARP (1<<4)
|
|
|
|
|
#define BM_SMOOTH (1<<5)
|
2009-03-09 09:52:32 +00:00
|
|
|
#define BM_ACTIVE (1<<6)
|
2009-03-12 03:55:53 +00:00
|
|
|
#define BM_NONORMCALC (1<<7)
|
2009-01-07 15:17:58 +00:00
|
|
|
|
|
|
|
|
typedef struct BMHeader {
|
|
|
|
|
struct BMHeader *next, *prev;
|
2009-02-15 00:47:19 +00:00
|
|
|
int EID; /*Consider removing this/making it ifdeffed for debugging*/
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*don't confuse this with tool flags. this flag
|
|
|
|
|
member is what "header flag" means.*/
|
|
|
|
|
int flag;
|
|
|
|
|
int type;
|
2009-02-15 00:47:19 +00:00
|
|
|
int eflag1, eflag2; /*Flags used by eulers. Try and get rid of/minimize some of these*/
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
//this can only be used to store a temporary index. don't use it for anything else.
|
|
|
|
|
int index;
|
2009-02-15 00:47:19 +00:00
|
|
|
struct BMFlagLayer *flags; /*Dynamically allocated block of flag layers for operators to use*/
|
2009-01-07 15:17:58 +00:00
|
|
|
} BMHeader;
|
|
|
|
|
|
|
|
|
|
typedef struct BMFlagLayer {
|
|
|
|
|
int f1;
|
|
|
|
|
short mask, pflag;
|
|
|
|
|
} BMFlagLayer;
|
|
|
|
|
|
|
|
|
|
#define BM_OVERLAP (1<<14) /*used by bmesh_verts_in_face*/
|
|
|
|
|
#define BM_EDGEVERT (1<<15) /*used by bmesh_make_ngon*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* BMNode
|
|
|
|
|
*
|
|
|
|
|
* Used for circular/linked list functions that form basis of
|
|
|
|
|
* adjacency system in BMesh. This should probably be hidden
|
|
|
|
|
* somewhere since tool authors never need to know about it.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef struct BMNode {
|
|
|
|
|
struct BMNode *next, *prev;
|
|
|
|
|
void *data;
|
|
|
|
|
} BMNode;
|
|
|
|
|
|
|
|
|
|
typedef struct BMesh {
|
|
|
|
|
ListBase verts, edges, polys;
|
|
|
|
|
struct BLI_mempool *vpool;
|
|
|
|
|
struct BLI_mempool *epool;
|
|
|
|
|
struct BLI_mempool *lpool;
|
|
|
|
|
struct BLI_mempool *ppool;
|
|
|
|
|
struct BMVert **vtar;
|
|
|
|
|
struct BMEdge **edar;
|
|
|
|
|
struct BMLoop **lpar;
|
|
|
|
|
struct BMFace **plar;
|
|
|
|
|
int vtarlen, edarlen, lparlen, plarlen;
|
|
|
|
|
int totvert, totedge, totface, totloop;
|
|
|
|
|
int nextv, nexte, nextp, nextl;
|
|
|
|
|
struct CustomData vdata, edata, pdata, ldata;
|
|
|
|
|
int selectmode;
|
|
|
|
|
struct BLI_mempool *flagpool; /*memory pool for dynamically allocated flag layers*/
|
|
|
|
|
int stackdepth; /*current depth of operator stack*/
|
|
|
|
|
int totflags, walkers; /*total number of tool flag layers*/
|
2009-01-22 13:59:30 +00:00
|
|
|
ListBase errorstack;
|
2009-01-07 15:17:58 +00:00
|
|
|
} BMesh;
|
|
|
|
|
|
|
|
|
|
typedef struct BMVert {
|
|
|
|
|
struct BMHeader head;
|
|
|
|
|
float co[3];
|
|
|
|
|
float no[3];
|
|
|
|
|
struct BMEdge *edge;
|
|
|
|
|
void *data;
|
|
|
|
|
void *tmp; /*what?*/
|
|
|
|
|
float bweight; /*please, someone just get rid of me...*/
|
|
|
|
|
} BMVert;
|
|
|
|
|
|
|
|
|
|
typedef struct BMEdge {
|
|
|
|
|
struct BMHeader head;
|
|
|
|
|
struct BMVert *v1, *v2;
|
|
|
|
|
struct BMNode d1, d2;
|
|
|
|
|
struct BMLoop *loop;
|
|
|
|
|
void *data;
|
2009-02-14 11:58:52 +00:00
|
|
|
float crease, bweight; /*make these custom data.... no really, please....*/
|
2009-01-07 15:17:58 +00:00
|
|
|
} BMEdge;
|
|
|
|
|
|
|
|
|
|
typedef struct BMLoop {
|
|
|
|
|
struct BMHeader head;
|
|
|
|
|
struct BMNode radial;
|
|
|
|
|
struct BMVert *v;
|
|
|
|
|
struct BMEdge *e;
|
|
|
|
|
struct BMFace *f;
|
|
|
|
|
void *data;
|
|
|
|
|
} BMLoop;
|
|
|
|
|
|
|
|
|
|
typedef struct BMFace {
|
|
|
|
|
struct BMHeader head;
|
|
|
|
|
struct BMLoop *loopbase;
|
2009-02-08 11:53:14 +00:00
|
|
|
int len;
|
2009-01-07 15:17:58 +00:00
|
|
|
void *data;
|
|
|
|
|
float no[3];
|
2009-02-08 11:53:14 +00:00
|
|
|
|
|
|
|
|
/*custom data again*/
|
|
|
|
|
short mat_nr;
|
2009-01-07 15:17:58 +00:00
|
|
|
} BMFace;
|
|
|
|
|
|
|
|
|
|
/*stub */
|
|
|
|
|
void bmesh_error(void);
|
|
|
|
|
|
|
|
|
|
/*Mesh Level Ops */
|
2009-01-19 04:05:15 +00:00
|
|
|
struct BMesh *BM_Make_Mesh(int allocsize[4]);
|
2009-05-16 16:18:08 +00:00
|
|
|
BMesh *BM_Copy_Mesh(BMesh *bmold);
|
2009-01-07 15:17:58 +00:00
|
|
|
void BM_Free_Mesh(struct BMesh *bm);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
/*frees mesh, but not actual BMesh struct*/
|
|
|
|
|
void BM_Free_Mesh_Data(BMesh *bm);
|
2009-01-07 15:17:58 +00:00
|
|
|
void BM_Compute_Normals(struct BMesh *bm);
|
|
|
|
|
|
|
|
|
|
/*Construction*/
|
|
|
|
|
struct BMVert *BM_Make_Vert(struct BMesh *bm, float co[3], struct BMVert *example);
|
|
|
|
|
struct BMEdge *BM_Make_Edge(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMEdge *example, int nodouble);
|
|
|
|
|
struct BMFace *BM_Make_Quadtriangle(struct BMesh *bm, struct BMVert **verts, BMEdge **edges, int len, struct BMFace *example, int nodouble);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*makes an ngon from an unordered list of edges. v1 and v2 must be the verts
|
|
|
|
|
defining edges[0], and define the winding of the new face.*/
|
2009-01-07 15:17:58 +00:00
|
|
|
struct BMFace *BM_Make_Ngon(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMEdge **edges, int len, int nodouble);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
/*stuff for dealing with header flags*/
|
|
|
|
|
#define BM_TestHFlag(ele, f) (((BMHeader*)ele)->flag & (f))
|
|
|
|
|
#define BM_SetHFlag(ele, f) (((BMHeader*)ele)->flag = ((BMHeader*)ele)->flag | (f))
|
|
|
|
|
#define BM_ClearHFlag(ele, f) (((BMHeader*)ele)->flag = ((BMHeader*)ele)->flag & ~(f))
|
|
|
|
|
|
|
|
|
|
/*stuff for setting indices*/
|
|
|
|
|
#define BMINDEX_SET(ele, i) (((BMHeader*)ele)->index = i)
|
|
|
|
|
#define BMINDEX_GET(ele) ((BMHeader*)ele)->index
|
2009-03-14 02:52:16 +00:00
|
|
|
|
2009-02-14 11:58:52 +00:00
|
|
|
/*copies loop data from adjacent faces*/
|
|
|
|
|
void BM_Face_CopyShared(BMesh *bm, BMFace *f);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*copies attributes, e.g. customdata, header flags, etc, from one element
|
|
|
|
|
to another of the same type.*/
|
2009-01-07 15:17:58 +00:00
|
|
|
void BM_Copy_Attributes(struct BMesh *source_mesh, struct BMesh *target_mesh, void *source, void *target);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*remove tool flagged elements*/
|
2009-01-07 15:17:58 +00:00
|
|
|
void BM_remove_tagged_faces(struct BMesh *bm, int flag);
|
|
|
|
|
void BM_remove_tagged_edges(struct BMesh *bm, int flag);
|
|
|
|
|
void BM_remove_tagged_verts(struct BMesh *bm, int flag);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*Modification*/
|
2009-03-14 02:52:16 +00:00
|
|
|
/*join two adjacent faces together along an edge. note that
|
|
|
|
|
the faces must only be joined by on edge. e is the edge you
|
|
|
|
|
wish to dissolve.*/
|
2009-03-13 13:11:50 +00:00
|
|
|
struct BMFace *BM_Join_Faces(struct BMesh *bm, struct BMFace *f1,
|
|
|
|
|
struct BMFace *f2, struct BMEdge *e);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*split a face along two vertices. returns the newly made face, and sets
|
|
|
|
|
the nl member to a loop in the newly created edge.*/
|
2009-03-13 13:11:50 +00:00
|
|
|
struct BMFace *BM_Split_Face(struct BMesh *bm, struct BMFace *f,
|
|
|
|
|
struct BMVert *v1, struct BMVert *v2,
|
|
|
|
|
struct BMLoop **nl, struct BMEdge *example);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*dissolves a vert shared only by two edges*/
|
2009-03-13 13:11:50 +00:00
|
|
|
void BM_Collapse_Vert(struct BMesh *bm, struct BMEdge *ke, struct BMVert *kv,
|
|
|
|
|
float fac);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*splits an edge. ne is set to the new edge created.*/
|
2009-03-13 13:11:50 +00:00
|
|
|
struct BMVert *BM_Split_Edge(struct BMesh *bm, struct BMVert *v,
|
|
|
|
|
struct BMEdge *e, struct BMEdge **ne,
|
|
|
|
|
float percent);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*split an edge multiple times evenly*/
|
2009-03-13 13:11:50 +00:00
|
|
|
struct BMVert *BM_Split_Edge_Multi(struct BMesh *bm, struct BMEdge *e,
|
|
|
|
|
int numcuts);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*connect two verts together, through a face they share. this function may
|
|
|
|
|
be removed in the future.*/
|
2009-01-07 15:17:58 +00:00
|
|
|
BMEdge *BM_Connect_Verts(BMesh *bm, BMVert *v1, BMVert *v2, BMFace **nf);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*updates a face normal*/
|
2009-03-12 03:55:53 +00:00
|
|
|
void BM_Face_UpdateNormal(BMesh *bm, BMFace *f);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*updates face and vertex normals incident on an edge*/
|
2009-03-12 03:55:53 +00:00
|
|
|
void BM_Edge_UpdateNormals(BMesh *bm, BMEdge *e);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*update a vert normal (but not the faces incident on it)*/
|
2009-03-12 03:55:53 +00:00
|
|
|
void BM_Vert_UpdateNormal(BMesh *bm, BMVert *v);
|
2009-03-01 06:23:22 +00:00
|
|
|
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*dissolves all faces around a vert, and removes it.*/
|
2009-03-01 06:23:22 +00:00
|
|
|
int BM_Dissolve_Disk(BMesh *bm, BMVert *v);
|
|
|
|
|
|
2009-03-14 02:52:16 +00:00
|
|
|
/*dissolves vert, in more situations then BM_Dissolve_Disk
|
|
|
|
|
(e.g. if the vert is part of a wire edge, etc).*/
|
2009-03-01 06:23:22 +00:00
|
|
|
int BM_Dissolve_Vert(BMesh *bm, BMVert *v);
|
2009-01-07 15:17:58 +00:00
|
|
|
|
2009-03-14 02:52:16 +00:00
|
|
|
|
2009-01-07 15:17:58 +00:00
|
|
|
/*Interpolation*/
|
|
|
|
|
void BM_Data_Interp_From_Verts(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, float fac);
|
|
|
|
|
void BM_Data_Facevert_Edgeinterp(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, struct BMEdge *e1, float fac);
|
|
|
|
|
//void bmesh_data_interp_from_face(struct BMesh *bm, struct BMFace *source, struct BMFace *target);
|
|
|
|
|
|
2009-05-18 08:46:04 +00:00
|
|
|
/*computes the centroid of a face, using the center of the bounding box*/
|
|
|
|
|
int BM_Compute_Face_Center(BMesh *bm, BMFace *f, float center[3]);
|
2009-05-18 10:29:37 +00:00
|
|
|
void BM_SelectMode_Flush(BMesh *bm);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*convert an editmesh to a bmesh*/
|
2009-01-19 04:05:15 +00:00
|
|
|
BMesh *editmesh_to_bmesh(struct EditMesh *em);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*initializes editmesh to bmesh operator, but doesn't execute.
|
|
|
|
|
this is used in situations where you need to get access to the
|
|
|
|
|
conversion operator's editmesh->bmesh mapping slot (e.g. if you
|
|
|
|
|
need to find the bmesh edge that corrusponds to a specific editmesh
|
|
|
|
|
edge).*/
|
2009-03-11 05:13:36 +00:00
|
|
|
BMesh *init_editmesh_to_bmesh(struct EditMesh *em, struct BMOperator *op);
|
2009-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
|
/*converts a bmesh to an editmesh*/
|
2009-01-07 15:17:58 +00:00
|
|
|
struct EditMesh *bmesh_to_editmesh(BMesh *bm);
|
|
|
|
|
|
|
|
|
|
/*include the rest of the API*/
|
|
|
|
|
#include "bmesh_filters.h"
|
|
|
|
|
#include "bmesh_iterators.h"
|
|
|
|
|
#include "bmesh_marking.h"
|
2009-03-09 10:38:36 +00:00
|
|
|
#include "bmesh_operator_api.h"
|
2009-01-07 15:17:58 +00:00
|
|
|
#include "bmesh_operators.h"
|
2009-03-09 10:38:36 +00:00
|
|
|
#include "bmesh_error.h"
|
2009-01-07 15:17:58 +00:00
|
|
|
#include "bmesh_queries.h"
|
2009-03-08 15:02:49 +00:00
|
|
|
#include "bmesh_walkers.h"
|
|
|
|
|
|
|
|
|
|
#endif /* BMESH_H */
|