Skip to content

Commit

Permalink
Support jka models in OpenJO (from mvdevs/jk2mv@ef336f9)
Browse files Browse the repository at this point in the history
  • Loading branch information
taysta committed Nov 19, 2024
1 parent 199ddc7 commit c99e064
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions code/rd-vanilla/tr_ghoul2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3494,6 +3494,64 @@ Bone 52: "face_always_":
*/

#ifdef JK2_MODE
int NewToOldRemapTable[53] = {
0, // JKA Bone 00 model_root to JK2 Bone 00 model_root
1, // JKA Bone 01 pelvis to JK2 Bone 01 pelvis
2, // JKA Bone 02 Motion to JK2 Bone 02 Motion
3, // JKA Bone 03 lfemurYZ to JK2 Bone 03 lfemurYZ
4, // JKA Bone 04 lfemurX to JK2 Bone 04 lfemurX
5, // JKA Bone 05 ltibia to JK2 Bone 05 ltibia
6, // JKA Bone 06 ltalus to JK2 Bone 06 ltalus
8, // JKA Bone 07 rfemurYZ to JK2 Bone 08 rfemurYZ
9, // JKA Bone 08 rfemurX to JK2 Bone 09 rfemurX
10, // JKA Bone 09 rtibia to JK2 Bone 10 rtibia
11, // JKA Bone 10 rtalus to JK2 Bone 11 rtalus
13, // JKA Bone 11 lower_lumbar to JK2 Bone 13 lower_lumbar
14, // JKA Bone 12 upper_lumbar to JK2 Bone 14 upper_lumbar
15, // JKA Bone 13 thoracic to JK2 Bone 15 thoracic
16, // JKA Bone 14 cervical to JK2 Bone 16 cervical
17, // JKA Bone 15 cranium to JK2 Bone 17 cranium
18, // JKA Bone 16 ceyebrow to JK2 Bone 18 ceyebrow
19, // JKA Bone 17 jaw to JK2 Bone 19 jaw
20, // JKA Bone 18 lblip2 to JK2 Bone 20 lblip2
21, // JKA Bone 19 leye to JK2 Bone 21 leye
22, // JKA Bone 20 rblip2 to JK2 Bone 22 rblip2
23, // JKA Bone 21 ltlip2 to JK2 Bone 23 ltlip2
24, // JKA Bone 22 rtlip2 to JK2 Bone 24 rtlip2
25, // JKA Bone 23 reye to JK2 Bone 25 reye
26, // JKA Bone 24 rclavical to JK2 Bone 26 rclavical
27, // JKA Bone 25 rhumerus to JK2 Bone 27 rhumerus
28, // JKA Bone 26 rhumerusX to JK2 Bone 28 rhumerusX
29, // JKA Bone 27 rradius to JK2 Bone 29 rradius
30, // JKA Bone 28 rradiusX to JK2 Bone 30 rradiusX
31, // JKA Bone 29 rhand to JK2 Bone 31 rhand
36, // JKA Bone 30 r_d1_j1 to JK2 Bone 36 r_d1_j1
37, // JKA Bone 31 r_d1_j2 to JK2 Bone 37 r_d1_j2
39, // JKA Bone 32 r_d2_j1 to JK2 Bone 39 r_d2_j1
40, // JKA Bone 33 r_d2_j2 to JK2 Bone 40 r_d2_j2
45, // JKA Bone 34 r_d4_j1 to JK2 Bone 45 r_d4_j1
46, // JKA Bone 35 r_d4_j2 to JK2 Bone 46 r_d4_j2
48, // JKA Bone 36 rhang_tag_bone to JK2 Bone 48 rhang_tag_bone
49, // JKA Bone 37 lclavical to JK2 Bone 49 lclavical
50, // JKA Bone 38 lhumerus to JK2 Bone 50 lhumerus
51, // JKA Bone 39 lhumerusX to JK2 Bone 51 lhumerusX
52, // JKA Bone 40 lradius to JK2 Bone 52 lradius
53, // JKA Bone 41 lradiusX to JK2 Bone 53 lradiusX
54, // JKA Bone 42 lhand to JK2 Bone 54 lhand
59, // JKA Bone 43 l_d4_j1 to JK2 Bone 59 l_d4_j1
60, // JKA Bone 44 l_d4_j2 to JK2 Bone 60 l_d4_j2
65, // JKA Bone 45 l_d2_j1 to JK2 Bone 65 l_d2_j1
66, // JKA Bone 46 l_d2_j2 to JK2 Bone 66 l_d2_j2
68, // JKA Bone 47 l_d1_j1 to JK2 Bone 68 l_d1_j1
69, // JKA Bone 48 l_d1_j2 to JK2 Bone 69 l_d1_j2
3, // JKA Bone 49 ltail to JK2 Bone 03 lfemurYZ
8, // JKA Bone 50 rtail to JK2 Bone 08 rfemurYZ
54, // JKA Bone 51 lhang_tag_bone to JK2 Bone 54 lhand
71 // JKA Bone 52 face to JK2 Bone 71 face
};
#endif

qboolean R_LoadMDXM( model_t *mod, void *buffer, const char *mod_name, qboolean &bAlreadyCached ) {
int i, l, j;
mdxmHeader_t *pinmodel, *mdxm;
Expand Down Expand Up @@ -3602,6 +3660,13 @@ qboolean R_LoadMDXM( model_t *mod, void *buffer, const char *mod_name, qboolean
isAnOldModelFile = true;
}
#endif
#ifdef JK2_MODE
bool isANewModelFile = false;
if (mdxm->numBones == 53 && strstr(mdxm->animName, "_humanoid"))
{
isANewModelFile = true;
}
#endif

if (!mdxm->animIndex)
{
Expand Down Expand Up @@ -3662,6 +3727,16 @@ qboolean R_LoadMDXM( model_t *mod, void *buffer, const char *mod_name, qboolean
surfInfo->name[strlen(surfInfo->name)-4]=0; //remove "_off" from name
}
#endif
#ifdef JK2_MODE
if ( isANewModelFile )
{
Q_strlwr(surfInfo->name); //just in case
if ( !strcmp( &surfInfo->name[strlen(surfInfo->name)-4],"_off") )
{
surfInfo->name[strlen(surfInfo->name)-4]=0; //remove "_off" from name
}
}
#endif

if ( surfInfo->shader[0] == '[' )
{
Expand Down Expand Up @@ -3802,6 +3877,24 @@ qboolean R_LoadMDXM( model_t *mod, void *buffer, const char *mod_name, qboolean
}
}
}
#endif
#ifdef JK2_MODE
if (isANewModelFile)
{
int *boneRef = (int *) ( (byte *)surf + surf->ofsBoneReferences );
for ( j = 0 ; j < surf->numBoneReferences ; j++ )
{
assert(boneRef[j] >= 0 && boneRef[j] < 53);
if (boneRef[j] >= 0 && boneRef[j] < 53)
{
boneRef[j]=NewToOldRemapTable[boneRef[j]];
}
else
{
boneRef[j]=0;
}
}
}
#endif
// find the next surface
surf = (mdxmSurface_t *)( (byte *)surf + surf->ofsEnd );
Expand Down

0 comments on commit c99e064

Please sign in to comment.