aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/mesh__multi__lod_8cpp-source.html
blob: 1e3a9afec2a97cdade365d34310fddd03c7a8fc5 (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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
	<TITLE>nevrax.org : docs</TITLE>
	<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">

<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0>
 <TR>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF='/'><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF='/'><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>

<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 height=100%>
 <TR>
	<TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

		<!------ Begin Box ------>
		<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0  cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
		<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td  colspan=2 bgcolor=#FFFFFF>
		<TABLE cellspacing=0 cellpadding=1 border=0>
			<tr><td ALIGN=middle><a  class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
&nbsp;

<!-- block -->
<TABLE  bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>mesh_multi_lod.cpp</h1><a href="mesh__multi__lod_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025 
00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font>
00027 
00028 <font class="preprocessor">#include "<a class="code" href="mesh__multi__lod_8h.html">3d/mesh_multi_lod.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="mesh__multi__lod__instance_8h.html">3d/mesh_multi_lod_instance.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="mesh__instance_8h.html">3d/mesh_instance.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="mesh__mrm_8h.html">3d/mesh_mrm.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="scene_8h.html">3d/scene.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="coarse__mesh__manager_8h.html">3d/coarse_mesh_manager.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="skeleton__model_8h.html">3d/skeleton_model.h</a>"</font>
00035 <font class="preprocessor">#include "<a class="code" href="fast__floor_8h.html">3d/fast_floor.h</a>"</font>
00036 <font class="preprocessor">#include "<a class="code" href="mesh__blender_8h.html">3d/mesh_blender.h</a>"</font>
00037 
00038 <font class="preprocessor">#include "<a class="code" href="debug_8h.html">nel/misc/debug.h</a>"</font>
00039 
00040 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00041 
00042 <font class="keyword">namespace </font>NL3D 
00043 {
00044 
00045 
00046 
00047 
00048 <font class="comment">// ***************************************************************************</font>
00049 
<a name="l00050"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#z581_0">00050</a> <font class="keywordtype">void</font> CMeshMultiLod::build(CMeshMultiLodBuild &amp;mbuild)
00051 {
00052         <font class="comment">// Clear the mesh</font>
00053         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#c0">clear</a> ();
00054 
00055         <font class="comment">// Build the base mesh</font>
00056         CMeshBase::buildMeshBase (mbuild.BaseMesh);
00057 
00058         <font class="comment">// Static flag</font>
00059         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o0">_StaticLod</a>=mbuild.StaticLod;
00060 
00061         <font class="comment">// Resize the array</font>
00062         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>.resize (mbuild.LodMeshes.size());
00063 
00064         <font class="comment">// Number of coarse meshes</font>
00065         <a class="code" href="types__nl_8h.html#a14">uint</a> coarse=0;
00066 
00067         <font class="comment">// For each slots</font>
00068         <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> slot=0; slot&lt;mbuild.LodMeshes.size(); slot++)
00069         {
00070                 <font class="comment">// Dist max</font>
00071                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].DistMax=mbuild.LodMeshes[slot].DistMax;
00072 
00073                 <font class="comment">// BlendLength</font>
00074                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].BlendLength=mbuild.LodMeshes[slot].BlendLength;
00075 
00076                 <font class="comment">// Flags</font>
00077                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].Flags=0;
00078 
00079                 <font class="comment">// Blend in ?</font>
00080                 <font class="keywordflow">if</font> (mbuild.LodMeshes[slot].Flags &amp; CMeshMultiLodBuild::CBuildSlot::BlendIn)
00081                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].Flags|=CMeshSlot::BlendIn;
00082 
00083                 <font class="comment">// Blend out ?</font>
00084                 <font class="keywordflow">if</font> (mbuild.LodMeshes[slot].Flags &amp; CMeshMultiLodBuild::CBuildSlot::BlendOut)
00085                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].Flags|=CMeshSlot::BlendOut;
00086 
00087                 <font class="comment">// Coarse mesh ?</font>
00088                 <font class="keywordflow">if</font> (mbuild.LodMeshes[slot].Flags &amp; CMeshMultiLodBuild::CBuildSlot::CoarseMesh)
00089                 {
00090                         <font class="comment">// Warning: no more than 2 coarse meshes in a lod mesh!</font>
00091                         <a class="code" href="debug_8h.html#a6">nlassert</a> (coarse&lt;=1);
00092 
00093                         <font class="comment">// Flag</font>
00094                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].Flags|=CMeshSlot::CoarseMesh;
00095 
00096                         <font class="comment">// Flag coarse ID</font>
00097                         <font class="keywordflow">if</font> (coarse==1)
00098                                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].Flags|=CMeshSlot::CoarseMeshId;
00099 
00100                         <font class="comment">// One more</font>
00101                         coarse++;
00102                 }
00103 
00104                 <font class="comment">// Is opaque</font>
00105                 <font class="keywordflow">if</font> (mbuild.LodMeshes[slot].Flags &amp; CMeshMultiLodBuild::CBuildSlot::IsOpaque)
00106                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].Flags|=CMeshSlot::IsOpaque;
00107 
00108                 <font class="comment">// Is transparent</font>
00109                 <font class="keywordflow">if</font> (mbuild.LodMeshes[slot].Flags &amp; CMeshMultiLodBuild::CBuildSlot::IsTransparent)
00110                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].Flags|=CMeshSlot::IsTransparent;
00111 
00112                 <font class="comment">// MeshGeom</font>
00113                 <a class="code" href="debug_8h.html#a6">nlassert</a> (mbuild.LodMeshes[slot].MeshGeom);
00114 
00115                 <font class="comment">// Valid pointer ?</font>
00116                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].Flags&amp;CMeshSlot::CoarseMesh)
00117                 {
00118                         <font class="comment">// If it is a coarse mesh, it must be a CMeshGeom.</font>
00119                         <font class="keywordflow">if</font> (dynamic_cast&lt;CMeshGeom*&gt;(mbuild.LodMeshes[slot].MeshGeom)==NULL)
00120                         {
00121                                 <font class="comment">// If it is a coarse mesh, it must be a CMeshGeom.</font>
00122                                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].MeshGeom = NULL;
00123                                 <font class="keyword">delete</font> mbuild.LodMeshes[slot].MeshGeom;
00124                         }
00125                         <font class="keywordflow">else</font>
00126                                 <font class="comment">// Ok, no prb</font>
00127                                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].MeshGeom = mbuild.LodMeshes[slot].MeshGeom;
00128                 }
00129                 <font class="keywordflow">else</font>
00130                         <font class="comment">// Ok, no prb</font>
00131                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].MeshGeom = mbuild.LodMeshes[slot].MeshGeom;   
00132         }
00133 
00134         <font class="comment">// Sort the slot by the distance...</font>
00135         <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=mbuild.LodMeshes.size()-1; i&gt;0; i--)
00136         <font class="keywordflow">for</font> (<font class="keywordtype">int</font> j=0; j&lt;i; j++)
00137         {
00138                 <font class="comment">// Bad sort ?</font>
00139                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[j].DistMax&gt;<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[j+1].DistMax)
00140                 {
00141                         <font class="comment">// Exchange slots</font>
00142                         CMeshSlot tmp=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[j];
00143                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[j]=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[j+1];
00144                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[j+1]=tmp;
00145                         tmp.MeshGeom=NULL;
00146                 }
00147         }
00148 
00149         <font class="comment">// Calc start and end polygon count</font>
00150         <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> k=0; k&lt;mbuild.LodMeshes.size(); k++)
00151         {
00152                 <font class="comment">// Get start distance</font>
00153                 <font class="keywordtype">float</font> startDist;
00154                 <font class="keywordflow">if</font> (k==0)
00155                         startDist=0;
00156                 <font class="keywordflow">else</font> 
00157                         startDist=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k-1].DistMax;
00158 
00159                 <font class="comment">// Get start poly count</font>
00160                 <font class="keywordtype">float</font> startPolyCount;
00161                 startPolyCount=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].MeshGeom-&gt;getNumTriangles (startDist);
00162 
00163                 <font class="comment">// Get end distance</font>
00164                 <font class="keywordtype">float</font> endDist=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].DistMax;
00165 
00166                 <font class="comment">// Get end poly count</font>
00167                 <font class="keywordflow">if</font> (k==mbuild.LodMeshes.size()-1)
00168                 {
00169                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].EndPolygonCount=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].MeshGeom-&gt;getNumTriangles (endDist);
00170                         <font class="keywordflow">if</font> (startPolyCount==<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].EndPolygonCount)
00171                                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].EndPolygonCount=startPolyCount/2;
00172                 }
00173                 <font class="keywordflow">else</font> 
00174                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].EndPolygonCount=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k+1].MeshGeom-&gt;getNumTriangles (endDist);
00175 
00176                 <font class="comment">// Calc A</font>
00177                 <font class="keywordflow">if</font> (endDist==startDist)
00178                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].A=0;
00179                 <font class="keywordflow">else</font>
00180                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].A=(<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].EndPolygonCount-startPolyCount)/(endDist-startDist);
00181 
00182                 <font class="comment">// Calc A</font>
00183                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].B=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].EndPolygonCount-<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[k].A*endDist;
00184         }
00185 
00186         <font class="comment">// End: compile the max distance of display</font>
00187         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#c3">compileDistMax</a>();
00188 }
00189 
00190 <font class="comment">// ***************************************************************************</font>
00191 
<a name="l00192"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#z582_0">00192</a> CTransformShape *CMeshMultiLod::createInstance(CScene &amp;scene)
00193 {
00194         <font class="comment">// Create a CMeshInstance, an instance of a multi lod mesh.</font>
00195         CMeshMultiLodInstance *mi=(CMeshMultiLodInstance*)scene.createModel(NL3D::MeshMultiLodInstanceId);
00196         mi-&gt;Shape= <font class="keyword">this</font>;
00197         mi-&gt;_LastLodMatrixDate[0]=0;
00198         mi-&gt;_LastLodMatrixDate[1]=0;
00199 
00200         <font class="comment">// instanciate the material part of the Mesh, ie the CMeshBase.</font>
00201         CMeshBase::instanciateMeshBase(mi, &amp;scene);
00202 
00203 
00204         <font class="comment">// For all lods, do some instance init for MeshGeom</font>
00205         <font class="keywordflow">for</font>(<a class="code" href="types__nl_8h.html#a14">uint</a> i=0; i&lt;<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>.size(); i++)
00206         {
00207                 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[i].MeshGeom)
00208                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[i].MeshGeom-&gt;initInstance(mi);
00209         }
00210 
00211 
00212         <font class="keywordflow">return</font> mi;
00213 }
00214 
00215 <font class="comment">// ***************************************************************************</font>
00216 
<a name="l00217"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#z582_1">00217</a> <font class="keywordtype">bool</font> CMeshMultiLod::clip(<font class="keyword">const</font> std::vector&lt;CPlane&gt;      &amp;pyramid, <font class="keyword">const</font> CMatrix &amp;worldMatrix)
00218 {
00219         <font class="comment">// Look for the biggest mesh</font>
00220         <a class="code" href="types__nl_8h.html#a14">uint</a> meshCount=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>.size();
00221         <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> i=0; i&lt;meshCount; i++)
00222         {
00223                 <font class="comment">// Ref on slot</font>
00224                 CMeshSlot &amp;slot=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[i];
00225 
00226                 <font class="comment">// Is mesh present ?</font>
00227                 <font class="keywordflow">if</font> (slot.MeshGeom)
00228                 {
00229                         <font class="comment">// Clip this mesh</font>
00230                         <font class="keywordflow">return</font> slot.MeshGeom-&gt;clip (pyramid, worldMatrix);
00231                 }
00232         }
00233         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00234 }
00235 
00236 <font class="comment">// ***************************************************************************</font>
00237 
<a name="l00238"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#z582_2">00238</a> <font class="keywordtype">void</font> CMeshMultiLod::render(IDriver *drv, CTransformShape *trans, <font class="keywordtype">bool</font> passOpaque)
00239 {
00240         <font class="comment">// Render good meshes</font>
00241         CMeshMultiLodInstance *instance=safe_cast&lt;CMeshMultiLodInstance*&gt;(trans);
00242 
00243         <font class="comment">// Static or dynamic coarse mesh ?</font>
00244         CCoarseMeshManager *manager;
00245         <font class="keywordflow">if</font> (_StaticLod)
00246         {
00247                 <font class="comment">// Get the static coarse mesh manager</font>
00248                 manager=instance-&gt;getScene()-&gt;getStaticCoarseMeshManager();
00249         }
00250         <font class="keywordflow">else</font>
00251         {
00252                 <font class="comment">// Get the dynamic coarse mesh manager</font>
00253                 manager=instance-&gt;getScene()-&gt;getDynamicCoarseMeshManager();
00254         }
00255 
00256         <font class="comment">// *** Render Lods</font>
00257 
00258         <font class="comment">// Second lod ?</font>
00259         <font class="keywordflow">if</font> ( (instance-&gt;Lod1!=0xffffffff) &amp;&amp; (passOpaque==<font class="keyword">false</font>) )
00260         {
00261                 <font class="comment">// build rdrFlags to rdr both transparent and opaque materials, </font>
00262                 <font class="comment">// use globalAlphaBlend, and disable ZWrite for Lod1</font>
00263                 <a class="code" href="types__nl_8h.html#a10">uint32</a>  rdrFlags= IMeshGeom::RenderOpaqueMaterial | IMeshGeom::RenderTransparentMaterial |
00264                         IMeshGeom::RenderGlobalAlpha | IMeshGeom::RenderGADisableZWrite;
00265                 <font class="comment">// NB: very important to render Lod1 first, because Lod0 is still rendered with ZWrite enabled.</font>
00266                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#c1">renderMeshGeom</a> (instance-&gt;Lod1, drv, instance, instance-&gt;PolygonCountLod1, rdrFlags, 1.f-instance-&gt;BlendFactor, manager);
00267         }
00268 
00269 
00270         <font class="comment">// Have an opaque pass ?</font>
00271         <font class="keywordflow">if</font> ( (instance-&gt;Flags&amp;CMeshMultiLodInstance::Lod0Blend) == 0)
00272         {
00273                 <font class="comment">// Is this slot a CoarseMesh?</font>
00274                 <font class="keywordflow">if</font> ( <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[instance-&gt;Lod0].Flags&amp;CMeshSlot::CoarseMesh )
00275                 {
00276                         <font class="comment">// render as a CoarseMesh the lod 0, only in opaque pass</font>
00277                         <font class="keywordflow">if</font>(passOpaque)
00278                                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#c2">renderCoarseMesh</a> (instance-&gt;Lod0, drv, instance, manager);
00279                 }
00280                 <font class="keywordflow">else</font>
00281                 {
00282                         <font class="comment">// build rdrFlags the normal way (as CMesh::render() for example)</font>
00283                         <a class="code" href="types__nl_8h.html#a10">uint32</a>  mask= (0-(uint32)passOpaque);
00284                         <a class="code" href="types__nl_8h.html#a10">uint32</a>  rdrFlags;
00285                         <font class="comment">// select rdrFlags, without ifs.</font>
00286                         rdrFlags=       mask &amp; (IMeshGeom::RenderOpaqueMaterial | IMeshGeom::RenderPassOpaque);
00287                         rdrFlags|=      ~mask &amp; (IMeshGeom::RenderTransparentMaterial);
00288                         <font class="comment">// Only render the normal way the first lod</font>
00289                         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#c1">renderMeshGeom</a> (instance-&gt;Lod0, drv, instance, instance-&gt;PolygonCountLod0, rdrFlags, 1, manager);
00290                 }
00291         }
00292         <font class="keywordflow">else</font>
00293         {
00294                 <font class="comment">// Should not be in opaque</font>
00295                 <a class="code" href="debug_8h.html#a6">nlassert</a> (passOpaque==<font class="keyword">false</font>);
00296 
00297                 <font class="comment">// build rdrFlags to rdr both transparent and opaque materials, </font>
00298                 <font class="comment">// use globalAlphaBlend, BUT Don't disable ZWrite for Lod0</font>
00299                 <a class="code" href="types__nl_8h.html#a10">uint32</a>  rdrFlags= IMeshGeom::RenderOpaqueMaterial | IMeshGeom::RenderTransparentMaterial |
00300                         IMeshGeom::RenderGlobalAlpha;
00301 
00302                 <font class="comment">// Render first lod in blend mode. Don't disable ZWrite for Lod0</font>
00303                 <a class="code" href="classNL3D_1_1CMeshMultiLod.html#c1">renderMeshGeom</a> (instance-&gt;Lod0, drv, instance, instance-&gt;PolygonCountLod0, rdrFlags, instance-&gt;BlendFactor, manager);
00304         }
00305 
00306         <font class="comment">// *** Remove unused coarse meshes.</font>
00307         <font class="comment">// Manager must exist beacuse a mesh has been loaded...</font>
00308         <font class="keywordflow">if</font> (manager)
00309         {
00310                 <a class="code" href="types__nl_8h.html#a14">uint</a> meshCount=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>.size();
00311                 <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> j=0; j&lt;meshCount; j++)
00312                 {
00313                         <font class="comment">// Is this slot a CoarseMesh?</font>
00314                         <font class="keywordflow">if</font> ( <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[j].Flags&amp;CMeshSlot::CoarseMesh )
00315                         {
00316                                 <font class="comment">// Are we in Alpha Blend Transition?</font>
00317                                 <font class="keywordtype">bool</font>    alphaTrans= instance-&gt;Flags&amp;CMeshMultiLodInstance::Lod0Blend;
00318                                 <font class="comment">// we must remove coarse if the slot is not used, or if we are in Alpha Transition.</font>
00319                                 <font class="comment">// NB: only Lod0 can use CoarseMesh (see code before)</font>
00320                                 <font class="keywordflow">if</font> ( alphaTrans || (j!=instance-&gt;Lod0) )
00321                                 {
00322                                         <font class="comment">// Get coarse id</font>
00323                                         <a class="code" href="types__nl_8h.html#a14">uint</a> coarseId=(<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[j].Flags&amp;CMeshSlot::CoarseMeshId)?1:0;
00324                                         <a class="code" href="types__nl_8h.html#a14">uint</a> flag=CMeshMultiLodInstance::Coarse0Loaded&lt;&lt;coarseId;
00325                                         
00326                                         <font class="comment">// Coarse mesh loaded ?</font>
00327                                         <font class="keywordflow">if</font> ( instance-&gt;Flags&amp;flag )
00328                                         {
00329                                                 <font class="comment">// Yes, remove it..</font>
00330 
00331                                                 <font class="comment">// Remove the lod</font>
00332                                                 manager-&gt;removeMesh (instance-&gt;CoarseMeshId[coarseId]);
00333 
00334                                                 <font class="comment">// Clear the flag</font>
00335                                                 instance-&gt;Flags&amp;=~flag;
00336                                         }
00337                                 }
00338                         }
00339                 }
00340         }
00341 }
00342 
00343 <font class="comment">// ***************************************************************************</font>
00344 
<a name="l00345"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#z582_5">00345</a> <font class="keywordtype">void</font> CMeshMultiLod::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &amp;f) <font class="keywordflow">throw</font>(NLMISC::EStream)
00346 {
00347         <font class="comment">// Serial a version number</font>
00348         (void)f.serialVersion (0);
00349 
00350         <font class="comment">// serial Materials infos contained in CMeshBase.</font>
00351         CMeshBase::serialMeshBase(f);
00352 
00353         <font class="comment">// Static lod flag</font>
00354         f.serial (_StaticLod);
00355 
00356         <font class="comment">// Serial the values</font>
00357         f.serialCont (_MeshVector);
00358 
00359 
00360         <font class="comment">// if reading, compile the new max distance of display</font>
00361         <font class="keywordflow">if</font> (f.isReading())
00362         {
00363                 compileDistMax();
00364         }
00365 }
00366 
00367 <font class="comment">// ***************************************************************************</font>
00368 
<a name="l00369"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#z582_3">00369</a> <font class="keywordtype">float</font> CMeshMultiLod::getNumTriangles (<font class="keywordtype">float</font> distance)
00370 {
00371         <font class="comment">// Look in the table for good distances..</font>
00372         <a class="code" href="types__nl_8h.html#a14">uint</a> meshCount=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>.size();
00373 
00374         <font class="comment">// At least on mesh</font>
00375         <font class="keywordflow">if</font> (meshCount&gt;0)
00376         {
00377                 <a class="code" href="types__nl_8h.html#a14">uint</a> i=0;
00378 
00379                 <font class="comment">// Look for good i</font>
00380                 <font class="keywordflow">while</font> ( <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[i].DistMax&lt;distance )
00381                 {
00382                         <font class="keywordflow">if</font> (i==meshCount-1)
00383                                 <font class="comment">// Abort if last one</font>
00384                                 <font class="keywordflow">break</font>;
00385                         i++;
00386                 }
00387 
00388                 <font class="comment">// Ref on slot</font>
00389                 CMeshSlot &amp;slot=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[i];
00390 
00391                 <font class="comment">// Is mesh present ?</font>
00392                 <font class="keywordflow">if</font> (slot.MeshGeom)
00393                 {
00394                         <font class="comment">// Get the polygon count with the distance</font>
00395                         <font class="keywordtype">float</font> polyCount=slot.A * distance + slot.B;
00396 
00397                         <font class="comment">/*// Get the perfect polygon count in this slot for the asked distance</font>
00398 <font class="comment">                        float goodPolyCount=slot.MeshGeom-&gt;getNumTriangles (distance);</font>
00399 <font class="comment"></font>
00400 <font class="comment">                        // Get the next slot perfect polygon count</font>
00401 <font class="comment">                        float realEndPolyCount;</font>
00402 <font class="comment"></font>
00403 <font class="comment">                        // Last slot ?</font>
00404 <font class="comment">                        if ( (i&lt;meshCount-1) &amp;&amp; _MeshVector[i+1].MeshGeom )</font>
00405 <font class="comment">                                // Take end number polygon count in the next slot</font>
00406 <font class="comment">                                realEndPolyCount=_MeshVector[i+1].MeshGeom-&gt;getNumTriangles (slot.DistMax);</font>
00407 <font class="comment">                        else</font>
00408 <font class="comment">                                // Take end number polygon count in the this slot</font>
00409 <font class="comment">                                realEndPolyCount=slot.EndPolygonCount;</font>
00410 <font class="comment"></font>
00411 <font class="comment">                        // Return blended polygon count to have a continous decreasing function</font>
00412 <font class="comment">                        return (goodPolyCount-slot.BeginPolygonCount) * (realEndPolyCount-slot.BeginPolygonCount) / </font>
00413 <font class="comment">                                (slot.EndPolygonCount-slot.BeginPolygonCount) + slot.BeginPolygonCount;*/</font>
00414                         <font class="keywordflow">return</font> polyCount;
00415                 }
00416         }
00417 
00418         <font class="keywordflow">return</font> 0;
00419 }
00420 
00421 <font class="comment">// ***************************************************************************</font>
00422 
<a name="l00423"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#z582_4">00423</a> <font class="keywordtype">void</font> CMeshMultiLod::getAABBox(<a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> &amp;bbox)<font class="keyword"> const</font>
00424 <font class="keyword"></font>{
00425         <font class="comment">// Get count</font>
00426         <a class="code" href="types__nl_8h.html#a14">uint</a> count=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>.size();
00427         <font class="keywordflow">for</font> (<a class="code" href="types__nl_8h.html#a14">uint</a> slot=0; slot&lt;count; slot++)
00428         {
00429                 <font class="comment">// Shape ?</font>
00430                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].MeshGeom)
00431                 {
00432                         <font class="comment">// Get the bounding box</font>
00433                         bbox=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].MeshGeom-&gt;getBoundingBox().getAABBox();
00434 
00435                         <font class="comment">// ok</font>
00436                         <font class="keywordflow">break</font>;
00437                 }
00438         }
00439 }
00440 
00441 <font class="comment">// ***************************************************************************</font>
00442 
<a name="l00443"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#c0">00443</a> <font class="keywordtype">void</font> CMeshMultiLod::clear ()
00444 {
00445         <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>.clear ();
00446 }
00447 
00448 <font class="comment">// ***************************************************************************</font>
00449 
<a name="l00450"></a><a class="code" href="classNL3D_1_1CMeshMultiLod_1_1CMeshSlot.html#a2">00450</a> <font class="keywordtype">void</font> CMeshMultiLod::CMeshSlot::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &amp;f) <font class="keywordflow">throw</font>(NLMISC::EStream)
00451 {
00452         <font class="comment">// Check version</font>
00453         (void)f.serialVersion (0);
00454 
00455         f.serialPolyPtr (MeshGeom);
00456         f.serial (A);
00457         f.serial (B);
00458         f.serial (DistMax);
00459         f.serial (EndPolygonCount);
00460         f.serial (BlendLength);
00461         f.serial (Flags);
00462 
00463         <font class="keywordflow">if</font> (f.isReading())
00464         {
00465         }
00466 }
00467 
00468 <font class="comment">// ***************************************************************************</font>
00469 
<a name="l00470"></a><a class="code" href="classNL3D_1_1CMeshMultiLod_1_1CMeshSlot.html#a0">00470</a> CMeshMultiLod::CMeshSlot::CMeshSlot ()
00471 {
00472         <a class="code" href="classNL3D_1_1CMeshMultiLod_1_1CMeshSlot.html#m0">MeshGeom</a>=NULL;
00473 }
00474 
00475 <font class="comment">// ***************************************************************************</font>
00476 
<a name="l00477"></a><a class="code" href="classNL3D_1_1CMeshMultiLod_1_1CMeshSlot.html#a1">00477</a> CMeshMultiLod::CMeshSlot::~CMeshSlot ()
00478 {
00479         <font class="keywordflow">if</font> (MeshGeom)
00480                 <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CMeshMultiLod_1_1CMeshSlot.html#m0">MeshGeom</a>;
00481 }
00482 
00483 <font class="comment">// ***************************************************************************</font>
00484 
<a name="l00485"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#c1">00485</a> <font class="keywordtype">void</font> CMeshMultiLod::renderMeshGeom (<a class="code" href="types__nl_8h.html#a14">uint</a> slot, IDriver *drv, CMeshMultiLodInstance *trans, <font class="keywordtype">float</font> numPoylgons, <a class="code" href="types__nl_8h.html#a10">uint32</a> rdrFlags, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a279">alpha</a>, CCoarseMeshManager *manager)
00486 {
00487         <font class="comment">// Ref</font>
00488         CMeshSlot &amp;slotRef=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot];
00489 
00490         <font class="comment">// MeshGeom exist?</font>
00491         <font class="keywordflow">if</font> (slotRef.MeshGeom)
00492         {
00493                 <font class="comment">// NB Here, the meshGeom may still be a coarseMesh, but rendered through CMeshGeom</font>
00494                 <font class="keywordflow">if</font>(slotRef.Flags&amp;CMeshSlot::CoarseMesh)
00495                 {
00496                         <font class="comment">// Render only for opaque material</font>
00497                         <font class="keywordflow">if</font>(manager &amp;&amp; (rdrFlags &amp; IMeshGeom::RenderOpaqueMaterial) )
00498                         {
00499                                 <font class="keywordtype">bool</font>    gaDisableZWrite= (rdrFlags &amp; IMeshGeom::RenderGADisableZWrite)?<font class="keyword">true</font>:<font class="keyword">false</font>;
00500 
00501                                 <font class="comment">// Render the CoarseMesh with the manager material</font>
00502                                 CMaterial       &amp;material= manager-&gt;getMaterial();
00503 
00504                                 <font class="comment">// modulate material for alphaBlend transition</font>
00505                                 <font class="comment">// ----------</font>
00506                                 <font class="comment">// get average sun color for this coarseMesh</font>
00507                                 CRGBA   newCol= trans-&gt;getCoarseMeshLighting();
00508 
00509                                 <font class="comment">// Use a CMeshBlender to modify material and driver.</font>
00510                                 CMeshBlender    blender;
00511                                 blender.prepareRenderForGlobalAlphaCoarseMesh(material, drv, newCol, <a class="code" href="driver__opengl__extension__def_8h.html#a279">alpha</a>, gaDisableZWrite);
00512                                 
00513 
00514                                 <font class="comment">// render simple the coarseMesh</font>
00515                                 CMeshGeom *meshGeom= safe_cast&lt;CMeshGeom*&gt;(slotRef.MeshGeom);
00516                                 meshGeom-&gt;renderSimpleWithMaterial(drv, trans-&gt;getWorldMatrix(), material);
00517 
00518 
00519                                 <font class="comment">// resetup standard CoarseMeshMaterial material values</font>
00520                                 <font class="comment">// ----------</font>
00521                                 <font class="comment">// blender restore</font>
00522                                 blender.restoreRenderCoarseMesh(material, drv, gaDisableZWrite);
00523                         }
00524                 }
00525                 <font class="keywordflow">else</font>
00526                 {
00527                         <font class="comment">// Render the geom mesh</font>
00528                         <font class="comment">// Disable ZWrite only if in transition and for rendering Lod1</font>
00529                         slotRef.MeshGeom-&gt;render (drv, trans, numPoylgons, rdrFlags, <a class="code" href="driver__opengl__extension__def_8h.html#a279">alpha</a>);
00530                 }
00531         }
00532 }
00533 <font class="comment">// ***************************************************************************</font>
00534 
<a name="l00535"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#c2">00535</a> <font class="keywordtype">void</font> CMeshMultiLod::renderCoarseMesh (<a class="code" href="types__nl_8h.html#a14">uint</a> slot, IDriver *drv, CMeshMultiLodInstance *trans, CCoarseMeshManager *manager)
00536 {
00537         <font class="comment">// if the manager is NULL, quit.</font>
00538         <font class="keywordflow">if</font>(manager==NULL)
00539                 <font class="keywordflow">return</font>;
00540 
00541         <font class="comment">// Ref</font>
00542         CMeshSlot &amp;slotRef=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot];
00543 
00544         <font class="comment">// the slot must be a Coarse mesh</font>
00545         <a class="code" href="debug_8h.html#a6">nlassert</a>(slotRef.Flags&amp;CMeshSlot::CoarseMesh);
00546 
00547         <font class="comment">// Mask</font>
00548         <a class="code" href="types__nl_8h.html#a14">uint</a> coarseId=(slotRef.Flags&amp;CMeshSlot::CoarseMeshId)?1:0;
00549         <a class="code" href="types__nl_8h.html#a14">uint</a> maskFlag = CMeshMultiLodInstance::Coarse0Loaded&lt;&lt;coarseId;
00550 
00551         <font class="comment">// Get a pointer on the geom mesh</font>
00552         CMeshGeom *meshGeom= safe_cast&lt;CMeshGeom*&gt;(slotRef.MeshGeom);
00553 
00554         <font class="comment">// Added in the manager ?</font>
00555         <font class="keywordflow">if</font> ( (trans-&gt;Flags&amp;maskFlag) == 0)
00556         {
00557                 <font class="comment">// Add to the manager</font>
00558                 trans-&gt;CoarseMeshId[coarseId]=manager-&gt;addMesh (*meshGeom);
00559                         
00560                 <font class="comment">// Added ?</font>
00561                 <font class="keywordflow">if</font> (trans-&gt;CoarseMeshId[coarseId]!=CCoarseMeshManager::CantAddCoarseMesh)
00562                         <font class="comment">// Flag it</font>
00563                         trans-&gt;Flags|=maskFlag;
00564 
00565                 <font class="comment">// Dirt the matrix</font>
00566                 trans-&gt;_LastLodMatrixDate[coarseId]=0;
00567                 <font class="comment">// Dirt the lighting. NB: period maximum is 255. Hence the -256, to ensure lighting compute now</font>
00568                 trans-&gt;_LastLodLightingDate[coarseId]= -0x100;
00569         }
00570 
00571         <font class="comment">// Finally loaded ?</font>
00572         <font class="keywordflow">if</font> (trans-&gt;Flags&amp;maskFlag)
00573         {
00574                 <font class="comment">// Matrix has changed ?</font>
00575                 <font class="keywordflow">if</font> ( trans-&gt;ITransformable::compareMatrixDate (trans-&gt;_LastLodMatrixDate[coarseId]) )
00576                 {
00577                         <font class="comment">// Get date</font>
00578                         trans-&gt;_LastLodMatrixDate[coarseId] = trans-&gt;ITransformable::getMatrixDate();
00579 
00580                         <font class="comment">// Set matrix</font>
00581                         manager-&gt;setMatrixMesh ( trans-&gt;CoarseMeshId[coarseId], *meshGeom, trans-&gt;getMatrix() );
00582                 }
00583 
00584                 <font class="comment">// Lighting: test if must update lighting, according to date of HrcTrav (num of CScene::render() call).</font>
00585                 CScene  *scene= trans-&gt;getScene();
00586                 <font class="keywordflow">if</font>(scene)
00587                 {
00588                         <a class="code" href="types__nl_8h.html#a11">sint64</a>  currentDate= scene-&gt;getHrcTrav()-&gt;CurrentDate;
00589                         <font class="keywordflow">if</font>( trans-&gt;_LastLodLightingDate[coarseId] &lt; currentDate - scene-&gt;getCoarseMeshLightingUpdate() )
00590                         {
00591                                 <font class="comment">// reset the date.</font>
00592                                 trans-&gt;_LastLodLightingDate[coarseId]= currentDate;
00593 
00594                                 <font class="comment">// get average sun color</font>
00595                                 CRGBA   sunContrib= trans-&gt;getCoarseMeshLighting();
00596 
00597                                 <font class="comment">// Set color</font>
00598                                 manager-&gt;setColorMesh ( trans-&gt;CoarseMeshId[coarseId], *meshGeom, sunContrib );
00599                         }
00600                 }
00601         }
00602 }
00603 
00604 <font class="comment">// ***************************************************************************</font>
<a name="l00605"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#c3">00605</a> <font class="keywordtype">void</font>    CMeshMultiLod::compileDistMax()
00606 {
00607         <font class="comment">// Last element</font>
00608         std::vector&lt;CMeshSlot&gt;::const_iterator ite=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>.end();
00609         ite--;
00610         <font class="keywordflow">if</font> (ite!=<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>.end())
00611                 IShape::_DistMax= ite-&gt;DistMax;
00612         <font class="keywordflow">else</font>
00613                 IShape::_DistMax= -1;
00614 }
00615 
00616 <font class="comment">// ***************************************************************************</font>
<a name="l00617"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#a0">00617</a> <font class="keyword">const</font> IMeshGeom&amp; CMeshMultiLod::getMeshGeom (<a class="code" href="types__nl_8h.html#a14">uint</a> slot)<font class="keyword"> const</font>
00618 <font class="keyword"></font>{
00619         <font class="comment">// Checks</font>
00620         <a class="code" href="debug_8h.html#a6">nlassert</a> (slot&lt;<a class="code" href="classNL3D_1_1CMeshMultiLod.html#a1">getNumSlotMesh</a> ());
00621 
00622         <font class="keywordflow">return</font> *<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].MeshGeom;
00623 }
00624 
00625 
00626 <font class="comment">// ***************************************************************************</font>
<a name="l00627"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#a4">00627</a> <font class="keywordtype">void</font>                    CMeshMultiLod::changeMRMDistanceSetup(<font class="keywordtype">float</font> distanceFinest, <font class="keywordtype">float</font> distanceMiddle, <font class="keywordtype">float</font> distanceCoarsest)
00628 {
00629         <font class="comment">// no-op if empty.</font>
00630         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CMeshMultiLod.html#a1">getNumSlotMesh</a> ()==0)
00631                 <font class="keywordflow">return</font>;
00632 
00633         <font class="comment">// If not NULL</font>
00634         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[0].MeshGeom==NULL)
00635                 <font class="keywordflow">return</font>;
00636 
00637         <font class="comment">// verify it is a CMeshMRMGeom. else no-op.</font>
00638         CMeshMRMGeom    *mgeom= dynamic_cast&lt;CMeshMRMGeom*&gt;(<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[0].MeshGeom);
00639         <font class="keywordflow">if</font>(mgeom==NULL)
00640                 <font class="keywordflow">return</font>;
00641         
00642         <font class="comment">// ok, setup.</font>
00643         mgeom-&gt;changeMRMDistanceSetup(distanceFinest, distanceMiddle, distanceCoarsest);
00644 }
00645 
00646 
00647 <font class="comment">// ***************************************************************************</font>
<a name="l00648"></a><a class="code" href="classNL3D_1_1CMeshMultiLod.html#z583_0">00648</a> IMeshGeom               *CMeshMultiLod::supportMeshBlockRendering (CTransformShape *trans, <font class="keywordtype">float</font> &amp;polygonCount )<font class="keyword"> const</font>
00649 <font class="keyword"></font>{
00650         IMeshGeom       *ret= NULL;
00651 
00652         <font class="comment">// get the instance</font>
00653         CMeshMultiLodInstance *instance=safe_cast&lt;CMeshMultiLodInstance*&gt;(trans);
00654 
00655         <font class="comment">// Must not be in blend transition.</font>
00656         <font class="keywordflow">if</font> ( (instance-&gt;Flags&amp;CMeshMultiLodInstance::Lod0Blend) == 0)
00657         {
00658                 <a class="code" href="types__nl_8h.html#a14">uint</a>    slot= instance-&gt;Lod0;
00659                 <font class="comment">// The slot must not be a CoarseMesh</font>
00660                 <font class="keywordflow">if</font> ( (<a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].Flags&amp;CMeshSlot::CoarseMesh)==0 )
00661                 {
00662                         <font class="comment">// MeshGeom exist?</font>
00663                         ret= <a class="code" href="classNL3D_1_1CMeshMultiLod.html#o1">_MeshVector</a>[slot].MeshGeom;
00664                 }
00665         }
00666 
00667         <font class="comment">// Ok if meshGeom is ok.</font>
00668         <font class="keywordflow">if</font>( ret &amp;&amp; ret-&gt;supportMeshBlockRendering() )
00669         {
00670                 polygonCount= instance-&gt;PolygonCountLod0;
00671                 <font class="keywordflow">return</font> ret;
00672         }
00673         <font class="keywordflow">else</font>
00674                 <font class="keywordflow">return</font> NULL;
00675 }
00676 
00677 
00678 } <font class="comment">// NL3D</font>
</pre></div>

<!-- footer -->
<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
</TD>
<TD WIDTH=15><IMG  SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>