-
Notifications
You must be signed in to change notification settings - Fork 3
/
bone.h
77 lines (62 loc) · 2.25 KB
/
bone.h
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
#pragma once
#include "mgs/common/util.h"
#include "mgs/model/kms/kms.h"
#include "mgs/model/evm/evm.h"
#include "mgs/model/mdl/mdl.h"
#include "noesis/plugin/pluginshare.h"
inline
int findBoneIdx(char* boneName, modelBone_t* noeBones, int numBones) {
for (int i = 0; i < numBones; i++) {
if (!strcmp(noeBones[i].name, boneName))
return i;
}
return -1;
}
inline
modelBone_t* bindBones(MdlBone* bones, int numBones, noeRAPI_t* rapi) {
modelBone_t* noeBones = rapi->Noesis_AllocBones(numBones);
for (int i = 0; i < numBones; i++) {
std::string boneName = intToHexString(bones[i].strcode);
strcpy_s(noeBones[i].name, boneName.c_str());
RichVec4 bonePos = { bones[i].worldPos.x, bones[i].worldPos.y, bones[i].worldPos.z, bones[i].worldPos.w };
RichVec3 bonePosV3 = bonePos.ToVec3();
memcpy_s(&noeBones[i].mat.o, 12, &bonePosV3, 12);
if (bones[i].parent > -1)
noeBones[i].eData.parent = &noeBones[bones[i].parent];
}
rapi->rpgSetExData_Bones(noeBones, numBones);
return noeBones;
}
inline
modelBone_t* bindKMSBones(KmsMesh* mesh, int numBones, noeRAPI_t* rapi)
{
modelBone_t* noeBones = rapi->Noesis_AllocBones(numBones);
for (int i = 0; i < numBones; i++)
{
RichVec3 bonePosV3 = { mesh[i].pos.x, mesh[i].pos.y, mesh[i].pos.z };
memcpy_s(&noeBones[i].mat.o, 12, &bonePosV3, 12);
if (mesh[i].parent > -1)
{
noeBones[i].eData.parent = &noeBones[mesh[i].parent];
RichMat43 cMat(noeBones[i].mat);
RichMat43 pMat(noeBones[i].eData.parent->mat);
noeBones[i].mat = (cMat * pMat).m;
}
}
rapi->rpgSetExData_Bones(noeBones, numBones);
return noeBones;
}
inline
modelBone_t* bindEVMBones(EvmBone* bones, int numBones, noeRAPI_t* rapi)
{
modelBone_t* noeBones = rapi->Noesis_AllocBones(numBones);
for (int i = 0; i < numBones; i++)
{
RichVec3 bonePosV3 = { bones[i].worldPos.x, bones[i].worldPos.y, bones[i].worldPos.z };
memcpy_s(&noeBones[i].mat.o, 12, &bonePosV3, 12);
if (bones[i].parent > -1)
noeBones[i].eData.parent = &noeBones[bones[i].parent];
}
rapi->rpgSetExData_Bones(noeBones, numBones);
return noeBones;
}