more (or rather fewer) lcs fixes

This commit is contained in:
aap 2015-12-20 10:38:27 +01:00
parent 90b2d98b97
commit 83d1420dd1
5 changed files with 898 additions and 884 deletions

File diff suppressed because it is too large Load Diff

View File

@ -492,7 +492,7 @@ readSkin(Stream *stream, int32 len, void *object, int32 offset, int32)
skin->init(header[0], header[1], geometry->numVertices); skin->init(header[0], header[1], geometry->numVertices);
skin->numWeights = header[2]; skin->numWeights = header[2];
if(!oldFormat) if(!oldFormat && !skinGlobals.forceSkipUsedBones)
stream->read(skin->usedBones, skin->numUsedBones); stream->read(skin->usedBones, skin->numUsedBones);
if(skin->indices) if(skin->indices)
stream->read(skin->indices, geometry->numVertices*4); stream->read(skin->indices, geometry->numVertices*4);

View File

@ -43,114 +43,114 @@ matrixMult(float32 *out, float32 *a, float32 *b)
#undef B #undef B
} }
void void
matrixInvert(float32 *out, float32 *m) matrixInvert(float32 *out, float32 *m)
{ {
float32 inv[16], det; float32 inv[16], det;
int i; int i;
inv[0] = m[5] * m[10] * m[15] - inv[0] = m[5] * m[10] * m[15] -
m[5] * m[11] * m[14] - m[5] * m[11] * m[14] -
m[9] * m[6] * m[15] + m[9] * m[6] * m[15] +
m[9] * m[7] * m[14] + m[9] * m[7] * m[14] +
m[13] * m[6] * m[11] - m[13] * m[6] * m[11] -
m[13] * m[7] * m[10]; m[13] * m[7] * m[10];
inv[4] = -m[4] * m[10] * m[15] + inv[4] = -m[4] * m[10] * m[15] +
m[4] * m[11] * m[14] + m[4] * m[11] * m[14] +
m[8] * m[6] * m[15] - m[8] * m[6] * m[15] -
m[8] * m[7] * m[14] - m[8] * m[7] * m[14] -
m[12] * m[6] * m[11] + m[12] * m[6] * m[11] +
m[12] * m[7] * m[10]; m[12] * m[7] * m[10];
inv[8] = m[4] * m[9] * m[15] - inv[8] = m[4] * m[9] * m[15] -
m[4] * m[11] * m[13] - m[4] * m[11] * m[13] -
m[8] * m[5] * m[15] + m[8] * m[5] * m[15] +
m[8] * m[7] * m[13] + m[8] * m[7] * m[13] +
m[12] * m[5] * m[11] - m[12] * m[5] * m[11] -
m[12] * m[7] * m[9]; m[12] * m[7] * m[9];
inv[12] = -m[4] * m[9] * m[14] + inv[12] = -m[4] * m[9] * m[14] +
m[4] * m[10] * m[13] + m[4] * m[10] * m[13] +
m[8] * m[5] * m[14] - m[8] * m[5] * m[14] -
m[8] * m[6] * m[13] - m[8] * m[6] * m[13] -
m[12] * m[5] * m[10] + m[12] * m[5] * m[10] +
m[12] * m[6] * m[9]; m[12] * m[6] * m[9];
inv[1] = -m[1] * m[10] * m[15] + inv[1] = -m[1] * m[10] * m[15] +
m[1] * m[11] * m[14] + m[1] * m[11] * m[14] +
m[9] * m[2] * m[15] - m[9] * m[2] * m[15] -
m[9] * m[3] * m[14] - m[9] * m[3] * m[14] -
m[13] * m[2] * m[11] + m[13] * m[2] * m[11] +
m[13] * m[3] * m[10]; m[13] * m[3] * m[10];
inv[5] = m[0] * m[10] * m[15] - inv[5] = m[0] * m[10] * m[15] -
m[0] * m[11] * m[14] - m[0] * m[11] * m[14] -
m[8] * m[2] * m[15] + m[8] * m[2] * m[15] +
m[8] * m[3] * m[14] + m[8] * m[3] * m[14] +
m[12] * m[2] * m[11] - m[12] * m[2] * m[11] -
m[12] * m[3] * m[10]; m[12] * m[3] * m[10];
inv[9] = -m[0] * m[9] * m[15] + inv[9] = -m[0] * m[9] * m[15] +
m[0] * m[11] * m[13] + m[0] * m[11] * m[13] +
m[8] * m[1] * m[15] - m[8] * m[1] * m[15] -
m[8] * m[3] * m[13] - m[8] * m[3] * m[13] -
m[12] * m[1] * m[11] + m[12] * m[1] * m[11] +
m[12] * m[3] * m[9]; m[12] * m[3] * m[9];
inv[13] = m[0] * m[9] * m[14] - inv[13] = m[0] * m[9] * m[14] -
m[0] * m[10] * m[13] - m[0] * m[10] * m[13] -
m[8] * m[1] * m[14] + m[8] * m[1] * m[14] +
m[8] * m[2] * m[13] + m[8] * m[2] * m[13] +
m[12] * m[1] * m[10] - m[12] * m[1] * m[10] -
m[12] * m[2] * m[9]; m[12] * m[2] * m[9];
inv[2] = m[1] * m[6] * m[15] - inv[2] = m[1] * m[6] * m[15] -
m[1] * m[7] * m[14] - m[1] * m[7] * m[14] -
m[5] * m[2] * m[15] + m[5] * m[2] * m[15] +
m[5] * m[3] * m[14] + m[5] * m[3] * m[14] +
m[13] * m[2] * m[7] - m[13] * m[2] * m[7] -
m[13] * m[3] * m[6]; m[13] * m[3] * m[6];
inv[6] = -m[0] * m[6] * m[15] + inv[6] = -m[0] * m[6] * m[15] +
m[0] * m[7] * m[14] + m[0] * m[7] * m[14] +
m[4] * m[2] * m[15] - m[4] * m[2] * m[15] -
m[4] * m[3] * m[14] - m[4] * m[3] * m[14] -
m[12] * m[2] * m[7] + m[12] * m[2] * m[7] +
m[12] * m[3] * m[6]; m[12] * m[3] * m[6];
inv[10] = m[0] * m[5] * m[15] - inv[10] = m[0] * m[5] * m[15] -
m[0] * m[7] * m[13] - m[0] * m[7] * m[13] -
m[4] * m[1] * m[15] + m[4] * m[1] * m[15] +
m[4] * m[3] * m[13] + m[4] * m[3] * m[13] +
m[12] * m[1] * m[7] - m[12] * m[1] * m[7] -
m[12] * m[3] * m[5]; m[12] * m[3] * m[5];
inv[14] = -m[0] * m[5] * m[14] + inv[14] = -m[0] * m[5] * m[14] +
m[0] * m[6] * m[13] + m[0] * m[6] * m[13] +
m[4] * m[1] * m[14] - m[4] * m[1] * m[14] -
m[4] * m[2] * m[13] - m[4] * m[2] * m[13] -
m[12] * m[1] * m[6] + m[12] * m[1] * m[6] +
m[12] * m[2] * m[5]; m[12] * m[2] * m[5];
inv[3] = -m[1] * m[6] * m[11] + inv[3] = -m[1] * m[6] * m[11] +
m[1] * m[7] * m[10] + m[1] * m[7] * m[10] +
m[5] * m[2] * m[11] - m[5] * m[2] * m[11] -
m[5] * m[3] * m[10] - m[5] * m[3] * m[10] -
m[9] * m[2] * m[7] + m[9] * m[2] * m[7] +
m[9] * m[3] * m[6]; m[9] * m[3] * m[6];
inv[7] = m[0] * m[6] * m[11] - inv[7] = m[0] * m[6] * m[11] -
m[0] * m[7] * m[10] - m[0] * m[7] * m[10] -
m[4] * m[2] * m[11] + m[4] * m[2] * m[11] +
m[4] * m[3] * m[10] + m[4] * m[3] * m[10] +
m[8] * m[2] * m[7] - m[8] * m[2] * m[7] -
m[8] * m[3] * m[6]; m[8] * m[3] * m[6];
inv[11] = -m[0] * m[5] * m[11] + inv[11] = -m[0] * m[5] * m[11] +
m[0] * m[7] * m[9] + m[0] * m[7] * m[9] +
m[4] * m[1] * m[11] - m[4] * m[1] * m[11] -
m[4] * m[3] * m[9] - m[4] * m[3] * m[9] -
m[8] * m[1] * m[7] + m[8] * m[1] * m[7] +
m[8] * m[3] * m[5]; m[8] * m[3] * m[5];
inv[15] = m[0] * m[5] * m[10] - inv[15] = m[0] * m[5] * m[10] -
m[0] * m[6] * m[9] - m[0] * m[6] * m[9] -
m[4] * m[1] * m[10] + m[4] * m[1] * m[10] +
m[4] * m[2] * m[9] + m[4] * m[2] * m[9] +
m[8] * m[1] * m[6] - m[8] * m[1] * m[6] -
m[8] * m[2] * m[5]; m[8] * m[2] * m[5];
det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12]; det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
if(det == 0) if(det == 0)
return; return;
det = 1.0f / det; det = 1.0f / det;
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
out[i] = inv[i] * det; out[i] = inv[i] * det;
} }
int32 int32

View File

@ -379,6 +379,7 @@ struct SkinGlobals
{ {
int32 offset; int32 offset;
ObjPipeline *pipelines[NUM_PLATFORMS]; ObjPipeline *pipelines[NUM_PLATFORMS];
bool32 forceSkipUsedBones;
}; };
extern SkinGlobals skinGlobals; extern SkinGlobals skinGlobals;
void registerSkinPlugin(void); void registerSkinPlugin(void);

View File

@ -14,117 +14,121 @@ using namespace rw;
struct bone { struct bone {
int32 id; int32 id;
char *name; char *name;
char *newName;
}; };
bone idMapVC[] = { bone idMapVC[] = {
{ 0, "Root" }, { 0, "Root", NULL },
{ 1, "Pelvis" }, { 1, "Pelvis", NULL },
{ 2, "Spine" }, { 2, "Spine", NULL },
{ 3, "Spine1" }, { 3, "Spine1", NULL },
{ 4, "Neck" }, { 4, "Neck", NULL },
{ 5, "Head" }, { 5, "Head", NULL },
{ 31, "Bip01 L Clavicle" }, { 31, "Bip01 L Clavicle", NULL },
{ 32, "L UpperArm" }, { 32, "L UpperArm", NULL },
{ 33, "L Forearm" }, { 33, "L Forearm", NULL },
{ 34, "L Hand" }, { 34, "L Hand", NULL },
{ 35, "L Finger" }, { 35, "L Finger", NULL },
{ 21, "Bip01 R Clavicle" }, { 21, "Bip01 R Clavicle", NULL },
{ 22, "R UpperArm" }, { 22, "R UpperArm", NULL },
{ 23, "R Forearm" }, { 23, "R Forearm", NULL },
{ 24, "R Hand" }, { 24, "R Hand", NULL },
{ 25, "R Finger" }, { 25, "R Finger", NULL },
{ 41, "L Thigh" }, { 41, "L Thigh", NULL },
{ 42, "L Calf" }, { 42, "L Calf", NULL },
{ 43, "L Foot" }, { 43, "L Foot", NULL },
{ 2000, "L Toe0" }, { 2000, "L Toe0", NULL },
{ 51, "R Thigh" }, { 51, "R Thigh", NULL },
{ 52, "R Calf" }, { 52, "R Calf", NULL },
{ 53, "R Foot" }, { 53, "R Foot", NULL },
{ 2001, "R Toe0" }, { 2001, "R Toe0", NULL },
}; };
bone csIdMapVC[] = { bone csIdMapVC[] = {
{ 0, "Root" }, { 0, "Root", NULL },
{ 1, "Pelvis" }, { 1, "Pelvis", NULL },
{ 2, "Spine" }, { 2, "Spine", NULL },
{ 3, "Spine1" }, { 3, "Spine1", NULL },
{ 4, "Neck" }, { 4, "Neck", NULL },
{ 5, "Head" }, { 5, "Head", NULL },
{ 2000, "HeadNub" }, // "Bip01 HeadNub" { 2000, "HeadNub", "Bip01 HeadNub" },
{ 5006, "llid" }, { 5006, "llid", NULL },
{ 5005, "rlid" }, { 5005, "rlid", NULL },
{ 5001, "rbrow1" }, { 5001, "rbrow1", NULL },
{ 5002, "rbrow2" }, { 5002, "rbrow2", NULL },
{ 5004, "lbrow1" }, { 5004, "lbrow1", NULL },
{ 5003, "lbrow2" }, { 5003, "lbrow2", NULL },
{ 5008, "lcheek" }, { 5008, "lcheek", NULL },
{ 5015, "rcorner" }, { 5015, "rcorner", NULL },
{ 5016, "lcorner" }, { 5016, "lcorner", NULL },
{ 5017, "jaw1" }, { 5017, "jaw1", NULL },
{ 5018, "jaw2" }, { 5018, "jaw2", NULL },
{ 5019, "llip" }, { 5019, "llip", NULL },
{ 5020, "llip01" }, { 5020, "llip01", NULL },
{ 5012, "ltlip1" }, { 5012, "ltlip1", NULL },
{ 5013, "ltlip2" }, { 5013, "ltlip2", NULL },
{ 5014, "ltlip3" }, { 5014, "ltlip3", NULL },
{ 5009, "rtlip1" }, { 5009, "rtlip1", NULL },
{ 5010, "rtlip2" }, { 5010, "rtlip2", NULL },
{ 5011, "rtlip3" }, { 5011, "rtlip3", NULL },
{ 5007, "rcheek" }, { 5007, "rcheek", NULL },
{ 5021, "reye" }, { 5021, "reye", NULL },
{ 5022, "leye" }, { 5022, "leye", NULL },
{ 31, "L Clavicle" }, // "Bip01 L Clavicle" { 31, "L Clavicle", "Bip01 L Clavicle" },
{ 32, "L UpperArm" }, { 32, "L UpperArm", NULL },
{ 33, "L Forearm" }, { 33, "L Forearm", NULL },
{ 34, "L Hand" }, { 34, "L Hand", NULL },
{ 35, "L Finger0" }, // "L Finger" { 35, "L Finger0", "L Finger" },
{ 36, "L Finger01" }, // "Root L Finger01" { 36, "L Finger01", "Root L Finger01" },
{ 2001, "L Finger0Nub" }, // "Bip01 L Finger0Nub" { 2001, "L Finger0Nub", "Bip01 L Finger0Nub" },
{ 21, "R Clavicle" }, // "Bip01 R Clavicle" { 21, "R Clavicle", "Bip01 R Clavicle" },
{ 22, "R UpperArm" }, { 22, "R UpperArm", NULL },
{ 23, "R Forearm" }, { 23, "R Forearm", NULL },
{ 24, "R Hand" }, { 24, "R Hand", NULL },
{ 25, "R Finger0" }, // "R Finger" { 25, "R Finger0", "R Finger" },
{ 26, "R Finger01" }, // "Root R Finger01" { 26, "R Finger01", "Root R Finger01" },
{ 2002, "R Finger0Nub" }, // "Bip01 R Finger0Nub" { 2002, "R Finger0Nub", "Bip01 R Finger0Nub" },
{ 41, "L Thigh" }, { 41, "L Thigh", NULL },
{ 42, "L Calf" }, { 42, "L Calf", NULL },
{ 43, "L Foot" }, { 43, "L Foot", NULL },
{ 2003, "L Toe0" }, { 2003, "L Toe0", NULL },
{ 2004, "L Toe0Nub" }, // "Bip01 L Toe0Nub" { 2004, "L Toe0Nub", "Bip01 L Toe0Nub" },
{ 51, "R Thigh" }, { 51, "R Thigh", NULL },
{ 52, "R Calf" }, { 52, "R Calf", NULL },
{ 53, "R Foot" }, { 53, "R Foot", NULL },
{ 2005, "R Toe0" }, { 2005, "R Toe0", NULL },
{ 2006, "R Toe0Nub" }, // "Bip01 R Toe0Nub" { 2006, "R Toe0Nub", "Bip01 R Toe0Nub" },
}; };
int //int
strcmpci(const char *s, const char *t) //strcmpci(const char *s, const char *t)
{ //{
while(*s && *t && tolower(*s) == tolower(*t)){ // while(*s && *t && tolower(*s) == tolower(*t)){
s++; // s++;
t++; // t++;
} // }
return *s-*t; // return *s-*t;
} //}
Frame* //Frame*
assignIdCB(Frame *f, void *p) //assignIdCB(Frame *f, void *p)
{ //{
HAnimData *hanim = PLUGINOFFSET(HAnimData, f, hAnimOffset); // HAnimData *hanim = PLUGINOFFSET(HAnimData, f, hAnimOffset);
char *name = PLUGINOFFSET(char, f, gta::nodeNameOffset); // char *name = PLUGINOFFSET(char, f, gta::nodeNameOffset);
HAnimHierarchy *hier = (HAnimHierarchy*)p; // HAnimHierarchy *hier = (HAnimHierarchy*)p;
bone *map = hier->numNodes == 24 ? idMapVC : csIdMapVC; // bone *map = hier->numNodes == 24 ? idMapVC : csIdMapVC;
for(int32 i = 0; i < hier->numNodes; i++){ // for(int32 i = 0; i < hier->numNodes; i++){
if(strcmpci(name, map[i].name) == 0){ // if(strcmpci(name, map[i].name) == 0){
hanim->id = map[i].id; // if(map[i].newName)
break; // strncpy(name, map[i].newName, 24);
} // //printf("%x %d %s\n", hanim->id, hanim->id, name);
} // //hanim->id = map[i].id;
f->forAllChildren(assignIdCB, hier); // break;
return f; // }
} // }
// f->forAllChildren(assignIdCB, hier);
// return f;
//}
Frame* Frame*
findHierCB(Frame *f, void *p) findHierCB(Frame *f, void *p)
@ -150,71 +154,78 @@ void
assignNodeIDs(Clump *c) assignNodeIDs(Clump *c)
{ {
HAnimHierarchy *hier = getHierarchy(c); HAnimHierarchy *hier = getHierarchy(c);
if(hier == NULL || (hier->numNodes != 24 && hier->numNodes != 53)) if(hier == NULL)
return; return;
bone *map = hier->numNodes == 24 ? idMapVC : csIdMapVC; // if(hier == NULL || (hier->numNodes != 24 && hier->numNodes != 53))
for(int32 i = 0; i < hier->numNodes; i++) // return;
hier->nodeInfo[i].id = map[hier->nodeInfo[i].index].id; // bone *map = hier->numNodes == 24 ? idMapVC : csIdMapVC;
assignIdCB((Frame*)c->parent, hier); for(int32 i = 0; i < hier->numNodes; i++){
} // printf("%x %x %d\n", hier->nodeInfo[i].index, hier->nodeInfo[i].id, hier->nodeInfo[i].id);
int32 id = hier->nodeInfo[i].id;
void if(id == 255) hier->nodeInfo[i].id = -1;
mirrorFrameHier(Frame *f) else if(id > 0x80) hier->nodeInfo[i].id |= 0x1300;
{ // hier->nodeInfo[i].id = map[hier->nodeInfo[i].index].id;
if(f->next){
Frame *n = f->next;
Frame *p = (Frame*)f->parent;
f->removeChild();
mirrorFrameHier(n);
p->addChild(f);
} }
if(f->child) // assignIdCB((Frame*)c->parent, hier);
mirrorFrameHier(f->child);
} }
void //void
generateInvBoneMats(Atomic *a) //mirrorFrameHier(Frame *f)
{ //{
float32 rootInv[16], tmp[16]; // if(f->next){
HAnimHierarchy *h = getHierarchy(a->clump); // Frame *n = f->next;
Frame *root = h->parentFrame; // Frame *p = (Frame*)f->parent;
root->updateLTM(); // f->removeChild();
matrixInvert(rootInv, root->ltm); // mirrorFrameHier(n);
Skin *skin = *PLUGINOFFSET(Skin*, a->geometry, skinGlobals.offset); // p->addChild(f);
assert(skin->numBones == h->numNodes); // }
for(int32 i = 0; i < h->numNodes; i++){ // if(f->child)
//assert(h->nodeInfo[i].frame); // mirrorFrameHier(f->child);
if(h->nodeInfo[i].frame == NULL){ //}
printf("warning: no node for node %d/%d\n", i, h->nodeInfo[i].id);
continue;
}
h->nodeInfo[i].frame->updateLTM();
float32 *m = &skin->inverseMatrices[i*16];
matrixMult(tmp, rootInv, h->nodeInfo[i].frame->ltm);
matrixInvert(m, tmp);
}
}
Frame* //void
findFrameById(Frame *f, int32 id) //generateInvBoneMats(Atomic *a)
{ //{
if(f == NULL) // float32 rootInv[16], tmp[16];
return NULL; // HAnimHierarchy *h = getHierarchy(a->clump);
HAnimData *hanim = PLUGINOFFSET(HAnimData, f, hAnimOffset); // Frame *root = h->parentFrame;
if(hanim->id == id) // root->updateLTM();
return f; // matrixInvert(rootInv, root->ltm);
Frame *ff = findFrameById(f->next, id); // Skin *skin = *PLUGINOFFSET(Skin*, a->geometry, skinGlobals.offset);
if(ff) return ff; // assert(skin->numBones == h->numNodes);
return findFrameById(f->child, id); // for(int32 i = 0; i < h->numNodes; i++){
} // //assert(h->nodeInfo[i].frame);
// if(h->nodeInfo[i].frame == NULL){
// printf("warning: no node for node %d/%d\n", i, h->nodeInfo[i].id);
// continue;
// }
// h->nodeInfo[i].frame->updateLTM();
// float32 *m = &skin->inverseMatrices[i*16];
// matrixMult(tmp, rootInv, h->nodeInfo[i].frame->ltm);
// matrixInvert(m, tmp);
// }
//}
void //Frame*
attachFrames(Clump *c) //findFrameById(Frame *f, int32 id)
{ //{
HAnimHierarchy *h = getHierarchy(c); // if(f == NULL)
for(int32 i = 0; i < h->numNodes; i++) // return NULL;
h->nodeInfo[i].frame = findFrameById(h->parentFrame, h->nodeInfo[i].id); // HAnimData *hanim = PLUGINOFFSET(HAnimData, f, hAnimOffset);
} // if(hanim->id == id)
// return f;
// Frame *ff = findFrameById(f->next, id);
// if(ff) return ff;
// return findFrameById(f->child, id);
//}
//void
//attachFrames(Clump *c)
//{
// HAnimHierarchy *h = getHierarchy(c);
// for(int32 i = 0; i < h->numNodes; i++)
// h->nodeInfo[i].frame = findFrameById(h->parentFrame, h->nodeInfo[i].id);
//}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
@ -230,6 +241,7 @@ main(int argc, char *argv[])
int lcs = 1; int lcs = 1;
matFXGlobals.hack = lcs; matFXGlobals.hack = lcs;
skinGlobals.forceSkipUsedBones = lcs;
gta::attachPlugins(); gta::attachPlugins();
@ -286,17 +298,18 @@ main(int argc, char *argv[])
if(lcs){ if(lcs){
HAnimHierarchy *hier = getHierarchy(c); HAnimHierarchy *hier = getHierarchy(c);
if(hier) if(hier){
hier->maxInterpKeyFrameSize = findAnimInterpolatorInfo(1)->keyFrameSize; hier->maxInterpKeyFrameSize = findAnimInterpolatorInfo(1)->keyFrameSize;
mirrorFrameHier((Frame*)c->parent); //mirrorFrameHier((Frame*)c->parent);
assignNodeIDs(c); assignNodeIDs(c);
attachFrames(c); }
//attachFrames(c);
for(int32 i = 0; i < c->numAtomics; i++){ for(int32 i = 0; i < c->numAtomics; i++){
Skin *skin = *PLUGINOFFSET(Skin*, c->atomicList[i]->geometry, skinGlobals.offset); Skin *skin = *PLUGINOFFSET(Skin*, c->atomicList[i]->geometry, skinGlobals.offset);
convertRslGeometry(c->atomicList[i]->geometry); convertRslGeometry(c->atomicList[i]->geometry);
if(skin){ if(skin){
c->atomicList[i]->pipeline = skinGlobals.pipelines[rw::platform]; c->atomicList[i]->pipeline = skinGlobals.pipelines[rw::platform];
generateInvBoneMats(c->atomicList[i]); //generateInvBoneMats(c->atomicList[i]);
} }
} }
} }