[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11384] branches/soc-2007-red_fox/source/ blender: Edge crease values and vertex weights working in modifier.c
Levi Schooley
redfox at hhofministries.org
Fri Jul 27 06:01:03 CEST 2007
Revision: 11384
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11384
Author: red_fox
Date: 2007-07-27 06:01:03 +0200 (Fri, 27 Jul 2007)
Log Message:
-----------
Edge crease values and vertex weights working in modifier.c
Many, many changes. There was a lot of code rework done,
splitting things into functions and such. I separated
transform data from the topological operations, added
weighting to the initial pass, and refined quite a few things.
1. Math should be more accurate now.
2. Added options to modifier to
- bevel only verts
- use subsurf crease values to make beveled edges sharper;
three options: Min (use the sharpest edge when weighting a
vert), Average (average the weights of all edges meeting at
a vert), and Max (use the largest edge when weighting a vert)
- use vertex weights to define where and how much beveling
takes place at the verts
Still needs to be done:
1. Bevel by angle
2. Bevel by radius
3. Multi-resolution
4. Transfer edge and face flags correctly
5. Inset "clipping" and fix wrapping for concave polys
Levi
Modified Paths:
--------------
branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h
branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_conversions.c
branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c
branches/soc-2007-red_fox/source/blender/blenkernel/intern/modifier.c
branches/soc-2007-red_fox/source/blender/makesdna/DNA_modifier_types.h
branches/soc-2007-red_fox/source/blender/src/buttons_editing.c
branches/soc-2007-red_fox/source/blender/src/editmesh_tools.c
Modified: branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h
===================================================================
--- branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h 2007-07-27 03:59:22 UTC (rev 11383)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h 2007-07-27 04:01:03 UTC (rev 11384)
@@ -39,6 +39,7 @@
#include "DNA_listBase.h"
#include "BLI_ghash.h"
+#include "BLI_memarena.h"
#include "DNA_customdata_types.h"
#include "BLI_editVert.h"
#include "BKE_DerivedMesh.h"
@@ -180,8 +181,41 @@
/*TOOLS CODE*/
struct BME_Loop *BME_inset_edge(struct BME_Mesh *bm, struct BME_Loop *l, struct BME_Poly *f);
struct BME_Poly *BME_inset_poly(struct BME_Mesh *bm, struct BME_Poly *f);
-struct BME_Mesh *BME_bevel_mesh(struct BME_Mesh *bm, float value, int res, int options);
+/* bevel tool defines */
+/* element flags */
+#define BME_BEVEL_ORIG 1
+#define BME_BEVEL_BEVEL (1<<1)
+#define BME_BEVEL_NONMAN (1<<2)
+#define BME_BEVEL_WIRE (1<<3)
+
+/* tool options */
+#define BME_BEVEL_SELECT 1
+#define BME_BEVEL_VERT (1<<1)
+#define BME_BEVEL_RADIUS (1<<2)
+#define BME_BEVEL_ANGLE (1<<3)
+#define BME_BEVEL_EWEIGHT (1<<4)
+#define BME_BEVEL_VWEIGHT (1<<5)
+#define BME_BEVEL_PERCENT (1<<6)
+#define BME_BEVEL_EMIN (1<<7)
+#define BME_BEVEL_EMAX (1<<8)
+typedef struct BME_TransData {
+ BME_Mesh *bm; /* the bmesh the vert belongs to */
+ BME_Vert *v; /* pointer to the vert this tdata applies to */
+ float co[3]; /* the original coordinate */
+ float org[3]; /* the origin */
+ float vec[3]; /* a directional vector; always, always normalize! */
+ float weight; /* a scaling factor */
+ float factor; /* another scaling factor */
+} BME_TransData;
+
+typedef struct BME_TransData_Head {
+ GHash *gh; /* the hash structure for element lookup */
+ MemArena *ma; /* the memory "pool" we will be drawing individual elements from */
+} BME_TransData_Head;
+
+struct BME_Mesh *BME_bevel_mesh(struct BME_Mesh *bm, float value, int res, int options, int defgrp_index, BME_TransData_Head **rtd);
+
/*CONVERSION FUNCTIONS*/
struct BME_Mesh *BME_editmesh_to_bmesh(EditMesh *em, struct BME_Mesh *bm);
struct EditMesh *BME_bmesh_to_editmesh(struct BME_Mesh *bm);
Modified: branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_conversions.c
===================================================================
--- branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_conversions.c 2007-07-27 03:59:22 UTC (rev 11383)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_conversions.c 2007-07-27 04:01:03 UTC (rev 11384)
@@ -250,16 +250,14 @@
medge = dm->getEdgeArray(dm);
mface = dm->getFaceArray(dm);
- bm = BME_make_mesh();
- BME_model_begin(bm);
/*custom data*/
/* NOTE: I haven't tested whether or not custom data is being copied correctly */
CustomData_copy(&dm->vertData, &bm->vdata, CD_MASK_DERIVEDMESH,
- CD_CALLOC, totvert);
+ CD_CALLOC, 0);
CustomData_copy(&dm->edgeData, &bm->edata, CD_MASK_DERIVEDMESH,
- CD_CALLOC, totedge);
+ CD_CALLOC, 0);
CustomData_copy(&dm->faceData, &bm->pdata, CD_MASK_DERIVEDMESH,
- CD_CALLOC, totface);
+ CD_CALLOC, 0);
/*add verts*/
for(i=0,mv = mvert; i < totvert;i++,mv++){
v1 = BME_MV(bm,mv->co);
@@ -300,7 +298,6 @@
f->flag = mf->flag;
CustomData_to_em_block(&dm->faceData, &bm->pdata, i, &f->data);
}
- BME_model_end(bm);
BLI_edgehash_free(edge_hash, NULL);
return bm;
Modified: branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c
===================================================================
--- branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c 2007-07-27 03:59:22 UTC (rev 11383)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c 2007-07-27 04:01:03 UTC (rev 11384)
@@ -13,7 +13,7 @@
* 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.
+ * about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -47,11 +47,13 @@
#include "BLI_arithb.h"
#include "BLI_blenlib.h"
+#include "blendef.h"
+
/**
* BME_dissolve_edge
*
* Edge Dissolve Function:
- *
+ *
* Dissolves a 2-manifold edge by joining it's two faces. if
* they have opposite windings it first makes them consistent
* by calling BME_loop_reverse()
@@ -63,7 +65,7 @@
* BME_inset_edge
*
* Edge Inset Function:
- *
+ *
* Splits a face in two along an edge and returns the next loop
*
* Returns -
@@ -80,7 +82,7 @@
* BME_inset_poly
*
* Face Inset Tool:
- *
+ *
* Insets a single face and returns a pointer to the face at the
* center of the newly created region
*
@@ -92,13 +94,13 @@
#define MAX(a,b) (((a)>(b))?(a):(b))
BME_Poly *BME_inset_poly(BME_Mesh *bm,BME_Poly *f){
-
+
BME_Vert *v;
BME_Loop *l,*nextloop, *killoop, *sloop;
-
+
int len,i;
float max[3],min[3],cent[3]; //center of original face
-
+
/*get bounding box for face*/
VECCOPY(max,f->loopbase->v->co);
VECCOPY(min,f->loopbase->v->co);
@@ -107,18 +109,18 @@
max[0] = MAX(max[0],l->v->co[0]);
max[1] = MAX(max[1],l->v->co[1]);
max[2] = MAX(max[2],l->v->co[2]);
-
+
min[0] = MIN(min[0],l->v->co[0]);
min[1] = MIN(min[1],l->v->co[1]);
min[2] = MIN(min[2],l->v->co[2]);
}
-
- cent[0] = (min[0] + max[0]) / 2.0;
- cent[1] = (min[1] + max[1]) / 2.0;
- cent[2] = (min[2] + max[2]) / 2.0;
-
-
-
+
+ cent[0] = (min[0] + max[0]) / 2.0f;
+ cent[1] = (min[1] + max[1]) / 2.0f;
+ cent[2] = (min[2] + max[2]) / 2.0f;
+
+
+
/*inset each edge in the polygon.*/
len = f->len;
for(i=0,l=f->loopbase; i < len; i++){
@@ -126,14 +128,14 @@
f = BME_SFME(bm,l->f,l->v,l->next->v,NULL);
l=nextloop;
}
-
+
/*for each new edge, call SEMV on it*/
for(i=0,l=f->loopbase; i < len; i++, l=l->next){
l->tflag1 = 1; //going to store info that this loops edge still needs split
f = BME_SFME(bm,l->f,l->v,l->next->v,NULL);
l->tflag2 = l->v->tflag1 = l->v->tflag2 = 0;
}
-
+
len = f->len;
for(i=0,l=f->loopbase; i < len; i++){
if(l->tflag1){
@@ -144,7 +146,7 @@
l = l->next->next;
}
}
-
+
len = f->len;
sloop = NULL;
for(i=0,l=f->loopbase; i < len; i++,l=l->next){
@@ -162,85 +164,121 @@
l=nextloop;
}
}
-
+
len = f->len;
for(i=0,l=f->loopbase; i < len; i++,l=l->next){
- l->v->co[0] = (l->v->co[0] + cent[0]) / 2.0;
- l->v->co[1] = (l->v->co[1] + cent[1]) / 2.0;
- l->v->co[2] = (l->v->co[2] + cent[2]) / 2.0;
+ l->v->co[0] = (l->v->co[0] + cent[0]) / 2.0f;
+ l->v->co[1] = (l->v->co[1] + cent[1]) / 2.0f;
+ l->v->co[2] = (l->v->co[2] + cent[2]) / 2.0f;
}
return NULL;
}
/* ------- Bevel code starts here -------- */
-/* element flags */
-#define BME_BEVEL_ORIG 1
-#define BME_BEVEL_BEVEL (1<<1)
-#define BME_BEVEL_NONMAN (1<<2)
-/* tool options */
-#define BME_BEVEL_SELECT 1
-#define BME_BEVEL_VERT (1<<1)
-#define BME_BEVEL_RADIUS (1<<2)
-#define BME_BEVEL_ANGLE (1<<3)
-#define BME_BEVEL_EWEIGHT (1<<4)
-#define BME_BEVEL_VWEIGHT (1<<5)
-#define BME_BEVEL_PERCENT (1<<6)
+BME_TransData_Head *BME_init_transdata(int bufsize) {
+ BME_TransData_Head *td;
-/* this is just scratch area for now, until I decide exactly where this is headed */
-typedef struct BME_TransData {
- BME_Mesh *bm; /* the bmesh the vert belongs to */
- BME_Vert *v; /* pointer to the vert this tdata applies to */
- float org[3]; /* the origin */
- float vec[3]; /* a directional vector */
- float co[3]; /* the original coordinate */
- float factor; /* scaling factor */
-} BME_TransData;
+ td = MEM_callocN(sizeof(BME_TransData_Head), "BMesh transdata header");
+ td->gh = BLI_ghash_new(BLI_ghashutil_ptrhash,BLI_ghashutil_ptrcmp);
+ td->ma = BLI_memarena_new(bufsize);
+ BLI_memarena_use_calloc(td->ma);
-/* this is meant to help manage an array of bevel transform data */
-typedef struct BME_TransData_Head {
- BME_TransData *head; /* the start of the array */
- BME_TransData *nextfree; /* the next position available for use */
- GHash *gh; /* the hash structure for reverse element lookup */
- int len; /* the number of used elements */
- int size; /* the total possible number of elements */
-} BME_TransData_Head;
+ return td;
+}
-/*
+void BME_free_transdata(BME_TransData_Head *td) {
+ BLI_ghash_free(td->gh,NULL,NULL);
+ BLI_memarena_free(td->ma);
+ MEM_freeN(td);
+}
+
+BME_TransData *BME_assign_transdata(BME_TransData_Head *td, BME_Mesh *bm, BME_Vert *v,
+ float *co, float *org, float *vec, float weight, float factor) {
+ BME_TransData *vtd;
+ int is_new = 0;
+
+ if (v == NULL) return NULL;
+
+ if ((vtd = BLI_ghash_lookup(td->gh, v)) == NULL && bm != NULL) {
+ vtd = BLI_memarena_alloc(td->ma, sizeof(*vtd));
+ BLI_ghash_insert(td->gh, v, vtd);
+ is_new = 1;
+ }
+
+ if (co != NULL) VECCOPY(vtd->co,co);
+ if (org == NULL && is_new) { VECCOPY(vtd->org,v->co); } /* default */
+ else if (org != NULL) VECCOPY(vtd->org,org);
+ if (vec == NULL && is_new) {
+ VECCOPY(vtd->vec,v->no); /* default */
+ Normalize(vtd->vec);
+ }
+ else if (vec != NULL) {
+ VECCOPY(vtd->vec,vec);
+ Normalize(vtd->vec);
+ }
+
+ vtd->weight = weight;
+ vtd->factor = factor;
+
+ return vtd;
+}
+
BME_TransData *BME_get_transdata(BME_TransData_Head *td, BME_Vert *v) {
-
-}*/
+ BME_TransData *vtd;
+ vtd = BLI_ghash_lookup(td->gh, v);
+ return vtd;
+}
-/* copied this function from the old bevel tool temporarily */
-void bevel_displace_vec(float *midvec, float *v1, float *v2, float *v3, float d, float no[3])
-{
- float a[3], c[3], n_a[3], n_c[3], mid[3], ac, ac2, fac;
+float inset_corner_vec(float *vec, float *v1, float *v2, float *v3, float *no) {
+ float a[3], c[3], n_a[3], n_c[3], tno[3], ac, ac2, fac;
VecSubf(a, v1, v2);
VecSubf(c, v3, v2);
+ Normalize(a);
+ Normalize(c);
+ ac = Inpf(a, c);
- Crossf(n_a, a, no);
+ if (no == NULL) {
+ no = tno;
+ Crossf(tno, a, c);
+ }
+
+ Crossf(n_a, no, a);
+ Crossf(n_c, c, no);
Normalize(n_a);
- Crossf(n_c, no, c);
Normalize(n_c);
- Normalize(a);
- Normalize(c);
- ac = Inpf(a, c);
-
if (ac == 1 || ac == -1) {
- midvec[0] = midvec[1] = midvec[2] = 0;
- return;
+ vec[0] = vec[1] = vec[2] = 0;
+ return 0;
}
+
ac2 = ac * ac;
fac = (float)sqrt((ac2 + 2*ac + 1)/(1 - ac2) + 1);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list