~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/bmesh/operators/bmo_primitive.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
 * Contributor(s): Joseph Eagar.
 
19
 *
 
20
 * ***** END GPL LICENSE BLOCK *****
 
21
 */
 
22
 
 
23
/** \file blender/bmesh/operators/bmo_primitive.c
 
24
 *  \ingroup bmesh
 
25
 */
 
26
 
 
27
#include "MEM_guardedalloc.h"
 
28
 
 
29
#include "BLI_math.h"
 
30
 
 
31
#include "bmesh.h"
 
32
#include "intern/bmesh_private.h"
 
33
 
 
34
#include "intern/bmesh_operators_private.h" /* own include */
 
35
 
 
36
/* ************************ primitives ******************* */
 
37
 
 
38
static float icovert[12][3] = {
 
39
        {0.0f,0.0f,-200.0f},
 
40
        {144.72f, -105.144f,-89.443f},
 
41
        {-55.277f, -170.128,-89.443f},
 
42
        {-178.885f,0.0f,-89.443f},
 
43
        {-55.277f,170.128f,-89.443f},
 
44
        {144.72f,105.144f,-89.443f},
 
45
        {55.277f,-170.128f,89.443f},
 
46
        {-144.72f,-105.144f,89.443f},
 
47
        {-144.72f,105.144f,89.443f},
 
48
        {55.277f,170.128f,89.443f},
 
49
        {178.885f,0.0f,89.443f},
 
50
        {0.0f,0.0f,200.0f}
 
51
};
 
52
 
 
53
static short icoface[20][3] = {
 
54
        {0,1,2},
 
55
        {1,0,5},
 
56
        {0,2,3},
 
57
        {0,3,4},
 
58
        {0,4,5},
 
59
        {1,5,10},
 
60
        {2,1,6},
 
61
        {3,2,7},
 
62
        {4,3,8},
 
63
        {5,4,9},
 
64
        {1,10,6},
 
65
        {2,6,7},
 
66
        {3,7,8},
 
67
        {4,8,9},
 
68
        {5,9,10},
 
69
        {6,10,11},
 
70
        {7,6,11},
 
71
        {8,7,11},
 
72
        {9,8,11},
 
73
        {10,9,11}
 
74
};
 
75
 
 
76
/* HACK: these can also be found in cmoview.tga.c, but are here so that they can be found by linker
 
77
 * this hack is only used so that scons & mingw + split-sources hack works
 
78
 * ------------------------------- start copied code */
 
79
/* these are not the monkeys you are looking for */
 
80
static int monkeyo = 4;
 
81
static int monkeynv = 271;
 
82
static int monkeynf = 250;
 
83
static signed char monkeyv[271][3] = {
 
84
        {-71,21,98},{-63,12,88},{-57,7,74},{-82,-3,79},{-82,4,92},
 
85
        {-82,17,100},{-92,21,102},{-101,12,95},{-107,7,83},
 
86
        {-117,31,84},{-109,31,95},{-96,31,102},{-92,42,102},
 
87
        {-101,50,95},{-107,56,83},{-82,66,79},{-82,58,92},
 
88
        {-82,46,100},{-71,42,98},{-63,50,88},{-57,56,74},
 
89
        {-47,31,72},{-55,31,86},{-67,31,97},{-66,31,99},
 
90
        {-70,43,100},{-82,48,103},{-93,43,105},{-98,31,105},
 
91
        {-93,20,105},{-82,31,106},{-82,15,103},{-70,20,100},
 
92
        {-127,55,95},{-127,45,105},{-127,-87,94},{-127,-41,100},
 
93
        {-127,-24,102},{-127,-99,92},{-127,52,77},{-127,73,73},
 
94
        {-127,115,-70},{-127,72,-109},{-127,9,-106},{-127,-49,-45},
 
95
        {-101,-24,72},{-87,-56,73},{-82,-89,73},{-80,-114,68},
 
96
        {-85,-121,67},{-104,-124,71},{-127,-126,74},{-71,-18,68},
 
97
        {-46,-5,69},{-21,19,57},{-17,55,76},{-36,62,80},
 
98
        {-64,77,88},{-86,97,94},{-107,92,97},{-119,63,96},
 
99
        {-106,53,99},{-111,39,98},{-101,12,95},{-79,2,90},
 
100
        {-64,8,86},{-47,24,83},{-45,38,83},{-50,48,85},
 
101
        {-72,56,92},{-95,60,97},{-127,-98,94},{-113,-92,94},
 
102
        {-112,-107,91},{-119,-113,89},{-127,-114,88},{-127,-25,96},
 
103
        {-127,-18,95},{-114,-19,95},{-111,-29,96},{-116,-37,95},
 
104
        {-76,-6,86},{-48,7,80},{-34,26,77},{-32,48,84},
 
105
        {-39,53,93},{-71,70,102},{-87,82,107},{-101,79,109},
 
106
        {-114,55,108},{-111,-13,104},{-100,-57,91},{-95,-90,88},
 
107
        {-93,-105,85},{-97,-117,81},{-106,-119,81},{-127,-121,82},
 
108
        {-127,6,93},{-127,27,98},{-85,61,95},{-106,18,96},
 
109
        {-110,27,97},{-112,-88,94},{-117,-57,96},{-127,-57,96},
 
110
        {-127,-42,95},{-115,-35,100},{-110,-29,102},{-113,-17,100},
 
111
        {-122,-16,100},{-127,-26,106},{-121,-19,104},{-115,-20,104},
 
112
        {-113,-29,106},{-117,-32,103},{-127,-37,103},{-94,-40,71},
 
113
        {-106,-31,91},{-104,-40,91},{-97,-32,71},{-127,-112,88},
 
114
        {-121,-111,88},{-115,-105,91},{-115,-95,93},{-127,-100,84},
 
115
        {-115,-96,85},{-115,-104,82},{-121,-109,81},{-127,-110,81},
 
116
        {-105,28,100},{-103,20,99},{-84,55,97},{-92,54,99},
 
117
        {-73,51,99},{-55,45,89},{-52,37,88},{-53,25,87},
 
118
        {-66,13,92},{-79,8,95},{-98,14,100},{-104,38,100},
 
119
        {-100,48,100},{-97,46,97},{-102,38,97},{-96,16,97},
 
120
        {-79,11,93},{-68,15,90},{-57,27,86},{-56,36,86},
 
121
        {-59,43,87},{-74,50,96},{-91,51,98},{-84,52,96},
 
122
        {-101,22,96},{-102,29,96},{-113,59,78},{-102,85,79},
 
123
        {-84,88,76},{-65,71,71},{-40,58,63},{-25,52,59},
 
124
        {-28,21,48},{-50,0,53},{-71,-12,60},{-127,115,37},
 
125
        {-127,126,-10},{-127,-25,-86},{-127,-59,24},{-127,-125,59},
 
126
        {-127,-103,44},{-127,-73,41},{-127,-62,36},{-18,30,7},
 
127
        {-17,41,-6},{-28,34,-56},{-68,56,-90},{-33,-6,9},
 
128
        {-51,-16,-21},{-45,-1,-55},{-84,7,-85},{-97,-45,52},
 
129
        {-104,-53,33},{-90,-91,49},{-95,-64,50},{-85,-117,51},
 
130
        {-109,-97,47},{-111,-69,46},{-106,-121,56},{-99,-36,55},
 
131
        {-100,-29,60},{-101,-22,64},{-100,-50,21},{-89,-40,-34},
 
132
        {-83,-19,-69},{-69,111,-49},{-69,119,-9},{-69,109,30},
 
133
        {-68,67,55},{-34,52,43},{-46,58,36},{-45,90,7},
 
134
        {-25,72,16},{-25,79,-15},{-45,96,-25},{-45,87,-57},
 
135
        {-25,69,-46},{-48,42,-75},{-65,3,-70},{-22,42,-26},
 
136
        {-75,-22,19},{-72,-25,-27},{-13,52,-30},{-28,-18,-16},
 
137
        {6,-13,-42},{37,7,-55},{46,41,-54},{31,65,-54},
 
138
        {4,61,-40},{3,53,-37},{25,56,-50},{35,37,-52},
 
139
        {28,10,-52},{5,-5,-39},{-21,-9,-17},{-9,46,-28},
 
140
        {-6,39,-37},{-14,-3,-27},{6,0,-47},{25,12,-57},
 
141
        {31,32,-57},{23,46,-56},{4,44,-46},{-19,37,-27},
 
142
        {-20,22,-35},{-30,12,-35},{-22,11,-35},{-19,2,-35},
 
143
        {-23,-2,-35},{-34,0,-9},{-35,-3,-22},{-35,5,-24},
 
144
        {-25,26,-27},{-13,31,-34},{-13,30,-41},{-23,-2,-41},
 
145
        {-18,2,-41},{-21,10,-41},{-29,12,-41},{-19,22,-41},
 
146
        {6,42,-53},{25,44,-62},{34,31,-63},{28,11,-62},
 
147
        {7,0,-54},{-14,-2,-34},{-5,37,-44},{-13,14,-42},
 
148
        {-7,8,-43},{1,16,-47},{-4,22,-45},{3,30,-48},
 
149
        {8,24,-49},{15,27,-50},{12,35,-50},{4,56,-62},
 
150
        {33,60,-70},{48,38,-64},{41,7,-68},{6,-11,-63},
 
151
        {-26,-16,-42},{-17,49,-49},
 
152
};
 
153
 
 
154
static signed char monkeyf[250][4] = {
 
155
        {27,4,5,26}, {25,4,5,24}, {3,6,5,4}, {1,6,5,2}, {5,6,7,4},
 
156
        {3,6,7,2}, {5,8,7,6}, {3,8,7,4}, {7,8,9,6},
 
157
        {5,8,9,4}, {7,10,9,8}, {5,10,9,6}, {9,10,11,8},
 
158
        {7,10,11,6}, {9,12,11,10}, {7,12,11,8}, {11,6,13,12},
 
159
        {5,4,13,12}, {3,-2,13,12}, {-3,-4,13,12}, {-5,-10,13,12},
 
160
        {-11,-12,14,12}, {-13,-18,14,13}, {-19,4,5,13}, {10,12,4,4},
 
161
        {10,11,9,9}, {8,7,9,9}, {7,5,6,6}, {6,3,4,4},
 
162
        {5,1,2,2}, {4,-1,0,0}, {3,-3,-2,-2}, {22,67,68,23},
 
163
        {20,65,66,21}, {18,63,64,19}, {16,61,62,17}, {14,59,60,15},
 
164
        {12,19,48,57}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47},
 
165
        {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47},
 
166
        {18,19,48,47}, {18,-9,-8,47}, {18,27,45,46}, {26,55,43,44},
 
167
        {24,41,42,54}, {22,39,40,23}, {20,37,38,21}, {18,35,36,19},
 
168
        {16,33,34,17}, {14,31,32,15}, {12,39,30,13}, {11,48,45,38},
 
169
        {8,36,-19,9}, {8,-20,44,47}, {42,45,46,43}, {18,19,40,39},
 
170
        {16,17,38,37}, {14,15,36,35}, {32,44,43,33}, {12,33,32,42},
 
171
        {19,44,43,42}, {40,41,42,-27}, {8,9,39,-28}, {15,43,42,16},
 
172
        {13,43,42,14}, {11,43,42,12}, {9,-30,42,10}, {37,12,38,-32},
 
173
        {-33,37,45,46}, {-33,40,41,39}, {38,40,41,37}, {36,40,41,35},
 
174
        {34,40,41,33}, {36,39,38,37}, {35,40,39,38}, {1,2,14,21},
 
175
        {1,2,40,13}, {1,2,40,39}, {1,24,12,39}, {-34,36,38,11},
 
176
        {35,38,36,37}, {-37,8,35,37}, {-11,-12,-45,40}, {-11,-12,39,38},
 
177
        {-11,-12,37,36}, {-11,-12,35,34}, {33,34,40,41}, {33,34,38,39},
 
178
        {33,34,36,37}, {33,-52,34,35}, {33,37,36,34}, {33,35,34,34},
 
179
        {8,7,37,36}, {-32,7,35,46}, {-34,-33,45,46}, {4,-33,43,34},
 
180
        {-34,-33,41,42}, {-34,-33,39,40}, {-34,-33,37,38}, {-34,-33,35,36},
 
181
        {-34,-33,33,34}, {-34,-33,31,32}, {-34,-4,28,30}, {-5,-34,28,27},
 
182
        {-35,-44,36,27}, {26,35,36,45}, {24,25,44,45}, {25,23,44,42},
 
183
        {25,24,41,40}, {25,24,39,38}, {25,24,37,36}, {25,24,35,34},
 
184
        {25,24,33,32}, {25,24,31,30}, {15,24,29,38}, {25,24,27,26},
 
185
        {23,12,37,26}, {11,12,35,36}, {-86,-59,36,-80}, {-60,-61,36,35},
 
186
        {-62,-63,36,35}, {-64,-65,36,35}, {-66,-67,36,35}, {-68,-69,36,35},
 
187
        {-70,-71,36,35}, {-72,-73,36,35}, {-74,-75,36,35}, {42,43,53,58},
 
188
        {40,41,57,56}, {38,39,55,57}, {-81,-80,37,56}, {-83,-82,55,52},
 
189
        {-85,-84,51,49}, {-87,-86,48,49}, {47,50,51,48}, {46,48,51,49},
 
190
        {43,46,49,44}, {-92,-91,45,42}, {-23,49,50,-20}, {-94,40,48,-24},
 
191
        {-96,-22,48,49}, {-97,48,21,-90}, {-100,36,50,23}, {22,49,48,-100},
 
192
        {-101,47,46,22}, {21,45,35,25}, {33,34,44,41}, {13,14,28,24},
 
193
        {-107,26,30,-106}, {14,46,45,15}, {14,44,43,-110}, {-111,42,23,-110},
 
194
        {6,7,45,46}, {45,44,47,46}, {45,46,47,48}, {47,46,49,48},
 
195
        {17,49,47,48}, {17,36,46,48}, {35,36,44,45}, {35,36,40,43},
 
196
        {35,36,38,39}, {-4,-3,37,35}, {-123,34,33,1}, {-9,-8,-7,-6},
 
197
        {-10,-7,32,-125}, {-127,-11,-126,-126}, {-7,-6,5,31}, {4,5,33,30},
 
198
        {4,39,33,32}, {4,35,32,38}, {20,21,39,38}, {4,37,38,5},
 
199
        {-11,-10,36,3}, {-11,15,14,35}, {13,16,34,34}, {-13,14,13,13},
 
200
        {-3,1,30,29}, {-3,28,29,1}, {-2,31,28,-1}, {12,13,27,30},
 
201
        {-2,26,12,12}, {35,29,42,36}, {34,35,36,33}, {32,35,36,31},
 
202
        {30,35,36,29}, {28,35,36,27}, {26,35,36,25}, {34,39,38,35},
 
203
        {32,39,38,33}, {30,39,38,31}, {28,39,38,29}, {26,39,38,27},
 
204
        {25,31,32,38}, {-18,-17,45,44}, {-18,17,28,44}, {-24,-20,42,-23},
 
205
        {11,35,27,14}, {25,28,39,41}, {37,41,40,38}, {34,40,36,35},
 
206
        {32,40,39,33}, {30,39,31,40}, {21,29,39,22}, {-31,37,28,4},
 
207
        {-32,33,35,36}, {32,33,34,34}, {18,35,36,48}, {34,25,40,35},
 
208
        {24,25,38,39}, {24,25,36,37}, {24,25,34,35}, {24,25,32,33},
 
209
        {24,13,41,31}, {17,11,41,35}, {15,16,34,35}, {13,14,34,35},
 
210
        {11,12,34,35}, {9,10,34,35}, {7,8,34,35}, {26,25,37,36},
 
211
        {35,36,37,38}, {37,36,39,38}, {37,38,39,40}, {25,31,36,39},
 
212
        {18,34,35,30}, {17,22,30,33}, {19,29,21,20}, {16,26,29,17},
 
213
        {24,29,28,25}, {22,31,28,23}, {20,31,30,21}, {18,31,30,19},
 
214
        {16,30,17,17}, {-21,-22,35,34}, {-21,-22,33,32}, {-21,-22,31,30},
 
215
        {-21,-22,29,28}, {-21,-22,27,26}, {-28,-22,25,31}, {24,28,29,30},
 
216
        {23,24,26,27}, {23,24,25,25}, {-69,-35,-32,27}, {-70,26,25,-66},
 
217
        {-68,-67,24,-33},
 
218
};
 
219
 
 
220
#define VERT_MARK       1
 
221
 
 
222
#define EDGE_ORIG       1
 
223
#define EDGE_MARK       2
 
224
 
 
225
#define FACE_MARK       1
 
226
#define FACE_NEW        2
 
227
 
 
228
void bmo_create_grid_exec(BMesh *bm, BMOperator *op)
 
229
{
 
230
        BMOperator bmop, prevop;
 
231
        BMVert *eve, *preveve;
 
232
        BMEdge *e;
 
233
        float vec[3], mat[4][4], phi, phid, dia = BMO_slot_float_get(op, "size");
 
234
        int a, tot = BMO_slot_int_get(op, "xsegments"), seg = BMO_slot_int_get(op, "ysegments");
 
235
 
 
236
        if (tot < 2) tot = 2;
 
237
        if (seg < 2) seg = 2;
 
238
 
 
239
        BMO_slot_mat4_get(op, "mat", mat);
 
240
 
 
241
        /* one segment first: the X axis */
 
242
        phi = 1.0f;
 
243
        phid = 2.0f / ((float)tot - 1);
 
244
        for (a = 0; a < tot; a++) {
 
245
                vec[0] = dia * phi;
 
246
                vec[1] = -dia;
 
247
                vec[2] = 0.0f;
 
248
                mul_m4_v3(mat, vec);
 
249
 
 
250
                eve = BM_vert_create(bm, vec, NULL);
 
251
                BMO_elem_flag_enable(bm, eve, VERT_MARK);
 
252
 
 
253
                if (a != 0) {
 
254
                        e = BM_edge_create(bm, preveve, eve, NULL, TRUE);
 
255
                        BMO_elem_flag_enable(bm, e, EDGE_ORIG);
 
256
                }
 
257
 
 
258
                preveve = eve;
 
259
                phi -= phid;
 
260
        }
 
261
 
 
262
        /* extrude and translate */
 
263
        phid = 2.0f / ((float)seg - 1);
 
264
        vec[0] = vec[2] = 0.0f;
 
265
        vec[1] = dia * phid;
 
266
        mul_mat3_m4_v3(mat, vec);
 
267
 
 
268
        for (a = 0; a < seg - 1; a++) {
 
269
                if (a) {
 
270
                        BMO_op_initf(bm, &bmop, "extrude_edge_only edges=%s", &prevop, "geomout");
 
271
                        BMO_op_exec(bm, &bmop);
 
272
                        BMO_op_finish(bm, &prevop);
 
273
 
 
274
                        BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_VERT, VERT_MARK);
 
275
                }
 
276
                else {
 
277
                        BMO_op_initf(bm, &bmop, "extrude_edge_only edges=%fe", EDGE_ORIG);
 
278
                        BMO_op_exec(bm, &bmop);
 
279
                        BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_VERT, VERT_MARK);
 
280
                }
 
281
 
 
282
                BMO_op_callf(bm, "translate vec=%v verts=%s", vec, &bmop, "geomout");
 
283
                prevop = bmop;
 
284
        }
 
285
 
 
286
        if (a)
 
287
                BMO_op_finish(bm, &bmop);
 
288
 
 
289
        BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK);
 
290
}
 
291
 
 
292
void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op)
 
293
{
 
294
        BMOperator bmop, prevop;
 
295
        BMVert *eve, *preveve;
 
296
        BMEdge *e;
 
297
        BMIter iter;
 
298
        float vec[3], mat[4][4], cmat[3][3], phi, q[4];
 
299
        float phid, dia = BMO_slot_float_get(op, "diameter");
 
300
        int a, seg = BMO_slot_int_get(op, "segments"), tot = BMO_slot_int_get(op, "revolutions");
 
301
 
 
302
        BMO_slot_mat4_get(op, "mat", mat);
 
303
 
 
304
        phid = 2.0f * (float)M_PI / tot;
 
305
        /* phi = 0.25f * (float)M_PI; */ /* UNUSED */
 
306
 
 
307
        /* one segment first */
 
308
        phi = 0;
 
309
        phid /= 2;
 
310
        for (a = 0; a <= tot; a++) {
 
311
                /* Going in this direction, then edge extruding, makes normals face outward */
 
312
                vec[0] = -dia * sinf(phi);
 
313
                vec[1] = 0.0;
 
314
                vec[2] = dia * cosf(phi);
 
315
                eve = BM_vert_create(bm, vec, NULL);
 
316
                BMO_elem_flag_enable(bm, eve, VERT_MARK);
 
317
 
 
318
                if (a != 0) {
 
319
                        e = BM_edge_create(bm, preveve, eve, NULL, FALSE);
 
320
                        BMO_elem_flag_enable(bm, e, EDGE_ORIG);
 
321
                }
 
322
 
 
323
                phi += phid;
 
324
                preveve = eve;
 
325
        }
 
326
 
 
327
        /* extrude and rotate; negative phi to make normals face outward */
 
328
        phi = -M_PI / seg;
 
329
        q[0] = cosf(phi);
 
330
        q[3] = sinf(phi);
 
331
        q[1] = q[2] = 0.0f;
 
332
        quat_to_mat3(cmat, q);
 
333
 
 
334
        for (a = 0; a < seg; a++) {
 
335
                if (a) {
 
336
                        BMO_op_initf(bm, &bmop, "extrude_edge_only edges=%s", &prevop, "geomout");
 
337
                        BMO_op_exec(bm, &bmop);
 
338
                        BMO_op_finish(bm, &prevop);
 
339
                }
 
340
                else {
 
341
                        BMO_op_initf(bm, &bmop, "extrude_edge_only edges=%fe", EDGE_ORIG);
 
342
                        BMO_op_exec(bm, &bmop);
 
343
                }
 
344
 
 
345
                BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_VERT, VERT_MARK);
 
346
                BMO_op_callf(bm, "rotate cent=%v mat=%m3 verts=%s", vec, cmat, &bmop, "geomout");
 
347
                
 
348
                prevop = bmop;
 
349
        }
 
350
 
 
351
        if (a)
 
352
                BMO_op_finish(bm, &bmop);
 
353
 
 
354
        {
 
355
                float len, len2, vec2[3];
 
356
 
 
357
                len = 2 * dia * sinf(phid / 2.0f);
 
358
 
 
359
                /* length of one segment in shortest parallen */
 
360
                vec[0] = dia * sinf(phid);
 
361
                vec[1] = 0.0f;
 
362
                vec[2] = dia * cosf(phid);
 
363
 
 
364
                mul_v3_m3v3(vec2, cmat, vec);
 
365
                len2 = len_v3v3(vec, vec2);
 
366
 
 
367
                /* use shortest segment length divided by 3 as merge threshold */
 
368
                BMO_op_callf(bm, "removedoubles verts=%fv dist=%f", VERT_MARK, MIN2(len, len2) / 3.0f);
 
369
        }
 
370
 
 
371
        /* and now do imat */
 
372
        BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
 
373
                if (BMO_elem_flag_test(bm, eve, VERT_MARK)) {
 
374
                        mul_m4_v3(mat, eve->co);
 
375
                }
 
376
        }
 
377
 
 
378
        BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK);
 
379
}
 
380
 
 
381
void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op)
 
382
{
 
383
        BMVert *eva[12];
 
384
        BMVert *v;
 
385
        BMIter liter;
 
386
        BMIter viter;
 
387
        BMLoop *l;
 
388
        float vec[3], mat[4][4] /* , phi, phid */;
 
389
        float dia = BMO_slot_float_get(op, "diameter");
 
390
        int a, subdiv = BMO_slot_int_get(op, "subdivisions");
 
391
 
 
392
        BMO_slot_mat4_get(op, "mat", mat);
 
393
 
 
394
        /* phid = 2.0f * (float)M_PI / subdiv; */ /* UNUSED */
 
395
        /* phi = 0.25f * (float)M_PI; */         /* UNUSED */
 
396
 
 
397
        dia /= 200.0f;
 
398
        for (a = 0; a < 12; a++) {
 
399
                vec[0] = dia * icovert[a][0];
 
400
                vec[1] = dia * icovert[a][1];
 
401
                vec[2] = dia * icovert[a][2];
 
402
                eva[a] = BM_vert_create(bm, vec, NULL);
 
403
 
 
404
                BMO_elem_flag_enable(bm, eva[a], VERT_MARK);
 
405
        }
 
406
 
 
407
        for (a = 0; a < 20; a++) {
 
408
                BMFace *eftemp;
 
409
                BMVert *v1, *v2, *v3;
 
410
 
 
411
                v1 = eva[icoface[a][0]];
 
412
                v2 = eva[icoface[a][1]];
 
413
                v3 = eva[icoface[a][2]];
 
414
 
 
415
                eftemp = BM_face_create_quad_tri(bm, v1, v2, v3, NULL, NULL, FALSE);
 
416
                
 
417
                BM_ITER_ELEM (l, &liter, eftemp, BM_LOOPS_OF_FACE) {
 
418
                        BMO_elem_flag_enable(bm, l->e, EDGE_MARK);
 
419
                }
 
420
 
 
421
                BMO_elem_flag_enable(bm, eftemp, FACE_MARK);
 
422
        }
 
423
 
 
424
        dia *= 200.0f;
 
425
 
 
426
        if (subdiv > 1) {
 
427
                BMOperator bmop;
 
428
 
 
429
                BMO_op_initf(bm, &bmop,
 
430
                             "esubd edges=%fe "
 
431
                             "smooth=%f "
 
432
                             "numcuts=%i "
 
433
                             "use_gridfill=%b use_sphere=%b",
 
434
                             EDGE_MARK, dia, (1 << (subdiv-1)) - 1,
 
435
                             TRUE, TRUE);
 
436
 
 
437
                BMO_op_exec(bm, &bmop);
 
438
                BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_VERT, VERT_MARK);
 
439
                BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_EDGE, EDGE_MARK);
 
440
                BMO_op_finish(bm, &bmop);
 
441
        }
 
442
 
 
443
        /* must transform after because of sphere subdivision */
 
444
        BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) {
 
445
                if (BMO_elem_flag_test(bm, v, VERT_MARK)) {
 
446
                        mul_m4_v3(mat, v->co);
 
447
                }
 
448
        }
 
449
 
 
450
        BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK);
 
451
}
 
452
 
 
453
void bmo_create_monkey_exec(BMesh *bm, BMOperator *op)
 
454
{
 
455
        BMVert *eve;
 
456
        BMVert **tv = MEM_mallocN(sizeof(*tv) * monkeynv * 2, "tv");
 
457
        float mat[4][4];
 
458
        int i;
 
459
 
 
460
        BMO_slot_mat4_get(op, "mat", mat);
 
461
 
 
462
        for (i = 0; i < monkeynv; i++) {
 
463
                float v[3];
 
464
 
 
465
                v[0] = (monkeyv[i][0] + 127) / 128.0, v[1] = monkeyv[i][1] / 128.0, v[2] = monkeyv[i][2] / 128.0;
 
466
 
 
467
                tv[i] = BM_vert_create(bm, v, NULL);
 
468
                BMO_elem_flag_enable(bm, tv[i], VERT_MARK);
 
469
 
 
470
                tv[monkeynv + i] = (fabsf(v[0] = -v[0]) < 0.001f) ?
 
471
                            tv[i] :
 
472
                            (eve = BM_vert_create(bm, v, NULL), mul_m4_v3(mat, eve->co), eve);
 
473
 
 
474
                BMO_elem_flag_enable(bm, tv[monkeynv + i], VERT_MARK);
 
475
 
 
476
                mul_m4_v3(mat, tv[i]->co);
 
477
        }
 
478
 
 
479
        for (i = 0; i < monkeynf; i++) {
 
480
                BM_face_create_quad_tri(bm,
 
481
                                        tv[monkeyf[i][0] + i - monkeyo],
 
482
                                        tv[monkeyf[i][1] + i - monkeyo],
 
483
                                        tv[monkeyf[i][2] + i - monkeyo],
 
484
                                        (monkeyf[i][3] != monkeyf[i][2]) ? tv[monkeyf[i][3] + i - monkeyo] : NULL,
 
485
                                        NULL, FALSE);
 
486
 
 
487
                BM_face_create_quad_tri(bm,
 
488
                                        tv[monkeynv + monkeyf[i][2] + i - monkeyo],
 
489
                                        tv[monkeynv + monkeyf[i][1] + i - monkeyo],
 
490
                                        tv[monkeynv + monkeyf[i][0] + i - monkeyo],
 
491
                                        (monkeyf[i][3] != monkeyf[i][2]) ? tv[monkeynv + monkeyf[i][3] + i - monkeyo]: NULL,
 
492
                                        NULL, FALSE);
 
493
        }
 
494
 
 
495
        MEM_freeN(tv);
 
496
 
 
497
        BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK);
 
498
}
 
499
 
 
500
 
 
501
void bmo_create_circle_exec(BMesh *bm, BMOperator *op)
 
502
{
 
503
        BMVert *v1, *lastv1 = NULL, *cent1, *firstv1 = NULL;
 
504
        float vec[3], mat[4][4], phi, phid;
 
505
        float dia = BMO_slot_float_get(op, "diameter");
 
506
        int segs = BMO_slot_int_get(op, "segments");
 
507
        int cap_ends = BMO_slot_bool_get(op, "cap_ends");
 
508
        int cap_tris = BMO_slot_bool_get(op, "cap_tris");
 
509
        int a;
 
510
        
 
511
        if (!segs)
 
512
                return;
 
513
        
 
514
        BMO_slot_mat4_get(op, "mat", mat);
 
515
 
 
516
        phid = 2.0f * (float)M_PI / segs;
 
517
        phi = 0;
 
518
 
 
519
        if (cap_ends) {
 
520
                vec[0] = vec[1] = 0.0f;
 
521
                vec[2] = 0.0;
 
522
                mul_m4_v3(mat, vec);
 
523
                
 
524
                cent1 = BM_vert_create(bm, vec, NULL);
 
525
        }
 
526
 
 
527
        for (a = 0; a < segs; a++, phi += phid) {
 
528
                /* Going this way ends up with normal(s) upward */
 
529
                vec[0] = -dia * sinf(phi);
 
530
                vec[1] = dia * cosf(phi);
 
531
                vec[2] = 0.0f;
 
532
                mul_m4_v3(mat, vec);
 
533
                v1 = BM_vert_create(bm, vec, NULL);
 
534
 
 
535
                BMO_elem_flag_enable(bm, v1, VERT_MARK);
 
536
                
 
537
                if (lastv1)
 
538
                        BM_edge_create(bm, v1, lastv1, NULL, FALSE);
 
539
                
 
540
                if (a && cap_ends) {
 
541
                        BMFace *f;
 
542
                        
 
543
                        f = BM_face_create_quad_tri(bm, cent1, lastv1, v1, NULL, NULL, FALSE);
 
544
                        BMO_elem_flag_enable(bm, f, FACE_NEW);
 
545
                }
 
546
                
 
547
                if (!firstv1)
 
548
                        firstv1 = v1;
 
549
 
 
550
                lastv1 = v1;
 
551
        }
 
552
 
 
553
        if (!a)
 
554
                return;
 
555
 
 
556
        BM_edge_create(bm, lastv1, firstv1, NULL, FALSE);
 
557
 
 
558
        if (cap_ends) {
 
559
                BMFace *f;
 
560
                
 
561
                f = BM_face_create_quad_tri(bm, cent1, v1, firstv1, NULL, NULL, FALSE);
 
562
                BMO_elem_flag_enable(bm, f, FACE_NEW);
 
563
        }
 
564
        
 
565
        if (!cap_tris) {
 
566
                BMO_op_callf(bm, "dissolve_faces faces=%ff", FACE_NEW);
 
567
        }
 
568
        
 
569
        BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK);
 
570
}
 
571
 
 
572
void bmo_create_cone_exec(BMesh *bm, BMOperator *op)
 
573
{
 
574
        BMVert *v1, *v2, *lastv1 = NULL, *lastv2 = NULL, *cent1, *cent2, *firstv1, *firstv2;
 
575
        float vec[3], mat[4][4], phi, phid;
 
576
        float dia1 = BMO_slot_float_get(op, "diameter1");
 
577
        float dia2 = BMO_slot_float_get(op, "diameter2");
 
578
        float depth = BMO_slot_float_get(op, "depth");
 
579
        int segs = BMO_slot_int_get(op, "segments");
 
580
        int cap_ends = BMO_slot_bool_get(op, "cap_ends");
 
581
        int cap_tris = BMO_slot_bool_get(op, "cap_tris");
 
582
        int a;
 
583
        
 
584
        if (!segs)
 
585
                return;
 
586
        
 
587
        BMO_slot_mat4_get(op, "mat", mat);
 
588
 
 
589
        phid = 2.0f * (float)M_PI / segs;
 
590
        phi = 0;
 
591
 
 
592
        depth *= 0.5f;
 
593
        if (cap_ends) {
 
594
                vec[0] = vec[1] = 0.0f;
 
595
                vec[2] = -depth;
 
596
                mul_m4_v3(mat, vec);
 
597
                
 
598
                cent1 = BM_vert_create(bm, vec, NULL);
 
599
 
 
600
                vec[0] = vec[1] = 0.0f;
 
601
                vec[2] = depth;
 
602
                mul_m4_v3(mat, vec);
 
603
                
 
604
                cent2 = BM_vert_create(bm, vec, NULL);
 
605
 
 
606
                BMO_elem_flag_enable(bm, cent1, VERT_MARK);
 
607
                BMO_elem_flag_enable(bm, cent2, VERT_MARK);
 
608
        }
 
609
 
 
610
        for (a = 0; a < segs; a++, phi += phid) {
 
611
                vec[0] = dia1 * sinf(phi);
 
612
                vec[1] = dia1 * cosf(phi);
 
613
                vec[2] = -depth;
 
614
                mul_m4_v3(mat, vec);
 
615
                v1 = BM_vert_create(bm, vec, NULL);
 
616
 
 
617
                vec[0] = dia2 * sinf(phi);
 
618
                vec[1] = dia2 * cosf(phi);
 
619
                vec[2] = depth;
 
620
                mul_m4_v3(mat, vec);
 
621
                v2 = BM_vert_create(bm, vec, NULL);
 
622
 
 
623
                BMO_elem_flag_enable(bm, v1, VERT_MARK);
 
624
                BMO_elem_flag_enable(bm, v2, VERT_MARK);
 
625
 
 
626
                if (a) {
 
627
                        if (cap_ends) {
 
628
                                BMFace *f;
 
629
                                
 
630
                                f = BM_face_create_quad_tri(bm, cent1, lastv1, v1, NULL, NULL, FALSE);
 
631
                                BMO_elem_flag_enable(bm, f, FACE_NEW);
 
632
                                f = BM_face_create_quad_tri(bm, cent2, v2, lastv2, NULL, NULL, FALSE);
 
633
                                BMO_elem_flag_enable(bm, f, FACE_NEW);
 
634
                        }
 
635
                        BM_face_create_quad_tri(bm, lastv1, lastv2, v2, v1, NULL, FALSE);
 
636
                }
 
637
                else {
 
638
                        firstv1 = v1;
 
639
                        firstv2 = v2;
 
640
                }
 
641
 
 
642
                lastv1 = v1;
 
643
                lastv2 = v2;
 
644
        }
 
645
 
 
646
        if (!a)
 
647
                return;
 
648
 
 
649
        if (cap_ends) {
 
650
                BMFace *f;
 
651
                
 
652
                f = BM_face_create_quad_tri(bm, cent1, v1, firstv1, NULL, NULL, FALSE);
 
653
                BMO_elem_flag_enable(bm, f, FACE_NEW);
 
654
                f = BM_face_create_quad_tri(bm, cent2, firstv2, v2, NULL, NULL, FALSE);
 
655
                BMO_elem_flag_enable(bm, f, FACE_NEW);
 
656
        }
 
657
        
 
658
        if (!cap_tris) {
 
659
                BMO_op_callf(bm, "dissolve_faces faces=%ff", FACE_NEW);
 
660
        }
 
661
        
 
662
        BM_face_create_quad_tri(bm, v1, v2, firstv2, firstv1, NULL, FALSE);
 
663
 
 
664
        BMO_op_callf(bm, "removedoubles verts=%fv dist=%f", VERT_MARK, 0.000001);
 
665
        BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK);
 
666
}
 
667
 
 
668
void bmo_create_cube_exec(BMesh *bm, BMOperator *op)
 
669
{
 
670
        BMVert *v1, *v2, *v3, *v4, *v5, *v6, *v7, *v8;
 
671
        float vec[3], mat[4][4], off = BMO_slot_float_get(op, "size") / 2.0f;
 
672
 
 
673
        BMO_slot_mat4_get(op, "mat", mat);
 
674
 
 
675
        if (!off) off = 0.5f;
 
676
 
 
677
        vec[0] = -off;
 
678
        vec[1] = -off;
 
679
        vec[2] = -off;
 
680
        mul_m4_v3(mat, vec);
 
681
        v1 = BM_vert_create(bm, vec, NULL);
 
682
        BMO_elem_flag_enable(bm, v1, VERT_MARK);
 
683
 
 
684
        vec[0] = -off;
 
685
        vec[1] = off;
 
686
        vec[2] = -off;
 
687
        mul_m4_v3(mat, vec);
 
688
        v2 = BM_vert_create(bm, vec, NULL);
 
689
        BMO_elem_flag_enable(bm, v2, VERT_MARK);
 
690
 
 
691
        vec[0] = off;
 
692
        vec[1] = off;
 
693
        vec[2] = -off;
 
694
        mul_m4_v3(mat, vec);
 
695
        v3 = BM_vert_create(bm, vec, NULL);
 
696
        BMO_elem_flag_enable(bm, v3, VERT_MARK);
 
697
 
 
698
        vec[0] = off;
 
699
        vec[1] = -off;
 
700
        vec[2] = -off;
 
701
        mul_m4_v3(mat, vec);
 
702
        v4 = BM_vert_create(bm, vec, NULL);
 
703
        BMO_elem_flag_enable(bm, v4, VERT_MARK);
 
704
 
 
705
        vec[0] = -off;
 
706
        vec[1] = -off;
 
707
        vec[2] = off;
 
708
        mul_m4_v3(mat, vec);
 
709
        v5 = BM_vert_create(bm, vec, NULL);
 
710
        BMO_elem_flag_enable(bm, v5, VERT_MARK);
 
711
 
 
712
        vec[0] = -off;
 
713
        vec[1] = off;
 
714
        vec[2] = off;
 
715
        mul_m4_v3(mat, vec);
 
716
        v6 = BM_vert_create(bm, vec, NULL);
 
717
        BMO_elem_flag_enable(bm, v6, VERT_MARK);
 
718
 
 
719
        vec[0] = off;
 
720
        vec[1] = off;
 
721
        vec[2] = off;
 
722
        mul_m4_v3(mat, vec);
 
723
        v7 = BM_vert_create(bm, vec, NULL);
 
724
        BMO_elem_flag_enable(bm, v7, VERT_MARK);
 
725
 
 
726
        vec[0] = off;
 
727
        vec[1] = -off;
 
728
        vec[2] = off;
 
729
        mul_m4_v3(mat, vec);
 
730
        v8 = BM_vert_create(bm, vec, NULL);
 
731
        BMO_elem_flag_enable(bm, v8, VERT_MARK);
 
732
 
 
733
        /* the four sides */
 
734
        BM_face_create_quad_tri(bm, v5, v6, v2, v1, NULL, FALSE);
 
735
        BM_face_create_quad_tri(bm, v6, v7, v3, v2, NULL, FALSE);
 
736
        BM_face_create_quad_tri(bm, v7, v8, v4, v3, NULL, FALSE);
 
737
        BM_face_create_quad_tri(bm, v8, v5, v1, v4, NULL, FALSE);
 
738
        
 
739
        /* top/bottom */
 
740
        BM_face_create_quad_tri(bm, v1, v2, v3, v4, NULL, FALSE);
 
741
        BM_face_create_quad_tri(bm, v8, v7, v6, v5, NULL, FALSE);
 
742
 
 
743
        BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK);
 
744
}