/
SkeletonX.cpp
629 lines (575 loc) · 20.6 KB
/
SkeletonX.cpp
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
// SkeletonX.cpp: implementation of the CSkeletonX class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "../../xr_3da/Render.h"
#include "SkeletonX.h"
#include "SkeletonCustom.h"
#include "../../xr_3da/fmesh.h"
#include "../../xr_3da/xrSkinXW.hpp"
//Для экспериментов
//#define QUATERNION_SKINNING
constexpr const char* s_bones_array_const = "sbones_array";
//////////////////////////////////////////////////////////////////////
// Body Part
//////////////////////////////////////////////////////////////////////
void CSkeletonX::AfterLoad(CKinematics* parent, u16 child_idx)
{
SetParent(parent);
ChildIDX = child_idx;
}
void CSkeletonX::_Copy(CSkeletonX* B)
{
Parent = NULL;
ChildIDX = B->ChildIDX;
Vertices1W = B->Vertices1W;
Vertices2W = B->Vertices2W;
Vertices3W = B->Vertices3W;
Vertices4W = B->Vertices4W;
BonesUsed = B->BonesUsed;
// caution - overlapped (union)
cache_DiscardID = B->cache_DiscardID;
cache_vCount = B->cache_vCount;
cache_vOffset = B->cache_vOffset;
RenderMode = B->RenderMode;
RMS_boneid = B->RMS_boneid;
RMS_bonecount = B->RMS_bonecount;
m_Indices = B->m_Indices;
}
//////////////////////////////////////////////////////////////////////
void CSkeletonX::_Render(ref_geom& hGeom, u32 vCount, u32 iOffset, u32 pCount)
{
RCache.stat.r.s_dynamic.add(vCount);
switch (RenderMode)
{
case RM_SKINNING_SOFT:
_Render_soft(hGeom, vCount, iOffset, pCount);
RCache.stat.r.s_dynamic_sw.add(vCount);
break;
case RM_SINGLE: {
Fmatrix W;
W.mul_43(RCache.xforms.m_w, Parent->LL_GetTransform_R(u16(RMS_boneid)));
RCache.set_xform_world(W);
RCache.set_Geometry(hGeom);
RCache.Render(D3DPT_TRIANGLELIST, 0, 0, vCount, iOffset, pCount);
RCache.stat.r.s_dynamic_inst.add(vCount);
}
break;
case RM_SKINNING_1B:
case RM_SKINNING_2B:
case RM_SKINNING_3B:
case RM_SKINNING_4B: {
// transfer matrices
#ifdef QUATERNION_SKINNING
const u32 c_bones_array_size = RMS_bonecount * sizeof(Fvector4) * 2;
#else
const u32 c_bones_array_size = RMS_bonecount * sizeof(Fvector4) * 3;
#endif
Fvector4* c_bones_array{};
RCache.get_ConstantDirect(s_bones_array_const, c_bones_array_size, reinterpret_cast<void**>(&c_bones_array), nullptr, nullptr);
if (c_bones_array)
{
for (u32 mid = 0; mid < RMS_bonecount; mid++)
{
const Fmatrix& M = Parent->LL_GetTransform_R(u16(mid));
#ifdef QUATERNION_SKINNING
using namespace DirectX;
XMVECTOR scale;
XMMatrixDecompose(&scale, reinterpret_cast<XMVECTOR*>(c_bones_array), reinterpret_cast<XMVECTOR*>(c_bones_array + 1), *reinterpret_cast<FXMMATRIX*>(&M));
c_bones_array += 2;
#else
c_bones_array->set(M._11, M._21, M._31, M._41);
c_bones_array++;
c_bones_array->set(M._12, M._22, M._32, M._42);
c_bones_array++;
c_bones_array->set(M._13, M._23, M._33, M._43);
c_bones_array++;
#endif
}
}
else
{
static bool logged{}; //чтоб не спамить в лог по сто раз за кадр.
if (!logged)
{
logged = true;
Msg("!![%s] Can't get/create sbones_array for model [%s] vith [%u] bones. Most likely, an incorrect shader is assigned there.", __FUNCTION__,
this->Parent->dbg_name.c_str(), RMS_bonecount);
}
}
// render
RCache.set_Geometry(hGeom);
RCache.Render(D3DPT_TRIANGLELIST, 0, 0, vCount, iOffset, pCount);
if (RM_SKINNING_1B == RenderMode)
RCache.stat.r.s_dynamic_1B.add(vCount);
else if (RM_SKINNING_2B == RenderMode)
RCache.stat.r.s_dynamic_2B.add(vCount);
else if (RM_SKINNING_3B == RenderMode)
RCache.stat.r.s_dynamic_3B.add(vCount);
else if (RM_SKINNING_4B == RenderMode)
RCache.stat.r.s_dynamic_4B.add(vCount);
}
break;
}
}
void CSkeletonX::_Render_soft(ref_geom& hGeom, u32 vCount, u32 iOffset, u32 pCount)
{
u32 vOffset = cache_vOffset;
_VertexStream& _VS = RCache.Vertex;
if (cache_DiscardID != _VS.DiscardID() || vCount >= cache_vCount)
{
vertRender* Dest = (vertRender*)_VS.Lock(vCount, hGeom->vb_stride, vOffset);
cache_DiscardID = _VS.DiscardID();
cache_vCount = vCount;
cache_vOffset = vOffset;
RDEVICE.Statistic->RenderDUMP_SKIN.Begin();
if (*Vertices1W)
{
Skin1W(Dest, // dest
*Vertices1W, // source
vCount, // count
Parent->bone_instances // bones
);
}
else if (*Vertices2W)
{
Skin2W(Dest, // dest
*Vertices2W, // source
vCount, // count
Parent->bone_instances // bones
);
}
else if (*Vertices3W)
{
Skin3W(Dest, // dest
*Vertices3W, // source
vCount, // count
Parent->bone_instances // bones
);
}
else if (*Vertices4W)
{
Skin4W(Dest, // dest
*Vertices4W, // source
vCount, // count
Parent->bone_instances // bones
);
}
else
R_ASSERT2(0, "unsupported soft rendering");
RDEVICE.Statistic->RenderDUMP_SKIN.End();
_VS.Unlock(vCount, hGeom->vb_stride);
}
RCache.set_Geometry(hGeom);
RCache.Render(D3DPT_TRIANGLELIST, vOffset, 0, vCount, iOffset, pCount);
}
void CSkeletonX::_Load(const char* N, IReader* data, u32& dwVertCount)
{
xr_vector<u16> bids;
// Load vertices
R_ASSERT(data->find_chunk(OGF_VERTICES));
// u16 hw_bones_cnt = u16((HW.Caps.geometry.dwRegisters-22)/3);
// Igor: some shaders in r1 need more free constant registers
u16 hw_bones_cnt = HW.Caps.geometry.dwRegisters;
u16 sw_bones_cnt = 0;
u32 dwVertType, it/*, size, crc*/;
dwVertType = data->r_u32();
dwVertCount = data->r_u32();
RenderMode = RM_SKINNING_SOFT;
Render->shader_option_skinning(-1);
switch (dwVertType)
{
case OGF_VERTEXFORMAT_FVF_1L: // 1-Link
case 1: {
//size = dwVertCount * sizeof(vertBoned1W);
vertBoned1W* pVO = (vertBoned1W*)data->pointer();
for (it = 0; it < dwVertCount; ++it)
{
const vertBoned1W& VB = pVO[it];
u16 mid = (u16)VB.matrix;
if (bids.end() == std::find(bids.begin(), bids.end(), mid))
bids.push_back(mid);
sw_bones_cnt = _max(sw_bones_cnt, mid);
}
if (1 == bids.size())
{
// HW- single bone
RenderMode = RM_SINGLE;
RMS_boneid = *bids.begin();
Render->shader_option_skinning(0);
}
else if (sw_bones_cnt <= hw_bones_cnt)
{
// HW- one weight
RenderMode = RM_SKINNING_1B;
RMS_bonecount = sw_bones_cnt + 1;
Render->shader_option_skinning(1);
}
else
{
// software
//crc = crc32(data->pointer(), size);
Vertices1W.create(dwVertCount, (vertBoned1W*)data->pointer());
Render->shader_option_skinning(-1);
}
}
break;
case OGF_VERTEXFORMAT_FVF_2L: // 2-Link
case 2: {
//size = dwVertCount * sizeof(vertBoned2W);
vertBoned2W* pVO = (vertBoned2W*)data->pointer();
for (it = 0; it < dwVertCount; ++it)
{
const vertBoned2W& VB = pVO[it];
sw_bones_cnt = _max(sw_bones_cnt, VB.matrix0);
sw_bones_cnt = _max(sw_bones_cnt, VB.matrix1);
if (bids.end() == std::find(bids.begin(), bids.end(), VB.matrix0))
bids.push_back(VB.matrix0);
if (bids.end() == std::find(bids.begin(), bids.end(), VB.matrix1))
bids.push_back(VB.matrix1);
}
//. R_ASSERT(sw_bones_cnt<=hw_bones_cnt);
if (sw_bones_cnt <= hw_bones_cnt)
{
// HW- two weights
RenderMode = RM_SKINNING_2B;
RMS_bonecount = sw_bones_cnt + 1;
Render->shader_option_skinning(2);
}
else
{
// software
//crc = crc32(data->pointer(), size);
Vertices2W.create(dwVertCount, (vertBoned2W*)data->pointer());
Render->shader_option_skinning(-1);
}
}
break;
case OGF_VERTEXFORMAT_FVF_3L: // 3-Link
case 3: {
//size = dwVertCount * sizeof(vertBoned3W);
vertBoned3W* pVO = (vertBoned3W*)data->pointer();
for (it = 0; it < dwVertCount; ++it)
{
const vertBoned3W& VB = pVO[it];
for (int i = 0; i < 3; ++i)
{
sw_bones_cnt = _max(sw_bones_cnt, VB.m[i]);
if (bids.end() == std::find(bids.begin(), bids.end(), VB.m[i]))
bids.push_back(VB.m[i]);
}
}
//. R_ASSERT(sw_bones_cnt<=hw_bones_cnt);
if ((sw_bones_cnt <= hw_bones_cnt))
{
RenderMode = RM_SKINNING_3B;
RMS_bonecount = sw_bones_cnt + 1;
Render->shader_option_skinning(3);
}
else
{
//crc = crc32(data->pointer(), size);
Vertices3W.create(dwVertCount, (vertBoned3W*)data->pointer());
Render->shader_option_skinning(-1);
}
}
break;
case OGF_VERTEXFORMAT_FVF_4L: // 4-Link
case 4: {
//size = dwVertCount * sizeof(vertBoned4W);
vertBoned4W* pVO = (vertBoned4W*)data->pointer();
for (it = 0; it < dwVertCount; ++it)
{
const vertBoned4W& VB = pVO[it];
for (int i = 0; i < 4; ++i)
{
sw_bones_cnt = _max(sw_bones_cnt, VB.m[i]);
if (bids.end() == std::find(bids.begin(), bids.end(), VB.m[i]))
bids.push_back(VB.m[i]);
}
}
//. R_ASSERT(sw_bones_cnt<=hw_bones_cnt);
if (sw_bones_cnt <= hw_bones_cnt)
{
RenderMode = RM_SKINNING_4B;
RMS_bonecount = sw_bones_cnt + 1;
Render->shader_option_skinning(4);
}
else
{
//crc = crc32(data->pointer(), size);
Vertices4W.create(dwVertCount, (vertBoned4W*)data->pointer());
Render->shader_option_skinning(-1);
}
}
break;
default: Debug.fatal(DEBUG_INFO, "Invalid vertex type in skinned model '%s'", N); break;
}
if (bids.size() > 1)
{
//crc = crc32(&*bids.begin(), bids.size() * sizeof(u16));
BonesUsed.create(bids.size(), &*bids.begin());
}
}
BOOL CSkeletonX::has_visible_bones()
{
if (RM_SINGLE == RenderMode)
{
return Parent->LL_GetBoneVisible((u16)RMS_boneid);
}
for (u32 it = 0; it < BonesUsed.size(); it++)
if (Parent->LL_GetBoneVisible(BonesUsed[it]))
{
return TRUE;
}
return FALSE;
}
void get_pos_bones(const vertBoned1W& v, Fvector& p, CKinematics* Parent)
{
const Fmatrix& xform = Parent->LL_GetBoneInstance((u16)v.matrix).mRenderTransform;
xform.transform_tiny(p, v.P);
}
void get_pos_bones(const vertBoned2W& vert, Fvector& p, CKinematics* Parent)
{
Fvector P0, P1;
Fmatrix& xform0 = Parent->LL_GetBoneInstance(vert.matrix0).mRenderTransform;
Fmatrix& xform1 = Parent->LL_GetBoneInstance(vert.matrix1).mRenderTransform;
xform0.transform_tiny(P0, vert.P);
xform1.transform_tiny(P1, vert.P);
p.lerp(P0, P1, vert.w);
}
void get_pos_bones(const vertBoned3W& vert, Fvector& p, CKinematics* Parent)
{
Fmatrix& M0 = Parent->LL_GetBoneInstance(vert.m[0]).mRenderTransform;
Fmatrix& M1 = Parent->LL_GetBoneInstance(vert.m[1]).mRenderTransform;
Fmatrix& M2 = Parent->LL_GetBoneInstance(vert.m[2]).mRenderTransform;
Fvector P0, P1, P2;
M0.transform_tiny(P0, vert.P);
P0.mul(vert.w[0]);
M1.transform_tiny(P1, vert.P);
P1.mul(vert.w[1]);
M2.transform_tiny(P2, vert.P);
P2.mul(1.0f - vert.w[0] - vert.w[1]);
p = P0;
p.add(P1);
p.add(P2);
}
void get_pos_bones(const vertBoned4W& vert, Fvector& p, CKinematics* Parent)
{
Fmatrix& M0 = Parent->LL_GetBoneInstance(vert.m[0]).mRenderTransform;
Fmatrix& M1 = Parent->LL_GetBoneInstance(vert.m[1]).mRenderTransform;
Fmatrix& M2 = Parent->LL_GetBoneInstance(vert.m[2]).mRenderTransform;
Fmatrix& M3 = Parent->LL_GetBoneInstance(vert.m[3]).mRenderTransform;
Fvector P0, P1, P2, P3;
M0.transform_tiny(P0, vert.P);
P0.mul(vert.w[0]);
M1.transform_tiny(P1, vert.P);
P1.mul(vert.w[1]);
M2.transform_tiny(P2, vert.P);
P2.mul(vert.w[2]);
M3.transform_tiny(P3, vert.P);
P3.mul(1.0f - vert.w[0] - vert.w[1] - vert.w[2]);
p = P0;
p.add(P1);
p.add(P2);
p.add(P3);
}
//-----------------------------------------------------------------------------------------------------
// Wallmarks
//-----------------------------------------------------------------------------------------------------
#include "cl_intersect.h"
BOOL CSkeletonX::_PickBoneSoft1W(IKinematics::pick_result& r, float dist, const Fvector& S, const Fvector& D, u16* indices, CBoneData::FacesVec& faces)
{
return pick_bone<vertBoned1W>(Vertices1W, Parent, r, dist, S, D, indices, faces);
}
BOOL CSkeletonX::_PickBoneSoft2W(IKinematics::pick_result& r, float dist, const Fvector& S, const Fvector& D, u16* indices, CBoneData::FacesVec& faces)
{
return pick_bone<vertBoned2W>(Vertices2W, Parent, r, dist, S, D, indices, faces);
}
BOOL CSkeletonX::_PickBoneSoft3W(IKinematics::pick_result& r, float dist, const Fvector& S, const Fvector& D, u16* indices, CBoneData::FacesVec& faces)
{
return pick_bone<vertBoned3W>(Vertices3W, Parent, r, dist, S, D, indices, faces);
}
BOOL CSkeletonX::_PickBoneSoft4W(IKinematics::pick_result& r, float dist, const Fvector& S, const Fvector& D, u16* indices, CBoneData::FacesVec& faces)
{
return pick_bone<vertBoned4W>(Vertices4W, Parent, r, dist, S, D, indices, faces);
}
// Fill Vertices
void CSkeletonX::_FillVerticesSoft1W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal, float size, u16* indices, CBoneData::FacesVec& faces)
{
VERIFY(*Vertices1W);
for (CBoneData::FacesVecIt it = faces.begin(); it != faces.end(); it++)
{
Fvector p[3];
u32 idx = (*it) * 3;
CSkeletonWallmark::WMFace F;
for (u32 k = 0; k < 3; k++)
{
vertBoned1W& vert = Vertices1W[indices[idx + k]];
F.bone_id[k][0] = (u16)vert.matrix;
F.bone_id[k][1] = F.bone_id[k][0];
F.bone_id[k][2] = F.bone_id[k][0];
F.bone_id[k][3] = F.bone_id[k][0];
F.weight[k][0] = 0.f;
F.weight[k][1] = 0.f;
F.weight[k][2] = 0.f;
const Fmatrix& xform = Parent->LL_GetBoneInstance(F.bone_id[k][0]).mRenderTransform;
F.vert[k].set(vert.P);
xform.transform_tiny(p[k], F.vert[k]);
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS)
continue;
if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
{
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
wm.m_Faces.push_back(F);
}
}
}
void CSkeletonX::_FillVerticesSoft2W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal, float size, u16* indices, CBoneData::FacesVec& faces)
{
VERIFY(*Vertices2W);
for (CBoneData::FacesVecIt it = faces.begin(); it != faces.end(); it++)
{
Fvector p[3];
u32 idx = (*it) * 3;
CSkeletonWallmark::WMFace F;
for (u32 k = 0; k < 3; k++)
{
Fvector P0, P1;
vertBoned2W& vert = Vertices2W[indices[idx + k]];
F.bone_id[k][0] = vert.matrix0;
F.bone_id[k][1] = vert.matrix1;
F.bone_id[k][2] = F.bone_id[k][1];
F.bone_id[k][3] = F.bone_id[k][1];
F.weight[k][0] = vert.w;
F.weight[k][1] = 0.f;
F.weight[k][2] = 0.f;
Fmatrix& xform0 = Parent->LL_GetBoneInstance(F.bone_id[k][0]).mRenderTransform;
Fmatrix& xform1 = Parent->LL_GetBoneInstance(F.bone_id[k][1]).mRenderTransform;
F.vert[k].set(vert.P);
xform0.transform_tiny(P0, F.vert[k]);
xform1.transform_tiny(P1, F.vert[k]);
p[k].lerp(P0, P1, F.weight[k][0]);
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS)
continue;
if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
{
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
wm.m_Faces.push_back(F);
}
}
}
void CSkeletonX::_FillVerticesSoft3W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal, float size, u16* indices, CBoneData::FacesVec& faces)
{
VERIFY(*Vertices3W);
for (CBoneData::FacesVecIt it = faces.begin(); it != faces.end(); ++it)
{
Fvector p[3];
u32 idx = (*it) * 3;
CSkeletonWallmark::WMFace F;
for (u32 k = 0; k < 3; k++)
{
const vertBoned3W& vert = Vertices3W[indices[idx + k]];
F.bone_id[k][0] = vert.m[0];
F.bone_id[k][1] = vert.m[1];
F.bone_id[k][2] = vert.m[2];
F.bone_id[k][3] = F.bone_id[k][2];
F.weight[k][0] = vert.w[0];
F.weight[k][1] = vert.w[1];
F.weight[k][2] = 0.f;
vert.get_pos(F.vert[k]);
get_pos_bones(vert, p[k], Parent);
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS)
continue;
if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
{
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
wm.m_Faces.push_back(F);
}
}
}
void CSkeletonX::_FillVerticesSoft4W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal, float size, u16* indices, CBoneData::FacesVec& faces)
{
VERIFY(*Vertices4W);
for (CBoneData::FacesVecIt it = faces.begin(); it != faces.end(); ++it)
{
Fvector p[3];
u32 idx = (*it) * 3;
CSkeletonWallmark::WMFace F;
for (u32 k = 0; k < 3; k++)
{
const vertBoned4W& vert = Vertices4W[indices[idx + k]];
F.bone_id[k][0] = vert.m[0];
F.bone_id[k][1] = vert.m[1];
F.bone_id[k][2] = vert.m[2];
F.bone_id[k][3] = vert.m[3];
F.weight[k][0] = vert.w[0];
F.weight[k][1] = vert.w[1];
F.weight[k][2] = vert.w[2];
vert.get_pos(F.vert[k]);
get_pos_bones(vert, p[k], Parent);
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS)
continue;
if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
{
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
wm.m_Faces.push_back(F);
}
}
}
void CSkeletonX::_DuplicateIndices(const char* N, IReader* data)
{
// We will have trouble with container since don't know were to take readable indices
VERIFY(!data->find_chunk(OGF_ICONTAINER));
// Index buffer replica since we can't read from index buffer in DX10
// ref_smem<u16> Indices;
R_ASSERT(data->find_chunk(OGF_INDICES));
u32 iCount = data->r_u32();
//u32 size = iCount * 2;
//u32 crc = crc32(data->pointer(), size);
m_Indices.create(iCount, (u16*)data->pointer());
}