-
Notifications
You must be signed in to change notification settings - Fork 0
/
3dmodeling_plant_compositae.cc
339 lines (322 loc) · 9.63 KB
/
3dmodeling_plant_compositae.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
3d modeling->plant->compositae
*/
// --------------------------------------------------------
// 菊花
// --------------------------------------------------------
void cm_flower2(vec o, vec v, vec n, real r0, real w)
{
binvnorm = true;
vec vside = v.cross(n); vside.norm();
vec lp;
int len = 6;
for (int i = 0; i < len; i++)
{
real ai = i / real(len);
real r = (r0 + r0 * rrnd(-0.25, 0.25));
vec p = o + v * r + vside * blend(-w / 2, w / 2, ai);
color = blendcor(0xFF00FFFF, 0xFF00A0FF, rrnd());
if (i > 0)
triang0(o, lp, p);
lp = p;
}
binvnorm = false;
}
void cm_flowerex2(vec o, vec v, vec n, real r0, real w)
{
binvnorm = true;
gverindfindstart = gsubmesh.vertices.size();
vec vside = v.cross(n); vside.norm();
vec lp, lpp, lpp1, lpp2;
int len = 2;
int wid = 8;
vec tn = n;
for (int i = 0; i < len; i++)
{
real ai = i / real(len);
real r = (r0 + r0 * blend2(-0.2, 0.2, ai, 2)) / 10;
tn = -tn;
vec p = o + v * r + vside * blend(-w / 2, w / 2, ai) + tn * (w / 18);
vec pp = p;
real tw =w / 4;
for(int j = 0; j <= wid; j ++)
{
real aj = j / real(wid);
real ww = tw * blend3(0.01, 1, aj, 0.7, 2);
pp += v * r + n * blend(-0.1, 0.1, aj);
vec vsd = vside * ww;
vec pp1 = pp - vsd;
vec pp2 = pp + vsd;
if (i > 0 && j > 0)
{
triang0(lpp1, lpp2, pp2);
triang0(lpp1, pp2, pp1);
}
lpp1 = pp1;
lpp2 = pp2;
lpp = pp;
}
//if (i > 0)
//triang(o, lp, p);
lp = p;
}
binvnorm = false;
}
void cm_leave2(vec o, vec v, vec n, real len, real w)
{
real t = blend(0.1, 1, gtimealpha);
color = blendcor(RGB(10, 50, 0), 0xFF00A000, rrnd(0, 1));
gcommonvertex = 1;
vec vside = v.cross(n); vside.norm();
vec p1 = o - vside * (w / 32);
vec p2 = o + vside * (w / 32);
real h = w / 200;
VECLIST e;
e.push_back(p1 + n * h);
e.push_back(p1);
e.push_back(p2);
e.push_back(p2 + n * h);
e.push_back(o);
// closeedge(e);
VECLIST le = e;
real step = w / 4;
int cnt = 4;
for (int i = 0; i < cnt; i++)
{
real ai = i / real(cnt);
static real scales[] = { 1, 5, 0.9, 0.4 };
extrudeedge(e, step * 0.75);
scaleedge(e, scales[i]);
rotedge(e, rrnd(-PI / 8, PI / 8), vside);
{
int cor0 = color;
//face(le, e);
for (int ii = 0; ii < le.size() - 1; ii++)
{
//color = ii > 2 ? 0xFFA0FFA0 : cor0;
plane(le[ii], le[ii + 1], e[ii + 1], e[ii]);
}
color = cor0;
}
if (i > 1 && t > 0.8)
{
real step2 = step / 4;
static real scales2[] = { 1, 1.5, 1.2, 1.1, 0.1 };
int cnt2 = 5 * t;
if (i == cnt - 1)
{
VECLIST ee = e;
for (int ii = 0; ii < cnt2; ii++)
{
extrudeedgeex(ee, step2 * 1.5, scales2[ii] * 1.2);
}
}
{
{// left
VECLIST ee;
ee.push_back(le[0]); ee.push_back(le[1]);
ee.push_back(e[1]); ee.push_back(e[0]);
closeedge(ee);
extrudeedgeex(ee, step2 / 2, 0.75);
for (int ii = 0; ii < cnt2; ii++)
{
extrudeedgeex(ee, step2, scales2[ii]);
}
}
{// right
VECLIST ee;
ee.push_back(le[2]); ee.push_back(le[3]);
ee.push_back(e[3]); ee.push_back(e[2]);
closeedge(ee);
extrudeedgeex(ee, step2 / 2, 0.75);
for (int ii = 0; ii < cnt2; ii++)
{
extrudeedgeex(ee, step2, scales2[ii]);
}
}
}
}
le = e;
}
// gcommonvertex = 0;
}
void chrysanthemum(vec o, real sz, real fw1, real fw2, int n0, int color0, int len0)
{
color = 0xFFFFFFFF;
real t = blend(0.1, 1, gtimealpha);
vec p = o;
VECLIST e;
real s = sz / 120 * t;
int len = len0;//blend(4, len0, t);
vec v0 = vec::UY;
real dpdeta = rrnd(0, 172.862);
real dpdeta2 = rrnd(0, 172.862);
for (int i = 0; i <= len; i++)
{
real ai = real(i) / (len);
vec np;
{
vec dp = vec::UX * ((perlin(p.x * 10, p.y * 10 + dpdeta2, p.z * 10 + dpdeta))) + vec::UZ * ((perlin(p.x * 10 + dpdeta2, p.y * 10 + dpdeta, p.z * 10)));
np = p + (v0 + dp - vec::UY * 0.1) * (s * blend(1.8, 10, ai, 4));
}
VECLIST e1;
if (i == 0)
{// µ◊≤ø
color = 0xFF00FFAA;
roundedge(e1, p, vec::UY, s, 8,0);
}
else if (i < len)
{// …ÌÃÂ
color = 0xFF00A080;
real dlen = (np - p).len();
vec gv = (np - p).normcopy();
{
moveedge(e, gv * (dlen), e1);
scaleedge(e1, 0.995);
}
//if(i > len * 0.1 && i < len * 0.75 && rrnd() < 0.5)
//{// leave
// cm_leave(p, blend(gv, vec::UX, 0.5).rotcopy(rrnd(-PI, PI), gv), vec::UY, sz * 2 * t, sz * 0.5 * t);
// color = 0xFFFFFFFF;
//}
color = 0xFF00A080;
}
else if(t > 0.5)
{
vec up = (np - p).normcopy();
vec vx, vy;
v2vxvy(up, vx, vy);
vec forward = blend(vx, vy, rrnd());
forward = blend(forward.rotcopy(rrnd(-PI, PI), up), up, rrnd(0.4, 0.6)).normcopy();
v2vxvy(forward, vx, vy);
//
real rr = s * 10 * fw1 / 2;
VECLIST ee = e;
moveedge(ee, forward * (s * 2));
scaleedge(ee, 10 * fw1);
rotedgebynorm(ee, forward);
face(e, ee);
color = 0xFF004080;
if (t > 0.8)
{
color = 0xFF0080FF;
extrudeedgeex(ee, s / 2, 0.9);
scaleedgeex(ee, 0.8);
extrudeedgeex(ee, -s / 2, 0.9);
color = 0xFF0080A0;
}
face(ee, p);
//int red = rrnd(0, 255);
//color = blendcor(0xFFFFFFFF, RGB(red, rrnd(0, red), rrnd(0, 255)), rrnd());
//color = color0;
real bansz = s * 500 * fw2;
int n = 4 + n0 * blend(0.25, 1, t) - 1;
for (int i = 0; i < n; i++)
{// flower
real ang = rrnd(-0.01, 0.01) * PI + i / real(n) * 2 * PI;
vec vv = vx * cos(ang) + vy * sin(ang);
vec fp = p + vv * (rr * t);
color = blendcor(color0, RGB(rrnd(0, 255), rrnd(0, 255), rrnd(0, 255)), rrnd(0, 0.2));
cm_flowerex2(fp, blend(vv, forward, rrnd(0, 0.5)), forward, bansz * sz / 5 * t, bansz * sz / 12 * t);
}
color = 0xFF004080;
}
gcommonvertex = 1;
if (i != 0)
face(e, e1);
gcommonvertex = 0;
e = e1;
p = np;
}
}
// -------------------------------------------------------------
// 八角金盘
// -------------------------------------------------------------
void fatsia_leave(vec o, vec v, vec n, real len, real w, int color0)
{
real t = blend(0.1, 1, gtimealpha);
color = color0;
gcommonvertex = 1;
vec vside = v.cross(n); vside.norm();
vec p1 = o - vside * (w / 32);
vec p2 = o + vside * (w / 32);
real h = w / 200;
real tk = h / 2.5;
VECLIST e;
e.push_back(o - vside * (w / 180));
e.push_back(p1 + n * h);
e.push_back(o - n * tk);
e.push_back(p2 + n * h);
e.push_back(o + vside * (w / 180));
closeedge(e);
VECLIST le = e;
real step = w / 4;
int cnt = 8;
for (int i = 0; i < cnt; i++)
{
real ai = i / real(cnt);
static real scales[] = { 1.5, 2, 1.5, 1.25, 1.0, 0.75, 0.5, 0.1 };
extrudeedge(e, step * 0.75);
scaleedge(e, scales[i]);
rotedge(e, rrnd(-PI / 18, PI / 8), vside);
{
int cor0 = color;
for (int ii = 0; ii < le.size() - 1; ii++)
{
plane(le[ii], le[ii + 1], e[ii + 1], e[ii]);
}
color = cor0;
}
le = e;
}
gcommonvertex = 0;
}
// -------------------------------------------------------------
void fatsia(vec o, vec v0, real s, int color0, real leafsz, int nl)
{
DEF_SCALES2(s);
VECLIST e;
v0.norm();
vec p = o;
vec dv = v0;
real dpdeta = rrnd(0, 172.862);
real dpdeta2 = rrnd(0, 172.862);
int len = lotus1_n;
for (int i = 0; i <= len; i++)
{
real ai = real(i) / (len);
real t = blend(0.0, 1, ai);
vec dp = vec::UX * ((perlin(p.x * 10, p.y * 10 + dpdeta2, p.z * 10 + dpdeta))) + vec::UZ * ((perlin(p.x * 10 + dpdeta2, p.y * 10 + dpdeta, p.z * 10)));
vec np = p + (v0 + dp) * (USIZE * 20);
{
color = blendcor(0xFF102000, color0, ai, 2);
VECLIST e1;
if (i == 0)
{//
roundedge(e1, p, vec::UY, s, 8);
}
else
{//
dv = np - p;
moveedge(e, dv, e1);
}
if (i != 0)
face(e, e1);
e = e1;
}
p = np;
}
{//
vec v = dv.normcopy();
vec vx, vy;
v2vxvy(v, vy, vx);
int nn = nl;
for (int ii = 0; ii < nn; ii++)
{
real aii = ii / MAX(8, real(nn));
real scl = 5 * leafsz;
fatsia_leave(getedgecenter(e), vx.rotcopy(blend(0, 2 * PI, aii), v), v, s * 20 * scl, s * 5 * scl, color0);
}
}
color = 0xFFFFFFFF;
}