aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/mesh__morpher_8cpp-source.html
blob: b644e84f8bfd08e4ce8f00aa5b5f33df2d2a5919 (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
<!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_morpher.cpp</h1><a href="mesh__morpher_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__morpher_8h.html">3d/mesh_morpher.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="vertex__buffer_8h.html">3d/vertex_buffer.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="vertex__buffer__hard_8h.html">3d/vertex_buffer_hard.h</a>"</font>
00031 
00032 
00033 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00034 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00035 
00036 
00037 <font class="keyword">namespace </font>NL3D 
00038 {
00039 
00040 <font class="comment">// ***************************************************************************</font>
<a name="l00041"></a><a class="code" href="classNL3D_1_1CBlendShape.html#a0">00041</a> <font class="keywordtype">void</font> CBlendShape::serial (<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &amp;f) <font class="keywordflow">throw</font>(NLMISC::EStream)
00042 {
00043         <font class="comment">// version 1 : added tangent space support</font>
00044         sint ver = f.serialVersion (1);
00045 
00046         f.serial (Name);
00047 
00048         f.serialCont (deltaPos);
00049         f.serialCont (deltaNorm);
00050         f.serialCont (deltaUV);
00051         f.serialCont (deltaCol);
00052 
00053         <font class="keywordflow">if</font> (ver &gt;= 1) f.serialCont(deltaTgSpace);
00054 
00055         f.serialCont (VertRefs);
00056 }
00057 
00058 <font class="comment">// ***************************************************************************</font>
<a name="l00059"></a><a class="code" href="classNL3D_1_1CMeshMorpher.html#a0">00059</a> CMeshMorpher::CMeshMorpher()
00060 {
00061         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a> = NULL;
00062         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a> = NULL;
00063         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o2">_VBDstHrd</a> = NULL;
00064 
00065         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o3">_Vertices</a> = NULL;
00066         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o4">_Normals</a> = NULL;
00067         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o5">_TgSpace</a>= NULL;
00068         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o6">_SkinApplied</a>= <font class="keyword">false</font>;
00069 }
00070 
00071 <font class="comment">// ***************************************************************************</font>
<a name="l00072"></a><a class="code" href="classNL3D_1_1CMeshMorpher.html#a1">00072</a> <font class="keywordtype">void</font> CMeshMorpher::init (CVertexBuffer *vbOri, CVertexBuffer *vbDst, IVertexBufferHard *vbDstHrd, <font class="keywordtype">bool</font> hasTgSpace)
00073 {
00074         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a> = vbOri;
00075         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a> = vbDst;
00076         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o2">_VBDstHrd</a> = vbDstHrd;
00077         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o7">_UseTgSpace</a> = hasTgSpace;
00078 }
00079 
00080 <font class="comment">// ***************************************************************************</font>
<a name="l00081"></a><a class="code" href="classNL3D_1_1CMeshMorpher.html#a2">00081</a> <font class="keywordtype">void</font> CMeshMorpher::initSkinned (CVertexBuffer *vbOri,
00082                                                         CVertexBuffer *vbDst,
00083                                                         IVertexBufferHard *vbDstHrd,
00084                                                         <font class="keywordtype">bool</font> hasTgSpace,
00085                                                         std::vector&lt;CVector&gt; *vVertices,
00086                                                         std::vector&lt;CVector&gt; *vNormals,
00087                                                         std::vector&lt;CVector&gt; *vTgSpace, <font class="comment">/* NULL if none */</font>
00088                                                         <font class="keywordtype">bool</font> bSkinApplied       )
00089 {
00090         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a> = vbOri;
00091         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a> = vbDst;
00092         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o2">_VBDstHrd</a> = vbDstHrd;
00093         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o7">_UseTgSpace</a> = hasTgSpace;
00094 
00095         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o3">_Vertices</a> = vVertices;
00096         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o4">_Normals</a> = vNormals;
00097         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o5">_TgSpace</a> = vTgSpace;
00098         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o6">_SkinApplied</a> = bSkinApplied;
00099 }
00100 
00101 <font class="comment">// ***************************************************************************</font>
<a name="l00102"></a><a class="code" href="classNL3D_1_1CMeshMorpher.html#a3">00102</a> <font class="keywordtype">void</font> CMeshMorpher::update (std::vector&lt;CAnimatedMorph&gt; *pBSFactor)
00103 {
00104         uint32 i, j;
00105 
00106         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a> == NULL)
00107                 <font class="keywordflow">return</font>;
00108         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#m0">BlendShapes</a>.size() == 0)
00109                 <font class="keywordflow">return</font>;
00110 
00111         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getNumVertices() != <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getNumVertices())
00112         {       <font class="comment">// Because the original vertex buffer is not initialized by default</font>
00113                 <font class="comment">// we must init it here (if there are some blendshapes)</font>
00114                 *<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a> = *<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>;
00115         }
00116 
00117         <font class="comment">// Does the flags are reserved ?</font>
00118         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.size() != <a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getNumVertices())
00119         {
00120                 <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.resize (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getNumVertices());
00121                 <font class="keywordflow">for</font> (i = 0; i &lt; <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.size(); ++i)
00122                         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] = <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u2">Modified</a>; <font class="comment">// Modified to update all</font>
00123         }
00124 
00125         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getVertexFormat() == <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexFormat());
00126 
00127         <font class="comment">// Cleaning with original vertex buffer</font>
00128         uint32 VBVertexSize = <a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getVertexSize();
00129         uint8 *pOri = (uint8*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getVertexCoordPointer ();
00130         uint8 *pDst = (uint8*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexCoordPointer ();
00131         
00132         <font class="keywordflow">for</font> (i= 0; i &lt; <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.size(); ++i)
00133         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] &gt;= <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u2">Modified</a>)
00134         {
00135                 <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] = <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u1">OriginalVBDst</a>;
00136 
00137                 <font class="keywordflow">for</font>(j = 0; j &lt; VBVertexSize; ++j)
00138                         pDst[j+i*VBVertexSize] = pOri[j+i*VBVertexSize];
00139         }
00140 
00141         uint tgSpaceStage = 0;
00142         <font class="keywordflow">if</font> (_UseTgSpace)
00143         {
00144                 tgSpaceStage = <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getNumTexCoordUsed() - 1;
00145         }
00146 
00147         <font class="comment">// Blending with blendshape</font>
00148         <font class="keywordflow">for</font> (i = 0; i &lt; <a class="code" href="classNL3D_1_1CMeshMorpher.html#m0">BlendShapes</a>.size(); ++i)
00149         {
00150                 CBlendShape &amp;rBS = <a class="code" href="classNL3D_1_1CMeshMorpher.html#m0">BlendShapes</a>[i];
00151                 <font class="keywordtype">float</font> rFactor = pBSFactor-&gt;operator[](i).getFactor()/100.0f;
00152 
00153                 <font class="keywordflow">if</font> (rFactor &gt; 0.0f)
00154                 <font class="keywordflow">for</font> (j = 0; j &lt; rBS.VertRefs.size(); ++j)
00155                 {
00156                         uint32 vp = rBS.VertRefs[j];
00157 
00158                         <font class="comment">// Modify Pos/Norm/TgSpace.</font>
00159                         <font class="comment">//------------</font>
00160                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexFormat() &amp; CVertexBuffer::PositionFlag)
00161                         <font class="keywordflow">if</font> (rBS.deltaPos.size() &gt; 0)
00162                         {
00163                                 CVector *pV = (CVector*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexCoordPointer (vp);
00164                                 *pV += rBS.deltaPos[j] * rFactor;
00165                         }
00166 
00167                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexFormat() &amp; CVertexBuffer::NormalFlag)
00168                         <font class="keywordflow">if</font> (rBS.deltaNorm.size() &gt; 0)
00169                         {
00170                                 CVector *pV = (CVector*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getNormalCoordPointer (vp);
00171                                 *pV += rBS.deltaNorm[j] * rFactor;
00172                         }
00173 
00174                         <font class="keywordflow">if</font> (_UseTgSpace)
00175                         <font class="keywordflow">if</font> (rBS.deltaTgSpace.size() &gt; 0)
00176                         {
00177                                 CVector *pV = (CVector*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getTexCoordPointer (vp, tgSpaceStage);
00178                                 *pV += rBS.deltaTgSpace[j] * rFactor;
00179                         }
00180 
00181                         <font class="comment">// Modify UV0 / Color</font>
00182                         <font class="comment">//------------</font>
00183                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexFormat() &amp; CVertexBuffer::TexCoord0Flag)
00184                         <font class="keywordflow">if</font> (rBS.deltaUV.size() &gt; 0)
00185                         {
00186                                 CUV *pUV = (CUV*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getTexCoordPointer (vp);
00187                                 *pUV += rBS.deltaUV[j] * rFactor;
00188                         }
00189 
00190                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexFormat() &amp; CVertexBuffer::PrimaryColorFlag)
00191                         <font class="keywordflow">if</font> (rBS.deltaCol.size() &gt; 0)
00192                         {
00193                                 CRGBA *pRGBA = (CRGBA*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getColorPointer (vp);
00194                                 CRGBAF rgbf(*pRGBA);
00195                                 rgbf.R += rBS.deltaCol[j].R * rFactor;
00196                                 rgbf.G += rBS.deltaCol[j].G * rFactor;
00197                                 rgbf.B += rBS.deltaCol[j].B * rFactor;
00198                                 rgbf.A += rBS.deltaCol[j].A * rFactor;
00199                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(rgbf.R, 0.0f, 1.0f);
00200                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(rgbf.G, 0.0f, 1.0f);
00201                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(rgbf.B, 0.0f, 1.0f);
00202                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(rgbf.A, 0.0f, 1.0f);
00203                                 *pRGBA = rgbf;
00204                         }
00205 
00206                         <font class="comment">// Modified</font>
00207                         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[vp] = <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u2">Modified</a>;
00208                 }
00209         }
00210 
00211         <font class="comment">// Copying to hardware vertex buffer if some</font>
00212         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o2">_VBDstHrd</a> != NULL)
00213         {
00214                 uint8 *pDstHrd = (uint8*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o2">_VBDstHrd</a>-&gt;lock();
00215                 <font class="keywordflow">for</font> (i = 0; i &lt; <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.size(); ++i)
00216                 {
00217                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] != <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u0">OriginalAll</a>) <font class="comment">// Not OriginalAll ?</font>
00218                         {
00219                                 <font class="keywordflow">for</font>(j = 0; j &lt; VBVertexSize; ++j)
00220                                         pDstHrd[j+i*VBVertexSize] = pDst[j+i*VBVertexSize];
00221                         }
00222                         <font class="comment">// if this vertex is original in the VBDst</font>
00223                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] == <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u1">OriginalVBDst</a>)
00224                                 <font class="comment">// then it is now copied into the VBHard</font>
00225                                 <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] = <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u0">OriginalAll</a>;
00226                 }
00227                 <a class="code" href="classNL3D_1_1CMeshMorpher.html#o2">_VBDstHrd</a>-&gt;unlock();
00228         }
00229 }
00230 
00231 
00232 <font class="comment">// ***************************************************************************</font>
<a name="l00233"></a><a class="code" href="classNL3D_1_1CMeshMorpher.html#a4">00233</a> <font class="keywordtype">void</font> CMeshMorpher::updateSkinned (std::vector&lt;CAnimatedMorph&gt; *pBSFactor)
00234 {
00235         uint32 i, j;
00236 
00237         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a> == NULL)
00238                 <font class="keywordflow">return</font>;
00239         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#m0">BlendShapes</a>.size() == 0)
00240                 <font class="keywordflow">return</font>;
00241 
00242         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getNumVertices() != <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getNumVertices())
00243         {       <font class="comment">// Because the original vertex buffer is not initialized by default</font>
00244                 <font class="comment">// we must init it here (if there are some blendshapes)</font>
00245                 *<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a> = *<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>;
00246         }
00247 
00248         <font class="comment">// Does the flags are reserved ?</font>
00249         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.size() != <a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getNumVertices())
00250         {
00251                 <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.resize (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getNumVertices());
00252                 <font class="keywordflow">for</font> (i = 0; i &lt; <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.size(); ++i)
00253                         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] = <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u2">Modified</a>; <font class="comment">// Modified to update all</font>
00254         }
00255 
00256         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getVertexFormat() == <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexFormat());
00257 
00258         uint tgSpaceStage;
00259         uint tgSpaceOff = 0;
00260         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o7">_UseTgSpace</a> &amp;&amp; <a class="code" href="classNL3D_1_1CMeshMorpher.html#o5">_TgSpace</a>)
00261         {
00262                 tgSpaceStage = <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getNumTexCoordUsed() - 1;
00263                 tgSpaceOff = <a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getTexCoordOff(tgSpaceStage);
00264         }
00265 
00266         <font class="comment">// Cleaning with original vertex buffer</font>
00267         uint32 VBVertexSize = <a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getVertexSize();
00268         uint8 *pOri = (uint8*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o0">_VBOri</a>-&gt;getVertexCoordPointer ();
00269         uint8 *pDst = (uint8*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexCoordPointer ();
00270         
00271         <font class="keywordflow">for</font> (i= 0; i &lt; <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.size(); ++i)
00272         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] &gt;= <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u2">Modified</a>)
00273         {
00274                 <font class="keywordflow">for</font>(j = 0; j &lt; VBVertexSize; ++j)
00275                         pDst[j+i*VBVertexSize] = pOri[j+i*VBVertexSize];
00276                 
00277                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o3">_Vertices</a> != NULL)
00278                         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o3">_Vertices</a>-&gt;operator[](i) = ((CVector*)(pOri+i*VBVertexSize))[0];
00279 
00280                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o4">_Normals</a> != NULL)
00281                         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o4">_Normals</a>-&gt;operator[](i) = ((CVector*)(pOri+i*VBVertexSize))[1];
00282 
00283                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o5">_TgSpace</a> != NULL)
00284                         (*_TgSpace)[i] = * (CVector*)(pOri + i * VBVertexSize + tgSpaceOff);
00285                         
00286                 <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] = <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u1">OriginalVBDst</a>;
00287         }
00288 
00289         <font class="comment">// Blending with blendshape</font>
00290         <font class="keywordflow">for</font> (i = 0; i &lt; <a class="code" href="classNL3D_1_1CMeshMorpher.html#m0">BlendShapes</a>.size(); ++i)
00291         {
00292                 CBlendShape &amp;rBS = <a class="code" href="classNL3D_1_1CMeshMorpher.html#m0">BlendShapes</a>[i];
00293                 <font class="keywordtype">float</font> rFactor = pBSFactor-&gt;operator[](i).getFactor()/100.0f;
00294 
00295                 <font class="keywordflow">if</font> (rFactor &gt; 0.0f)
00296                 <font class="keywordflow">for</font> (j = 0; j &lt; rBS.VertRefs.size(); ++j)
00297                 {
00298                         uint32 vp = rBS.VertRefs[j];
00299 
00300                         <font class="comment">// Modify Pos/Norm/TgSpace.</font>
00301                         <font class="comment">//------------</font>
00302                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o3">_Vertices</a> != NULL)
00303                         <font class="keywordflow">if</font> (rBS.deltaPos.size() &gt; 0)
00304                         {
00305                                 CVector *pV = &amp;(<a class="code" href="classNL3D_1_1CMeshMorpher.html#o3">_Vertices</a>-&gt;operator[](vp));
00306                                 *pV += rBS.deltaPos[j] * rFactor;
00307                         }
00308 
00309                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o4">_Normals</a> != NULL)
00310                         <font class="keywordflow">if</font> (rBS.deltaNorm.size() &gt; 0)
00311                         {
00312                                 CVector *pV = &amp;(<a class="code" href="classNL3D_1_1CMeshMorpher.html#o4">_Normals</a>-&gt;operator[](vp));
00313                                 *pV += rBS.deltaNorm[j] * rFactor;
00314                         }
00315 
00316                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o7">_UseTgSpace</a> &amp;&amp; <a class="code" href="classNL3D_1_1CMeshMorpher.html#o5">_TgSpace</a> != NULL)
00317                         <font class="keywordflow">if</font> (rBS.deltaTgSpace.size() &gt; 0)
00318                         {
00319                                 CVector *pV = &amp;((*_TgSpace)[vp]);
00320                                 *pV += rBS.deltaTgSpace[j] * rFactor;
00321                         }
00322 
00323                         <font class="comment">// Modify UV0 / Color</font>
00324                         <font class="comment">//------------</font>
00325                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexFormat() &amp; CVertexBuffer::TexCoord0Flag)
00326                         <font class="keywordflow">if</font> (rBS.deltaUV.size() &gt; 0)
00327                         {
00328                                 CUV *pUV = (CUV*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getTexCoordPointer (vp);
00329                                 *pUV += rBS.deltaUV[j] * rFactor;
00330                         }
00331 
00332                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getVertexFormat() &amp; CVertexBuffer::PrimaryColorFlag)
00333                         <font class="keywordflow">if</font> (rBS.deltaCol.size() &gt; 0)
00334                         {
00335                                 CRGBA *pRGBA = (CRGBA*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o1">_VBDst</a>-&gt;getColorPointer (vp);
00336                                 CRGBAF rgbf(*pRGBA);
00337                                 rgbf.R += rBS.deltaCol[j].R * rFactor;
00338                                 rgbf.G += rBS.deltaCol[j].G * rFactor;
00339                                 rgbf.B += rBS.deltaCol[j].B * rFactor;
00340                                 rgbf.A += rBS.deltaCol[j].A * rFactor;
00341                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(rgbf.R, 0.0f, 1.0f);
00342                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(rgbf.G, 0.0f, 1.0f);
00343                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(rgbf.B, 0.0f, 1.0f);
00344                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(rgbf.A, 0.0f, 1.0f);
00345                                 *pRGBA = rgbf;
00346                         }
00347 
00348                         <font class="comment">// Modified</font>
00349                         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[vp] = <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u2">Modified</a>;
00350                 }
00351         }
00352 
00353         <font class="comment">// Do some transfert to the VBHard if exist.</font>
00354         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o2">_VBDstHrd</a> != NULL)
00355         {
00356                 <font class="comment">// lock.</font>
00357                 uint8 *pDstHrd = (uint8*)<a class="code" href="classNL3D_1_1CMeshMorpher.html#o2">_VBDstHrd</a>-&gt;lock();
00358 
00359                 <font class="comment">// If the skin is applied we have nothing to do </font>
00360                 <font class="comment">// Because the skinning will transfert ALL the vertices of interest</font>
00361                 <font class="keywordflow">if</font> (!<a class="code" href="classNL3D_1_1CMeshMorpher.html#o6">_SkinApplied</a>) 
00362                 {
00363                         <font class="keywordflow">for</font> (i = 0; i &lt; <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>.size(); ++i)
00364                         {
00365                                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] != <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u0">OriginalAll</a>) <font class="comment">// Not OriginalAll ?</font>
00366                                 {
00367                                         <font class="comment">// We must write the whole vertex because the skinning may not copy </font>
00368                                         <font class="comment">// vertex and normal changes into VBHard</font>
00369                                         <font class="keywordflow">for</font>(j = 0; j &lt; VBVertexSize; ++j)
00370                                                 pDstHrd[j+i*VBVertexSize] = pDst[j+i*VBVertexSize];
00371                                 }
00372                                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] == <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u1">OriginalVBDst</a>) <font class="comment">// OriginalVBDst ?</font>
00373                                         <a class="code" href="classNL3D_1_1CMeshMorpher.html#o8">_Flags</a>[i] = <a class="code" href="classNL3D_1_1CMeshMorpher.html#u3u0">OriginalAll</a>; <font class="comment">// So OriginalAll !</font>
00374                         }
00375                 }
00376 
00377                 <font class="comment">// unlock.</font>
00378                 <a class="code" href="classNL3D_1_1CMeshMorpher.html#o2">_VBDstHrd</a>-&gt;unlock();
00379         }
00380 }
00381 
00382 <font class="comment">// ***************************************************************************</font>
<a name="l00383"></a><a class="code" href="classNL3D_1_1CMeshMorpher.html#a5">00383</a> <font class="keywordtype">void</font> CMeshMorpher::serial (<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &amp;f) <font class="keywordflow">throw</font>(NLMISC::EStream)
00384 {
00385         (void)f.serialVersion (0);
00386 
00387         f.serialCont (BlendShapes);
00388 }
00389 
00390 
00391 } <font class="comment">// NL3D</font>
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 
00401 
</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>