~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/modifiers_bmesh.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * The Original Code is Copyright (C) 2005 by the Blender Foundation.
 
19
 * All rights reserved.
 
20
 *
 
21
 * Contributor(s): Joseph Eagar
 
22
 *
 
23
 * ***** END GPL LICENSE BLOCK *****
 
24
 *
 
25
 */
 
26
 
 
27
/** \file blender/blenkernel/intern/modifiers_bmesh.c
 
28
 *  \ingroup bke
 
29
 */
 
30
 
 
31
#include "BLI_math.h"
 
32
 
 
33
#include "MEM_guardedalloc.h"
 
34
 
 
35
#include "DNA_object_types.h"
 
36
 
 
37
#include "BLI_array.h"
 
38
 
 
39
#include "BKE_DerivedMesh.h"
 
40
#include "BKE_bmesh.h"
 
41
#include "BKE_tessmesh.h"
 
42
 
 
43
/* main function for copying DerivedMesh data into BMesh */
 
44
void DM_to_bmesh_ex(DerivedMesh *dm, BMesh *bm)
 
45
{
 
46
        MVert *mv, *mvert;
 
47
        MEdge *me, *medge;
 
48
        MPoly /* *mpoly, */ /* UNUSED */ *mp;
 
49
        MLoop *mloop, *ml;
 
50
        BMVert *v, **vtable, **verts = NULL;
 
51
        BMEdge *e, **etable, **edges = NULL;
 
52
        float has_face_normals;
 
53
        BMFace *f;
 
54
        BMIter liter;
 
55
        BLI_array_declare(verts);
 
56
        BLI_array_declare(edges);
 
57
        int i, j, k, totvert, totedge /* , totface */ /* UNUSED */ ;
 
58
 
 
59
        /*merge custom data layout*/
 
60
        CustomData_bmesh_merge(&dm->vertData, &bm->vdata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_VERT);
 
61
        CustomData_bmesh_merge(&dm->edgeData, &bm->edata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_EDGE);
 
62
        CustomData_bmesh_merge(&dm->loopData, &bm->ldata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_LOOP);
 
63
        CustomData_bmesh_merge(&dm->polyData, &bm->pdata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_FACE);
 
64
 
 
65
        totvert = dm->getNumVerts(dm);
 
66
        totedge = dm->getNumEdges(dm);
 
67
        /* totface = dm->getNumPolys(dm); */ /* UNUSED */
 
68
 
 
69
        /* add crease layer */
 
70
        BM_data_layer_add(bm, &bm->edata, CD_CREASE);
 
71
        /* add bevel weight layers */
 
72
        BM_data_layer_add(bm, &bm->edata, CD_BWEIGHT);
 
73
        BM_data_layer_add(bm, &bm->vdata, CD_BWEIGHT);
 
74
 
 
75
        vtable = MEM_callocN(sizeof(void**) * totvert, "vert table in BMDM_Copy");
 
76
        etable = MEM_callocN(sizeof(void**) * totedge, "edge table in BMDM_Copy");
 
77
 
 
78
        /*do verts*/
 
79
        mv = mvert = dm->dupVertArray(dm);
 
80
        for (i = 0; i < totvert; i++, mv++) {
 
81
                v = BM_vert_create(bm, mv->co, NULL);
 
82
                normal_short_to_float_v3(v->no, mv->no);
 
83
                v->head.hflag = BM_vert_flag_from_mflag(mv->flag);
 
84
 
 
85
                CustomData_to_bmesh_block(&dm->vertData, &bm->vdata, i, &v->head.data);
 
86
 
 
87
                /* add bevel weight */
 
88
                BM_elem_float_data_set(&bm->vdata, v, CD_BWEIGHT, (float)mv->bweight / 255.0f);
 
89
                vtable[i] = v;
 
90
        }
 
91
        MEM_freeN(mvert);
 
92
 
 
93
        /*do edges*/
 
94
        me = medge = dm->dupEdgeArray(dm);
 
95
        for (i = 0; i < totedge; i++, me++) {
 
96
                e = BM_edge_create(bm, vtable[me->v1], vtable[me->v2], NULL, FALSE);
 
97
 
 
98
                e->head.hflag = BM_edge_flag_from_mflag(me->flag);
 
99
 
 
100
                CustomData_to_bmesh_block(&dm->edgeData, &bm->edata, i, &e->head.data);
 
101
                etable[i] = e;
 
102
 
 
103
                /* add crease */
 
104
                BM_elem_float_data_set(&bm->edata, e, CD_CREASE, (float)me->crease / 255.0f);
 
105
                /* add bevel weight */
 
106
                BM_elem_float_data_set(&bm->edata, e, CD_BWEIGHT, (float)me->bweight / 255.0f);
 
107
        }
 
108
        MEM_freeN(medge);
 
109
 
 
110
        /*do faces*/
 
111
        mp = dm->getPolyArray(dm);
 
112
        mloop = dm->getLoopArray(dm);
 
113
        has_face_normals = CustomData_has_layer(&dm->polyData, CD_NORMAL);
 
114
        for (i = 0; i < dm->numPolyData; i++, mp++) {
 
115
                BMLoop *l;
 
116
 
 
117
                BLI_array_empty(verts);
 
118
                BLI_array_empty(edges);
 
119
 
 
120
                BLI_array_growitems(verts, mp->totloop);
 
121
                BLI_array_growitems(edges, mp->totloop);
 
122
 
 
123
                ml = mloop + mp->loopstart;
 
124
                for (j = 0; j < mp->totloop; j++, ml++) {
 
125
 
 
126
                        verts[j] = vtable[ml->v];
 
127
                        edges[j] = etable[ml->e];
 
128
                }
 
129
 
 
130
                f = BM_face_create_ngon(bm, verts[0], verts[1], edges, mp->totloop, FALSE);
 
131
 
 
132
                if (!f)
 
133
                        continue;
 
134
 
 
135
                f->head.hflag = BM_face_flag_from_mflag(mp->flag);
 
136
                f->mat_nr = mp->mat_nr;
 
137
 
 
138
                l = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, f);
 
139
 
 
140
                for (k = mp->loopstart; l; l = BM_iter_step(&liter), k++) {
 
141
                        CustomData_to_bmesh_block(&dm->loopData, &bm->ldata, k, &l->head.data);
 
142
                }
 
143
 
 
144
                CustomData_to_bmesh_block(&dm->polyData, &bm->pdata, i, &f->head.data);
 
145
 
 
146
                if (has_face_normals) {
 
147
                        float *fno;
 
148
 
 
149
                        fno = CustomData_bmesh_get(&bm->pdata, &f->head.data, CD_NORMAL);
 
150
                        copy_v3_v3(f->no, fno);
 
151
                }
 
152
        }
 
153
 
 
154
        MEM_freeN(vtable);
 
155
        MEM_freeN(etable);
 
156
 
 
157
        BLI_array_free(verts);
 
158
        BLI_array_free(edges);
 
159
}
 
160
 
 
161
/* converts a cddm to a BMEditMesh.  if existing is non-NULL, the
 
162
 * new geometry will be put in there.*/
 
163
BMEditMesh *DM_to_editbmesh(DerivedMesh *dm, BMEditMesh *existing, int do_tessellate)
 
164
{
 
165
        BMEditMesh *em = existing;
 
166
        BMesh *bm;
 
167
 
 
168
        if (em) {
 
169
                bm = em->bm;
 
170
        }
 
171
        else {
 
172
                bm = BM_mesh_create(&bm_mesh_allocsize_default);
 
173
        }
 
174
 
 
175
        DM_to_bmesh_ex(dm, bm);
 
176
 
 
177
        if (!em) {
 
178
                em = BMEdit_Create(bm, do_tessellate);
 
179
        }
 
180
        else {
 
181
                if (do_tessellate) {
 
182
                        BMEdit_RecalcTessellation(em);
 
183
                }
 
184
        }
 
185
 
 
186
        return em;
 
187
}
 
188
 
 
189
BMesh *DM_to_bmesh(DerivedMesh *dm)
 
190
{
 
191
        BMesh *bm;
 
192
 
 
193
        bm = BM_mesh_create(&bm_mesh_allocsize_default);
 
194
 
 
195
        DM_to_bmesh_ex(dm, bm);
 
196
 
 
197
        return bm;
 
198
}