/
AnimModel.cpp
496 lines (413 loc) · 16.3 KB
/
AnimModel.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
#include "AnimModel.h"
#include "Mediator.h"
// îáíîâëåíèå
bool SingleAnimatedModel::Update(float dT) {
if (restCurClip) { // ñìåøåíèå àíèìàöèè îòñóòñòâóåò
// îáíîâèòü òåêóùèé êàäð
accumulation[curClip] += dT * Const::animationSpeed;
curFrame[curClip] = (UINT)accumulation[curClip];
if (curFrame[curClip] >= framesAmount[curClip]) {
curFrame[curClip] -= framesAmount[curClip];
accumulation[curClip] -= framesAmount[curClip];
}
}
else { // àíèìàöèÿ ñìåøèâàåòñÿ
// îáíîâèòü âåñà êëèïîâ
for (UINT i(0); i < clipsAmount; i++) {
if (i == curClip) blendFactors[i] += dT * clipBlendSpeed;
else blendFactors[i] -= dT * clipBlendSpeed;
blendFactors[i] = MathHelper::Clutch(blendFactors[i], 0.0f, 1.0f);
}
// îáíîâèòü òåêóùèé êàäð ìàññèâà êëèïîâ
for (UINT i(0); i < clipsAmount; i++) {
if (blendFactors[i]) {
accumulation[i] += dT * Const::animationSpeed;
curFrame[i] = (UINT)accumulation[i];
if (curFrame[i] >= framesAmount[i]) {
curFrame[i] -= framesAmount[i];
accumulation[i] -= framesAmount[i];
}
}
else accumulation[i] = 0.0f;
}
// ïîðà ïåðåêëþ÷àòü àíèìàöèþ?
if (waitNextClip) {
nextClipTime -= dT;
if (nextClipTime <= 1.0f / clipBlendSpeed) {
// àíèìàöèÿ ïåðåêëþ÷àåòñÿ
SingleAnimatedModel::SetCurrentClip(nextClip);
}
}
else {
// àíèìàöèÿ ñìåøèâàåòñÿ?
for (UINT i(0); i < clipsAmount; i++) {
if (i == curClip) {
if (blendFactors[i] != 1.0f) break;
}
else {
if (blendFactors[i] != 0.0f) break;
}
// àíèìàöèÿ áîëüøå íå ñìåøèâàåòñÿ
if (i == (clipsAmount - 1)) restCurClip = true;
}
}
}
// îãðàíè÷åíèå óãëîâ ïðåäåëîì â 2ïè
if (rotAngle >= XM_2PI) rotAngle -= XM_2PI;
if (rotAngle < 0.0f) rotAngle += XM_2PI;
if (drawAngle >= XM_2PI) drawAngle -= XM_2PI;
if (drawAngle < 0.0f) drawAngle += XM_2PI;
// óãëîâîå ïåðåìåùåíèå
float maxRotAngle = angleSpeed * dT;
if (abs(rotAngle - drawAngle) > XM_PI) {
// ïåðåìåùåíèå áëèæå ÷åðåç êðàé 2Ïè
if (drawAngle - rotAngle > maxRotAngle) drawAngle += maxRotAngle; // ïî ÷àñîâîé ñòðåëêå
else if (rotAngle - drawAngle > maxRotAngle) drawAngle -= maxRotAngle; // ïðîòèâ ÷àñîâîé ñòðåëêè
}
else {
// ïåðåìåùåíèå áëèæå íàïðÿìóþ
if (drawAngle - rotAngle > maxRotAngle) drawAngle -= maxRotAngle; // ïðîòèâ ÷àñîâîé ñòðåëêè
else if (rotAngle - drawAngle > maxRotAngle) drawAngle += maxRotAngle; // ïî ÷àñîâîé ñòðåëêå
}
// îáíîâèòü ìàòðèöó âðàùåíèÿ
XMStoreFloat4x4(&rotationMatrix, XMMatrixRotationY(drawAngle));
recreateFinalMatrices = true;
return true;
}
// óñòàíîâèòü íîâûé êëèï
float SingleAnimatedModel::SetCurrentClip(UINT clipNumber) { // çàöèêëèòü
curClip = clipNumber;
restCurClip = false;
waitNextClip = false;
nextClipTime = 0.0f;
return framesAmount[curClip] / (float)Const::animationSpeed;
}
float SingleAnimatedModel::SetCurrentClip(UINT clipNumber, UINT nextClipNumber) { // îäèí öèêë
curClip = clipNumber;
restCurClip = false;
nextClip = nextClipNumber;
waitNextClip = true;
nextClipTime = framesAmount[curClip] / (float)Const::animationSpeed;
return nextClipTime;
}
// êîíñòðóêòîð ìîäåëè ñ êîñòÿìè
AnimModel::AnimModel(wchar_t* binFilePath, wchar_t* textureFilePath, bool* result) {
// èíèöèàëèçàöèÿ ïåðåìåííûõ
position = Const::spawnPoint; // êîîðäèíàòû ìîäåëè
// çàãðóçèòü ìîäåëü èç ôàéëà
BRR(LoadAmimModelFromFile(binFilePath));
// èíèöèàëèçàöèÿ ýëåìåíòîâ ïîñëå çàãðóçêè
std::fill(curFrame.begin(), curFrame.end(), 0);
std::fill(accumulation.begin(), accumulation.end(), 0.0f);
std::fill(blendFactors.begin(), blendFactors.end(), 0.0f);
blendFactors[0] = 1.0f;
// ñîçäàòü ìàòðèöó ïîðÿäêà óìíîæåíèÿ ôèíàëüíûõ êîñòåé
BRR(BuildOrder());
// çàãðóçèòü òåêñòóðó
if (FAILED(D3DX11CreateShaderResourceViewFromFile(Mediator::pDev, textureFilePath, NULL, NULL, &pSRtexture, NULL))) {
BRR(Mediator::errors->Push(textureFilePath));
*result = false;
return;
}
*result = true;
}
// çàãðóçèòü ìîäåëü èç ôàéëà
bool AnimModel::LoadAmimModelFromFile(wchar_t* binFilePath) {
// îòêðûòèå ôàéëà
std::ifstream fin;
fin.open(binFilePath, std::ios_base::binary);
BR(fin.is_open());
// ÷òåíèå çàãîëîâêà
UINT vertexAmount = 0; // êîëè÷åñòâî âåðøèí
fin.read((char*)&vertexAmount, sizeof(UINT));
fin.read((char*)&indicesAmount, sizeof(UINT));
fin.read((char*)&bonesAmount, sizeof(UINT));
fin.read((char*)&clipsAmount, sizeof(UINT));
clips.resize(clipsAmount);
curFrame.resize(clipsAmount);
framesAmount = new UINT[clipsAmount];
accumulation.resize(clipsAmount);
blendFactors.resize(clipsAmount);
for (UINT i(0); i < clipsAmount; i++) {
fin.read((char*)&framesAmount[i], sizeof(UINT));
}
BR(bonesAmount <= 32);
// ÷òåíèå áóôåðà âåðøèí
VertPos3Nor2Tex2W1Bone2* vertexBuffer = new VertPos3Nor2Tex2W1Bone2[vertexAmount];
fin.read((char*)vertexBuffer, sizeof(VertPos3Nor2Tex2W1Bone2)* vertexAmount);
// ÷òåíèå áóôåðà èíäåêñîâ
UINT* indexBuffer = new UINT[indicesAmount];
fin.read((char*)indexBuffer, sizeof(UINT)* indicesAmount);
// ÷òåíèå èåðàðõèè
hierarchy.resize(bonesAmount);
for (UINT i(0); i < bonesAmount; i++) {
fin.read((char*)&hierarchy[i], sizeof(int));
}
// ÷òåíèå ìàòðèö offset
offsetMatrices.resize(bonesAmount);
XMFLOAT3 pos;
XMFLOAT4 quat;
for (UINT i(0); i < bonesAmount; i++) {
fin.read((char*)&pos, sizeof(XMFLOAT3));
fin.read((char*)&quat, sizeof(XMFLOAT4));
XMMATRIX T = XMMatrixTranslation(pos.x, pos.y, pos.z);
XMMATRIX R = XMMatrixRotationQuaternion(XMLoadFloat4(&quat));
XMStoreFloat4x4(&offsetMatrices[i], R * T);
}
// ÷òåíèå íàñëåäñòâåííûõ ìàòðèö êîñòåé
clips.resize(clipsAmount);
for (UINT clipNumber(0); clipNumber < clipsAmount; clipNumber++) {
clips[clipNumber].bonesPositions = new XMFLOAT3[framesAmount[clipNumber] * bonesAmount];
clips[clipNumber].bonesQuaternions = new XMFLOAT4[framesAmount[clipNumber] * bonesAmount];
XMFLOAT3* posPointer = clips[clipNumber].bonesPositions;
XMFLOAT4* quatPointer = clips[clipNumber].bonesQuaternions;
for (UINT i(0); i < framesAmount[clipNumber]; i++)
for (UINT j(0); j < bonesAmount; j++) {
fin.read((char*)posPointer, sizeof(XMFLOAT3));
BR(!fin.eof());
fin.read((char*)quatPointer, sizeof(XMFLOAT4));
posPointer++;
quatPointer++;
}
}
// ñòðóêòóðà áóôåðà âåðøèí
D3D11_BUFFER_DESC bufferVertDesc = { 0 };
bufferVertDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferVertDesc.ByteWidth = sizeof(VertPos3Nor2Tex2W1Bone2)* vertexAmount;
bufferVertDesc.CPUAccessFlags = 0;
bufferVertDesc.MiscFlags = 0;
bufferVertDesc.StructureByteStride = 0;
bufferVertDesc.Usage = D3D11_USAGE_IMMUTABLE;
// ñîçäàíèå áóôåðà âåðøèí
D3D11_SUBRESOURCE_DATA subVertData = { 0 };
subVertData.pSysMem = vertexBuffer;
HR(Mediator::pDev->CreateBuffer(&bufferVertDesc, &subVertData, &pVertexBuffer));
// ñòðóêòóðà áóôåðà èíäåêñîâ
D3D11_BUFFER_DESC bufferIndDesc = { 0 };
bufferIndDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
bufferIndDesc.ByteWidth = sizeof(UINT)* indicesAmount;
bufferIndDesc.CPUAccessFlags = 0;
bufferIndDesc.MiscFlags = 0;
bufferIndDesc.StructureByteStride = 0;
bufferIndDesc.Usage = D3D11_USAGE_IMMUTABLE;
// ñîçäàíèå áóôåð èíäåêñîâ
D3D11_SUBRESOURCE_DATA subIndData = { 0 };
subIndData.pSysMem = indexBuffer;
HR(Mediator::pDev->CreateBuffer(&bufferIndDesc, &subIndData, &pIndexBuffer));
// ïðîâåðêà íà ÷òåíèå âñåãî ôàéëà
UINT endOfFileBuffer;
fin.read((char*)&endOfFileBuffer, sizeof(UINT));
BR(fin.eof());
// îñâîáîæäåíèå ðåñóðñîâ
ReleaseNULLS(indexBuffer);
ReleaseNULLS(vertexBuffer);
fin.close();
return true;
}
// ïîñòðîèòü âåòîð order äëÿ óìíîæíèÿ ìàòðèö
bool AnimModel::BuildOrder() {
std::vector<int> newParent;
std::vector<int> newChild;
// ñîáðàòü ðîäèòåëüñêèå êîñòè
for (UINT i(0); i < bonesAmount; i++) {
if (hierarchy[i] == -1) {
newParent.push_back(i);
order.push_back(i);
}
}
// ñîáðàòü âñå îñòàëüíûå êîñòè
for (UINT k(0); k < bonesAmount; k++) {
for (UINT i(0); i < bonesAmount; i++) {
for (UINT j(0); j < newParent.size(); j++) {
if (hierarchy[i] == newParent[j])
newChild.push_back(i);
}
}
newParent.clear();
for (UINT i(0); i < newChild.size(); i++) {
order.push_back(newChild[i]);
if (order.size() == bonesAmount) return true;
newParent.push_back(newChild[i]);
}
newChild.clear();
}
return false;
}
// ñîçäàòü ôèíàëüíûå ìàòðèöû äëÿ øåéäåðà
void AnimModel::CreateFinalMatricesOldStyle(UINT clipNumber, UINT frameNumber, XMFLOAT4X4* finalMatrices) { // áåç ñìåøèâàíèÿ êëèïîâ ïî äðåâíåìó àëãîðèòìó (äëÿ îòëàäêè)
// çàãðóçêà ìàòðèö
std::vector<XMFLOAT4X4> reserve(bonesAmount);
std::vector<XMFLOAT4X4> reserve2(bonesAmount);
for (UINT i(0); i < bonesAmount; i++) {
XMFLOAT3 position = clips[clipNumber].bonesPositions[i + bonesAmount * frameNumber];
XMMATRIX T = XMMatrixTranslation(position.x, position.y, position.z);
XMFLOAT4 quaternion = clips[clipNumber].bonesQuaternions[i + bonesAmount * frameNumber];
XMMATRIX R = XMMatrixRotationQuaternion(XMLoadFloat4(&quaternion));
XMStoreFloat4x4(&reserve[i], R * T);
XMStoreFloat4x4(&reserve2[i], R * T);
}
// ïåðåìíîæåíèå ìàòðèö äëÿ ïîëó÷åíèÿ final
for (UINT i(0); i < bonesAmount; i++) {
XMMATRIX fin = XMMatrixIdentity();
UINT curMatrix = i;
fin = fin * XMLoadFloat4x4(&reserve[curMatrix]);
while (curMatrix != -1) {
curMatrix = hierarchy[curMatrix];
if (curMatrix == -1) break;
fin = fin * XMLoadFloat4x4(&reserve[curMatrix]);
}
XMMATRIX offSet = XMLoadFloat4x4(&offsetMatrices[i]);
XMStoreFloat4x4(&finalMatrices[i], offSet * fin);
}
}
void AnimModel::CreateFinalMatrices(UINT clipNumber, UINT frameNumber, XMFLOAT4X4* finalMatrices) { // áåç ñìåøèâàíèÿ êëèïîâ
// çàãðóçêà ìàòðèö
std::vector<XMFLOAT4X4> toRoot(bonesAmount);
for (UINT i(0); i < bonesAmount; i++) {
XMFLOAT3 position = clips[clipNumber].bonesPositions[i + bonesAmount * frameNumber];
XMMATRIX T = XMMatrixTranslation(position.x, position.y, position.z);
XMFLOAT4 quaternion = clips[clipNumber].bonesQuaternions[i + bonesAmount * frameNumber];
XMMATRIX R = XMMatrixRotationQuaternion(XMLoadFloat4(&quaternion));
XMStoreFloat4x4(&toRoot[i], R * T);
}
// ïåðåìíîæåíèå ìàòðèö äëÿ ïîëó÷åíèÿ final
for (UINT i(0); i < bonesAmount; i++) {
UINT coef = order[i];
if (hierarchy[coef] == -1) continue;
XMStoreFloat4x4(&toRoot[coef], XMLoadFloat4x4(&toRoot[coef]) * XMLoadFloat4x4(&toRoot[hierarchy[coef]]));
}
for (UINT i(0); i < bonesAmount; i++) {
XMMATRIX offSet = XMLoadFloat4x4(&offsetMatrices[i]);
XMStoreFloat4x4(&finalMatrices[i], offSet * XMLoadFloat4x4(&toRoot[i]));
}
}
void AnimModel::CreateFinalMatrices(UINT clipNumber1, UINT frameNumber1, UINT clipNumber2, UINT frameNumber2, float blendFactor, XMFLOAT4X4* finalMatrices) { // ñìåøèâàíèå äâóõ êëèïîâ
XMFLOAT3 positionF3;
XMVECTOR quatF4;
std::vector<XMFLOAT4X4> toRoot(bonesAmount);
for (UINT i(0); i < bonesAmount; i++) {
// çàãðóçêà ìàòðèö
XMVECTOR position1 = XMLoadFloat3(&clips[clipNumber1].bonesPositions[i + bonesAmount * frameNumber1]);
XMVECTOR position2 = XMLoadFloat3(&clips[clipNumber2].bonesPositions[i + bonesAmount * frameNumber2]);
XMStoreFloat3(&positionF3, XMVectorLerp(position1, position2, blendFactor));
XMVECTOR quaternion1 = XMLoadFloat4(&clips[clipNumber1].bonesQuaternions[i + bonesAmount * frameNumber1]);
XMVECTOR quaternion2 = XMLoadFloat4(&clips[clipNumber2].bonesQuaternions[i + bonesAmount * frameNumber2]);
quatF4 = XMQuaternionSlerp(quaternion1, quaternion2, blendFactor);
// èíòåðïîëÿöèÿ ìàòðèö
XMMATRIX T = XMMatrixTranslation(positionF3.x, positionF3.y, positionF3.z);
XMMATRIX R = XMMatrixRotationQuaternion(quatF4);
XMStoreFloat4x4(&toRoot[i], R * T);
}
// ïåðåìíîæåíèå ìàòðèö äëÿ ïîëó÷åíèÿ final
for (UINT i(0); i < bonesAmount; i++) {
UINT coef = order[i];
if (hierarchy[coef] == -1) continue;
XMStoreFloat4x4(&toRoot[coef], XMLoadFloat4x4(&toRoot[coef]) * XMLoadFloat4x4(&toRoot[hierarchy[coef]]));
}
for (UINT i(0); i < bonesAmount; i++) {
XMMATRIX offSet = XMLoadFloat4x4(&offsetMatrices[i]);
XMStoreFloat4x4(&finalMatrices[i], offSet * XMLoadFloat4x4(&toRoot[i]));
}
}
void AnimModel::CreateFinalMatrices(std::vector<UINT> frameNumbers, std::vector<float> blendFactors, XMFLOAT4X4* finalMatrices) { // ñìåøèâàíèå íåñêîëüêèõ êëèïîâ
std::vector<XMFLOAT4X4> toRoot(bonesAmount);
// ïîèñê íåíóëåâûõ âåñîâ
std::vector<UINT> iterators;
for (UINT i(0); i < clips.size(); i++)
if (blendFactors[i]) iterators.push_back(i);
// äëÿ êàæäîé êîñòè
for (UINT i(0); i < bonesAmount; i++) {
XMFLOAT3 position = XMFLOAT3(0.0f, 0.0f, 0.0f);
XMFLOAT4 quaternion = XMFLOAT4(0.0f, 0.0f, 0.0f, 0.0f);
// ñîçäàíèå âåêòîðà äëÿ îáðàáîòêè
std::vector<XMFLOAT4> quats;
std::vector<XMFLOAT3> posits;
std::vector<float> weights;
for (UINT j(0); j < iterators.size(); j++) {
quats.push_back(clips[iterators[j]].bonesQuaternions[i + bonesAmount * frameNumbers[iterators[j]]]);
posits.push_back(clips[iterators[j]].bonesPositions[i + bonesAmount * frameNumbers[iterators[j]]]);
weights.push_back(blendFactors[iterators[j]]);
}
// îáðàáîòêà âåêòîðà
while (quats.size() > 1) {
XMFLOAT4 newQuat;
XMFLOAT3 newPosit;
float relWeight = weights[1] / (weights[1] + weights[0]);
XMStoreFloat4(&newQuat, XMQuaternionSlerp(XMLoadFloat4(&quats[0]), XMLoadFloat4(&quats[1]), relWeight));
XMStoreFloat3(&newPosit, XMVectorLerp(XMLoadFloat3(&posits[0]), XMLoadFloat3(&posits[1]), relWeight));
float newWeight = weights[0] + weights[1];
quats.erase(quats.begin());
quats.erase(quats.begin());
quats.push_back(newQuat);
posits.erase(posits.begin());
posits.erase(posits.begin());
posits.push_back(newPosit);
weights.erase(weights.begin());
weights.erase(weights.begin());
weights.push_back(newWeight);
}
// çàïèñü èíòåðïîëèðîâàííûõ ìàòðèö ìàòðèö
XMVECTOR quatResult = XMLoadFloat4(&quats[0]);
XMMATRIX R = XMMatrixRotationQuaternion(quatResult);
XMMATRIX T = XMMatrixTranslation(posits[0].x, posits[0].y, posits[0].z);
XMStoreFloat4x4(&toRoot[i], R * T);
}
// ïåðåìíîæåíèå ìàòðèö äëÿ ïîëó÷åíèÿ final
for (UINT i(0); i < bonesAmount; i++) {
UINT coef = order[i];
if (hierarchy[coef] == -1) continue;
XMStoreFloat4x4(&toRoot[coef], XMLoadFloat4x4(&toRoot[coef]) * XMLoadFloat4x4(&toRoot[hierarchy[coef]]));
}
for (UINT i(0); i < bonesAmount; i++) {
XMMATRIX offSet = XMLoadFloat4x4(&offsetMatrices[i]);
XMStoreFloat4x4(&finalMatrices[i], offSet * XMLoadFloat4x4(&toRoot[i]));
}
}
// ðèñîâàòü ìîäåëü
bool AnimModel::Draw(bool toShadowMap) {
// óñòàíîâèòü êîíñòàíòû
myXMFLOAT3 positionJP = position - Mediator::camera->GetPosition();
XMMATRIX W_JP = XMMatrixTranslation(positionJP.x, positionJP.y, positionJP.z);
XMMATRIX R = XMLoadFloat4x4(&GetRotationMatrix());
if (recreateFinalMatrices) {
if (restCurClip) CreateFinalMatrices(curClip, curFrame[curClip], finalMatrices);
else CreateFinalMatrices(curFrame, blendFactors, finalMatrices);
recreateFinalMatrices = false;
}
UINT vertexStride = sizeof(VertPos3Nor2Tex2W1Bone2);
UINT vertexOffset = 0;
// óñòàíîâèòü ïàðàìåòðû
Mediator::pDevContext->IASetVertexBuffers(0, 1, &pVertexBuffer, &vertexStride, &vertexOffset);
Mediator::pDevContext->IASetIndexBuffer(pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
Mediator::pDevContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
Mediator::pDevContext->IASetInputLayout(Mediator::pInputLayoutPos3Nor3Tex2W1Bone2);
if (toShadowMap) {
Mediator::pDevContext->VSSetShader(Mediator::pVSShadow, NULL, 0);
Mediator::pDevContext->PSSetShader(Mediator::pPSEmpty, NULL, 0);
}
else {
Mediator::pDevContext->PSSetShaderResources(TEXTURE_BUFFER, 1, &pSRtexture);
Mediator::pDevContext->VSSetShader(Mediator::pVSPosNorTexWBone, NULL, 0);
Mediator::pDevContext->PSSetShader(Mediator::pPSPosNorTex, NULL, 0);
}
// îáíîâèòü êîíñòàíòíûé áóôåð øåéäåðà
D3D11_MAPPED_SUBRESOURCE mappedData;
HR(Mediator::pDevContext->Map(Mediator::cbufAnimModel, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData));
CbufAnimModel* cbuf = reinterpret_cast<CbufAnimModel*>(mappedData.pData);
XMStoreFloat4x4(&cbuf->gWorld, XMMatrixTranspose(R * W_JP));
for (UINT i(0); i < bonesAmount; i++) {
XMStoreFloat4x4(&cbuf->gBones[i], XMMatrixTranspose(XMLoadFloat4x4(&finalMatrices[i])));
}
Mediator::pDevContext->Unmap(Mediator::cbufAnimModel, 0);
Mediator::pDevContext->VSSetConstantBuffers(SR_ANIMMODEL, 1, &Mediator::cbufAnimModel);
// ðèñîâàíèå
Mediator::pDevContext->DrawIndexed(indicesAmount, 0, 0);
return true;
}
// äåñòðóêòîð
AnimModel::~AnimModel() {
ReleaseNULLS(framesAmount);
ReleaseCOM(pSRtexture);
ReleaseCOM(pVertexBuffer);
ReleaseCOM(pIndexBuffer);
}