aboutsummaryrefslogtreecommitdiff
path: root/advtrains/models/advtrains_dtrack_vst2_45.obj
blob: 5dc708b78c4ec755c85eaefdb2ef67b413e8f688 (plain)
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# Blender v2.78 (sub 0) OBJ File: 'rail_redo.blend'
# www.blender.org
o dtrack_vst2_45_Cube.035
v 0.111416 0.278660 0.354093
v 0.111416 0.442721 0.354093
v 0.354093 0.157340 0.111416
v 0.354093 0.321400 0.111416
v 0.205542 0.278660 0.448220
v 0.205542 0.442721 0.448220
v 0.448220 0.157340 0.205543
v 0.448220 0.321400 0.205543
v -0.208358 0.539814 0.791422
v 0.791423 0.040000 -0.208357
v 0.896243 0.040000 -0.103536
v -0.103538 0.539814 0.896242
v -0.164683 0.559814 0.835097
v 0.835098 0.060000 -0.164682
v 0.852568 0.060000 -0.147212
v -0.147213 0.559814 0.852567
v -0.164683 0.609814 0.835097
v 0.835098 0.110000 -0.164682
v 0.852568 0.110000 -0.147212
v -0.147213 0.609814 0.852567
v 0.874406 0.115000 -0.125374
v -0.125375 0.614814 0.874405
v -0.186520 0.614814 0.813259
v 0.813260 0.115000 -0.186519
v 0.874406 0.140000 -0.125374
v -0.125375 0.639814 0.874405
v -0.186520 0.639814 0.813259
v 0.813260 0.140000 -0.186519
v 0.476117 0.313896 0.572089
v -0.572088 0.313896 -0.476117
v -0.656942 0.356316 -0.391265
v 0.391264 0.356316 0.656941
v 0.476117 0.263896 0.572089
v -0.572088 0.263896 -0.476117
v -0.656941 0.306316 -0.391265
v 0.391264 0.306316 0.656942
v -0.508186 3.379001 0.491594
v 0.491594 2.879186 -0.508186
v -0.508186 3.400629 0.491593
v 0.491594 2.900814 -0.508186
v 0.508186 2.879186 -0.491594
v -0.491594 3.379001 0.508186
v 0.508186 2.900814 -0.491594
v -0.491594 3.400629 0.508186
v 0.208358 0.040000 -0.791421
v -0.791423 0.539814 0.208357
v -0.896244 0.539814 0.103537
v 0.103537 0.040000 -0.896242
v 0.164682 0.060000 -0.835097
v -0.835099 0.559815 0.164682
v -0.852568 0.559814 0.147212
v 0.147212 0.060000 -0.852567
v 0.164682 0.110000 -0.835097
v -0.835099 0.609815 0.164682
v -0.852568 0.609814 0.147212
v 0.147212 0.110000 -0.852567
v -0.874406 0.614814 0.125374
v 0.125375 0.115000 -0.874404
v 0.186520 0.115000 -0.813259
v -0.813261 0.614815 0.186520
v -0.874406 0.639814 0.125374
v 0.125375 0.140000 -0.874404
v 0.186520 0.140000 -0.813259
v -0.813261 0.639814 0.186520
v -0.230055 0.092905 -0.818151
v 0.818151 0.092905 0.230055
v 0.733298 0.135325 0.314908
v -0.314908 0.135325 -0.733299
v -0.230055 0.142905 -0.818151
v 0.818151 0.142905 0.230056
v 0.733298 0.185325 0.314908
v -0.314908 0.185325 -0.733298
v 0.314908 0.394489 0.733298
v -0.733298 0.394489 -0.314908
v -0.818151 0.436909 -0.230056
v 0.230055 0.436909 0.818151
v 0.314908 0.344489 0.733298
v -0.733298 0.344489 -0.314908
v -0.818151 0.386909 -0.230055
v 0.230055 0.386909 0.818151
v -0.391264 0.173498 -0.656942
v 0.656941 0.173498 0.391265
v 0.572089 0.215918 0.476118
v -0.476117 0.215918 -0.572089
v -0.391264 0.223498 -0.656941
v 0.656942 0.223498 0.391265
v 0.572088 0.265918 0.476117
v -0.476117 0.265918 -0.572089
v -0.354093 0.278660 -0.111416
v -0.354093 0.442721 -0.111416
v -0.111416 0.157340 -0.354093
v -0.111416 0.321400 -0.354093
v -0.448220 0.278660 -0.205543
v -0.448220 0.442721 -0.205543
v -0.205543 0.157340 -0.448220
v -0.205543 0.321400 -0.448220
v -0.069408 0.012594 -0.978798
v 0.978798 0.012594 0.069409
v 0.893945 0.055014 0.154261
v -0.154261 0.055014 -0.893945
v -0.069408 0.062594 -0.978798
v 0.978798 0.062594 0.069409
v 0.893945 0.105014 0.154261
v -0.154261 0.105014 -0.893945
v 0.069408 0.467220 0.978798
v -0.978798 0.467220 -0.069409
v -0.893945 0.424800 -0.154261
v 0.154261 0.424800 0.893945
v 0.069408 0.517220 0.978797
v -0.978798 0.517220 -0.069409
v -0.893945 0.474800 -0.154261
v 0.154261 0.474800 0.893945
v -0.029561 -0.000000 -1.029558
v 1.029558 0.000000 0.029561
v -1.029558 -0.000000 -0.029561
v -1.029558 0.500000 -0.029561
v 0.029561 0.000000 1.029558
v 0.029561 0.500000 1.029558
v -0.500000 0.500000 1.559119
v -1.559119 0.500000 0.500000
v -0.499999 0.500000 0.499999
v -1.559120 -0.000000 0.500000
v -0.500000 0.000000 1.559119
v -0.500003 0.000000 0.500000
v 1.029558 -0.500000 0.029561
v -0.029561 -0.500000 -1.029558
v 0.029561 -0.500000 1.029558
v -1.029558 -0.500000 -0.029561
v -0.500003 -0.500000 0.500000
v -0.500000 -0.500000 1.559119
v -1.559120 -0.500000 0.500000
vt 0.7427 0.1169
vt 0.7427 0.3317
vt 0.6400 0.3317
vt 0.6400 0.1169
vt 0.8260 0.3317
vt 0.8260 0.4343
vt 0.7427 0.4343
vt 0.8260 0.1169
vt 0.7427 0.0142
vt 0.8260 0.0142
vt 0.5691 0.2971
vt 0.5691 0.9229
vt 0.5378 0.9229
vt 0.5378 0.2971
vt 0.3413 0.2971
vt 0.3819 0.2971
vt 0.3819 0.9229
vt 0.3413 0.9229
vt 0.4291 0.9855
vt 0.4678 0.9730
vt 0.4833 0.9730
vt 0.5219 0.9855
vt 0.6097 0.9229
vt 0.6097 0.2971
vt 0.4678 0.2470
vt 0.4291 0.2345
vt 0.5219 0.2345
vt 0.4833 0.2470
vt 0.4833 0.2783
vt 0.4678 0.2783
vt 0.4132 0.2971
vt 0.4132 0.9229
vt 0.4678 0.9417
vt 0.4833 0.9417
vt 0.5182 0.9229
vt 0.5182 0.2971
vt 0.4328 0.2971
vt 0.4328 0.9229
vt 0.5026 0.9229
vt 0.5026 0.2971
vt 0.4485 0.2971
vt 0.4485 0.9229
vt 0.5026 0.2814
vt 0.4485 0.2814
vt 0.4485 0.9386
vt 0.5026 0.9386
vt 0.9588 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt 0.8837 0.9625
vt 0.8524 0.0348
vt 0.8837 0.0348
vt 0.8524 0.9625
vt 0.9588 0.0035
vt 0.9588 0.0348
vt 0.8837 0.0035
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.6554 0.3627
vt 0.6690 0.3627
vt 0.6690 0.9885
vt 0.6554 0.9885
vt 0.6972 0.9885
vt 0.6837 0.9885
vt 0.6837 0.3627
vt 0.6972 0.3627
vt 0.7119 0.3627
vt 0.7119 0.9885
vt 0.5691 0.2971
vt 0.5691 0.9229
vt 0.5378 0.9229
vt 0.5378 0.2971
vt 0.3413 0.2971
vt 0.3819 0.2971
vt 0.3819 0.9229
vt 0.3413 0.9229
vt 0.4291 0.9855
vt 0.4678 0.9730
vt 0.4833 0.9730
vt 0.5219 0.9855
vt 0.6097 0.9229
vt 0.6097 0.2971
vt 0.4678 0.2470
vt 0.4291 0.2345
vt 0.5219 0.2345
vt 0.4833 0.2470
vt 0.4833 0.2783
vt 0.4678 0.2783
vt 0.4132 0.2971
vt 0.4132 0.9229
vt 0.4678 0.9417
vt 0.4833 0.9417
vt 0.5182 0.9229
vt 0.5182 0.2971
vt 0.4328 0.2971
vt 0.4328 0.9229
vt 0.5026 0.9229
vt 0.5026 0.2971
vt 0.4485 0.2971
vt 0.4485 0.9229
vt 0.5026 0.2814
vt 0.4485 0.2814
vt 0.4485 0.9386
vt 0.5026 0.9386
vt 0.9588 0.9625
vt 0.8837 0.9625
vt 0.8837 0.0348
vt 0.9588 0.0348
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.9588 0.0035
vt 0.8837 0.0035
vt 0.8524 0.0348
vt 0.8524 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt 0.9588 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt 0.8837 0.9625
vt 0.8524 0.0348
vt 0.8837 0.0348
vt 0.8524 0.9625
vt 0.9588 0.0035
vt 0.9588 0.0348
vt 0.8837 0.0035
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.9588 0.9625
vt 0.8837 0.9625
vt 0.8837 0.0348
vt 0.9588 0.0348
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.9588 0.0035
vt 0.8837 0.0035
vt 0.8524 0.0348
vt 0.8524 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt 0.7427 0.1169
vt 0.6400 0.1169
vt 0.6400 0.3317
vt 0.7427 0.3317
vt 0.7427 0.4343
vt 0.8260 0.4343
vt 0.8260 0.3317
vt 0.8260 0.1169
vt 0.8260 0.0142
vt 0.7427 0.0142
vt 0.9588 0.9625
vt 0.8837 0.9625
vt 0.8837 0.0348
vt 0.9588 0.0348
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.9588 0.0035
vt 0.8837 0.0035
vt 0.8524 0.0348
vt 0.8524 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt 0.9588 0.9625
vt 0.8837 0.9625
vt 0.8837 0.0348
vt 0.9588 0.0348
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.9588 0.0035
vt 0.8837 0.0035
vt 0.8524 0.0348
vt 0.8524 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt -0.2938 0.5095
vt 0.6540 0.0358
vt 0.6540 0.5096
vt 0.6549 0.9852
vt -0.2928 0.5114
vt 0.6549 0.5114
vt 0.1047 0.9953
vt 0.1047 0.4934
vt 0.1047 -0.0085
vt 1.1643 -0.0085
vt 1.1643 0.9953
vt 1.1568 0.5114
vt 0.6549 0.0377
vt 1.1568 0.0377
vt -0.3972 0.9953
vt -0.3972 -0.0085
vt 1.1431 0.5009
vt 0.4334 0.5009
vt 0.4334 0.0272
vt 1.1431 0.0272
vt 1.1431 0.9747
vt 0.4334 0.9747
vt 0.7633 0.9654
vt 0.0536 0.9654
vt 0.0536 0.4916
vt 0.7633 0.4916
vt 1.1559 0.5096
vt 1.1559 0.9833
vt 0.6540 0.9833
vt 0.1053 -0.0176
vt 0.1052 0.4843
vt -0.3966 -0.0176
vt 1.0530 -0.0176
vt 1.0530 0.9861
vt 0.1053 0.9861
vt -0.3966 0.9861
vt 0.0536 0.0179
vt 0.7633 0.0179
vt -0.2928 0.0377
vt -0.2938 0.9833
vt 0.0455 0.1273
vt 1.0492 0.1273
vt 1.0492 0.6011
vt 0.0455 0.6011
vt 1.1568 0.9852
vt 1.1559 0.0358
vn -0.7071 0.0000 -0.7071
vn 0.7071 0.0000 -0.7071
vn -0.7071 0.0000 0.7071
vn 0.2357 0.9428 -0.2357
vn 0.7071 0.0000 0.7071
vn 0.0189 0.9017 -0.4319
vn 0.4319 0.9017 -0.0189
vn -0.1263 -0.9320 0.3397
vn -0.3397 -0.9320 0.1263
vn -0.2357 -0.9428 0.2357
vn 0.0000 1.0000 0.0000
vn -0.0000 0.0000 1.0000
vn -1.0000 0.0000 0.0000
vn 0.0000 -1.0000 0.0000
g dtrack_vst2_45_Cube.035_SlopeRailMaterial
s off
f 2/1/1 4/2/1 3/3/1 1/4/1
f 4/2/2 8/5/2 7/6/2 3/7/2
f 6/8/3 2/1/3 1/9/3 5/10/3
f 6/8/4 8/5/4 4/2/4 2/1/4
f 16/11/5 15/12/5 19/13/5 20/14/5
f 9/15/6 13/16/6 14/17/6 10/18/6
f 10/19/2 14/20/2 15/21/2 11/22/2
f 11/23/7 15/12/7 16/11/7 12/24/7
f 13/25/3 9/26/3 12/27/3 16/28/3
f 20/29/3 17/30/3 13/25/3 16/28/3
f 13/16/1 17/31/1 18/32/1 14/17/1
f 15/21/2 14/20/2 18/33/2 19/34/2
f 20/14/8 19/13/8 21/35/8 22/36/8
f 18/32/9 17/31/9 23/37/9 24/38/9
f 22/36/5 21/35/5 25/39/5 26/40/5
f 24/38/1 23/37/1 27/41/1 28/42/1
f 25/39/4 28/42/4 27/41/4 26/40/4
f 17/30/3 20/29/3 22/43/3 26/40/3 27/41/3 23/44/3
f 18/33/2 24/45/2 28/42/2 25/39/2 21/46/2 19/34/2
f 32/47/5 36/48/5 33/49/5 29/50/5
f 34/51/2 30/52/2 29/50/2 33/53/2
f 35/54/1 31/55/1 30/52/1 34/56/1
f 36/57/3 32/47/3 31/55/3 35/58/3
f 32/47/4 29/50/4 30/52/4 31/55/4
f 37/59/1 39/60/1 40/61/1 38/62/1
f 41/63/5 43/64/5 44/65/5 42/66/5
f 37/67/10 38/68/10 41/63/10 42/66/10
f 39/60/4 44/65/4 43/64/4 40/61/4
f 52/69/1 51/70/1 55/71/1 56/72/1
f 45/73/7 49/74/7 50/75/7 46/76/7
f 46/77/3 50/78/3 51/79/3 47/80/3
f 47/81/6 51/70/6 52/69/6 48/82/6
f 49/83/2 45/84/2 48/85/2 52/86/2
f 56/87/2 53/88/2 49/83/2 52/86/2
f 49/74/5 53/89/5 54/90/5 50/75/5
f 51/79/3 50/78/3 54/91/3 55/92/3
f 56/72/9 55/71/9 57/93/9 58/94/9
f 54/90/8 53/89/8 59/95/8 60/96/8
f 58/94/1 57/93/1 61/97/1 62/98/1
f 60/96/5 59/95/5 63/99/5 64/100/5
f 61/97/4 64/100/4 63/99/4 62/98/4
f 53/88/2 56/87/2 58/101/2 62/98/2 63/99/2 59/102/2
f 54/91/3 60/103/3 64/100/3 61/97/3 57/104/3 55/92/3
f 69/105/4 72/106/4 71/107/4 70/108/4
f 65/109/2 69/105/2 70/108/2 66/110/2
f 66/111/5 70/108/5 71/107/5 67/112/5
f 67/113/3 71/107/3 72/106/3 68/114/3
f 69/105/1 65/115/1 68/116/1 72/106/1
f 76/117/5 80/118/5 77/119/5 73/120/5
f 78/121/2 74/122/2 73/120/2 77/123/2
f 79/124/1 75/125/1 74/122/1 78/126/1
f 80/127/3 76/117/3 75/125/3 79/128/3
f 76/117/4 73/120/4 74/122/4 75/125/4
f 85/129/4 88/130/4 87/131/4 86/132/4
f 81/133/2 85/129/2 86/132/2 82/134/2
f 82/135/5 86/132/5 87/131/5 83/136/5
f 83/137/3 87/131/3 88/130/3 84/138/3
f 85/129/1 81/139/1 84/140/1 88/130/1
f 90/141/5 89/142/5 91/143/5 92/144/5
f 92/144/2 91/145/2 95/146/2 96/147/2
f 94/148/3 93/149/3 89/150/3 90/141/3
f 94/148/4 90/141/4 92/144/4 96/147/4
f 101/151/4 104/152/4 103/153/4 102/154/4
f 97/155/2 101/151/2 102/154/2 98/156/2
f 98/157/5 102/154/5 103/153/5 99/158/5
f 99/159/3 103/153/3 104/152/3 100/160/3
f 101/151/1 97/161/1 100/162/1 104/152/1
f 109/163/4 112/164/4 111/165/4 110/166/4
f 105/167/3 109/163/3 110/166/3 106/168/3
f 106/169/1 110/166/1 111/165/1 107/170/1
f 107/171/2 111/165/2 112/164/2 108/172/2
f 109/163/5 105/173/5 108/174/5 112/164/5
g dtrack_vst2_45_Cube.035_SlopeGravelMaterial
f 114/175/5 118/176/5 117/177/5
f 116/178/1 113/179/1 115/180/1
f 116/181/4 121/182/4 118/183/4 114/184/4 113/185/4
f 122/186/1 115/180/1 128/187/1 131/188/1
f 116/181/11 120/189/11 121/182/11
f 118/183/11 121/182/11 119/190/11
f 124/191/12 122/192/12 131/193/12 129/194/12
f 121/195/12 120/196/12 122/192/12 124/191/12
f 119/197/13 121/198/13 124/199/13 123/200/13
f 117/177/5 123/201/5 130/202/5 127/203/5
f 128/204/14 129/205/14 131/206/14
f 126/207/14 125/208/14 127/209/14 129/205/14 128/204/14
f 130/210/14 129/205/14 127/209/14
f 123/200/13 124/199/13 129/211/13 130/212/13
f 115/180/1 113/179/1 126/213/1 128/187/1
f 114/175/5 117/177/5 127/203/5 125/214/5
f 113/215/2 114/216/2 125/217/2 126/218/2
f 116/178/1 115/180/1 122/186/1 120/219/1
f 117/177/5 118/176/5 119/220/5 123/201/5
="hl ppc">#include "client/renderingengine.h" #define WIELD_SCALE_FACTOR 30.0 #define WIELD_SCALE_FACTOR_EXTRUDED 40.0 #define MIN_EXTRUSION_MESH_RESOLUTION 16 #define MAX_EXTRUSION_MESH_RESOLUTION 512 static scene::IMesh *createExtrusionMesh(int resolution_x, int resolution_y) { const f32 r = 0.5; scene::IMeshBuffer *buf = new scene::SMeshBuffer(); video::SColor c(255,255,255,255); v3f scale(1.0, 1.0, 0.1); // Front and back { video::S3DVertex vertices[8] = { // z- video::S3DVertex(-r,+r,-r, 0,0,-1, c, 0,0), video::S3DVertex(+r,+r,-r, 0,0,-1, c, 1,0), video::S3DVertex(+r,-r,-r, 0,0,-1, c, 1,1), video::S3DVertex(-r,-r,-r, 0,0,-1, c, 0,1), // z+ video::S3DVertex(-r,+r,+r, 0,0,+1, c, 0,0), video::S3DVertex(-r,-r,+r, 0,0,+1, c, 0,1), video::S3DVertex(+r,-r,+r, 0,0,+1, c, 1,1), video::S3DVertex(+r,+r,+r, 0,0,+1, c, 1,0), }; u16 indices[12] = {0,1,2,2,3,0,4,5,6,6,7,4}; buf->append(vertices, 8, indices, 12); } f32 pixelsize_x = 1 / (f32) resolution_x; f32 pixelsize_y = 1 / (f32) resolution_y; for (int i = 0; i < resolution_x; ++i) { f32 pixelpos_x = i * pixelsize_x - 0.5; f32 x0 = pixelpos_x; f32 x1 = pixelpos_x + pixelsize_x; f32 tex0 = (i + 0.1) * pixelsize_x; f32 tex1 = (i + 0.9) * pixelsize_x; video::S3DVertex vertices[8] = { // x- video::S3DVertex(x0,-r,-r, -1,0,0, c, tex0,1), video::S3DVertex(x0,-r,+r, -1,0,0, c, tex1,1), video::S3DVertex(x0,+r,+r, -1,0,0, c, tex1,0), video::S3DVertex(x0,+r,-r, -1,0,0, c, tex0,0), // x+ video::S3DVertex(x1,-r,-r, +1,0,0, c, tex0,1), video::S3DVertex(x1,+r,-r, +1,0,0, c, tex0,0), video::S3DVertex(x1,+r,+r, +1,0,0, c, tex1,0), video::S3DVertex(x1,-r,+r, +1,0,0, c, tex1,1), }; u16 indices[12] = {0,1,2,2,3,0,4,5,6,6,7,4}; buf->append(vertices, 8, indices, 12); } for (int i = 0; i < resolution_y; ++i) { f32 pixelpos_y = i * pixelsize_y - 0.5; f32 y0 = -pixelpos_y - pixelsize_y; f32 y1 = -pixelpos_y; f32 tex0 = (i + 0.1) * pixelsize_y; f32 tex1 = (i + 0.9) * pixelsize_y; video::S3DVertex vertices[8] = { // y- video::S3DVertex(-r,y0,-r, 0,-1,0, c, 0,tex0), video::S3DVertex(+r,y0,-r, 0,-1,0, c, 1,tex0), video::S3DVertex(+r,y0,+r, 0,-1,0, c, 1,tex1), video::S3DVertex(-r,y0,+r, 0,-1,0, c, 0,tex1), // y+ video::S3DVertex(-r,y1,-r, 0,+1,0, c, 0,tex0), video::S3DVertex(-r,y1,+r, 0,+1,0, c, 0,tex1), video::S3DVertex(+r,y1,+r, 0,+1,0, c, 1,tex1), video::S3DVertex(+r,y1,-r, 0,+1,0, c, 1,tex0), }; u16 indices[12] = {0,1,2,2,3,0,4,5,6,6,7,4}; buf->append(vertices, 8, indices, 12); } // Create mesh object scene::SMesh *mesh = new scene::SMesh(); mesh->addMeshBuffer(buf); buf->drop(); scaleMesh(mesh, scale); // also recalculates bounding box return mesh; } /* Caches extrusion meshes so that only one of them per resolution is needed. Also caches one cube (for convenience). E.g. there is a single extrusion mesh that is used for all 16x16 px images, another for all 256x256 px images, and so on. WARNING: Not thread safe. This should not be a problem since rendering related classes (such as WieldMeshSceneNode) will be used from the rendering thread only. */ class ExtrusionMeshCache: public IReferenceCounted { public: // Constructor ExtrusionMeshCache() { for (int resolution = MIN_EXTRUSION_MESH_RESOLUTION; resolution <= MAX_EXTRUSION_MESH_RESOLUTION; resolution *= 2) { m_extrusion_meshes[resolution] = createExtrusionMesh(resolution, resolution); } m_cube = createCubeMesh(v3f(1.0, 1.0, 1.0)); } // Destructor virtual ~ExtrusionMeshCache() { for (auto &extrusion_meshe : m_extrusion_meshes) { extrusion_meshe.second->drop(); } m_cube->drop(); } // Get closest extrusion mesh for given image dimensions // Caller must drop the returned pointer scene::IMesh* create(core::dimension2d<u32> dim) { // handle non-power of two textures inefficiently without cache if (!is_power_of_two(dim.Width) || !is_power_of_two(dim.Height)) { return createExtrusionMesh(dim.Width, dim.Height); } int maxdim = MYMAX(dim.Width, dim.Height); std::map<int, scene::IMesh*>::iterator it = m_extrusion_meshes.lower_bound(maxdim); if (it == m_extrusion_meshes.end()) { // no viable resolution found; use largest one it = m_extrusion_meshes.find(MAX_EXTRUSION_MESH_RESOLUTION); sanity_check(it != m_extrusion_meshes.end()); } scene::IMesh *mesh = it->second; mesh->grab(); return mesh; } // Returns a 1x1x1 cube mesh with one meshbuffer (material) per face // Caller must drop the returned pointer scene::IMesh* createCube() { m_cube->grab(); return m_cube; } private: std::map<int, scene::IMesh*> m_extrusion_meshes; scene::IMesh *m_cube; }; ExtrusionMeshCache *g_extrusion_mesh_cache = NULL; WieldMeshSceneNode::WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id, bool lighting): scene::ISceneNode(mgr->getRootSceneNode(), mgr, id), m_material_type(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF), m_lighting(lighting) { m_enable_shaders = g_settings->getBool("enable_shaders"); m_anisotropic_filter = g_settings->getBool("anisotropic_filter"); m_bilinear_filter = g_settings->getBool("bilinear_filter"); m_trilinear_filter = g_settings->getBool("trilinear_filter"); // If this is the first wield mesh scene node, create a cache // for extrusion meshes (and a cube mesh), otherwise reuse it if (!g_extrusion_mesh_cache) g_extrusion_mesh_cache = new ExtrusionMeshCache(); else g_extrusion_mesh_cache->grab(); // Disable bounding box culling for this scene node // since we won't calculate the bounding box. setAutomaticCulling(scene::EAC_OFF); // Create the child scene node scene::IMesh *dummymesh = g_extrusion_mesh_cache->createCube(); m_meshnode = SceneManager->addMeshSceneNode(dummymesh, this, -1); m_meshnode->setReadOnlyMaterials(false); m_meshnode->setVisible(false); dummymesh->drop(); // m_meshnode grabbed it m_shadow = RenderingEngine::get_shadow_renderer(); } WieldMeshSceneNode::~WieldMeshSceneNode() { sanity_check(g_extrusion_mesh_cache); // Remove node from shadow casters. m_shadow might be an invalid pointer! if (auto shadow = RenderingEngine::get_shadow_renderer()) shadow->removeNodeFromShadowList(m_meshnode); if (g_extrusion_mesh_cache->drop()) g_extrusion_mesh_cache = nullptr; } void WieldMeshSceneNode::setCube(const ContentFeatures &f, v3f wield_scale) { scene::IMesh *cubemesh = g_extrusion_mesh_cache->createCube(); scene::SMesh *copy = cloneMesh(cubemesh); cubemesh->drop(); postProcessNodeMesh(copy, f, false, true, &m_material_type, &m_colors, true); changeToMesh(copy); copy->drop(); m_meshnode->setScale(wield_scale * WIELD_SCALE_FACTOR); } void WieldMeshSceneNode::setExtruded(const std::string &imagename, const std::string &overlay_name, v3f wield_scale, ITextureSource *tsrc, u8 num_frames) { video::ITexture *texture = tsrc->getTexture(imagename); if (!texture) { changeToMesh(nullptr); return; } video::ITexture *overlay_texture = overlay_name.empty() ? NULL : tsrc->getTexture(overlay_name); core::dimension2d<u32> dim = texture->getSize(); // Detect animation texture and pull off top frame instead of using entire thing if (num_frames > 1) { u32 frame_height = dim.Height / num_frames; dim = core::dimension2d<u32>(dim.Width, frame_height); } scene::IMesh *original = g_extrusion_mesh_cache->create(dim); scene::SMesh *mesh = cloneMesh(original); original->drop(); //set texture mesh->getMeshBuffer(0)->getMaterial().setTexture(0, tsrc->getTexture(imagename)); if (overlay_texture) { scene::IMeshBuffer *copy = cloneMeshBuffer(mesh->getMeshBuffer(0)); copy->getMaterial().setTexture(0, overlay_texture); mesh->addMeshBuffer(copy); copy->drop(); } changeToMesh(mesh); mesh->drop(); m_meshnode->setScale(wield_scale * WIELD_SCALE_FACTOR_EXTRUDED); // Customize materials for (u32 layer = 0; layer < m_meshnode->getMaterialCount(); layer++) { video::SMaterial &material = m_meshnode->getMaterial(layer); material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE; material.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; material.MaterialType = m_material_type; material.MaterialTypeParam = 0.5f; material.setFlag(video::EMF_BACK_FACE_CULLING, true); // Enable bi/trilinear filtering only for high resolution textures if (dim.Width > 32) { material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter); material.setFlag(video::EMF_TRILINEAR_FILTER, m_trilinear_filter); } else { material.setFlag(video::EMF_BILINEAR_FILTER, false); material.setFlag(video::EMF_TRILINEAR_FILTER, false); } material.setFlag(video::EMF_ANISOTROPIC_FILTER, m_anisotropic_filter); // mipmaps cause "thin black line" artifacts material.setFlag(video::EMF_USE_MIP_MAPS, false); if (m_enable_shaders) { material.setTexture(2, tsrc->getShaderFlagsTexture(false)); } } } static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n, std::vector<ItemPartColor> *colors, const ContentFeatures &f) { MeshMakeData mesh_make_data(client, false); MeshCollector collector; mesh_make_data.setSmoothLighting(false); MapblockMeshGenerator gen(&mesh_make_data, &collector, client->getSceneManager()->getMeshManipulator()); if (n.getParam2()) { // keep it } else if (f.param_type_2 == CPT2_WALLMOUNTED || f.param_type_2 == CPT2_COLORED_WALLMOUNTED) { if (f.drawtype == NDT_TORCHLIKE || f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_NODEBOX || f.drawtype == NDT_MESH) { n.setParam2(4); } } else if (f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_TORCHLIKE) { n.setParam2(1); } gen.renderSingle(n.getContent(), n.getParam2()); colors->clear(); scene::SMesh *mesh = new scene::SMesh(); for (auto &prebuffers : collector.prebuffers) for (PreMeshBuffer &p : prebuffers) { if (p.layer.material_flags & MATERIAL_FLAG_ANIMATION) { const FrameSpec &frame = (*p.layer.frames)[0]; p.layer.texture = frame.texture; p.layer.normal_texture = frame.normal_texture; } for (video::S3DVertex &v : p.vertices) { v.Color.setAlpha(255); } scene::SMeshBuffer *buf = new scene::SMeshBuffer(); buf->Material.setTexture(0, p.layer.texture); p.layer.applyMaterialOptions(buf->Material); mesh->addMeshBuffer(buf); buf->append(&p.vertices[0], p.vertices.size(), &p.indices[0], p.indices.size()); buf->drop(); colors->push_back( ItemPartColor(p.layer.has_color, p.layer.color)); } return mesh; } void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client, bool check_wield_image) { ITextureSource *tsrc = client->getTextureSource(); IItemDefManager *idef = client->getItemDefManager(); IShaderSource *shdrsrc = client->getShaderSource(); const NodeDefManager *ndef = client->getNodeDefManager(); const ItemDefinition &def = item.getDefinition(idef); const ContentFeatures &f = ndef->get(def.name); content_t id = ndef->getId(def.name); scene::SMesh *mesh = nullptr; if (m_enable_shaders) { u32 shader_id = shdrsrc->getShader("object_shader", TILE_MATERIAL_BASIC, NDT_NORMAL); m_material_type = shdrsrc->getShaderInfo(shader_id).material; } // Color-related m_colors.clear(); m_base_color = idef->getItemstackColor(item, client); // If wield_image needs to be checked and is defined, it overrides everything else if (!def.wield_image.empty() && check_wield_image) { setExtruded(def.wield_image, def.wield_overlay, def.wield_scale, tsrc, 1); m_colors.emplace_back(); // overlay is white, if present m_colors.emplace_back(true, video::SColor(0xFFFFFFFF)); return; } // Handle nodes // See also CItemDefManager::createClientCached() if (def.type == ITEM_NODE) { bool cull_backface = f.needsBackfaceCulling(); // Select rendering method switch (f.drawtype) { case NDT_AIRLIKE: setExtruded("no_texture_airlike.png", "", v3f(1.0, 1.0, 1.0), tsrc, 1); break; case NDT_SIGNLIKE: case NDT_TORCHLIKE: case NDT_RAILLIKE: case NDT_PLANTLIKE: case NDT_FLOWINGLIQUID: { v3f wscale = def.wield_scale; if (f.drawtype == NDT_FLOWINGLIQUID) wscale.Z *= 0.1f; setExtruded(tsrc->getTextureName(f.tiles[0].layers[0].texture_id), tsrc->getTextureName(f.tiles[0].layers[1].texture_id), wscale, tsrc, f.tiles[0].layers[0].animation_frame_count); // Add color const TileLayer &l0 = f.tiles[0].layers[0]; m_colors.emplace_back(l0.has_color, l0.color); const TileLayer &l1 = f.tiles[0].layers[1]; m_colors.emplace_back(l1.has_color, l1.color); break; } case NDT_PLANTLIKE_ROOTED: { setExtruded(tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id), "", def.wield_scale, tsrc, f.special_tiles[0].layers[0].animation_frame_count); // Add color const TileLayer &l0 = f.special_tiles[0].layers[0]; m_colors.emplace_back(l0.has_color, l0.color); break; } case NDT_NORMAL: case NDT_ALLFACES: case NDT_LIQUID: setCube(f, def.wield_scale); break; default: { // Render non-trivial drawtypes like the actual node MapNode n(id); n.setParam2(def.place_param2); mesh = createSpecialNodeMesh(client, n, &m_colors, f); changeToMesh(mesh); mesh->drop(); m_meshnode->setScale( def.wield_scale * WIELD_SCALE_FACTOR / (BS * f.visual_scale)); break; } } u32 material_count = m_meshnode->getMaterialCount(); for (u32 i = 0; i < material_count; ++i) { video::SMaterial &material = m_meshnode->getMaterial(i); material.MaterialType = m_material_type; material.MaterialTypeParam = 0.5f; material.setFlag(video::EMF_BACK_FACE_CULLING, cull_backface); material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter); material.setFlag(video::EMF_TRILINEAR_FILTER, m_trilinear_filter); } return; } else if (!def.inventory_image.empty()) { setExtruded(def.inventory_image, def.inventory_overlay, def.wield_scale, tsrc, 1); m_colors.emplace_back(); // overlay is white, if present m_colors.emplace_back(true, video::SColor(0xFFFFFFFF)); return; } // no wield mesh found changeToMesh(nullptr); } void WieldMeshSceneNode::setColor(video::SColor c) { assert(!m_lighting); scene::IMesh *mesh = m_meshnode->getMesh(); if (!mesh) return; u8 red = c.getRed(); u8 green = c.getGreen(); u8 blue = c.getBlue(); u32 mc = mesh->getMeshBufferCount(); for (u32 j = 0; j < mc; j++) { video::SColor bc(m_base_color); if ((m_colors.size() > j) && (m_colors[j].override_base)) bc = m_colors[j].color; video::SColor buffercolor(255, bc.getRed() * red / 255, bc.getGreen() * green / 255, bc.getBlue() * blue / 255); scene::IMeshBuffer *buf = mesh->getMeshBuffer(j); if (m_enable_shaders) setMeshBufferColor(buf, buffercolor); else colorizeMeshBuffer(buf, &buffercolor); } } void WieldMeshSceneNode::setNodeLightColor(video::SColor color) { if (!m_meshnode) return; if (m_enable_shaders) { for (u32 i = 0; i < m_meshnode->getMaterialCount(); ++i) { video::SMaterial &material = m_meshnode->getMaterial(i); material.EmissiveColor = color; } } setColor(color); } void WieldMeshSceneNode::render() { // note: if this method is changed to actually do something, // you probably should implement OnRegisterSceneNode as well } void WieldMeshSceneNode::changeToMesh(scene::IMesh *mesh) { if (!mesh) { scene::IMesh *dummymesh = g_extrusion_mesh_cache->createCube(); m_meshnode->setVisible(false); m_meshnode->setMesh(dummymesh); dummymesh->drop(); // m_meshnode grabbed it } else { m_meshnode->setMesh(mesh); } m_meshnode->setMaterialFlag(video::EMF_LIGHTING, m_lighting); // need to normalize normals when lighting is enabled (because of setScale()) m_meshnode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, m_lighting); m_meshnode->setVisible(true); // Add mesh to shadow caster if (m_shadow) m_shadow->addNodeToShadowList(m_meshnode); } void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result) { ITextureSource *tsrc = client->getTextureSource(); IItemDefManager *idef = client->getItemDefManager(); const NodeDefManager *ndef = client->getNodeDefManager(); const ItemDefinition &def = item.getDefinition(idef); const ContentFeatures &f = ndef->get(def.name); content_t id = ndef->getId(def.name); FATAL_ERROR_IF(!g_extrusion_mesh_cache, "Extrusion mesh cache is not yet initialized"); scene::SMesh *mesh = nullptr; // Shading is on by default result->needs_shading = true; bool cull_backface = f.needsBackfaceCulling(); // If inventory_image is defined, it overrides everything else if (!def.inventory_image.empty()) { mesh = getExtrudedMesh(tsrc, def.inventory_image, def.inventory_overlay); result->buffer_colors.emplace_back(); // overlay is white, if present result->buffer_colors.emplace_back(true, video::SColor(0xFFFFFFFF)); // Items with inventory images do not need shading result->needs_shading = false; } else if (def.type == ITEM_NODE && f.drawtype == NDT_AIRLIKE) { // Fallback image for airlike node mesh = getExtrudedMesh(tsrc, "no_texture_airlike.png", def.inventory_overlay); result->needs_shading = false; } else if (def.type == ITEM_NODE) { switch (f.drawtype) { case NDT_NORMAL: case NDT_ALLFACES: case NDT_LIQUID: case NDT_FLOWINGLIQUID: { scene::IMesh *cube = g_extrusion_mesh_cache->createCube(); mesh = cloneMesh(cube); cube->drop(); if (f.drawtype == NDT_FLOWINGLIQUID) { scaleMesh(mesh, v3f(1.2, 0.03, 1.2)); translateMesh(mesh, v3f(0, -0.57, 0)); } else scaleMesh(mesh, v3f(1.2, 1.2, 1.2)); // add overlays postProcessNodeMesh(mesh, f, false, false, nullptr, &result->buffer_colors, true); if (f.drawtype == NDT_ALLFACES) scaleMesh(mesh, v3f(f.visual_scale)); break; } case NDT_PLANTLIKE: { mesh = getExtrudedMesh(tsrc, tsrc->getTextureName(f.tiles[0].layers[0].texture_id), tsrc->getTextureName(f.tiles[0].layers[1].texture_id)); // Add color const TileLayer &l0 = f.tiles[0].layers[0]; result->buffer_colors.emplace_back(l0.has_color, l0.color); const TileLayer &l1 = f.tiles[0].layers[1]; result->buffer_colors.emplace_back(l1.has_color, l1.color); break; } case NDT_PLANTLIKE_ROOTED: { mesh = getExtrudedMesh(tsrc, tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id), ""); // Add color const TileLayer &l0 = f.special_tiles[0].layers[0]; result->buffer_colors.emplace_back(l0.has_color, l0.color); break; } default: { // Render non-trivial drawtypes like the actual node MapNode n(id); n.setParam2(def.place_param2); mesh = createSpecialNodeMesh(client, n, &result->buffer_colors, f); scaleMesh(mesh, v3f(0.12, 0.12, 0.12)); break; } } u32 mc = mesh->getMeshBufferCount(); for (u32 i = 0; i < mc; ++i) { scene::IMeshBuffer *buf = mesh->getMeshBuffer(i); video::SMaterial &material = buf->getMaterial(); material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; material.MaterialTypeParam = 0.5f; material.setFlag(video::EMF_BILINEAR_FILTER, false); material.setFlag(video::EMF_TRILINEAR_FILTER, false); material.setFlag(video::EMF_BACK_FACE_CULLING, cull_backface); material.setFlag(video::EMF_LIGHTING, false); }