~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/modifiers/intern/MOD_bevel.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
#include "BKE_cdderivedmesh.h"
40
40
#include "BKE_modifier.h"
41
 
#include "BKE_tessmesh.h"
42
41
#include "BKE_mesh.h"
43
 
 
44
42
#include "BKE_bmesh.h" /* only for defines */
45
43
 
 
44
#include "bmesh.h"
 
45
 
46
46
#include "DNA_object_types.h"
47
47
 
48
48
#include "MEM_guardedalloc.h"
50
50
 
51
51
static void initData(ModifierData *md)
52
52
{
53
 
        BevelModifierData *bmd = (BevelModifierData*) md;
 
53
        BevelModifierData *bmd = (BevelModifierData *) md;
54
54
 
55
55
        bmd->value = 0.1f;
56
56
        bmd->res = 1;
64
64
 
65
65
static void copyData(ModifierData *md, ModifierData *target)
66
66
{
67
 
        BevelModifierData *bmd = (BevelModifierData*) md;
68
 
        BevelModifierData *tbmd = (BevelModifierData*) target;
 
67
        BevelModifierData *bmd = (BevelModifierData *) md;
 
68
        BevelModifierData *tbmd = (BevelModifierData *) target;
69
69
 
70
70
        tbmd->value = bmd->value;
71
71
        tbmd->res = bmd->res;
88
88
        return dataMask;
89
89
}
90
90
 
91
 
#define EDGE_MARK       1
 
91
// #define USE_BM_BEVEL_OP_AS_MOD
92
92
 
93
93
#ifdef USE_BM_BEVEL_OP_AS_MOD
94
94
 
95
95
/* BMESH_TODO
96
96
 *
97
 
 * this bevel calls the operator which is missing many of the options
98
 
 * which the bevel modifier in trunk has.
 
97
 * this bevel calls the new bevel code (added since 2.64)
 
98
 * which is missing many of the options which the bevel modifier from 2.4x has.
99
99
 * - no vertex bevel
100
100
 * - no weight bevel
101
101
 *
102
102
 * These will need to be added to the bmesh operator.
103
 
 *       - campbell
104
 
 *
105
 
 * note: this code is very close to MOD_edgesplit.c.
106
 
 * note: if 0'd code from trunk included below.
 
103
 * - campbell
107
104
 */
108
105
static DerivedMesh *applyModifier(ModifierData *md, struct Object *UNUSED(ob),
109
106
                                  DerivedMesh *dm,
110
 
                                  int UNUSED(useRenderParams),
111
 
                                  int UNUSED(isFinalCalc))
 
107
                                  ModifierApplyFlag UNUSED(flag))
112
108
{
113
109
        DerivedMesh *result;
114
110
        BMesh *bm;
115
 
        BMEditMesh *em;
116
111
        BMIter iter;
117
112
        BMEdge *e;
118
 
        BevelModifierData *bmd = (BevelModifierData*) md;
119
 
        float threshold = cos((bmd->bevel_angle + 0.00001) * M_PI / 180.0);
120
 
 
121
 
        em = DM_to_editbmesh(dm, NULL, FALSE);
122
 
        bm = em->bm;
123
 
 
124
 
        BM_mesh_normals_update(bm, FALSE);
125
 
        BMO_push(bm, NULL);
 
113
        BevelModifierData *bmd = (BevelModifierData *) md;
 
114
        const float threshold = cosf((bmd->bevel_angle + 0.00001f) * (float)M_PI / 180.0f);
 
115
        const int segments = 16;  /* XXX */
 
116
 
 
117
        bm = DM_to_bmesh(dm);
126
118
 
127
119
        if (bmd->lim_flags & BME_BEVEL_ANGLE) {
128
120
                BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
129
121
                        /* check for 1 edge having 2 face users */
130
 
                        BMLoop *l1, *l2;
131
 
                        if ( (l1= e->l) &&
132
 
                             (l2= e->l->radial_next) != l1)
133
 
                        {
134
 
                                if (dot_v3v3(l1->f->no, l2->f->no) < threshold) {
135
 
                                        BMO_elem_flag_enable(bm, e, EDGE_MARK);
 
122
                        BMLoop *l_a, *l_b;
 
123
                        if (BM_edge_loop_pair(e, &l_a, &l_b)) {
 
124
                                if (dot_v3v3(l_a->f->no, l_b->f->no) < threshold) {
 
125
                                        BM_elem_flag_enable(e, BM_ELEM_TAG);
 
126
                                        BM_elem_flag_enable(e->v1, BM_ELEM_TAG);
 
127
                                        BM_elem_flag_enable(e->v2, BM_ELEM_TAG);
136
128
                                }
137
129
                        }
138
130
                }
140
132
        else {
141
133
                /* crummy, is there a way just to operator on all? - campbell */
142
134
                BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
143
 
                        BMO_elem_flag_enable(bm, e, EDGE_MARK);
 
135
                        if (BM_edge_is_manifold(e)) {
 
136
                                BM_elem_flag_enable(e, BM_ELEM_TAG);
 
137
                                BM_elem_flag_enable(e->v1, BM_ELEM_TAG);
 
138
                                BM_elem_flag_enable(e->v2, BM_ELEM_TAG);
 
139
                        }
144
140
                }
145
141
        }
146
142
 
147
 
        BMO_op_callf(bm, "bevel geom=%fe percent=%f use_even=%b use_dist=%b",
148
 
                     EDGE_MARK, bmd->value, (bmd->flags & BME_BEVEL_EVEN) != 0, (bmd->flags & BME_BEVEL_DIST) != 0);
149
 
        BMO_pop(bm);
150
 
 
151
 
        BLI_assert(em->looptris == NULL);
152
 
        result = CDDM_from_BMEditMesh(em, NULL, TRUE, FALSE);
153
 
        BMEdit_Free(em);
154
 
        MEM_freeN(em);
 
143
        BM_mesh_bevel(bm, bmd->value, segments, bmd->flags & BME_BEVEL_VERT);
 
144
 
 
145
        result = CDDM_from_bmesh(bm, TRUE);
 
146
 
 
147
        BLI_assert(bm->toolflagpool == NULL);  /* make sure we never alloc'd this */
 
148
        BM_mesh_free(bm);
 
149
 
 
150
        CDDM_calc_normals(result);
155
151
 
156
152
        return result;
157
153
}
160
156
#else /* from trunk, see note above */
161
157
 
162
158
static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
163
 
                                                DerivedMesh *derivedData,
164
 
                                                int UNUSED(useRenderParams),
165
 
                                                int UNUSED(isFinalCalc))
 
159
                                  DerivedMesh *derivedData,
 
160
                                  ModifierApplyFlag UNUSED(flag))
166
161
{
167
162
        DerivedMesh *result;
168
 
        BMEditMesh *em;
 
163
        BMesh *bm;
169
164
 
170
165
        /*bDeformGroup *def;*/
171
166
        int /*i,*/ options, defgrp_index = -1;
172
 
        BevelModifierData *bmd = (BevelModifierData*) md;
 
167
        BevelModifierData *bmd = (BevelModifierData *) md;
173
168
 
174
169
        options = bmd->flags | bmd->val_flags | bmd->lim_flags | bmd->e_flags;
175
170
 
176
171
#if 0
177
172
        if ((options & BME_BEVEL_VWEIGHT) && bmd->defgrp_name[0]) {
178
173
                defgrp_index = defgroup_name_index(ob, bmd->defgrp_name);
179
 
                if (defgrp_index < 0) {
 
174
                if (defgrp_index == -1) {
180
175
                        options &= ~BME_BEVEL_VWEIGHT;
181
176
                }
182
177
        }
183
178
#endif
184
179
 
185
 
        em = DM_to_editbmesh(derivedData, NULL, FALSE);
186
 
        BME_bevel(em, bmd->value, bmd->res, options, defgrp_index, DEG2RADF(bmd->bevel_angle), NULL, FALSE);
187
 
        BLI_assert(em->looptris == NULL);
188
 
        result = CDDM_from_BMEditMesh(em, NULL, TRUE, FALSE);
189
 
        BMEdit_Free(em);
190
 
        MEM_freeN(em);
 
180
        bm = DM_to_bmesh(derivedData);
 
181
        BME_bevel(bm, bmd->value, bmd->res, options, defgrp_index, DEG2RADF(bmd->bevel_angle), NULL);
 
182
        result = CDDM_from_bmesh(bm, TRUE);
 
183
        BM_mesh_free(bm);
191
184
 
192
185
        /* until we allow for dirty normal flag, always calc,
193
186
         * note: calculating on the CDDM is faster then the BMesh equivalent */
199
192
#endif
200
193
 
201
194
static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob,
202
 
                                                struct BMEditMesh *UNUSED(editData),
203
 
                                                DerivedMesh *derivedData)
 
195
                                    struct BMEditMesh *UNUSED(editData),
 
196
                                    DerivedMesh *derivedData)
204
197
{
205
 
        return applyModifier(md, ob, derivedData, 0, 1);
 
198
        return applyModifier(md, ob, derivedData, MOD_APPLY_USECACHE);
206
199
}
207
200
 
208
201
 
211
204
        /* structName */        "BevelModifierData",
212
205
        /* structSize */        sizeof(BevelModifierData),
213
206
        /* type */              eModifierTypeType_Constructive,
214
 
        /* flags */             eModifierTypeFlag_AcceptsMesh
215
 
                                                        | eModifierTypeFlag_SupportsEditmode
216
 
                                                        | eModifierTypeFlag_EnableInEditmode,
 
207
        /* flags */             eModifierTypeFlag_AcceptsMesh |
 
208
                                eModifierTypeFlag_SupportsEditmode |
 
209
                                eModifierTypeFlag_EnableInEditmode,
217
210
 
218
211
        /* copyData */          copyData,
219
212
        /* deformVerts */       NULL,
228
221
        /* isDisabled */        NULL,
229
222
        /* updateDepgraph */    NULL,
230
223
        /* dependsOnTime */     NULL,
231
 
        /* dependsOnNormals */  NULL,
 
224
        /* dependsOnNormals */  NULL,
232
225
        /* foreachObjectLink */ NULL,
233
226
        /* foreachIDLink */     NULL,
234
227
        /* foreachTexLink */    NULL,